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 chartype;
059:
060: import java.util.Collection;
061: import java.util.HashMap;
062: import java.util.Hashtable;
063: import java.util.Iterator;
064:
065: import junit.framework.Test;
066: import junit.framework.TestCase;
067: import junit.framework.TestSuite;
068:
069: import org.apache.wsif.WSIFMessage;
070: import org.apache.wsif.WSIFOperation;
071: import org.apache.wsif.WSIFPort;
072: import org.apache.wsif.WSIFService;
073: import org.apache.wsif.WSIFServiceFactory;
074: import util.TestUtilities;
075:
076: /**
077: * JUnit test to verify that char arguments to Java servies can be sent as parts containing
078: * Strings of length 1 and that chars/Characters returned from a Java service are converted
079: * to Strings before being added to the output message. These conversions allow Java/EJB
080: * services to be more interoperable with SOAP services since XML does not define a char
081: * type.
082: *
083: * @author Owen Burroughs <owenb@apache.org>
084: */
085: public class CharTest extends TestCase {
086:
087: private boolean debugMode = true;
088: private String wsdl = TestUtilities
089: .getWsdlPath("java\\test\\chartype")
090: + "CharService.wsdl";;
091:
092: public static void main(java.lang.String[] args) {
093: junit.textui.TestRunner.run(suite());
094: }
095:
096: public static Test suite() {
097: return new TestSuite(CharTest.class);
098: }
099:
100: public CharTest(String arg0) {
101: super (arg0);
102: }
103:
104: protected void setUp() {
105: }
106:
107: public void testJava() throws Exception {
108: WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
109: WSIFService service = factory.getService(wsdl, null, null,
110: null, null);
111:
112: WSIFPort port = service.getPort();
113:
114: WSIFOperation operation;
115: WSIFMessage inputMessage;
116: WSIFMessage outputMessage;
117: WSIFMessage faultMessage;
118:
119: String tempString;
120:
121: Object part;
122: boolean operationSucceeded;
123:
124: /**********************************************************
125: * Test calling a service that takes a char as an argument
126: **********************************************************/
127: operation = port.createOperation("setCharOperation");
128: inputMessage = operation.createInputMessage();
129: outputMessage = operation.createOutputMessage();
130: faultMessage = operation.createFaultMessage();
131:
132: inputMessage.setObjectPart("in", "a");
133:
134: operationSucceeded = operation.executeRequestResponseOperation(
135: inputMessage, outputMessage, faultMessage);
136:
137: assertTrue("setChar failed!!", operationSucceeded);
138:
139: if (operationSucceeded) {
140: assertTrue(
141: "setChar did not return a boolean",
142: outputMessage.getObjectPart("out") instanceof Boolean);
143: assertTrue("setChar did not return true",
144: ((Boolean) outputMessage.getObjectPart("out"))
145: .booleanValue());
146: debug("setChar returned "
147: + outputMessage.getObjectPart("out"));
148: } else {
149: debug("operation failed");
150: }
151:
152: /**********************************************************
153: * Test calling a service that returns a char
154: **********************************************************/
155: operation = port.createOperation("getCharOperation");
156: inputMessage = operation.createInputMessage();
157: outputMessage = operation.createOutputMessage();
158: faultMessage = operation.createFaultMessage();
159:
160: inputMessage.setBooleanPart("in", true);
161:
162: operationSucceeded = operation.executeRequestResponseOperation(
163: inputMessage, outputMessage, faultMessage);
164:
165: assertTrue("getChar failed!!", operationSucceeded);
166:
167: if (operationSucceeded) {
168: assertTrue("getChar did not return a String", outputMessage
169: .getObjectPart("out") instanceof String);
170: debug("getChar returned "
171: + outputMessage.getObjectPart("out"));
172: } else {
173: debug("operation failed");
174: }
175:
176: /*************************************************************
177: * Test calling a service that takes a char[][] as an argument
178: *************************************************************/
179: operation = port.createOperation("setCharArrayOperation");
180: inputMessage = operation.createInputMessage();
181: outputMessage = operation.createOutputMessage();
182: faultMessage = operation.createFaultMessage();
183:
184: String[][] sa = new String[][] { { "a", "b" },
185: { "d", "e", "g" } };
186:
187: inputMessage.setObjectPart("in", sa);
188:
189: operationSucceeded = operation.executeRequestResponseOperation(
190: inputMessage, outputMessage, faultMessage);
191:
192: assertTrue("setCharArray failed!!", operationSucceeded);
193:
194: if (operationSucceeded) {
195: assertTrue(
196: "setCharArray did not return a boolean",
197: outputMessage.getObjectPart("out") instanceof Boolean);
198: assertTrue("getCharArray did not return true",
199: ((Boolean) outputMessage.getObjectPart("out"))
200: .booleanValue());
201: debug("setCharArray returned "
202: + outputMessage.getObjectPart("out"));
203: } else {
204: debug("operation failed");
205: }
206:
207: /*************************************************************
208: * Test calling a service that returns a char[][]
209: *************************************************************/
210: operation = port.createOperation("getCharArrayOperation");
211: inputMessage = operation.createInputMessage();
212: outputMessage = operation.createOutputMessage();
213: faultMessage = operation.createFaultMessage();
214:
215: inputMessage.setBooleanPart("in", true);
216:
217: operationSucceeded = operation.executeRequestResponseOperation(
218: inputMessage, outputMessage, faultMessage);
219:
220: assertTrue("getCharArray failed!!", operationSucceeded);
221:
222: if (operationSucceeded) {
223: assertTrue(
224: "getCharArray did not return a String array",
225: outputMessage.getObjectPart("out") instanceof String[][]);
226: String[][] out = (String[][]) outputMessage
227: .getObjectPart("out");
228: debug("getCharArray returned ");
229: for (int i = 0; i < out.length; i++) {
230: for (int j = 0; j < out[i].length; j++) {
231: char c = 'X';
232: debug(" out[" + i + "][" + j + "] = "
233: + out[i][j]);
234: }
235: }
236: } else {
237: debug("operation failed");
238: }
239: }
240:
241: private void debug(Object s) {
242: if (debugMode)
243: System.out.println(s);
244: }
245: }
|