1 7 package org.jboss.test.webservice.marshalltest; 8 9 11 import org.jboss.test.webservice.WebserviceTestBase; 12 import org.jboss.test.webservice.marshalltest.types.Bean; 13 14 import javax.xml.namespace.QName ; 15 import java.math.BigDecimal ; 16 import java.math.BigInteger ; 17 import java.util.Arrays ; 18 import java.util.Calendar ; 19 import java.util.Date ; 20 import java.util.GregorianCalendar ; 21 import java.util.TimeZone ; 22 23 29 public abstract class AbstractRpcTestBase extends WebserviceTestBase 30 { 31 protected static MarshallRpcServiceInterface rpcPort; 32 33 36 public AbstractRpcTestBase(String name) 37 { 38 super(name); 39 } 40 41 public void testEchoString() throws Exception 42 { 43 Object 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 54 { 55 Object ret = rpcPort.echoInteger(new BigInteger ("100")); 56 assertEquals(new BigInteger ("100"), ret); 57 58 ret = rpcPort.echoInteger(null); 59 assertNull(ret); 60 } 61 62 public void testEchoInt() throws Exception 63 { 64 int ret = rpcPort.echoInt(100); 65 assertEquals(100, ret); 66 } 67 68 public void testEchoLong() throws Exception 69 { 70 long ret = rpcPort.echoLong(100); 71 assertEquals(100, ret); 72 } 73 74 public void testEchoShort() throws Exception 75 { 76 short ret = rpcPort.echoShort((short)100); 77 assertEquals((short)100, ret); 78 } 79 80 public void testEchoDecimal() throws Exception 81 { 82 Object ret = rpcPort.echoDecimal(new BigDecimal ("100")); 83 assertEquals(new BigDecimal ("100"), ret); 84 85 ret = rpcPort.echoDecimal(null); 86 assertNull(ret); 87 } 88 89 public void testEchoFloat() throws Exception 90 { 91 float ret = rpcPort.echoFloat((float)100.3); 92 assertEquals(100.3, ret, 0.0001); 93 } 94 95 public void testEchoDouble() throws Exception 96 { 97 double ret = rpcPort.echoDouble(100.7); 98 assertEquals(100.7, ret, 0.0001); 99 } 100 101 public void testEchoBoolean() throws Exception 102 { 103 boolean ret = rpcPort.echoBoolean(true); 104 assertEquals(true, ret); 105 } 106 107 public void testEchoByte() throws Exception 108 { 109 byte ret = rpcPort.echoByte((byte)0x6a); 110 assertEquals((byte)0x6a, ret); 111 } 112 113 public void testEchoQName() throws Exception 114 { 115 Object ret = rpcPort.echoQName(new QName ("uri", "local")); 116 assertEquals(new QName ("uri", "local"), ret); 117 118 ret = rpcPort.echoQName(null); 119 assertNull(ret); 120 } 121 122 public void testEchoDateTimeCalendar() throws Exception 123 { 124 Calendar cal = new GregorianCalendar (TimeZone.getTimeZone("GMT+1")); 125 Calendar ret = (Calendar )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 134 { 135 Date date = new Date (); 136 Date 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 144 { 145 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Hong_Kong")); 146 cal.clear(); 147 cal.set(2004, 11, 21); 148 Calendar 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 157 { 158 Calendar cal = Calendar.getInstance(); 159 cal.clear(); 160 cal.set(2004, 11, 21); 161 Date 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 169 { 170 byte[] bytes = "Hello world!".getBytes(); 171 Object ret = rpcPort.echoBase64Binary(bytes); 172 assertEquals("Hello world!", new String ((byte[])ret)); 173 174 ret = rpcPort.echoBase64Binary(null); 175 assertNull(ret); 176 } 177 178 public void testEchoHexBinary() throws Exception 179 { 180 byte[] bytes = "Hello world!".getBytes(); 181 Object ret = rpcPort.echoHexBinary(bytes); 182 assertEquals("Hello world!", new String ((byte[])ret)); 183 184 ret = rpcPort.echoHexBinary(null); 185 assertNull(ret); 186 } 187 188 public void testEchoBean() throws Exception 189 { 190 Bean bean = new Bean(); 191 bean.setX(1); 192 bean.setY(2); 193 bean.setBase64("base64".getBytes()); 194 195 Object ret = rpcPort.echoBean(bean); 196 assertEquals(bean, ret); 197 198 ret = rpcPort.echoBean(null); 199 assertNull(ret); 200 } 201 202 public void testEchoBeanNullProperties() throws Exception 204 { 205 Bean bean = new Bean(); 206 207 Object ret = rpcPort.echoBean(bean); 209 assertEquals(bean, ret); 210 211 bean.setBase64(new byte[0]); 213 214 ret = rpcPort.echoBean(bean); 215 assertEquals(bean, ret); 216 } 217 218 public void testEchoStringArray() throws Exception 219 { 220 String [] arr = new String []{"Hello", "world", "!"}; 221 Object ret = rpcPort.echoStringArray(arr); 222 assertEquals(Arrays.asList(arr), Arrays.asList((String [])ret)); 223 } 224 225 public void testEchoIntegerArray() throws Exception 226 { 227 BigInteger [] arr = new BigInteger []{new BigInteger ("1"), new BigInteger ("0"), new BigInteger ("-1")}; 228 Object ret = rpcPort.echoIntegerArray(arr); 229 assertEquals(Arrays.asList(arr), Arrays.asList((BigInteger [])ret)); 230 } 231 232 public void testEchoIntArray() throws Exception 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 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 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 257 { 258 BigDecimal [] arr = new BigDecimal []{new BigDecimal ("1"), new BigDecimal ("0"), new BigDecimal ("-1")}; 259 Object ret = rpcPort.echoDecimalArray(arr); 260 assertEquals(Arrays.asList(arr), Arrays.asList((BigDecimal [])ret)); 261 } 262 263 public void testEchoFloatArray() throws Exception 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 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 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 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 296 { 297 QName [] arr = new QName []{new QName ("uri", "loc1"), new QName ("uri", "loc2"), new QName ("uri", "loc3")}; 298 QName [] ret = (QName [])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 [])ret)); 302 } 303 304 public void testEchoDateTimeArray() throws Exception 305 { 306 Calendar cal1 = new GregorianCalendar (2004, 5, 10); 307 Calendar cal2 = new GregorianCalendar (2004, 5, 11); 308 Calendar cal3 = new GregorianCalendar (2004, 5, 12); 309 Calendar [] arr = new Calendar []{cal1, cal2, cal3}; 310 Calendar [] ret = (Calendar [])rpcPort.echoDateTimeArray(arr); 311 312 for (int i = 0; i < arr.length; i++) 314 assertEquals(arr[i].getTime(), ret[i].getTime()); 315 } 316 } 317 | Popular Tags |