001: package org.objectweb.celtix.axisinterop;
002:
003: import java.math.BigDecimal;
004: import java.util.Arrays;
005: import java.util.Calendar;
006: import java.util.Date;
007: import java.util.TimeZone;
008:
009: import junit.framework.Test;
010: import junit.framework.TestCase;
011: import junit.framework.TestSuite;
012:
013: //import org.apache.axis.types.HexBinary;
014: import org.apache.axis.types.NegativeInteger;
015: import org.apache.axis.types.NonNegativeInteger;
016: import org.apache.axis.types.NonPositiveInteger;
017: import org.apache.axis.types.NormalizedString;
018: import org.apache.axis.types.PositiveInteger;
019: import org.apache.axis.types.Token;
020: import org.apache.axis.types.UnsignedByte;
021: import org.apache.axis.types.UnsignedInt;
022: import org.apache.axis.types.UnsignedLong;
023: import org.apache.axis.types.UnsignedShort;
024:
025: import org.objectweb.celtix.testutil.common.AbstractClientServerSetupBase;
026:
027: import org.soapinterop.axis.CeltixEchoServiceLocator;
028: import org.soapinterop.axis.InteropTestDocLitBindingStub;
029: import org.soapinterop.axis.InteropTestPortType;
030: import org.soapinterop.axis.SOAPStruct;
031:
032: public class AxisClientEchoTest extends TestCase {
033:
034: private static InteropTestPortType binding;
035:
036: public AxisClientEchoTest() {
037: }
038:
039: public static Test suite() throws Exception {
040: TestSuite suite = new TestSuite(AxisClientEchoTest.class);
041: return new AbstractClientServerSetupBase(suite) {
042: public void startServers() throws Exception {
043: boolean ok = launchServer(CeltixServer.class);
044: if (!ok) {
045: fail("Failed to launch celtix server.");
046: }
047: }
048: };
049: }
050:
051: public void setUp() throws Exception {
052: java.net.URL url = new java.net.URL(
053: "http://localhost:9240/CeltixEchoService/Echo");
054: binding = new CeltixEchoServiceLocator().getEcho(url);
055: assertNotNull("Could not create binding", binding);
056: ((InteropTestDocLitBindingStub) binding).setTimeout(30000);
057: ((InteropTestDocLitBindingStub) binding)
058: .setMaintainSession(true);
059: }
060:
061: private boolean equalsDate(Calendar orig, Calendar actual) {
062: return orig.get(Calendar.YEAR) == actual.get(Calendar.YEAR)
063: && orig.get(Calendar.MONTH) == actual
064: .get(Calendar.MONTH)
065: && orig.get(Calendar.DATE) == actual.get(Calendar.DATE);
066: }
067:
068: public void testBoolean() throws Exception {
069: boolean in = true;
070: boolean out = binding.echoBoolean(in);
071: assertEquals("echoBoolean : incorrect return value : " + out
072: + " expected : " + in, in, out);
073: }
074:
075: public void testFloat() throws Exception {
076: float in = 3.7F;
077: float out = binding.echoFloat(in);
078: assertEquals("echoFloat : incorrect return value : " + out
079: + " expected : " + in, in, out);
080: }
081:
082: public void testInteger() throws Exception {
083: int in = 42;
084: int out = binding.echoInteger(in);
085: assertEquals("echoInteger : incorrect return value : " + out
086: + " expected : " + in, in, out);
087: }
088:
089: public void testVoid() throws Exception {
090: binding.echoVoid();
091: }
092:
093: // TODO: Investigate why this test fails.
094: //public void testHexBinary() throws Exception {
095: // HexBinary in = new HexBinary("3344".getBytes());
096: // HexBinary out = new HexBinary(binding.echoHexBinary(in.getBytes()));
097: // assertEquals("echoHexBinary : incorrect return value : "
098: // + out + " expected : " + in, in, out);
099: //}
100:
101: public void testNegativeInteger() throws Exception {
102: // Test xsd:negativeInteger
103: NegativeInteger in = new NegativeInteger(
104: "-12345678900987654321");
105: NegativeInteger out = binding.echoNegativeInteger(in);
106: assertEquals("echoNegativeInteger : incorrect return value : "
107: + out + " expected : " + in, in, out);
108: }
109:
110: public void testNonNegativeInteger() throws Exception {
111: // Test xsd:nonNegativeInteger
112: NonNegativeInteger in = new NonNegativeInteger(
113: "12345678901234567890");
114: NonNegativeInteger out = binding.echoNonNegativeInteger(in);
115: assertEquals(
116: "echoNonNegativeInteger : incorrect return value : "
117: + out + " expected : " + in, in, out);
118: }
119:
120: public void testNonPositiveInteger() throws Exception {
121: // Test xsd:nonPositiveInteger
122: NonPositiveInteger in = new NonPositiveInteger(
123: "-12345678901234567890");
124: NonPositiveInteger out = binding.echoNonPositiveInteger(in);
125: assertEquals(
126: "echoNonPositiveInteger : incorrect return value : "
127: + out + " expected : " + in, in, out);
128: }
129:
130: public void testPositiveInteger() throws Exception {
131: // Test xsd:positiveInteger
132: PositiveInteger in = new PositiveInteger("12345678900987654321");
133: PositiveInteger out = binding.echoPositiveInteger(in);
134: assertEquals("echoPositiveInteger : incorrect return value : "
135: + out + " expected : " + in, in, out);
136: }
137:
138: public void testNormalizedString() throws Exception {
139: // Test xsd:normalizedString
140: NormalizedString in = new NormalizedString("abc-Normalized-def");
141: NormalizedString out = binding.echoNormalizedString(in);
142: assertEquals("echoNormalizedString : incorrect return value : "
143: + out + " expected : " + in, in, out);
144: }
145:
146: public void testToken() throws Exception {
147: // Test xsd:token
148: Token in = new Token("abc-Token-def");
149: Token out = binding.echoToken(in);
150: assertEquals("echoToken : incorrect return value : " + out
151: + " expected : " + in, in, out);
152: }
153:
154: public void testUnsignedByte() throws Exception {
155: // Test xsd:unsignedByte
156: UnsignedByte in = new UnsignedByte(103);
157: UnsignedByte out = binding.echoUnsignedByte(in);
158: assertEquals("echoUnsignedByte : incorrect return value : "
159: + out + " expected : " + in, in, out);
160: }
161:
162: public void testUnsignedInt() throws Exception {
163: // Test xsd:unsignedInt
164: UnsignedInt in = new UnsignedInt(101);
165: UnsignedInt out = binding.echoUnsignedInt(in);
166: assertEquals("echoUnsignedInt : incorrect return value : "
167: + out + " expected : " + in, in, out);
168: }
169:
170: public void testUnsignedLong() throws Exception {
171: // Test xsd:unsignedLong
172: UnsignedLong in = new UnsignedLong(100);
173: UnsignedLong out = binding.echoUnsignedLong(in);
174: assertEquals("echoUnsignedLong : incorrect return value : "
175: + out + " expected : " + in, in, out);
176: }
177:
178: public void testUnsignedShort() throws Exception {
179: // Test xsd:unsignedShort
180: UnsignedShort in = new UnsignedShort(102);
181: UnsignedShort out = binding.echoUnsignedShort(in);
182: assertEquals("echoUnsignedShort : incorrect return value : "
183: + out + " expected : " + in, in, out);
184: }
185:
186: public void testString() throws Exception {
187: String in = "abcdefg";
188: String out = binding.echoString(in);
189: assertEquals("echoString : incorrect return value : " + out
190: + " expected : " + in, in, out);
191: }
192:
193: // TODO: Figure out why this fails.
194: //public void testStringArray() throws Exception {
195: // String[] in = new String[] {"abc", "def"};
196: // String[] out = binding.echoStringArray(in);
197: // for (String s1 : in) {
198: // System.out.print(s1 + " ");
199: // }
200: // System.out.println(".");
201: // for (String s2 : out) {
202: // System.out.print(s2 + " ");
203: // }
204: // System.out.println(".");
205: // assertTrue("echoStringArray : incorrect return value", Arrays.equals(in, out));
206: //}
207:
208: public void testStruct() throws Exception {
209: SOAPStruct in = new SOAPStruct();
210: in.setVarInt(5);
211: in.setVarString("Hello");
212: in.setVarFloat(103F);
213: SOAPStruct out = binding.echoStruct(in);
214: assertEquals("echoStruct : incorrect return value : " + out
215: + " expected : " + in, in, out);
216: }
217:
218: public void testBase64() throws Exception {
219: byte[] in = "Base64".getBytes();
220: byte[] out = binding.echoBase64(in);
221: assertTrue("echoBase64 : incorrect return value : ", Arrays
222: .equals(in, out));
223: }
224:
225: public void testDate() throws Exception {
226: Calendar inCalendar = Calendar.getInstance();
227: Date out = binding.echoDate(inCalendar.getTime());
228: Calendar outCalendar = Calendar.getInstance();
229: outCalendar.setTime(out);
230: assertTrue("echoDate : incorrect return value", equalsDate(
231: inCalendar, outCalendar));
232: }
233:
234: // XXX: Fails with Axis 1.3, passes with Axis 1.2
235: public void testDateTime() throws Exception {
236: Calendar in = Calendar.getInstance();
237: in.setTimeZone(TimeZone.getTimeZone("GMT"));
238: in.setTime(new Date());
239: Calendar out = binding.echoDateTime(in);
240: assertTrue("echoDateTime : incorrect return value : " + out
241: + " expected : " + in, in.equals(out));
242: }
243:
244: public void testDecimal() throws Exception {
245: BigDecimal in = new BigDecimal("3.14159");
246: BigDecimal out = binding.echoDecimal(in);
247: assertEquals("echoDecimal : incorrect return value : " + out
248: + " expected : " + in, in, out);
249: }
250:
251: public static void main(String[] args) {
252: junit.textui.TestRunner.run(AxisClientEchoTest.class);
253: }
254:
255: }
|