1 package org.jacorb.test.orb; 2 3 23 24 import java.util.Properties ; 25 26 import junit.framework.*; 27 28 import org.jacorb.test.*; 29 import org.jacorb.test.common.*; 30 31 38 public class AlternateIIOPAddressTest extends ClientServerTestCase 39 { 40 protected IIOPAddressServer server = null; 41 42 private static final String CORRECT_HOST = "127.0.0.1"; 43 private static final String WRONG_HOST = "10.0.1.222"; 44 private static final String WRONG_HOST_2 = "10.0.1.223"; 45 46 private static final int CORRECT_PORT = 45000; 47 private static final int WRONG_PORT = 45001; 48 49 public AlternateIIOPAddressTest(String name, ClientServerSetup setup) 50 { 51 super(name, setup); 52 } 53 54 protected void setUp() throws Exception 55 { 56 server = IIOPAddressServerHelper.narrow(setup.getServerObject()); 57 } 58 59 protected void tearDown() throws Exception 60 { 61 server.setIORAddress (CORRECT_HOST, CORRECT_PORT); 63 server.clearAlternateAddresses(); 64 } 65 66 public static Test suite() 67 { 68 TestSuite suite = new JacORBTestSuite("Test TAG_ALTERNATE_IIOP_ADDRESS", 69 AlternateIIOPAddressTest.class); 70 71 Properties client_props = new Properties (); 72 client_props.setProperty ("jacorb.retries", "0"); 73 client_props.setProperty ("jacorb.retry_interval", "50"); 74 75 Properties server_props = new Properties (); 76 server_props.setProperty 77 ("org.omg.PortableInterceptor.ORBInitializerClass." 78 + "org.jacorb.test.orb.IIOPAddressORBInitializer", ""); 79 server_props.setProperty ("OAPort", Integer.toString(CORRECT_PORT)); 80 81 ClientServerSetup setup = 82 new ClientServerSetup (suite, 83 "org.jacorb.test.orb.IIOPAddressServerImpl", 84 client_props, 85 server_props); 86 87 suite.addTest (new AlternateIIOPAddressTest("test_ping", setup)); 88 suite.addTest (new AlternateIIOPAddressTest("test_primary_ok", setup)); 89 suite.addTest (new AlternateIIOPAddressTest("test_primary_wrong_host", setup)); 90 suite.addTest (new AlternateIIOPAddressTest("test_primary_wrong_port", setup)); 91 suite.addTest (new AlternateIIOPAddressTest("test_alternate_ok", setup)); 92 suite.addTest (new AlternateIIOPAddressTest("test_alternate_ok_2", setup)); 93 suite.addTest (new AlternateIIOPAddressTest("test_alternate_wrong", setup)); 94 95 return setup; 96 } 97 98 public void test_ping() 99 { 100 Sample s = server.getObject(); 101 int result = s.ping (17); 102 assertEquals (18, result); 103 } 104 105 public void test_primary_ok() 106 { 107 server.setIORAddress( CORRECT_HOST, CORRECT_PORT ); 108 Sample s = server.getObject(); 109 int result = s.ping (77); 110 assertEquals (78, result); 111 } 112 113 public void test_primary_wrong_host() 114 { 115 server.setIORAddress( WRONG_HOST, CORRECT_PORT ); 116 Sample s = server.getObject(); 117 try 118 { 119 int result = s.ping (123); 120 fail ("TRANSIENT exception expected"); 121 } 122 catch (org.omg.CORBA.TRANSIENT ex) 123 { 124 } 126 } 127 128 public void test_primary_wrong_port() 129 { 130 server.setIORAddress( CORRECT_HOST, WRONG_PORT ); 131 Sample s = server.getObject(); 132 try 133 { 134 int result = s.ping (4); 135 fail ("TRANSIENT exception expected"); 136 } 137 catch (org.omg.CORBA.TRANSIENT ex) 138 { 139 } 141 } 142 143 public void test_alternate_ok() 144 { 145 server.setIORAddress( WRONG_HOST, CORRECT_PORT ); 146 server.addAlternateAddress( CORRECT_HOST, CORRECT_PORT ); 147 Sample s = server.getObject(); 148 int result = s.ping (99); 149 assertEquals (100, result); 150 } 151 152 public void test_alternate_ok_2() 153 { 154 server.setIORAddress( WRONG_HOST, CORRECT_PORT ); 155 server.addAlternateAddress( WRONG_HOST_2, CORRECT_PORT ); 156 server.addAlternateAddress( CORRECT_HOST, CORRECT_PORT ); 157 Sample s = server.getObject(); 158 int result = s.ping (187); 159 assertEquals (188, result); 160 } 161 162 public void test_alternate_wrong() 163 { 164 server.setIORAddress( CORRECT_HOST, WRONG_PORT ); 165 server.addAlternateAddress( WRONG_HOST, CORRECT_PORT ); 166 server.addAlternateAddress( WRONG_HOST_2, WRONG_PORT ); 167 server.addAlternateAddress( WRONG_HOST_2, WRONG_PORT ); 168 Sample s = server.getObject(); 169 try 170 { 171 int result = s.ping (33); 172 fail ("TRANSIENT exception expected"); 173 } 174 catch (org.omg.CORBA.TRANSIENT ex) 175 { 176 } 178 179 } 180 181 } 182 | Popular Tags |