KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > message > TestMUValues


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 (gdaniels@apache.org)
21  */

22 public class TestMUValues extends TestCase {
23     private AxisEngine engine;
24
25     public TestMUValues(String JavaDoc name) {
26         super(name);
27     }
28
29     private String JavaDoc header =
30         "<?xml version=\"1.0\"?>\n" +
31         "<soap:Envelope " +
32           "xmlns:soap=\"";
33     
34     private String JavaDoc middle = "\">\n" +
35           "<soap:Header>\n" +
36             "<test soap:mustUnderstand=\"";
37     
38     private String JavaDoc 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 JavaDoc {
47         SimpleProvider provider = new SimpleProvider();
48         engine = new AxisServer(provider);
49     }
50     
51     public void checkVal(String JavaDoc val, boolean desiredResult, String JavaDoc ns)
52             throws Exception JavaDoc {
53         String JavaDoc 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 JavaDoc {
69         String JavaDoc soap12 = Constants.URI_SOAP12_ENV;
70         String JavaDoc 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 JavaDoc 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 JavaDoc e) {
88         }
89         try {
90             checkVal("false", false, soap11);
91             fail("Didn't throw exception with bad MU value");
92         } catch (Exception JavaDoc e) {
93         }
94         try {
95             checkVal("dennis", false, soap11);
96             fail("Didn't throw exception with bad MU value");
97         } catch (Exception JavaDoc e) {
98         }
99     }
100 }
101
Popular Tags