From 296d842878e530ee819fa2f58012665b76e2e670 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Tue, 30 Apr 2019 11:00:46 +0200 Subject: Add Optional mzs:DeliveryRequest/Config & Validate / Augment It Add Optional "Config" to MZS Schema: - Add mzs:DeliveryRequest/Config Element with a "PerformQueryPersonRequest" node - The config element contains parameters that are interpreted by moa-zs and not forwarded to the ZD - The boolean PerformQueryPersonRequest tells moa-zs if moa-zs should perform a QueryPersonRequest towards the TNVZ. - If config is missing, moa-zs augments the delivery request with parameters from the app's configuartion or the default configuartion Other Changes: - Validate and augment incoming requests with the DeliveryPreprocessor. - Add stub for TlnvzClient. - Remove some leftover ObjectFactory imports (because of the builder they are not needed anymore) Fixes - Fixed incorrect API usage of Messageformat.format: format string needs an index. pom.xml - Add Hamcrest Dependency (for writing more expressive tests) - Add copy constructor to JAXB Builder Testing - Test validation of incoming request - Refactor testcases to improve readability --- .../java/at/gv/egiz/moazs/App2MzsServiceTest.java | 47 +++++++++++---------- .../formallyIncorrectDeliveryRequest.soap | 2 +- .../App2MzsServiceTest/missingAppDeliveryId.soap | 48 ++++++++++++++++++++++ .../moazs/App2MzsServiceTest/missingMetaData.soap | 47 +++++++++++++++++++++ .../App2MzsServiceTest/validDeliveryRequest.soap | 2 +- 5 files changed, 123 insertions(+), 23 deletions(-) create mode 100644 src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap create mode 100644 src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingMetaData.soap (limited to 'src/test') diff --git a/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java b/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java index 5579f06..03992ae 100644 --- a/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java +++ b/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java @@ -6,6 +6,7 @@ import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.D import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ObjectFactory; import at.gv.egiz.moazs.pipeline.DeliveryPipeline; import at.gv.egiz.moazs.repository.DeliveryRepository; +import org.hamcrest.Matchers; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; @@ -24,9 +25,12 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.file.Paths; +import java.util.Arrays; import static java.net.http.HttpClient.Version; -import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.text.StringContainsInOrder.stringContainsInOrder; +import static org.junit.Assert.assertEquals; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) @@ -63,42 +67,43 @@ public class App2MzsServiceTest { } } - @Test public void acceptValidDeliveryRequest() throws IOException, InterruptedException { + var response = sendDeliveryRequestFile("validDeliveryRequest.soap"); + assertEquals(200, response.statusCode()); + } - final String payloadFile = basePath + "validDeliveryRequest.soap"; - - var client = HttpClient.newBuilder().version(Version.HTTP_1_1).build(); - var request = HttpRequest.newBuilder() - .uri(URI.create(serviceUri)) - .header("Content-Type", "text/xml;charset=UTF-8") - .header("SOAPAction", "\"\"") - .POST(HttpRequest.BodyPublishers.ofFile(Paths.get(payloadFile))) - .build(); - - var response = client.send(request, HttpResponse.BodyHandlers.ofString()); - logger.info("response.body was " + response.body()); - logger.info("response.code was " + response.statusCode()); - assertThat(response.statusCode()).isEqualTo(200); + @Test + public void rejectFormallyIncorrectDeliveryRequest() throws IOException, InterruptedException { + var response = sendDeliveryRequestFile("formallyIncorrectDeliveryRequest.soap"); + assertEquals(500, response.statusCode()); + } + @Test + public void rejectRequestWithoutAppDeliveryID() throws IOException, InterruptedException { + var response = sendDeliveryRequestFile("missingAppDeliveryId.soap"); + assertEquals(200, response.statusCode()); + assertThat(response.body(), stringContainsInOrder(Arrays.asList("Code>", "500", "/", "Code>"))); } @Test - public void rejectFormallyIncorrectDeliveryRequest() throws IOException, InterruptedException { + public void rejectRequestWithoutMetaData() throws IOException, InterruptedException { + var response = sendDeliveryRequestFile("missingMetaData.soap"); + assertEquals(500, response.statusCode()); + } - var invalidDeliveryRequest = basePath + "formallyIncorrectDeliveryRequest.soap"; + private HttpResponse sendDeliveryRequestFile(String fileName) throws IOException, InterruptedException { + var path = basePath + fileName; var client = HttpClient.newBuilder().version(Version.HTTP_1_1).build(); var request = HttpRequest.newBuilder() .uri(URI.create(serviceUri)) .header("Content-Type", "text/xml;charset=UTF-8") .header("SOAPAction", "\"\"") - .POST(HttpRequest.BodyPublishers.ofFile(Paths.get(invalidDeliveryRequest))) + .POST(HttpRequest.BodyPublishers.ofFile(Paths.get(path))) .build(); - var response = client.send(request, HttpResponse.BodyHandlers.ofString()); - assertThat(response.statusCode()).isEqualTo(500); + return client.send(request, HttpResponse.BodyHandlers.ofString()); } diff --git a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/formallyIncorrectDeliveryRequest.soap b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/formallyIncorrectDeliveryRequest.soap index e8bd7f2..0570005 100644 --- a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/formallyIncorrectDeliveryRequest.soap +++ b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/formallyIncorrectDeliveryRequest.soap @@ -30,7 +30,7 @@ - asd + formally-incorrect-delivery-request-id nonRSa false diff --git a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap new file mode 100644 index 0000000..e981b31 --- /dev/null +++ b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap @@ -0,0 +1,48 @@ + + + + + + + Bundesministerium für Testzwecke + + https://authority.gv.at/delivery_notification + + + + + Maxi + Mustermann1 + + 1984-01-24 + + + AT + 1010 + Wien + + Muststrasse + 10 + + + + + + https://authority.gv.at/files/73bdf969781ba41fa07df1ff8439cf685c0db1c3 + brief.xml + text/xml + + SHA1 + 9b972c70fdaf5e1b26b3387c87b0ffb72e5940b6 + + 123401 + + + + diff --git a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingMetaData.soap b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingMetaData.soap new file mode 100644 index 0000000..4a1e02d --- /dev/null +++ b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingMetaData.soap @@ -0,0 +1,47 @@ + + + + + + + Bundesministerium für Testzwecke + + https://authority.gv.at/delivery_notification + + + + + Maxi + Mustermann1 + + 1984-01-24 + + + AT + 1010 + Wien + + Muststrasse + 10 + + + + + https://authority.gv.at/files/73bdf969781ba41fa07df1ff8439cf685c0db1c3 + brief.xml + text/xml + + SHA1 + 9b972c70fdaf5e1b26b3387c87b0ffb72e5940b6 + + 123401 + + + + diff --git a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/validDeliveryRequest.soap b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/validDeliveryRequest.soap index d71939b..dcd8c5f 100644 --- a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/validDeliveryRequest.soap +++ b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/validDeliveryRequest.soap @@ -33,7 +33,7 @@ - asd + valid-delivery-request-id WichtigeMitteilung RSa -- cgit v1.2.3