1 package org.jacorb.test.common; 2 3 23 24 import java.util.*; 25 26 import org.omg.CORBA.*; 27 import org.omg.PortableServer.*; 28 29 import junit.framework.*; 30 import junit.extensions.*; 31 32 import org.jacorb.test.common.launch.*; 33 34 80 public class ClientServerSetup extends TestSetup { 81 82 protected String servantName; 83 protected Process serverProcess; 84 protected StreamListener outListener, errListener; 85 protected org.omg.CORBA.Object serverObject; 86 protected org.omg.CORBA.ORB clientOrb; 87 protected org.omg.PortableServer.POA clientRootPOA; 88 89 private Properties clientOrbProperties = null; 90 private Properties serverOrbProperties = null; 91 92 private static Comparator comparator = new JacORBVersionComparator(); 93 94 106 public ClientServerSetup ( Test test, String servantName ) 107 { 108 super ( test ); 109 this.servantName = servantName; 110 clientOrbProperties = new Properties(); 111 clientOrbProperties.put ("org.omg.CORBA.ORBClass", 112 "org.jacorb.orb.ORB"); 113 clientOrbProperties.put ("org.omg.CORBA.ORBSingletonClass", 114 "org.jacorb.orb.ORBSingleton"); 115 } 116 117 public ClientServerSetup( Test test, 118 String servantName, 119 Properties clientOrbProperties, 120 Properties serverOrbProperties ) 121 { 122 this( test, servantName ); 123 if (clientOrbProperties != null) 124 this.clientOrbProperties.putAll (clientOrbProperties); 125 this.serverOrbProperties = serverOrbProperties; 126 } 127 128 public void setUp() throws Exception 129 { 130 clientOrb = ORB.init (new String [0], clientOrbProperties ); 131 clientRootPOA = POAHelper.narrow 132 ( clientOrb.resolve_initial_references( "RootPOA" ) ); 133 clientRootPOA.the_POAManager().activate(); 134 135 String serverVersion = System.getProperty ("jacorb.test.server.version", 136 "cvs"); 137 String testID = System.getProperty("jacorb.test.id", ""); 138 String cs = System.getProperty ("jacorb.test.coverage", "false"); 139 boolean coverage = cs.equals("true") || cs.equals("on"); 140 141 Properties serverProperties = new Properties(); 142 if (serverOrbProperties != null) 143 serverProperties.putAll (serverOrbProperties); 144 serverProperties.put ("jacorb.implname", servantName); 145 146 JacORBLauncher launcher = JacORBLauncher.getLauncher (serverVersion, 147 coverage); 148 149 if (coverage) 150 serverProperties.put ("emma.coverage.out.file", 151 launcher.getJacorbHome() 152 + "/test/regression/output/" 153 + testID + "/coverage-server.ec"); 154 155 serverProcess = launcher.launch 156 ( 157 TestUtils.testHome() + "/classes", 158 serverProperties, 159 getTestServerMain(), 160 new String [] { servantName } 161 ); 162 163 outListener = new StreamListener (serverProcess.getInputStream(), 164 "OUT"); 165 errListener = new StreamListener (serverProcess.getErrorStream(), 166 "ERR"); 167 outListener.start(); 168 errListener.start(); 169 String ior = outListener.getIOR(); 170 serverObject = clientOrb.string_to_object(ior); 171 } 172 173 public void tearDown() throws Exception 174 { 175 serverProcess.destroy(); 176 } 177 178 public String getTestServerMain() 179 { 180 String serverVersion = System.getProperty ("jacorb.test.server.version", 181 "cvs"); 182 if (comparator.compare (serverVersion, "2.2") >= 0) 183 return "org.jacorb.test.common.TestServer"; 184 else 185 return "org.jacorb.test.common.TestServer_before_2_2"; 186 } 187 188 192 public org.omg.CORBA.Object getServerObject() 193 { 194 return serverObject; 195 } 196 197 200 public org.omg.CORBA.ORB getClientOrb() 201 { 202 return clientOrb; 203 } 204 205 209 public String getServantName() 210 { 211 return servantName; 212 } 213 214 217 public Process getServerProcess() 218 { 219 return serverProcess; 220 } 221 222 public POA getClientRootPOA() 223 { 224 return clientRootPOA; 225 } 226 227 } 228 | Popular Tags |