KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > axisinterop > AxisClientEchoTest


1 package org.objectweb.celtix.axisinterop;
2
3 import java.math.BigDecimal JavaDoc;
4 import java.util.Arrays JavaDoc;
5 import java.util.Calendar JavaDoc;
6 import java.util.Date JavaDoc;
7 import java.util.TimeZone JavaDoc;
8
9 import junit.framework.Test;
10 import junit.framework.TestCase;
11 import junit.framework.TestSuite;
12
13 //import org.apache.axis.types.HexBinary;
14
import org.apache.axis.types.NegativeInteger;
15 import org.apache.axis.types.NonNegativeInteger;
16 import org.apache.axis.types.NonPositiveInteger;
17 import org.apache.axis.types.NormalizedString;
18 import org.apache.axis.types.PositiveInteger;
19 import org.apache.axis.types.Token;
20 import org.apache.axis.types.UnsignedByte;
21 import org.apache.axis.types.UnsignedInt;
22 import org.apache.axis.types.UnsignedLong;
23 import org.apache.axis.types.UnsignedShort;
24
25 import org.objectweb.celtix.testutil.common.AbstractClientServerSetupBase;
26
27 import org.soapinterop.axis.CeltixEchoServiceLocator;
28 import org.soapinterop.axis.InteropTestDocLitBindingStub;
29 import org.soapinterop.axis.InteropTestPortType;
30 import org.soapinterop.axis.SOAPStruct;
31
32 public class AxisClientEchoTest extends TestCase {
33
34     private static InteropTestPortType binding;
35
36     public AxisClientEchoTest() {
37     }
38
39     public static Test suite() throws Exception JavaDoc {
40         TestSuite suite = new TestSuite(AxisClientEchoTest.class);
41         return new AbstractClientServerSetupBase(suite) {
42             public void startServers() throws Exception JavaDoc {
43                 boolean ok = launchServer(CeltixServer.class);
44                 if (!ok) {
45                     fail("Failed to launch celtix server.");
46                 }
47             }
48         };
49     }
50
51     public void setUp() throws Exception JavaDoc {
52         java.net.URL JavaDoc url = new java.net.URL JavaDoc("http://localhost:9240/CeltixEchoService/Echo");
53         binding = new CeltixEchoServiceLocator().getEcho(url);
54         assertNotNull("Could not create binding", binding);
55         ((InteropTestDocLitBindingStub)binding).setTimeout(30000);
56         ((InteropTestDocLitBindingStub)binding).setMaintainSession(true);
57     }
58
59     private boolean equalsDate(Calendar JavaDoc orig, Calendar JavaDoc actual) {
60         return orig.get(Calendar.YEAR) == actual.get(Calendar.YEAR)
61             && orig.get(Calendar.MONTH) == actual.get(Calendar.MONTH)
62             && orig.get(Calendar.DATE) == actual.get(Calendar.DATE);
63     }
64
65     public void testBoolean() throws Exception JavaDoc {
66         boolean in = true;
67         boolean out = binding.echoBoolean(in);
68         assertEquals("echoBoolean : incorrect return value : "
69             + out + " expected : " + in, in, out);
70     }
71
72     public void testFloat() throws Exception JavaDoc {
73         float in = 3.7F;
74         float out = binding.echoFloat(in);
75         assertEquals("echoFloat : incorrect return value : "
76             + out + " expected : " + in, in, out);
77     }
78
79     public void testInteger() throws Exception JavaDoc {
80         int in = 42;
81         int out = binding.echoInteger(in);
82         assertEquals("echoInteger : incorrect return value : "
83             + out + " expected : " + in, in, out);
84     }
85
86     public void testVoid() throws Exception JavaDoc {
87         binding.echoVoid();
88     }
89
90     // TODO: Investigate why this test fails.
91
//public void testHexBinary() throws Exception {
92
// HexBinary in = new HexBinary("3344".getBytes());
93
// HexBinary out = new HexBinary(binding.echoHexBinary(in.getBytes()));
94
// assertEquals("echoHexBinary : incorrect return value : "
95
// + out + " expected : " + in, in, out);
96
//}
97

98     public void testNegativeInteger() throws Exception JavaDoc {
99         // Test xsd:negativeInteger
100
NegativeInteger in = new NegativeInteger("-12345678900987654321");
101         NegativeInteger out = binding.echoNegativeInteger(in);
102         assertEquals("echoNegativeInteger : incorrect return value : "
103             + out + " expected : " + in, in, out);
104     }
105
106     public void testNonNegativeInteger() throws Exception JavaDoc {
107         // Test xsd:nonNegativeInteger
108
NonNegativeInteger in = new NonNegativeInteger("12345678901234567890");
109         NonNegativeInteger out = binding.echoNonNegativeInteger(in);
110         assertEquals("echoNonNegativeInteger : incorrect return value : "
111             + out + " expected : " + in, in, out);
112     }
113
114     public void testNonPositiveInteger() throws Exception JavaDoc {
115         // Test xsd:nonPositiveInteger
116
NonPositiveInteger in = new NonPositiveInteger("-12345678901234567890");
117         NonPositiveInteger out = binding.echoNonPositiveInteger(in);
118         assertEquals("echoNonPositiveInteger : incorrect return value : "
119             + out + " expected : " + in, in, out);
120     }
121
122     public void testPositiveInteger() throws Exception JavaDoc {
123         // Test xsd:positiveInteger
124
PositiveInteger in = new PositiveInteger("12345678900987654321");
125         PositiveInteger out = binding.echoPositiveInteger(in);
126         assertEquals("echoPositiveInteger : incorrect return value : "
127             + out + " expected : " + in, in, out);
128     }
129
130     public void testNormalizedString() throws Exception JavaDoc {
131         // Test xsd:normalizedString
132
NormalizedString in = new NormalizedString("abc-Normalized-def");
133         NormalizedString out = binding.echoNormalizedString(in);
134         assertEquals("echoNormalizedString : incorrect return value : "
135             + out + " expected : " + in, in, out);
136     }
137
138     public void testToken() throws Exception JavaDoc {
139         // Test xsd:token
140
Token in = new Token("abc-Token-def");
141         Token out = binding.echoToken(in);
142         assertEquals("echoToken : incorrect return value : " + out + " expected : " + in, in, out);
143     }
144
145     public void testUnsignedByte() throws Exception JavaDoc {
146         // Test xsd:unsignedByte
147
UnsignedByte in = new UnsignedByte(103);
148         UnsignedByte out = binding.echoUnsignedByte(in);
149         assertEquals("echoUnsignedByte : incorrect return value : "
150             + out + " expected : " + in, in, out);
151     }
152
153     public void testUnsignedInt() throws Exception JavaDoc {
154         // Test xsd:unsignedInt
155
UnsignedInt in = new UnsignedInt(101);
156         UnsignedInt out = binding.echoUnsignedInt(in);
157         assertEquals("echoUnsignedInt : incorrect return value : "
158             + out + " expected : " + in, in, out);
159     }
160
161     public void testUnsignedLong() throws Exception JavaDoc {
162         // Test xsd:unsignedLong
163
UnsignedLong in = new UnsignedLong(100);
164         UnsignedLong out = binding.echoUnsignedLong(in);
165         assertEquals("echoUnsignedLong : incorrect return value : "
166             + out + " expected : " + in, in, out);
167     }
168
169     public void testUnsignedShort() throws Exception JavaDoc {
170         // Test xsd:unsignedShort
171
UnsignedShort in = new UnsignedShort(102);
172         UnsignedShort out = binding.echoUnsignedShort(in);
173         assertEquals("echoUnsignedShort : incorrect return value : "
174             + out + " expected : " + in, in, out);
175     }
176
177     public void testString() throws Exception JavaDoc {
178         String JavaDoc in = "abcdefg";
179         String JavaDoc out = binding.echoString(in);
180         assertEquals("echoString : incorrect return value : "
181             + out + " expected : " + in, in, out);
182     }
183
184     // TODO: Figure out why this fails.
185
//public void testStringArray() throws Exception {
186
// String[] in = new String[] {"abc", "def"};
187
// String[] out = binding.echoStringArray(in);
188
// for (String s1 : in) {
189
// System.out.print(s1 + " ");
190
// }
191
// System.out.println(".");
192
// for (String s2 : out) {
193
// System.out.print(s2 + " ");
194
// }
195
// System.out.println(".");
196
// assertTrue("echoStringArray : incorrect return value", Arrays.equals(in, out));
197
//}
198

199     public void testStruct() throws Exception JavaDoc {
200         SOAPStruct in = new SOAPStruct();
201         in.setVarInt(5);
202         in.setVarString("Hello");
203         in.setVarFloat(103F);
204         SOAPStruct out = binding.echoStruct(in);
205         assertEquals("echoStruct : incorrect return value : "
206             + out + " expected : " + in, in, out);
207     }
208
209     public void testBase64() throws Exception JavaDoc {
210         byte[] in = "Base64".getBytes();
211         byte[] out = binding.echoBase64(in);
212         assertTrue("echoBase64 : incorrect return value : ", Arrays.equals(in, out));
213     }
214
215     public void testDate() throws Exception JavaDoc {
216         Calendar JavaDoc inCalendar = Calendar.getInstance();
217         Date JavaDoc out = binding.echoDate(inCalendar.getTime());
218         Calendar JavaDoc outCalendar = Calendar.getInstance();
219         outCalendar.setTime(out);
220         assertTrue("echoDate : incorrect return value", equalsDate(inCalendar, outCalendar));
221     }
222
223     // XXX: Fails with Axis 1.3, passes with Axis 1.2
224
public void testDateTime() throws Exception JavaDoc {
225         Calendar JavaDoc in = Calendar.getInstance();
226         in.setTimeZone(TimeZone.getTimeZone("GMT"));
227         in.setTime(new Date JavaDoc());
228         Calendar JavaDoc out = binding.echoDateTime(in);
229         assertTrue("echoDateTime : incorrect return value : "
230             + out + " expected : " + in, in.equals(out));
231     }
232
233     public void testDecimal() throws Exception JavaDoc {
234         BigDecimal JavaDoc in = new BigDecimal JavaDoc("3.14159");
235         BigDecimal JavaDoc out = binding.echoDecimal(in);
236         assertEquals("echoDecimal : incorrect return value : "
237             + out + " expected : " + in, in, out);
238     }
239
240     public static void main(String JavaDoc[] args) {
241         junit.textui.TestRunner.run(AxisClientEchoTest.class);
242     }
243
244 }
245
Popular Tags