KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.objectweb.celtix.axisinterop;
2
3 import java.math.BigDecimal JavaDoc;
4 import java.math.BigInteger JavaDoc;
5 import java.net.URL JavaDoc;
6 import java.util.Arrays JavaDoc;
7 //import java.util.List;
8

9 import javax.xml.datatype.DatatypeConstants JavaDoc;
10 import javax.xml.datatype.XMLGregorianCalendar JavaDoc;
11 import javax.xml.namespace.QName JavaDoc;
12
13 import junit.framework.Test;
14 import junit.framework.TestCase;
15 import junit.framework.TestSuite;
16
17 import org.objectweb.celtix.bus.jaxws.spi.ProviderImpl;
18 import org.objectweb.celtix.testutil.common.AbstractClientServerSetupBase;
19
20 import org.soapinterop.celtix.AxisEchoService;
21 import org.soapinterop.celtix.InteropTestPortType;
22 import org.soapinterop.celtix.SOAPStruct;
23
24 public class CeltixClientEchoTest extends TestCase {
25
26     private final QName JavaDoc serviceName = new QName JavaDoc("http://soapinterop.org/celtix",
27                                                 "AxisEchoService");
28     private final QName JavaDoc portName = new QName JavaDoc("http://soapinterop.org/celtix",
29                                              "Echo");
30
31     private InteropTestPortType port;
32
33     static {
34         System.setProperty(ProviderImpl.JAXWSPROVIDER_PROPERTY, ProviderImpl.JAXWS_PROVIDER);
35     }
36
37     public CeltixClientEchoTest() {
38     }
39
40     public static Test suite() throws Exception JavaDoc {
41         TestSuite suite = new TestSuite(CeltixClientEchoTest.class);
42         return new AbstractClientServerSetupBase(suite) {
43             public void startServers() throws Exception JavaDoc {
44                 boolean ok = launchServer(AxisServer.class);
45                 if (!ok) {
46                     fail("Failed to launch axis server.");
47                 }
48             }
49         };
50     }
51
52     public void setUp() throws Exception JavaDoc {
53         super.setUp();
54         URL JavaDoc wsdl = getClass().getResource("/wsdl/axis_echo.wsdl");
55         assertNotNull("Could not get axis_echo.wsdl resource.", wsdl);
56         
57         AxisEchoService service = new AxisEchoService(wsdl, serviceName);
58         assertNotNull("Failed to create AxisEchoService.", service);
59         
60         port = service.getPort(portName, InteropTestPortType.class);
61     }
62
63     protected boolean equalsDate(XMLGregorianCalendar JavaDoc orig, XMLGregorianCalendar JavaDoc actual) {
64         boolean result = false;
65
66         if ((orig.getYear() == actual.getYear())
67             && (orig.getMonth() == actual.getMonth())
68             && (orig.getDay() == actual.getDay())
69             && (actual.getHour() == DatatypeConstants.FIELD_UNDEFINED)
70             && (actual.getMinute() == DatatypeConstants.FIELD_UNDEFINED)
71             && (actual.getSecond() == DatatypeConstants.FIELD_UNDEFINED)
72             && (actual.getMillisecond() == DatatypeConstants.FIELD_UNDEFINED)) {
73
74             result = orig.getTimezone() == actual.getTimezone();
75         }
76         return result;
77     }
78
79     protected boolean equalsDateTime(XMLGregorianCalendar JavaDoc orig, XMLGregorianCalendar JavaDoc actual) {
80         if ((orig.getYear() == actual.getYear())
81             && (orig.getMonth() == actual.getMonth())
82             && (orig.getDay() == actual.getDay())
83             && (orig.getHour() == actual.getHour())
84             && (orig.getMinute() == actual.getMinute())
85             && (orig.getSecond() == actual.getSecond())) {
86             return (orig.getMillisecond() == DatatypeConstants.FIELD_UNDEFINED
87                 || actual.getMillisecond() == DatatypeConstants.FIELD_UNDEFINED
88                 || orig.getMillisecond() == actual.getMillisecond())
89                 && (orig.getTimezone() == DatatypeConstants.FIELD_UNDEFINED
90                 || actual.getTimezone() == DatatypeConstants.FIELD_UNDEFINED
91                 || orig.getTimezone() == actual.getTimezone());
92         }
93         return false;
94     }
95
96     protected boolean equals(SOAPStruct obj1, SOAPStruct obj2) {
97         if (null == obj1) {
98             return null == obj2;
99         } else {
100             return Float.floatToIntBits(obj1.getVarFloat()) == Float.floatToIntBits(obj2.getVarFloat())
101                 && obj1.getVarInt() == obj2.getVarInt()
102                 && obj1.getVarString().equals(obj2.getVarString());
103         }
104     }
105
106     public void testBoolean() throws Exception JavaDoc {
107         boolean in = true;
108         boolean out = port.echoBoolean(in);
109         assertEquals("echoBoolean : incorrect return value : "
110             + out + " expected : " + in, in, out);
111     }
112
113     public void testFloat() throws Exception JavaDoc {
114         float in = 3.7F;
115         float out = port.echoFloat(in);
116         assertEquals("echoFloat : incorrect return value : "
117             + out + " expected : " + in, in, out);
118     }
119
120     public void testInteger() throws Exception JavaDoc {
121         int in = 42;
122         int out = port.echoInteger(in);
123         assertEquals("echoInteger : incorrect return value : "
124             + out + " expected : " + in, in, out);
125     }
126
127     public void testVoid() throws Exception JavaDoc {
128         port.echoVoid();
129     }
130
131     // TODO: Investigate why this fails.
132
//public void testHexBinary() throws Exception {
133
// byte[] in = "1234".getBytes();
134
// byte[] out = port.echoHexBinary(in);
135
// assertTrue("echoHexBinary : incorrect return value : "
136
// + new String(out) + " expected : " + new String(in), Arrays.equals(in, out));
137
//}
138

139     public void testNegativeInteger() throws Exception JavaDoc {
140         // Test xsd:negativeInteger
141
BigInteger JavaDoc in = new BigInteger JavaDoc("-12345678900987654321");
142         BigInteger JavaDoc out = port.echoNegativeInteger(in);
143         assertEquals("echoNegativeInteger : incorrect return value : "
144             + out + " expected : " + in, in, out);
145     }
146
147     public void testNonNegativeInteger() throws Exception JavaDoc {
148         // Test xsd:nonNegativeInteger
149
BigInteger JavaDoc in = new BigInteger JavaDoc("12345678901234567890");
150         BigInteger JavaDoc out = port.echoNonNegativeInteger(in);
151         assertEquals("echoNonNegativeInteger : incorrect return value : "
152             + out + " expected : " + in, in, out);
153     }
154
155     public void testNonPositiveInteger() throws Exception JavaDoc {
156         // Test xsd:nonPositiveInteger
157
BigInteger JavaDoc in = new BigInteger JavaDoc("-12345678901234567890");
158         BigInteger JavaDoc out = port.echoNonPositiveInteger(in);
159         assertEquals("echoNonPositiveInteger : incorrect return value : "
160             + out + " expected : " + in, in, out);
161     }
162
163     public void testPositiveInteger() throws Exception JavaDoc {
164         // Test xsd:positiveInteger
165
BigInteger JavaDoc in = new BigInteger JavaDoc("12345678900987654321");
166         BigInteger JavaDoc out = port.echoPositiveInteger(in);
167         assertEquals("echoPositiveInteger : incorrect return value : "
168             + out + " expected : " + in, in, out);
169     }
170
171     public void testNormalizedString() throws Exception JavaDoc {
172         // Test xsd:normalizedString
173
String JavaDoc in = "abc-Normalized-def";
174         String JavaDoc out = port.echoNormalizedString(in);
175         assertEquals("echoNormalizedString : incorrect return value : "
176             + out + " expected : " + in, in, out);
177     }
178
179     public void testToken() throws Exception JavaDoc {
180         // Test xsd:token
181
String JavaDoc in = "abc-Token-def";
182         String JavaDoc out = port.echoToken(in);
183         assertEquals("echoToken : incorrect return value : " + out + " expected : " + in, in, out);
184     }
185
186     public void testUnsignedByte() throws Exception JavaDoc {
187         // Test xsd:unsignedByte
188
short in = 103;
189         short out = port.echoUnsignedByte(in);
190         assertEquals("echoUnsignedByte : incorrect return value : "
191             + out + " expected : " + in, in, out);
192     }
193
194     public void testUnsignedInt() throws Exception JavaDoc {
195         // Test xsd:unsignedInt
196
long in = 101;
197         long out = port.echoUnsignedInt(in);
198         assertEquals("echoUnsignedInt : incorrect return value : "
199             + out + " expected : " + in, in, out);
200     }
201
202     public void testUnsignedLong() throws Exception JavaDoc {
203         // Test xsd:unsignedLong
204
BigInteger JavaDoc in = new BigInteger JavaDoc("123456789");
205         BigInteger JavaDoc out = port.echoUnsignedLong(in);
206         assertEquals("echoUnsignedLong : incorrect return value : "
207             + out + " expected : " + in, in, out);
208     }
209
210     public void testUnsignedShort() throws Exception JavaDoc {
211         // Test xsd:unsignedShort
212
int in = 102;
213         int out = port.echoUnsignedShort(in);
214         assertEquals("echoUnsignedShort : incorrect return value : "
215             + out + " expected : " + in, in, out);
216     }
217
218     public void testString() throws Exception JavaDoc {
219         String JavaDoc in = "abcdefg";
220         String JavaDoc out = port.echoString(in);
221         assertEquals("echoString : incorrect return value : "
222             + out + " expected : " + in, in, out);
223     }
224
225     // TODO: Figure out why this hits an assertion in JAXBDataBindingCallback
226
//public void testStringArray() throws Exception {
227
// List<String> in = Arrays.asList("abc", "def");
228
// List<String> out = port.echoStringArray(in);
229
// assertTrue("echoStringArray : incorrect return value : ", in.equals(out));
230
//}
231

232     public void testStruct() throws Exception JavaDoc {
233         SOAPStruct in = new SOAPStruct();
234         in.setVarInt(6);
235         in.setVarString("Rover");
236         in.setVarFloat(1010F);
237         SOAPStruct out = port.echoStruct(in);
238         assertTrue("echoStruct : incorrect return value", equals(in, out));
239     }
240
241     public void testBase64() throws Exception JavaDoc {
242         byte[] in = "Base64".getBytes();
243         byte[] out = port.echoBase64(in);
244         assertTrue("echoBase64 : incorrect return value : ", Arrays.equals(in, out));
245     }
246
247     // TODO: Figure out why this causes a NumberFormatException
248
//public void testDate() throws Exception {
249
// javax.xml.datatype.DatatypeFactory factory = javax.xml.datatype.DatatypeFactory.newInstance();
250
// XMLGregorianCalendar in = factory.newXMLGregorianCalendar();
251
// in.setYear(1975);
252
// in.setMonth(5);
253
// in.setDay(5);
254
// XMLGregorianCalendar out = port.echoDate(in);
255
// assertTrue("echoDate : incorrect return value : "
256
// + out + " expected : " + in, equalsDate(in, out));
257
//}
258

259     public void testDateTime() throws Exception JavaDoc {
260         javax.xml.datatype.DatatypeFactory JavaDoc factory = javax.xml.datatype.DatatypeFactory.newInstance();
261         XMLGregorianCalendar JavaDoc in = factory.newXMLGregorianCalendar();
262         in.setYear(1975);
263         in.setMonth(5);
264         in.setDay(5);
265         in.setHour(12);
266         in.setMinute(30);
267         in.setSecond(15);
268         XMLGregorianCalendar JavaDoc out = port.echoDateTime(in);
269         assertTrue("echoDate : incorrect return value : "
270             + out + " expected : " + in, equalsDateTime(in, out));
271     }
272
273     public void testDecimal() throws Exception JavaDoc {
274         BigDecimal JavaDoc in = new BigDecimal JavaDoc("3.14159");
275         BigDecimal JavaDoc out = port.echoDecimal(in);
276         assertEquals("echoDecimal : incorrect return value : "
277             + out + " expected : " + in, in, out);
278     }
279
280     public static void main(String JavaDoc[] args) {
281         junit.textui.TestRunner.run(CeltixClientEchoTest.class);
282     }
283
284 }
285
Popular Tags