1 package org.jacorb.test.notification; 2 3 23 24 import java.util.Properties ; 25 26 import junit.extensions.TestSetup; 27 import junit.framework.Test; 28 29 import org.apache.avalon.framework.configuration.Configuration; 30 import org.jacorb.notification.AbstractChannelFactory; 31 import org.jacorb.notification.container.PicoContainerFactory; 32 import org.omg.CORBA.ORB ; 33 import org.omg.PortableServer.POA ; 34 import org.omg.PortableServer.POAHelper ; 35 import org.picocontainer.MutablePicoContainer; 36 37 40 41 public class NotificationTestCaseSetup extends TestSetup 42 { 43 private MutablePicoContainer container_; 44 45 private Thread orbThread_; 46 47 private NotificationTestUtils testUtils_; 48 49 private AbstractChannelFactory eventChannelFactory_; 50 51 private ORB clientORB_; 52 53 private ORB orb_; 54 55 57 public NotificationTestCaseSetup(Test suite) throws Exception 58 { 59 super(suite); 60 } 61 62 64 public NotificationTestUtils getTestUtils() 65 { 66 return testUtils_; 67 } 68 69 public void setUp() throws Exception 70 { 71 super.setUp(); 72 73 orb_ = ORB.init(new String [0], null); 74 POAHelper.narrow(orb_.resolve_initial_references("RootPOA")).the_POAManager().activate(); 75 76 container_ = PicoContainerFactory.createRootContainer((org.jacorb.orb.ORB) orb_); 77 78 testUtils_ = new NotificationTestUtils(getORB()); 79 80 orbThread_ = new Thread (new Runnable () 81 { 82 public void run() 83 { 84 getORB().run(); 85 } 86 }); 87 88 orbThread_.setDaemon(true); 89 90 orbThread_.start(); 91 92 clientORB_ = ORB.init(new String [] {}, null); 93 POAHelper.narrow(clientORB_.resolve_initial_references("RootPOA")).the_POAManager() 94 .activate(); 95 96 Thread clientOrbThread = new Thread (new Runnable () 97 { 98 public void run() 99 { 100 getClientORB().run(); 101 } 102 }, "JUnit-Client-ORB-Runner"); 103 104 clientOrbThread.setDaemon(true); 105 106 clientOrbThread.start(); 107 } 108 109 public void tearDown() throws Exception 110 { 111 if (eventChannelFactory_ != null) 112 { 113 eventChannelFactory_.dispose(); 114 } 115 116 container_.dispose(); 117 118 orb_.shutdown(true); 119 120 clientORB_.shutdown(true); 121 122 super.tearDown(); 123 } 124 125 public ORB getClientORB() 126 { 127 return clientORB_; 128 } 129 130 public AbstractChannelFactory getFactoryServant() throws Exception 131 { 132 if (eventChannelFactory_ == null) 133 { 134 eventChannelFactory_ = AbstractChannelFactory.newFactory(new Properties ()); 135 } 136 137 return eventChannelFactory_; 138 } 139 140 public ORB getORB() 141 { 142 return (ORB ) container_.getComponentInstanceOfType(ORB .class); 143 } 144 145 public POA getPOA() 146 { 147 return (POA ) container_.getComponentInstanceOfType(POA .class); 148 } 149 150 public MutablePicoContainer getPicoContainer() 151 { 152 return container_; 153 } 154 155 public Configuration getConfiguration() 156 { 157 return (Configuration) container_.getComponentInstanceOfType(Configuration.class); 158 } 159 } | Popular Tags |