| 1 |
package test.message; |
| 2 |
|
| 3 |
import junit.framework.TestCase; |
| 4 |
import org.apache.axis.AxisEngine; |
| 5 |
import org.apache.axis.Constants; |
| 6 |
import org.apache.axis.Message; |
| 7 |
import org.apache.axis.MessageContext; |
| 8 |
import org.apache.axis.configuration.SimpleProvider; |
| 9 |
import org.apache.axis.message.SOAPEnvelope; |
| 10 |
import org.apache.axis.message.SOAPHeaderElement; |
| 11 |
import org.apache.axis.server.AxisServer; |
| 12 |
|
| 13 |
/** |
| 14 |
* This test confirms the behavior of the various possible values for |
| 15 |
* the mustUnderstand attribute in both SOAP 1.1 and SOAP 1.2. In particular: |
| 16 |
* |
| 17 |
* For SOAP 1.1, the only valid values are "0" and "1" |
| 18 |
* For SOAP 1.2, "0"/"false" and "1"/"true" are valid |
| 19 |
* |
| 20 |
* @author Glen Daniels ([email protected]) |
| 21 |
*/ |
| 22 |
public class TestMUValues extends TestCase { |
| 23 |
private AxisEngine engine; |
| 24 |
|
| 25 |
public TestMUValues(String name) { |
| 26 |
super(name); |
| 27 |
} |
| 28 |
|
| 29 |
private String header = |
| 30 |
"<?xml version=\"1.0\"?>\n" + |
| 31 |
"<soap:Envelope " + |
| 32 |
"xmlns:soap=\""; |
| 33 |
|
| 34 |
private String middle = "\">\n" + |
| 35 |
"<soap:Header>\n" + |
| 36 |
"<test soap:mustUnderstand=\""; |
| 37 |
|
| 38 |
private String footer = |
| 39 |
"\"/>\n" + |
| 40 |
"</soap:Header>\n" + |
| 41 |
"<soap:Body>\n" + |
| 42 |
"<noContent/>\n" + |
| 43 |
"</soap:Body>\n" + |
| 44 |
"</soap:Envelope>\n"; |
| 45 |
|
| 46 |
public void setUp() throws Exception { |
| 47 |
SimpleProvider provider = new SimpleProvider(); |
| 48 |
engine = new AxisServer(provider); |
| 49 |
} |
| 50 |
|
| 51 |
public void checkVal(String val, boolean desiredResult, String ns) |
| 52 |
throws Exception { |
| 53 |
String request = header + ns + middle + val + footer; |
| 54 |
|
| 55 |
// create a message in context |
| 56 |
MessageContext msgContext = new MessageContext(engine); |
| 57 |
Message message = new Message(request); |
| 58 |
message.setMessageContext(msgContext); |
| 59 |
|
| 60 |
// Parse the message and check the mustUnderstand value |
| 61 |
SOAPEnvelope envelope = message.getSOAPEnvelope(); |
| 62 |
SOAPHeaderElement header = envelope.getHeaderByName("", "test"); |
| 63 |
assertEquals("MustUnderstand value wasn't right using value '" + |
| 64 |
val + "'", |
| 65 |
desiredResult, header.getMustUnderstand()); |
| 66 |
} |
| 67 |
|
| 68 |
public void testMustUnderstandValues() throws Exception { |
| 69 |
String soap12 = Constants.URI_SOAP12_ENV; |
| 70 |
String soap11 = Constants.URI_SOAP11_ENV; |
| 71 |
|
| 72 |
checkVal("0", false, soap12); |
| 73 |
checkVal("1", true, soap12); |
| 74 |
checkVal("true", true, soap12); |
| 75 |
checkVal("false", false, soap12); |
| 76 |
try { |
| 77 |
checkVal("dennis", false, soap12); |
| 78 |
fail("Didn't throw exception with bad MU value"); |
| 79 |
} catch (Exception e) { |
| 80 |
} |
| 81 |
|
| 82 |
checkVal("0", false, soap11); |
| 83 |
checkVal("1", true, soap11); |
| 84 |
try { |
| 85 |
checkVal("true", false, soap11); |
| 86 |
fail("Didn't throw exception with bad MU value"); |
| 87 |
} catch (Exception e) { |
| 88 |
} |
| 89 |
try { |
| 90 |
checkVal("false", false, soap11); |
| 91 |
fail("Didn't throw exception with bad MU value"); |
| 92 |
} catch (Exception e) { |
| 93 |
} |
| 94 |
try { |
| 95 |
checkVal("dennis", false, soap11); |
| 96 |
fail("Didn't throw exception with bad MU value"); |
| 97 |
} catch (Exception e) { |
| 98 |
} |
| 99 |
} |
| 100 |
} |