1 package org.objectweb.celtix.tools.processors.wsdl2; 2 3 import java.io.File ; 4 import java.util.Iterator ; 5 6 import javax.wsdl.Service; 7 import javax.wsdl.extensions.soap.SOAPAddress; 8 import javax.xml.namespace.QName ; 9 10 import org.objectweb.celtix.tools.WSDLToService; 11 import org.objectweb.celtix.tools.common.ToolConstants; 12 import org.objectweb.celtix.tools.common.ToolException; 13 import org.objectweb.celtix.tools.extensions.jms.JMSAddress; 14 import org.objectweb.celtix.tools.processors.ProcessorTestBase; 15 16 public class WSDLToServiceProcessorTest extends ProcessorTestBase { 17 18 public void setUp() throws Exception { 19 super.setUp(); 20 env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath()); 21 } 22 23 public void testNewService() throws Exception { 24 String [] args = new String [] {"-transport", "http", "-e", "serviceins", "-p", "portins", "-n", 25 "Greeter_SOAPBinding", "-a", 26 "http://localhost:9000/newservice/newport", "-d", 27 output.getCanonicalPath(), getLocation("/wsdl/hello_world.wsdl")}; 28 WSDLToService.main(args); 29 30 File outputFile = new File (output, "hello_world-service.wsdl"); 31 assertTrue("New wsdl file is not generated", outputFile.exists()); 32 WSDLToJavaProcessor processor = new WSDLToJavaProcessor(); 33 processor.setEnvironment(env); 34 try { 35 processor.parseWSDL(outputFile.getAbsolutePath()); 36 Service service = processor.getWSDLDefinition().getService( 37 new QName (processor 38 .getWSDLDefinition() 39 .getTargetNamespace(), 40 "serviceins")); 41 if (service == null) { 42 fail("Element wsdl:service serviceins Missed!"); 43 } 44 Iterator it = service.getPort("portins").getExtensibilityElements().iterator(); 45 if (service == null) { 46 fail("Element wsdl:port portins Missed!"); 47 } 48 boolean found = false; 49 while (it.hasNext()) { 50 Object obj = it.next(); 51 if (obj instanceof SOAPAddress) { 52 SOAPAddress soapAddress = (SOAPAddress)obj; 53 if (soapAddress.getLocationURI() != null 54 && soapAddress.getLocationURI().equals("http://localhost:9000/newservice/newport")) { 55 found = true; 56 break; 57 } 58 } 59 } 60 if (!found) { 61 fail("Element soap:address of service port Missed!"); 62 } 63 } catch (ToolException e) { 64 fail("Exception Encountered when parsing wsdl, error: " + e.getMessage()); 65 } 66 } 67 68 public void testDefaultLocation() throws Exception { 69 70 String [] args = new String [] {"-transport", "http", "-e", "serviceins", "-p", "portins", "-n", 71 "Greeter_SOAPBinding", "-d", output.getCanonicalPath(), 72 getLocation("/wsdl/hello_world.wsdl")}; 73 WSDLToService.main(args); 74 75 File outputFile = new File (output, "hello_world-service.wsdl"); 76 assertTrue("New wsdl file is not generated", outputFile.exists()); 77 WSDLToJavaProcessor processor = new WSDLToJavaProcessor(); 78 processor.setEnvironment(env); 79 try { 80 processor.parseWSDL(outputFile.getAbsolutePath()); 81 Service service = processor.getWSDLDefinition().getService( 82 new QName (processor 83 .getWSDLDefinition() 84 .getTargetNamespace(), 85 "serviceins")); 86 if (service == null) { 87 fail("Element wsdl:service serviceins Missed!"); 88 } 89 Iterator it = service.getPort("portins").getExtensibilityElements().iterator(); 90 if (service == null) { 91 fail("Element wsdl:port portins Missed!"); 92 } 93 boolean found = false; 94 while (it.hasNext()) { 95 Object obj = it.next(); 96 if (obj instanceof SOAPAddress) { 97 SOAPAddress soapAddress = (SOAPAddress)obj; 98 if (soapAddress.getLocationURI() != null 99 && soapAddress.getLocationURI().equals("http://localhost:9000/serviceins/portins")) { 100 found = true; 101 break; 102 } 103 } 104 } 105 if (!found) { 106 fail("Element soap:address of service port Missed!"); 107 } 108 } catch (ToolException e) { 109 fail("Exception Encountered when parsing wsdl, error: " + e.getMessage()); 110 } 111 } 112 113 public void testJMSNewService() throws Exception { 114 String [] args = new String [] {"-transport", "jms", "-e", "serviceins", "-p", "portins", "-n", 115 "HelloWorldPortBinding", "-jpu", "tcp://localhost:61616", "-jcf", 116 "org.activemq.jndi.ActiveMQInitialContextFactory", "-jfn", 117 "ConnectionFactory", "-jdn", 118 "dynamicQueues/test.celtix.jmstransport.queue", "-jmt", "text", "-jmc", 119 "false", "-jsn", "Celtix_Queue_subscriber", "-d", 120 output.getCanonicalPath(), getLocation("/wsdl/jms_test.wsdl")}; 121 WSDLToService.main(args); 122 File outputFile = new File (output, "jms_test-service.wsdl"); 123 assertTrue("New wsdl file is not generated", outputFile.exists()); 124 WSDLToJavaProcessor processor = new WSDLToJavaProcessor(); 125 processor.setEnvironment(env); 126 try { 127 processor.parseWSDL(outputFile.getAbsolutePath()); 128 Service service = processor.getWSDLDefinition().getService( 129 new QName (processor 130 .getWSDLDefinition() 131 .getTargetNamespace(), 132 "serviceins")); 133 if (service == null) { 134 fail("Element wsdl:service serviceins Missed!"); 135 } 136 Iterator it = service.getPort("portins").getExtensibilityElements().iterator(); 137 if (service == null) { 138 fail("Element wsdl:port portins Missed!"); 139 } 140 boolean found = false; 141 while (it.hasNext()) { 142 Object obj = it.next(); 143 if (obj instanceof JMSAddress) { 144 JMSAddress jmsAddress = (JMSAddress)obj; 145 if (!(jmsAddress.getDestinationStyle() != null && jmsAddress.getDestinationStyle() 146 .equals("queue"))) { 147 break; 148 } 149 if (!(jmsAddress.getDurableSubscriberName() != null && jmsAddress 150 .getDurableSubscriberName().equals("Celtix_Queue_subscriber"))) { 151 break; 152 } 153 if (!(jmsAddress.getInitialContextFactory() != null && jmsAddress 154 .getInitialContextFactory() 155 .equals("org.activemq.jndi.ActiveMQInitialContextFactory"))) { 156 break; 157 } 158 if (!(jmsAddress.getJndiDestinationName() != null && jmsAddress.getJndiDestinationName() 159 .equals("dynamicQueues/test.celtix.jmstransport.queue"))) { 160 break; 161 } 162 if (!(jmsAddress.getJndiProviderURL() != null && jmsAddress.getJndiProviderURL() 163 .equals("tcp://localhost:61616"))) { 164 break; 165 } 166 if (!(jmsAddress.getMessageType() != null && jmsAddress.getMessageType().equals("text") 167 && !jmsAddress.isUseMessageIDAsCorrelationID())) { 168 break; 169 } 170 found = true; 171 break; 172 } 173 } 174 if (!found) { 175 fail("Element jms:address of service port Missed!"); 176 } 177 } catch (ToolException e) { 178 fail("Exception Encountered when parsing wsdl, error: " + e.getMessage()); 179 } 180 } 181 182 public void testServiceExist() throws Exception { 183 184 WSDLToServiceProcessor processor = new WSDLToServiceProcessor(); 185 186 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world.wsdl")); 187 env.put(ToolConstants.CFG_TRANSPORT, new String ("http")); 188 env.put(ToolConstants.CFG_SERVICE, new String ("SOAPService_Test1")); 189 env.put(ToolConstants.CFG_PORT, new String ("SoapPort_Test1")); 190 env.put(ToolConstants.CFG_BINDING_ATTR, new String ("Greeter_SOAPBinding")); 191 192 processor.setEnvironment(env); 193 194 try { 195 processor.process(); 196 fail("Do not catch expected tool exception for service and port exist"); 197 } catch (Exception e) { 198 if (!(e instanceof ToolException && e.toString() 199 .indexOf("Input service and port already exist in imported contract") >= 0)) { 200 fail("Do not catch tool exception for service and port exist, " 201 + "catch other unexpected exception!"); 202 } 203 } 204 } 205 206 public void testBindingNotExist() throws Exception { 207 208 WSDLToServiceProcessor processor = new WSDLToServiceProcessor(); 209 210 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world.wsdl")); 211 env.put(ToolConstants.CFG_TRANSPORT, new String ("http")); 212 env.put(ToolConstants.CFG_BINDING_ATTR, new String ("BindingNotExist")); 213 env.put(ToolConstants.CFG_SERVICE, new String ("serviceins")); 214 env.put(ToolConstants.CFG_PORT, new String ("portins")); 215 216 processor.setEnvironment(env); 217 218 try { 219 processor.process(); 220 fail("Do not catch expected tool exception for binding not exist!"); 221 } catch (Exception e) { 222 if (!(e instanceof ToolException && e.toString() 223 .indexOf("Input binding does not exist in imported contract") >= 0)) { 224 fail("Do not catch tool exception for binding not exist, " 225 + "catch other unexpected exception!"); 226 } 227 } 228 } 229 230 private String getLocation(String wsdlFile) { 231 return WSDLToServiceProcessorTest.class.getResource(wsdlFile).getFile(); 232 } 233 } 234 | Popular Tags |