Debian Codegraph @

test/wsdl/qualify/Qualify_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.qualify;
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.Element;
30 import org.w3c.dom.Node;
31
32 import javax.xml.rpc.ServiceException;
33
34 public class Qualify_ServiceTestCase extends junit.framework.TestCase {
35
36 public static final String namespace = "urn:qualifyTest";
37
38 public Qualify_ServiceTestCase(String name) {
39 super(name);
40 }
41
42 public void test1QualifySimple() {
43 Qualify_ServiceLocator locator = new Qualify_ServiceLocator();
44 Qualify_BindingStub binding;
45 try {
46 binding = (Qualify_BindingStub)locator.getQualify();
47 } catch (javax.xml.rpc.ServiceException jre) {
48 throw new AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
49 }
50 assertTrue("binding is null", binding != null);
51
52 try {
53 String value = null;
54 String name = "Tommy";
55 value = binding.simple(name);
56
57 // Validate XML reponse to make sure elements are properly qualified
58 // or not per the WSDL
59 MessageContext mc = null;
60 mc = binding._getCall().getMessageContext();
61 Message response = mc.getResponseMessage();
62 SOAPEnvelope env = response.getSOAPEnvelope();
63 String responseString = response.getSOAPPartAsString();
64
65 Element body;
66 try {
67 body = env.getFirstBody().getAsDOM();
68 } catch (Exception e) {
69 throw new AssertionFailedError("Unable to get request body as DOM Element on server");
70 }
71
72 // debug
73 //System.err.println("Response:\n---------\n" + responseString + "\n------");
74
75 /*
76 * Here is what we expect the Body to look like:
77 * <SimpleResponse xmlns="urn:qualifyTest">
78 * <SimpleResult>Hello there: Tommy</SimpleResult>
79 * </SimpleResponse>
80 */
81
82 // Now we have a DOM Element, verfy namespace attributes
83 String simpleNS = body.getNamespaceURI();
84 assertEquals("Namespace of Simple element incorrect", simpleNS, namespace);
85
86 Node nameNode = body.getFirstChild();
87 String nameNS = nameNode.getNamespaceURI();
88 assertEquals("Namespace of <name> element incorrect",
89 nameNS, namespace);
90
91 // Check the response
92 assertEquals(value, "Hello there: " + name);
93
94 } catch (java.rmi.RemoteException re) {
95 throw new AssertionFailedError("Remote Exception caught: " + re);
96 }
97 }
98
99 public void test2QualifyFormOverride() {
100 Qualify_ServiceLocator locator = new Qualify_ServiceLocator();
101 test.wsdl.qualify.Qualify_BindingStub binding;
102 try {
103 binding = (test.wsdl.qualify.Qualify_BindingStub)locator.getQualify();
104 } catch (javax.xml.rpc.ServiceException jre) {
105 throw new AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
106 }
107 assertTrue("binding is null", binding != null);
108
109 try {
110 FormOverrideResponseResponse value = null;
111 FormOverrideComplex arg = new FormOverrideComplex();
112 arg.setName("Timmah");
113 value = binding.formOverride(arg);
114
115 // Get the XML response
116 // Validate XML reponse to make sure elements are properly qualified
117 // or not per the WSDL
118 MessageContext mc = null;
119 mc = binding._getCall().getMessageContext();
120 Message response = mc.getResponseMessage();
121 SOAPEnvelope env = response.getSOAPEnvelope();
122 String responseString = response.getSOAPPartAsString();
123
124 Element body;
125 try {
126 body = env.getFirstBody().getAsDOM();
127 } catch (Exception e) {
128 throw new AssertionFailedError("Unable to get request body as DOM Element on server");
129 }
130
131 // debug
132 //System.err.println("Response:\n---------\n" + responseString + "\n------");
133
134 /*
135 * Here is what we expect the Body to look like:
136 * <FormOverrideResponse xmlns="urn:qualifyTest">
137 * <response xmlns="">
138 * <ns1:name xmlns:ns1="urn:qualifyTest">Tommy</ns1:name>
139 * </response>
140 * </FormOverrideResponse>
141 */
142
143 // Now we have a DOM Element, verfy namespace attributes
144 String FormOverrideNS = body.getNamespaceURI();
145 assertEquals("Namespace of <FormOverrideResponse> element incorrect",
146 FormOverrideNS, namespace);
147
148 Node complexNode = body.getFirstChild();
149 String complexNS = complexNode.getNamespaceURI();
150 assertNull("Namespace of <complex> element incorrect", complexNS);
151
152 // FIXME: for some reason I can't get at the <name> node which is
153 // under the <complex> node. Are we not converting the request to
154 // DOM correctly?
155 if (complexNode.hasChildNodes()) {
156 Node nameNode = complexNode.getFirstChild();
157 String nameNS = nameNode.getNamespaceURI();
158 assertEquals("Namespace of <name> element incorrect",
159 nameNS, namespace);
160 }
161
162 // Check the response
163 assertEquals(value.getName(), "Tommy");
164 } catch (java.rmi.RemoteException re) {
165 throw new AssertionFailedError("Remote Exception caught: " + re);
166 }
167 }
168
169 }
170