001: package org.objectweb.celtix.bus.handlers;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005: import java.util.concurrent.Future;
006:
007: import javax.jws.HandlerChain;
008: import javax.jws.WebService;
009: import javax.xml.ws.AsyncHandler;
010: import javax.xml.ws.Response;
011: import javax.xml.ws.WebServiceException;
012: import javax.xml.ws.handler.Handler;
013: import javax.xml.ws.handler.LogicalHandler;
014:
015: import junit.framework.TestCase;
016:
017: import org.easymock.EasyMock;
018: import org.objectweb.hello_world_soap_http.AnnotatedGreeterImpl;
019: import org.objectweb.hello_world_soap_http.BadRecordLitFault;
020: import org.objectweb.hello_world_soap_http.Greeter;
021: import org.objectweb.hello_world_soap_http.NoSuchCodeLitFault;
022: import org.objectweb.hello_world_soap_http.types.BareDocumentResponse;
023: import org.objectweb.hello_world_soap_http.types.GreetMeResponse;
024: import org.objectweb.hello_world_soap_http.types.GreetMeSometimeResponse;
025: import org.objectweb.hello_world_soap_http.types.SayHiResponse;
026: import org.objectweb.hello_world_soap_http.types.TestDocLitFaultResponse;
027:
028: public class AnnotationHandlerChainBuilderTest extends TestCase {
029:
030: Handler[] allHandlers = {
031: EasyMock.createMock(LogicalHandler.class),
032: EasyMock.createMock(Handler.class),
033: EasyMock.createMock(Handler.class),
034: EasyMock.createMock(LogicalHandler.class) };
035: Handler[] logicalHandlers = { allHandlers[0], allHandlers[3] };
036: Handler[] protocolHandlers = { allHandlers[1], allHandlers[2] };
037: AnnotatedGreeterImpl greeterImpl = new AnnotatedGreeterImpl();
038:
039: AnnotationHandlerChainBuilder builder = new AnnotationHandlerChainBuilder();
040:
041: public void testBuildHandlerChainWithExistingHandlers() {
042:
043: List<Handler> existingChain = new ArrayList<Handler>();
044: existingChain.add(EasyMock.createMock(LogicalHandler.class));
045: existingChain.add(EasyMock.createMock(Handler.class));
046:
047: List<Handler> chain = builder.buildHandlerChainFor(
048: AnnotatedGreeterImpl.class, existingChain);
049:
050: assertNotNull(chain);
051: assertEquals(3, chain.size());
052: assertTrue(chain.get(0) instanceof LogicalHandler);
053: assertFalse(chain.get(1) instanceof LogicalHandler);
054: assertFalse(chain.get(2) instanceof LogicalHandler);
055: }
056:
057: public void testBuildHandlerChainWithExistingHandlersNoAnnotation() {
058:
059: List<Handler> existingChain = new ArrayList<Handler>();
060: existingChain.add(EasyMock.createMock(LogicalHandler.class));
061: existingChain.add(EasyMock.createMock(Handler.class));
062:
063: List<Handler> chain = builder.buildHandlerChainFor(
064: Greeter.class, existingChain);
065:
066: assertNotNull(chain);
067: assertEquals(existingChain.size(), chain.size());
068: assertSame(existingChain.get(0), chain.get(0));
069: assertSame(existingChain.get(1), chain.get(1));
070:
071: }
072:
073: public void testBuildHandlerChain() {
074:
075: List<Handler> chain = builder
076: .buildHandlerChainFor(AnnotatedGreeterImpl.class);
077:
078: assertNotNull(chain);
079: assertEquals(1, chain.size());
080: }
081:
082: public void testBuildHandlerForServiceEndpointInterface() {
083:
084: List<Handler> chain = builder
085: .buildHandlerChainFor(GreeterWithHandlerChainOnInterfaceImpl.class);
086:
087: assertNotNull(chain);
088: assertEquals(1, chain.size());
089: }
090:
091: public void testBuildHandlerChainNoHanlders() {
092: List<Handler> chain = builder
093: .buildHandlerChainFor(String.class);
094: assertNotNull(chain);
095: assertEquals(0, chain.size());
096: }
097:
098: public void testBuildHandlerChainInvalidFile() {
099:
100: try {
101: builder.buildHandlerChainFor(InvalidAnnotation.class);
102: fail("did not get expected exception");
103: } catch (WebServiceException ex) {
104: // happy
105: }
106: }
107:
108: public void testBuildHandlerChainInvalidHandlerList() {
109:
110: try {
111: builder.buildHandlerChainFor(InvalidName.class);
112: fail("did not get expected exception");
113: } catch (WebServiceException ex) {
114: // happy
115: }
116: }
117:
118: }
119:
120: @HandlerChain(file="invalid_annotation.xml",name="yoohoo")
121: class InvalidAnnotation extends AnnotatedGreeterImpl {
122: }
123:
124: @HandlerChain(file="handlers.xml",name="yoohoo")
125: class InvalidName extends AnnotatedGreeterImpl {
126: }
127:
128: @HandlerChain(file="./broken_handlers.xml",name="BrokenHandlerChain")
129: class NoSuchClassName extends AnnotatedGreeterImpl {
130: }
131:
132: @HandlerChain(file="../../../hello_world_soap_http/handlers.xml",name="HandlerChainNoInitParam")
133: class HandlerChainNoInit extends AnnotatedGreeterImpl {
134: }
135:
136: @WebService(name="Greeter")
137: @HandlerChain(file="../../../hello_world_soap_http/handlers.xml",name="TestHandlerChain")
138: interface GreeterWithHandlerChain extends Greeter {
139:
140: }
141:
142: class GreeterWithHandlerChainOnInterfaceImpl implements
143: GreeterWithHandlerChain {
144:
145: public String sayHi() {
146: return "";
147: }
148:
149: public String greetMe(String requestType) {
150: return requestType;
151: }
152:
153: public String greetMeSometime(String requestType) {
154: return requestType;
155: }
156:
157: public Future<?> greetMeSometimeAsync(String requestType,
158: AsyncHandler ah) {
159: return null;
160: /*not called */
161: }
162:
163: public Response<GreetMeSometimeResponse> greetMeSometimeAsync(
164: String requestType) {
165: return null;
166: /*not called */
167: }
168:
169: public Future<?> greetMeAsync(String requestType,
170: AsyncHandler<GreetMeResponse> asyncHandler) {
171: return null;
172: /*not called */
173: }
174:
175: public Response<GreetMeResponse> greetMeAsync(String requestType) {
176: return null;
177: /*not called */
178: }
179:
180: public Future<?> sayHiAsync(AsyncHandler<SayHiResponse> asyncHandler) {
181: return null;
182: /*not called */
183: }
184:
185: public Response<SayHiResponse> sayHiAsync() {
186: return null;
187: /*not called */
188: }
189:
190: public void greetMeOneWay(String requestType) {
191: }
192:
193: public Response<TestDocLitFaultResponse> testDocLitFaultAsync(
194: String faultType) {
195: return null;
196: /*not called */
197: }
198:
199: public Future<?> testDocLitFaultAsync(String faultType,
200: AsyncHandler ah) {
201: return null;
202: /*not called */
203: }
204:
205: public Future<?> testDocLitBareAsync(String bare, AsyncHandler ah) {
206: return null;
207: /* not called*/
208: }
209:
210: public Response<BareDocumentResponse> testDocLitBareAsync(
211: String bare) {
212: return null;
213: /* not called */
214: }
215:
216: public void testDocLitFault(String faultType)
217: throws BadRecordLitFault, NoSuchCodeLitFault {
218: }
219:
220: public BareDocumentResponse testDocLitBare(String in) {
221: BareDocumentResponse res = new BareDocumentResponse();
222: res.setCompany("Celtix");
223: res.setId(1);
224: return res;
225: }
226: }
|