File: Echo2ServiceTestCase.java

package info (click to toggle)
axis 1.4-29
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 52,100 kB
  • sloc: java: 129,124; xml: 10,602; jsp: 983; sh: 84; cs: 36; makefile: 18
file content (229 lines) | stat: -rw-r--r-- 9,643 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/**
 * Echo2ServiceTestCase.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis 1.2RC3 Mar 22, 2005 (05:08:41 CET) WSDL2Java emitter.
 */
package test.wsdl.echo2;

import java.util.Iterator;
import javax.xml.namespace.QName;
import org.apache.axis.MessageContext;
import org.apache.axis.message.MessageElement;
import org.apache.axis.message.PrefixedQName;
import org.apache.axis.message.SOAPBody;

public class Echo2ServiceTestCase extends junit.framework.TestCase {
    public Echo2ServiceTestCase(java.lang.String name) {
        super(name);
    }

    public void testEcho2WSDL() throws Exception {
        javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory
                .newInstance();
        java.net.URL url = new java.net.URL(
                new test.wsdl.echo2.Echo2ServiceLocator().getEcho2Address()
                        + "?WSDL");
        javax.xml.rpc.Service service = serviceFactory.createService(url,
                new test.wsdl.echo2.Echo2ServiceLocator().getServiceName());
        assertTrue(service != null);
    }

    public void test1Echo2EchoMyBase64Bean() throws Exception {
        test.wsdl.echo2.Echo2SoapBindingStub binding;
        binding = (test.wsdl.echo2.Echo2SoapBindingStub) new test.wsdl.echo2.Echo2ServiceLocator()
                .getEcho2();
        assertNotNull("binding is null", binding);
        // Time out after a minute
        binding.setTimeout(60000);

        // message is more clear without multiref
        //binding._setProperty("sendMultiRefs", Boolean.FALSE);
        // Test operation
        test.wsdl.echo2.MyBase64Bean input = new test.wsdl.echo2.MyBase64Bean();
        fillMyBase64Bean(input);
        test.wsdl.echo2.MyBase64Bean ret = binding.echoMyBase64Bean(input);

        // Body
        //  echoMyBase64BeanResponse
        //   return HREF
        //  multiRef : 1 element, no child

        // Check message format
        binding._getCall().getResponseMessage().writeTo(System.out);
        SOAPBody body = (SOAPBody) binding._getCall().getResponseMessage().getSOAPBody();

        QName responseQName = new QName("urn:echo2.wsdl.test", "echoMyBase64BeanResponse");
        QName returnQName = new QName("", "return");
        QName xsdByteQName = new QName("", "varXsdByte");
        QName soapByteQName = new QName("", "varSoapByte");
        QName xsdBase64BinQName = new QName("", "varXsdBase64Binary");
        QName soapBase64BinQName = new QName("", "varSoapBase64Binary");
        QName xsdHexBinQName = new QName("", "varXsdHexBinary");
        QName soapBase64QName = new QName("", "varSoapBase64");

        MessageElement response = body.getChildElement(responseQName);
        assertNotNull("no <ns1:echoMyBase64BeanResponse> found", response);
        MessageElement return1 = response.getChildElement(returnQName);
        assertNotNull("no <return> found", return1);
        MessageElement realRet = return1.getRealElement();

        Iterator it = realRet.getChildElements(xsdByteQName);
        // only 1 element
        MessageElement one = null;
        while (it.hasNext()) {
            assertNull("only 1 element named " + xsdByteQName, one);
            one = (MessageElement) it.next();
        }
        assertNull(xsdByteQName + " is nil and shouldn't have any children", one.getChildren());

        it = realRet.getChildElements(soapByteQName);
        // only 1 element
        one = null;
        while (it.hasNext()) {
            assertNull("only 1 element named " + soapByteQName, one);
            one = (MessageElement) it.next();
        }
        assertNull(soapByteQName + " is nil and shouldn't have any children", one.getChildren());

        it = realRet.getChildElements(xsdBase64BinQName);
        // only 1 element
        one = null;
        while (it.hasNext()) {
            assertNull("only 1 element named " + xsdBase64BinQName, one);
            one = (MessageElement) it.next();
        }
        assertEquals(xsdBase64BinQName + " have wrong value", "fwCB", one.getFirstChild().getNodeValue());

        it = realRet.getChildElements(soapBase64BinQName);
        // only 1 element
        one = null;
        while (it.hasNext()) {
            assertNull("only 1 element named " + soapBase64BinQName, one);
            one = (MessageElement) it.next();
        }
        assertEquals(soapBase64BinQName + " have wrong value", "fwCB", one.getFirstChild().getNodeValue());

        it = realRet.getChildElements(xsdHexBinQName);
        // only 1 element
        one = null;
        while (it.hasNext()) {
            assertNull("only 1 element named " + xsdHexBinQName, one);
            one = (MessageElement) it.next();
        }
        assertEquals(xsdHexBinQName + " have wrong value", "7f0081", one.getFirstChild().getNodeValue());

        it = realRet.getChildElements(soapBase64QName);
        // only 1 element
        one = null;
        while (it.hasNext()) {
            assertNull("only 1 element named " + soapBase64QName, one);
            one = (MessageElement) it.next();
        }
        assertEquals(soapBase64QName + " have wrong value", "fwCB", one.getFirstChild().getNodeValue());

    }

