From a95679d191c2ac9cd4d61a5848240163e1676495 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Thu, 9 May 2019 16:12:08 +0200 Subject: Reactivate and Fix Unit Tests - Relax Validation for now by only validating incoming requests. --- src/main/java/at/gv/egiz/moazs/App2MzsService.java | 2 +- .../java/at/gv/egiz/moazs/App2MzsServiceTest.java | 57 ++++++++++------ .../App2MzsServiceTest/missingAppDeliveryId.soap | 75 ++++++++++++---------- .../moazs/App2MzsServiceTest/missingMetaData.soap | 70 ++++++++++---------- 4 files changed, 117 insertions(+), 87 deletions(-) (limited to 'src') diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsService.java b/src/main/java/at/gv/egiz/moazs/App2MzsService.java index 090bad3..6c59f85 100644 --- a/src/main/java/at/gv/egiz/moazs/App2MzsService.java +++ b/src/main/java/at/gv/egiz/moazs/App2MzsService.java @@ -22,7 +22,7 @@ import static java.text.MessageFormat.format; import static java.util.concurrent.CompletableFuture.supplyAsync; @Service -@SchemaValidation +@SchemaValidation(type = SchemaValidation.SchemaValidationType.IN) public class App2MzsService implements App2MzsPortType { private static final Logger logger = LoggerFactory.getLogger(App2MzsService.class); diff --git a/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java b/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java index f13a4dd..2924bf2 100644 --- a/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java +++ b/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java @@ -2,6 +2,7 @@ package at.gv.egiz.moazs; import at.gv.egiz.moazs.pipeline.DeliveryPipeline; import at.gv.egiz.moazs.repository.DeliveryRepository; +import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.DeliveryRequestStatusTypeBuilder; import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.Success.SuccessBuilder; import org.junit.Test; @@ -16,13 +17,19 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import org.springframework.test.context.junit4.SpringRunner; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.file.Paths; +import java.util.GregorianCalendar; +import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.Success.successBuilder; +import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder; import static java.net.http.HttpClient.Version; import static org.junit.Assert.assertEquals; @@ -48,17 +55,29 @@ public class App2MzsServiceTest { public DeliveryPipeline deliveryPipelineThatAlwaysSucceeds() { return appDeliveryId -> { - var success = new SuccessBuilder() + var success = successBuilder() + .withDeliverySystem("Test Delivery System") + .withZSDeliveryID("ZD-Delivery-ID") .withAppDeliveryID(appDeliveryId) + .withDeliveryTimestamp(genTimeStamp()) .build(); - var status = new DeliveryRequestStatusTypeBuilder() + var status = deliveryRequestStatusTypeBuilder() .withSuccess(success) .build(); repository.add(status); }; } + + private XMLGregorianCalendar genTimeStamp() { + try { + return DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()); + } catch (DatatypeConfigurationException e) { + throw new RuntimeException("ups"); + } + + } } @Test @@ -79,23 +98,23 @@ public class App2MzsServiceTest { assertEquals(500, response.statusCode()); } -// @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(500, response.statusCode()); -// } -// -// @Test -// public void rejectRequestWithoutMetaData() throws IOException, InterruptedException { -// var response = sendDeliveryRequestFile("missingMetaData.soap"); -// assertEquals(500, response.statusCode()); -// } + @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(500, response.statusCode()); + } + + @Test + public void rejectRequestWithoutMetaData() throws IOException, InterruptedException { + var response = sendDeliveryRequestFile("missingMetaData.soap"); + assertEquals(500, response.statusCode()); + } private HttpResponse sendDeliveryRequestFile(String fileName) throws IOException, InterruptedException { diff --git a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap index e981b31..e481caa 100644 --- a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap +++ b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap @@ -9,40 +9,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 - + + + kkvj693+tw99uW8UPuEK9en1LzZItkylPajkUUyJJDWQB78VGPkAuhCEk+TD12yQDD/WRglsf+JfQpjubIs/4l/ptluJ9teF3nwkNlu5Dm7mIjzgW1qxrDyomCmPvVxTWOCBuMUbOWRZBhOq+KvDQAu9Vv9KnqSfjYeDZrpHYu4= + urn:publicid:gv:at:cemtoken + + Bundesministerium für Testzwecke + + https://authority.gv.at/delivery_notification + + + + + Maxi + Mustermann1 + + 1984-01-24 + + + AT + 1010 + Wien + + Muststrasse + 10 + + + + + WichtigeMitteilung + RSa + + + 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 index 4a1e02d..cf55d6d 100644 --- a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingMetaData.soap +++ b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingMetaData.soap @@ -9,39 +9,43 @@ - - 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 - + + + kkvj693+tw99uW8UPuEK9en1LzZItkylPajkUUyJJDWQB78VGPkAuhCEk+TD12yQDD/WRglsf+JfQpjubIs/4l/ptluJ9teF3nwkNlu5Dm7mIjzgW1qxrDyomCmPvVxTWOCBuMUbOWRZBhOq+KvDQAu9Vv9KnqSfjYeDZrpHYu4= + urn:publicid:gv:at:cemtoken + + 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 + -- cgit v1.2.3