1 package org.jacorb.test.orb.rmi; 2 3 22 23 import java.rmi.Remote ; 24 import java.util.Properties ; 25 import javax.rmi.PortableRemoteObject ; 26 import junit.framework.Test; 27 import junit.framework.TestSuite; 28 import junit.framework.Assert; 29 import org.jacorb.test.common.ClientServerSetup; 30 import org.jacorb.test.common.ClientServerTestCase; 31 import org.jacorb.test.orb.rmi.Boo; 32 import org.jacorb.test.orb.rmi.Foo; 33 import org.jacorb.test.orb.rmi.NegativeArgumentException; 34 35 public class RMITest extends ClientServerTestCase 36 { 37 private RMITestInterface server; 38 39 public RMITest(String name, ClientServerSetup setup) 40 { 41 super(name, setup); 42 } 43 44 public void setUp() throws Exception 45 { 46 server = (RMITestInterface)javax.rmi.PortableRemoteObject.narrow( 47 setup.getServerObject(), 48 RMITestInterface.class); 49 } 50 51 public static Test suite() 52 { 53 TestSuite suite = new TestSuite( "RMI/IIOP tests" ); 54 55 Properties client_props = new Properties (); 56 client_props.setProperty 57 ("jacorb.interop.strict_check_on_tc_creation", "off"); 58 59 Properties server_props = new Properties (); 60 server_props.setProperty 61 ("jacorb.interop.strict_check_on_tc_creation", "off"); 62 63 ClientServerSetup setup = 64 new ClientServerSetup( suite, 65 "org.jacorb.test.orb.rmi.RMITestServant", 66 client_props, 67 server_props); 68 69 suite.addTest( new RMITest( "test_getString", setup )); 70 suite.addTest( new RMITest( "test_primitiveTypes", setup )); 71 suite.addTest( new RMITest( "test_String", setup )); 72 suite.addTest( new RMITest( "test_RMITestInterface", setup )); 73 suite.addTest( new RMITest( "test_Remote", setup )); 74 suite.addTest( new RMITest( "test_Serializable", setup )); 75 suite.addTest( new RMITest( "test_intArray", setup )); 76 suite.addTest( new RMITest( "test_valueArray", setup )); 77 suite.addTest( new RMITest( "test_exception", setup )); 78 suite.addTest( new RMITest( "test_FooValueToObject", setup )); 79 suite.addTest( new RMITest( "test_BooValueToObject", setup )); 80 suite.addTest( new RMITest( "test_valueArrayToVector", setup )); 81 suite.addTest( new RMITest( "test_vectorToValueArray", setup )); 82 suite.addTest( new RMITest( "test_getException", setup )); 83 suite.addTest( new RMITest( "test_getZooValue", setup )); 84 suite.addTest( new RMITest( "test_referenceSharingWithinArray", 85 setup )); 86 suite.addTest( new RMITest( "test_referenceSharingWithinCollection", 87 setup )); 88 suite.addTest( new RMITest( "test_getVectorWithObjectArrayAsElement", 89 setup )); 90 suite.addTest( new RMITest( "test_getVectorWithVectorAsElement", 91 setup )); 92 suite.addTest( new RMITest( "test_getVectorWithHashtableAsElement", 93 setup )); 94 95 return setup; 96 } 97 98 public void test_getString() 99 { 100 try 101 { 102 String s = server.getString(); 104 assertEquals(RMITestUtil.STRING, s); 106 } 107 catch (java.rmi.RemoteException re) 108 { 109 throw new RuntimeException (re.toString()); 110 } 111 } 112 113 public void test_primitiveTypes() 114 { 115 try 116 { 117 String s; 118 s = server.testPrimitiveTypes(false, 120 'A', 121 Byte.MIN_VALUE, 122 Short.MIN_VALUE, 123 Integer.MIN_VALUE, 124 Long.MIN_VALUE, 125 Float.MIN_VALUE, 126 Double.MIN_VALUE); 127 assertEquals(RMITestUtil.primitiveTypesToString(false, 129 'A', 130 Byte.MIN_VALUE, 131 Short.MIN_VALUE, 132 Integer.MIN_VALUE, 133 Long.MIN_VALUE, 134 Float.MIN_VALUE, 135 Double.MIN_VALUE), 136 s); 137 s = server.testPrimitiveTypes(true, 138 'Z', 139 Byte.MAX_VALUE, 140 Short.MAX_VALUE, 141 Integer.MAX_VALUE, 142 Long.MAX_VALUE, 143 Float.MAX_VALUE, 144 Double.MAX_VALUE); 145 assertEquals(RMITestUtil.primitiveTypesToString(true, 147 'Z', 148 Byte.MAX_VALUE, 149 Short.MAX_VALUE, 150 Integer.MAX_VALUE, 151 Long.MAX_VALUE, 152 Float.MAX_VALUE, 153 Double.MAX_VALUE), 154 s); 155 } 156 catch (java.rmi.RemoteException re) 157 { 158 throw new RuntimeException (re.toString()); 159 } 160 } 161 162 public void test_String() 163 { 164 try 165 { 166 String original = "0123456789"; 168 String echoedBack = server.testString("0123456789"); 169 assertEquals(RMITestUtil.echo(original), echoedBack); 171 } 172 catch (java.rmi.RemoteException re) 173 { 174 throw new RuntimeException (re.toString()); 175 } 176 } 177 178 public void test_RMITestInterface() 179 { 180 try 181 { 182 RMITestInterface t = 184 server.testRMITestInterface("the quick brown fox", server); 185 String s = t.getString(); 186 assertEquals(RMITestUtil.STRING, s); 188 } 189 catch (java.rmi.RemoteException re) 190 { 191 throw new RuntimeException (re.toString()); 192 } 193 } 194 195 public void test_Remote() 196 { 197 try 198 { 199 Remote r = server.testRemote("jumps over the lazy dog", server); 201 RMITestInterface t = 202 (RMITestInterface)PortableRemoteObject.narrow(r, 203 RMITestInterface.class); 204 String s = t.getString(); 205 assertEquals(RMITestUtil.STRING, s); 207 } 208 catch (java.rmi.RemoteException re) 209 { 210 throw new RuntimeException (re.toString()); 211 } 212 } 213 214 public void test_Serializable() 215 { 216 try 217 { 218 Foo original = new Foo(7, "foo test"); 220 Foo echoedBack = server.testSerializable(original); 221 assertEquals(RMITestUtil.echoFoo(original), echoedBack); 223 } 224 catch (java.rmi.RemoteException re) 225 { 226 throw new RuntimeException (re.toString()); 227 } 228 } 229 230 public void test_intArray() 231 { 232 try 233 { 234 int[] original= new int[10]; 236 for (int i = 0; i < original.length; i++) 237 { 238 original[i] = 100 + i; 239 } 240 int[] echoedBack = server.testIntArray(original); 241 assertEquals(original.length, echoedBack.length); 242 for (int i = 0; i < echoedBack.length; i++) 243 { 244 assertEquals(original[i] + 1, echoedBack[i]); 246 } 247 } 249 catch (java.rmi.RemoteException re) 250 { 251 throw new RuntimeException (re.toString()); 252 } 253 } 254 255 public void test_valueArray() 256 { 257 try 258 { 259 Foo[] original = new Foo[4]; 261 for (int i = 0; i < original.length; i++) 262 { 263 original[i] = new Foo(100 + i, "foo array test"); 264 } 265 Foo[] echoedBack = server.testValueArray(original); 266 assertEquals(original.length, echoedBack.length); 267 for (int i = 0; i < echoedBack.length; i++) 268 { 269 assertEquals(RMITestUtil.echoFoo(original[i]), echoedBack[i]); 271 } 272 } 273 catch (java.rmi.RemoteException re) 274 { 275 throw new RuntimeException (re.toString()); 276 } 277 } 278 279 public void test_exception() 280 { 281 try 282 { 283 285 assertEquals("#0", server.testException(0)); 287 assertEquals("#1", server.testException(1)); 289 assertEquals("#2", server.testException(2)); 291 try 292 { 293 server.testException(-2); 294 fail("NegativeArgumentException expected but not thrown."); 295 } 296 catch (NegativeArgumentException na) 297 { 298 assertEquals(-2, na.getNegativeArgument()); 300 } 301 try 302 { 303 server.testException(-1); 304 fail("NegativeArgumentException expected but not thrown."); 305 } 306 catch (NegativeArgumentException na) 307 { 308 assertEquals(-1, na.getNegativeArgument()); 310 } 311 assertEquals("#0", server.testException(0)); 313 } 314 catch (NegativeArgumentException na) 315 { 316 throw new RuntimeException (na.toString()); 317 } 318 catch (java.rmi.RemoteException re) 319 { 320 throw new RuntimeException (re.toString()); 321 } 322 } 323 324 public void test_FooValueToObject() 325 { 326 try 327 { 328 Foo original = new Foo(9999, "foo test"); 330 java.lang.Object echoedBack = server.fooValueToObject(original); 331 assertEquals(RMITestUtil.echoFoo(original), echoedBack); 333 } 334 catch (java.rmi.RemoteException re) 335 { 336 throw new RuntimeException (re.toString()); 337 } 338 } 339 340 public void test_BooValueToObject() 341 { 342 try 343 { 344 Boo original = new Boo("t1", "boo test"); 346 java.lang.Object echoedBack = server.booValueToObject(original); 347 assertEquals(RMITestUtil.echoBoo(original), echoedBack); 349 } 350 catch (java.rmi.RemoteException re) 351 { 352 throw new RuntimeException (re.toString()); 353 } 354 } 355 356 public void test_valueArrayToVector() 357 { 358 try 359 { 360 Foo[] original = new Foo[4]; 362 for (int i = 0; i < original.length; i++) 363 { 364 original[i] = new Foo(100 + i, "foo vector test"); 365 } 366 java.util.Vector v = server.valueArrayToVector(original); 367 java.lang.Object [] echoedBack = v.toArray(); 368 assertEquals(original.length, echoedBack.length); 369 for (int i = 0; i < echoedBack.length; i++) 370 { 371 assertEquals(RMITestUtil.echoFoo(original[i]), echoedBack[i]); 373 } 374 } 375 catch (java.rmi.RemoteException re) 376 { 377 throw new RuntimeException (re.toString()); 378 } 379 } 380 381 public void test_vectorToValueArray() 382 { 383 try 384 { 385 Foo[] original = new Foo[4]; 386 for (int i = 0; i < original.length; i++) 387 { 388 original[i] = new Foo(100 + i, "foo vector test"); 389 } 390 391 java.util.Vector v = server.valueArrayToVector(original); 393 Foo[] echoedBack = server.vectorToValueArray(v); 394 assertEquals(original.length, echoedBack.length); 395 for (int i = 0; i < echoedBack.length; i++) 396 { 397 assertEquals( 399 RMITestUtil.echoFoo(RMITestUtil.echoFoo(original[i])), 400 echoedBack[i]); 401 } 402 } 403 catch (java.rmi.RemoteException re) 404 { 405 throw new RuntimeException (re.toString()); 406 } 407 } 408 409 public void test_getException() 410 { 411 try 412 { 413 java.lang.Object obj = server.getException(); 415 NegativeArgumentException na = (NegativeArgumentException)obj; 417 assertEquals(-7777, na.getNegativeArgument()); 418 } 419 catch (java.rmi.RemoteException re) 420 { 421 throw new RuntimeException (re.toString()); 422 } 423 } 424 425 public void test_getZooValue() 426 { 427 try 428 { 429 java.lang.Object obj = server.getZooValue(); 431 Assert.assertEquals(new Zoo("outer_zoo!", 433 "returned by getZooValue", 434 new Zoo("inner_zoo!", "inner")), 435 obj); 436 } 437 catch (java.rmi.RemoteException re) 438 { 439 throw new RuntimeException (re.toString()); 440 } 441 } 442 443 public void test_referenceSharingWithinArray() 444 { 445 try 446 { 447 int n = 100; 449 Object [] original = new Object [n]; 450 for (int i = 0; i < n; i++) 451 { 452 original[i] = new Boo("t" + i, "boo array test"); 454 } 455 Object [] echoedBack = 456 server.testReferenceSharingWithinArray(original); 457 assertEquals(2 * n, echoedBack.length); 458 459 for (int i = 0; i < n; i++) 460 { 461 assertEquals(original[i], echoedBack[i]); 462 assertEquals(original[i], echoedBack[i + n]); 463 assertSame(echoedBack[i], echoedBack[i + n]); 464 } 465 } 466 catch (java.rmi.RemoteException re) 467 { 468 throw new RuntimeException (re.toString()); 469 } 470 } 471 472 public void test_referenceSharingWithinCollection() 473 { 474 try 475 { 476 java.util.Collection original = new java.util.ArrayList (); 478 int n = 10; 479 for (int i = 0; i < n; i++) 480 { 481 original.add(new Foo(100 + i, "foo collection test")); 482 } 484 java.util.Collection echoedBack = 485 server.testReferenceSharingWithinCollection(original); 486 assertEquals(2 * n, echoedBack.size()); 487 488 java.util.ArrayList originalList = (java.util.ArrayList )original; 489 java.util.ArrayList echoedList = (java.util.ArrayList )echoedBack; 490 491 492 for (int i = 0; i < n; i++) 493 { 494 assertEquals(originalList.get(i), echoedList.get(i)); 496 assertEquals(originalList.get(i), echoedList.get(i + n)); 497 assertSame(echoedList.get(i), echoedList.get(i + n)); 498 } 499 } 500 catch (java.rmi.RemoteException re) 501 { 502 throw new RuntimeException (re.toString()); 503 } 504 } 505 506 public void test_getVectorWithObjectArrayAsElement() 507 { 508 try 509 { 510 java.util.Vector vector = 512 server.getVectorWithObjectArrayAsElement(); 513 assertTrue(vector.size() == 1); 515 Object [] inner = (Object []) vector.get(0); 516 assertEquals(new Integer (1), inner[0]); 517 assertEquals(new Integer (2), inner[1]); 518 assertEquals("Third Element", inner[2]); 519 } 520 catch (java.rmi.RemoteException re) 521 { 522 throw new RuntimeException (re.toString()); 523 } 524 } 525 526 public void test_getVectorWithVectorAsElement() 527 { 528 try 529 { 530 java.util.Vector vector = 532 server.getVectorWithVectorAsElement(); 533 assertTrue(vector.size() == 1); 535 java.util.Vector inner = (java.util.Vector ) vector.get(0); 536 assertEquals(new Integer (1), inner.get(0)); 537 assertEquals(new Integer (2), inner.get(1)); 538 assertEquals("Third Element", inner.get(2)); 539 } 540 catch (java.rmi.RemoteException re) 541 { 542 throw new RuntimeException (re.toString()); 543 } 544 } 545 546 public void test_getVectorWithHashtableAsElement() 547 { 548 try 549 { 550 java.util.Vector vector = 552 server.getVectorWithHashtableAsElement(); 553 assertTrue(vector.size() == 1); 555 java.util.Hashtable inner = (java.util.Hashtable ) vector.get(0); 556 assertEquals(new Integer (1), inner.get(new Integer (0))); 557 assertEquals(new Integer (2), inner.get(new Integer (1))); 558 assertEquals("Third Element", inner.get(new Integer (2))); 559 } 560 catch (java.rmi.RemoteException re) 561 { 562 throw new RuntimeException (re.toString()); 563 } 564 } 565 566 } 567 | Popular Tags |