001: package org.objectweb.celtix.geronimo.builder;
002:
003: import java.net.URL;
004: import java.util.HashMap;
005: import java.util.Map;
006: import java.util.jar.JarFile;
007:
008: import junit.framework.TestCase;
009:
010: import org.apache.geronimo.common.DeploymentException;
011: import org.apache.geronimo.gbean.GBeanData;
012: import org.apache.geronimo.gbean.GBeanInfo;
013: import org.apache.geronimo.j2ee.deployment.WebServiceBuilder;
014: import org.apache.geronimo.kernel.StoredObject;
015: import org.easymock.classextension.EasyMock;
016: import org.objectweb.celtix.geronimo.MockBusFactory;
017: import org.objectweb.hello_world_soap_http.Greeter;
018:
019: public class CeltixBuilderTest extends TestCase {
020:
021: private static final String SERVICE_NAME = "HelloWorldService";
022: private static final String SERVLET_NAME = "HelloWorldServlet";
023: private static final String PORT_NAME = "SoapPort";
024: private static final String WSDL_FILE = "file:/hello_world.wsdl";
025:
026: private final JarFile moduleFile = EasyMock
027: .createMock(JarFile.class);
028:
029: private URL wsDescriptor;
030: private PortInfo portInfo;
031:
032: private CeltixBuilder builder;
033:
034: private MockBusFactory mockBusFactory = new MockBusFactory();
035:
036: public void setUp() throws Exception {
037:
038: wsDescriptor = getClass().getResource("webservices.xml");
039: assertNotNull("failed to load test fixture", wsDescriptor);
040:
041: portInfo = new PortInfo();
042: portInfo.setServiceName(SERVICE_NAME);
043: portInfo.setServletLink(SERVLET_NAME);
044: portInfo.setServiceEndpointInterfaceName(Greeter.class
045: .getName());
046: portInfo.setPortName(PORT_NAME);
047: portInfo.setWsdlFile(WSDL_FILE);
048:
049: mockBusFactory.createMockBus();
050: builder = new CeltixBuilder(mockBusFactory.getBus());
051: }
052:
053: public void testGetGBeanInfo() {
054:
055: GBeanInfo beanInfo = CeltixBuilder.getGBeanInfo();
056: assertNotNull("getGBeanInfo must not return null", beanInfo);
057: assertEquals("GBean must support correct interfaces", 1,
058: beanInfo.getInterfaces().size());
059: assertTrue("GBean must support WebServicesBuilder interface",
060: beanInfo.getInterfaces().contains(
061: WebServiceBuilder.class.getName()));
062: }
063:
064: public void testConfigurePojo() throws Exception {
065:
066: GBeanData gbeanData = EasyMock.createMock(GBeanData.class);
067: ClassLoader loader = EasyMock.createMock(ClassLoader.class);
068:
069: gbeanData
070: .setAttribute("pojoClassName", Greeter.class.getName());
071: loader.loadClass(Greeter.class.getName());
072: EasyMock.expectLastCall().andReturn(Greeter.class);
073: gbeanData.setAttribute(EasyMock.matches("webServiceContainer"),
074: EasyMock.isA(StoredObject.class));
075:
076: EasyMock.replay(gbeanData);
077: mockBusFactory.replay();
078:
079: builder.configurePOJO(gbeanData, moduleFile, portInfo,
080: Greeter.class.getName(), getClass().getClassLoader());
081:
082: EasyMock.verify(gbeanData);
083: }
084:
085: @SuppressWarnings("unchecked")
086: public void testParseWebServiceDescriptor()
087: throws DeploymentException {
088:
089: boolean isEJB = false;
090: Map<String, String> correctedPortLocations = new HashMap<String, String>();
091: correctedPortLocations.put("HelloWorldServlet",
092: "//wstest/Hello");
093:
094: Map ret = builder.parseWebServiceDescriptor(wsDescriptor,
095: moduleFile, isEJB, correctedPortLocations);
096: assertNotNull(
097: "parseWebServiceDescriptor must return port-info map",
098: ret);
099: assertTrue("port info map must not be empty", !ret.isEmpty());
100:
101: Map<String, PortInfo> map = (Map<String, PortInfo>) ret;
102:
103: PortInfo pi = map.get("HelloWorldServlet");
104: assertNotNull("could not find port info object", pi);
105: }
106:
107: public void testLoadSEI() throws Exception {
108:
109: Class<?> seiClass = builder.loadSEI(Greeter.class.getName(),
110: getClass().getClassLoader());
111: assertNotNull("method must not return null class", seiClass);
112: assertEquals("method returned correct class", Greeter.class,
113: seiClass);
114: }
115:
116: }
|