aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at/gv/egiz/moazs/ITForwardResponseTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/at/gv/egiz/moazs/ITForwardResponseTest.java')
-rw-r--r--src/test/java/at/gv/egiz/moazs/ITForwardResponseTest.java121
1 files changed, 121 insertions, 0 deletions
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");
+ };
+ }
+
+
+
+
+
+
+}