From 5cb5e4803e315bb717c9db882f60c848da8e660c Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Mon, 9 Dec 2019 09:36:48 +0100 Subject: Add "Forward-Response-to-Service" Test Cases - Refactor: Move genTimestamp from ITMzsServiceTest to TestUtils (because needed in multiple test cases). - application.yaml: Complete app-client config in config profile. --- .../at/gv/egiz/moazs/ITForwardResponseTest.java | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 src/test/java/at/gv/egiz/moazs/ITForwardResponseTest.java (limited to 'src/test/java/at/gv/egiz/moazs/ITForwardResponseTest.java') 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 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 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 fault() { + return i -> { + throw new RuntimeException("Service offline"); + }; + } + + + + + + +} -- cgit v1.2.3