diff --git a/Jenkinsfile b/Jenkinsfile index fdecd4f8a59315a989d59a37c203de9b61308d71..10c9f89198afe72f35fbb8722c7eae72f2ec8f1a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -61,10 +61,10 @@ pipeline { } configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { sh "mvn -s $MAVEN_SETTINGS versions:set -DnewVersion=${JAR_TAG} -DprocessAllModules=true" - + } } - } + } stage('Build ZufiManager Interface & Server') { steps { @@ -157,10 +157,10 @@ pipeline { } configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { sh 'mvn -s $MAVEN_SETTINGS versions:revert' - + } } - } + } stage ('OWASP Dependency-Check Vulnerabilities') { steps { @@ -242,24 +242,23 @@ pipeline { } } - // TODO: Rollout Zufi deployment on test, when it is ready - // stage('Trigger Test') { - // when { - // branch 'release' - // } + stage('Trigger Test') { + when { + branch 'release' + } - // steps { - // script { - // FAILED_STAGE = env.STAGE_NAME + steps { + script { + FAILED_STAGE = env.STAGE_NAME - // cloneGitopsRepo() + cloneGitopsRepo() - // setNewTestZufiVersion() + setNewTestZufiVersion() - // pushTestGitopsRepo() - // } - // } - // } + pushTestGitopsRepo() + } + } + } } post { diff --git a/pom.xml b/pom.xml index e05ef8cd67882bb97699c521215b5bd5dbd13910..ad799ad71a6c84bb27716d07d94980cf5fe02fdd 100644 --- a/pom.xml +++ b/pom.xml @@ -46,26 +46,22 @@ <module>zufi-manager-server</module> </modules> - <licenses> - <license> - <name>EUPL-1.2</name> - <url>https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12</url> - <distribution>repo</distribution> - </license> - </licenses> - <properties> <jaxb.version>4.0.2</jaxb.version> - <protoc-jar-plugin.version>3.11.4</protoc-jar-plugin.version> <jaxb-impl.version>4.0.5</jaxb-impl.version> - <reactor-test.version>3.6.5</reactor-test.version> - <compiler-plugin.version>3.8.1</compiler-plugin.version> <mojo-jaxb2-plugin.version>3.2.0</mojo-jaxb2-plugin.version> - <mojo-jaxb2-plugin-activation.version>1.1.1</mojo-jaxb2-plugin-activation.version> + + <find-and-replace-maven-plugin.version>1.2.0</find-and-replace-maven-plugin.version> + <protoc-jar-plugin.version>3.11.4</protoc-jar-plugin.version> + <jakarta.activation.api.version>2.1.3</jakarta.activation.api.version> - <wiremock-standalone.version>3.5.4</wiremock-standalone.version> - <testcontainers-keycloak.version>3.3.1</testcontainers-keycloak.version> + + <wiremock-standalone.version>3.8.0</wiremock-standalone.version> + <testcontainers-keycloak.version>3.4.0</testcontainers-keycloak.version> <testcontainers.version>1.19.8</testcontainers.version> + + <!-- version in ozgcloud-common (1.3.0) was obsolete, remove this when fixed --> + <ozgcloud.license.version>1.6.0</ozgcloud.license.version> </properties> <dependencyManagement> @@ -75,6 +71,16 @@ <artifactId>jakarta.xml.bind-api</artifactId> <version>${jaxb.version}</version> </dependency> + <dependency> + <groupId>org.glassfish.jaxb</groupId> + <artifactId>jaxb-runtime</artifactId> + <version>${jaxb.version}</version> + </dependency> + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <version>${jaxb-impl.version}</version> + </dependency> <dependency> <groupId>org.wiremock</groupId> <artifactId>wiremock-standalone</artifactId> @@ -100,55 +106,31 @@ <artifactId>mapstruct-processor</artifactId> <version>${mapstruct.version}</version> </dependency> - <dependency> - <groupId>org.glassfish.jaxb</groupId> - <artifactId>jaxb-runtime</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-impl</artifactId> - <version>${jaxb-impl.version}</version> - </dependency> - <dependency> - <groupId>io.projectreactor</groupId> - <artifactId>reactor-test</artifactId> - <version>${reactor-test.version}</version> - </dependency> </dependencies> </dependencyManagement> <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>com.mycila</groupId> - <artifactId>license-maven-plugin</artifactId> - <version>4.1</version> - <configuration> - <mapping> - <config>SCRIPT_STYLE</config> - </mapping> - <licenseSets> - <licenseSet> - <header>license/eupl_v1_2_de/header.txt</header> - <excludes> - <exclude>**/README</exclude> - <exclude>src/test/resources/**</exclude> - <exclude>src/main/resources/**</exclude> - </excludes> - </licenseSet> - </licenseSets> - </configuration> - <dependencies> - <dependency> - <groupId>de.ozgcloud.common</groupId> - <artifactId>ozgcloud-common-license</artifactId> - <version>${ozgcloud.license.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </pluginManagement> + <plugins> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + </plugin> + <plugin> + <groupId>com.mycila</groupId> + <artifactId>license-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>io.github.git-commit-id</groupId> + <artifactId>git-commit-id-maven-plugin</artifactId> + </plugin> + </plugins> </build> </project> diff --git a/zufi-manager-interface/pom.xml b/zufi-manager-interface/pom.xml index 683c7846c20a045217c38f3494c1769bde2bbda3..af3f750b029f0efd3c5f79d936d27a6fddad7291 100644 --- a/zufi-manager-interface/pom.xml +++ b/zufi-manager-interface/pom.xml @@ -38,11 +38,6 @@ <name>OZG-Cloud Zufi Manager Interface</name> <description>gRPC Api for Zufi Manager</description> - <properties> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <find-and-replace-maven-plugin.version>1.1.0</find-and-replace-maven-plugin.version> - </properties> - <dependencies> <!-- GRPC --> <dependency> @@ -131,26 +126,6 @@ </execution> </executions> </plugin> - <plugin> - <groupId>com.mycila</groupId> - <artifactId>license-maven-plugin</artifactId> - <configuration> - <mapping> - <proto>SLASHSTAR_STYLE</proto> - <config>SCRIPT_STYLE</config> - </mapping> - <licenseSets> - <licenseSet> - <header>license/eupl_v1_2_de/header.txt</header> - <excludes> - <exclude>**/*.yaml</exclude> - <exclude>**/*.yml</exclude> - <exclude>README.md</exclude> - </excludes> - </licenseSet> - </licenseSets> - </configuration> - </plugin> </plugins> </build> </project> diff --git a/zufi-manager-model/pom.xml b/zufi-manager-model/pom.xml index dc083a229b134c459110a863926f46a967240cb1..c47ad8c61b2d3a4823adb70ba5c0e84e08cec320 100644 --- a/zufi-manager-model/pom.xml +++ b/zufi-manager-model/pom.xml @@ -2,12 +2,13 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> + <parent> <groupId>de.ozgcloud.zufi</groupId> <artifactId>zufi-manager</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> - <groupId>de.ozgcloud.zufi</groupId> + <artifactId>zufi-manager-model</artifactId> <version>1.0.0-SNAPSHOT</version> <name>OZG-Cloud Zufi Manager Model</name> @@ -38,23 +39,6 @@ <build> <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.jacoco</groupId> - <artifactId>jacoco-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>io.github.git-commit-id</groupId> - <artifactId>git-commit-id-maven-plugin</artifactId> - </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> diff --git a/zufi-manager-pvog/pom.xml b/zufi-manager-pvog/pom.xml index c3c0cd4a96d411020759976516b8c2ea32d16bcb..5c9458d3fea5a8919d2e6cdf5edf1ae383549a6a 100644 --- a/zufi-manager-pvog/pom.xml +++ b/zufi-manager-pvog/pom.xml @@ -2,20 +2,23 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> + <parent> <groupId>de.ozgcloud.zufi</groupId> <artifactId>zufi-manager</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> - <groupId>de.ozgcloud.zufi</groupId> + <artifactId>zufi-manager-pvog</artifactId> <version>1.0.0-SNAPSHOT</version> <name>OZG-Cloud Zufi Manager PVOG</name> + <properties> <imageName>docker.ozg-sh.de/zufi-manager</imageName> <imageTag>build-latest</imageTag> <publishImage>false</publishImage> </properties> + <dependencies> <dependency> <groupId>de.ozgcloud.zufi</groupId> @@ -238,48 +241,6 @@ </excludes> </configuration> </plugin> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>${compiler-plugin.version}</version> - <configuration> - <fork>true</fork> - <annotationProcessorPaths> - <path> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <version>${lombok.version}</version> - </path> - <path> - <groupId>org.mapstruct</groupId> - <artifactId>mapstruct-processor</artifactId> - <version>${mapstruct.version}</version> - </path> - <!-- other annotation processors --> - </annotationProcessorPaths> - <showWarnings>true</showWarnings> - <compilerArgs> - <arg>-parameters</arg> - <compilerArg> - -Amapstruct.defaultComponentModel=spring - </compilerArg> - <compilerArg> - -Amapstruct.unmappedTargetPolicy=WARN - </compilerArg> - </compilerArgs> - </configuration> - </plugin> - <plugin> - <groupId>org.jacoco</groupId> - <artifactId>jacoco-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - </plugin> </plugins> </build> diff --git a/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/PvogProcessor.java b/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/PvogProcessor.java index 6beebeda8c4b8d47f6cd9d9460f36f78e9e3ccc2..9be86a911e23a924f12765baa49ba2cfda4ea3fe 100644 --- a/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/PvogProcessor.java +++ b/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/PvogProcessor.java @@ -27,7 +27,6 @@ import java.util.Set; import org.springframework.stereotype.Component; -import de.ozgcloud.common.errorhandling.TechnicalException; import de.ozgcloud.common.logging.OzgCloudLogging; import de.ozgcloud.zufi.metadocument.MetaDocumentService; import lombok.RequiredArgsConstructor; @@ -38,8 +37,6 @@ import lombok.extern.log4j.Log4j2; @Log4j2 @RequiredArgsConstructor public class PvogProcessor { - static final String INVALID_DATA_RECEICED_FROM_PVOG_SERVICE = "Invalid data receiced from PVOG Service"; - static final String GENERAL_ERROR_PROCESSING_PVOG_DATA = "General error processing PVOG data"; private final PvogService pvogService; @@ -47,56 +44,78 @@ public class PvogProcessor { private final Set<TransferOperationEntryProcessor> processors; + private final TransferOperationMapper transferOperationMapper; + public void process() { - var startIndex = metaDocumentService.findNaechsterIndex(); - - startIndex.ifPresentOrElse( - index -> { - LOG.info("Start incremental sync with index {}", index); - processFromIndex(index); - }, - () -> { - LOG.info("Start full sync"); - processFromIndex(0); - }); + int startIndex = getStartIndex(); + logSyncStarted(startIndex); + processFromIndex(startIndex); + logSyncFinished(); + } + + int getStartIndex() { + return metaDocumentService.findNaechsterIndex().orElse(0); + } + + void logSyncStarted(int startIndex) { + if (startIndex == 0) { + LOG.info("Start full sync"); + } else { + LOG.info("Start incremental sync with index {}", startIndex); + } + } + + void logSyncFinished() { LOG.info("Finished sync"); } void processFromIndex(int startIndex) { - int index = startIndex; - AntwortTransfernachricht transfernachricht; - var indexChanged = true; + var importState = new ImportState(startIndex); do { - LOG.info("Fetching further data using naechsterIndex {}", index); + var antwortTransfernachricht = fetchVerwaltungsObjekteAt(importState.index()); + process(antwortTransfernachricht); + importState = importState.nextState(antwortTransfernachricht); + } while (!isFinished(importState)); + } - transfernachricht = pvogService.getIncrementVerwaltungsObjekte(index); + AntwortTransfernachricht fetchVerwaltungsObjekteAt(int index) { + LOG.info("Fetching further data using index {}", index); + return pvogService.getVerwaltungsObjekteAt(index); + } - if (pvogService.dataAvailable(transfernachricht)) { - handleAntwortTransfernachricht(transfernachricht); - } + void process(AntwortTransfernachricht antwortTransfernachricht) { + if (pvogService.containsVerwaltungsObjekte(antwortTransfernachricht)) { + processVerwaltungsObjekteAndUpdateMetaData(antwortTransfernachricht); + } + } - if (transfernachricht.naechsterIndex() == index) { - indexChanged = false; - LOG.warn("PVOG service returned naechsterIndex {} twice. Aborting synchronization.", index); - } + void processVerwaltungsObjekteAndUpdateMetaData(AntwortTransfernachricht antwortTransfernachricht) { + process(toTransferOperation(antwortTransfernachricht)); + metaDocumentService.saveMetaDocument(antwortTransfernachricht); + } - index = transfernachricht.naechsterIndex(); + private TransferOperation toTransferOperation(AntwortTransfernachricht transfernachricht) { + return transferOperationMapper.fromAntwortTransfernachricht(transfernachricht); + } - } while (pvogService.hasMoreData(transfernachricht) && indexChanged); + private void process(TransferOperation transferOperation) { + transferOperation.getEntries().forEach(entry -> processors.forEach(p -> p.process(entry))); } - void handleAntwortTransfernachricht(AntwortTransfernachricht transfernachricht) { - try { - var transferOperation = pvogService.parseXml(transfernachricht.xzufiObjekte()); - processTransferOperation(transferOperation); - metaDocumentService.saveMetaDocument(transfernachricht); - } catch (Exception e) { - throw new TechnicalException(GENERAL_ERROR_PROCESSING_PVOG_DATA, e); - } + boolean isFinished(ImportState importState) { + return !(pvogService.hasMoreData(importState.antwortTransfernachricht()) && importState.indexChanged()); } - void processTransferOperation(TransferOperation transferOperation) { - transferOperation.getEntries().forEach(entry -> processors.forEach(p -> p.process(entry))); + record ImportState(int index, boolean indexChanged, AntwortTransfernachricht antwortTransfernachricht) { + ImportState(int index) { + this(index, true, null); + } + + ImportState nextState(AntwortTransfernachricht antwortTransfernachricht) { + return (antwortTransfernachricht.naechsterIndex() == index) + ? new ImportState(index, false, antwortTransfernachricht) + : new ImportState(antwortTransfernachricht.naechsterIndex(), true, antwortTransfernachricht); + } } } diff --git a/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/PvogService.java b/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/PvogService.java index 905b90e179be82e97d479811864f8ccd682e3dc7..5c4d18be8584ad2adabc06c7eef354c7b91e9dbc 100644 --- a/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/PvogService.java +++ b/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/PvogService.java @@ -40,10 +40,8 @@ class PvogService { private final PvogRemoteService remoteService; private final ZufiProperties zufiProperties; - private final TransferOperationMapper mapper; - private final XzufiObjekteUnmarshaller xzufiObjekteUnmarshaller; - public AntwortTransfernachricht getIncrementVerwaltungsObjekte(int index) { + public AntwortTransfernachricht getVerwaltungsObjekteAt(int index) { try { return remoteService.getVerwaltungsObjekte(index, zufiProperties.getAmtlicheRegionalSchluessel()); } catch (TechnicalException e) { @@ -53,11 +51,7 @@ class PvogService { } } - public TransferOperation parseXml(String xzufiObjekte) { - return mapper.fromJaxb(xzufiObjekteUnmarshaller.unmarshal(xzufiObjekte)); - } - - public boolean dataAvailable(AntwortTransfernachricht transfernachricht) { + public boolean containsVerwaltungsObjekte(AntwortTransfernachricht transfernachricht) { return StringUtils.isNotEmpty(transfernachricht.xzufiObjekte()); } diff --git a/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/TransferOperationMapper.java b/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/TransferOperationMapper.java index 7cb645977278650bd3463af86afdbd61374d82e2..88cc1fa9db14cd4ad25c4dd6439cc84eebaf8437 100644 --- a/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/TransferOperationMapper.java +++ b/zufi-manager-pvog/src/main/java/de/ozgcloud/zufi/pvog/TransferOperationMapper.java @@ -26,13 +26,21 @@ package de.ozgcloud.zufi.pvog; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.ReportingPolicy; +import org.springframework.beans.factory.annotation.Autowired; import de.ozgcloud.zufi.schema.TransferOperation040502; @Mapper(unmappedTargetPolicy = ReportingPolicy.WARN, uses = TransferOperationEntryMapper.class) -interface TransferOperationMapper { +abstract class TransferOperationMapper { + + @Autowired + private XzufiObjekteUnmarshaller xzufiObjekteUnmarshaller; + + public TransferOperation fromAntwortTransfernachricht(AntwortTransfernachricht antwortTransfernachricht) { + return fromXzufi(xzufiObjekteUnmarshaller.unmarshal(antwortTransfernachricht.xzufiObjekte())); + } @Mapping(target = "entries", source = "transferOperation") - TransferOperation fromJaxb(TransferOperation040502 transferOperation); + abstract TransferOperation fromXzufi(TransferOperation040502 transferOperation); } diff --git a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/PvogProcessorRunnerTest.java b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/PvogProcessorRunnerTest.java index 74e7dd1c433cd9d26d5f197c50d71ad6ab32c3ef..cdc3c6361c66a7ce399694a4c155d8ac37f02050 100644 --- a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/PvogProcessorRunnerTest.java +++ b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/PvogProcessorRunnerTest.java @@ -1,5 +1,6 @@ package de.ozgcloud.zufi; +import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; import org.junit.jupiter.api.Nested; @@ -7,6 +8,7 @@ import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; +import de.ozgcloud.common.errorhandling.TechnicalException; import de.ozgcloud.zufi.pvog.PvogProcessor; class PvogProcessorRunnerTest { @@ -19,6 +21,7 @@ class PvogProcessorRunnerTest { @Nested class TestRun { + @Test void shouldRunPvogProcessRunner() { runner.run(); @@ -26,6 +29,13 @@ class PvogProcessorRunnerTest { verify(processor).process(); } + @Test + void shouldRethrowException() { + var exception = new TechnicalException("something bad happened"); + doThrow(exception).when(processor).process(); + + assertThatThrownBy(() -> runner.run()).isEqualTo(exception); + } } } \ No newline at end of file diff --git a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/common/PvogServiceStubSetup.java b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/common/PvogServiceStubSetup.java index 124e69a031bcb77d57ab661cd3e818b9e5f166f4..b191711330b79ac1d467f7bed38716cc4f86e83e 100644 --- a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/common/PvogServiceStubSetup.java +++ b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/common/PvogServiceStubSetup.java @@ -6,14 +6,13 @@ import static de.ozgcloud.zufi.pvog.AntwortTransfernachrichtTestFactory.*; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import jakarta.ws.rs.core.MediaType; - import org.apache.commons.lang3.StringUtils; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; import de.ozgcloud.zufi.pvog.PvogProperties; +import jakarta.ws.rs.core.MediaType; public class PvogServiceStubSetup { @@ -56,6 +55,6 @@ public class PvogServiceStubSetup { .withBody(StringUtils.EMPTY))); } - public static record QueryParams(String index, String ars) { + public record QueryParams(String index, String ars) { } } diff --git a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogProcessorITCase.java b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogProcessorITCase.java index 48d48ba1fa71739d541b2a0520730d3da53bbecc..3b81334729b1b61835bea51b71bb5f76dc938399 100644 --- a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogProcessorITCase.java +++ b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogProcessorITCase.java @@ -77,15 +77,15 @@ class PvogProcessorITCase { @BeforeEach void initRemoteService() { - doReturn(AntwortTransfernachrichtTestFactory.create()).when(pvogService).getIncrementVerwaltungsObjekte(0); + doReturn(AntwortTransfernachrichtTestFactory.create()).when(pvogService).getVerwaltungsObjekteAt(0); doReturn(AntwortTransfernachrichtTestFactory.createBuilder().xzufiObjekte(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE_INCREMENT) .build()) - .when(pvogService).getIncrementVerwaltungsObjekte(AntwortTransfernachrichtTestFactory.NEXT_INDEX); + .when(pvogService).getVerwaltungsObjekteAt(AntwortTransfernachrichtTestFactory.NEXT_INDEX); } @BeforeEach void init() { - doReturn(true).when(pvogService).dataAvailable(any()); + doReturn(true).when(pvogService).containsVerwaltungsObjekte(any()); } @Test @@ -116,8 +116,8 @@ class PvogProcessorITCase { @BeforeEach void initData() { doReturn(AntwortTransfernachrichtTestFactory.createBuilder().xzufiObjekte(createLoescheTransferObject()).build()) - .when(pvogService).getIncrementVerwaltungsObjekte(anyInt()); - doReturn(true).when(pvogService).dataAvailable(any()); + .when(pvogService).getVerwaltungsObjekteAt(anyInt()); + doReturn(true).when(pvogService).containsVerwaltungsObjekte(any()); processor.process(); } diff --git a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogProcessorTest.java b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogProcessorTest.java index 83342595e570bcb3b1f26b50f887e70d8fd1c12c..3366b22715f4b9220b49bd86153524b23bd094d3 100644 --- a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogProcessorTest.java +++ b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogProcessorTest.java @@ -24,24 +24,25 @@ package de.ozgcloud.zufi.pvog; import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.List; import java.util.Optional; +import java.util.Random; import java.util.Set; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import de.ozgcloud.common.errorhandling.TechnicalException; import de.ozgcloud.zufi.metadocument.MetaDocumentService; import de.ozgcloud.zufi.metadocument.MetaDocumentTestFactory; +import de.ozgcloud.zufi.pvog.PvogProcessor.ImportState; class PvogProcessorTest { @Spy @@ -53,220 +54,235 @@ class PvogProcessorTest { private MetaDocumentService metaDocumentService; @Mock private Set<TransferOperationEntryProcessor> entryProcessors; + @Mock + private TransferOperationMapper transferOperationMapper; - @DisplayName("Test processing the PVOG data") @Nested class TestProcess { - @DisplayName("when it is a full sync") - @Nested - class OnFullSync { + private static final int INDEX = new Random().nextInt(); - @BeforeEach - void init() { - when(metaDocumentService.findNaechsterIndex()).thenReturn(Optional.empty()); - doNothing().when(processor).processFromIndex(0); - } + @BeforeEach + void init() { + doReturn(INDEX).when(processor).getStartIndex(); + doNothing().when(processor).processFromIndex(INDEX); + } - @Test - void shouldFindNaechsterIndex() { - processor.process(); + @Test + void shouldGetStartIndex() { + processor.process(); - verify(metaDocumentService).findNaechsterIndex(); - } + verify(processor).getStartIndex(); + } - @Test - void shouldProcessFromIndex() { - processor.process(); + @Test + void shouldProcessFromIndex() { + processor.process(); - verify(processor).processFromIndex(0); - } + verify(processor).processFromIndex(INDEX); } - @DisplayName("when it is a incremental sync") - @Nested - class OnIncrementalSync { + @Test + void shouldLogSyncStarted() { + processor.process(); - @BeforeEach - void init() { - when(metaDocumentService.findNaechsterIndex()).thenReturn(Optional.of(MetaDocumentTestFactory.NAECHSTER_INDEX)); - doNothing().when(processor).processFromIndex(MetaDocumentTestFactory.NAECHSTER_INDEX); - } + verify(processor).logSyncStarted(INDEX); + } - @Test - void shouldFindNaechsterIndex() { - processor.process(); + @Test + void shouldLogSyncFinished() { + processor.process(); - verify(metaDocumentService).findNaechsterIndex(); - } + verify(processor).logSyncFinished(); + } + } - @Test - void shouldProcessFromIndex() { - processor.process(); + @Nested + class TestGetStartIndex { - verify(processor).processFromIndex(MetaDocumentTestFactory.NAECHSTER_INDEX); - } + @Test + void shouldFindNextIndex() { + givenFindNaechsterIndexReturnsNextIndex(); + + processor.getStartIndex(); + + verify(metaDocumentService).findNaechsterIndex(); } + @Test + void shouldReturnNextIndex() { + givenFindNaechsterIndexReturnsNextIndex(); + + var startIndex = processor.getStartIndex(); + + assertThat(startIndex).isEqualTo(MetaDocumentTestFactory.NAECHSTER_INDEX); + } + + @Test + void shouldReturnZeroIfNextIndexNotFound() { + givenFindNaechsterIndexReturnsEmpty(); + + var startIndex = processor.getStartIndex(); + + assertThat(startIndex).isZero(); + } + + private void givenFindNaechsterIndexReturnsNextIndex() { + when(metaDocumentService.findNaechsterIndex()).thenReturn(Optional.of(MetaDocumentTestFactory.NAECHSTER_INDEX)); + } + + private void givenFindNaechsterIndexReturnsEmpty() { + when(metaDocumentService.findNaechsterIndex()).thenReturn(Optional.empty()); + } } @Nested class TestProcessFromIndex { + private static final int START_INDEX = 1000; + private static final int IMPORT_STATE_1_INDEX = 2000; + + private final AntwortTransfernachricht antwortTransfernachricht1 = AntwortTransfernachrichtTestFactory.createBuilder().naechsterIndex(IMPORT_STATE_1_INDEX).build(); + private final ImportState importState1 = new ImportState(IMPORT_STATE_1_INDEX, true, antwortTransfernachricht1); + + @BeforeEach + void mockProcessorMethods() { + doReturn(antwortTransfernachricht1).when(processor).fetchVerwaltungsObjekteAt(START_INDEX); + doNothing().when(processor).process(antwortTransfernachricht1); + } @Nested - class TestWithChangedNaechsterIndex { - private final AntwortTransfernachricht antwortTransfernachricht = AntwortTransfernachrichtTestFactory.create(); - private final AntwortTransfernachricht nextAntwortTransfernachricht = AntwortTransfernachrichtTestFactory.createBuilder() - .naechsterIndex(MetaDocumentTestFactory.NAECHSTER_INDEX + 100).build(); + class OnIsFinishedAfterProcessingFirstIndex { @BeforeEach - void init() { - when(service.getIncrementVerwaltungsObjekte(MetaDocumentTestFactory.NAECHSTER_INDEX)).thenReturn(antwortTransfernachricht); + void mockIsFinished() { + doReturn(true).when(processor).isFinished(importState1); } @Test - void shouldGetIncrementVerwaltungsObjekte() { - when(service.hasMoreData(antwortTransfernachricht)).thenReturn(false); - - callProcessor(); + void shouldFetchVerwaltungsObjekteAtIndex() { + processFromStartIndex(); - verify(service).getIncrementVerwaltungsObjekte(MetaDocumentTestFactory.NAECHSTER_INDEX); + verify(processor).fetchVerwaltungsObjekteAt(START_INDEX); } @Test - void shouldNotHandleAntwortTransfernachrichtWithoutData() { - when(service.hasMoreData(antwortTransfernachricht)).thenReturn(false); - when(service.dataAvailable(antwortTransfernachricht)).thenReturn(false); + void shouldProcessAntwortTransfernachricht() { + processFromStartIndex(); - callProcessor(); - - verify(processor, never()).handleAntwortTransfernachricht(any()); + verify(processor).process(antwortTransfernachricht1); } @Test - void shouldHandleAntwortTransfernachrichtWithData() { - when(service.hasMoreData(antwortTransfernachricht)).thenReturn(false); - when(service.dataAvailable(antwortTransfernachricht)).thenReturn(true); - doNothing().when(processor).handleAntwortTransfernachricht(antwortTransfernachricht); - - callProcessor(); + void shouldCheckIfImportIsFinishedBasedOnNextState() { + processFromStartIndex(); - verify(processor).handleAntwortTransfernachricht(antwortTransfernachricht); + verify(processor).isFinished(importState1); } + } - @Test - void shouldNotProcessNextIndex() { - when(service.hasMoreData(antwortTransfernachricht)).thenReturn(false); - when(service.dataAvailable(antwortTransfernachricht)).thenReturn(false); + @Nested + class OnIsNotFinishedAfterProcessingFirstIndex { + private static final int IMPORT_STATE_2_INDEX = 3000; - callProcessor(); + private final AntwortTransfernachricht antwortTransfernachricht2 = AntwortTransfernachrichtTestFactory.createBuilder().naechsterIndex(IMPORT_STATE_2_INDEX).build(); + private final ImportState importState2 = new ImportState(IMPORT_STATE_2_INDEX, true, antwortTransfernachricht2); - verify(service, never()).getIncrementVerwaltungsObjekte(AntwortTransfernachrichtTestFactory.NEXT_INDEX); + @BeforeEach + void mockProcessorMethods() { + doReturn(antwortTransfernachricht2).when(processor).fetchVerwaltungsObjekteAt(IMPORT_STATE_1_INDEX); + doNothing().when(processor).process(antwortTransfernachricht2); } - @Test - void shouldProcessNextIndex() { - when(service.hasMoreData(antwortTransfernachricht)).thenReturn(true); - when(service.hasMoreData(nextAntwortTransfernachricht)).thenReturn(false); - when(service.dataAvailable(any())).thenReturn(false); - when(service.getIncrementVerwaltungsObjekte(AntwortTransfernachrichtTestFactory.NEXT_INDEX)).thenReturn(nextAntwortTransfernachricht); + @BeforeEach + void mockIsFinished() { + doReturn(false).when(processor).isFinished(importState1); + doReturn(true).when(processor).isFinished(importState2); + } - callProcessor(); + @Test + void shouldFetchVerwaltungsObjekteAtIndex() { + processFromStartIndex(); - verify(service).getIncrementVerwaltungsObjekte(AntwortTransfernachrichtTestFactory.NEXT_INDEX); + verify(processor).fetchVerwaltungsObjekteAt(IMPORT_STATE_1_INDEX); } - } - - @Nested - class TestWithSameNaechsterIndex { - private final AntwortTransfernachricht antwortTransfernachricht = AntwortTransfernachrichtTestFactory.createBuilder() - .naechsterIndex(MetaDocumentTestFactory.NAECHSTER_INDEX).build(); @Test - void shouldExitLoopOnRepeatedNextIndex() { - when(service.getIncrementVerwaltungsObjekte(MetaDocumentTestFactory.NAECHSTER_INDEX)).thenReturn(antwortTransfernachricht); - when(service.dataAvailable(antwortTransfernachricht)).thenReturn(false); - when(service.hasMoreData(antwortTransfernachricht)).thenReturn(true); - - callProcessor(); + void shouldProcessAntwortTransfernachricht() { + processFromStartIndex(); - verify(service, times(1)).getIncrementVerwaltungsObjekte(MetaDocumentTestFactory.NAECHSTER_INDEX); + verify(processor).process(antwortTransfernachricht2); } + @Test + void shouldCheckIfImportIsFinishedBasedOnNextState() { + processFromStartIndex(); + + verify(processor).isFinished(importState2); + } } - private void callProcessor() { - processor.processFromIndex(MetaDocumentTestFactory.NAECHSTER_INDEX); + private void processFromStartIndex() { + processor.processFromIndex(START_INDEX); } } @Nested - class TestHandleAntwortTransfernachricht { - private final AntwortTransfernachricht antwortTransfernachricht = AntwortTransfernachrichtTestFactory.create(); - private final TransferOperation transferOperation = TransferOperationTestFactory.create(); + class TestFetchVerwaltungsObjekteAtIndex { - @Nested - class OnNoException { + private static final int INDEX = new Random().nextInt(); - @BeforeEach - void setUpMocks() { - when(service.parseXml(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE)).thenReturn(transferOperation); - doNothing().when(processor).processTransferOperation(transferOperation); - } - - @Test - void shouldCallParseXml() { - callProcessor(); + @Test + void shouldCallPvogService() { + processor.fetchVerwaltungsObjekteAt(INDEX); - verify(service).parseXml(any()); - } + verify(service).getVerwaltungsObjekteAt(INDEX); + } + } - @Test - void shouldProcessTransferOperation() { - callProcessor(); + @Nested + class TestProcessAntwortTransfernachricht { - verify(processor).processTransferOperation(transferOperation); - } + private final AntwortTransfernachricht antwortTransfernachricht = AntwortTransfernachrichtTestFactory.create(); - @Test - void shouldSaveMetaDocument() { - callProcessor(); + @Test + void shouldCheckForVerwaltungsObjekte() { + processor.process(antwortTransfernachricht); - verify(metaDocumentService).saveMetaDocument(antwortTransfernachricht); - } + verify(service).containsVerwaltungsObjekte(antwortTransfernachricht); } - @DisplayName("check error handling") - @Nested - class OnException { - - @Test - void shouldThrowTechnicalExceptionOnError() { - doThrow(new RuntimeException()).when(processor).processTransferOperation(any()); + @Test + void shouldDoNothingIfAntwortDoesNotContainVerwaltungsObjekte() { + when(service.containsVerwaltungsObjekte(antwortTransfernachricht)).thenReturn(false); - assertThatExceptionOfType(TechnicalException.class).isThrownBy( // NOSONAR - () -> processor.handleAntwortTransfernachricht( - AntwortTransfernachrichtTestFactory.create())) - .withMessageContaining(PvogProcessor.GENERAL_ERROR_PROCESSING_PVOG_DATA); + processor.process(antwortTransfernachricht); - verify(metaDocumentService, never()).saveMetaDocument(any()); - } + verify(processor, never()).processVerwaltungsObjekteAndUpdateMetaData(any()); } - private void callProcessor() { - processor.handleAntwortTransfernachricht(antwortTransfernachricht); + @Test + void shouldProcessVerwaltungsObjekte() { + when(service.containsVerwaltungsObjekte(antwortTransfernachricht)).thenReturn(true); + doNothing().when(processor).processVerwaltungsObjekteAndUpdateMetaData(antwortTransfernachricht); + + processor.process(antwortTransfernachricht); + + verify(processor).processVerwaltungsObjekteAndUpdateMetaData(antwortTransfernachricht); } } @Nested - class TestProcessTransferOperation { + class TestProcessVerwaltungsObjekteAndUpdateMetaData { + + private final AntwortTransfernachricht antwortTransfernachricht = AntwortTransfernachrichtTestFactory.create(); @Test void shouldProcessOneEntry() { var entry = TransferOperationEntryTestFactory.createWriteEntry(); - var entries = TransferOperationTestFactory.createBuilder().entries(List.of(entry)).build(); + var transferOperation = TransferOperationTestFactory.createBuilder().entries(List.of(entry)).build(); + when(transferOperationMapper.fromAntwortTransfernachricht(antwortTransfernachricht)).thenReturn(transferOperation); - processor.processTransferOperation(entries); + processor.processVerwaltungsObjekteAndUpdateMetaData(antwortTransfernachricht); entryProcessors.forEach(entryProcessor -> verify(entryProcessor).process(entry)); } @@ -276,15 +292,128 @@ class PvogProcessorTest { var entry1 = TransferOperationEntryTestFactory.createWriteEntry(); var entry2 = TransferOperationEntryTestFactory.createWriteEntry(); var entry3 = TransferOperationEntryTestFactory.createDeleteEntry(); - var entries = TransferOperationTestFactory.createBuilder().entries(List.of(entry1, entry2, entry3)).build(); + var transferOperation = TransferOperationTestFactory.createBuilder().entries(List.of(entry1, entry2, entry3)).build(); + when(transferOperationMapper.fromAntwortTransfernachricht(antwortTransfernachricht)).thenReturn(transferOperation); - processor.processTransferOperation(entries); + processor.processVerwaltungsObjekteAndUpdateMetaData(antwortTransfernachricht); entryProcessors.forEach(entryProcessor -> verify(entryProcessor).process(entry1)); entryProcessors.forEach(entryProcessor -> verify(entryProcessor).process(entry2)); entryProcessors.forEach(entryProcessor -> verify(entryProcessor).process(entry3)); } + @Test + void shouldUpdateMetaData() { + var transferOperation = TransferOperationTestFactory.create(); + when(transferOperationMapper.fromAntwortTransfernachricht(antwortTransfernachricht)).thenReturn(transferOperation); + + processor.processVerwaltungsObjekteAndUpdateMetaData(antwortTransfernachricht); + + verify(metaDocumentService).saveMetaDocument(antwortTransfernachricht); + } } + @Nested + class TestIsFinished { + private static final int DUMMY_INDEX = 100; + + private final AntwortTransfernachricht antwortTransfernachricht = AntwortTransfernachrichtTestFactory.create(); + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void shouldReturnTrueIfHasNoMoreData(boolean indexChanged) { + var importState = new ImportState(DUMMY_INDEX, indexChanged, antwortTransfernachricht); + when(service.hasMoreData(antwortTransfernachricht)).thenReturn(false); + + var finished = processor.isFinished(importState); + + assertThat(finished).isTrue(); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void shouldReturnTrueIfIndexNotChanged(boolean hasMoreData) { + var importState = new ImportState(DUMMY_INDEX, false, antwortTransfernachricht); + when(service.hasMoreData(antwortTransfernachricht)).thenReturn(hasMoreData); + + var finished = processor.isFinished(importState); + + assertThat(finished).isTrue(); + } + + @Test + void shouldReturnFalseIfHasMoreDataAndIndexChanged() { + var importState = new ImportState(DUMMY_INDEX, true, antwortTransfernachricht); + when(service.hasMoreData(antwortTransfernachricht)).thenReturn(true); + + var finished = processor.isFinished(importState); + + assertThat(finished).isFalse(); + } + } + + @Nested + class TestImportState { + + @Nested + class TestCustomConstructor { + + @Test + void shouldSetIndexChangedToTrue() { + var importState = new ImportState(100); + + assertThat(importState.indexChanged()).isTrue(); + } + } + + @Nested + class TestNextState { + + private final AntwortTransfernachricht antwortTransfernachricht = AntwortTransfernachrichtTestFactory.create(); + + @Test + void shouldHaveAntwortTransfernachricht() { + var importState = new ImportState(100); + + var nextState = importState.nextState(antwortTransfernachricht); + + assertThat(nextState.antwortTransfernachricht()).isEqualTo(antwortTransfernachricht); + } + + @Test + void shouldHaveIndex() { + var importState = new ImportState(100); + + var nextState = importState.nextState(antwortTransfernachricht); + + assertThat(nextState.index()).isEqualTo(AntwortTransfernachrichtTestFactory.NEXT_INDEX); + } + + @Nested + class OnNaechsterIndexEqualsIndex { + + @Test + void shouldHaveIndexChangedEqualsFalse() { + var importState = new ImportState(AntwortTransfernachrichtTestFactory.NEXT_INDEX); + + var nextState = importState.nextState(antwortTransfernachricht); + + assertThat(nextState.indexChanged()).isFalse(); + } + } + + @Nested + class OnNaechsterIndexDiffersFromIndex { + + @Test + void shouldHaveIndexChangedEqualsTrue() { + var importState = new ImportState(AntwortTransfernachrichtTestFactory.NEXT_INDEX - 100); + + var nextState = importState.nextState(antwortTransfernachricht); + + assertThat(nextState.indexChanged()).isTrue(); + } + } + } + } } diff --git a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogServiceTest.java b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogServiceTest.java index 5181f502b735c7d12749ab1c7ece503a25fc0d09..2957c05fd6448606b6812aec9ecf54a0d6950c25 100644 --- a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogServiceTest.java +++ b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/PvogServiceTest.java @@ -38,8 +38,6 @@ import org.mockito.Spy; import com.thedeanda.lorem.LoremIpsum; -import de.ozgcloud.zufi.schema.TransferOperation040502; - class PvogServiceTest { @Spy @@ -49,10 +47,6 @@ class PvogServiceTest { private ZufiProperties zufiProperties; @Mock private PvogRemoteService remoteService; - @Mock - private TransferOperationMapper mapper; - @Mock - private XzufiObjekteUnmarshaller xzufiObjekteUnmarshaller; @Nested class TestGetIncrementVerwaltungsObjekte { @@ -82,7 +76,7 @@ class PvogServiceTest { } private AntwortTransfernachricht callService() { - return service.getIncrementVerwaltungsObjekte(index); + return service.getVerwaltungsObjekteAt(index); } } @@ -110,40 +104,6 @@ class PvogServiceTest { } } - @Nested - class TestParseXml { - - @Mock - private TransferOperation040502 jaxbTransferOperation; - - @BeforeEach - void init() { - when(xzufiObjekteUnmarshaller.unmarshal(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE)).thenReturn(jaxbTransferOperation); - when(mapper.fromJaxb(jaxbTransferOperation)).thenReturn(TransferOperationTestFactory.create()); - } - - @Test - void shouldUnmarshalXzufiObjekte() { - service.parseXml(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE); - - verify(xzufiObjekteUnmarshaller).unmarshal(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE); - } - - @Test - void shouldMapToTransferOperation() { - service.parseXml(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE); - - verify(mapper).fromJaxb(jaxbTransferOperation); - } - - @Test - void shouldReturnTransferOperation() { - var transferOperation = service.parseXml(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE); - - assertThat(transferOperation.getEntries()).isEqualTo(TransferOperationTestFactory.ENTRIES); - } - } - @DisplayName("Verify the xzufi data of the incomming AntwortTransfernachricht") @Nested class TestDataAvailable { @@ -152,7 +112,7 @@ class PvogServiceTest { void shouldHandleEmptyBody() { var emptyBody = AntwortTransfernachrichtTestFactory.createBuilder().xzufiObjekte("").build(); - var result = service.dataAvailable(emptyBody); + var result = service.containsVerwaltungsObjekte(emptyBody); assertThat(result).isFalse(); } @@ -161,7 +121,7 @@ class PvogServiceTest { void shouldHandleNullBody() { var nullBody = AntwortTransfernachrichtTestFactory.createBuilder().xzufiObjekte(null).build(); - var result = service.dataAvailable(nullBody); + var result = service.containsVerwaltungsObjekte(nullBody); assertThat(result).isFalse(); } @@ -170,7 +130,7 @@ class PvogServiceTest { void shouldReturnTrue() { var validNachricht = AntwortTransfernachrichtTestFactory.create(); - var result = service.dataAvailable(validNachricht); + var result = service.containsVerwaltungsObjekte(validNachricht); assertThat(result).isTrue(); } diff --git a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/SchreibeObjektTestFactory.java b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/SchreibeObjektTestFactory.java index 156879d0739ae86e389956df4d230b7695cbb9e7..17328b862a1970098947b1709b3734405e4a22d3 100644 --- a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/SchreibeObjektTestFactory.java +++ b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/SchreibeObjektTestFactory.java @@ -26,25 +26,25 @@ package de.ozgcloud.zufi.pvog; import de.ozgcloud.zufi.schema.SchreibeObjekt; public class SchreibeObjektTestFactory { - public static final SchreibeObjekt createWithOrganisationseinheit() { + public static SchreibeObjekt createWithOrganisationseinheit() { var schreibeObjekt = new SchreibeObjekt(); schreibeObjekt.setOrganisationseinheit(OrganisationseinheitTestFactory.create()); return schreibeObjekt; } - public static final SchreibeObjekt createWithOrganisationseinheitWithoutAnschrift() { + public static SchreibeObjekt createWithOrganisationseinheitWithoutAnschrift() { var schreibeObjekt = new SchreibeObjekt(); schreibeObjekt.setOrganisationseinheit(OrganisationseinheitTestFactory.createWithoutAnschrift()); return schreibeObjekt; } - public static final SchreibeObjekt createWithOrganisationseinheitWithoutVerwaltungspolitischeKodierung() { + public static SchreibeObjekt createWithOrganisationseinheitWithoutVerwaltungspolitischeKodierung() { var schreibeObjekt = new SchreibeObjekt(); schreibeObjekt.setOrganisationseinheit(OrganisationseinheitTestFactory.createWithoutVerwaltungspolitischeKodierung()); return schreibeObjekt; } - public static final SchreibeObjekt createWithZustaendigkeit() { + public static SchreibeObjekt createWithZustaendigkeit() { var schreibeObjekt = new SchreibeObjekt(); schreibeObjekt.setZustaendigkeitTransferObjekt(ZustaendigkeitTransferObjektTestFactory.create()); return schreibeObjekt; diff --git a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/TransferOperationMapperITCase.java b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/TransferOperationMapperITCase.java index f65aad102ea6e056f425e0515072ce9e4b7c9c73..4fdc8f25b85dd5a30a87bd8a18d429c0860323de 100644 --- a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/TransferOperationMapperITCase.java +++ b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/TransferOperationMapperITCase.java @@ -69,7 +69,7 @@ class TransferOperationMapperITCase { } private TransferOperation map() { - return mapper.fromJaxb(XzufiTestUtils.unmarshal(createLoescheTransferObject())); + return mapper.fromXzufi(XzufiTestUtils.unmarshal(createLoescheTransferObject())); } private String createLoescheTransferObject() { @@ -82,6 +82,6 @@ class TransferOperationMapperITCase { } private TransferOperation map() { - return mapper.fromJaxb(XzufiTestUtils.unmarshal(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE)); + return mapper.fromXzufi(XzufiTestUtils.unmarshal(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE)); } } diff --git a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/TransferOperationMapperTest.java b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/TransferOperationMapperTest.java index d61905fe2c114bcc43488774a18a3027a18324bb..89b7b5c09164e1ac59299c728037b1152e7af204 100644 --- a/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/TransferOperationMapperTest.java +++ b/zufi-manager-pvog/src/test/java/de/ozgcloud/zufi/pvog/TransferOperationMapperTest.java @@ -24,10 +24,9 @@ package de.ozgcloud.zufi.pvog; import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; @@ -35,19 +34,58 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; +import de.ozgcloud.zufi.schema.TransferOperation040502; + class TransferOperationMapperTest { @Spy @InjectMocks - private TransferOperationMapper mapper = Mappers.getMapper(TransferOperationMapper.class); - + private final TransferOperationMapper mapper = Mappers.getMapper(TransferOperationMapper.class); @Mock - private TransferOperationEntryMapper entryMapper = Mappers.getMapper(TransferOperationEntryMapper.class); + private TransferOperationEntryMapper entryMapper; + @Mock + private XzufiObjekteUnmarshaller xzufiObjekteUnmarshaller; - @DisplayName("Verify the received transfer object") @Nested - class TestFromJaxb { + class TestFromAntwortTransfernachricht { + + @Mock + private TransferOperation040502 xzufiTransferOperation; + + @BeforeEach + void init() { + when(xzufiObjekteUnmarshaller.unmarshal(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE)).thenReturn(xzufiTransferOperation); + doReturn(TransferOperationTestFactory.create()).when(mapper).fromXzufi(xzufiTransferOperation); + } + + @Test + void shouldUnmarshalXzufiObjekte() { + map(); + + verify(xzufiObjekteUnmarshaller).unmarshal(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE); + } + @Test + void shouldMapToTransferOperation() { + map(); + + verify(mapper).fromXzufi(xzufiTransferOperation); + } + + @Test + void shouldReturnTransferOperation() { + var transferOperation = map(); + + assertThat(transferOperation.getEntries()).isEqualTo(TransferOperationTestFactory.ENTRIES); + } + + private TransferOperation map() { + return mapper.fromAntwortTransfernachricht(AntwortTransfernachrichtTestFactory.create()); + } + } + + @Nested + class TestFromXzufi { @Test void shouldCallTransferOperationEntryMapper() { map(); @@ -62,9 +100,8 @@ class TransferOperationMapperTest { assertThat(data.getEntries()).hasSize(AntwortTransfernachrichtTestFactory.ANZAHL_OBJEKTE); } - } - - private TransferOperation map() { - return mapper.fromJaxb(XzufiTestUtils.unmarshal(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE)); + private TransferOperation map() { + return mapper.fromXzufi(XzufiTestUtils.unmarshal(AntwortTransfernachrichtTestFactory.XZUFI_OBJEKTE)); + } } } diff --git a/zufi-manager-server/pom.xml b/zufi-manager-server/pom.xml index 94a0d213da9e186a46f50c0094a46f303424930c..1cfa43cb07ed9cb87a0c29ab93d313a39417c2c6 100644 --- a/zufi-manager-server/pom.xml +++ b/zufi-manager-server/pom.xml @@ -33,7 +33,6 @@ <version>1.0.0-SNAPSHOT</version> </parent> - <groupId>de.ozgcloud.zufi</groupId> <artifactId>zufi-manager-server</artifactId> <version>1.0.0-SNAPSHOT</version> <name>OZG-Cloud Zufi Manager Server</name> @@ -49,8 +48,6 @@ <maven.compiler.source>${java.version}</maven.compiler.source> <maven.compiler.target>${java.version}</maven.compiler.target> - - <testcontainer.version>1.19.7</testcontainer.version> </properties> <dependencies> @@ -208,29 +205,6 @@ </profiles> <build> <plugins> - <plugin> - <groupId>org.jacoco</groupId> - <artifactId>jacoco-maven-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.graalvm.buildtools</groupId> - <artifactId>native-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>com.mycila</groupId> - <artifactId>license-maven-plugin</artifactId> - </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> diff --git a/zufi-manager-server/src/main/java/de/ozgcloud/zufi/registration/VorgangManagerRoutingGrpcService.java b/zufi-manager-server/src/main/java/de/ozgcloud/zufi/registration/VorgangManagerRoutingGrpcService.java index 950d31476001f986f52f68888cfc3c6aabdbdaf9..b78734b98dcb7f9146aa695e090c12d74d0c594e 100644 --- a/zufi-manager-server/src/main/java/de/ozgcloud/zufi/registration/VorgangManagerRoutingGrpcService.java +++ b/zufi-manager-server/src/main/java/de/ozgcloud/zufi/registration/VorgangManagerRoutingGrpcService.java @@ -12,11 +12,11 @@ import net.devh.boot.grpc.server.service.GrpcService; @RequiredArgsConstructor class VorgangManagerRoutingGrpcService extends VorgangManagerRoutingServiceImplBase { - private final VorgangManagerRoutingService RoutingService; + private final VorgangManagerRoutingService routingService; @Override public void routing(GrpcVorgangManagerRoutingRequest request, StreamObserver<GrpcVorgangManagerRoutingResponse> responseObserver) { - RoutingService.findVorgangManagerAddress(request.getOrganisationsEinheitId()).ifPresentOrElse( + routingService.findVorgangManagerAddress(request.getOrganisationsEinheitId()).ifPresentOrElse( result -> buildResponse(responseObserver, result), () -> throwException(request));