001: package org.objectweb.celtix.geronimo.container;
002:
003: import java.util.Collection;
004: import java.util.LinkedList;
005:
006: import javax.xml.namespace.QName;
007:
008: import junit.framework.AssertionFailedError;
009: import junit.framework.TestCase;
010:
011: import org.objectweb.celtix.Bus;
012: import org.objectweb.celtix.geronimo.MockBusFactory;
013: import org.objectweb.celtix.transports.ServerTransport;
014: import org.objectweb.celtix.ws.addressing.AttributedURIType;
015: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
016: import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
017:
018: public class GeronimoTransportFactoryTest extends TestCase {
019:
020: private ThreadAssertionHandler handler = new ThreadAssertionHandler();
021:
022: private CeltixWebServiceContainer container;
023: private GeronimoTransportFactory factory = new GeronimoTransportFactory();
024: private EndpointReferenceType addr;
025:
026: public void setUp() throws Exception {
027: container = new CeltixWebServiceContainer(null);
028: addr = new EndpointReferenceType();
029: AttributedURIType uri = new AttributedURIType();
030: uri.setValue("http://not.there.iona.com/wibbly/wobbly/wonder");
031: addr.setAddress(uri);
032: QName serviceName = new QName("http://www.w3.org/2004/08/wsdl",
033: "testServiceName");
034: EndpointReferenceUtils.setServiceAndPortName(addr, serviceName,
035: "");
036:
037: MockBusFactory busFactory = new MockBusFactory();
038: Bus mockBus = busFactory.createMockBus();
039: busFactory.replay();
040:
041: factory.init(mockBus);
042:
043: }
044:
045: public void testCreateServerTransport() throws Exception {
046:
047: factory.setCurrentContainer(container);
048: ServerTransport st = factory.createServerTransport(addr);
049: assertNotNull("factory must not return null transport", st);
050: assertTrue("factory must return GeronimoServerTransport",
051: st instanceof GeronimoServerTransport);
052: assertSame(
053: "CeltixWebServiceContainer must contain server transport",
054: st, container.getServerTransport());
055: }
056:
057: public void testCurrentContainer() throws Exception {
058:
059: assertSame(null, factory.getCurrentContainer());
060: factory.setCurrentContainer(container);
061: assertSame(container, factory.getCurrentContainer());
062:
063: Thread t = new Thread() {
064: public void run() {
065: CeltixWebServiceContainer cntr1 = new CeltixWebServiceContainer(
066: null);
067: assertSame(null, factory.getCurrentContainer());
068: factory.setCurrentContainer(cntr1);
069: assertSame(cntr1, factory.getCurrentContainer());
070: }
071: };
072:
073: t.start();
074: try {
075: t.join();
076: } catch (InterruptedException e) {
077: fail(e.toString());
078: }
079: handler.checkAssertions();
080: }
081:
082: static class ThreadAssertionHandler implements
083: Thread.UncaughtExceptionHandler {
084: private final Collection<AssertionFailedError> assertions = new LinkedList<AssertionFailedError>();
085:
086: public ThreadAssertionHandler() {
087: Thread.setDefaultUncaughtExceptionHandler(this );
088: }
089:
090: public ThreadAssertionHandler(Thread t) {
091: t.setUncaughtExceptionHandler(this );
092: }
093:
094: public void uncaughtException(Thread thread, Throwable ex) {
095: if (ex instanceof AssertionFailedError) {
096: assertions.add((AssertionFailedError) ex);
097: } else {
098: throw new RuntimeException("unexpected exception", ex);
099: }
100: }
101:
102: public void checkAssertions() {
103: for (AssertionFailedError assertion : assertions) {
104: // just throw the first one we meet
105: throw assertion;
106: }
107: }
108: }
109: }
|