From 5e6304ee003285793c0992a81e424969a2a6af88 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Wed, 15 May 2019 15:44:44 +0200 Subject: Move Services / Clients To Dedicated Packages --- src/main/java/at/gv/egiz/moazs/App2MzsService.java | 99 ---------------- src/main/java/at/gv/egiz/moazs/MoaZS.java | 13 ++ src/main/java/at/gv/egiz/moazs/Mzs2AppClient.java | 13 -- src/main/java/at/gv/egiz/moazs/MzsApp.java | 13 -- .../gv/egiz/moazs/config/App2MzsServiceConfig.java | 30 ----- .../at/gv/egiz/moazs/config/MzsServiceConfig.java | 30 +++++ src/main/java/at/gv/egiz/moazs/mzs/MzsClient.java | 13 ++ src/main/java/at/gv/egiz/moazs/mzs/MzsService.java | 100 ++++++++++++++++ .../java/at/gv/egiz/moazs/App2MzsServiceTest.java | 131 --------------------- src/test/java/at/gv/egiz/moazs/MzsServiceTest.java | 131 +++++++++++++++++++++ .../formallyIncorrectDeliveryRequest.soap | 53 --------- .../App2MzsServiceTest/missingAppDeliveryId.soap | 55 --------- .../moazs/App2MzsServiceTest/missingMetaData.soap | 51 -------- .../moazs/App2MzsServiceTest/missingSender.soap | 46 -------- .../profileAndCorporateBody.soap | 59 ---------- .../App2MzsServiceTest/validDeliveryRequest.soap | 56 --------- .../formallyIncorrectDeliveryRequest.soap | 53 +++++++++ .../moazs/MzsServiceTest/missingAppDeliveryId.soap | 55 +++++++++ .../egiz/moazs/MzsServiceTest/missingMetaData.soap | 51 ++++++++ .../egiz/moazs/MzsServiceTest/missingSender.soap | 46 ++++++++ .../MzsServiceTest/profileAndCorporateBody.soap | 59 ++++++++++ .../moazs/MzsServiceTest/validDeliveryRequest.soap | 56 +++++++++ 22 files changed, 607 insertions(+), 606 deletions(-) delete mode 100644 src/main/java/at/gv/egiz/moazs/App2MzsService.java create mode 100644 src/main/java/at/gv/egiz/moazs/MoaZS.java delete mode 100644 src/main/java/at/gv/egiz/moazs/Mzs2AppClient.java delete mode 100644 src/main/java/at/gv/egiz/moazs/MzsApp.java delete mode 100644 src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java create mode 100644 src/main/java/at/gv/egiz/moazs/config/MzsServiceConfig.java create mode 100644 src/main/java/at/gv/egiz/moazs/mzs/MzsClient.java create mode 100644 src/main/java/at/gv/egiz/moazs/mzs/MzsService.java delete mode 100644 src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java create mode 100644 src/test/java/at/gv/egiz/moazs/MzsServiceTest.java delete mode 100644 src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/formallyIncorrectDeliveryRequest.soap delete mode 100644 src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap delete mode 100644 src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingMetaData.soap delete mode 100644 src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingSender.soap delete mode 100644 src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/profileAndCorporateBody.soap delete mode 100644 src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/validDeliveryRequest.soap create mode 100644 src/test/resources/at/gv/egiz/moazs/MzsServiceTest/formallyIncorrectDeliveryRequest.soap create mode 100644 src/test/resources/at/gv/egiz/moazs/MzsServiceTest/missingAppDeliveryId.soap create mode 100644 src/test/resources/at/gv/egiz/moazs/MzsServiceTest/missingMetaData.soap create mode 100644 src/test/resources/at/gv/egiz/moazs/MzsServiceTest/missingSender.soap create mode 100644 src/test/resources/at/gv/egiz/moazs/MzsServiceTest/profileAndCorporateBody.soap create mode 100644 src/test/resources/at/gv/egiz/moazs/MzsServiceTest/validDeliveryRequest.soap diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsService.java b/src/main/java/at/gv/egiz/moazs/App2MzsService.java deleted file mode 100644 index 19eb856..0000000 --- a/src/main/java/at/gv/egiz/moazs/App2MzsService.java +++ /dev/null @@ -1,99 +0,0 @@ -package at.gv.egiz.moazs; - -import at.gv.egiz.moazs.pipeline.DeliveryPipeline; -import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter; -import at.gv.egiz.moazs.repository.DeliveryRepository; -import at.gv.zustellung.app2mzs.xsd.App2MzsPortType; -import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; -import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; -import org.apache.cxf.annotations.SchemaValidation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import javax.jws.WebParam; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import static at.gv.egiz.moazs.MoaZSException.moaZSException; -import static at.gv.zustellung.msg.xsd.DeliveryAnswerType.deliveryAnswerTypeBuilder; -import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder; -import static java.lang.String.format; -import static java.util.concurrent.CompletableFuture.supplyAsync; - -//todo : validate Schema in both directions. -@Service -@SchemaValidation(type = SchemaValidation.SchemaValidationType.IN) -public class App2MzsService implements App2MzsPortType { - - private static final Logger logger = LoggerFactory.getLogger(App2MzsService.class); - - //TODO move timeout and namespaces to config - private static final int TIMEOUT_FOR_ANWSER = 10; - - private final DeliveryRepository repository; - private final DeliveryPipeline pipeline; - private final Mzs2AppClient appClient; - private final DeliveryRequestAugmenter augmenter; - - @Autowired - public App2MzsService(DeliveryRepository repository, DeliveryPipeline pipeline, Mzs2AppClient appClient, - DeliveryRequestAugmenter augmenter) { - this.repository = repository; - this.pipeline = pipeline; - this.appClient = appClient; - this.augmenter = augmenter; - } - - @Override - public DeliveryRequestStatusType app2Mzs( - @WebParam(partName = "DeliveryRequest", - name = "DeliveryRequest") - DeliveryRequestType deliveryRequest) { - - var appDeliveryID = deliveryRequest.getMetaData().getAppDeliveryID(); - - var future = supplyAsync(() -> augmenter.augment(deliveryRequest)) - .thenApply(this::process); - - try { - return future.get(TIMEOUT_FOR_ANWSER, TimeUnit.SECONDS); - } catch (TimeoutException e) { - future.thenAccept(appClient::sendNotification); - logger.info("Answer Timed Out", e); - return generatePartialSuccessResponse(appDeliveryID); - - } catch (Exception e ) { - var message = format("An error occurred while processing DeliveryRequest with AppDeliveryID=%s. ", appDeliveryID); - throw new MoaZSException(message, e); - - } - - } - - private DeliveryRequestStatusType process(DeliveryRequestType deliveryRequest) { - - var appDeliveryID = deliveryRequest.getMetaData().getAppDeliveryID(); - logger.info("Receive request with appDeliveryID = {}.", appDeliveryID); - - repository.add(deliveryRequest); - pipeline.processRequest(appDeliveryID); - - return repository.getDeliveryRequestStatus(appDeliveryID) - .orElseThrow(() -> moaZSException("Could not get a response for AppDeliveryID=%s.", appDeliveryID)); - - } - - private DeliveryRequestStatusType generatePartialSuccessResponse(String appDeliveryId) { - - var answer = deliveryAnswerTypeBuilder() - .withAppDeliveryID(appDeliveryId) - .build(); - - return deliveryRequestStatusTypeBuilder() - .withPartialSuccess(answer) - .build(); - } - -} diff --git a/src/main/java/at/gv/egiz/moazs/MoaZS.java b/src/main/java/at/gv/egiz/moazs/MoaZS.java new file mode 100644 index 0000000..3009745 --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/MoaZS.java @@ -0,0 +1,13 @@ +package at.gv.egiz.moazs; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MoaZS { + + public static void main(String[] args) { + SpringApplication.run(MoaZS.class, args); + } +} diff --git a/src/main/java/at/gv/egiz/moazs/Mzs2AppClient.java b/src/main/java/at/gv/egiz/moazs/Mzs2AppClient.java deleted file mode 100644 index a7a52bf..0000000 --- a/src/main/java/at/gv/egiz/moazs/Mzs2AppClient.java +++ /dev/null @@ -1,13 +0,0 @@ -package at.gv.egiz.moazs; - -import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; -import org.springframework.stereotype.Component; - -@Component -public class Mzs2AppClient { - - public void sendNotification(DeliveryRequestStatusType status) { - throw new UnsupportedOperationException("Not implemented."); - } - -} diff --git a/src/main/java/at/gv/egiz/moazs/MzsApp.java b/src/main/java/at/gv/egiz/moazs/MzsApp.java deleted file mode 100644 index 6b4e34b..0000000 --- a/src/main/java/at/gv/egiz/moazs/MzsApp.java +++ /dev/null @@ -1,13 +0,0 @@ -package at.gv.egiz.moazs; - - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class MzsApp { - - public static void main(String[] args) { - SpringApplication.run(MzsApp.class, args); - } -} diff --git a/src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java b/src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java deleted file mode 100644 index 9bf03fb..0000000 --- a/src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -package at.gv.egiz.moazs.config; - -import at.gv.egiz.moazs.App2MzsService; -import at.gv.zustellung.app2mzs.xsd.App2Mzs; -import org.apache.cxf.Bus; -import org.apache.cxf.jaxws.EndpointImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.xml.ws.Endpoint; - -@Configuration -public class App2MzsServiceConfig { - - @Bean - @Autowired - public Endpoint endpoint(Bus bus, App2MzsService app2mzsService, App2Mzs app2mzs) { - EndpointImpl endpoint = new EndpointImpl(bus, app2mzsService); - endpoint.setAddress("/"); - endpoint.setServiceName(app2mzs.getServiceName()); - endpoint.setWsdlLocation(app2mzs.getWSDLDocumentLocation().toString()); - endpoint.publish(); - return endpoint; - } - - @Bean public App2Mzs app2mzs() { - return new App2Mzs(); - } -} diff --git a/src/main/java/at/gv/egiz/moazs/config/MzsServiceConfig.java b/src/main/java/at/gv/egiz/moazs/config/MzsServiceConfig.java new file mode 100644 index 0000000..713c616 --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/config/MzsServiceConfig.java @@ -0,0 +1,30 @@ +package at.gv.egiz.moazs.config; + +import at.gv.egiz.moazs.mzs.MzsService; +import at.gv.zustellung.app2mzs.xsd.App2Mzs; +import org.apache.cxf.Bus; +import org.apache.cxf.jaxws.EndpointImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.xml.ws.Endpoint; + +@Configuration +public class MzsServiceConfig { + + @Bean + @Autowired + public Endpoint endpoint(Bus bus, MzsService mzsService, App2Mzs app2mzs) { + EndpointImpl endpoint = new EndpointImpl(bus, mzsService); + endpoint.setAddress("/"); + endpoint.setServiceName(app2mzs.getServiceName()); + endpoint.setWsdlLocation(app2mzs.getWSDLDocumentLocation().toString()); + endpoint.publish(); + return endpoint; + } + + @Bean public App2Mzs app2mzs() { + return new App2Mzs(); + } +} diff --git a/src/main/java/at/gv/egiz/moazs/mzs/MzsClient.java b/src/main/java/at/gv/egiz/moazs/mzs/MzsClient.java new file mode 100644 index 0000000..5785703 --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/mzs/MzsClient.java @@ -0,0 +1,13 @@ +package at.gv.egiz.moazs.mzs; + +import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; +import org.springframework.stereotype.Component; + +@Component +public class MzsClient { + + public void sendNotification(DeliveryRequestStatusType status) { + throw new UnsupportedOperationException("Not implemented."); + } + +} diff --git a/src/main/java/at/gv/egiz/moazs/mzs/MzsService.java b/src/main/java/at/gv/egiz/moazs/mzs/MzsService.java new file mode 100644 index 0000000..774f7f4 --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/mzs/MzsService.java @@ -0,0 +1,100 @@ +package at.gv.egiz.moazs.mzs; + +import at.gv.egiz.moazs.MoaZSException; +import at.gv.egiz.moazs.pipeline.DeliveryPipeline; +import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter; +import at.gv.egiz.moazs.repository.DeliveryRepository; +import at.gv.zustellung.app2mzs.xsd.App2MzsPortType; +import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; +import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; +import org.apache.cxf.annotations.SchemaValidation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.jws.WebParam; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static at.gv.egiz.moazs.MoaZSException.moaZSException; +import static at.gv.zustellung.msg.xsd.DeliveryAnswerType.deliveryAnswerTypeBuilder; +import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder; +import static java.lang.String.format; +import static java.util.concurrent.CompletableFuture.supplyAsync; + +//todo : validate Schema in both directions. +@Service +@SchemaValidation(type = SchemaValidation.SchemaValidationType.IN) +public class MzsService implements App2MzsPortType { + + private static final Logger logger = LoggerFactory.getLogger(MzsService.class); + + //TODO move timeout and namespaces to config + private static final int TIMEOUT_FOR_ANWSER = 10; + + private final DeliveryRepository repository; + private final DeliveryPipeline pipeline; + private final MzsClient appClient; + private final DeliveryRequestAugmenter augmenter; + + @Autowired + public MzsService(DeliveryRepository repository, DeliveryPipeline pipeline, MzsClient appClient, + DeliveryRequestAugmenter augmenter) { + this.repository = repository; + this.pipeline = pipeline; + this.appClient = appClient; + this.augmenter = augmenter; + } + + @Override + public DeliveryRequestStatusType app2Mzs( + @WebParam(partName = "DeliveryRequest", + name = "DeliveryRequest") + DeliveryRequestType deliveryRequest) { + + var appDeliveryID = deliveryRequest.getMetaData().getAppDeliveryID(); + + var future = supplyAsync(() -> augmenter.augment(deliveryRequest)) + .thenApply(this::process); + + try { + return future.get(TIMEOUT_FOR_ANWSER, TimeUnit.SECONDS); + } catch (TimeoutException e) { + future.thenAccept(appClient::sendNotification); + logger.info("Answer Timed Out", e); + return generatePartialSuccessResponse(appDeliveryID); + + } catch (Exception e ) { + var message = format("An error occurred while processing DeliveryRequest with AppDeliveryID=%s.", appDeliveryID); + throw new MoaZSException(message, e); + + } + + } + + private DeliveryRequestStatusType process(DeliveryRequestType deliveryRequest) { + + var appDeliveryID = deliveryRequest.getMetaData().getAppDeliveryID(); + logger.info("Receive request with appDeliveryID = {}.", appDeliveryID); + + repository.add(deliveryRequest); + pipeline.processRequest(appDeliveryID); + + return repository.getDeliveryRequestStatus(appDeliveryID) + .orElseThrow(() -> moaZSException("Could not get a response for AppDeliveryID=%s.", appDeliveryID)); + + } + + private DeliveryRequestStatusType generatePartialSuccessResponse(String appDeliveryId) { + + var answer = deliveryAnswerTypeBuilder() + .withAppDeliveryID(appDeliveryId) + .build(); + + return deliveryRequestStatusTypeBuilder() + .withPartialSuccess(answer) + .build(); + } + +} diff --git a/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java b/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java deleted file mode 100644 index 2d4d65f..0000000 --- a/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java +++ /dev/null @@ -1,131 +0,0 @@ -package at.gv.egiz.moazs; - -import at.gv.egiz.moazs.pipeline.DeliveryPipeline; -import at.gv.egiz.moazs.repository.DeliveryRepository; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.context.TestConfiguration; -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; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) - -public class App2MzsServiceTest { - - private final String serviceUri = "http://localhost:8080/services/DeliveryRequest"; - - private final String basePath = "src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/"; - - private final static Logger logger = LoggerFactory.getLogger(App2MzsServiceTest.class); - - @TestConfiguration - public static class TestConfig { - - @Autowired - private DeliveryRepository repository; - - @Bean - @Primary - public DeliveryPipeline deliveryPipelineThatAlwaysSucceeds() { - return appDeliveryId -> { - - var success = successBuilder() - .withDeliverySystem("Test Delivery System") - .withZSDeliveryID("ZD-Delivery-ID") - .withAppDeliveryID(appDeliveryId) - .withDeliveryTimestamp(genTimeStamp()) - .build(); - - 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 - public void acceptValidDeliveryRequest() throws IOException, InterruptedException { - var response = sendDeliveryRequestFile("validDeliveryRequest.soap"); - assertEquals(200, response.statusCode()); - } - - @Test - public void rejectRequestWithoutSender() throws IOException, InterruptedException { - var response = sendDeliveryRequestFile("missingSender.soap"); - assertEquals(500, response.statusCode()); - } - - @Test - public void rejectBothProfileAndCorporateBody() throws IOException, InterruptedException { - var response = sendDeliveryRequestFile("profileAndCorporateBody.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 { - - 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(path))) - .build(); - - return client.send(request, HttpResponse.BodyHandlers.ofString()); - - } - -} diff --git a/src/test/java/at/gv/egiz/moazs/MzsServiceTest.java b/src/test/java/at/gv/egiz/moazs/MzsServiceTest.java new file mode 100644 index 0000000..579051d --- /dev/null +++ b/src/test/java/at/gv/egiz/moazs/MzsServiceTest.java @@ -0,0 +1,131 @@ +package at.gv.egiz.moazs; + +import at.gv.egiz.moazs.pipeline.DeliveryPipeline; +import at.gv.egiz.moazs.repository.DeliveryRepository; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.context.TestConfiguration; +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; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) + +public class MzsServiceTest { + + private final String serviceUri = "http://localhost:8080/services/DeliveryRequest"; + + private final String basePath = "src/test/resources/at/gv/egiz/moazs/MzsServiceTest/"; + + private final static Logger logger = LoggerFactory.getLogger(MzsServiceTest.class); + + @TestConfiguration + public static class TestConfig { + + @Autowired + private DeliveryRepository repository; + + @Bean + @Primary + public DeliveryPipeline deliveryPipelineThatAlwaysSucceeds() { + return appDeliveryId -> { + + var success = successBuilder() + .withDeliverySystem("Test Delivery System") + .withZSDeliveryID("ZD-Delivery-ID") + .withAppDeliveryID(appDeliveryId) + .withDeliveryTimestamp(genTimeStamp()) + .build(); + + 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 + public void acceptValidDeliveryRequest() throws IOException, InterruptedException { + var response = sendDeliveryRequestFile("validDeliveryRequest.soap"); + assertEquals(200, response.statusCode()); + } + + @Test + public void rejectRequestWithoutSender() throws IOException, InterruptedException { + var response = sendDeliveryRequestFile("missingSender.soap"); + assertEquals(500, response.statusCode()); + } + + @Test + public void rejectBothProfileAndCorporateBody() throws IOException, InterruptedException { + var response = sendDeliveryRequestFile("profileAndCorporateBody.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 { + + 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(path))) + .build(); + + 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 deleted file mode 100644 index 0570005..0000000 --- a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/formallyIncorrectDeliveryRequest.soap +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - SampleProfile2 - - - - - - Maxi - Mustermann1 - - 1984-01-24 - - - AT - 1010 - Wien - - Muststrasse - 10 - - - - - formally-incorrect-delivery-request-id - nonRSa - false - - - - - Hello There! - -

