1 package org.objectweb.celtix.bus.handlers; 2 3 import java.util.List ; 4 5 import javax.xml.namespace.QName ; 6 import javax.xml.ws.WebServiceException; 7 import javax.xml.ws.handler.Handler; 8 9 import junit.framework.TestCase; 10 11 import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerChainType; 12 import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerType; 13 import org.objectweb.celtix.bus.jaxws.configuration.types.ObjectFactory; 14 import org.objectweb.celtix.configuration.Configuration; 15 16 import static org.easymock.EasyMock.*; 17 18 19 public class HandlerResolverImplTest extends TestCase { 20 21 private final HandlerResolverImpl resolver = new HandlerResolverImpl(); 22 private final PortInfoImpl portInfo = new PortInfoImpl( 23 new QName ("http://objectweb.org/hello_world_soap_http", "Greeter"), 24 new QName ("http://objectweb.org/hello_world_soap_http", "SOAP_Service"), 25 "Greeter_SOAPBinding"); 26 27 public void testGetHandlerChain() { 28 List <Handler> handlerChain = resolver.getHandlerChain(portInfo); 29 assertNotNull(handlerChain); 30 assertEquals(0, handlerChain.size()); 31 32 Handler handler = createMock(Handler.class); 33 handlerChain.add(handler); 34 35 handlerChain = resolver.getHandlerChain(portInfo); 36 assertEquals(1, handlerChain.size()); 37 assertSame(handler, handlerChain.get(0)); 38 } 39 40 public void testGetHandlerChainFromConfiguration() { 41 ObjectFactory factory = new ObjectFactory(); 42 HandlerType h1 = factory.createHandlerType(); 43 h1.setHandlerClass(getClass().getPackage().getName() + ".TestHandler"); 44 h1.setHandlerName("first"); 45 HandlerType h2 = factory.createHandlerType(); 46 h2.setHandlerClass(getClass().getPackage().getName() + ".TestHandler"); 47 h2.setHandlerName("second"); 48 49 HandlerChainType chain = factory.createHandlerChainType(); 50 List <HandlerType> handlers = chain.getHandler(); 51 handlers.add(h1); 52 handlers.add(h2); 53 54 Configuration busConfiguration = createMock(Configuration.class); 55 QName service = new QName ("http://objectweb.org/hello_world_soap_http", "SOAP_Service"); 56 HandlerResolverImpl res = new HandlerResolverImpl(busConfiguration, service); 57 Configuration portConf = createMock(Configuration.class); 58 String id = service.toString() + "/" + portInfo.getPortName().getLocalPart(); 59 busConfiguration.getChild(HandlerResolverImpl.PORT_CONFIGURATION_URI, id); 60 expectLastCall().andReturn(portConf); 61 portConf.getObject("handlerChain"); 62 expectLastCall().andReturn(chain); 63 replay(busConfiguration); 64 replay(portConf); 65 66 List <Handler> handlerChain = res.getHandlerChain(portInfo); 67 assertNotNull(handlerChain); 68 assertEquals(2, handlerChain.size()); 69 verify(busConfiguration); 70 verify(portConf); 71 } 72 73 public void testHandlerClassNotFound() { 74 ObjectFactory factory = new ObjectFactory(); 75 HandlerType h3 = factory.createHandlerType(); 76 h3.setHandlerClass("a.b.c.TestHandler"); 77 h3.setHandlerName("nonExistingClassHandler"); 78 79 HandlerChainType chain = factory.createHandlerChainType(); 80 List <HandlerType> handlers = chain.getHandler(); 81 handlers.add(h3); 82 83 Configuration busConfiguration = createMock(Configuration.class); 84 QName service = new QName ("http://objectweb.org/hello_world_soap_http", "SOAP_Service"); 85 HandlerResolverImpl res = new HandlerResolverImpl(busConfiguration, service); 86 Configuration portConf = createMock(Configuration.class); 87 String id = service.toString() + "/" + portInfo.getPortName().getLocalPart(); 88 busConfiguration.getChild(HandlerResolverImpl.PORT_CONFIGURATION_URI, id); 89 expectLastCall().andReturn(portConf); 90 portConf.getObject("handlerChain"); 91 expectLastCall().andReturn(chain); 92 replay(busConfiguration); 93 replay(portConf); 94 95 try { 96 res.getHandlerChain(portInfo); 97 } catch (WebServiceException ex) { 98 assertTrue(ex.getCause() instanceof ClassNotFoundException ); 99 } 100 verify(busConfiguration); 101 verify(portConf); 102 } 103 104 129 130 public void testHandlerInstantiation() { 131 ObjectFactory factory = new ObjectFactory(); 132 HandlerType h5 = factory.createHandlerType(); 133 h5.setHandlerClass("javax.xml.ws.handler.Handler"); 134 h5.setHandlerName("interfaceHandler"); 135 136 HandlerChainType chain = factory.createHandlerChainType(); 137 List <HandlerType> handlers = chain.getHandler(); 138 handlers.add(h5); 139 140 Configuration busConfiguration = createMock(Configuration.class); 141 QName service = new QName ("http://objectweb.org/hello_world_soap_http", "SOAP_Service"); 142 HandlerResolverImpl res = new HandlerResolverImpl(busConfiguration, service); 143 Configuration portConf = createMock(Configuration.class); 144 String id = service.toString() + "/" + portInfo.getPortName().getLocalPart(); 145 busConfiguration.getChild(HandlerResolverImpl.PORT_CONFIGURATION_URI, id); 146 expectLastCall().andReturn(portConf); 147 portConf.getObject("handlerChain"); 148 expectLastCall().andReturn(chain); 149 replay(busConfiguration); 150 replay(portConf); 151 152 try { 153 res.getHandlerChain(portInfo); 154 } catch (WebServiceException ex) { 155 assertTrue(ex.getCause() instanceof InstantiationException ); 156 } 157 verify(busConfiguration); 158 verify(portConf); 159 } 160 } 161 | Popular Tags |