001: package org.objectweb.celtix.bus.handlers;
002:
003: import java.util.List;
004:
005: import javax.xml.namespace.QName;
006: import javax.xml.ws.WebServiceException;
007: import javax.xml.ws.handler.Handler;
008:
009: import junit.framework.TestCase;
010:
011: import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerChainType;
012: import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerType;
013: import org.objectweb.celtix.bus.jaxws.configuration.types.ObjectFactory;
014: import org.objectweb.celtix.configuration.Configuration;
015:
016: import static org.easymock.EasyMock.*;
017:
018: public class HandlerResolverImplTest extends TestCase {
019:
020: private final HandlerResolverImpl resolver = new HandlerResolverImpl();
021: private final PortInfoImpl portInfo = new PortInfoImpl(new QName(
022: "http://objectweb.org/hello_world_soap_http", "Greeter"),
023: new QName("http://objectweb.org/hello_world_soap_http",
024: "SOAP_Service"), "Greeter_SOAPBinding");
025:
026: public void testGetHandlerChain() {
027: List<Handler> handlerChain = resolver.getHandlerChain(portInfo);
028: assertNotNull(handlerChain);
029: assertEquals(0, handlerChain.size());
030:
031: Handler handler = createMock(Handler.class);
032: handlerChain.add(handler);
033:
034: handlerChain = resolver.getHandlerChain(portInfo);
035: assertEquals(1, handlerChain.size());
036: assertSame(handler, handlerChain.get(0));
037: }
038:
039: public void testGetHandlerChainFromConfiguration() {
040: ObjectFactory factory = new ObjectFactory();
041: HandlerType h1 = factory.createHandlerType();
042: h1.setHandlerClass(getClass().getPackage().getName()
043: + ".TestHandler");
044: h1.setHandlerName("first");
045: HandlerType h2 = factory.createHandlerType();
046: h2.setHandlerClass(getClass().getPackage().getName()
047: + ".TestHandler");
048: h2.setHandlerName("second");
049:
050: HandlerChainType chain = factory.createHandlerChainType();
051: List<HandlerType> handlers = chain.getHandler();
052: handlers.add(h1);
053: handlers.add(h2);
054:
055: Configuration busConfiguration = createMock(Configuration.class);
056: QName service = new QName(
057: "http://objectweb.org/hello_world_soap_http",
058: "SOAP_Service");
059: HandlerResolverImpl res = new HandlerResolverImpl(
060: busConfiguration, service);
061: Configuration portConf = createMock(Configuration.class);
062: String id = service.toString() + "/"
063: + portInfo.getPortName().getLocalPart();
064: busConfiguration.getChild(
065: HandlerResolverImpl.PORT_CONFIGURATION_URI, id);
066: expectLastCall().andReturn(portConf);
067: portConf.getObject("handlerChain");
068: expectLastCall().andReturn(chain);
069: replay(busConfiguration);
070: replay(portConf);
071:
072: List<Handler> handlerChain = res.getHandlerChain(portInfo);
073: assertNotNull(handlerChain);
074: assertEquals(2, handlerChain.size());
075: verify(busConfiguration);
076: verify(portConf);
077: }
078:
079: public void testHandlerClassNotFound() {
080: ObjectFactory factory = new ObjectFactory();
081: HandlerType h3 = factory.createHandlerType();
082: h3.setHandlerClass("a.b.c.TestHandler");
083: h3.setHandlerName("nonExistingClassHandler");
084:
085: HandlerChainType chain = factory.createHandlerChainType();
086: List<HandlerType> handlers = chain.getHandler();
087: handlers.add(h3);
088:
089: Configuration busConfiguration = createMock(Configuration.class);
090: QName service = new QName(
091: "http://objectweb.org/hello_world_soap_http",
092: "SOAP_Service");
093: HandlerResolverImpl res = new HandlerResolverImpl(
094: busConfiguration, service);
095: Configuration portConf = createMock(Configuration.class);
096: String id = service.toString() + "/"
097: + portInfo.getPortName().getLocalPart();
098: busConfiguration.getChild(
099: HandlerResolverImpl.PORT_CONFIGURATION_URI, id);
100: expectLastCall().andReturn(portConf);
101: portConf.getObject("handlerChain");
102: expectLastCall().andReturn(chain);
103: replay(busConfiguration);
104: replay(portConf);
105:
106: try {
107: res.getHandlerChain(portInfo);
108: } catch (WebServiceException ex) {
109: assertTrue(ex.getCause() instanceof ClassNotFoundException);
110: }
111: verify(busConfiguration);
112: verify(portConf);
113: }
114:
115: /*
116: public void testHandlerIllegalAccess() {
117: ObjectFactory factory = new ObjectFactory();
118: HandlerType h4 = factory.createHandlerType();
119: h4.setClassName("org.objectweb.celtix.bus.jaxb.JAXBUtils");
120: h4.setName("privateConstructor");
121:
122: HandlerChainType chain = factory.createHandlerChainType();
123: List<HandlerType> handlers = chain.getHandler();
124: handlers.add(h4);
125:
126: Configuration conf = createMock(Configuration.class);
127: HandlerResolverImpl res = new HandlerResolverImpl(conf);
128: conf.getObject("handlerChain");
129: expectLastCall().andReturn(chain);
130: replay(conf);
131:
132: try {
133: res.getHandlerChain(portInfo);
134: } catch (WebServiceException ex) {
135: assertTrue(ex.getCause() instanceof IllegalAccessException);
136: }
137: verify(conf);
138: }
139: */
140:
141: public void testHandlerInstantiation() {
142: ObjectFactory factory = new ObjectFactory();
143: HandlerType h5 = factory.createHandlerType();
144: h5.setHandlerClass("javax.xml.ws.handler.Handler");
145: h5.setHandlerName("interfaceHandler");
146:
147: HandlerChainType chain = factory.createHandlerChainType();
148: List<HandlerType> handlers = chain.getHandler();
149: handlers.add(h5);
150:
151: Configuration busConfiguration = createMock(Configuration.class);
152: QName service = new QName(
153: "http://objectweb.org/hello_world_soap_http",
154: "SOAP_Service");
155: HandlerResolverImpl res = new HandlerResolverImpl(
156: busConfiguration, service);
157: Configuration portConf = createMock(Configuration.class);
158: String id = service.toString() + "/"
159: + portInfo.getPortName().getLocalPart();
160: busConfiguration.getChild(
161: HandlerResolverImpl.PORT_CONFIGURATION_URI, id);
162: expectLastCall().andReturn(portConf);
163: portConf.getObject("handlerChain");
164: expectLastCall().andReturn(chain);
165: replay(busConfiguration);
166: replay(portConf);
167:
168: try {
169: res.getHandlerChain(portInfo);
170: } catch (WebServiceException ex) {
171: assertTrue(ex.getCause() instanceof InstantiationException);
172: }
173: verify(busConfiguration);
174: verify(portConf);
175: }
176: }
|