diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/NormDto.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/DokumentDto.java similarity index 91% rename from backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/NormDto.java rename to backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/DokumentDto.java index c37bd3065..1a360f774 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/NormDto.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/DokumentDto.java @@ -25,8 +25,7 @@ import org.hibernate.type.SqlTypes; /** - * Data Transfer Object (DTO) class representing a norm entity. This class is annotated with Lombok - * annotations for generating getters, setters, constructors, and builder methods. + * Data Transfer Object (DTO) class representing a dokument of a norm. */ @Getter @Setter @@ -34,8 +33,8 @@ @AllArgsConstructor @Builder(toBuilder = true) @Entity -@Table(name = "norms") -public class NormDto { +@Table(name = "dokumente") +public class DokumentDto { @Id @GeneratedValue diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/ReleaseDto.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/ReleaseDto.java index 6375dfd42..7897bcfe2 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/ReleaseDto.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/ReleaseDto.java @@ -48,5 +48,5 @@ public class ReleaseDto { ) ) @Builder.Default - private List norms = new ArrayList<>(); + private List norms = new ArrayList<>(); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/NormMapper.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/NormMapper.java index 536e17504..44f8d2161 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/NormMapper.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/NormMapper.java @@ -1,42 +1,52 @@ package de.bund.digitalservice.ris.norms.adapter.output.database.mapper; -import de.bund.digitalservice.ris.norms.adapter.output.database.dto.NormDto; +import de.bund.digitalservice.ris.norms.adapter.output.database.dto.DokumentDto; import de.bund.digitalservice.ris.norms.domain.entity.Norm; -import de.bund.digitalservice.ris.norms.domain.entity.Regelungstext; -import de.bund.digitalservice.ris.norms.utils.XmlMapper; +import java.util.Collection; +import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; -/** Mapper class for converting between {@link NormDto} and {@link Norm}. */ +/** Mapper class for converting between {@link DokumentDto} and {@link Norm}. */ public class NormMapper { // Private constructor to hide the implicit public one and prevent instantiation private NormMapper() {} /** - * Maps a {@link NormDto} to the domain {@link Norm}. + * Maps multiple {@link DokumentDto}s to the domain {@link Norm}. * - * @param normDto The input {@link NormDto} to be mapped. - * @return A new {@link Norm} mapped from the input {@link NormDto}. + * @param dokumentDtos The input {@link DokumentDto}s to be mapped. + * @return A new {@link Norm} mapped from the input {@link DokumentDto}. */ - public static Norm mapToDomain(final NormDto normDto) { - return Norm - .builder() - .regelungstexte(Set.of(new Regelungstext(XmlMapper.toDocument(normDto.getXml())))) - .publishState(normDto.getPublishState()) - .build(); + public static Optional mapToDomain(@Nonnull final Collection dokumentDtos) { + if (dokumentDtos.isEmpty()) { + return Optional.empty(); + } + + return Optional.of( + Norm + .builder() + .regelungstexte( + dokumentDtos.stream().map(RegelungstextMapper::mapToDomain).collect(Collectors.toSet()) + ) + .publishState(dokumentDtos.stream().findFirst().get().getPublishState()) + .build() + ); } /** - * Maps a domain {@link Norm} to {@link NormDto}. + * Maps a domain {@link Norm} to {@link DokumentDto}s for each of the dokuments of the norm. * * @param norm The input {@link Norm} to be mapped. - * @return A new {@link NormDto} mapped from the input {@link Norm}. + * @return A new {@link DokumentDto}s mapped from the input {@link Norm}. */ - public static NormDto mapToDto(final Norm norm) { - return NormDto - .builder() - .xml(XmlMapper.toString(norm.getDocument())) - .publishState(norm.getPublishState()) - .build(); + public static Set mapToDtos(final Norm norm) { + return norm + .getRegelungstexte() + .stream() + .map(regelungstext -> RegelungstextMapper.mapToDto(regelungstext, norm.getPublishState())) + .collect(Collectors.toSet()); } } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/RegelungstextMapper.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/RegelungstextMapper.java new file mode 100644 index 000000000..a0ae7e62d --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/RegelungstextMapper.java @@ -0,0 +1,42 @@ +package de.bund.digitalservice.ris.norms.adapter.output.database.mapper; + +import de.bund.digitalservice.ris.norms.adapter.output.database.dto.DokumentDto; +import de.bund.digitalservice.ris.norms.domain.entity.Norm; +import de.bund.digitalservice.ris.norms.domain.entity.NormPublishState; +import de.bund.digitalservice.ris.norms.domain.entity.Regelungstext; +import de.bund.digitalservice.ris.norms.utils.XmlMapper; + +/** Mapper class for converting between {@link DokumentDto} and {@link Regelungstext}. */ +public class RegelungstextMapper { + + // Private constructor to hide the implicit public one and prevent instantiation + private RegelungstextMapper() {} + + /** + * Maps a {@link DokumentDto} to the domain {@link Norm}. + * + * @param dokumentDto The input {@link DokumentDto} to be mapped. + * @return A new {@link Regelungstext} mapped from the input {@link DokumentDto}. + */ + public static Regelungstext mapToDomain(final DokumentDto dokumentDto) { + return new Regelungstext(XmlMapper.toDocument(dokumentDto.getXml())); + } + + /** + * Maps a domain {@link Regelungstext} to {@link DokumentDto}. + * + * @param regelungstext The input {@link Regelungstext} to be mapped. + * @param publishState The publishState of the {@link Norm} associated with the {@link Regelungstext}. For now this is still stored on every dokument. + * @return A new {@link DokumentDto} mapped from the input {@link Regelungstext}. + */ + public static DokumentDto mapToDto( + final Regelungstext regelungstext, + final NormPublishState publishState + ) { + return DokumentDto + .builder() + .xml(XmlMapper.toString(regelungstext.getDocument())) + .publishState(publishState) + .build(); + } +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/ReleaseMapper.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/ReleaseMapper.java index c187d554a..32ae353cf 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/ReleaseMapper.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/ReleaseMapper.java @@ -2,6 +2,8 @@ import de.bund.digitalservice.ris.norms.adapter.output.database.dto.ReleaseDto; import de.bund.digitalservice.ris.norms.domain.entity.Release; +import java.util.List; +import java.util.Optional; /** Mapper class for converting between {@link ReleaseDto} and {@link Release}. */ public class ReleaseMapper { @@ -19,7 +21,15 @@ public static Release mapToDomain(final ReleaseDto releaseDto) { return Release .builder() .releasedAt(releaseDto.getReleasedAt()) - .publishedNorms(releaseDto.getNorms().stream().map(NormMapper::mapToDomain).toList()) + .publishedNorms( + releaseDto + .getNorms() + .stream() + .map(List::of) + .map(NormMapper::mapToDomain) + .flatMap(Optional::stream) + .toList() + ) .build(); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/repository/NormRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/repository/DokumentRepository.java similarity index 56% rename from backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/repository/NormRepository.java rename to backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/repository/DokumentRepository.java index 2a254c02e..17ca80de8 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/repository/NormRepository.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/repository/DokumentRepository.java @@ -1,6 +1,6 @@ package de.bund.digitalservice.ris.norms.adapter.output.database.repository; -import de.bund.digitalservice.ris.norms.adapter.output.database.dto.NormDto; +import de.bund.digitalservice.ris.norms.adapter.output.database.dto.DokumentDto; import de.bund.digitalservice.ris.norms.domain.entity.NormPublishState; import jakarta.transaction.Transactional; import java.util.List; @@ -12,42 +12,42 @@ import org.springframework.stereotype.Repository; /** - * Repository interface for interacting with the database and managing {@link NormDto} entities. + * Repository interface for interacting with the database and managing {@link DokumentDto} entities. * This interface extends {@link JpaRepository} and focuses on operations related to {@link - * NormDto}. + * DokumentDto}. */ @Repository -public interface NormRepository extends JpaRepository { +public interface DokumentRepository extends JpaRepository { /** - * Finds a {@link NormDto} by its expression ELI (European Legislation Identifier). + * Finds a {@link DokumentDto} by its expression ELI (European Legislation Identifier). * It takes the newest manifestation if multiple exist. * * @param expressionEli The ELI to search for. - * @return An {@link Optional} containing the found {@link NormDto} if exists, or empty if not found. + * @return An {@link Optional} containing the found {@link DokumentDto} if exists, or empty if not found. */ - Optional findFirstByEliDokumentExpressionOrderByEliDokumentManifestationDesc( + Optional findFirstByEliDokumentExpressionOrderByEliDokumentManifestationDesc( final String expressionEli ); /** - * Finds a {@link NormDto} by its manifestation ELI (European Legislation Identifier). + * Finds a {@link DokumentDto} by its manifestation ELI (European Legislation Identifier). * * @param manifestationEli The ELI to search for. - * @return An {@link Optional} containing the found {@link NormDto} if exists, or empty if not found. + * @return An {@link Optional} containing the found {@link DokumentDto} if exists, or empty if not found. */ - Optional findByEliDokumentManifestation(final String manifestationEli); + Optional findByEliDokumentManifestation(final String manifestationEli); /** - * Finds a {@link NormDto} by its GUID. + * Finds a {@link DokumentDto} by its GUID. * It takes the newest manifestation if multiple norms with the same guid exist. * * @param guid The GUID to search for. - * @return An {@link Optional} containing the found {@link NormDto} if exists, or empty if not found. + * @return An {@link Optional} containing the found {@link DokumentDto} if exists, or empty if not found. */ - Optional findFirstByGuidOrderByEliDokumentManifestation(final UUID guid); + Optional findFirstByGuidOrderByEliDokumentManifestation(final UUID guid); /** - * Deletes all {@link NormDto} with the given GUID + * Deletes all {@link DokumentDto} with the given GUID * * @param guid The GUID to search for. */ @@ -55,7 +55,7 @@ Optional findFirstByEliDokumentExpressionOrderByEliDokumentManifestatio void deleteAllByGuid(final UUID guid); /** - * Deletes a {@link NormDto} by its manifestation ELI (European Legislation Identifier) if it is in the given publish state. + * Deletes a {@link DokumentDto} by its manifestation ELI (European Legislation Identifier) if it is in the given publish state. * * @param manifestationEli The ELI to search for. * @param publishState The publishState to search for. @@ -66,7 +66,7 @@ void deleteByEliDokumentManifestationAndPublishState( ); /** - * Deletes all {@link NormDto} of the given work ELI that are in the given publish state. + * Deletes all {@link DokumentDto} of the given work ELI that are in the given publish state. * @param workEli The ELI to search for. * @param publishState The publishState to search for. */ @@ -76,12 +76,12 @@ void deleteAllByEliDokumentWorkAndPublishState( ); /** - * Retrieves the ids of all {@link NormDto} with a specific {@link NormPublishState}. + * Retrieves the ids of all {@link DokumentDto} with a specific {@link NormPublishState}. * * @param normPublishState the publish state to filter the norms by (e.g., {@link NormPublishState#QUEUED_FOR_PUBLISH}) - * @return a {@link List} of {@link UUID}s of the {@link NormDto}s matching the specified publish state + * @return a {@link List} of {@link UUID}s of the {@link DokumentDto}s matching the specified publish state */ - @Query("SELECT n.id FROM NormDto n WHERE n.publishState = :publishState") + @Query("SELECT n.id FROM DokumentDto n WHERE n.publishState = :publishState") List findNormIdsByPublishState( @Param("publishState") final NormPublishState normPublishState ); diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/service/DBService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/service/DBService.java index 7b742a240..e6c68e7be 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/service/DBService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/service/DBService.java @@ -1,15 +1,15 @@ package de.bund.digitalservice.ris.norms.adapter.output.database.service; import de.bund.digitalservice.ris.norms.adapter.output.database.dto.AnnouncementDto; -import de.bund.digitalservice.ris.norms.adapter.output.database.dto.NormDto; +import de.bund.digitalservice.ris.norms.adapter.output.database.dto.DokumentDto; import de.bund.digitalservice.ris.norms.adapter.output.database.dto.ReleaseDto; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.AnnouncementMapper; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.MigrationLogMapper; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.NormMapper; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.ReleaseMapper; import de.bund.digitalservice.ris.norms.adapter.output.database.repository.AnnouncementRepository; +import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository; import de.bund.digitalservice.ris.norms.adapter.output.database.repository.MigrationLogRepository; -import de.bund.digitalservice.ris.norms.adapter.output.database.repository.NormRepository; import de.bund.digitalservice.ris.norms.adapter.output.database.repository.ReleaseRepository; import de.bund.digitalservice.ris.norms.application.port.output.*; import de.bund.digitalservice.ris.norms.domain.entity.*; @@ -20,6 +20,7 @@ import java.util.Comparator; import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.UUID; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,18 +51,18 @@ public class DBService LoadMigrationLogByDatePort { private final AnnouncementRepository announcementRepository; - private final NormRepository normRepository; + private final DokumentRepository dokumentRepository; private final ReleaseRepository releaseRepository; private final MigrationLogRepository migrationLogRepository; public DBService( AnnouncementRepository announcementRepository, - NormRepository normRepository, + DokumentRepository dokumentRepository, ReleaseRepository releaseRepository, MigrationLogRepository migrationLogRepository ) { this.announcementRepository = announcementRepository; - this.normRepository = normRepository; + this.dokumentRepository = dokumentRepository; this.releaseRepository = releaseRepository; this.migrationLogRepository = migrationLogRepository; } @@ -69,20 +70,22 @@ public DBService( @Override public Optional loadNorm(LoadNormPort.Command command) { return switch (command.eli()) { - case DokumentExpressionEli expressionEli -> normRepository + case DokumentExpressionEli expressionEli -> dokumentRepository .findFirstByEliDokumentExpressionOrderByEliDokumentManifestationDesc( expressionEli.toString() ) - .map(NormMapper::mapToDomain); + .map(List::of) + .flatMap(NormMapper::mapToDomain); case DokumentManifestationEli manifestationEli -> { if (!manifestationEli.hasPointInTimeManifestation()) { // we can find the norm based on the expression eli as the point in time manifestation is the only additional identifying part of the eli in our system (all norms are xmls) yield this.loadNorm(new LoadNormPort.Command(manifestationEli.asExpressionEli())); } - yield normRepository + yield dokumentRepository .findByEliDokumentManifestation(manifestationEli.toString()) - .map(NormMapper::mapToDomain); + .map(List::of) + .flatMap(NormMapper::mapToDomain); } case DokumentWorkEli workEli -> throw new IllegalArgumentException( "It's currently not possible to load a norm by it's work eli." @@ -92,9 +95,10 @@ public Optional loadNorm(LoadNormPort.Command command) { @Override public Optional loadNormByGuid(LoadNormByGuidPort.Command command) { - return normRepository + return dokumentRepository .findFirstByGuidOrderByEliDokumentManifestation(command.guid()) - .map(NormMapper::mapToDomain); + .map(List::of) + .flatMap(NormMapper::mapToDomain); } @Override @@ -123,12 +127,12 @@ public List loadAllAnnouncements() { @Override public Optional updateNorm(UpdateNormPort.Command command) { var normXml = XmlMapper.toString(command.norm().getDocument()); - return normRepository + return dokumentRepository .findByEliDokumentManifestation(command.norm().getManifestationEli().toString()) - .map(normDto -> { + .flatMap(normDto -> { normDto.setXml(normXml); normDto.setPublishState(command.norm().getPublishState()); - return NormMapper.mapToDomain(normRepository.save(normDto)); + return NormMapper.mapToDomain(List.of(dokumentRepository.save(normDto))); }); } @@ -136,8 +140,8 @@ public Optional updateNorm(UpdateNormPort.Command command) { public Norm updateOrSave(UpdateOrSaveNormPort.Command command) { final Optional updatedNorm = updateNorm(new UpdateNormPort.Command(command.norm())); if (updatedNorm.isEmpty()) { - final NormDto normDto = NormMapper.mapToDto(command.norm()); - return NormMapper.mapToDomain(normRepository.save(normDto)); + final Set dokumentDtos = NormMapper.mapToDtos(command.norm()); + return NormMapper.mapToDomain(dokumentRepository.saveAll(dokumentDtos)).orElseThrow(); } else { return updatedNorm.get(); } @@ -175,7 +179,7 @@ public void deleteAnnouncementByNormEli(DeleteAnnouncementByNormEliPort.Command @Override @Transactional public void deleteNorm(DeleteNormPort.Command command) { - normRepository.deleteByEliDokumentManifestationAndPublishState( + dokumentRepository.deleteByEliDokumentManifestationAndPublishState( command.eli().toString(), command.publishState() ); @@ -184,7 +188,7 @@ public void deleteNorm(DeleteNormPort.Command command) { @Override @Transactional public void deleteQueuedForPublishNorms(DeleteQueuedNormsPort.Command command) { - normRepository.deleteAllByEliDokumentWorkAndPublishState( + dokumentRepository.deleteAllByEliDokumentWorkAndPublishState( command.eli().toString(), NormPublishState.QUEUED_FOR_PUBLISH ); @@ -209,7 +213,7 @@ public Release saveReleaseToAnnouncement(SaveReleaseToAnnouncementPort.Command c .release() .getPublishedNorms() .forEach(norm -> - normRepository + dokumentRepository .findByEliDokumentManifestation(norm.getManifestationEli().toString()) .ifPresent(normDto -> releaseDto.getNorms().add(normDto)) ); @@ -242,7 +246,9 @@ public List deleteQueuedReleases(DeleteQueuedReleasesPort.Command comma releaseDto .getNorms() .stream() + .map(List::of) .map(NormMapper::mapToDomain) + .flatMap(Optional::stream) .allMatch(norm -> norm.getPublishState() == NormPublishState.QUEUED_FOR_PUBLISH) ) .toList(); @@ -257,12 +263,12 @@ public List deleteQueuedReleases(DeleteQueuedReleasesPort.Command comma @Override public List loadNormIdsByPublishState(LoadNormIdsByPublishStatePort.Command command) { - return normRepository.findNormIdsByPublishState(command.publishState()); + return dokumentRepository.findNormIdsByPublishState(command.publishState()); } @Override public Optional loadNormById(LoadNormByIdPort.Command command) { - return normRepository.findById(command.id()).map(NormMapper::mapToDomain); + return dokumentRepository.findById(command.id()).map(List::of).flatMap(NormMapper::mapToDomain); } @Override diff --git a/backend/src/main/resources/db/data/R__001_2017_s419_2017-03-15_Vereinsgesetzes.sql b/backend/src/main/resources/db/data/R__001_2017_s419_2017-03-15_Vereinsgesetzes.sql index bfb925f3d..57ee0ea28 100644 --- a/backend/src/main/resources/db/data/R__001_2017_s419_2017-03-15_Vereinsgesetzes.sql +++ b/backend/src/main/resources/db/data/R__001_2017_s419_2017-03-15_Vereinsgesetzes.sql @@ -1,10 +1,10 @@ -- REAPPLY -- TARGET LAW DELETE -FROM norms +FROM dokumente WHERE eli_dokument_expression = 'eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/regelungstext-1'; -INSERT INTO norms (publish_state, xml) +INSERT INTO dokumente (publish_state, xml) VALUES ('PUBLISHED', ' diff --git a/backend/src/main/resources/db/data/R__003_1000_1_1000-01-01_Formatting.sql b/backend/src/main/resources/db/data/R__003_1000_1_1000-01-01_Formatting.sql index 634540731..322c47c62 100644 --- a/backend/src/main/resources/db/data/R__003_1000_1_1000-01-01_Formatting.sql +++ b/backend/src/main/resources/db/data/R__003_1000_1_1000-01-01_Formatting.sql @@ -1,10 +1,10 @@ -- REAPPLY -- TARGET LAW DELETE -FROM norms +FROM dokumente WHERE eli_dokument_expression = 'eli/bund/bgbl-1/1000/s1/1000-01-01/1/deu/regelungstext-1'; -INSERT INTO norms (publish_state, xml) +INSERT INTO dokumente (publish_state, xml) VALUES ('PUBLISHED', ' diff --git a/backend/src/main/resources/db/data/R__004_2024_108_2024-03-27_Wachstumschancengesetz.sql b/backend/src/main/resources/db/data/R__004_2024_108_2024-03-27_Wachstumschancengesetz.sql index bdf95d941..447cc09ea 100644 --- a/backend/src/main/resources/db/data/R__004_2024_108_2024-03-27_Wachstumschancengesetz.sql +++ b/backend/src/main/resources/db/data/R__004_2024_108_2024-03-27_Wachstumschancengesetz.sql @@ -1,10 +1,10 @@ -- REAPPLY -- TARGET LAW DELETE -FROM norms +FROM dokumente where eli_dokument_expression = 'eli/bund/bgbl-1/2024/108/2024-03-27/1/deu/regelungstext-1'; -INSERT INTO norms (publish_state, xml) +INSERT INTO dokumente (publish_state, xml) VALUES ('PUBLISHED', ' diff --git a/backend/src/main/resources/db/data/R__008_1002_10_1002-01-10_Mods_Substitution_01.sql b/backend/src/main/resources/db/data/R__008_1002_10_1002-01-10_Mods_Substitution_01.sql index f7770417e..d1c54be35 100644 --- a/backend/src/main/resources/db/data/R__008_1002_10_1002-01-10_Mods_Substitution_01.sql +++ b/backend/src/main/resources/db/data/R__008_1002_10_1002-01-10_Mods_Substitution_01.sql @@ -1,10 +1,10 @@ -- REAPPLY -- TARGET LAW DELETE -FROM norms +FROM dokumente WHERE eli_dokument_expression = 'eli/bund/bgbl-1/1002/1/1002-01-01/1/deu/regelungstext-1'; -INSERT INTO norms (publish_state, xml) +INSERT INTO dokumente (publish_state, xml) VALUES ('PUBLISHED', ' diff --git a/backend/src/main/resources/db/data/R__009_bgbl-1_2024_10.sql b/backend/src/main/resources/db/data/R__009_bgbl-1_2024_10.sql index a80c18834..97caae9ba 100644 --- a/backend/src/main/resources/db/data/R__009_bgbl-1_2024_10.sql +++ b/backend/src/main/resources/db/data/R__009_bgbl-1_2024_10.sql @@ -1,10 +1,10 @@ -- REAPPLY -- TARGET LAW DELETE -FROM norms +FROM dokumente WHERE eli_dokument_expression = 'eli/bund/bgbl-1/2021/s818/2021-04-16/1/deu/regelungstext-1'; -INSERT INTO norms (publish_state, xml) +INSERT INTO dokumente (publish_state, xml) VALUES ('PUBLISHED', ' diff --git a/backend/src/main/resources/db/migration/V0.22__rename_norms_to_dokumente.sql b/backend/src/main/resources/db/migration/V0.22__rename_norms_to_dokumente.sql new file mode 100644 index 000000000..957c66b3a --- /dev/null +++ b/backend/src/main/resources/db/migration/V0.22__rename_norms_to_dokumente.sql @@ -0,0 +1 @@ +ALTER TABLE norms RENAME TO dokumente; diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/NormDtoTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/DokumentDtoTest.java similarity index 76% rename from backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/NormDtoTest.java rename to backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/DokumentDtoTest.java index 09b6f3e2a..73ac64ad4 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/NormDtoTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/dto/DokumentDtoTest.java @@ -14,7 +14,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -class NormDtoTest { +class DokumentDtoTest { private static Validator validator; @@ -32,8 +32,8 @@ void testAllConstraintsAreMet() { var guid = UUID.fromString("c01334e2-f12b-4055-ac82-15ac03c74c78"); // When - final NormDto normDto = NormDto.builder().xml(xml).guid(guid).build(); - final Set> violations = validator.validate(normDto); + final DokumentDto dokumentDto = DokumentDto.builder().xml(xml).guid(guid).build(); + final Set> violations = validator.validate(dokumentDto); // Then assertThat(violations).isEmpty(); @@ -42,10 +42,10 @@ void testAllConstraintsAreMet() { @Test void testMissingNotNullProperties() { // Given - final NormDto normDto = new NormDto(); + final DokumentDto dokumentDto = new DokumentDto(); // When - final Set> violations = validator.validate(normDto); + final Set> violations = validator.validate(dokumentDto); // Then assertThat(violations) @@ -58,12 +58,12 @@ void testMissingNotNullProperties() { @Test void shouldBeUnpublishedByDefaultWhenCreatedUsingBuilder() { // Given - final NormDto normDto = NormDto + final DokumentDto dokumentDto = DokumentDto .builder() .xml(Fixtures.loadTextFromDisk("SimpleNorm.xml")) .build(); // Then - assertThat(normDto.getPublishState()).isEqualTo(NormPublishState.UNPUBLISHED); + assertThat(dokumentDto.getPublishState()).isEqualTo(NormPublishState.UNPUBLISHED); } } diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/NormMapperTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/NormMapperTest.java index 00dfea0e2..e92e2276e 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/NormMapperTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/NormMapperTest.java @@ -2,13 +2,15 @@ import static org.assertj.core.api.Assertions.assertThat; -import de.bund.digitalservice.ris.norms.adapter.output.database.dto.NormDto; +import de.bund.digitalservice.ris.norms.adapter.output.database.dto.DokumentDto; +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.NormPublishState; import de.bund.digitalservice.ris.norms.domain.entity.Regelungstext; import de.bund.digitalservice.ris.norms.utils.XmlMapper; +import java.util.List; +import java.util.Optional; import java.util.Set; -import java.util.UUID; import org.junit.jupiter.api.Test; class NormMapperTest { @@ -16,79 +18,56 @@ class NormMapperTest { @Test void itShouldMapToDomain() { // Given - var xml = - """ - - - - - - - - - - - - - - - - - """; - var normDto = NormDto + var regelungstext1Xml = Fixtures.loadTextFromDisk("SimpleNorm.xml"); + var dokumentDto1 = DokumentDto .builder() - .xml(xml) - .guid(UUID.fromString("c01334e2-f12b-4055-ac82-15ac03c74c78")) + .xml(regelungstext1Xml) + .publishState(NormPublishState.QUEUED_FOR_PUBLISH) + .build(); + + var regelungstext2Xml = Fixtures.loadTextFromDisk("NormWithMods.xml"); + var dokumentDto2 = DokumentDto + .builder() + .xml(regelungstext2Xml) .publishState(NormPublishState.QUEUED_FOR_PUBLISH) .build(); // When - final Norm norm = NormMapper.mapToDomain(normDto); + final Optional norm = NormMapper.mapToDomain(List.of(dokumentDto1, dokumentDto2)); // Then - assertThat(norm).isNotNull(); - assertThat(norm.getPublishState()).isEqualTo(NormPublishState.QUEUED_FOR_PUBLISH); - assertThat(norm.getDocument().isEqualNode(XmlMapper.toDocument(xml))).isTrue(); + assertThat(norm).isPresent(); + assertThat(norm.get().getPublishState()).isEqualTo(NormPublishState.QUEUED_FOR_PUBLISH); + assertThat(norm.get().getRegelungstexte()) + .containsExactlyInAnyOrder( + new Regelungstext(XmlMapper.toDocument(regelungstext1Xml)), + new Regelungstext(XmlMapper.toDocument(regelungstext2Xml)) + ); } @Test - void itShouldMapToDto() { + void itShouldMapToDtos() { // Given - var xml = - """ - - - - - - - - - - - - - - - - - """; + var regelungstext1 = Fixtures.loadRegelungstextFromDisk("SimpleNorm.xml"); + var regelungstext2 = Fixtures.loadRegelungstextFromDisk("NormWithMods.xml"); var norm = Norm .builder() - .regelungstexte(Set.of(new Regelungstext(XmlMapper.toDocument(xml)))) + .regelungstexte(Set.of(regelungstext1, regelungstext2)) .publishState(NormPublishState.PUBLISHED) .build(); // When - final NormDto normDto = NormMapper.mapToDto(norm); + final Set dokumentDtos = NormMapper.mapToDtos(norm); // Then - assertThat(normDto).isNotNull(); - assertThat(normDto.getPublishState()).isEqualTo(NormPublishState.PUBLISHED); - assertThat(XmlMapper.toDocument(normDto.getXml()).isEqualNode(norm.getDocument())).isTrue(); + assertThat(dokumentDtos).hasSize(2); + assertThat(dokumentDtos.stream().findFirst().get().getPublishState()) + .isEqualTo(NormPublishState.PUBLISHED); + assertThat(dokumentDtos) + .map(DokumentDto::getXml) + .containsExactlyInAnyOrder( + XmlMapper.toString(regelungstext1.getDocument()), + XmlMapper.toString(regelungstext2.getDocument()) + ); } } diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/RegelungstextMapperTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/RegelungstextMapperTest.java new file mode 100644 index 000000000..8620ccebd --- /dev/null +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/RegelungstextMapperTest.java @@ -0,0 +1,47 @@ +package de.bund.digitalservice.ris.norms.adapter.output.database.mapper; + +import static org.assertj.core.api.Assertions.assertThat; + +import de.bund.digitalservice.ris.norms.adapter.output.database.dto.DokumentDto; +import de.bund.digitalservice.ris.norms.domain.entity.Fixtures; +import de.bund.digitalservice.ris.norms.domain.entity.NormPublishState; +import de.bund.digitalservice.ris.norms.domain.entity.Regelungstext; +import de.bund.digitalservice.ris.norms.utils.XmlMapper; +import org.junit.jupiter.api.Test; + +class RegelungstextMapperTest { + + @Test + void itShouldMapToDomain() { + // Given + var regelungstextXml = Fixtures.loadTextFromDisk("SimpleNorm.xml"); + var dokumentDto = DokumentDto.builder().xml(regelungstextXml).build(); + + // When + final Regelungstext regelungstext = RegelungstextMapper.mapToDomain(dokumentDto); + + // Then + assertThat(regelungstext).isNotNull(); + assertThat(regelungstext.getDocument().isEqualNode(XmlMapper.toDocument(regelungstextXml))) + .isTrue(); + } + + @Test + void itShouldMapToDto() { + // Given + var xml = Fixtures.loadTextFromDisk("SimpleNorm.xml"); + var regelungstext = new Regelungstext(XmlMapper.toDocument(xml)); + + // When + final DokumentDto dokumentDto = RegelungstextMapper.mapToDto( + regelungstext, + NormPublishState.QUEUED_FOR_PUBLISH + ); + + // Then + assertThat(dokumentDto).isNotNull(); + assertThat(XmlMapper.toDocument(dokumentDto.getXml()).isEqualNode(regelungstext.getDocument())) + .isTrue(); + assertThat(dokumentDto.getPublishState()).isEqualTo(NormPublishState.QUEUED_FOR_PUBLISH); + } +} diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/AnnouncementControllerIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/AnnouncementControllerIntegrationTest.java index ccc268c70..91145aea5 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/AnnouncementControllerIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/AnnouncementControllerIntegrationTest.java @@ -10,7 +10,7 @@ import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.AnnouncementMapper; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.NormMapper; import de.bund.digitalservice.ris.norms.adapter.output.database.repository.AnnouncementRepository; -import de.bund.digitalservice.ris.norms.adapter.output.database.repository.NormRepository; +import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository; import de.bund.digitalservice.ris.norms.adapter.output.database.repository.ReleaseRepository; import de.bund.digitalservice.ris.norms.domain.entity.*; import de.bund.digitalservice.ris.norms.integration.BaseIntegrationTest; @@ -19,6 +19,9 @@ import java.time.Instant; import java.time.LocalDate; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -38,7 +41,7 @@ class AnnouncementControllerIntegrationTest extends BaseIntegrationTest { private AnnouncementRepository announcementRepository; @Autowired - private NormRepository normRepository; + private DokumentRepository dokumentRepository; @Autowired private ReleaseRepository releaseRepository; @@ -47,7 +50,7 @@ class AnnouncementControllerIntegrationTest extends BaseIntegrationTest { void cleanUp() { announcementRepository.deleteAll(); releaseRepository.deleteAll(); - normRepository.deleteAll(); + dokumentRepository.deleteAll(); } @Nested @@ -70,7 +73,7 @@ void itReturnsAllAnnouncementsNorm() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("Vereinsgesetz.xml"); var announcement = Announcement.builder().eli(norm.getExpressionEli()).build(); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); announcementRepository.save(AnnouncementMapper.mapToDto(announcement)); // When @@ -133,7 +136,7 @@ void itDoesNotReturnReleaseBecauseAmendingLawNotFound() throws Exception { void itDoesReturnNoReleasesIfNoneFound() throws Exception { // Given var amendingNorm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - normRepository.save(NormMapper.mapToDto(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); var announcement = Announcement.builder().eli(amendingNorm.getExpressionEli()).build(); announcementRepository.save(AnnouncementMapper.mapToDto(announcement)); @@ -157,15 +160,19 @@ void itReturnsRelease() throws Exception { var affectedNorm = Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml"); var affectedNormZf0 = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml"); - var normDto1 = normRepository.save(NormMapper.mapToDto(amendingNorm)); - var normDto2 = normRepository.save(NormMapper.mapToDto(affectedNorm)); - var normDto3 = normRepository.save(NormMapper.mapToDto(affectedNormZf0)); + var dokumentDtos = dokumentRepository.saveAll( + Stream + .of(amendingNorm, affectedNorm, affectedNormZf0) + .map(NormMapper::mapToDtos) + .flatMap(Set::stream) + .collect(Collectors.toSet()) + ); var releaseDto = releaseRepository.save( ReleaseDto .builder() .releasedAt(Instant.parse("2024-01-02T10:20:30.0Z")) - .norms(List.of(normDto1, normDto2, normDto3)) + .norms(dokumentDtos) .build() ); announcementRepository.save( @@ -192,20 +199,12 @@ void itReturnsRelease() throws Exception { .andExpect(jsonPath("[0].norms[3]").doesNotExist()) .andExpect( jsonPath( - "[0].norms[0]", - equalTo("eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/2022-08-23/regelungstext-1.xml") - ) - ) - .andExpect( - jsonPath( - "[0].norms[1]", - equalTo("eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/1964-08-05/regelungstext-1.xml") - ) - ) - .andExpect( - jsonPath( - "[0].norms[2]", - equalTo("eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/2022-08-23/regelungstext-1.xml") + "[0].norms", + containsInAnyOrder( + "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/2022-08-23/regelungstext-1.xml", + "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/1964-08-05/regelungstext-1.xml", + "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/2022-08-23/regelungstext-1.xml" + ) ) ); } @@ -253,7 +252,7 @@ void itDoesNotReleaseButReturnsNotFoundIfTargetLawNotFound() throws Exception { // Given var amendingNorm = Fixtures.loadNormFromDisk("NormWithMods.xml"); var announcement = Announcement.builder().eli(amendingNorm.getExpressionEli()).build(); - normRepository.save(NormMapper.mapToDto(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); announcementRepository.save(AnnouncementMapper.mapToDto(announcement)); // When // Then @@ -293,10 +292,10 @@ void itReleaseAnnouncement() throws Exception { var affectedNormZf0 = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml"); var announcement = Announcement.builder().eli(amendingNorm.getExpressionEli()).build(); - normRepository.save(NormMapper.mapToDto(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); announcementRepository.save(AnnouncementMapper.mapToDto(announcement)); - normRepository.save(NormMapper.mapToDto(affectedNorm)); - normRepository.save(NormMapper.mapToDto(affectedNormZf0)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNormZf0)); // When // Then mockMvc @@ -326,7 +325,7 @@ void itReleaseAnnouncement() throws Exception { ) ); - var publishedManifestationOfAmendingNorm = normRepository.findByEliDokumentManifestation( + var publishedManifestationOfAmendingNorm = dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/%s/regelungstext-1.xml".formatted( LocalDate.now().toString() ) @@ -335,7 +334,7 @@ void itReleaseAnnouncement() throws Exception { assertThat(publishedManifestationOfAmendingNorm.get().getPublishState()) .isEqualTo(NormPublishState.QUEUED_FOR_PUBLISH); - var publishedZf0ManifestationOfTargetNorm = normRepository.findByEliDokumentManifestation( + var publishedZf0ManifestationOfTargetNorm = dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/%s/regelungstext-1.xml".formatted( LocalDate.now().toString() ) @@ -345,7 +344,7 @@ void itReleaseAnnouncement() throws Exception { .isEqualTo(NormPublishState.QUEUED_FOR_PUBLISH); var publishedManifestationOfTargetNormAtFirstTimeBoundary = - normRepository.findByEliDokumentManifestation( + dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/1964/s593/2017-03-23/1/deu/%s/regelungstext-1.xml".formatted( LocalDate.now().toString() ) @@ -354,26 +353,28 @@ void itReleaseAnnouncement() throws Exception { assertThat(publishedManifestationOfTargetNormAtFirstTimeBoundary.get().getPublishState()) .isEqualTo(NormPublishState.QUEUED_FOR_PUBLISH); - var newUnpublishedManifestationOfAmendingNorm = normRepository.findByEliDokumentManifestation( - "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/%s/regelungstext-1.xml".formatted( - LocalDate.now().plusDays(1).toString() - ) - ); + var newUnpublishedManifestationOfAmendingNorm = + dokumentRepository.findByEliDokumentManifestation( + "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/%s/regelungstext-1.xml".formatted( + LocalDate.now().plusDays(1).toString() + ) + ); assertThat(newUnpublishedManifestationOfAmendingNorm).isPresent(); assertThat(newUnpublishedManifestationOfAmendingNorm.get().getPublishState()) .isEqualTo(NormPublishState.UNPUBLISHED); - var newUnpublishedManifestationOfTargetNorm = normRepository.findByEliDokumentManifestation( - "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/%s/regelungstext-1.xml".formatted( - LocalDate.now().plusDays(1).toString() - ) - ); + var newUnpublishedManifestationOfTargetNorm = + dokumentRepository.findByEliDokumentManifestation( + "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/%s/regelungstext-1.xml".formatted( + LocalDate.now().plusDays(1).toString() + ) + ); assertThat(newUnpublishedManifestationOfTargetNorm).isPresent(); assertThat(newUnpublishedManifestationOfTargetNorm.get().getPublishState()) .isEqualTo(NormPublishState.UNPUBLISHED); // original target norm + 3 queued for publish norms + 2 newly created manifestations for further work. The original amending norm and zf0 norm should no longer exist - assertThat(normRepository.findAll()).hasSize(6); + assertThat(dokumentRepository.findAll()).hasSize(6); } @Test @@ -386,10 +387,10 @@ void releasingAnAnnouncementASecondTimeCreatesTheSameFilesAndCleansUpOldRelease( var affectedNormZf0 = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml"); var announcement = Announcement.builder().eli(amendingNorm.getExpressionEli()).build(); - normRepository.save(NormMapper.mapToDto(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); announcementRepository.save(AnnouncementMapper.mapToDto(announcement)); - normRepository.save(NormMapper.mapToDto(affectedNorm)); - normRepository.save(NormMapper.mapToDto(affectedNormZf0)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNormZf0)); // When // Then mockMvc @@ -411,7 +412,7 @@ void releasingAnAnnouncementASecondTimeCreatesTheSameFilesAndCleansUpOldRelease( ) .andExpect(status().isOk()); - var publishedManifestationOfAmendingNorm = normRepository.findByEliDokumentManifestation( + var publishedManifestationOfAmendingNorm = dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/%s/regelungstext-1.xml".formatted( LocalDate.now().toString() ) @@ -420,7 +421,7 @@ void releasingAnAnnouncementASecondTimeCreatesTheSameFilesAndCleansUpOldRelease( assertThat(publishedManifestationOfAmendingNorm.get().getPublishState()) .isEqualTo(NormPublishState.QUEUED_FOR_PUBLISH); - var publishedZf0ManifestationOfTargetNorm = normRepository.findByEliDokumentManifestation( + var publishedZf0ManifestationOfTargetNorm = dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/%s/regelungstext-1.xml".formatted( LocalDate.now().toString() ) @@ -430,7 +431,7 @@ void releasingAnAnnouncementASecondTimeCreatesTheSameFilesAndCleansUpOldRelease( .isEqualTo(NormPublishState.QUEUED_FOR_PUBLISH); var publishedManifestationOfTargetNormAtFirstTimeBoundary = - normRepository.findByEliDokumentManifestation( + dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/1964/s593/2017-03-23/1/deu/%s/regelungstext-1.xml".formatted( LocalDate.now().toString() ) @@ -439,26 +440,28 @@ void releasingAnAnnouncementASecondTimeCreatesTheSameFilesAndCleansUpOldRelease( assertThat(publishedManifestationOfTargetNormAtFirstTimeBoundary.get().getPublishState()) .isEqualTo(NormPublishState.QUEUED_FOR_PUBLISH); - var newUnpublishedManifestationOfAmendingNorm = normRepository.findByEliDokumentManifestation( - "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/%s/regelungstext-1.xml".formatted( - LocalDate.now().plusDays(1).toString() - ) - ); + var newUnpublishedManifestationOfAmendingNorm = + dokumentRepository.findByEliDokumentManifestation( + "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/%s/regelungstext-1.xml".formatted( + LocalDate.now().plusDays(1).toString() + ) + ); assertThat(newUnpublishedManifestationOfAmendingNorm).isPresent(); assertThat(newUnpublishedManifestationOfAmendingNorm.get().getPublishState()) .isEqualTo(NormPublishState.UNPUBLISHED); - var newUnpublishedManifestationOfTargetNorm = normRepository.findByEliDokumentManifestation( - "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/%s/regelungstext-1.xml".formatted( - LocalDate.now().plusDays(1).toString() - ) - ); + var newUnpublishedManifestationOfTargetNorm = + dokumentRepository.findByEliDokumentManifestation( + "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/%s/regelungstext-1.xml".formatted( + LocalDate.now().plusDays(1).toString() + ) + ); assertThat(newUnpublishedManifestationOfTargetNorm).isPresent(); assertThat(newUnpublishedManifestationOfTargetNorm.get().getPublishState()) .isEqualTo(NormPublishState.UNPUBLISHED); // original target norm + 3 queued for publish norms + 2 newly created manifestations for further work. The original amending norm and zf0 norm should no longer exist - assertThat(normRepository.findAll()).hasSize(6); + assertThat(dokumentRepository.findAll()).hasSize(6); } @Test @@ -471,10 +474,10 @@ void failsWhenTryingToReleaseAnXsdInvalidNorm() throws Exception { var announcement = Announcement.builder().eli(amendingNorm.getExpressionEli()).build(); - normRepository.save(NormMapper.mapToDto(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); announcementRepository.save(AnnouncementMapper.mapToDto(announcement)); - normRepository.save(NormMapper.mapToDto(affectedNorm)); - normRepository.save(NormMapper.mapToDto(affectedNormZf0)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNormZf0)); // When // Then // Request is refused @@ -489,21 +492,21 @@ void failsWhenTryingToReleaseAnXsdInvalidNorm() throws Exception { .andExpect(jsonPath("type", equalTo("/errors/ldml-de-not-valid"))); // Content of the DB should be unchanged = 3 sample norms, all unpublished - assertThat(normRepository.findAll()).hasSize(3); + assertThat(dokumentRepository.findAll()).hasSize(3); assertThat( - normRepository.findByEliDokumentManifestation( + dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/2022-08-23/regelungstext-1.xml" ) ) .isNotEmpty(); assertThat( - normRepository.findByEliDokumentManifestation( + dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/1964-08-05/regelungstext-1.xml" ) ) .isNotEmpty(); - var originalNormWithPassiveMods = normRepository.findByEliDokumentManifestation( + var originalNormWithPassiveMods = dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/2022-08-23/regelungstext-1.xml" ); @@ -520,10 +523,10 @@ void failsWhenTryingToReleaseASchematronInvalidNorm() throws Exception { var affectedNormZf0 = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml"); var announcement = Announcement.builder().eli(amendingNorm.getExpressionEli()).build(); - normRepository.save(NormMapper.mapToDto(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); announcementRepository.save(AnnouncementMapper.mapToDto(announcement)); - normRepository.save(NormMapper.mapToDto(affectedNorm)); - normRepository.save(NormMapper.mapToDto(affectedNormZf0)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNormZf0)); // When // Then // Request is refused @@ -538,21 +541,21 @@ void failsWhenTryingToReleaseASchematronInvalidNorm() throws Exception { .andExpect(jsonPath("type", equalTo("/errors/ldml-de-not-schematron-valid"))); // Content of the DB should be unchanged = 3 sample norms, all unpublished - assertThat(normRepository.findAll()).hasSize(3); + assertThat(dokumentRepository.findAll()).hasSize(3); assertThat( - normRepository.findByEliDokumentManifestation( + dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/2022-08-23/regelungstext-1.xml" ) ) .isNotEmpty(); assertThat( - normRepository.findByEliDokumentManifestation( + dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/1964-08-05/regelungstext-1.xml" ) ) .isNotEmpty(); assertThat( - normRepository.findByEliDokumentManifestation( + dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/2022-08-23/regelungstext-1.xml" ) ) @@ -569,7 +572,7 @@ void itCreatesANewAnnouncement() throws Exception { var norm = Fixtures.loadNormFromDisk("NormWithMods.xml"); var affectedNorm = Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); var xmlContent = XmlMapper.toString(norm.getDocument()); var file = new MockMultipartFile( @@ -589,7 +592,7 @@ void itCreatesANewAnnouncement() throws Exception { // Assert ZF0 was created assertThat( - normRepository.findByEliDokumentManifestation( + dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/%s/regelungstext-1.xml".formatted( LocalDate.now().toString() ) @@ -676,8 +679,8 @@ void itFailsIfTheNormAlreadyExist() throws Exception { var norm = Fixtures.loadNormFromDisk("NormWithMods.xml"); var affectedNorm = Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(affectedNorm)); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); var xmlContent = XmlMapper.toString(norm.getDocument()); var file = new MockMultipartFile( @@ -704,9 +707,9 @@ void itFailsIfANormWithSameGuidAlreadyExist() throws Exception { var norm = Fixtures.loadNormFromDisk("NormWithQuotedStructureMods.xml"); var affectedNorm = Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructure.xml"); - normRepository.save(NormMapper.mapToDto(affectedNormForNormWithSameGuid)); - normRepository.save(NormMapper.mapToDto(affectedNorm)); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNormForNormWithSameGuid)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); normWithSameGuid.getMeta().getFRBRExpression().setFRBRaliasCurrentVersionId(norm.getGuid()); var xmlContent = XmlMapper.toString(normWithSameGuid.getDocument()); @@ -730,7 +733,7 @@ void itFailsIfTheNormIsInvalid() throws Exception { var norm = Fixtures.loadNormFromDisk("NormWithModsXsdInvalid.xml"); var affectedNorm = Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); var xmlContent = XmlMapper.toString(norm.getDocument()); var file = new MockMultipartFile( @@ -756,7 +759,7 @@ void itFailsIfTheNormIsSchematronInvalid() throws Exception { var norm = Fixtures.loadNormFromDisk("NormWithModsSchematronInvalid.xml"); var affectedNorm = Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); var xmlContent = XmlMapper.toString(norm.getDocument()); var file = new MockMultipartFile( @@ -827,9 +830,9 @@ void ifCreatesAnnouncementWithForce() throws Exception { var affectedNorm = Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml"); // eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/regelungstext-1" var affectedNormZf0 = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml"); // the one for the existing amending norm; eli/bund/bgbl-1/1964/s593/2022-08-23/1/deu/regelungstext-1" - normRepository.save(NormMapper.mapToDto(norm)); - normRepository.save(NormMapper.mapToDto(affectedNorm)); - normRepository.save(NormMapper.mapToDto(affectedNormZf0)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNormZf0)); announcementRepository.save(AnnouncementMapper.mapToDto(announcement)); var xmlContent = XmlMapper.toString(norm.getDocument()); @@ -854,7 +857,7 @@ void ifCreatesAnnouncementWithForce() throws Exception { // Assert ZF0 was created assertThat( - normRepository.findByEliDokumentManifestation( + dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/%s/regelungstext-1.xml".formatted( LocalDate.now().toString() ) @@ -864,7 +867,7 @@ void ifCreatesAnnouncementWithForce() throws Exception { // Assert old ZF0 was deleted assertThat( - normRepository.findByEliDokumentManifestation( + dokumentRepository.findByEliDokumentManifestation( "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/2022-08-23/regelungstext-1.xml" ) ) diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ArticleControllerIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ArticleControllerIntegrationTest.java index 85451c354..079c553bc 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ArticleControllerIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ArticleControllerIntegrationTest.java @@ -6,7 +6,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.NormMapper; -import de.bund.digitalservice.ris.norms.adapter.output.database.repository.NormRepository; +import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository; 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.Regelungstext; @@ -29,11 +29,11 @@ class ArticleControllerIntegrationTest extends BaseIntegrationTest { private MockMvc mockMvc; @Autowired - private NormRepository normRepository; + private DokumentRepository dokumentRepository; @AfterEach void cleanUp() { - normRepository.deleteAll(); + dokumentRepository.deleteAll(); } @Nested @@ -42,12 +42,14 @@ class getArticles { @Test void itReturnsArticles() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); // When // Then @@ -74,7 +76,7 @@ void itReturnsArticles() throws Exception { void itReturnsArticlesFilteredByAmendedAt() throws Exception { // Given var affectedNorm = Fixtures.loadNormFromDisk("NormWithMultiplePassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); // When // Then mockMvc @@ -96,7 +98,7 @@ void itReturnsArticlesFilteredByAmendedBy() throws Exception { var affectedNorm = Fixtures.loadNormFromDisk( "NormWithPassiveModificationsInDifferentArticles.xml" ); - normRepository.save(NormMapper.mapToDto(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); // When // Then mockMvc @@ -116,7 +118,7 @@ void itReturnsArticlesFilteredByAmendedBy() throws Exception { void itReturnsEmptyListWhenTheNormHasNoArticles() throws Exception { // Given var affectedNorm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - normRepository.save(NormMapper.mapToDto(affectedNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(affectedNorm)); // When // Then mockMvc @@ -132,7 +134,7 @@ void itReturnsEmptyListWhenTheNormHasNoArticles() throws Exception { void itReturnsEmptyListIfAmendedByIsNotFound() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithMultiplePassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When / Then mockMvc @@ -150,7 +152,7 @@ void itReturnsEmptyListIfAmendedByIsNotFound() throws Exception { void itReturnsEmptyListIfAmendedAtIsNotFound() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithMultiplePassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When / Then mockMvc @@ -206,7 +208,7 @@ void itReturnsTheXmlOfArticles() throws Exception { // Given var amendingNorm = Fixtures.loadNormFromDisk("NormWithMods.xml"); - normRepository.save(NormMapper.mapToDto(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); // When // Then mockMvc .perform( @@ -244,7 +246,7 @@ void itReturnsTheXmlOfTheArticleInkrafttreten() throws Exception { // Given var amendingNorm = Fixtures.loadNormFromDisk("NormWithMods.xml"); - normRepository.save(NormMapper.mapToDto(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); // When // Then mockMvc @@ -321,7 +323,7 @@ void itReturnsNotFoundIfNoArticleOfTypeExist() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When // Then mockMvc @@ -358,7 +360,7 @@ void itReturnsNotFoundIfTheNormHasNoArticles() throws Exception { // Given var amendingNorm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - normRepository.save(NormMapper.mapToDto(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); // When // Then mockMvc @@ -398,12 +400,14 @@ class getArticle { void itReturnsArticle() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); // When // Then @@ -459,7 +463,9 @@ void itReturnsNothingIfNormDoesNotExist() throws Exception { @Test void itReturnsNothingIfArticleDoesNotExist() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) + ); // When // Then mockMvc @@ -500,7 +506,7 @@ void itReturnsArticleRender() throws Exception { // Given var amendingNorm = Fixtures.loadNormFromDisk("NormWithMods.xml"); - normRepository.save(NormMapper.mapToDto(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); // When // Then mockMvc @@ -524,8 +530,8 @@ void itReturnsArticleRenderAtIsoDate() throws Exception { var amendingNorm = Fixtures.loadNormFromDisk("NormWithMultipleMods.xml"); var targetNorm = Fixtures.loadNormFromDisk("NormWithMultiplePassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(amendingNorm)); - normRepository.save(NormMapper.mapToDto(targetNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(targetNorm)); // When / Then mockMvc @@ -605,8 +611,8 @@ void itReturnsNotFoundIfArticleDoesntExist() throws Exception { var amendingNorm = Fixtures.loadNormFromDisk("NormWithMultipleMods.xml"); var targetNorm = Fixtures.loadNormFromDisk("NormWithMultiplePassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(amendingNorm)); - normRepository.save(NormMapper.mapToDto(targetNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(targetNorm)); // When / Then mockMvc @@ -714,8 +720,8 @@ void itThrowsValidationExceptionBecauseWithinTimeMachineMetaModDoesNotHaveSource ) .build(); final Norm amendingNorm = Fixtures.loadNormFromDisk("NormWithMods.xml"); - normRepository.save(NormMapper.mapToDto(amendingNorm)); - normRepository.save(NormMapper.mapToDto(targetNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(targetNorm)); // When / Then mockMvc @@ -818,8 +824,8 @@ void itThrowsMandatoryNodeNotFoundBecauseTemporalDataMissing() throws Exception ) .build(); final Norm amendingNorm = Fixtures.loadNormFromDisk("NormWithMods.xml"); - normRepository.save(NormMapper.mapToDto(amendingNorm)); - normRepository.save(NormMapper.mapToDto(targetNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(targetNorm)); // When / Then mockMvc diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ElementControllerIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ElementControllerIntegrationTest.java index b7ef877b8..b751806ce 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ElementControllerIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ElementControllerIntegrationTest.java @@ -6,7 +6,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.NormMapper; -import de.bund.digitalservice.ris.norms.adapter.output.database.repository.NormRepository; +import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository; import de.bund.digitalservice.ris.norms.domain.entity.Fixtures; import de.bund.digitalservice.ris.norms.integration.BaseIntegrationTest; import org.junit.jupiter.api.AfterEach; @@ -24,11 +24,11 @@ class ElementControllerIntegrationTest extends BaseIntegrationTest { private MockMvc mockMvc; @Autowired - private NormRepository normRepository; + private DokumentRepository dokumentRepository; @AfterEach void cleanUp() { - normRepository.deleteAll(); + dokumentRepository.deleteAll(); } @Nested @@ -74,7 +74,7 @@ void returnsNotFoundIfNormNotFoundByEli() throws Exception { void returnsNotFoundIfElementNotFoundByEid() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithMultipleMods.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When mockMvc @@ -111,7 +111,7 @@ void returnsNotFoundIfElementNotFoundByEid() throws Exception { void returnsElementRenderedAsHtml() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithMultipleMods.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When mockMvc @@ -132,8 +132,8 @@ void returnsElementAtGivenIsoDateRenderedAsHtml() throws Exception { var amendingNorm = Fixtures.loadNormFromDisk("NormWithMultipleMods.xml"); var targetNorm = Fixtures.loadNormFromDisk("NormWithMultiplePassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(amendingNorm)); - normRepository.save(NormMapper.mapToDto(targetNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(targetNorm)); // When / Then mockMvc @@ -218,7 +218,7 @@ void returnsNotFoundIfNormNotFoundByEli() throws Exception { void returnsNotFoundIfElementNotFoundByEid() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithMultipleMods.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When mockMvc @@ -255,7 +255,7 @@ void returnsNotFoundIfElementNotFoundByEid() throws Exception { void returnElementEidTitleAndType() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithMultipleMods.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When mockMvc @@ -368,7 +368,7 @@ void itReturnsNotFoundIfNormIsNotFound() throws Exception { void itReturnsEmptyListIfNoMatchingElementsAreFound() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithMultipleMods.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When mockMvc @@ -386,7 +386,7 @@ void itReturnsEmptyListIfNoMatchingElementsAreFound() throws Exception { void itReturnsEntriesWithPrefacePreambleArticleAndConclusionInformation() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithPrefacePreambleAndConclusions.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); var url = "/api/v1/norms/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/elements" + "?type=preface" + @@ -426,7 +426,7 @@ void itReturnsEntriesWithBookPartChapterTitleSubtitleSectionAndSubsectionInforma throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithGliederung.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); var url = "/api/v1/norms/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/elements" + "?type=book" + @@ -491,9 +491,9 @@ void itReturnsEntriesWithBookPartChapterTitleSubtitleSectionAndSubsectionInforma void itReturnsAnEmptyListIfNoElementIsAffectedByTheGivenAmendingLaw() throws Exception { // Given var targetNorm = Fixtures.loadNormFromDisk("NormWithMultiplePassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(targetNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(targetNorm)); var amendingNorm = Fixtures.loadNormFromDisk("NormWithPrefacePreambleAndConclusions.xml"); - normRepository.save(NormMapper.mapToDto(amendingNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(amendingNorm)); var url = "/api/v1/norms/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/elements" + @@ -517,7 +517,7 @@ void itReturnsOnlyTheElementsMatchingTheGivenAmendingLaw() throws Exception { var targetNorm = Fixtures.loadNormFromDisk( "NormWithPassiveModificationsInDifferentArticles.xml" ); - normRepository.save(NormMapper.mapToDto(targetNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(targetNorm)); var url = "/api/v1/norms/eli/bund/bgbl-1/1990/s2954/2022-12-19/1/deu/regelungstext-1/elements" + diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/NormExpressionControllerIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/NormExpressionControllerIntegrationTest.java index 153147c36..acf8017a3 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/NormExpressionControllerIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/NormExpressionControllerIntegrationTest.java @@ -7,7 +7,7 @@ import de.bund.digitalservice.ris.norms.XmlMatcher; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.NormMapper; -import de.bund.digitalservice.ris.norms.adapter.output.database.repository.NormRepository; +import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository; import de.bund.digitalservice.ris.norms.domain.entity.Fixtures; import de.bund.digitalservice.ris.norms.domain.entity.Href; import de.bund.digitalservice.ris.norms.domain.entity.Norm; @@ -33,11 +33,11 @@ class NormExpressionControllerIntegrationTest extends BaseIntegrationTest { private MockMvc mockMvc; @Autowired - private NormRepository normRepository; + private DokumentRepository dokumentRepository; @AfterEach void cleanUp() { - normRepository.deleteAll(); + dokumentRepository.deleteAll(); } @Nested @@ -48,7 +48,9 @@ class GetNormByEli { @Test void itCallsNormsServiceAndReturnsNorm() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("Vereinsgesetz.xml"))); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("Vereinsgesetz.xml")) + ); // When // Then mockMvc @@ -69,7 +71,9 @@ void itCallsNormsServiceAndReturnsNorm() throws Exception { @Test void itCallsNormsServiceAndReturnsNormXml() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("Vereinsgesetz.xml"))); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("Vereinsgesetz.xml")) + ); // When // Then mockMvc @@ -87,8 +91,8 @@ void itCallsNormsServiceAndReturnsNormXml() throws Exception { @Test void itCallsNormServiceAndReturnsNormRender() throws Exception { // Given - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("Vereinsgesetz_2017_s419_2017-03-15.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("Vereinsgesetz_2017_s419_2017-03-15.xml")) ); // When // Then @@ -118,7 +122,9 @@ class GetNormRenderWithQueryParameters { @Test void itCallsNormServiceAndReturnsNormRenderWithMetadata() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) + ); // When // Then mockMvc @@ -152,7 +158,7 @@ void itCallsNormServiceAndReturnsNormRenderWithMetadata() throws Exception { @Test void itReturnsBadRequestWhenRenderingAtInvalidIsoDate() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); + dokumentRepository.saveAll(NormMapper.mapToDtos(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); // When // Then mockMvc @@ -176,7 +182,7 @@ void itReturnsBadRequestWhenRenderingAtInvalidIsoDate() throws Exception { @Test void itReturnsHtmlWhenRenderingAtValidTimeBoundary() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); + dokumentRepository.saveAll(NormMapper.mapToDtos(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); // When // Then mockMvc @@ -231,7 +237,7 @@ void itReturnsNormNotFound() throws Exception { @Test void itThrowsInvalidUpdateExceptionBecauseEliChanged() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); + dokumentRepository.saveAll(NormMapper.mapToDtos(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); var newXml = """ @@ -289,7 +295,7 @@ void itThrowsInvalidUpdateExceptionBecauseEliChanged() throws Exception { @Test void itThrowsInvalidUpdateExceptionBecauseGuidChanged() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); + dokumentRepository.saveAll(NormMapper.mapToDtos(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); var newXml = """ @@ -347,7 +353,7 @@ void itThrowsInvalidUpdateExceptionBecauseGuidChanged() throws Exception { @Test void itCallsNormServiceAndUpdatesNorm() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); + dokumentRepository.saveAll(NormMapper.mapToDtos(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); var newXml = """ @@ -434,7 +440,7 @@ class GetNormTimeBoundaries { void itExtractsAndReturnsTimeBoundariesFromNorm() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithMods.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When // Then mockMvc @@ -515,7 +521,7 @@ void itExtractsAndReturnsTimeBoundariesFromNormWhenDateIsEmpty() throws Exceptio .builder() .regelungstexte(Set.of(new Regelungstext(XmlMapper.toDocument(xml)))) .build(); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When // Then mockMvc @@ -580,7 +586,9 @@ void itReturns404NotFound() throws Exception { @Test void itThrowsValidationExceptionBecauseDestinationHrefHasNoEli() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) + ); final String eli = "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1"; final String destinationHref = "#destination-href-without-eli"; @@ -625,12 +633,14 @@ void itThrowsValidationExceptionBecauseDestinationHrefHasNoEli() throws Exceptio @Test void itThrowsValidationExceptionBecauseModWithGivenEidNotFound() throws Exception { - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); final String eli = "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1"; @@ -676,12 +686,14 @@ void itThrowsValidationExceptionBecauseModWithGivenEidNotFound() throws Exceptio @ValueSource(strings = { "", "?dryRun=true" }) void itUpdatesAQuotedTextMod(String queryParameters) throws Exception { // When - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); String path = @@ -785,11 +797,11 @@ void itUpdatesAQuotedTextMod(String queryParameters) throws Exception { @Test void itUpdatesAQuotedTextModBasedOnPreviousChange() throws Exception { // When - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithModsSameTarget.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithModsSameTarget.xml")) ); - normRepository.save( - NormMapper.mapToDto( + dokumentRepository.saveAll( + NormMapper.mapToDtos( Fixtures.loadNormFromDisk("NormWithoutPassiveModificationsSameTarget.xml") ) ); @@ -895,14 +907,14 @@ void itUpdatesAQuotedTextModBasedOnPreviousChange() throws Exception { @Test void itUpdatesAQuotedStructureMod() throws Exception { // When - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithQuotedStructureMods.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithQuotedStructureMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructure.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructure.xml")) ); String refersTo = "THIS_IS_NOT_BEING_HANDLED"; @@ -995,14 +1007,14 @@ void itUpdatesAQuotedStructureMod() throws Exception { @Test void itUpdatesAQuotedStructureModFromRefToRref() throws Exception { // When - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithQuotedStructureMods.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithQuotedStructureMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructure.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructure.xml")) ); String refersTo = "THIS_IS_NOT_BEING_HANDLED"; @@ -1107,19 +1119,19 @@ void itUpdatesAQuotedStructureModFromRefToRref() throws Exception { @Test void itUpdatesAQuotedStructureModFromRrefToRef() throws Exception { // When - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithQuotedStructureModsAndUpTo.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithQuotedStructureModsAndUpTo.xml")) ); - normRepository.save( - NormMapper.mapToDto( + dokumentRepository.saveAll( + NormMapper.mapToDtos( Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructureAndUpTo.xml") ) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) ); - normRepository.save( - NormMapper.mapToDto( + dokumentRepository.saveAll( + NormMapper.mapToDtos( Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructureAndUpTo.xml") ) ); @@ -1192,12 +1204,14 @@ void itUpdatesAQuotedStructureModFromRrefToRef() throws Exception { @Test void itThrowsValidationExceptionBecauseCharacterRangeNotPresent() throws Exception { // When - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); String path = @@ -1262,12 +1276,14 @@ void itThrowsValidationExceptionBecauseCharacterRangeNotPresent() throws Excepti @Test void itThrowsValidationExceptionBecauseCharacterRangeHasInvalidFormat() throws Exception { // When - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); String path = @@ -1330,12 +1346,14 @@ void itThrowsValidationExceptionBecauseCharacterRangeHasInvalidFormat() throws E void itThrowsValidationExceptionBecauseCharacterRangeDoesNotResolveToTargetText() throws Exception { // When - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); String path = @@ -1397,12 +1415,14 @@ void itThrowsValidationExceptionBecauseCharacterRangeDoesNotResolveToTargetText( @Test void itThrowsValidationExceptionBecauseCharacterRangeNotWithinNodeRange() throws Exception { // When - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); String path = @@ -1465,12 +1485,14 @@ void itThrowsValidationExceptionBecauseCharacterRangeNotWithinNodeRange() throws @Test void itThrowsValidationExceptionBecauseTargetNodeNotPresent() throws Exception { // When - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); String path = @@ -1535,14 +1557,14 @@ void itThrowsValidationExceptionBecauseTargetNodeNotPresent() throws Exception { @Test void itThrowsValidationExceptionBecauseTargetUptoNodeNotPresent() throws Exception { // When - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithQuotedStructureMods.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithQuotedStructureMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructure.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructure.xml")) ); String refersTo = "THIS_IS_NOT_BEING_HANDLED"; @@ -1609,14 +1631,14 @@ void itThrowsValidationExceptionBecauseTargetUptoNodeNotPresent() throws Excepti @Test void itThrowsValidationExceptionBecauseTargetNodeAndUptoNodeNotSiblings() throws Exception { // When - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithQuotedStructureMods.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithQuotedStructureMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructure.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructure.xml")) ); String refersTo = "THIS_IS_NOT_BEING_HANDLED"; @@ -1684,14 +1706,14 @@ void itThrowsValidationExceptionBecauseTargetNodeAndUptoNodeNotSiblings() throws @Test void itThrowsValidationExceptionBecauseTargetNodeAfterUptoNode() throws Exception { // When - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithQuotedStructureMods.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithQuotedStructureMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModsQuotedStructure.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructure.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModsQuotedStructure.xml")) ); String refersTo = "THIS_IS_NOT_BEING_HANDLED"; @@ -1805,7 +1827,9 @@ void itReturnsNormNotFoundAsEliNotFound() throws Exception { @Test void itThrowsInvalidUpdateExceptionBecauseModEidNotInAmendingLaw() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) + ); final String eli = "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1"; // When @@ -1847,7 +1871,7 @@ void itThrowsInvalidateUpdateExceptionBecauseTargetHrefWithoutEli() throws Excep ) .findFirst() .ifPresent(mod -> mod.setTargetRefHref(new Href("#href-without-eli"))); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); final String eli = "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1"; @@ -1898,7 +1922,7 @@ void itThrowsInvalidateUpdateExceptionBecauseModsWithoutSameTarget() throws Exce ) ) ); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); final String eli = "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1"; @@ -1931,12 +1955,14 @@ void itThrowsInvalidateUpdateExceptionBecauseModsWithoutSameTarget() throws Exce @Test void itUpdatesASingleMod() throws Exception { // When - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); // When @@ -2057,11 +2083,11 @@ void itUpdatesASingleMod() throws Exception { @Test void itUpdatesMultipleMods() throws Exception { // When - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMultipleSimpleMods.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMultipleSimpleMods.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMultipleSimpleModsTargetNorm.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMultipleSimpleModsTargetNorm.xml")) ); // When @@ -2153,12 +2179,14 @@ void itUpdatesMultipleMods() throws Exception { @Test void itDryRunsTheUpdate() throws Exception { // When - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); // When @@ -2221,12 +2249,14 @@ void itDryRunsTheUpdate() throws Exception { @Test void itReturnsBadRequestAndDoesNotSaveIt() throws Exception { // When - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml"))); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) + ); + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) ); - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml")) ); // When (the eid does not exist) diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/NormManifestationControllerIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/NormManifestationControllerIntegrationTest.java index 9e1260136..0401676f3 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/NormManifestationControllerIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/NormManifestationControllerIntegrationTest.java @@ -4,7 +4,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.NormMapper; -import de.bund.digitalservice.ris.norms.adapter.output.database.repository.NormRepository; +import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository; import de.bund.digitalservice.ris.norms.domain.entity.Fixtures; import de.bund.digitalservice.ris.norms.integration.BaseIntegrationTest; import org.junit.jupiter.api.AfterEach; @@ -22,11 +22,11 @@ public class NormManifestationControllerIntegrationTest extends BaseIntegrationT private MockMvc mockMvc; @Autowired - private NormRepository normRepository; + private DokumentRepository dokumentRepository; @AfterEach void cleanUp() { - normRepository.deleteAll(); + dokumentRepository.deleteAll(); } @Nested @@ -35,7 +35,7 @@ class getNormManifestationXml { @Test void itCallsNormServiceAndReturnsNormXml() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); + dokumentRepository.saveAll(NormMapper.mapToDtos(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); var eli = "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/1964-08-05/regelungstext-1.xml"; // When // Then @@ -78,7 +78,7 @@ void itReturnsNotFoundIfManifestationDoesntExist() throws Exception { @Test void itReturnsNotFoundIfTypeIsNotXml() throws Exception { // Given - normRepository.save(NormMapper.mapToDto(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); + dokumentRepository.saveAll(NormMapper.mapToDtos(Fixtures.loadNormFromDisk("SimpleNorm.xml"))); var eli = "eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/1964-08-05/regelungstext-1.pdf"; // When // Then diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ProprietaryControllerIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ProprietaryControllerIntegrationTest.java index f7c56d7a4..0410c4235 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ProprietaryControllerIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/ProprietaryControllerIntegrationTest.java @@ -6,9 +6,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.NormMapper; -import de.bund.digitalservice.ris.norms.adapter.output.database.repository.NormRepository; +import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.RegelungstextMapper; +import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository; 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.Regelungstext; import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli; import de.bund.digitalservice.ris.norms.integration.BaseIntegrationTest; import java.time.LocalDate; @@ -27,11 +29,11 @@ public class ProprietaryControllerIntegrationTest extends BaseIntegrationTest { private MockMvc mockMvc; @Autowired - private NormRepository normRepository; + private DokumentRepository dokumentRepository; @AfterEach void cleanUp() { - normRepository.deleteAll(); + dokumentRepository.deleteAll(); } @Nested @@ -81,7 +83,7 @@ void returnEmptyValuesIfNormHasNoProprietaryAtAll() throws Exception { ); var atDateString = "2024-06-03"; var norm = Fixtures.loadNormFromDisk("NormWithoutProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when mockMvc @@ -111,7 +113,7 @@ void returnEmptyValuesIfInvalidProprietaryDoesNotContainThem() throws Exception ); var atDateString = "2024-06-03"; var norm = Fixtures.loadNormFromDisk("NormWithInvalidProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when mockMvc @@ -141,7 +143,7 @@ void returnProprietary() throws Exception { ); var atDateString = "2024-06-03"; var norm = Fixtures.loadNormFromDisk("NormWithProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when mockMvc @@ -220,7 +222,7 @@ void updatesAll() throws Exception { final String eli = "eli/bund/bgbl-1/2002/s1181/2019-11-22/1/deu/rechtsetzungsdokument-1"; final LocalDate date = LocalDate.parse("1990-01-01"); final Norm norm = Fixtures.loadNormFromDisk("NormWithProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when mockMvc @@ -255,29 +257,41 @@ void updatesAll() throws Exception { .andExpect(jsonPath("ressort").value("Bundesministerium der Magie")) .andExpect(jsonPath("organisationsEinheit").value("Andere Organisationseinheit")); - final Norm normLoaded = NormMapper.mapToDomain( - normRepository + final Regelungstext regelungstextLoaded = RegelungstextMapper.mapToDomain( + dokumentRepository .findFirstByEliDokumentExpressionOrderByEliDokumentManifestationDesc(eli) .get() ); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getFna(date)).contains("new-fna"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArt(date)).contains("new-art"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getTyp(date)).contains("new-typ"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getFna(date)) + .contains("new-fna"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArt(date)) + .contains("new-art"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getTyp(date)) + .contains("new-typ"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)) .contains("new-subtyp"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date) + ) .contains("new-bezeichnungInVorlage"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)) .contains("ÄN,ÜN"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getStaat(date)).contains("DDR"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getStaat(date)) + .contains("DDR"); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date) + ) .contains("LT"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date) + ) .contains(false); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getRessort(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getRessort(date)) .contains("Bundesministerium der Magie"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date) + ) .contains("Andere Organisationseinheit"); } @@ -287,7 +301,7 @@ void doesResetAllFieldsBySendingNullAndGetSomeDefaults() throws Exception { final String eli = "eli/bund/bgbl-1/2002/s1181/2019-11-22/1/deu/rechtsetzungsdokument-1"; final LocalDate date = LocalDate.parse("1990-01-01"); final Norm norm = Fixtures.loadNormFromDisk("NormWithProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when @@ -323,27 +337,38 @@ void doesResetAllFieldsBySendingNullAndGetSomeDefaults() throws Exception { .andExpect(jsonPath("ressort").isEmpty()) .andExpect(jsonPath("organisationsEinheit").isEmpty()); - final Norm normLoaded = NormMapper.mapToDomain( - normRepository + final Regelungstext regelungstextLoaded = RegelungstextMapper.mapToDomain( + dokumentRepository .findFirstByEliDokumentExpressionOrderByEliDokumentManifestationDesc(eli) .get() ); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getFna(date)).contains("754-28-1"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArt(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getFna(date)) + .contains("754-28-1"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArt(date)) .contains("rechtsetzungsdokument"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getTyp(date)).contains("gesetz"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getTyp(date)) + .contains("gesetz"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)).isEmpty(); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date) + ) .isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getStaat(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)) .isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getStaat(date)).isEmpty(); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date) + ) .isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getRessort(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date) + ) + .isEmpty(); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getRessort(date)).isEmpty(); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date) + ) .isEmpty(); } @@ -353,7 +378,7 @@ void doesResetAllFieldsBySendingEmptyStringAndGetSomeDefaults() throws Exception final String eli = "eli/bund/bgbl-1/2002/s1181/2019-11-22/1/deu/rechtsetzungsdokument-1"; final LocalDate date = LocalDate.parse("1990-01-01"); final Norm norm = Fixtures.loadNormFromDisk("NormWithProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when @@ -389,27 +414,38 @@ void doesResetAllFieldsBySendingEmptyStringAndGetSomeDefaults() throws Exception .andExpect(jsonPath("ressort").isEmpty()) .andExpect(jsonPath("organisationsEinheit").isEmpty()); - final Norm normLoaded = NormMapper.mapToDomain( - normRepository + final Regelungstext regelungstextLoaded = RegelungstextMapper.mapToDomain( + dokumentRepository .findFirstByEliDokumentExpressionOrderByEliDokumentManifestationDesc(eli) .get() ); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getFna(date)).contains("754-28-1"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArt(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getFna(date)) + .contains("754-28-1"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArt(date)) .contains("rechtsetzungsdokument"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getTyp(date)).contains("gesetz"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getTyp(date)) + .contains("gesetz"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)).isEmpty(); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date) + ) + .isEmpty(); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)) .isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getStaat(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getStaat(date)).isEmpty(); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date) + ) .isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date) + ) .isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getRessort(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getRessort(date)).isEmpty(); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date) + ) .isEmpty(); } @@ -419,7 +455,7 @@ void updatesProprietaryByCreatingNewMetadatenDsNodes() throws Exception { final String eli = "eli/bund/bgbl-1/2002/s1181/2019-11-22/1/deu/rechtsetzungsdokument-1"; final LocalDate date = LocalDate.parse("2003-01-01"); final Norm norm = Fixtures.loadNormFromDisk("NormWithProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when mockMvc @@ -455,28 +491,41 @@ void updatesProprietaryByCreatingNewMetadatenDsNodes() throws Exception { .andExpect(jsonPath("organisationsEinheit").value("andere org einheit")); // then - final Norm normLoaded = NormMapper.mapToDomain( - normRepository + final Regelungstext regelungstextLoaded = RegelungstextMapper.mapToDomain( + dokumentRepository .findFirstByEliDokumentExpressionOrderByEliDokumentManifestationDesc(eli) .get() ); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getFna(date)).contains("fna"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArt(date)).contains("art"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getTyp(date)).contains("typ"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)).contains("subtype"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getFna(date)) + .contains("fna"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArt(date)) + .contains("art"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getTyp(date)) + .contains("typ"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)) + .contains("subtype"); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date) + ) .contains("bezeichnungInVorlage"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)) .contains("ÄN,ÜN"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getStaat(date)).contains("DDR"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getStaat(date)) + .contains("DDR"); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date) + ) .contains("Landtag"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date) + ) .contains(false); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getRessort(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getRessort(date)) .contains("BMJ - Bundesministerium der Justiz"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date) + ) .contains("andere org einheit"); } @@ -486,7 +535,7 @@ void updatesProprietaryByCreatingNewProprietaryAndMetadatenDsNodes() throws Exce final String eli = "eli/bund/bgbl-1/2002/s1181/2019-11-22/1/deu/rechtsetzungsdokument-1"; final LocalDate date = LocalDate.parse("2003-01-01"); final Norm norm = Fixtures.loadNormFromDisk("NormWithProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when mockMvc @@ -522,27 +571,38 @@ void updatesProprietaryByCreatingNewProprietaryAndMetadatenDsNodes() throws Exce .andExpect(jsonPath("organisationsEinheit").isEmpty()); // then - final Norm normLoaded = NormMapper.mapToDomain( - normRepository + final Regelungstext regelungstextLoaded = RegelungstextMapper.mapToDomain( + dokumentRepository .findFirstByEliDokumentExpressionOrderByEliDokumentManifestationDesc(eli) .get() ); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getFna(date)).contains("fna"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArt(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getFna(date)) + .contains("fna"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArt(date)) .contains("rechtsetzungsdokument"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getTyp(date)).contains("gesetz"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getTyp(date)) + .contains("gesetz"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)).isEmpty(); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date) + ) + .isEmpty(); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)) .isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getStaat(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getStaat(date)).isEmpty(); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date) + ) .isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date) + ) .isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getRessort(date)).isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getRessort(date)).isEmpty(); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date) + ) .isEmpty(); } @@ -554,7 +614,7 @@ void doesRemoveQualifizierteMehrheitFromBeschliessendesOrganWhenNull() throws Ex final Norm norm = Fixtures.loadNormFromDisk( "NormWithProprietaryAndMultipleTimeBoundaries.xml" ); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when @@ -590,27 +650,39 @@ void doesRemoveQualifizierteMehrheitFromBeschliessendesOrganWhenNull() throws Ex .andExpect(jsonPath("qualifizierteMehrheit").isEmpty()) // meaning json "qualifizierteMehrheit":null .andExpect(jsonPath("organisationsEinheit").value("Andere Organisationseinheit")); - final Norm normLoaded = NormMapper.mapToDomain( - normRepository + final Regelungstext regelungstextLoaded = RegelungstextMapper.mapToDomain( + dokumentRepository .findFirstByEliDokumentExpressionOrderByEliDokumentManifestationDesc(eli) .get() ); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getFna(date)).contains("new-fna"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArt(date)).contains("new-art"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getTyp(date)).contains("new-typ"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getFna(date)) + .contains("new-fna"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArt(date)) + .contains("new-art"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getTyp(date)) + .contains("new-typ"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)) .contains("new-subtyp"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date) + ) .contains("new-bezeichnungInVorlage"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)) .contains("ÄN,ÜN"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getStaat(date)).contains("DDR"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getStaat(date)) + .contains("DDR"); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date) + ) .isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date) + ) .isEmpty(); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date) + ) .contains("Andere Organisationseinheit"); } @@ -620,7 +692,7 @@ void createsProprietaryAndMetadatenDsAndUpdatesFna() throws Exception { final String eli = "eli/bund/bgbl-1/2002/s1181/2019-11-22/1/deu/rechtsetzungsdokument-1"; final LocalDate date = LocalDate.parse("1990-01-01"); final Norm norm = Fixtures.loadNormFromDisk("NormWithoutProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when mockMvc @@ -653,27 +725,39 @@ void createsProprietaryAndMetadatenDsAndUpdatesFna() throws Exception { .andExpect(jsonPath("qualifizierteMehrheit").value(true)) .andExpect(jsonPath("organisationsEinheit").value("Organisationseinheit")); - final Norm normLoaded = NormMapper.mapToDomain( - normRepository + final Regelungstext regelungstextLoaded = RegelungstextMapper.mapToDomain( + dokumentRepository .findFirstByEliDokumentExpressionOrderByEliDokumentManifestationDesc(eli) .get() ); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getFna(date)).contains("new-fna"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArt(date)).contains("new-art"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getTyp(date)).contains("new-typ"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getFna(date)) + .contains("new-fna"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArt(date)) + .contains("new-art"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getTyp(date)) + .contains("new-typ"); + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getSubtyp(date)) .contains("new-subtyp"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBezeichnungInVorlage(date) + ) .contains("new-bezeichnungInVorlage"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getArtDerNorm(date)) .contains("SN,ÄN,ÜN"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getStaat(date)).contains("DEU"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date)) + assertThat(regelungstextLoaded.getMeta().getOrCreateProprietary().getStaat(date)) + .contains("DEU"); + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getBeschliessendesOrgan(date) + ) .contains("Bundestag"); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getQualifizierteMehrheit(date) + ) .contains(true); - assertThat(normLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date)) + assertThat( + regelungstextLoaded.getMeta().getOrCreateProprietary().getOrganisationsEinheit(date) + ) .contains("Organisationseinheit"); } } @@ -727,7 +811,7 @@ void returnEmptyValuesIfNormHasNoProprietaryAtAll() throws Exception { var eid = "hauptteil-1_abschnitt-0_art-1"; var atDateString = "2024-06-03"; var norm = Fixtures.loadNormFromDisk("NormWithoutProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when mockMvc @@ -749,7 +833,7 @@ void returnEmptyValuesIfInvalidProprietaryDoesNotContainThem() throws Exception var eid = "hauptteil-1_abschnitt-0_art-1"; var atDateString = "2024-06-03"; var norm = Fixtures.loadNormFromDisk("NormWithInvalidProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when mockMvc @@ -771,7 +855,7 @@ void returnProprietaryEinzelelement() throws Exception { var eid = "hauptteil-1_abschnitt-0_art-1"; var atDateString = "2024-06-03"; var norm = Fixtures.loadNormFromDisk("NormWithProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when mockMvc @@ -836,7 +920,7 @@ void createsProprietaryAndMetadatenDsAndEinzelelementAndSetsValue() throws Excep var eid = "hauptteil-1_abschnitt-0_art-1"; var atDateString = "2024-06-03"; var norm = Fixtures.loadNormFromDisk("NormWithoutProprietary.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // when mockMvc diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/RenderingControllerIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/RenderingControllerIntegrationTest.java index e2a177370..9006b1d2f 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/RenderingControllerIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/RenderingControllerIntegrationTest.java @@ -6,7 +6,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import de.bund.digitalservice.ris.norms.adapter.output.database.repository.NormRepository; +import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository; import de.bund.digitalservice.ris.norms.domain.entity.Fixtures; import de.bund.digitalservice.ris.norms.integration.BaseIntegrationTest; import org.junit.jupiter.api.AfterEach; @@ -24,11 +24,11 @@ class RenderingControllerIntegrationTest extends BaseIntegrationTest { private MockMvc mockMvc; @Autowired - private NormRepository normRepository; + private DokumentRepository dokumentRepository; @AfterEach void cleanUp() { - normRepository.deleteAll(); + dokumentRepository.deleteAll(); } @Nested diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/TimeBoundaryControllerIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/TimeBoundaryControllerIntegrationTest.java index 29cb4306a..949cc9eab 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/TimeBoundaryControllerIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/TimeBoundaryControllerIntegrationTest.java @@ -8,7 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.NormMapper; -import de.bund.digitalservice.ris.norms.adapter.output.database.repository.NormRepository; +import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository; 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.Regelungstext; @@ -30,11 +30,11 @@ public class TimeBoundaryControllerIntegrationTest extends BaseIntegrationTest { private MockMvc mockMvc; @Autowired - private NormRepository normRepository; + private DokumentRepository dokumentRepository; @AfterEach void cleanUp() { - normRepository.deleteAll(); + dokumentRepository.deleteAll(); } @Nested @@ -73,7 +73,7 @@ void itCallsGetTimeBoundariesAndReturns404() throws Exception { void itCallsGetTimeBoundariesAndReturnsJson() throws Exception { // Given var norm = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When // Then mockMvc @@ -136,7 +136,7 @@ void itCallsGetTimeBoundariesAmendedByAndReturnsEmpty() throws Exception { var amendedBy = "eli/bund/bgbl-1/2024/81/2024-03-05/1/deu/non-in-norm"; var norm = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When // Then mockMvc @@ -158,7 +158,7 @@ void itCallsGetTimeBoundariesAmendedByAndReturnsJson() throws Exception { var amendedBy = "eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1"; var norm = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When // Then mockMvc @@ -221,7 +221,7 @@ void itCallsPutTimeBoundariesAndReturns404() throws Exception { void itCallsUpdateTimeBoundariesDateNull() throws Exception { // When var norm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // Then mockMvc @@ -250,7 +250,7 @@ void itCallsUpdateTimeBoundariesDateMalformed() throws Exception { // When var norm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // Then mockMvc @@ -278,7 +278,7 @@ void itCallsUpdateTimeBoundariesMultipleSameDates() throws Exception { // When var norm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // Then mockMvc @@ -409,7 +409,7 @@ void itCallsUpdateTimeBoundariesAddAndDeleteAndEdit() throws Exception { .builder() .regelungstexte(Set.of(new Regelungstext(XmlMapper.toDocument(xml)))) .build(); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // Then mockMvc diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/database/DBServiceIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/database/DBServiceIntegrationTest.java index a942277f9..0e7028209 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/database/DBServiceIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/database/DBServiceIntegrationTest.java @@ -3,15 +3,15 @@ import static org.assertj.core.api.Assertions.assertThat; import de.bund.digitalservice.ris.norms.adapter.output.database.dto.AnnouncementDto; -import de.bund.digitalservice.ris.norms.adapter.output.database.dto.NormDto; +import de.bund.digitalservice.ris.norms.adapter.output.database.dto.DokumentDto; import de.bund.digitalservice.ris.norms.adapter.output.database.dto.ReleaseDto; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.AnnouncementMapper; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.MigrationLogMapper; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.NormMapper; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.ReleaseMapper; import de.bund.digitalservice.ris.norms.adapter.output.database.repository.AnnouncementRepository; +import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository; import de.bund.digitalservice.ris.norms.adapter.output.database.repository.MigrationLogRepository; -import de.bund.digitalservice.ris.norms.adapter.output.database.repository.NormRepository; import de.bund.digitalservice.ris.norms.adapter.output.database.repository.ReleaseRepository; import de.bund.digitalservice.ris.norms.adapter.output.database.service.DBService; import de.bund.digitalservice.ris.norms.application.port.output.*; @@ -41,7 +41,7 @@ class DBServiceIntegrationTest extends BaseIntegrationTest { private AnnouncementRepository announcementRepository; @Autowired - private NormRepository normRepository; + private DokumentRepository dokumentRepository; @Autowired private ReleaseRepository releaseRepository; @@ -53,7 +53,7 @@ class DBServiceIntegrationTest extends BaseIntegrationTest { void cleanUp() { announcementRepository.deleteAll(); releaseRepository.deleteAll(); - normRepository.deleteAll(); + dokumentRepository.deleteAll(); migrationLogRepository.deleteAll(); } @@ -61,7 +61,7 @@ void cleanUp() { void itFindsNormOnDB() { // Given var norm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When final Optional normOptional = dbService.loadNorm( @@ -80,7 +80,7 @@ void itFindsNormOnDB() { void itFindsNormByManifestationEliWithoutPointInTimeManifestationOnDB() { // Given var norm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When final Optional normOptional = dbService.loadNorm( @@ -99,7 +99,7 @@ void itFindsNormByManifestationEliWithoutPointInTimeManifestationOnDB() { void itFindsNormByManifestationEli() { // Given var norm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When final Optional normOptional = dbService.loadNorm( @@ -117,11 +117,11 @@ void itFindsNormByManifestationEli() { @Test void itFindsNewestManifestationOfNorm() { // Given - normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) + dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithoutPassiveModifications.xml")) ); var norm = Fixtures.loadNormFromDisk("NormWithPassiveModifications.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When final Optional normOptional = dbService.loadNorm( @@ -140,7 +140,7 @@ void itFindsNewestManifestationOfNorm() { void itFindsNormByGuidOnDB() { // When var norm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); // When final Optional normOptional = dbService.loadNormByGuid( @@ -262,7 +262,7 @@ void itUpdatesNorm() { // Given var oldNorm = Fixtures.loadNormFromDisk("NormWithAppliedQuotedStructure.xml"); oldNorm.setPublishState(NormPublishState.UNPUBLISHED); - normRepository.save(NormMapper.mapToDto(oldNorm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(oldNorm)); var newNorm = new Norm(oldNorm); newNorm.setPublishState(NormPublishState.QUEUED_FOR_PUBLISH); @@ -271,7 +271,7 @@ void itUpdatesNorm() { var normFromDatabase = dbService.updateNorm(new UpdateNormPort.Command(newNorm)); // Then - assertThat(normRepository.findAll()).hasSize(1); + assertThat(dokumentRepository.findAll()).hasSize(1); assertThat(normFromDatabase).contains(newNorm); } @@ -335,30 +335,29 @@ void itCreatesNewAnnouncement() { @Test void itFindsReleaseOnDB() { // Given - var norm = normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("SimpleNorm.xml")) - ); - var norm2 = normRepository.save( - NormMapper.mapToDto(Fixtures.loadNormFromDisk("NormWithMods.xml")) + var norm1 = Fixtures.loadNormFromDisk("SimpleNorm.xml"); + var norm1Dtos = dokumentRepository.saveAll(NormMapper.mapToDtos(norm1)); + var norm2Dtos = dokumentRepository.saveAll( + NormMapper.mapToDtos(Fixtures.loadNormFromDisk("NormWithMods.xml")) ); var release1 = releaseRepository.save( ReleaseDto .builder() .releasedAt(Instant.parse("2024-01-01T00:00:00Z")) - .norms(List.of(norm2)) + .norms(norm2Dtos) .build() ); var release2 = releaseRepository.save( ReleaseDto .builder() .releasedAt(Instant.parse("2024-02-01T00:00:00Z")) - .norms(List.of(norm)) + .norms(norm1Dtos) .build() ); announcementRepository.save( AnnouncementDto .builder() - .eli(norm.getEliDokumentExpression()) + .eli(norm1.getExpressionEli().toString()) .releases(List.of(release1, release2)) .build() ); @@ -396,7 +395,7 @@ void itUpdatesAnnouncementAndSavesRelease() { var announcement = Announcement.builder().eli(norm.getExpressionEli()).build(); var release = Release.builder().publishedNorms(List.of(norm)).build(); - normRepository.save(NormMapper.mapToDto(norm)); + dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); announcementRepository.save(AnnouncementMapper.mapToDto(announcement)); // When @@ -433,10 +432,10 @@ void itDeletesQueuedReleases() { var announcement = Announcement.builder().eli(norm.getExpressionEli()).build(); var release = Release.builder().publishedNorms(List.of(norm)).build(); - var normDto = normRepository.save(NormMapper.mapToDto(norm)); + var normDto = dokumentRepository.saveAll(NormMapper.mapToDtos(norm)); var releaseDto = ReleaseMapper.mapToDto(release); - releaseDto.setNorms(List.of(normDto)); + releaseDto.setNorms(normDto); releaseRepository.save(releaseDto); var announcementDto = AnnouncementMapper.mapToDto(announcement); @@ -451,7 +450,7 @@ void itDeletesQueuedReleases() { assertThat(savedAnnouncement).isPresent(); assertThat(savedAnnouncement.get().getReleases()).isEmpty(); - var savedNorm = normRepository.findByEliDokumentManifestation( + var savedNorm = dokumentRepository.findByEliDokumentManifestation( norm.getManifestationEli().toString() ); assertThat(savedNorm).isPresent(); @@ -470,8 +469,8 @@ void itLoadsNormIdByPublishState() { var normPublished = Fixtures.loadNormFromDisk("NormToBeReleased.xml"); normPublished.setPublishState(NormPublishState.PUBLISHED); - normRepository.save(NormMapper.mapToDto(normQueued)); - normRepository.save(NormMapper.mapToDto(normPublished)); + dokumentRepository.saveAll(NormMapper.mapToDtos(normQueued)); + dokumentRepository.saveAll(NormMapper.mapToDtos(normPublished)); // When final List publishedNorms = dbService.loadNormIdsByPublishState( @@ -488,7 +487,9 @@ void itLoadsNormById() { var normQueued = Fixtures.loadNormFromDisk("SimpleNorm.xml"); normQueued.setPublishState(NormPublishState.QUEUED_FOR_PUBLISH); - NormDto norm = normRepository.save(NormMapper.mapToDto(normQueued)); + DokumentDto norm = dokumentRepository.save( + NormMapper.mapToDtos(normQueued).stream().findFirst().get() + ); UUID normId = norm.getId(); // When diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/application/PublishServiceIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/application/PublishServiceIntegrationTest.java index 7a0e67260..7d5df6768 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/application/PublishServiceIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/application/PublishServiceIntegrationTest.java @@ -2,9 +2,9 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import de.bund.digitalservice.ris.norms.adapter.output.database.dto.NormDto; -import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.NormMapper; -import de.bund.digitalservice.ris.norms.adapter.output.database.repository.NormRepository; +import de.bund.digitalservice.ris.norms.adapter.output.database.dto.DokumentDto; +import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.RegelungstextMapper; +import de.bund.digitalservice.ris.norms.adapter.output.database.repository.DokumentRepository; import de.bund.digitalservice.ris.norms.application.service.PublishService; import de.bund.digitalservice.ris.norms.domain.entity.Fixtures; import de.bund.digitalservice.ris.norms.domain.entity.Norm; @@ -22,21 +22,23 @@ class PublishServiceIntegrationTest extends BaseS3MockIntegrationTest { private PublishService publishService; @Autowired - private NormRepository normRepository; + private DokumentRepository dokumentRepository; @Test void processQueuedFilesForPublish() { // Given final Norm norm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - final NormDto normDto = NormMapper.mapToDto(norm); - normDto.setPublishState(NormPublishState.QUEUED_FOR_PUBLISH); - normRepository.save(normDto); + final DokumentDto dokumentDto = RegelungstextMapper.mapToDto( + norm.getRegelungstext1(), + NormPublishState.QUEUED_FOR_PUBLISH + ); + dokumentRepository.save(dokumentDto); // When publishService.processQueuedFilesForPublish(); // Then - final Optional loaded = normRepository.findByEliDokumentManifestation( + final Optional loaded = dokumentRepository.findByEliDokumentManifestation( norm.getManifestationEli().toString() ); assertThat(loaded)