KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > marshalltest > AbstractRpcTestBase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.webservice.marshalltest;
8
9 // $Id: AbstractRpcTestBase.java,v 1.1.2.6 2005/03/04 22:11:49 tdiesler Exp $
10

11 import org.jboss.test.webservice.WebserviceTestBase;
12 import org.jboss.test.webservice.marshalltest.types.Bean;
13
14 import javax.xml.namespace.QName JavaDoc;
15 import java.math.BigDecimal JavaDoc;
16 import java.math.BigInteger JavaDoc;
17 import java.util.Arrays JavaDoc;
18 import java.util.Calendar JavaDoc;
19 import java.util.Date JavaDoc;
20 import java.util.GregorianCalendar JavaDoc;
21 import java.util.TimeZone JavaDoc;
22
23 /**
24  * Tests of the ws4ee marshalling
25  *
26  * @author Thomas.Diesler@jboss.org
27  * @since 09-May-2004
28  */

29 public abstract class AbstractRpcTestBase extends WebserviceTestBase
30 {
31    protected static MarshallRpcServiceInterface rpcPort;
32
33    /**
34     * Construct the test case with a given name
35     */

36    public AbstractRpcTestBase(String JavaDoc name)
37    {
38       super(name);
39    }
40
41    public void testEchoString() throws Exception JavaDoc
42    {
43       Object JavaDoc ret = rpcPort.echoString("Hello");
44       assertEquals("Hello", ret);
45
46       ret = rpcPort.echoString("");
47       assertEquals("", ret);
48
49       ret = rpcPort.echoString(null);
50       assertNull(ret);
51    }
52
53    public void testEchoInteger() throws Exception JavaDoc
54    {
55       Object JavaDoc ret = rpcPort.echoInteger(new BigInteger JavaDoc("100"));
56       assertEquals(new BigInteger JavaDoc("100"), ret);
57
58       ret = rpcPort.echoInteger(null);
59       assertNull(ret);
60    }
61
62    public void testEchoInt() throws Exception JavaDoc
63    {
64       int ret = rpcPort.echoInt(100);
65       assertEquals(100, ret);
66    }
67
68    public void testEchoLong() throws Exception JavaDoc
69    {
70       long ret = rpcPort.echoLong(100);
71       assertEquals(100, ret);
72    }
73
74    public void testEchoShort() throws Exception JavaDoc
75    {
76       short ret = rpcPort.echoShort((short)100);
77       assertEquals((short)100, ret);
78    }
79
80    public void testEchoDecimal() throws Exception JavaDoc
81    {
82       Object JavaDoc ret = rpcPort.echoDecimal(new BigDecimal JavaDoc("100"));
83       assertEquals(new BigDecimal JavaDoc("100"), ret);
84
85       ret = rpcPort.echoDecimal(null);
86       assertNull(ret);
87    }
88
89    public void testEchoFloat() throws Exception JavaDoc
90    {
91       float ret = rpcPort.echoFloat((float)100.3);
92       assertEquals(100.3, ret, 0.0001);
93    }
94
95    public void testEchoDouble() throws Exception JavaDoc
96    {
97       double ret = rpcPort.echoDouble(100.7);
98       assertEquals(100.7, ret, 0.0001);
99    }
100
101    public void testEchoBoolean() throws Exception JavaDoc
102    {
103       boolean ret = rpcPort.echoBoolean(true);
104       assertEquals(true, ret);
105    }
106
107    public void testEchoByte() throws Exception JavaDoc
108    {
109       byte ret = rpcPort.echoByte((byte)0x6a);
110       assertEquals((byte)0x6a, ret);
111    }
112
113    public void testEchoQName() throws Exception JavaDoc
114    {
115       Object JavaDoc ret = rpcPort.echoQName(new QName JavaDoc("uri", "local"));
116       assertEquals(new QName JavaDoc("uri", "local"), ret);
117
118       ret = rpcPort.echoQName(null);
119       assertNull(ret);
120    }
121
122    public void testEchoDateTimeCalendar() throws Exception JavaDoc
123    {
124       Calendar JavaDoc cal = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT+1"));
125       Calendar JavaDoc ret = (Calendar JavaDoc)rpcPort.echoDateTimeCalendar(cal);
126       assertEquals(cal.getTime(), ret.getTime());
127       assertEquals(cal.get(Calendar.ZONE_OFFSET), ret.get(Calendar.ZONE_OFFSET));
128
129       ret = rpcPort.echoDateTimeCalendar(null);
130       assertNull(ret);
131    }
132
133    public void testEchoDateTimeDate() throws Exception JavaDoc
134    {
135       Date JavaDoc date = new Date JavaDoc();
136       Date JavaDoc ret = rpcPort.echoDateTimeDate(date);
137       assertEquals(date.getTime(), ret.getTime());
138
139       ret = rpcPort.echoDateTimeDate(null);
140       assertNull(ret);
141    }
142
143    public void testEchoDateCalendar() throws Exception JavaDoc
144    {
145       Calendar JavaDoc cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Hong_Kong"));
146       cal.clear();
147       cal.set(2004, 11, 21);
148       Calendar JavaDoc ret = rpcPort.echoDateCalendar(cal);
149       assertEquals(cal.getTime().getTime(), ret.getTime().getTime());
150       assertEquals(cal.get(Calendar.ZONE_OFFSET), ret.get(Calendar.ZONE_OFFSET));
151
152       ret = rpcPort.echoDateCalendar(null);
153       assertNull(ret);
154    }
155
156    public void testEchoDateDate() throws Exception JavaDoc
157    {
158       Calendar JavaDoc cal = Calendar.getInstance();
159       cal.clear();
160       cal.set(2004, 11, 21);
161       Date JavaDoc ret = rpcPort.echoDateDate(cal.getTime());
162       assertEquals(cal.getTime().getTime(), ret.getTime());
163
164       ret = rpcPort.echoDateDate(null);
165       assertNull(ret);
166    }
167
168    public void testEchoBase64Binary() throws Exception JavaDoc
169    {
170       byte[] bytes = "Hello world!".getBytes();
171       Object JavaDoc ret = rpcPort.echoBase64Binary(bytes);
172       assertEquals("Hello world!", new String JavaDoc((byte[])ret));
173
174       ret = rpcPort.echoBase64Binary(null);
175       assertNull(ret);
176    }
177
178    public void testEchoHexBinary() throws Exception JavaDoc
179    {
180       byte[] bytes = "Hello world!".getBytes();
181       Object JavaDoc ret = rpcPort.echoHexBinary(bytes);
182       assertEquals("Hello world!", new String JavaDoc((byte[])ret));
183
184       ret = rpcPort.echoHexBinary(null);
185       assertNull(ret);
186    }
187
188    public void testEchoBean() throws Exception JavaDoc
189    {
190       Bean bean = new Bean();
191       bean.setX(1);
192       bean.setY(2);
193       bean.setBase64("base64".getBytes());
194
195       Object JavaDoc ret = rpcPort.echoBean(bean);
196       assertEquals(bean, ret);
197
198       ret = rpcPort.echoBean(null);
199       assertNull(ret);
200    }
201
202    // See: http://jira.jboss.com/jira/browse/JBWS-30
203
public void testEchoBeanNullProperties() throws Exception JavaDoc
204    {
205       Bean bean = new Bean();
206
207       // Test null byte array
208
Object JavaDoc ret = rpcPort.echoBean(bean);
209       assertEquals(bean, ret);
210
211       // Test empty byte array
212
bean.setBase64(new byte[0]);
213
214       ret = rpcPort.echoBean(bean);
215       assertEquals(bean, ret);
216    }
217
218    public void testEchoStringArray() throws Exception JavaDoc
219    {
220       String JavaDoc[] arr = new String JavaDoc[]{"Hello", "world", "!"};
221       Object JavaDoc ret = rpcPort.echoStringArray(arr);
222       assertEquals(Arrays.asList(arr), Arrays.asList((String JavaDoc[])ret));
223    }
224
225    public void testEchoIntegerArray() throws Exception JavaDoc
226    {
227       BigInteger JavaDoc[] arr = new BigInteger JavaDoc[]{new BigInteger JavaDoc("1"), new BigInteger JavaDoc("0"), new BigInteger JavaDoc("-1")};
228       Object JavaDoc ret = rpcPort.echoIntegerArray(arr);
229       assertEquals(Arrays.asList(arr), Arrays.asList((BigInteger JavaDoc[])ret));
230    }
231
232    public void testEchoIntArray() throws Exception JavaDoc
233    {
234       int[] arr = new int[]{1, 0, -1};
235       int[] ret = (int[])rpcPort.echoIntArray(arr);
236       for (int i = 0; i < arr.length; i++)
237          assertEquals(arr[i], ret[i]);
238    }
239
240    public void testEchoLongArray() throws Exception JavaDoc
241    {
242       long[] arr = new long[]{1, 0, -1};
243       long[] ret = (long[])rpcPort.echoLongArray(arr);
244       for (int i = 0; i < arr.length; i++)
245          assertEquals(arr[i], ret[i]);
246    }
247
248    public void testEchoShortArray() throws Exception JavaDoc
249    {
250       short[] arr = new short[]{1, 0, -1};
251       short[] ret = (short[])rpcPort.echoShortArray(arr);
252       for (int i = 0; i < arr.length; i++)
253          assertEquals(arr[i], ret[i]);
254    }
255
256    public void testEchoDecimalArray() throws Exception JavaDoc
257    {
258       BigDecimal JavaDoc[] arr = new BigDecimal JavaDoc[]{new BigDecimal JavaDoc("1"), new BigDecimal JavaDoc("0"), new BigDecimal JavaDoc("-1")};
259       Object JavaDoc ret = rpcPort.echoDecimalArray(arr);
260       assertEquals(Arrays.asList(arr), Arrays.asList((BigDecimal JavaDoc[])ret));
261    }
262
263    public void testEchoFloatArray() throws Exception JavaDoc
264    {
265       float[] arr = new float[]{1, 0, -1};
266       float[] ret = (float[])rpcPort.echoFloatArray(arr);
267       for (int i = 0; i < arr.length; i++)
268          assertEquals(arr[i], ret[i], 0);
269    }
270
271    public void testEchoDoubleArray() throws Exception JavaDoc
272    {
273       double[] arr = new double[]{1, 0, -1};
274       double[] ret = (double[])rpcPort.echoDoubleArray(arr);
275       for (int i = 0; i < arr.length; i++)
276          assertEquals(arr[i], ret[i], 0);
277    }
278
279    public void testEchoBooleanArray() throws Exception JavaDoc
280    {
281       boolean[] arr = new boolean[]{true, false, true};
282       boolean[] ret = (boolean[])rpcPort.echoBooleanArray(arr);
283       for (int i = 0; i < arr.length; i++)
284          assertEquals(arr[i], ret[i]);
285    }
286
287    public void testEchoByteArray() throws Exception JavaDoc
288    {
289       byte[] arr = new byte[]{1, 0, -1};
290       byte[] ret = (byte[])rpcPort.echoByteArray(arr);
291       for (int i = 0; i < arr.length; i++)
292          assertEquals(arr[i], ret[i]);
293    }
294
295    public void testEchoQNameArray() throws Exception JavaDoc
296    {
297       QName JavaDoc[] arr = new QName JavaDoc[]{new QName JavaDoc("uri", "loc1"), new QName JavaDoc("uri", "loc2"), new QName JavaDoc("uri", "loc3")};
298       QName JavaDoc[] ret = (QName JavaDoc[])rpcPort.echoQNameArray(arr);
299       for (int i = 0; i < arr.length; i++)
300          assertEquals(arr[i], ret[i]);
301       assertEquals(Arrays.asList(arr), Arrays.asList((QName JavaDoc[])ret));
302    }
303
304    public void testEchoDateTimeArray() throws Exception JavaDoc
305    {
306       Calendar JavaDoc cal1 = new GregorianCalendar JavaDoc(2004, 5, 10);
307       Calendar JavaDoc cal2 = new GregorianCalendar JavaDoc(2004, 5, 11);
308       Calendar JavaDoc cal3 = new GregorianCalendar JavaDoc(2004, 5, 12);
309       Calendar JavaDoc[] arr = new Calendar JavaDoc[]{cal1, cal2, cal3};
310       Calendar JavaDoc[] ret = (Calendar JavaDoc[])rpcPort.echoDateTimeArray(arr);
311
312       // Note, the TimeZone is not encoded, so the server might change it
313
for (int i = 0; i < arr.length; i++)
314          assertEquals(arr[i].getTime(), ret[i].getTime());
315    }
316 }
317
Popular Tags