diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/bayernid/BayernIdPostfachClient.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/bayernid/BayernIdPostfachClient.java index 902912fdbf59c2b76f2e15fc5946fd4d73768384..98b80085850bf97cee0b454250c6a524f1f4cfa2 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/bayernid/BayernIdPostfachClient.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/bayernid/BayernIdPostfachClient.java @@ -4,6 +4,7 @@ import javax.xml.bind.JAXBElement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.oxm.jaxb.Jaxb2Marshaller; +import org.springframework.ws.client.core.WebServiceTemplate; import org.springframework.ws.client.core.support.WebServiceGatewaySupport; import org.springframework.xml.transform.StringResult; import org.springframework.xml.transform.StringSource; @@ -40,4 +41,9 @@ class BayernIdPostfachClient extends WebServiceGatewaySupport { return reply.getValue(); } + + public WebServiceTemplate getWSTemplate() { + return this.getWebServiceTemplate(); + } + } diff --git a/pluto-server/pom.xml b/pluto-server/pom.xml index 47476f7b2bb57edabb2ca44e85b4877dadc5366c..0663b55b170600ce1be6185da37db0c4aed1904f 100644 --- a/pluto-server/pom.xml +++ b/pluto-server/pom.xml @@ -55,8 +55,10 @@ <jsoup.version>1.15.3</jsoup.version> <mongock.version>5.1.4</mongock.version> <testcontainer.version>1.17.3</testcontainer.version> - + <maven-deploy-plugin.version>3.0.0</maven-deploy-plugin.version> + + <spring-ws-test.version>2.0.2.RELEASE</spring-ws-test.version> </properties> <dependencies> @@ -256,6 +258,13 @@ <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> </dependency> + <dependency> + <groupId>org.springframework.ws</groupId> + <artifactId>spring-ws-test</artifactId> + <version>${spring-ws-test.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.junit.jupiter</groupId> diff --git a/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/PostfachMailITCase.java b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/PostfachMailITCase.java index 7a52b898ab311ff805b102a39db9fcbd2cd21c77..f51a80074194a3b1eacff1a8e52d269fa7e3697a 100644 --- a/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/PostfachMailITCase.java +++ b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/PostfachMailITCase.java @@ -34,7 +34,9 @@ import java.time.temporal.ChronoUnit; import java.util.List; import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -45,6 +47,7 @@ import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.client.ExpectedCount; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; @@ -65,6 +68,7 @@ import io.grpc.stub.StreamObserver; @SpringBootTest(classes = { PlutoServerApplication.class, OsiPostfachProperties.class }) @DataITCase @WithMockUser +@ActiveProfiles({ "itcase", "with_db", "itcase-osi-postfach" }) class PostfachMailITCase { private static final String TEST_OSI_POSTFACH_URI = "http://localhost/ApiProxy/V1/Message"; diff --git a/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/bayernid/BayernIdPostfachServiceITCase.java b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/bayernid/BayernIdPostfachServiceITCase.java new file mode 100644 index 0000000000000000000000000000000000000000..c41fab7dc42c8acb99a30e5f4b75cd3ba950e3a0 --- /dev/null +++ b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/bayernid/BayernIdPostfachServiceITCase.java @@ -0,0 +1,96 @@ +package de.itvsh.ozg.mail.postfach.bayernid; + +import static org.assertj.core.api.Assertions.*; +import static org.springframework.ws.test.client.RequestMatchers.*; +import static org.springframework.ws.test.client.ResponseCreators.*; + +import java.io.IOException; +import java.util.Collections; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.io.Resource; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.ws.test.client.MockWebServiceServer; + +import de.itvsh.kop.common.test.ITCase; +import de.itvsh.ozg.mail.postfach.PostfachAddressTestFactory; +import de.itvsh.ozg.mail.postfach.PostfachBadRequestException; +import de.itvsh.ozg.mail.postfach.PostfachNachrichtTestFactory; +import de.itvsh.ozg.mail.postfach.StringBasedIdentifier; +import de.itvsh.ozg.pluto.PlutoServerApplication; +import lombok.val; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { PlutoServerApplication.class, BayernIdProperties.class }) +@ITCase +@ActiveProfiles({ "itcase", "itcase-bayernid-postfach" }) +class BayernIdPostfachServiceITCase { + + @Autowired + private BayernIdPostfachRemoteService bayernIdPostfachRemoteService; + + @Autowired + private BayernIdPostfachClient bayernIdPostfachClient; + + @Value("classpath:bayernid/bsp-nachricht") + private Resource bspNachrichtNativeResource; + + @Value("classpath:bayernid/bsp-quittung") + private Resource bspQuittungNativeResource; + + @Value("classpath:bayernid/bsp-quittung-error-in-schema") + private Resource bspQuittungErrorNativeResource; + + private MockWebServiceServer mockWebServiceServer; + + @BeforeEach + void createMockWebServiceServer() { + mockWebServiceServer = MockWebServiceServer.createServer(bayernIdPostfachClient.getWSTemplate()); + } + + @Test + void shouldSendMessageSuccessfully() throws IOException { + mockWebServiceServer.expect(payload(bspNachrichtNativeResource)).andRespond(withPayload(bspQuittungNativeResource)); + + val nachricht = PostfachNachrichtTestFactory.createBuilder() + .vorgangId("1") + .postfachAddress(PostfachAddressTestFactory.createBuilder() + .type(PostfachAddressTestFactory.TYPE) + .version(PostfachAddressTestFactory.VERSION) + .identifier(StringBasedIdentifier.builder().postfachId("1").build()) + .build()) + .messageId("1") + .attachments(Collections.emptyList()) + .build(); + + assertThatCode(() -> bayernIdPostfachRemoteService.sendMessage(nachricht)).doesNotThrowAnyException(); + + mockWebServiceServer.verify(); + } + + @Test + void shouldThrowPostfachBadRequestException() throws IOException { + mockWebServiceServer.expect(payload(bspNachrichtNativeResource)).andRespond(withPayload(bspQuittungErrorNativeResource)); + + val nachricht = PostfachNachrichtTestFactory.createBuilder() + .vorgangId("1") + .postfachAddress(PostfachAddressTestFactory.createBuilder() + .type(PostfachAddressTestFactory.TYPE) + .version(PostfachAddressTestFactory.VERSION) + .identifier(StringBasedIdentifier.builder().postfachId("1").build()) + .build()) + .messageId("1") + .attachments(Collections.emptyList()) + .build(); + + assertThatThrownBy(() -> bayernIdPostfachRemoteService.sendMessage(nachricht)).isInstanceOf(PostfachBadRequestException.class); + + mockWebServiceServer.verify(); + } +} diff --git a/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachServiceITCase.java b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachServiceITCase.java index aa1866a4c28a63e86c131a9fdc4a072d7e7c59ba..bc9966216fd7fe1251927a7dea50c5452da46f69 100644 --- a/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachServiceITCase.java +++ b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachServiceITCase.java @@ -29,7 +29,9 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat import java.util.Collections; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; diff --git a/pluto-server/src/test/resources/application-itcase-bayernid-postfach.yml b/pluto-server/src/test/resources/application-itcase-bayernid-postfach.yml new file mode 100644 index 0000000000000000000000000000000000000000..c2694bddb339d0ba7b5445e8f39ebef432ff53c6 --- /dev/null +++ b/pluto-server/src/test/resources/application-itcase-bayernid-postfach.yml @@ -0,0 +1,13 @@ +ozgcloud: + bayernid: + server: http://localhost + zertifikat: + keystore: classpath:bayernid.p12 + password: SyPaRAxe97 + absender: + postkorbId: 28721c6f-b78f-4d5c-a048-19fd2fc429d2 + name: test name + anschrift: Niemalsgasse 5, 99999 Irgendwo Stadt + dienst: Stadtverwaltung + mandant: Fürth + gemeindeSchluessel: 09563000 \ No newline at end of file diff --git a/pluto-server/src/test/resources/application-itcase-osi-postfach.yml b/pluto-server/src/test/resources/application-itcase-osi-postfach.yml new file mode 100644 index 0000000000000000000000000000000000000000..32f273be9ff583fa0c62d3ed62548fecc1776f84 --- /dev/null +++ b/pluto-server/src/test/resources/application-itcase-osi-postfach.yml @@ -0,0 +1,9 @@ +kop: + osi: + postfach: + proxyapi: + url: http://localhost/ApiProxy/V1/Message + key: 1234 + realm: test-realm + notification: + mail-from: test@local.host diff --git a/pluto-server/src/test/resources/application-itcase.yml b/pluto-server/src/test/resources/application-itcase.yml index 8af9c9e7159165e85e36f6043041972ed5c60cc3..56b72852a2216fd652af827280df5ec833e763b4 100644 --- a/pluto-server/src/test/resources/application-itcase.yml +++ b/pluto-server/src/test/resources/application-itcase.yml @@ -12,15 +12,5 @@ grpc: aktenzeichen: de.itvsh.ozg.pluto.vorgang.AktenzeichenProviderEA -kop: - osi: - postfach: - proxyapi: - url: http://localhost/ApiProxy/V1/Message - key: 1234 - realm: test-realm - notification: - mail-from: test@local.host - mongock: enabled: false \ No newline at end of file diff --git a/pluto-server/src/test/resources/bayernid.p12 b/pluto-server/src/test/resources/bayernid.p12 new file mode 100644 index 0000000000000000000000000000000000000000..fa82ce9007cc50831496073cdb03d8b6a92b5ee4 Binary files /dev/null and b/pluto-server/src/test/resources/bayernid.p12 differ diff --git a/pluto-server/src/test/resources/bayernid/bsp-nachricht b/pluto-server/src/test/resources/bayernid/bsp-nachricht new file mode 100644 index 0000000000000000000000000000000000000000..531b80b0923fc7beb2dc147c62211019c539311f --- /dev/null +++ b/pluto-server/src/test/resources/bayernid/bsp-nachricht @@ -0,0 +1 @@ +<ns4:sendBspNachrichtNative xmlns:ns3="http://www.akdb.de/egov/bsp/nachrichten" xmlns:ns4="urn:akdb:bsp:postkorb:komm:webservice"><bspNachricht><?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:BspNachricht xmlns:ns2="http://www.akdb.de/egov/bsp/nachrichten" xmlns:ns3="urn:akdb:bsp:postkorb:komm:webservice"><ns2:NachrichtenKopf><ns2:Identifikation.Nachricht><ns2:Erstellungszeitpunkt>2020-04-01T10:30:10.000Z</ns2:Erstellungszeitpunkt><ns2:NachrichtenId>1</ns2:NachrichtenId></ns2:Identifikation.Nachricht><ns2:Absender><ns2:Dienst>Stadtverwaltung</ns2:Dienst><ns2:Mandant>Fürth</ns2:Mandant><ns2:Gemeindeschluessel><ns2:Tabelle>36</ns2:Tabelle><ns2:Schluessel>09563000</ns2:Schluessel></ns2:Gemeindeschluessel></ns2:Absender><ns2:Empfaenger><ns2:PostkorbId>1</ns2:PostkorbId></ns2:Empfaenger></ns2:NachrichtenKopf><ns2:NachrichtenInhalt><ns2:Betreff>Test Subject</ns2:Betreff><ns2:StorkQaaLevel>LEVEL_1</ns2:StorkQaaLevel><ns2:ZuVorgang><ns2:VorgangsId>1</ns2:VorgangsId></ns2:ZuVorgang><ns2:FreiText><ns2:Encoding><ns2:Tabelle>9004</ns2:Tabelle><ns2:Schluessel>text/plain</ns2:Schluessel></ns2:Encoding><ns2:Text>BodyString</ns2:Text></ns2:FreiText></ns2:NachrichtenInhalt></ns2:BspNachricht></bspNachricht></ns4:sendBspNachrichtNative> \ No newline at end of file diff --git a/pluto-server/src/test/resources/bayernid/bsp-quittung b/pluto-server/src/test/resources/bayernid/bsp-quittung new file mode 100644 index 0000000000000000000000000000000000000000..15782e2e4a0145479ce0cb7b9f222557bfff1064 --- /dev/null +++ b/pluto-server/src/test/resources/bayernid/bsp-quittung @@ -0,0 +1,9 @@ +<ns2:sendBspNachrichtNativeOutput xmlns:ns2="urn:akdb:bsp:postkorb:komm:webservice"><bspQuittung><?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<BspQuittung version="1.5" fassung="2020-03-15" xmlns="http://www.akdb.de/egov/bsp/nachrichten"> + <AnnahmeErfolgreich>true</AnnahmeErfolgreich> + <ErgebnisStatus> + <Tabelle>9006</Tabelle> + <Schluessel>0</Schluessel> + </ErgebnisStatus> +</BspQuittung> +</bspQuittung></ns2:sendBspNachrichtNativeOutput> \ No newline at end of file diff --git a/pluto-server/src/test/resources/bayernid/bsp-quittung-error-in-schema b/pluto-server/src/test/resources/bayernid/bsp-quittung-error-in-schema new file mode 100644 index 0000000000000000000000000000000000000000..a1cbbc080f03c8939b6f0de1c9b2ab71cd479bd1 --- /dev/null +++ b/pluto-server/src/test/resources/bayernid/bsp-quittung-error-in-schema @@ -0,0 +1,9 @@ +<ns2:sendBspNachrichtNativeOutput xmlns:ns2="urn:akdb:bsp:postkorb:komm:webservice"><bspQuittung><?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<BspQuittung version="1.5" fassung="2020-03-15" xmlns="http://www.akdb.de/egov/bsp/nachrichten"> + <AnnahmeErfolgreich>false</AnnahmeErfolgreich> + <ErgebnisStatus> + <Tabelle>9006</Tabelle> + <Schluessel>20</Schluessel> + </ErgebnisStatus> +</BspQuittung> +</bspQuittung></ns2:sendBspNachrichtNativeOutput> \ No newline at end of file