1 package org.objectweb.celtix; 2 3 4 5 import java.util.HashMap ; 6 import java.util.Map ; 7 import javax.xml.ws.Holder; 8 import junit.framework.*; 9 import org.objectweb.celtix.bindings.BindingFactory; 10 import org.objectweb.celtix.bindings.BindingManager; 11 import org.objectweb.celtix.bus.busimpl.CeltixBus; 12 13 public class BusTest extends TestCase { 14 15 public void tearDown() { 16 Bus.clearCurrent(); 17 Bus.clearDefault(); 18 } 19 20 public void testBusInit() throws Exception { 21 22 Bus bus = Bus.init(null, new HashMap <String , Object >()); 23 assertNotNull(bus); 24 assertTrue("Bus not a Celtix bus", bus instanceof CeltixBus); 25 26 Map <String , Object > map = new HashMap <String , Object >(); 27 map.put(Bus.BUS_CLASS_PROPERTY, "com.foo.bar.Bus"); 28 try { 29 bus = Bus.init(null, map); 30 fail("Should have thrown an exception"); 31 } catch (BusException ex) { 32 } finally { 34 Thread.sleep(100); 35 bus.shutdown(true); 36 } 37 } 38 39 42 public void testBusGetCurrent() throws Exception { 43 44 Bus bus1 = Bus.init(null, new HashMap <String , Object >()); 45 assertNotNull(bus1); 46 47 assertSame("getCurrent should have returned the same bus handle.", bus1, Bus.getCurrent()); 48 49 Bus bus2 = Bus.init(null, new HashMap <String , Object >()); 51 assertNotSame("getCurrent should have returned a different bus handle.", bus1, Bus.getCurrent()); 52 assertSame("last bus initilialised should be the current bus ", bus2, Bus.getCurrent()); 53 54 bus1.shutdown(true); 55 bus2.shutdown(true); 56 } 57 58 public void testBusGetCurrentDefaultMulitpleThreads() throws Exception { 59 60 final Bus bus1 = Bus.getCurrent(); 61 62 Thread t = new Thread () { 63 public void run() { 64 Bus bus2 = Bus.getCurrent(); 65 assertSame("default bus not visible on all threads", bus1, bus2); 66 try { 67 try { 68 Thread.sleep(100); 69 } catch (InterruptedException e) { 70 } 72 bus2.shutdown(true); 73 } catch (BusException e) { 74 e.printStackTrace(); 76 } 77 } 78 }; 79 80 t.start(); 81 t.join(); 82 } 84 85 public void testBusGetCurrentPreInitMulitpleThreads() throws Exception { 86 87 final Bus bus1 = Bus.init(null, new HashMap <String , Object >()); 88 assertNotNull(bus1); 89 assertTrue("Bus not a Celtix bus", bus1 instanceof CeltixBus); 90 91 assertSame("getCurrent should have returned the same bus handle.", bus1, Bus.getCurrent()); 93 94 final Holder<Bus> busHolder = new Holder<Bus>(); 95 Thread t = new Thread () { 96 public void run() { 97 busHolder.value = Bus.getCurrent(); 98 } 99 }; 100 101 t.start(); 102 t.join(); 103 104 assertSame("initialised bus not visible on all threads", bus1, busHolder.value); 105 Thread.sleep(100); 106 bus1.shutdown(true); 107 } 108 109 110 public void testBusGetCurrentDefault() throws Exception { 111 112 Bus bus1 = Bus.getCurrent(); 113 assertNotNull("getCurrent did not return default bus", bus1); 114 Bus bus2 = Bus.getCurrent(); 115 assertNotNull("getCurrent did not return default bus", bus2); 116 assertSame("calls to get default bus returned different buses", bus1, bus2); 117 118 Thread.sleep(100); 119 bus1.shutdown(true); 120 121 } 122 123 126 public void testBusGetBindingManager() throws Exception { 127 128 Bus bus = Bus.init(null, new HashMap <String , Object >()); 129 assertNotNull(bus); 130 131 BindingManager bindingManager = bus.getBindingManager(); 132 assertNotNull(bindingManager); 133 134 BindingFactory factory = bindingManager.getBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/"); 135 assertNotNull(factory); 136 Thread.sleep(100); 138 bus.shutdown(true); 139 } 140 141 142 143 public void testBusRun() throws Exception { 144 145 final Bus bus = Bus.init(); 146 Thread th = new Thread () { 147 public void run() { 148 try { 149 Thread.sleep(100); 150 bus.shutdown(true); 151 } catch (InterruptedException e) { 152 e.printStackTrace(); 154 } catch (BusException e) { 155 e.printStackTrace(); 157 } 158 } 159 }; 160 th.start(); 161 bus.run(); 162 } 163 164 public void testBusInitCommand() throws Exception { 165 String [] args = {"Bus" , "test"}; 167 final Bus bus = Bus.init(args); 168 assertNotNull(bus); 169 assertTrue("Bus not a Celtix bus", bus instanceof CeltixBus); 170 Thread.sleep(1000); 171 bus.shutdown(true); 172 } 173 } 174 175 176 | Popular Tags |