1 package org.objectweb.celtix.bus.wsdl; 2 3 import java.io.StringWriter ; 4 import java.net.URL ; 5 import java.util.List ; 6 import java.util.Map ; 7 import java.util.WeakHashMap ; 8 9 import javax.wsdl.Definition; 10 import javax.wsdl.Port; 11 import javax.wsdl.extensions.ExtensibilityElement; 12 import javax.xml.namespace.QName ; 13 14 import junit.framework.TestCase; 15 16 import org.objectweb.celtix.Bus; 17 import org.objectweb.celtix.transports.jms.JMSAddressPolicyType; 18 import org.objectweb.celtix.ws.addressing.EndpointReferenceType; 19 import org.objectweb.celtix.wsdl.EndpointReferenceUtils; 20 import org.objectweb.celtix.wsdl.JAXBExtensionHelper; 21 import org.objectweb.celtix.wsdl.WSDLManager; 22 23 public class WSDLManagerTest extends TestCase { 24 25 public WSDLManagerTest(String arg0) { 26 super(arg0); 27 } 28 29 public static void main(String [] args) { 30 junit.textui.TestRunner.run(WSDLManagerTest.class); 31 } 32 33 36 public void testGetExtenstionRegistry() throws Exception { 37 assertNotNull(new WSDLManagerImpl(null).getExtenstionRegistry()); 38 } 39 40 43 public void testGetDefinitionURL() throws Exception { 44 URL url = getClass().getResource("/wsdl/hello_world.wsdl"); 45 assertNotNull("Could not find WSDL", url); 46 WSDLManager wsdlManager = new WSDLManagerImpl(null); 47 Definition def = wsdlManager.getDefinition(url); 48 assertNotNull(def); 49 50 Definition def2 = wsdlManager.getDefinition(url); 51 assertTrue(def == def2); 52 53 url = null; 54 System.gc(); 55 System.gc(); 56 url = getClass().getResource("/wsdl/hello_world.wsdl"); 57 Definition def3 = wsdlManager.getDefinition(url); 58 assertTrue(def != def3); 59 } 60 61 64 public void testGetDefinitionString() throws Exception { 65 URL neturl = getClass().getResource("/wsdl/hello_world.wsdl"); 66 assertNotNull("Could not find WSDL", neturl); 67 String url = neturl.toString(); 68 WSDLManager wsdlManager = new WSDLManagerImpl(null); 69 Definition def = wsdlManager.getDefinition(url); 70 assertNotNull(def); 71 72 Definition def2 = wsdlManager.getDefinition(url); 73 assertTrue(def == def2); 74 75 url = null; 76 System.gc(); 77 System.gc(); 78 url = getClass().getResource("/wsdl/hello_world.wsdl").toString(); 79 Definition def3 = wsdlManager.getDefinition(url); 80 assertTrue(def != def3); 81 } 82 83 84 public void testExtensions() throws Exception { 85 URL neturl = getClass().getResource("/wsdl/jms_test.wsdl"); 86 assertNotNull("Could not find WSDL", neturl); 87 String url = neturl.toString(); 88 WSDLManager wsdlManager = new WSDLManagerImpl(null); 89 JAXBExtensionHelper.addExtensions(wsdlManager.getExtenstionRegistry(), 90 javax.wsdl.Port.class, 91 JMSAddressPolicyType.class); 92 93 Definition def = wsdlManager.getDefinition(url); 94 assertNotNull(def); 95 96 StringWriter writer = new StringWriter (); 97 wsdlManager.getWSDLFactory().newWSDLWriter().writeWSDL(def, writer); 98 assertTrue(writer.toString().indexOf("jms:address") != -1); 99 } 100 101 public void testExtensionReturnsProperJAXBType() throws Exception { 102 URL neturl = getClass().getResource("/wsdl/jms_test.wsdl"); 103 Bus bus = Bus.init(); 104 assertNotNull("Could not find WSDL", neturl); 105 WSDLManager wsdlManager = bus.getWSDLManager(); 106 JAXBExtensionHelper.addExtensions(wsdlManager.getExtenstionRegistry(), 107 javax.wsdl.Port.class, 108 JMSAddressPolicyType.class); 109 110 QName serviceName = new QName ("http://celtix.objectweb.org/hello_world_jms", "HelloWorldService"); 111 112 EndpointReferenceType ref = 113 EndpointReferenceUtils.getEndpointReference(neturl, serviceName, ""); 114 115 assertNotNull("Unable to create EndpointReference ", ref); 116 117 Port port = EndpointReferenceUtils.getPort(wsdlManager, ref); 118 List <?> list = port.getExtensibilityElements(); 119 JMSAddressPolicyType jmsAddressDetails = null; 120 for (Object ep : list) { 121 ExtensibilityElement ext = (ExtensibilityElement)ep; 122 if (ext instanceof JMSAddressPolicyType) { 123 jmsAddressDetails = (JMSAddressPolicyType)ext; 124 } 125 } 126 assertNotNull(jmsAddressDetails); 127 } 128 129 public void testPlugableWSDLManager() throws Exception { 130 WSDLManager wsdlManager = new WSDLManagerImpl(null); 131 Map <String , Object > properties = new WeakHashMap <String , Object >(); 132 properties.put("celtix.WSDLManager", wsdlManager); 133 Bus bus = Bus.init(new String [0], properties); 134 135 WSDLManager wsdlManagerNew = bus.getWSDLManager(); 136 137 assertEquals("wsdlManager is the one we expected", wsdlManager, wsdlManagerNew); 139 } 140 } 141 | Popular Tags |