package at.gv.egiz.moazs; 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 javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.nio.charset.StandardCharsets; import static org.assertj.core.api.Assertions.assertThat; public class SOAPUtilsTest { SOAPUtils utils; private static final String SOAP_MESSAGE = "" + "https://testzustellsystem.egiz.gv.atzs-valid-delivery-requ" + "est-idvalid-delivery-request-id12345" + ""; @Before public void setup() { utils = new SOAPUtils(); } @Test public void toDom() throws ParserConfigurationException, SAXException, IOException { byte[] bytes = SOAP_MESSAGE.getBytes(StandardCharsets.UTF_8); Element root = utils.toDOM(bytes); assertThat(root.getTagName()).isEqualTo("soap:Envelope"); } @Test public void unwrapSoapEnvelope() throws ParserConfigurationException, SAXException, IOException { byte[] bytes = SOAP_MESSAGE.getBytes(StandardCharsets.UTF_8); Element soapRoot = utils.toDOM(bytes); byte[] unwrappedMessage = utils.unwrapSoapEnvelope(soapRoot); Element deliveryResponseRoot = utils.toDOM(unwrappedMessage); assertThat(deliveryResponseRoot.getTagName()).isEqualTo("DeliveryResponse"); } @Test public void getAppDeliveryID() throws ParserConfigurationException, SAXException, IOException { byte[] bytes = SOAP_MESSAGE.getBytes(StandardCharsets.UTF_8); Element soapRoot = utils.toDOM(bytes); String appDeliveryID = utils.getAppDeliveryIDFrom(soapRoot); assertThat(appDeliveryID).isEqualTo("valid-delivery-request-id"); } }