How are you

-

Nice to hear from you!

-

Regards, V

- -
-
- deckblatt -
- - -
-
diff --git a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap deleted file mode 100644 index e481caa..0000000 --- a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingAppDeliveryId.soap +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - 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 deleted file mode 100644 index cf55d6d..0000000 --- a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingMetaData.soap +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - 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 - - - - diff --git a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingSender.soap b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingSender.soap deleted file mode 100644 index 62cda34..0000000 --- a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/missingSender.soap +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - Maxi - Mustermann1 - - 1984-01-24 - - - AT - 1010 - Wien - - Muststrasse - 10 - - - - - valid-delivery-request-id - 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/profileAndCorporateBody.soap b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/profileAndCorporateBody.soap deleted file mode 100644 index 3e52062..0000000 --- a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/profileAndCorporateBody.soap +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - 132456 - - - - 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 - - - - - valid-delivery-request-id - 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/validDeliveryRequest.soap b/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/validDeliveryRequest.soap deleted file mode 100644 index 519749c..0000000 --- a/src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/validDeliveryRequest.soap +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - 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 - - - - - valid-delivery-request-id - 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/MzsServiceTest/formallyIncorrectDeliveryRequest.soap b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/formallyIncorrectDeliveryRequest.soap new file mode 100644 index 0000000..0570005 --- /dev/null +++ b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/formallyIncorrectDeliveryRequest.soap @@ -0,0 +1,53 @@ + + + + + + SampleProfile2 + + + + + + Maxi + Mustermann1 + + 1984-01-24 + + + AT + 1010 + Wien + + Muststrasse + 10 + + + + + formally-incorrect-delivery-request-id + nonRSa + false + + + + + Hello There! + +

