1 package org.objectweb.celtix.geronimo.builder; 2 3 import java.net.URL ; 4 import java.util.HashMap ; 5 import java.util.Map ; 6 import java.util.jar.JarFile ; 7 8 import junit.framework.TestCase; 9 10 import org.apache.geronimo.common.DeploymentException; 11 import org.apache.geronimo.gbean.GBeanData; 12 import org.apache.geronimo.gbean.GBeanInfo; 13 import org.apache.geronimo.j2ee.deployment.WebServiceBuilder; 14 import org.apache.geronimo.kernel.StoredObject; 15 import org.easymock.classextension.EasyMock; 16 import org.objectweb.celtix.geronimo.MockBusFactory; 17 import org.objectweb.hello_world_soap_http.Greeter; 18 19 public class CeltixBuilderTest extends TestCase { 20 21 private static final String SERVICE_NAME = "HelloWorldService"; 22 private static final String SERVLET_NAME = "HelloWorldServlet"; 23 private static final String PORT_NAME = "SoapPort"; 24 private static final String WSDL_FILE = "file:/hello_world.wsdl"; 25 26 private final JarFile moduleFile = EasyMock.createMock(JarFile .class); 27 28 private URL wsDescriptor; 29 private PortInfo portInfo; 30 31 private CeltixBuilder builder; 32 33 private MockBusFactory mockBusFactory = new MockBusFactory(); 34 35 public void setUp() throws Exception { 36 37 wsDescriptor = getClass().getResource("webservices.xml"); 38 assertNotNull("failed to load test fixture", wsDescriptor); 39 40 portInfo = new PortInfo(); 41 portInfo.setServiceName(SERVICE_NAME); 42 portInfo.setServletLink(SERVLET_NAME); 43 portInfo.setServiceEndpointInterfaceName(Greeter.class.getName()); 44 portInfo.setPortName(PORT_NAME); 45 portInfo.setWsdlFile(WSDL_FILE); 46 47 mockBusFactory.createMockBus(); 48 builder = new CeltixBuilder(mockBusFactory.getBus()); 49 } 50 51 52 53 54 public void testGetGBeanInfo() { 55 56 GBeanInfo beanInfo = CeltixBuilder.getGBeanInfo(); 57 assertNotNull("getGBeanInfo must not return null", beanInfo); 58 assertEquals("GBean must support correct interfaces", 59 1, beanInfo.getInterfaces().size()); 60 assertTrue("GBean must support WebServicesBuilder interface", 61 beanInfo.getInterfaces().contains(WebServiceBuilder.class.getName())); 62 } 63 64 public void testConfigurePojo() throws Exception { 65 66 GBeanData gbeanData = EasyMock.createMock(GBeanData.class); 67 ClassLoader loader = EasyMock.createMock(ClassLoader .class); 68 69 gbeanData.setAttribute("pojoClassName", Greeter.class.getName()); 70 loader.loadClass(Greeter.class.getName()); 71 EasyMock.expectLastCall().andReturn(Greeter.class); 72 gbeanData.setAttribute(EasyMock.matches("webServiceContainer"), 73 EasyMock.isA(StoredObject.class)); 74 75 EasyMock.replay(gbeanData); 76 mockBusFactory.replay(); 77 78 builder.configurePOJO(gbeanData, moduleFile, portInfo, Greeter.class.getName(), 79 getClass().getClassLoader()); 80 81 EasyMock.verify(gbeanData); 82 } 83 84 @SuppressWarnings ("unchecked") 85 public void testParseWebServiceDescriptor() throws DeploymentException { 86 87 boolean isEJB = false; 88 Map <String , String > correctedPortLocations = new HashMap <String , String >(); 89 correctedPortLocations.put("HelloWorldServlet", "//wstest/Hello"); 90 91 Map ret = builder.parseWebServiceDescriptor(wsDescriptor, moduleFile, isEJB, correctedPortLocations); 92 assertNotNull("parseWebServiceDescriptor must return port-info map", 93 ret); 94 assertTrue("port info map must not be empty", !ret.isEmpty()); 95 96 Map <String , PortInfo> map = (Map <String , PortInfo>)ret; 97 98 PortInfo pi = map.get("HelloWorldServlet"); 99 assertNotNull("could not find port info object", pi); 100 } 101 102 public void testLoadSEI() throws Exception { 103 104 Class <?> seiClass = builder.loadSEI(Greeter.class.getName(), getClass().getClassLoader()); 105 assertNotNull("method must not return null class", seiClass); 106 assertEquals("method returned correct class", Greeter.class, seiClass); 107 } 108 109 } 110 | Popular Tags |