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 --- .../java/at/gv/egiz/moazs/App2MzsServiceTest.java | 131 --------------------- src/test/java/at/gv/egiz/moazs/MzsServiceTest.java | 131 +++++++++++++++++++++ 2 files changed, 131 insertions(+), 131 deletions(-) delete mode 100644 src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java create mode 100644 src/test/java/at/gv/egiz/moazs/MzsServiceTest.java (limited to 'src/test/java/at/gv/egiz/moazs') 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()); + + } + +} -- cgit v1.2.3