KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.webservice.marshalltest;
23
24 import java.math.BigDecimal JavaDoc;
25 import java.math.BigInteger JavaDoc;
26 import java.util.Arrays JavaDoc;
27 import java.util.Calendar JavaDoc;
28 import java.util.Date JavaDoc;
29 import java.util.GregorianCalendar JavaDoc;
30 import java.util.TimeZone JavaDoc;
31
32 import javax.xml.namespace.QName JavaDoc;
33
34 import org.jboss.test.webservice.WebserviceTestBase;
35 import org.jboss.test.webservice.marshalltest.types.Bean;
36
37 /**
38  * Tests of the ws4ee rpc/literal marshalling
39  *
40  * @author Thomas.Diesler@jboss.org
41  * @since 09-May-2004
42  */

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