001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package soapinterop;
059:
060: import java.math.BigDecimal;
061: import java.text.DateFormat;
062: import java.util.Date;
063: import java.util.Locale;
064:
065: import junit.framework.Test;
066: import junit.framework.TestCase;
067: import junit.framework.TestSuite;
068:
069: import org.apache.wsif.providers.soap.apachesoap.WSIFDynamicProvider_ApacheSOAP;
070: import org.apache.wsif.util.WSIFPluggableProviders;
071:
072: public class InteropTest extends TestCase {
073:
074: public static void main(String[] args) {
075: junit.textui.TestRunner.run(suite());
076: }
077:
078: public static Test suite() {
079: return new TestSuite(InteropTest.class);
080: }
081:
082: public InteropTest(String name) {
083: super (name);
084: }
085:
086: /**
087: * Tests the Java binding for the shopping cart scenario via WSDL
088: */
089:
090: public void testInterop() {
091: try {
092: // only for soap not axis provider
093: WSIFPluggableProviders.overrideDefaultProvider(
094: "http://schemas.xmlsoap.org/wsdl/soap/",
095: new WSIFDynamicProvider_ApacheSOAP());
096:
097: InteropTestServiceProxy proxy = new InteropTestServiceProxy();
098:
099: //echoString(String)
100: System.out.println("echoString");
101: assertTrue("echoString", proxy.echoString("String").equals(
102: "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 dateIn = new Date();
119: DateFormat fmt = DateFormat.getDateInstance(
120: DateFormat.FULL, Locale.US);
121: dateIn = fmt.parse("Thursday, January 10, 2002 ");
122: assertTrue("echoDate", proxy.echoDate(dateIn)
123: .equals(dateIn));
124:
125: //echoStruct(SOAPStruct)
126: /* SOAPStruct structIn = new SOAPStruct();
127: structIn.setVarString("SOAPString");
128: structIn.setVarInt(7);
129: structIn.setVarFloat((float)9);
130: SOAPStruct structOut = proxy.echoStruct(structIn);
131: System.out.println("SOAPStruct start");
132: System.out.println(structOut.getVarString());
133: System.out.println(structOut.getVarInt());
134: System.out.println(structOut.getVarFloat());
135: System.out.println("SOAPStruct end"); */
136:
137: //echoBase64(byte [])
138: System.out.println("echoBase64");
139: byte[] base64In = { -1, 0, 1 };
140: byte[] base64Out = proxy.echoBase64(base64In);
141:
142: for (int i = 0; i < base64Out.length; i++) {
143: assertTrue("echoBase64 [" + i + "]",
144: base64In[i] == base64Out[i]);
145: }
146:
147: /* //echoHexBinary(byte [])
148: byte[] hexBinaryIn = {-2, -1, 0, 1, 2};
149: byte[] hexBinaryOut = proxy.echoHexBinary(hexBinaryIn);
150: for( int i=0; i < hexBinaryOut.length; i++) {
151: System.out.print(hexBinaryOut[i]);
152: System.out.print(",");
153: }
154: System.out.println();
155: */
156:
157: //echoDecimal(BigDecimal)
158: System.out.println("echoBigDecimal");
159: BigDecimal bigDecimalIn = new BigDecimal("7");
160: assertTrue("echoDecimal", proxy.echoDecimal(bigDecimalIn)
161: .equals(bigDecimalIn));
162:
163: //echoBoolean(boolean)
164: System.out.println("echoBoolean");
165: boolean booleanIn = false;
166: assertTrue("echoBoolean",
167: proxy.echoBoolean(booleanIn) == booleanIn);
168:
169: //echoStringArray(String [])
170: /*System.out.println("echoStringArray");
171: String[] stringArrayIn = { "This", "is", "the", "stringArray", "test." };
172: String[] stringArrayOut = proxy.echoStringArray(stringArrayIn);
173: for (int i = 0; i < stringArrayOut.length; i++) {
174: assertTrue(
175: "echoStringArray [" + i + "]",
176: stringArrayOut[i].equals(stringArrayIn[i]));
177: }
178: */
179: //echoStructArray(SOAPStruct [])
180: /* SOAPStruct struct1 = new SOAPStruct();
181: struct1.setVarString("SOAPString1");
182: struct1.setVarInt(5);
183: struct1.setVarFloat((float)8);
184: SOAPStruct struct2 = new SOAPStruct();
185: struct2.setVarString("SOAPString2");
186: struct2.setVarInt(7);
187: struct2.setVarFloat((float)9);
188: SOAPStruct[] structArrayIn = new SOAPStruct[2];
189: structArrayIn[0] = struct1;
190: structArrayIn[1] = struct2;
191: SOAPStruct[] structArrayOut = proxy.echoStructArray(structArrayIn);
192: for (int i = 0; i < structArrayOut.length; i++) {
193: System.out.println(structArrayOut[i].getVarString());
194: System.out.println(structArrayOut[i].getVarInt());
195: System.out.println(structArrayOut[i].getVarFloat());
196: }
197: */
198:
199: //echoFloatArray(float [])
200: /*System.out.println("echoFloatArray");
201: float[] floatArrayIn = new float[5];
202: for (int i = 0; i < floatArrayIn.length; i++) {
203: floatArrayIn[i] = (float) (45.0 * Math.random() - 10.0);
204: }
205: float[] floatArrayOut = proxy.echoFloatArray(floatArrayIn);
206: for (int i = 0; i < floatArrayOut.length; i++) {
207: assertTrue("echoFloatArray [" + i + "]", floatArrayOut[i] == floatArrayIn[i]);
208: }
209: */
210: //echoIntegerArray(int [])
211: /*System.out.println("echoIntegerArray");
212: int[] intArrayIn = new int[5];
213: for (int i = 0; i < intArrayIn.length; i++) {
214: intArrayIn[i] = i;
215: }
216: int[] intArrayOut = proxy.echoIntegerArray(intArrayIn);
217: for (int i = 0; i < intArrayOut.length; i++) {
218: assertTrue("echoIntArray [" + i + "]", intArrayOut[i] == intArrayIn[i]);
219: }
220: */
221: } catch (Exception e) {
222: System.out.println("InteropTest caught exception " + e);
223: e.printStackTrace();
224: assertTrue(false);
225: }
226:
227: }
228: }
|