aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at/gv/egiz/moazs/SOAPUtilsTest.java
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-22 13:02:19 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-22 13:02:19 +0200
commitcb9a76eaafd37f921006822bcfe043655288bc63 (patch)
tree76c2463e181ac293134f4c5bfc7e342607f3f399 /src/test/java/at/gv/egiz/moazs/SOAPUtilsTest.java
parentd873625c0ced62e712dc1b1a7570b63482fd0a0a (diff)
downloadmoa-zs-cb9a76eaafd37f921006822bcfe043655288bc63.tar.gz
moa-zs-cb9a76eaafd37f921006822bcfe043655288bc63.tar.bz2
moa-zs-cb9a76eaafd37f921006822bcfe043655288bc63.zip
Test Flow of DeliveryRequest from "End-To-End" & Fix Bugs
Schema Changes: - Remove mzs:DeliveryRequest/TnvzMetaData because all metadata fields can be collected from DeliveryRequest and redundancy is not needed. Fixes and Refactoring in preprocess: - MzsDeliveryRequestValidator: Instead of returning false, throw an exception when a condition is not met, and explain which condition is not met / why it is not met in the exception's message. - Integrate interface change in ConfigProfileGenerator and DeliveryRequestAugmenter. - Rewrite and simplify DeliveryRequestAugmenter's augmentation. - ConfigUtil Fixes: Ensure that we do not override the wrong parameters while merging. This error appeared in tnvz / msg client, connection / receive timeout, key / trust store, and lax hostname verification / trust all. Fix Bugs in Interceptor / SoapUtils: - Problem: DOM access and information extraction was implemented somewhat sloppy. - SolutioN: Change DOM access interface to access DOM more efficiently. Add boundary checks and handle edge cases while extracting information from SOAP Messages. - Test those changes properly. Testing: - Implement Delivery Request Flow in ITEndToEndTest. - Start application on random port instead of fixed port when running integration tests. - Add assertions to tests in ITMzsServiceTest suite. Others Bug Fixes: - ServicesConfig: Ensure that mzs service and msg service run on different endpoint addresses (/msg and /mzs). - DeliveryRequestBackend: Throw exception when binary message is missing. Don't wrap the exception. - SaveResponseToFileSink: Wrap Response in JAXB Element (otherwise, marshaller does not recognize it)
Diffstat (limited to 'src/test/java/at/gv/egiz/moazs/SOAPUtilsTest.java')
-rw-r--r--src/test/java/at/gv/egiz/moazs/SOAPUtilsTest.java143
1 files changed, 127 insertions, 16 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/SOAPUtilsTest.java b/src/test/java/at/gv/egiz/moazs/SOAPUtilsTest.java
index 31aa197..ff0060e 100644
--- a/src/test/java/at/gv/egiz/moazs/SOAPUtilsTest.java
+++ b/src/test/java/at/gv/egiz/moazs/SOAPUtilsTest.java
@@ -4,10 +4,8 @@ import at.gv.egiz.moazs.scheme.SOAPUtils;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
+import org.w3c.dom.Node;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.IOException;
import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
@@ -25,39 +23,152 @@ public class SOAPUtilsTest {
"est-id</ZSDeliveryID><AppDeliveryID>valid-delivery-request-id</AppDeliveryID><GZ>12345</GZ>" +
"</PartialSuccess></DeliveryResponse></soap:Body></soap:Envelope>";
+
+ public static final String FORMATTED_MESSAGE =
+ "<soapenv:Envelope\n" +
+ " xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
+ " xmlns:msg=\"http://reference.e-government.gv.at/namespace/zustellung/msg/phase2/20181206#\">\n" +
+ " <soapenv:Body>\n" +
+ " <msg:DeliveryNotification>\n" +
+ " <msg:AppDeliveryID>formatted-adid</msg:AppDeliveryID>\n" +
+ " </msg:DeliveryNotification>\n" +
+ " </soapenv:Body>\n" +
+ "</soapenv:Envelope>\n";
+
+ public static final String CLUTTERED_MESSAGE =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<soapenv:Envelope " +
+ " xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n " +
+ " xmlns:msg=\"http://reference.e-government.gv.at/namespace/zustellung/msg/phase2/20181206#\">\n" +
+ " <soapenv:Body unexpected-attribute=\"unexpectedvalue\"> \n" +
+ " <msg:DeliveryNotification>\n" +
+ " <msg:AppDeliveryID attribute=\"some-value\"><element-that-got-lost />cluttered-adid</msg:AppDeliveryID>\n" +
+ " </msg:DeliveryNotification>\n" +
+ " </soapenv:Body>\n" +
+ "</soapenv:Envelope>\n";
+
+ private static final String MISSING_BODY_MESSAGE =
+ "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><NotABodyTag></NotABodyTag></soap:Envelope>";
+
+ private static final String EMPTY_BODY_MESSAGE =
+ "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body> </soap:Body></soap:Envelope>";
+
+ public static final String EMPTY_APP_DELIVERY_ID_MESSAGE =
+ "<soapenv:Envelope\n" +
+ " xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
+ " xmlns:msg=\"http://reference.e-government.gv.at/namespace/zustellung/msg/phase2/20181206#\">\n" +
+ " <soapenv:Body>\n" +
+ " <msg:DeliveryNotification>\n" +
+ " <msg:AppDeliveryID />\n" +
+ " </msg:DeliveryNotification>\n" +
+ " </soapenv:Body>\n" +
+ "</soapenv:Envelope>\n";
+
+ public static final String BLANK_APP_DELIVERY_ID_MESSAGE =
+ "<soapenv:Envelope\n" +
+ " xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
+ " xmlns:msg=\"http://reference.e-government.gv.at/namespace/zustellung/msg/phase2/20181206#\">\n" +
+ " <soapenv:Body>\n" +
+ " <msg:DeliveryNotification>\n" +
+ " <msg:AppDeliveryID> </msg:AppDeliveryID>\n" +
+ " </msg:DeliveryNotification>\n" +
+ " </soapenv:Body>\n" +
+ "</soapenv:Envelope>\n";
+
@Before
public void setup() {
utils = new SOAPUtils();
}
@Test
- public void toDom() throws ParserConfigurationException, SAXException, IOException {
- byte[] bytes = SOAP_MESSAGE.getBytes(StandardCharsets.UTF_8);
+ public void canParseSoapMessage() throws Exception {
+ parseAndCheckLocalName(SOAP_MESSAGE);
+ }
+
+ @Test
+ public void canParseFormattedSoapMessage() throws Exception {
+ parseAndCheckLocalName(FORMATTED_MESSAGE);
+ }
+
+ @Test
+ public void canParseClutteredSoapMessage() throws Exception {
+ parseAndCheckLocalName(CLUTTERED_MESSAGE);
+ }
+ private void parseAndCheckLocalName(String text) throws Exception {
+ byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
Element root = utils.toDOM(bytes);
+ assertThat(root.getLocalName()).isEqualTo("Envelope");
+ }
+
+ @Test
+ public void canUnwrapSoapMessage() throws Exception {
+ getFirstChildAndCheckLocalName(SOAP_MESSAGE, "DeliveryResponse");
+ }
- assertThat(root.getTagName()).isEqualTo("soap:Envelope");
+ @Test
+ public void canUnwrapFormattedSoapMessage() throws Exception {
+ getFirstChildAndCheckLocalName(FORMATTED_MESSAGE, "DeliveryNotification");
}
@Test
- public void unwrapSoapEnvelope() throws ParserConfigurationException, SAXException, IOException {
- byte[] bytes = SOAP_MESSAGE.getBytes(StandardCharsets.UTF_8);
+ public void canUnwrapClutteredSoapMessage() throws Exception {
+ getFirstChildAndCheckLocalName(CLUTTERED_MESSAGE, "DeliveryNotification");
+ }
+
+ @Test(expected=MoaZSException.class)
+ public void failUnwrapMissingBody() throws Exception {
+ getFirstChildAndCheckLocalName(MISSING_BODY_MESSAGE, "");
+ }
+
+ @Test(expected=MoaZSException.class)
+ public void failUnwrapEmptyBody() throws Exception {
+ getFirstChildAndCheckLocalName(EMPTY_BODY_MESSAGE, "");
+ }
+
+ private void getFirstChildAndCheckLocalName(String message, String expectedLocalNameOfChild) throws Exception {
+ byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
Element soapRoot = utils.toDOM(bytes);
+ Node child = utils.getChildElementOfSoapBody(soapRoot);
+ var actualLocalName = child.getLocalName();
+ assertThat(actualLocalName).isEqualTo(expectedLocalNameOfChild);
+ }
- byte[] unwrappedMessage = utils.unwrapSoapEnvelope(soapRoot);
+ @Test
+ public void getAppDeliveryIDFromSoapMessage() throws Exception {
+ getAppDeliveryIDAndCheck(SOAP_MESSAGE, "valid-delivery-request-id");
+ }
- Element deliveryResponseRoot = utils.toDOM(unwrappedMessage);
- assertThat(deliveryResponseRoot.getTagName()).isEqualTo("DeliveryResponse");
+ @Test
+ public void getAppDeliveryIDFromFormattedMessage() throws Exception {
+ getAppDeliveryIDAndCheck(FORMATTED_MESSAGE, "formatted-adid");
}
@Test
- public void getAppDeliveryID() throws ParserConfigurationException, SAXException, IOException {
- byte[] bytes = SOAP_MESSAGE.getBytes(StandardCharsets.UTF_8);
- Element soapRoot = utils.toDOM(bytes);
+ public void getAppDeliveryIDFromClutteredMessage() throws Exception {
+ getAppDeliveryIDAndCheck(CLUTTERED_MESSAGE, "cluttered-adid");
+ }
+
+ @Test(expected = MoaZSException.class)
+ public void failToRetrieveAppDeliveryIDWhenBodyIsMissing() throws Exception {
+ getAppDeliveryIDAndCheck(MISSING_BODY_MESSAGE, "");
+ }
- String appDeliveryID = utils.getAppDeliveryIDFrom(soapRoot);
+ @Test(expected = MoaZSException.class)
+ public void failToRetrieveEmptyAppDeliveryID() throws Exception {
+ getAppDeliveryIDAndCheck(EMPTY_APP_DELIVERY_ID_MESSAGE, "");
+ }
+
+ @Test(expected = MoaZSException.class)
+ public void failToRetrieveBlankAppDeliveryID() throws Exception {
+ getAppDeliveryIDAndCheck(BLANK_APP_DELIVERY_ID_MESSAGE, "");
+ }
- assertThat(appDeliveryID).isEqualTo("valid-delivery-request-id");
+ private void getAppDeliveryIDAndCheck(String message, String expectedValue) throws Exception {
+ byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
+ Element soapRoot = utils.toDOM(bytes);
+ String actualAppDeliveryID = utils.getAppDeliveryIDFrom(soapRoot);
+ assertThat(actualAppDeliveryID).isEqualTo(expectedValue);
}
}