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 ++++++++++++---------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'src/test/java/at/gv') 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()); } -- cgit v1.2.3