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/test/java/at/gv/egiz/moazs/MsgClientTest.java | 74 ++++++++++++++++++++++ .../at/gv/egiz/moazs/Mzs2MsgConverterTest.java | 2 + .../moazs/MsgClientTest/validDeliveryRequest.xml | 56 ++++++++++++++++ 3 files changed, 132 insertions(+) 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 (limited to 'src/test') 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