aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-03-19 12:38:33 +0100
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-03-19 12:38:33 +0100
commit7b3a0d2b5522ae4d43ef384e63d03d07438c23d9 (patch)
treeb58c0caad983f02a133845e59099fbd9d8e0add4
parent4fb466ee906d7442b059bc62fde13463ca6c4173 (diff)
downloadmoa-zs-7b3a0d2b5522ae4d43ef384e63d03d07438c23d9.tar.gz
moa-zs-7b3a0d2b5522ae4d43ef384e63d03d07438c23d9.tar.bz2
moa-zs-7b3a0d2b5522ae4d43ef384e63d03d07438c23d9.zip
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
-rw-r--r--src/main/java/at/gv/egiz/moazs/App2MzsService.java (renamed from src/main/java/at/gv/egiz/moazs/App2MzsPortTypeImplementation.java)2
-rw-r--r--src/main/java/at/gv/egiz/moazs/App2MzsServiceConfig.java (renamed from src/main/java/at/gv/egiz/moazs/App2MzsEndpointConfig.java)5
-rw-r--r--src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java46
-rw-r--r--src/test/resources/delivery_request_app2mzs.soap52
4 files changed, 102 insertions, 3 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsPortTypeImplementation.java b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
index 244cf4d..ccca4f5 100644
--- a/src/main/java/at/gv/egiz/moazs/App2MzsPortTypeImplementation.java
+++ b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
@@ -8,7 +8,7 @@ import at.gv.e_government.reference.namespace.moazs10.app2mzs_.SuccessType;
import javax.jws.WebParam;
-public class App2MzsPortTypeImplementation implements App2MzsPortType {
+public class App2MzsService implements App2MzsPortType {
@Override
public DeliveryResponseType app2Mzs(
diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsEndpointConfig.java b/src/main/java/at/gv/egiz/moazs/App2MzsServiceConfig.java
index 2d524df..64e353d 100644
--- a/src/main/java/at/gv/egiz/moazs/App2MzsEndpointConfig.java
+++ b/src/main/java/at/gv/egiz/moazs/App2MzsServiceConfig.java
@@ -9,14 +9,15 @@ import org.springframework.context.annotation.Configuration;
import javax.xml.ws.Endpoint;
@Configuration
-public class App2MzsEndpointConfig {
+public class App2MzsServiceConfig {
@Autowired
private Bus bus;
@Bean
public Endpoint endpoint() {
- EndpointImpl endpoint = new EndpointImpl(bus, new App2MzsPortTypeImplementation());
+ EndpointImpl endpoint = new EndpointImpl(bus, new App2MzsService());
+ endpoint.setAddress("/");
endpoint.publish();
return endpoint;
}
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());
+ }
+}
diff --git a/src/test/resources/delivery_request_app2mzs.soap b/src/test/resources/delivery_request_app2mzs.soap
new file mode 100644
index 0000000..662a161
--- /dev/null
+++ b/src/test/resources/delivery_request_app2mzs.soap
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<soapenv:Envelope
+ xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:mzs="http://reference.e-government.gv.at/namespace/moazs10/app2mzs#"
+ xmlns:p="http://reference.e-government.gv.at/namespace/persondata/20020228#"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+<soapenv:Body>
+<mzs:DeliveryRequest>
+ <mzs:Sender>
+ <mzs:ProfileID>SampleProfile2</mzs:ProfileID>
+ <mzs:SignatureKeyID></mzs:SignatureKeyID>
+ </mzs:Sender>
+ <mzs:Receiver>
+ <p:PhysicalPerson>
+ <p:Name>
+ <p:GivenName>Maxi</p:GivenName>
+ <p:FamilyName>Mustermann1</p:FamilyName>
+ </p:Name>
+ <p:DateOfBirth>1984-01-24</p:DateOfBirth>
+ </p:PhysicalPerson>
+ <p:PostalAddress>
+ <p:CountryCode>AT</p:CountryCode>
+ <p:PostalCode>1010</p:PostalCode>
+ <p:Municipality>Wien</p:Municipality>
+ <p:DeliveryAddress>
+ <p:StreetName>Muststrasse</p:StreetName>
+ <p:BuildingNumber>10</p:BuildingNumber>
+ </p:DeliveryAddress>
+ </p:PostalAddress>
+ </mzs:Receiver>
+ <mzs:MetaData>
+ <mzs:AppDeliveryID>asd</mzs:AppDeliveryID>
+ <mzs:DeliveryQuality>nonRSa</mzs:DeliveryQuality>
+ <mzs:RequiresEncryption>false</mzs:RequiresEncryption>
+ </mzs:MetaData>
+ <mzs:XMLDocument>
+ <mzs:XMLContent>
+ <message>
+ <subject>Hello There!</subject>
+ <body>
+ <p>How are you</p>
+ <p>Nice to hear from you!</p>
+ <p>Regards, V</p>
+ </body>
+ </message>
+ </mzs:XMLContent>
+ <mzs:XMLProfileID>deckblatt</mzs:XMLProfileID>
+ </mzs:XMLDocument>
+</mzs:DeliveryRequest>
+</soapenv:Body>
+</soapenv:Envelope>