How are you

+

Nice to hear from you!

+

Regards, V

+ +
+
+ deckblatt +
+ + +
+
diff --git a/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/missingAppDeliveryId.soap b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/missingAppDeliveryId.soap new file mode 100644 index 0000000..e481caa --- /dev/null +++ b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/missingAppDeliveryId.soap @@ -0,0 +1,55 @@ + + + + + + + + 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/MzsServiceTest/missingMetaData.soap b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/missingMetaData.soap new file mode 100644 index 0000000..cf55d6d --- /dev/null +++ b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/missingMetaData.soap @@ -0,0 +1,51 @@ + + + + + + + + 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 + + + + diff --git a/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/missingSender.soap b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/missingSender.soap new file mode 100644 index 0000000..62cda34 --- /dev/null +++ b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/missingSender.soap @@ -0,0 +1,46 @@ + + + + + + + + Maxi + Mustermann1 + + 1984-01-24 + + + AT + 1010 + Wien + + Muststrasse + 10 + + + + + valid-delivery-request-id + 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/MzsServiceTest/profileAndCorporateBody.soap b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/profileAndCorporateBody.soap new file mode 100644 index 0000000..3e52062 --- /dev/null +++ b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/profileAndCorporateBody.soap @@ -0,0 +1,59 @@ + + + + + + + 132456 + + + + 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 + + + + + valid-delivery-request-id + 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/MzsServiceTest/validDeliveryRequest.soap b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/validDeliveryRequest.soap new file mode 100644 index 0000000..519749c --- /dev/null +++ b/src/test/resources/at/gv/egiz/moazs/MzsServiceTest/validDeliveryRequest.soap @@ -0,0 +1,56 @@ + + + + + + + + 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 + + + + + valid-delivery-request-id + WichtigeMitteilung + RSa + + + https://authority.gv.at/files/73bdf969781ba41fa07df1ff8439cf685c0db1c3 + brief.xml + text/xml + + SHA1 + 9b972c70fdaf5e1b26b3387c87b0ffb72e5940b6 + + 123401 + + + + -- cgit v1.2.3