From 96f82d09c22853ce3b37db0983ce6ccc34c2587f Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Mon, 20 May 2019 08:18:53 +0200 Subject: Add Testcase for MsgClient --- src/main/java/at/gv/egiz/moazs/msg/MsgClient.java | 1 - src/main/resources/application.properties | 1 - src/main/resources/application.yaml | 2 +- src/test/java/at/gv/egiz/moazs/MsgClientTest.java | 74 ++++++++++++++++++++++ .../at/gv/egiz/moazs/Mzs2MsgConverterTest.java | 2 + .../moazs/MsgClientTest/validDeliveryRequest.xml | 56 ++++++++++++++++ 6 files changed, 133 insertions(+), 3 deletions(-) delete mode 100644 src/main/resources/application.properties create mode 100644 src/test/java/at/gv/egiz/moazs/MsgClientTest.java create mode 100644 src/test/resources/at/gv/egiz/moazs/MsgClientTest/validDeliveryRequest.xml diff --git a/src/main/java/at/gv/egiz/moazs/msg/MsgClient.java b/src/main/java/at/gv/egiz/moazs/msg/MsgClient.java index 5742c83..47ee8c3 100644 --- a/src/main/java/at/gv/egiz/moazs/msg/MsgClient.java +++ b/src/main/java/at/gv/egiz/moazs/msg/MsgClient.java @@ -11,7 +11,6 @@ import org.springframework.stereotype.Component; public class MsgClient { public DeliveryRequestStatusType send(DeliveryRequestType msgRequest, ConfigType config) { - var address = config.getServer().getZUSEUrlID(); var proxy = connect(address); return proxy.delivery(msgRequest); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 8b13789..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 9e987bf..a59c460 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -14,7 +14,7 @@ spring: delivery-request-configuration-profiles: default: msg: - url: http://localhost:8090/ + url: http://localhost:8081/ x509: todo! perform-query-person-request: false diff --git a/src/test/java/at/gv/egiz/moazs/MsgClientTest.java b/src/test/java/at/gv/egiz/moazs/MsgClientTest.java new file mode 100644 index 0000000..6dc94e0 --- /dev/null +++ b/src/test/java/at/gv/egiz/moazs/MsgClientTest.java @@ -0,0 +1,74 @@ +package at.gv.egiz.moazs; + +import at.gv.egiz.moazs.msg.MsgClient; +import at.gv.egiz.moazs.scheme.Marshaller; +import at.gv.zustellung.app2mzs.xsd.ConfigType; +import at.gv.zustellung.msg.xsd.DeliveryRequestType; +import at.gv.zustellung.msg.xsd.ObjectFactory; +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.test.context.junit4.SpringRunner; + +import javax.xml.bind.JAXBElement; +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.IOException; + +import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; +import static at.gv.zustellung.app2mzs.xsd.ServerType.serverTypeBuilder; + + +@RunWith(SpringRunner.class) +@SpringBootTest +public class MsgClientTest { + + private final static Logger logger = LoggerFactory.getLogger(MsgClient.class); + + private final String serviceUri = "http://localhost:8081/services/DeliveryRequest"; + private final String basePath = "src/test/resources/at/gv/egiz/moazs/MsgClientTest/"; + + @Autowired + private Marshaller msgMarshaller; + + private static final ObjectFactory OF = new ObjectFactory(); + + + // this test requires that a zusemsg service runs under serviceUri! + + @Test + public void sendValidMessage() throws IOException { + + var request = loadFromFile("validDeliveryRequest.xml"); + var config = generateConfig(); + var client = new MsgClient(); + + var status = client.send(request, config); + + logger.info("status: " + msgMarshaller.marshallXml(OF.createDeliveryRequestStatus(status))); + } + + private DeliveryRequestType loadFromFile(String fileName) throws IOException { + try (var inputStream = new BufferedInputStream(new FileInputStream(basePath + fileName))) { + var request = (JAXBElement) msgMarshaller.unmarshallXml(inputStream); + return request.getValue(); + } + } + + private ConfigType generateConfig() { + + var server = serverTypeBuilder() + .withZUSEUrlID(serviceUri) + .build(); + + return configTypeBuilder() + .withServer(server) + .withPerformQueryPersonRequest(false) + .build(); + + } + +} diff --git a/src/test/java/at/gv/egiz/moazs/Mzs2MsgConverterTest.java b/src/test/java/at/gv/egiz/moazs/Mzs2MsgConverterTest.java index 2564121..de72148 100644 --- a/src/test/java/at/gv/egiz/moazs/Mzs2MsgConverterTest.java +++ b/src/test/java/at/gv/egiz/moazs/Mzs2MsgConverterTest.java @@ -52,6 +52,8 @@ public class Mzs2MsgConverterTest { String msgRequestXML = msgMarshaller.marshallXml(jaxbMsgRequest); + logger.info(msgRequestXML); + assertThat(msgRequestXML).contains("valid-delivery-request-id"); } diff --git a/src/test/resources/at/gv/egiz/moazs/MsgClientTest/validDeliveryRequest.xml b/src/test/resources/at/gv/egiz/moazs/MsgClientTest/validDeliveryRequest.xml new file mode 100644 index 0000000..f1879eb --- /dev/null +++ b/src/test/resources/at/gv/egiz/moazs/MsgClientTest/validDeliveryRequest.xml @@ -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 + + + + brief.xml + text/xml + 123401 + + SHA1 + 9b972c70fdaf5e1b26b3387c87b0ffb72e5940b6 + + https://authority.gv.at/files/73bdf969781ba41fa07df1ff8439cf685c0db1c3 + + + \ No newline at end of file -- cgit v1.2.3