001: package org.objectweb.celtix.bus.wsdl;
002:
003: import java.io.StringWriter;
004: import java.net.URL;
005: import java.util.List;
006: import java.util.Map;
007: import java.util.WeakHashMap;
008:
009: import javax.wsdl.Definition;
010: import javax.wsdl.Port;
011: import javax.wsdl.extensions.ExtensibilityElement;
012: import javax.xml.namespace.QName;
013:
014: import junit.framework.TestCase;
015:
016: import org.objectweb.celtix.Bus;
017: import org.objectweb.celtix.transports.jms.JMSAddressPolicyType;
018: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
019: import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
020: import org.objectweb.celtix.wsdl.JAXBExtensionHelper;
021: import org.objectweb.celtix.wsdl.WSDLManager;
022:
023: public class WSDLManagerTest extends TestCase {
024:
025: public WSDLManagerTest(String arg0) {
026: super (arg0);
027: }
028:
029: public static void main(String[] args) {
030: junit.textui.TestRunner.run(WSDLManagerTest.class);
031: }
032:
033: /*
034: * Test method for 'org.objectweb.celtix.bus.WSDLManagerImpl.getExtenstionRegistry()'
035: */
036: public void testGetExtenstionRegistry() throws Exception {
037: assertNotNull(new WSDLManagerImpl(null).getExtenstionRegistry());
038: }
039:
040: /*
041: * Test method for 'org.objectweb.celtix.bus.WSDLManagerImpl.getDefinition(URL)'
042: */
043: public void testGetDefinitionURL() throws Exception {
044: URL url = getClass().getResource("/wsdl/hello_world.wsdl");
045: assertNotNull("Could not find WSDL", url);
046: WSDLManager wsdlManager = new WSDLManagerImpl(null);
047: Definition def = wsdlManager.getDefinition(url);
048: assertNotNull(def);
049:
050: Definition def2 = wsdlManager.getDefinition(url);
051: assertTrue(def == def2);
052:
053: url = null;
054: System.gc();
055: System.gc();
056: url = getClass().getResource("/wsdl/hello_world.wsdl");
057: Definition def3 = wsdlManager.getDefinition(url);
058: assertTrue(def != def3);
059: }
060:
061: /*
062: * Test method for 'org.objectweb.celtix.bus.WSDLManagerImpl.getDefinition(String)'
063: */
064: public void testGetDefinitionString() throws Exception {
065: URL neturl = getClass().getResource("/wsdl/hello_world.wsdl");
066: assertNotNull("Could not find WSDL", neturl);
067: String url = neturl.toString();
068: WSDLManager wsdlManager = new WSDLManagerImpl(null);
069: Definition def = wsdlManager.getDefinition(url);
070: assertNotNull(def);
071:
072: Definition def2 = wsdlManager.getDefinition(url);
073: assertTrue(def == def2);
074:
075: url = null;
076: System.gc();
077: System.gc();
078: url = getClass().getResource("/wsdl/hello_world.wsdl")
079: .toString();
080: Definition def3 = wsdlManager.getDefinition(url);
081: assertTrue(def != def3);
082: }
083:
084: public void testExtensions() throws Exception {
085: URL neturl = getClass().getResource("/wsdl/jms_test.wsdl");
086: assertNotNull("Could not find WSDL", neturl);
087: String url = neturl.toString();
088: WSDLManager wsdlManager = new WSDLManagerImpl(null);
089: JAXBExtensionHelper.addExtensions(wsdlManager
090: .getExtenstionRegistry(), javax.wsdl.Port.class,
091: JMSAddressPolicyType.class);
092:
093: Definition def = wsdlManager.getDefinition(url);
094: assertNotNull(def);
095:
096: StringWriter writer = new StringWriter();
097: wsdlManager.getWSDLFactory().newWSDLWriter().writeWSDL(def,
098: writer);
099: assertTrue(writer.toString().indexOf("jms:address") != -1);
100: }
101:
102: public void testExtensionReturnsProperJAXBType() throws Exception {
103: URL neturl = getClass().getResource("/wsdl/jms_test.wsdl");
104: Bus bus = Bus.init();
105: assertNotNull("Could not find WSDL", neturl);
106: WSDLManager wsdlManager = bus.getWSDLManager();
107: JAXBExtensionHelper.addExtensions(wsdlManager
108: .getExtenstionRegistry(), javax.wsdl.Port.class,
109: JMSAddressPolicyType.class);
110:
111: QName serviceName = new QName(
112: "http://celtix.objectweb.org/hello_world_jms",
113: "HelloWorldService");
114:
115: EndpointReferenceType ref = EndpointReferenceUtils
116: .getEndpointReference(neturl, serviceName, "");
117:
118: assertNotNull("Unable to create EndpointReference ", ref);
119:
120: Port port = EndpointReferenceUtils.getPort(wsdlManager, ref);
121: List<?> list = port.getExtensibilityElements();
122: JMSAddressPolicyType jmsAddressDetails = null;
123: for (Object ep : list) {
124: ExtensibilityElement ext = (ExtensibilityElement) ep;
125: if (ext instanceof JMSAddressPolicyType) {
126: jmsAddressDetails = (JMSAddressPolicyType) ext;
127: }
128: }
129: assertNotNull(jmsAddressDetails);
130: }
131:
132: public void testPlugableWSDLManager() throws Exception {
133: WSDLManager wsdlManager = new WSDLManagerImpl(null);
134: Map<String, Object> properties = new WeakHashMap<String, Object>();
135: properties.put("celtix.WSDLManager", wsdlManager);
136: Bus bus = Bus.init(new String[0], properties);
137:
138: WSDLManager wsdlManagerNew = bus.getWSDLManager();
139:
140: //Verify that the WSDLManger is the one we plugged into bus previously
141: assertEquals("wsdlManager is the one we expected", wsdlManager,
142: wsdlManagerNew);
143: }
144: }
|