From 7b3a0d2b5522ae4d43ef384e63d03d07438c23d9 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Tue, 19 Mar 2019 12:38:33 +0100 Subject: Add Unit Test Stub for App2MzsService - Unit test makes a http request to the service - Fix NPE by adding endpoint.setAdress("/") - Choose better name for App2MzsService --- .../java/at/gv/egiz/moazs/App2MzsServiceTest.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.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 new file mode 100644 index 0000000..836bfab --- /dev/null +++ b/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java @@ -0,0 +1,46 @@ +package at.gv.egiz.moazs; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringRunner; + +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 static java.net.http.HttpClient.*; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) + +public class App2MzsServiceTest { + + private final String serviceUri = "http://localhost:8080/services/DeliveryRequest"; + + private final String payloadFile = "src/test/resources/delivery_request_app2mzs.soap"; + + Logger logger = LoggerFactory.getLogger(App2MzsServiceTest.class); + + @Test + public void testService() throws IOException, InterruptedException { + + 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()); + } +} -- cgit v1.2.3