Skip to content

Commit

Permalink
refactor: make test fixtures less specific to norms
Browse files Browse the repository at this point in the history
RISDEV-6259
  • Loading branch information
andreasphil committed Jan 17, 2025
1 parent 4db4160 commit 4444c04
Show file tree
Hide file tree
Showing 36 changed files with 1,086 additions and 1,202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ class getRelease {
@Test
void itReturnsRelease() throws Exception {
// Given
var amendingNorm = NormFixtures.loadFromDisk("NormWithMods.xml");
var affectedNormZf0 = NormFixtures.loadFromDisk("NormWithPassiveModifications.xml");
var amendingNorm = Fixtures.loadNormFromDisk("NormWithMods.xml");
var affectedNormZf0 = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml");
var announcement = Announcement
.builder()
.eli(amendingNorm.getExpressionEli())
Expand Down Expand Up @@ -252,8 +252,8 @@ class putRelease {
@Test
void itReleaseAnAnnouncement() throws Exception {
// Given
var amendingNorm = NormFixtures.loadFromDisk("NormWithMods.xml");
var affectedNormZf0 = NormFixtures.loadFromDisk("NormWithPassiveModifications.xml");
var amendingNorm = Fixtures.loadNormFromDisk("NormWithMods.xml");
var affectedNormZf0 = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml");
var announcement = Announcement
.builder()
.eli(amendingNorm.getExpressionEli())
Expand Down Expand Up @@ -303,7 +303,7 @@ class postAnnouncement {
@Test
void itCreatesAnAnnouncement() throws Exception {
// Given
var norm = NormFixtures.loadFromDisk("NormWithMods.xml");
var norm = Fixtures.loadNormFromDisk("NormWithMods.xml");
var xmlContent = XmlMapper.toString(norm.getDocument());
final MockMultipartFile file = new MockMultipartFile(
"file",
Expand Down Expand Up @@ -333,7 +333,7 @@ void itCreatesAnAnnouncement() throws Exception {
@Test
void itCreatesAnAnnouncementWithForce() throws Exception {
// Given
var norm = NormFixtures.loadFromDisk("NormWithMods.xml");
var norm = Fixtures.loadNormFromDisk("NormWithMods.xml");
var xmlContent = XmlMapper.toString(norm.getDocument());
final MockMultipartFile file = new MockMultipartFile(
"file",
Expand Down Expand Up @@ -363,7 +363,7 @@ void itCreatesAnAnnouncementWithForce() throws Exception {
@Test
void itShouldNotExposeInternalInformationOnUnexpectedErrors() throws Exception {
// Given
var norm = NormFixtures.loadFromDisk("NormWithMods.xml");
var norm = Fixtures.loadNormFromDisk("NormWithMods.xml");
var xmlContent = XmlMapper.toString(norm.getDocument());
final MockMultipartFile file = new MockMultipartFile(
"file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import de.bund.digitalservice.ris.norms.application.port.input.*;
import de.bund.digitalservice.ris.norms.config.SecurityConfig;
import de.bund.digitalservice.ris.norms.domain.entity.Fixtures;
import de.bund.digitalservice.ris.norms.domain.entity.Norm;
import de.bund.digitalservice.ris.norms.domain.entity.NormFixtures;
import de.bund.digitalservice.ris.norms.domain.entity.Regelungstext;
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
Expand Down Expand Up @@ -61,8 +61,8 @@ class getArticles {
@Test
void itReturnsArticles() throws Exception {
// Given
var norm = NormFixtures.loadFromDisk("NormWithMods.xml");
var zf0Norm = NormFixtures.loadFromDisk("NormWithPassiveModifications.xml");
var norm = Fixtures.loadNormFromDisk("NormWithMods.xml");
var zf0Norm = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml");

when(loadNormUseCase.loadNorm(any())).thenReturn(zf0Norm);
when(loadArticlesFromNormUseCase.loadArticlesFromNorm(any())).thenReturn(norm.getArticles());
Expand Down Expand Up @@ -103,7 +103,7 @@ void itReturnsArticles() throws Exception {
@Test
void itReturnsArticlesFilteredByAmendedAt() throws Exception {
// Given
var norm = NormFixtures.loadFromDisk("NormWithMultiplePassiveModifications.xml");
var norm = Fixtures.loadNormFromDisk("NormWithMultiplePassiveModifications.xml");

when(loadNormUseCase.loadNorm(any())).thenReturn(norm);

Expand Down Expand Up @@ -145,7 +145,7 @@ void itReturnsArticlesFilteredByAmendedAt() throws Exception {
@Test
void itReturnsArticlesFilteredByAmendedBy() throws Exception {
// Given
var norm = NormFixtures.loadFromDisk("NormWithPassiveModificationsInDifferentArticles.xml");
var norm = Fixtures.loadNormFromDisk("NormWithPassiveModificationsInDifferentArticles.xml");

when(loadNormUseCase.loadNorm(any())).thenReturn(norm);

Expand Down Expand Up @@ -189,7 +189,7 @@ void itReturnsArticlesFilteredByAmendedBy() throws Exception {
@Test
void itReturnsUnprocessableEntityWhenMandatoryNodeIsMissing() throws Exception {
// Given
var norm = NormFixtures.loadFromDisk("NormWithPassiveModificationsInDifferentArticles.xml");
var norm = Fixtures.loadNormFromDisk("NormWithPassiveModificationsInDifferentArticles.xml");

when(loadNormUseCase.loadNorm(any())).thenReturn(norm);

Expand Down Expand Up @@ -244,8 +244,8 @@ class getArticle {
@Test
void itReturnsArticle() throws Exception {
// Given
var norm = NormFixtures.loadFromDisk("NormWithMods.xml");
var normZf0 = NormFixtures.loadFromDisk("NormWithPassiveModifications.xml");
var norm = Fixtures.loadNormFromDisk("NormWithMods.xml");
var normZf0 = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml");

when(loadNormUseCase.loadNorm(any())).thenReturn(norm).thenReturn(normZf0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import de.bund.digitalservice.ris.norms.application.exception.NormNotFoundException;
import de.bund.digitalservice.ris.norms.application.port.input.*;
import de.bund.digitalservice.ris.norms.config.SecurityConfig;
import de.bund.digitalservice.ris.norms.domain.entity.Fixtures;
import de.bund.digitalservice.ris.norms.domain.entity.Norm;
import de.bund.digitalservice.ris.norms.domain.entity.NormFixtures;
import de.bund.digitalservice.ris.norms.domain.entity.Regelungstext;
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
Expand Down Expand Up @@ -255,10 +255,10 @@ void itCallsNormServiceAndReturnsNormRenderWithAtIsoDate() throws Exception {
final String eli = "eli/bund/bgbl-1/1990/s2954/2022-12-19/1/deu/regelungstext-1";
final String html = "<div></div>";

when(loadNormUseCase.loadNorm(any())).thenReturn(NormFixtures.loadFromDisk("SimpleNorm.xml"));
when(loadNormUseCase.loadNorm(any())).thenReturn(Fixtures.loadNormFromDisk("SimpleNorm.xml"));
when(transformLegalDocMlToHtmlUseCase.transformLegalDocMlToHtml(any())).thenReturn(html);
when(applyPassiveModificationsUseCase.applyPassiveModifications(any()))
.thenReturn(NormFixtures.loadFromDisk("SimpleNorm.xml"));
.thenReturn(Fixtures.loadNormFromDisk("SimpleNorm.xml"));

// When // Then
mockMvc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import de.bund.digitalservice.ris.norms.application.port.input.UpdateProprietaryFrameFromNormUseCase;
import de.bund.digitalservice.ris.norms.application.port.input.UpdateProprietarySingleElementFromNormUseCase;
import de.bund.digitalservice.ris.norms.config.SecurityConfig;
import de.bund.digitalservice.ris.norms.domain.entity.NormFixtures;
import de.bund.digitalservice.ris.norms.domain.entity.Fixtures;
import de.bund.digitalservice.ris.norms.domain.entity.Proprietary;
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
Expand Down Expand Up @@ -86,7 +86,7 @@ void returnsProprietaryResponseSchema() throws Exception {
"eli/bund/bgbl-1/2002/s1181/2019-11-22/1/deu/rechtsetzungsdokument-1"
);
var atDateString = "2024-06-03";
var normWithProprietary = NormFixtures.loadFromDisk("NormWithProprietary.xml");
var normWithProprietary = Fixtures.loadNormFromDisk("NormWithProprietary.xml");
var proprietary = normWithProprietary.getMeta().getOrCreateProprietary();
when(
loadProprietaryFromNormUseCase.loadProprietaryFromNorm(
Expand Down Expand Up @@ -122,7 +122,7 @@ void returnsEmptyValuesIfSpecificProprietaryDataIsNotFound() throws Exception {
"eli/bund/bgbl-1/2002/s1181/2019-11-22/1/deu/rechtsetzungsdokument-1"
);
var atDateString = "2024-06-03";
var normWithInvalidProprietary = NormFixtures.loadFromDisk("NormWithInvalidProprietary.xml");
var normWithInvalidProprietary = Fixtures.loadNormFromDisk("NormWithInvalidProprietary.xml");
var proprietary = normWithInvalidProprietary.getMeta().getOrCreateProprietary();
when(
loadProprietaryFromNormUseCase.loadProprietaryFromNorm(
Expand Down Expand Up @@ -158,7 +158,7 @@ void returnsEmptyValuesIfProprietaryDoesNotExist() throws Exception {
"eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/regelungstext-1"
);
var atDateString = "2024-06-03";
var normWithInvalidProprietary = NormFixtures.loadFromDisk("SimpleNorm.xml");
var normWithInvalidProprietary = Fixtures.loadNormFromDisk("SimpleNorm.xml");
var proprietary = normWithInvalidProprietary.getMeta().getOrCreateProprietary();
when(
loadProprietaryFromNormUseCase.loadProprietaryFromNorm(
Expand Down Expand Up @@ -342,7 +342,7 @@ void returnsProprietaryResponseSchema() throws Exception {
);
var eid = "hauptteil-1_abschnitt-0_art-1";
var atDateString = "2024-06-03";
var normWithProprietary = NormFixtures.loadFromDisk("NormWithProprietary.xml");
var normWithProprietary = Fixtures.loadNormFromDisk("NormWithProprietary.xml");
var proprietary = normWithProprietary.getMeta().getOrCreateProprietary();
when(
loadProprietaryFromNormUseCase.loadProprietaryFromNorm(
Expand Down Expand Up @@ -370,7 +370,7 @@ void returnsEmptyValuesIfSpecificProprietaryDataIsNotFound() throws Exception {
);
var eid = "hauptteil-1_abschnitt-0_art-1";
var atDateString = "2024-06-03";
var normWithInvalidProprietary = NormFixtures.loadFromDisk("NormWithInvalidProprietary.xml");
var normWithInvalidProprietary = Fixtures.loadNormFromDisk("NormWithInvalidProprietary.xml");
var proprietary = normWithInvalidProprietary.getMeta().getOrCreateProprietary();
when(
loadProprietaryFromNormUseCase.loadProprietaryFromNorm(
Expand Down Expand Up @@ -398,7 +398,7 @@ void returnsEmptyValuesIfProprietaryDoesNotExist() throws Exception {
);
var eid = "hauptteil-1_abschnitt-0_art-1";
var atDateString = "2024-06-03";
var normWithInvalidProprietary = NormFixtures.loadFromDisk("SimpleNorm.xml");
var normWithInvalidProprietary = Fixtures.loadNormFromDisk("SimpleNorm.xml");
var proprietary = normWithInvalidProprietary.getMeta().getOrCreateProprietary();
when(
loadProprietaryFromNormUseCase.loadProprietaryFromNorm(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import de.bund.digitalservice.ris.norms.adapter.input.restapi.schema.ReleaseResponseSchema;
import de.bund.digitalservice.ris.norms.domain.entity.NormFixtures;
import de.bund.digitalservice.ris.norms.domain.entity.Fixtures;
import de.bund.digitalservice.ris.norms.domain.entity.Release;
import java.time.Instant;
import java.util.List;
Expand All @@ -18,8 +18,8 @@ void canMapAnnouncementAndEffectedNorms() {
.releasedAt(Instant.parse("2024-01-02T10:20:30.0Z"))
.publishedNorms(
List.of(
NormFixtures.loadFromDisk("SimpleNorm.xml"),
NormFixtures.loadFromDisk("NormWithMods.xml")
Fixtures.loadNormFromDisk("SimpleNorm.xml"),
Fixtures.loadNormFromDisk("NormWithMods.xml")
)
)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import de.bund.digitalservice.ris.norms.domain.entity.NormFixtures;
import de.bund.digitalservice.ris.norms.domain.entity.Fixtures;
import de.bund.digitalservice.ris.norms.domain.entity.NormPublishState;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
Expand All @@ -28,7 +28,7 @@ public static void setUp() {
@Test
void testAllConstraintsAreMet() {
// Given
var xml = NormFixtures.loadTextFromDisk("SimpleNorm.xml");
var xml = Fixtures.loadTextFromDisk("SimpleNorm.xml");
var guid = UUID.fromString("c01334e2-f12b-4055-ac82-15ac03c74c78");

// When
Expand Down Expand Up @@ -60,7 +60,7 @@ void shouldBeUnpublishedByDefaultWhenCreatedUsingBuilder() {
// Given
final NormDto normDto = NormDto
.builder()
.xml(NormFixtures.loadTextFromDisk("SimpleNorm.xml"))
.xml(Fixtures.loadTextFromDisk("SimpleNorm.xml"))
.build();

// Then
Expand Down
Loading

0 comments on commit 4444c04

Please sign in to comment.