KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soapinterop > InteropTest


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "WSIF" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package soapinterop;
59
60 import java.math.BigDecimal JavaDoc;
61 import java.text.DateFormat JavaDoc;
62 import java.util.Date JavaDoc;
63 import java.util.Locale JavaDoc;
64
65 import junit.framework.Test;
66 import junit.framework.TestCase;
67 import junit.framework.TestSuite;
68
69 import org.apache.wsif.providers.soap.apachesoap.WSIFDynamicProvider_ApacheSOAP;
70 import org.apache.wsif.util.WSIFPluggableProviders;
71
72 public class InteropTest extends TestCase {
73
74     public static void main(String JavaDoc[] args) {
75         junit.textui.TestRunner.run(suite());
76     }
77
78     public static Test suite() {
79         return new TestSuite(InteropTest.class);
80     }
81
82     public InteropTest(String JavaDoc name) {
83         super(name);
84     }
85
86     /**
87      * Tests the Java binding for the shopping cart scenario via WSDL
88      */

89
90     public void testInterop() {
91       try
92       {
93         // only for soap not axis provider
94
WSIFPluggableProviders.overrideDefaultProvider(
95            "http://schemas.xmlsoap.org/wsdl/soap/",
96            new WSIFDynamicProvider_ApacheSOAP() );
97            
98         InteropTestServiceProxy proxy = new InteropTestServiceProxy();
99
100         //echoString(String)
101
System.out.println("echoString");
102         assertTrue("echoString", proxy.echoString("String").equals("String"));
103
104         //echoInteger(int)
105
System.out.println("echoInteger");
106         assertTrue("echoInteger", proxy.echoInteger(3) == 3);
107
108         //echoFloat(float)
109
System.out.println("echoFloat");
110         assertTrue("echoInteger", proxy.echoFloat((float) 5) == 5.0);
111
112         //echoVoid() - exception thrown if problem
113
System.out.println("echoVoid");
114         proxy.echoVoid();
115
116         //echoDate(Date)
117
System.out.println("echoDate");
118         Date JavaDoc dateIn = new Date JavaDoc();
119         DateFormat JavaDoc fmt = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
120         dateIn = fmt.parse("Thursday, January 10, 2002 ");
121         assertTrue("echoDate", proxy.echoDate(dateIn).equals(dateIn));
122
123         //echoStruct(SOAPStruct)
124
/* SOAPStruct structIn = new SOAPStruct();
125                     structIn.setVarString("SOAPString");
126                     structIn.setVarInt(7);
127                     structIn.setVarFloat((float)9);
128                     SOAPStruct structOut = proxy.echoStruct(structIn);
129                     System.out.println("SOAPStruct start");
130                     System.out.println(structOut.getVarString());
131                     System.out.println(structOut.getVarInt());
132                     System.out.println(structOut.getVarFloat());
133                     System.out.println("SOAPStruct end"); */

134
135         //echoBase64(byte [])
136
System.out.println("echoBase64");
137         byte[] base64In = { -1, 0, 1 };
138         byte[] base64Out = proxy.echoBase64(base64In);
139
140         for (int i = 0; i < base64Out.length; i++) {
141             assertTrue("echoBase64 [" + i + "]", base64In[i] == base64Out[i]);
142         }
143
144         /* //echoHexBinary(byte [])
145                     byte[] hexBinaryIn = {-2, -1, 0, 1, 2};
146                     byte[] hexBinaryOut = proxy.echoHexBinary(hexBinaryIn);
147                     for( int i=0; i < hexBinaryOut.length; i++) {
148                         System.out.print(hexBinaryOut[i]);
149                         System.out.print(",");
150                     }
151                     System.out.println();
152         */

153
154         //echoDecimal(BigDecimal)
155
System.out.println("echoBigDecimal");
156         BigDecimal JavaDoc bigDecimalIn = new BigDecimal JavaDoc("7");
157         assertTrue("echoDecimal", proxy.echoDecimal(bigDecimalIn).equals(bigDecimalIn));
158
159         //echoBoolean(boolean)
160
System.out.println("echoBoolean");
161         boolean booleanIn = false;
162         assertTrue("echoBoolean", proxy.echoBoolean(booleanIn) == booleanIn);
163
164         //echoStringArray(String [])
165
/*System.out.println("echoStringArray");
166         String[] stringArrayIn = { "This", "is", "the", "stringArray", "test." };
167         String[] stringArrayOut = proxy.echoStringArray(stringArrayIn);
168         for (int i = 0; i < stringArrayOut.length; i++) {
169             assertTrue(
170                 "echoStringArray [" + i + "]",
171                 stringArrayOut[i].equals(stringArrayIn[i]));
172         }
173         */

174         //echoStructArray(SOAPStruct [])
175
/* SOAPStruct struct1 = new SOAPStruct();
176                     struct1.setVarString("SOAPString1");
177                     struct1.setVarInt(5);
178                     struct1.setVarFloat((float)8);
179                     SOAPStruct struct2 = new SOAPStruct();
180                     struct2.setVarString("SOAPString2");
181                     struct2.setVarInt(7);
182                     struct2.setVarFloat((float)9);
183                     SOAPStruct[] structArrayIn = new SOAPStruct[2];
184                     structArrayIn[0] = struct1;
185                     structArrayIn[1] = struct2;
186                     SOAPStruct[] structArrayOut = proxy.echoStructArray(structArrayIn);
187                     for (int i = 0; i < structArrayOut.length; i++) {
188                         System.out.println(structArrayOut[i].getVarString());
189                         System.out.println(structArrayOut[i].getVarInt());
190                         System.out.println(structArrayOut[i].getVarFloat());
191                     }
192         */

193
194         //echoFloatArray(float [])
195
/*System.out.println("echoFloatArray");
196         float[] floatArrayIn = new float[5];
197         for (int i = 0; i < floatArrayIn.length; i++) {
198             floatArrayIn[i] = (float) (45.0 * Math.random() - 10.0);
199         }
200         float[] floatArrayOut = proxy.echoFloatArray(floatArrayIn);
201         for (int i = 0; i < floatArrayOut.length; i++) {
202             assertTrue("echoFloatArray [" + i + "]", floatArrayOut[i] == floatArrayIn[i]);
203         }
204         */

205         //echoIntegerArray(int [])
206
/*System.out.println("echoIntegerArray");
207         int[] intArrayIn = new int[5];
208         for (int i = 0; i < intArrayIn.length; i++) {
209             intArrayIn[i] = i;
210         }
211         int[] intArrayOut = proxy.echoIntegerArray(intArrayIn);
212         for (int i = 0; i < intArrayOut.length; i++) {
213             assertTrue("echoIntArray [" + i + "]", intArrayOut[i] == intArrayIn[i]);
214         }
215         */

216       }
217       catch (Exception JavaDoc e)
218       {
219         System.out.println("InteropTest caught exception "+e);
220         e.printStackTrace();
221         assertTrue(false);
222       }
223         
224     }
225 }
226
Popular Tags