KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > qualify2 > AttributeQualify_ServiceTestCase


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /**
17  * Qualify_ServiceTestCase.java
18  *
19  * This file was auto-generated from WSDL
20  * by the Apache Axis Wsdl2java emitter.
21  */

22
23 package test.wsdl.qualify2;
24
25 import junit.framework.AssertionFailedError;
26 import org.apache.axis.Message;
27 import org.apache.axis.MessageContext;
28 import org.apache.axis.message.SOAPEnvelope;
29 import org.w3c.dom.Attr JavaDoc;
30 import org.w3c.dom.Element JavaDoc;
31
32 import javax.xml.rpc.ServiceException JavaDoc;
33
34 public class AttributeQualify_ServiceTestCase extends junit.framework.TestCase {
35
36     public static final String JavaDoc NAMESPACE = "urn:attributeQualify";
37
38     public AttributeQualify_ServiceTestCase(String JavaDoc name) {
39         super(name);
40     }
41
42     public void test1AttributeQualifyEchoPhone() {
43         test.wsdl.qualify2.AttributeQualify_Port binding;
44         test.wsdl.qualify2.AttributeQualify_ServiceLocator locator = new test.wsdl.qualify2.AttributeQualify_ServiceLocator();
45         try {
46             binding = locator.getAttributeQualify();
47         }
48         catch (javax.xml.rpc.ServiceException JavaDoc jre) {
49             throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
50         }
51         assertTrue("binding is null", binding != null);
52
53         try {
54             test.wsdl.qualify2.Phone phone = new Phone();
55             phone.setAge(35);
56             phone.setAreaCode(505);
57             phone.setColor("red");
58             phone.setExchange("555");
59             phone.setHair("brown");
60             phone.setNumber("1212");
61             
62             Phone result = binding.echoPhone(phone);
63             
64             // Check the response
65
assertTrue(result.equals(phone));
66
67             // Validate XML reponse to make sure attributes are properly
68
// qualified or not per the WSDL
69
MessageContext mc = null;
70             try {
71                 mc = locator.getCall().getMessageContext();
72             } catch (ServiceException JavaDoc e) {
73                 throw new AssertionFailedError("Unable to get call object from service");
74             }
75             Message response = mc.getResponseMessage();
76             SOAPEnvelope env = response.getSOAPEnvelope();
77             String JavaDoc responseString = response.getSOAPPartAsString();
78
79             Element JavaDoc body;
80             try {
81                 body = env.getFirstBody().getAsDOM();
82             } catch (Exception JavaDoc e) {
83                 throw new AssertionFailedError("Unable to get request body as DOM Element on server");
84             }
85
86             // debug
87
//System.out.println("Response:\n---------\n" + responseString + "\n------");
88

89             // Now we have a DOM Element, verfy namespace attributes
90
// Here is what we think it looks like
91
// <phone age="35"
92
// ns1:color="red"
93
// ns1:hair="brown"
94
// xmlns:ns1="urn:attributeQualify">
95
// <areaCode>505</areaCode>
96
// <exchange>555</exchange>
97
// <number>1212</number>
98
//</phone>
99

100             String JavaDoc bodyNS = body.getNamespaceURI();
101             assertEquals("Namespace of body element incorrect", bodyNS, NAMESPACE);
102
103             // Verify age does NOT have a namespace (unqualified)
104
Attr JavaDoc ageAttr = body.getAttributeNode("age");
105             assertNull("namespace of attribute 'age' should be null",
106                        ageAttr.getNamespaceURI());
107             
108             // Verify hair and color have the right namespace (are qualified).
109
Attr JavaDoc hairAttr = body.getAttributeNodeNS(NAMESPACE, "hair");
110             assertNotNull("namespace of attribute 'hair' is not correct",
111                          hairAttr);
112             Attr JavaDoc colorAttr = body.getAttributeNodeNS(NAMESPACE, "color");
113             assertNotNull("namespace of attribute 'color' is not correct",
114                          colorAttr);
115             
116         } catch (java.rmi.RemoteException JavaDoc re) {
117             throw new AssertionFailedError("Remote Exception caught: " + re);
118         }
119     }
120
121
122 }
123
124
Popular Tags