1 package org.objectweb.celtix.geronimo.container; 2 3 import java.util.Collection ; 4 import java.util.LinkedList ; 5 6 import javax.xml.namespace.QName ; 7 8 import junit.framework.AssertionFailedError; 9 import junit.framework.TestCase; 10 11 import org.objectweb.celtix.Bus; 12 import org.objectweb.celtix.geronimo.MockBusFactory; 13 import org.objectweb.celtix.transports.ServerTransport; 14 import org.objectweb.celtix.ws.addressing.AttributedURIType; 15 import org.objectweb.celtix.ws.addressing.EndpointReferenceType; 16 import org.objectweb.celtix.wsdl.EndpointReferenceUtils; 17 18 public class GeronimoTransportFactoryTest extends TestCase { 19 20 private ThreadAssertionHandler handler = new ThreadAssertionHandler(); 21 22 private CeltixWebServiceContainer container; 23 private GeronimoTransportFactory factory = new GeronimoTransportFactory(); 24 private EndpointReferenceType addr; 25 26 public void setUp() throws Exception { 27 container = new CeltixWebServiceContainer(null); 28 addr = new EndpointReferenceType(); 29 AttributedURIType uri = new AttributedURIType(); 30 uri.setValue("http://not.there.iona.com/wibbly/wobbly/wonder"); 31 addr.setAddress(uri); 32 QName serviceName = new QName ("http://www.w3.org/2004/08/wsdl", "testServiceName"); 33 EndpointReferenceUtils.setServiceAndPortName(addr, serviceName, ""); 34 35 MockBusFactory busFactory = new MockBusFactory(); 36 Bus mockBus = busFactory.createMockBus(); 37 busFactory.replay(); 38 39 factory.init(mockBus); 40 41 } 42 43 44 public void testCreateServerTransport() throws Exception { 45 46 factory.setCurrentContainer(container); 47 ServerTransport st = factory.createServerTransport(addr); 48 assertNotNull("factory must not return null transport", st); 49 assertTrue("factory must return GeronimoServerTransport", st instanceof GeronimoServerTransport); 50 assertSame("CeltixWebServiceContainer must contain server transport", st, 51 container.getServerTransport()); 52 } 53 54 55 public void testCurrentContainer() throws Exception { 56 57 assertSame(null, factory.getCurrentContainer()); 58 factory.setCurrentContainer(container); 59 assertSame(container, factory.getCurrentContainer()); 60 61 Thread t = new Thread () { 62 public void run() { 63 CeltixWebServiceContainer cntr1 = new CeltixWebServiceContainer(null); 64 assertSame(null, factory.getCurrentContainer()); 65 factory.setCurrentContainer(cntr1); 66 assertSame(cntr1, factory.getCurrentContainer()); 67 } 68 }; 69 70 71 t.start(); 72 try { 73 t.join(); 74 } catch (InterruptedException e) { 75 fail(e.toString()); 76 } 77 handler.checkAssertions(); 78 } 79 80 static class ThreadAssertionHandler implements Thread.UncaughtExceptionHandler { 81 private final Collection <AssertionFailedError> assertions = new LinkedList <AssertionFailedError>(); 82 83 public ThreadAssertionHandler() { 84 Thread.setDefaultUncaughtExceptionHandler(this); 85 } 86 87 public ThreadAssertionHandler(Thread t) { 88 t.setUncaughtExceptionHandler(this); 89 } 90 91 public void uncaughtException(Thread thread, Throwable ex) { 92 if (ex instanceof AssertionFailedError) { 93 assertions.add((AssertionFailedError)ex); 94 } else { 95 throw new RuntimeException ("unexpected exception", ex); 96 } 97 } 98 99 public void checkAssertions() { 100 for (AssertionFailedError assertion : assertions) { 101 throw assertion; 103 } 104 } 105 } 106 } 107 | Popular Tags |