Debian Codegraph @

test/wsdl/qualify2/AttributeQualify_ServiceTestCase.java

raw
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;
30 import org.w3c.dom.Element;
31
32 import javax.xml.rpc.ServiceException;
33
34 public class AttributeQualify_ServiceTestCase extends junit.framework.TestCase {
35
36 public static final String NAMESPACE = "urn:attributeQualify";
37
38 public AttributeQualify_ServiceTestCase(String name) {
39 super(name);
40 }
41
42 public void test1AttributeQualifyEchoPhone() {
43 test.wsdl.qualify2.AttributeQualify_BindingStub binding;
44 test.wsdl.qualify2.AttributeQualify_ServiceLocator locator = new test.wsdl.qualify2.AttributeQualify_ServiceLocator();
45 try {
46 binding = (test.wsdl.qualify2.AttributeQualify_BindingStub)locator.getAttributeQualify();
47 }
48 catch (javax.xml.rpc.ServiceException 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 mc = binding._getCall().getMessageContext();
71 Message response = mc.getResponseMessage();
72 SOAPEnvelope env = response.getSOAPEnvelope();
73 String responseString = response.getSOAPPartAsString();
74
75 Element body;
76 try {
77 body = env.getFirstBody().getAsDOM();
78 } catch (Exception e) {
79 throw new AssertionFailedError("Unable to get request body as DOM Element on server");
80 }
81
82 // debug
83 //System.out.println("Response:\n---------\n" + responseString + "\n------");
84
85 // Now we have a DOM Element, verfy namespace attributes
86 // Here is what we think it looks like
87 // <phone age="35"
88 // ns1:color="red"
89 // ns1:hair="brown"
90 // xmlns:ns1="urn:attributeQualify">
91 // <areaCode>505</areaCode>
92 // <exchange>555</exchange>
93 // <number>1212</number>
94 //</phone>
95
96 String bodyNS = body.getNamespaceURI();
97 assertEquals("Namespace of body element incorrect", bodyNS, NAMESPACE);
98
99 // Verify age does NOT have a namespace (unqualified)
100 Attr ageAttr = body.getAttributeNode("age");
101 assertNull("namespace of attribute 'age' should be null",
102 ageAttr.getNamespaceURI());
103
104 // Verify hair and color have the right namespace (are qualified).
105 Attr hairAttr = body.getAttributeNodeNS(NAMESPACE, "hair");
106 assertNotNull("namespace of attribute 'hair' is not correct",
107 hairAttr);
108 Attr colorAttr = body.getAttributeNodeNS(NAMESPACE, "color");
109 assertNotNull("namespace of attribute 'color' is not correct",
110 colorAttr);
111
112 } catch (java.rmi.RemoteException re) {
113 throw new AssertionFailedError("Remote Exception caught: " + re);
114 }
115 }
116
117
118 }
119