1 22 package org.jboss.test.webservice.marshalltest; 23 24 import java.math.BigDecimal ; 25 import java.math.BigInteger ; 26 import java.util.Arrays ; 27 import java.util.Calendar ; 28 import java.util.Date ; 29 import java.util.GregorianCalendar ; 30 import java.util.TimeZone ; 31 32 import javax.xml.namespace.QName ; 33 34 import org.jboss.test.webservice.WebserviceTestBase; 35 import org.jboss.test.webservice.marshalltest.types.Bean; 36 37 43 public class MarshallTestBase extends WebserviceTestBase 44 { 45 protected MarshallEndpoint port; 46 47 public MarshallTestBase(String name) 48 { 49 super(name); 50 } 51 52 public void testEchoString() throws Exception 53 { 54 Object 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 65 { 66 Object ret = port.echoInteger(new BigInteger ("100")); 67 assertEquals(new BigInteger ("100"), ret); 68 69 ret = port.echoInteger(null); 70 assertNull(ret); 71 } 72 73 public void testEchoInt() throws Exception 74 { 75 int ret = port.echoInt(100); 76 assertEquals(100, ret); 77 } 78 79 public void testEchoLong() throws Exception 80 { 81 long ret = port.echoLong(100); 82 assertEquals(100, ret); 83 } 84 85 public void testEchoShort() throws Exception 86 { 87 short ret = port.echoShort((short)100); 88 assertEquals((short)100, ret); 89 } 90 91 public void testEchoDecimal() throws Exception 92 { 93 Object ret = port.echoDecimal(new BigDecimal ("100")); 94 assertEquals(new BigDecimal ("100"), ret); 95 96 ret = port.echoDecimal(null); 97 assertNull(ret); 98 } 99 100 public void testEchoFloat() throws Exception 101 { 102 float ret = port.echoFloat((float)100.3); 103 assertEquals(100.3, ret, 0.0001); 104 } 105 106 public void testEchoDouble() throws Exception 107 { 108 double ret = port.echoDouble(100.7); 109 assertEquals(100.7, ret, 0.0001); 110 } 111 112 public void testEchoBoolean() throws Exception 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 122 { 123 byte ret = port.echoByte((byte)0x6a); 124 assertEquals((byte)0x6a, ret); 125 } 126 127 public void testEchoQName() throws Exception 128 { 129 Object ret = port.echoQName(new QName ("uri", "local")); 130 assertEquals(new QName ("uri", "local"), ret); 131 132 ret = port.echoQName(null); 133 assertNull(ret); 134 } 135 136 public void testEchoDateTimeCalendar() throws Exception 137 { 138 Calendar cal = new GregorianCalendar (TimeZone.getTimeZone("GMT+1")); 139 Calendar ret = (Calendar )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 148 { 149 Calendar cal = Calendar.getInstance(); 150 cal.clear(); 151 cal.set(2004, 11, 21, 14, 20, 30); 152 Date date = cal.getTime(); 153 154 Date 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 162 { 163 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Hong_Kong")); 164 cal.clear(); 165 cal.set(2004, 11, 21); 166 Calendar 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 175 { 176 Calendar cal = Calendar.getInstance(); 177 cal.clear(); 178 cal.set(2004, 11, 21); 179 Date 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 187 { 188 byte[] bytes = "Hello world!".getBytes(); 189 Object ret = port.echoBase64Binary(bytes); 190 assertEquals("Hello world!", new String ((byte[])ret)); 191 192 ret = port.echoBase64Binary(null); 193 assertNull(ret); 194 } 195 196 public void testEchoHexBinary() throws Exception 197 { 198 byte[] bytes = "Hello world!".getBytes(); 199 Object ret = port.echoHexBinary(bytes); 200 assertEquals("Hello world!", new String ((byte[])ret)); 201 202 ret = port.echoHexBinary(null); 203 assertNull(ret); 204 } 205 206 public void testEchoBean() throws Exception 207 { 208 Bean bean = new Bean(); 209 bean.setX(1); 210 bean.setY(2); 211 bean.setBase64("base64".getBytes()); 212 213 Object ret = port.echoBean(bean); 214 assertEquals(bean, ret); 215 216 ret = port.echoBean(null); 217 assertNull(ret); 218 } 219 220 public void testEchoBeanNullProperties() throws Exception 222 { 223 Bean bean = new Bean(); 224 225 Object ret = port.echoBean(bean); 227 assertEquals(bean, ret); 228 229 bean.setBase64(new byte[0]); 231 232 ret = port.echoBean(bean); 233 assertEquals(bean, ret); 234 } 235 236 public void testEchoStringArray() throws Exception 237 { 238 String [] arr = new String [] { "Hello", "world", "!" }; 239 Object ret = port.echoStringArray(arr); 240 assertEquals(Arrays.asList(arr), Arrays.asList((String [])ret)); 241 } 242 243 public void testEchoIntegerArray() throws Exception 244 { 245 BigInteger [] arr = new BigInteger [] { new BigInteger ("1"), new BigInteger ("0"), new BigInteger ("-1") }; 246 Object ret = port.echoIntegerArray(arr); 247 assertEquals(Arrays.asList(arr), Arrays.asList((BigInteger [])ret)); 248 } 249 250 public void testEchoIntArray() throws Exception 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 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 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 275 { 276 BigDecimal [] arr = new BigDecimal [] { new BigDecimal ("1"), new BigDecimal ("0"), new BigDecimal ("-1") }; 277 Object ret = port.echoDecimalArray(arr); 278 assertEquals(Arrays.asList(arr), Arrays.asList((BigDecimal [])ret)); 279 } 280 281 public void testEchoFloatArray() throws Exception 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 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 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 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 314 { 315 QName [] arr = new QName [] { new QName ("uri", "loc1"), new QName ("uri", "loc2"), new QName ("uri", "loc3") }; 316 QName [] ret = (QName [])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 [])ret)); 320 } 321 322 public void testEchoDateTimeArray() throws Exception 323 { 324 Calendar cal1 = Calendar.getInstance(); 325 cal1.clear(); cal1.set(2004, 5, 10, 14, 23, 30); 326 cal1.setTimeZone(TimeZone.getTimeZone("GMT+1")); 327 Calendar cal2 = Calendar.getInstance(); 328 cal2.clear(); cal2.set(2004, 5, 11, 14, 23, 31); 329 cal2.setTimeZone(TimeZone.getTimeZone("GMT+1")); 330 Calendar cal3 = Calendar.getInstance(); 331 cal3.clear(); cal3.set(2004, 5, 12, 14, 23, 32); 332 cal3.setTimeZone(TimeZone.getTimeZone("GMT+1")); 333 Calendar [] arr = new Calendar [] { cal1, cal2, cal3 }; 334 Calendar [] ret = (Calendar [])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 |