    public void test1Echo2EchoArrayOfMyBase64Bean() throws Exception {
        test.wsdl.echo2.Echo2SoapBindingStub binding;
        binding = (test.wsdl.echo2.Echo2SoapBindingStub) new test.wsdl.echo2.Echo2ServiceLocator()
                .getEcho2();
        assertNotNull("binding is null", binding);
        // Time out after a minute
        binding.setTimeout(60000);
        // Test operation
        MyBase64Bean[] value = null;
        MyBase64Bean[] array = new MyBase64Bean[2];
        array[0] = new MyBase64Bean();
        fillMyBase64Bean(array[0]);
        array[1] = new MyBase64Bean();
        fillMyBase64Bean(array[1]);
        value = binding.echoArrayOfMyBase64Bean(array);
        // TBD - validate results
    }

    /**
     * @param bean
     */
    private void fillMyBase64Bean(MyBase64Bean bean) {
        bean.setVarSoapBase64(new byte[] {127, 0, -127});
        bean.setVarSoapBase64Binary(new byte[] {127, 0, -127});
        bean.setVarXsdBase64Binary(new byte[] {127, 0, -127});
        bean.setVarXsdHexBinary(new byte[] {127, 0, -127});

    }

    public void test2Echo2EchoArrayOfString_MaxOccursUnbounded()
            throws Exception {
        test.wsdl.echo2.Echo2SoapBindingStub binding;
        Echo2ServiceLocator loc = new test.wsdl.echo2.Echo2ServiceLocator();
        try {
            binding = (test.wsdl.echo2.Echo2SoapBindingStub)loc.getEcho2();
        } catch (javax.xml.rpc.ServiceException jre) {
            if (jre.getLinkedCause() != null)
                jre.getLinkedCause().printStackTrace();
            throw new junit.framework.AssertionFailedError(
                    "JAX-RPC ServiceException caught: " + jre);
        }
        assertNotNull("binding is null", binding);
        // Time out after a minute
        binding.setTimeout(60000);
        // Test operation
        String [] args = new String[] {"one", "two", "", null};
		java.lang.String[] value = null;
        value = binding
                .echoArrayOfString_MaxOccursUnbounded(args);

        // Validate results - NOTE: This checks the XML directly, so if
        // any changes are made to the WSDL/code for this test, equivalent
        // changes must be made in this code.

        SOAPBody body = (SOAPBody)binding._getCall().getResponseMessage().getSOAPBody();
        MessageElement element;
        QName responseQName = new QName("urn:echo2.wsdl.test", "echoArrayOfString_MaxOccursUnboundedResponse");
        QName returnQName = new QName("", "return");
        QName itemQName = new QName("", "varStringArray");
        element = body.getChildElement(responseQName);
        assertNotNull("Couldn't find response element", element);
        element = element.getChildElement(returnQName);
        assertNotNull("Couldn't find return element", element);
        Iterator elements = element.getChildElements(itemQName);
        assertNotNull("Couldn't find items", elements);
        int count = 0;
        while (elements.hasNext()) {
            element = (MessageElement) elements.next();
            count++;
        }
        assertEquals("Wrong # of items", 4, count);

        // OK, now that we know the XML looked right, just for yuks check the values
        for (int i = 0; i < value.length; i++) {
            assertEquals("Item " + i + " didn't match!", args[i], value[i]);
        }
    }

    public void test3Echo2EchoArrayOfString_SoapEncArray() throws Exception {
        test.wsdl.echo2.Echo2SoapBindingStub binding;
        try {
            binding = (test.wsdl.echo2.Echo2SoapBindingStub) new test.wsdl.echo2.Echo2ServiceLocator()
                    .getEcho2();
        } catch (javax.xml.rpc.ServiceException jre) {
            if (jre.getLinkedCause() != null)
                jre.getLinkedCause().printStackTrace();
            throw new junit.framework.AssertionFailedError(
                    "JAX-RPC ServiceException caught: " + jre);
        }
        assertNotNull("binding is null", binding);
        // Time out after a minute
        binding.setTimeout(60000);
        // Test operation
        java.lang.String[] value = null;
        value = binding.echoArrayOfString_SoapEncArray(new java.lang.String[] {
                "one", "two", "three", "", null });
        // TBD - validate results
    }
	public static void main(String[] argv) throws Exception {
		Echo2ServiceTestCase tc = new Echo2ServiceTestCase("somehging;");
		tc.test1Echo2EchoMyBase64Bean();
	}
}