1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.ws.utils;
17
18 import org.junit.Test;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNull;
22 import static org.openehealth.ipf.commons.ihe.ws.utils.SoapUtils.extractSoapBody;
23
24 public class TestSoapUtils {
25
26 private final String contents =
27 "<ns2:ImportantQuestion>" +
28 "Camel rules as cigarettes as well. Do Apache Indians smoke it?" +
29 "</ns2:ImportantQuestion>";
30
31 private final String envelopeWithNamespacePrefixes =
32 "<soap:Envelope><soap:Header>" +
33 " <thirdns:header value=\"12345\">some text</thirdns:header></soap:Header>" +
34 " <soap:Body>" +
35 contents +
36 "</soap:Body></soap:Envelope>";
37
38 private final String envelopeWithoutNamespacePrefixes =
39 "<Envelope><Header>" +
40 " <thirdns:header value=\"12345\">some text</thirdns:header></Header>" +
41 " <Body>" +
42 contents +
43 "</Body></Envelope>";
44
45 private final String emptyEnvelopeWithNamespacePrefixes =
46 "<soap:Envelope><soap:Header>" +
47 " <thirdns:header value=\"12345\">some text</thirdns:header></soap:Header>" +
48 " <soap:Body xmlns:prefix=\"uri\"></soap:Body></soap:Envelope>";
49
50 private final String emptyEnvelopeWithoutNamespacePrefixes =
51 "<Envelope><Header>" +
52 " <thirdns:header value=\"12345\">some text</thirdns:header></Header>" +
53 " <Body></Body></Envelope>";
54
55 private final String emptyEnvelopeWithNamespacePrefixesShort =
56 "<soap:Envelope><soap:Header>" +
57 " <thirdns:header value=\"12345\">some text</thirdns:header></soap:Header>" +
58 " <soap:Body attrib=\"value\" /></soap:Envelope>";
59
60 private final String emptyEnvelopeWithoutNamespacePrefixesShort =
61 "<Envelope><Header>" +
62 " <thirdns:header value=\"12345\">some text</thirdns:header></Header>" +
63 " <Body /></Envelope>";
64
65 private final String totallyBad = "12345";
66
67
68 @Test
69 public void testExctractSoapBody() {
70 assertEquals(contents, extractSoapBody(envelopeWithNamespacePrefixes));
71 assertEquals(contents, extractSoapBody(envelopeWithoutNamespacePrefixes));
72
73 assertEquals("", extractSoapBody(emptyEnvelopeWithNamespacePrefixes));
74 assertEquals("", extractSoapBody(emptyEnvelopeWithoutNamespacePrefixes));
75 assertEquals("", extractSoapBody(emptyEnvelopeWithNamespacePrefixesShort));
76 assertEquals("", extractSoapBody(emptyEnvelopeWithoutNamespacePrefixesShort));
77
78 assertNull(extractSoapBody(null));
79 assertEquals(totallyBad, extractSoapBody(totallyBad));
80 }
81
82 }