1 package org.objectweb.celtix.bus.handlers; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 import java.util.concurrent.Future ; 6 7 import javax.jws.HandlerChain; 8 import javax.jws.WebService; 9 import javax.xml.ws.AsyncHandler; 10 import javax.xml.ws.Response; 11 import javax.xml.ws.WebServiceException; 12 import javax.xml.ws.handler.Handler; 13 import javax.xml.ws.handler.LogicalHandler; 14 15 import junit.framework.TestCase; 16 17 import org.easymock.EasyMock; 18 import org.objectweb.hello_world_soap_http.AnnotatedGreeterImpl; 19 import org.objectweb.hello_world_soap_http.BadRecordLitFault; 20 import org.objectweb.hello_world_soap_http.Greeter; 21 import org.objectweb.hello_world_soap_http.NoSuchCodeLitFault; 22 import org.objectweb.hello_world_soap_http.types.BareDocumentResponse; 23 import org.objectweb.hello_world_soap_http.types.GreetMeResponse; 24 import org.objectweb.hello_world_soap_http.types.GreetMeSometimeResponse; 25 import org.objectweb.hello_world_soap_http.types.SayHiResponse; 26 import org.objectweb.hello_world_soap_http.types.TestDocLitFaultResponse; 27 28 public class AnnotationHandlerChainBuilderTest extends TestCase { 29 30 Handler[] allHandlers = {EasyMock.createMock(LogicalHandler.class), 31 EasyMock.createMock(Handler.class), 32 EasyMock.createMock(Handler.class), 33 EasyMock.createMock(LogicalHandler.class)}; 34 Handler[] logicalHandlers = {allHandlers[0], allHandlers[3]}; 35 Handler[] protocolHandlers = {allHandlers[1], allHandlers[2]}; 36 AnnotatedGreeterImpl greeterImpl = new AnnotatedGreeterImpl(); 37 38 AnnotationHandlerChainBuilder builder = new AnnotationHandlerChainBuilder(); 39 40 41 public void testBuildHandlerChainWithExistingHandlers() { 42 43 List <Handler> existingChain = new ArrayList <Handler>(); 44 existingChain.add(EasyMock.createMock(LogicalHandler.class)); 45 existingChain.add(EasyMock.createMock(Handler.class)); 46 47 List <Handler> chain = builder.buildHandlerChainFor(AnnotatedGreeterImpl.class, existingChain); 48 49 assertNotNull(chain); 50 assertEquals(3, chain.size()); 51 assertTrue(chain.get(0) instanceof LogicalHandler); 52 assertFalse(chain.get(1) instanceof LogicalHandler); 53 assertFalse(chain.get(2) instanceof LogicalHandler); 54 } 55 56 57 public void testBuildHandlerChainWithExistingHandlersNoAnnotation() { 58 59 List <Handler> existingChain = new ArrayList <Handler>(); 60 existingChain.add(EasyMock.createMock(LogicalHandler.class)); 61 existingChain.add(EasyMock.createMock(Handler.class)); 62 63 List <Handler> chain = builder.buildHandlerChainFor(Greeter.class, existingChain); 64 65 assertNotNull(chain); 66 assertEquals(existingChain.size(), chain.size()); 67 assertSame(existingChain.get(0), chain.get(0)); 68 assertSame(existingChain.get(1), chain.get(1)); 69 70 } 71 72 73 public void testBuildHandlerChain() { 74 75 List <Handler> chain = builder.buildHandlerChainFor(AnnotatedGreeterImpl.class); 76 77 assertNotNull(chain); 78 assertEquals(1, chain.size()); 79 } 80 81 public void testBuildHandlerForServiceEndpointInterface() { 82 83 List <Handler> chain = builder.buildHandlerChainFor(GreeterWithHandlerChainOnInterfaceImpl.class); 84 85 assertNotNull(chain); 86 assertEquals(1, chain.size()); 87 } 88 89 90 public void testBuildHandlerChainNoHanlders() { 91 List <Handler> chain = builder.buildHandlerChainFor(String .class); 92 assertNotNull(chain); 93 assertEquals(0, chain.size()); 94 } 95 96 public void testBuildHandlerChainInvalidFile() { 97 98 try { 99 builder.buildHandlerChainFor(InvalidAnnotation.class); 100 fail("did not get expected exception"); 101 } catch (WebServiceException ex) { 102 } 104 } 105 106 public void testBuildHandlerChainInvalidHandlerList() { 107 108 try { 109 builder.buildHandlerChainFor(InvalidName.class); 110 fail("did not get expected exception"); 111 } catch (WebServiceException ex) { 112 } 114 } 115 116 } 117 118 119 @HandlerChain(file = "invalid_annotation.xml", name = "yoohoo") 120 class InvalidAnnotation extends AnnotatedGreeterImpl { 121 } 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 137 @WebService(name = "Greeter") 138 @HandlerChain(file = "../../../hello_world_soap_http/handlers.xml", name = "TestHandlerChain") 139 interface GreeterWithHandlerChain extends Greeter { 140 141 } 142 143 class GreeterWithHandlerChainOnInterfaceImpl implements 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, AsyncHandler ah) { 158 return null; 159 160 } 161 162 public Response<GreetMeSometimeResponse> greetMeSometimeAsync(String requestType) { 163 return null; 164 165 } 166 167 public Future <?> greetMeAsync(String requestType, AsyncHandler<GreetMeResponse> asyncHandler) { 168 return null; 169 170 } 171 172 public Response<GreetMeResponse> greetMeAsync(String requestType) { 173 return null; 174 175 } 176 177 public Future <?> sayHiAsync(AsyncHandler<SayHiResponse> asyncHandler) { 178 return null; 179 180 } 181 182 public Response<SayHiResponse> sayHiAsync() { 183 return null; 184 185 } 186 187 public void greetMeOneWay(String requestType) { 188 } 189 190 public Response<TestDocLitFaultResponse> testDocLitFaultAsync(String faultType) { 191 return null; 192 193 } 194 195 public Future <?> testDocLitFaultAsync(String faultType, AsyncHandler ah) { 196 return null; 197 198 } 199 200 public Future <?> testDocLitBareAsync(String bare, AsyncHandler ah) { 201 return null; 202 203 } 204 205 public Response<BareDocumentResponse>testDocLitBareAsync(String bare) { 206 return null; 207 208 } 209 210 public void testDocLitFault(String faultType) throws BadRecordLitFault, NoSuchCodeLitFault { 211 } 212 213 public BareDocumentResponse testDocLitBare(String in) { 214 BareDocumentResponse res = new BareDocumentResponse(); 215 res.setCompany("Celtix"); 216 res.setId(1); 217 return res; 218 } 219 } 220 | Popular Tags |