diff options
Diffstat (limited to 'src/test/java/at')
-rw-r--r-- | src/test/java/at/gv/egiz/moazs/ITEndToEndTest.java | 14 | ||||
-rw-r--r-- | src/test/java/at/gv/egiz/moazs/ITForwardResponseTest.java | 121 | ||||
-rw-r--r-- | src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java | 12 | ||||
-rw-r--r-- | src/test/java/at/gv/egiz/moazs/TestUtils.java | 13 |
4 files changed, 137 insertions, 23 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/ITEndToEndTest.java b/src/test/java/at/gv/egiz/moazs/ITEndToEndTest.java index 5baddfc..eb761ec 100644 --- a/src/test/java/at/gv/egiz/moazs/ITEndToEndTest.java +++ b/src/test/java/at/gv/egiz/moazs/ITEndToEndTest.java @@ -34,7 +34,6 @@ import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; import at.gv.zustellung.msg.xsd.DeliveryRequestType; import at.gv.zustellung.tnvz.xsd.TNVZServicePort; import org.apache.commons.io.FileUtils; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; @@ -50,25 +49,16 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.PostConstruct; import java.io.File; 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.charset.StandardCharsets; -import java.nio.file.Paths; import java.util.Collection; import java.util.List; import java.util.function.Consumer; -import static at.gv.egiz.moazs.TestUtils.formatFile; -import static at.gv.egiz.moazs.TestUtils.sendSOAP; +import static at.gv.egiz.moazs.TestUtils.*; import static at.gv.zustellung.app2mzs.xsd.DeliveryNotificationACKType.deliveryNotificationACKTypeBuilder; import static at.gv.zustellung.app2mzs.xsd.persondata.IdentificationType.Value.valueBuilder; import static at.gv.zustellung.app2mzs.xsd.persondata.IdentificationType.identificationTypeBuilder; import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.PartialSuccess.partialSuccessBuilder; import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder; -import static java.net.http.HttpResponse.BodyHandlers.ofString; -import static org.apache.commons.io.FileUtils.readFileToString; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.Mockito.*; @@ -188,7 +178,7 @@ public class ITEndToEndTest { //prepare var appDeliveryID = "delivery-request-id"; var zsDeliveryID = "ZSDID-" + appDeliveryID; - var timestamp = ITMzsServiceTest.genTimeStamp().toXMLFormat(); + var timestamp = genTimeStamp().toXMLFormat(); var saveSinkFolder = "target/tmp/ITEndToEndTestOut"; delete(saveSinkFolder); diff --git a/src/test/java/at/gv/egiz/moazs/ITForwardResponseTest.java b/src/test/java/at/gv/egiz/moazs/ITForwardResponseTest.java new file mode 100644 index 0000000..34935ee --- /dev/null +++ b/src/test/java/at/gv/egiz/moazs/ITForwardResponseTest.java @@ -0,0 +1,121 @@ +package at.gv.egiz.moazs; + + +import at.gv.zustellung.app2mzs.xsd.ConfigType; +import at.gv.zustellung.app2mzs.xsd.DeliveryNotificationACKType; +import at.gv.zustellung.app2mzs.xsd.DeliveryNotificationType; +import at.gv.zustellung.app2mzs.xsd.Mzs2AppPortType; +import com.skjolberg.mockito.soap.SoapServiceRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.stubbing.Answer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.PostConstruct; +import java.io.IOException; +import java.util.Map; + +import static at.gv.egiz.moazs.TestUtils.*; +import static at.gv.egiz.moazs.preprocess.ConfigProfileGenerator.DEFAULT_CONFIG_KEY; +import static at.gv.zustellung.app2mzs.xsd.DeliveryNotificationACKType.deliveryNotificationACKTypeBuilder; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = {MoaZS.class}) +@TestPropertySource(locations = {"/config/application.yaml"}, properties = { + "delivery-request-configuration-profiles.default.msg-response-sinks.forward-response-to-service.active:true" +}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class ITForwardResponseTest { + + @Autowired + private Map<String, ConfigType> deliveryRequestConfigs; + + @LocalServerPort + public int port; + + @Rule + public SoapServiceRule soap = SoapServiceRule.newInstance(); + + private Mzs2AppPortType mzs2appPort; + private final String notificationPath = "src/test/resources/at/gv/egiz/moazs/ITEndToEndTest/msg-delivery-notification.xml"; + private String frontendURI; + + @PostConstruct + void init() { + frontendURI = "http://localhost:" + port + "/services/msg/"; + } + + @Before + public void setup() { + var clientParameters = deliveryRequestConfigs.get(DEFAULT_CONFIG_KEY) + .getMsgResponseSinks() + .getForwardResponseToService() + .getAppClient(); + + mzs2appPort = soap.mock(Mzs2AppPortType.class, clientParameters.getURL()); + } + + @Test + public void ackSuccessfulReceipt() throws IOException, InterruptedException { + + when(mzs2appPort.forwardNotification(any())).thenAnswer(acknowledge()); + + var appDeliveryID = "ack-successful-receipt"; + var zsDeliveryID = "ZSDID-" + appDeliveryID; + var timestamp = genTimeStamp().toXMLFormat(); + var notification = formatFile(notificationPath, new String[] { + "any-system", zsDeliveryID, appDeliveryID, "any-watermark", timestamp, timestamp}); + + var response = sendSOAP(frontendURI, notification); + assertThat(response.body()).contains("DeliveryNotificationACK", appDeliveryID); + + } + + private Answer<DeliveryNotificationACKType> acknowledge() { + return i -> { + var notification = (DeliveryNotificationType) i.getArgument(0); + var appDeliveryID = notification.getSuccess().getAppDeliveryID(); + return deliveryNotificationACKTypeBuilder() + .withAppDeliveryID(appDeliveryID) + .build(); + }; + } + + @Test + public void nackFaultyReceipt() throws IOException, InterruptedException { + + when(mzs2appPort.forwardNotification(any())).thenAnswer(fault()); + + var appDeliveryID = "nack-faulty-receipt"; + var zsDeliveryID = "ZSDID-" + appDeliveryID; + var timestamp = genTimeStamp().toXMLFormat(); + var notification = formatFile(notificationPath, new String[] { + "any-system", zsDeliveryID, appDeliveryID, "any-watermark", timestamp, timestamp}); + + var response = sendSOAP(frontendURI, notification); + assertThat(response.body()).contains("soap:Fault"); + + } + + private Answer<DeliveryNotificationACKType> fault() { + return i -> { + throw new RuntimeException("Service offline"); + }; + } + + + + + + +} diff --git a/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java b/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java index e33a9cd..5719814 100644 --- a/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java +++ b/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java @@ -35,18 +35,15 @@ 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 java.util.function.Consumer; +import static at.gv.egiz.moazs.TestUtils.genTimeStamp; 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; @@ -153,13 +150,6 @@ public class ITMzsServiceTest { } - public static XMLGregorianCalendar genTimeStamp() { - try { - return DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()); - } catch (DatatypeConfigurationException e) { - throw new RuntimeException("ups"); - } - } } diff --git a/src/test/java/at/gv/egiz/moazs/TestUtils.java b/src/test/java/at/gv/egiz/moazs/TestUtils.java index 96d3a22..8120af1 100644 --- a/src/test/java/at/gv/egiz/moazs/TestUtils.java +++ b/src/test/java/at/gv/egiz/moazs/TestUtils.java @@ -2,6 +2,9 @@ package at.gv.egiz.moazs; import org.apache.commons.io.FileUtils; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; import java.io.File; import java.io.IOException; import java.net.URI; @@ -9,6 +12,7 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; +import java.util.GregorianCalendar; import static java.net.http.HttpResponse.BodyHandlers.ofString; @@ -33,4 +37,13 @@ public class TestUtils { return client.send(request, ofString()); } + + public static XMLGregorianCalendar genTimeStamp() { + try { + return DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()); + } catch (DatatypeConfigurationException e) { + throw new RuntimeException("ups"); + } + + } } |