1 package org.objectweb.celtix.tools.processors.wsdl2; 2 3 import java.io.File ; 4 import java.util.Iterator ; 5 6 import javax.wsdl.Binding; 7 import javax.wsdl.BindingFault; 8 import javax.wsdl.BindingInput; 9 import javax.wsdl.BindingOperation; 10 import javax.wsdl.extensions.soap.SOAPBinding; 11 import javax.wsdl.extensions.soap.SOAPBody; 12 import javax.wsdl.extensions.soap.SOAPFault; 13 import javax.wsdl.extensions.soap.SOAPOperation; 14 import javax.xml.namespace.QName ; 15 16 import org.objectweb.celtix.tools.WSDLToSoap; 17 import org.objectweb.celtix.tools.common.ToolConstants; 18 import org.objectweb.celtix.tools.common.ToolException; 19 import org.objectweb.celtix.tools.processors.ProcessorTestBase; 20 21 public class WSDLToSoapProcessorTest extends ProcessorTestBase { 22 23 public void setUp() throws Exception { 24 super.setUp(); 25 env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath()); 26 } 27 28 public void testDocLitWithFault() throws Exception { 29 String [] args = new String [] {"-i", "Greeter", "-d", output.getCanonicalPath(), 30 getLocation("/wsdl/hello_world_doc_lit.wsdl")}; 31 WSDLToSoap.main(args); 32 33 File outputFile = new File (output, "hello_world_doc_lit-soapbinding.wsdl"); 34 assertTrue("New wsdl file is not generated", outputFile.exists()); 35 WSDLToJavaProcessor processor = new WSDLToJavaProcessor(); 36 processor.setEnvironment(env); 37 try { 38 processor.parseWSDL(outputFile.getAbsolutePath()); 39 Binding binding = processor.getWSDLDefinition().getBinding( 40 new QName (processor 41 .getWSDLDefinition() 42 .getTargetNamespace(), 43 "Greeter_Binding")); 44 if (binding == null) { 45 fail("Element wsdl:binding Greeter_Binding Missed!"); 46 } 47 Iterator it = binding.getExtensibilityElements().iterator(); 48 boolean found = false; 49 while (it.hasNext()) { 50 Object obj = it.next(); 51 if (obj instanceof SOAPBinding 52 && ((SOAPBinding)obj).getStyle().equalsIgnoreCase("document")) { 53 found = true; 54 break; 55 } 56 } 57 if (!found) { 58 fail("Element soap:binding Missed!"); 59 } 60 BindingOperation bo = binding.getBindingOperation("pingMe", null, null); 61 if (bo == null) { 62 fail("Element <wsdl:operation name=\"pingMe\"> Missed!"); 63 } 64 it = bo.getExtensibilityElements().iterator(); 65 found = false; 66 while (it.hasNext()) { 67 Object obj = it.next(); 68 if (obj instanceof SOAPOperation 69 && ((SOAPOperation)obj).getStyle().equalsIgnoreCase("document")) { 70 found = true; 71 break; 72 } 73 } 74 if (!found) { 75 fail("Element soap:operation Missed!"); 76 } 77 BindingFault fault = bo.getBindingFault("pingMeFault"); 78 if (fault == null) { 79 fail("Element <wsdl:fault name=\"pingMeFault\"> Missed!"); 80 } 81 it = fault.getExtensibilityElements().iterator(); 82 found = false; 83 while (it.hasNext()) { 84 Object obj = it.next(); 85 if (obj instanceof SOAPFault) { 86 found = true; 87 break; 88 } 89 } 90 if (!found) { 91 fail("Element soap:fault Missed!"); 92 } 93 } catch (ToolException e) { 94 fail("Exception Encountered when parsing wsdl, error: " + e.getMessage()); 95 } 96 } 97 98 public void testRpcLitWithoutFault() throws Exception { 99 String [] args = new String [] {"-i", "GreeterRPCLit", "-n", 100 "http://objectweb.org/hello_world_rpclit_test", "-b", 101 "Greeter_SOAPBinding_NewBinding", "-style", "rpc", "-use", "literal", 102 "-d", output.getCanonicalPath(), "-o", 103 "hello_world_rpc_lit_newbinding.wsdl", 104 getLocation("/wsdl/hello_world_rpc_lit.wsdl")}; 105 WSDLToSoap.main(args); 106 107 File outputFile = new File (output, "hello_world_rpc_lit_newbinding.wsdl"); 108 assertTrue("New wsdl file is not generated", outputFile.exists()); 109 110 WSDLToJavaProcessor processor = new WSDLToJavaProcessor(); 111 processor.setEnvironment(env); 112 try { 113 processor.parseWSDL(outputFile.getAbsolutePath()); 114 Binding binding = processor.getWSDLDefinition() 115 .getBinding( 116 new QName (processor.getWSDLDefinition().getTargetNamespace(), 117 "Greeter_SOAPBinding_NewBinding")); 118 if (binding == null) { 119 fail("Element wsdl:binding Greeter_SOAPBinding_NewBinding Missed!"); 120 } 121 Iterator it = binding.getExtensibilityElements().iterator(); 122 boolean found = false; 123 while (it.hasNext()) { 124 Object obj = it.next(); 125 if (obj instanceof SOAPBinding && ((SOAPBinding)obj).getStyle().equalsIgnoreCase("rpc")) { 126 found = true; 127 break; 128 129 } 130 } 131 if (!found) { 132 fail("Element soap:binding style=rpc Missed!"); 133 } 134 BindingOperation bo = binding.getBindingOperation("sendReceiveData", null, null); 135 if (bo == null) { 136 fail("Element <wsdl:operation name=\"sendReceiveData\"> Missed!"); 137 } 138 it = bo.getExtensibilityElements().iterator(); 139 found = false; 140 while (it.hasNext()) { 141 Object obj = it.next(); 142 if (obj instanceof SOAPOperation && ((SOAPOperation)obj).getStyle().equalsIgnoreCase("rpc")) { 143 found = true; 144 break; 145 } 146 } 147 if (!found) { 148 fail("Element soap:operation style=rpc Missed!"); 149 } 150 BindingInput bi = bo.getBindingInput(); 151 it = bi.getExtensibilityElements().iterator(); 152 found = false; 153 while (it.hasNext()) { 154 Object obj = it.next(); 155 if (obj instanceof SOAPBody && ((SOAPBody)obj).getUse().equalsIgnoreCase("literal")) { 156 found = true; 157 break; 158 } 159 } 160 if (!found) { 161 fail("Element soap:body use=literal Missed!"); 162 } 163 } catch (ToolException e) { 164 fail("Exception Encountered when parsing wsdl, error: " + e.getMessage()); 165 } 166 } 167 168 public void testPartValidation() throws Exception { 169 WSDLToSoapProcessor processor = new WSDLToSoapProcessor(); 170 env.put(ToolConstants.CFG_PORTTYPE, "Greeter"); 171 env.put(ToolConstants.CFG_BINDING, "Greeter_Binding"); 172 env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath()); 173 env.put(ToolConstants.CFG_STYLE, "rpc"); 174 env.put(ToolConstants.CFG_USE, "literal"); 175 env.put(ToolConstants.CFG_NAMESPACE, "http://com.iona.hello_world/rpc"); 176 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world.wsdl")); 177 processor.setEnvironment(env); 178 try { 179 processor.process(); 180 fail("Do not catch expected tool exception for Part Reference illegal!"); 181 } catch (Exception e) { 182 if (!(e instanceof ToolException && e.toString() 183 .indexOf("does not use type reference not confirm to RPC style") >= 0)) { 184 fail("Do not catch tool exception for Part Reference illegal, " 185 + "catch other unexpected exception: " + e.getMessage()); 186 } 187 } 188 } 189 190 public void testBindingExist() throws Exception { 191 WSDLToSoapProcessor processor = new WSDLToSoapProcessor(); 192 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_rpc_lit.wsdl")); 193 env.put(ToolConstants.CFG_PORTTYPE, new String ("GreeterRPCLit")); 194 env.put(ToolConstants.CFG_BINDING, new String ("Greeter_SOAPBinding_RPCLit")); 195 processor.setEnvironment(env); 196 try { 197 processor.process(); 198 fail("Do not catch expected tool exception for binding exist!"); 199 } catch (Exception e) { 200 if (!(e instanceof ToolException && e.toString() 201 .indexOf("Input binding already exist in imported contract") >= 0)) { 202 fail("Do not catch tool exception for binding exist, " + "catch other unexpected exception!"); 203 } 204 } 205 } 206 207 public void testPortTypeNotExist() throws Exception { 208 WSDLToSoapProcessor processor = new WSDLToSoapProcessor(); 209 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_rpc_lit.wsdl")); 210 env.put(ToolConstants.CFG_PORTTYPE, new String ("NonExistPortType")); 211 env.put(ToolConstants.CFG_BINDING, new String ("NewBinding_RPCLit")); 212 processor.setEnvironment(env); 213 try { 214 processor.process(); 215 fail("Do not catch expected tool exception for binding not exist!"); 216 } catch (Exception e) { 217 if (!(e instanceof ToolException && e.toString() 218 .indexOf("Input port type does not exist in imported contract") >= 0)) { 219 fail("Do not catch tool exception for port type not exist, " 220 + "catch other unexpected exception!"); 221 } 222 } 223 } 224 225 public void testNameSpaceMissing() throws Exception { 226 WSDLToSoapProcessor processor = new WSDLToSoapProcessor(); 227 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_rpc_lit.wsdl")); 228 env.put(ToolConstants.CFG_PORTTYPE, new String ("GreeterRPCLit")); 229 env.put(ToolConstants.CFG_BINDING, new String ("NewBinding_RPCLit")); 230 env.put(ToolConstants.CFG_STYLE, new String ("rpc")); 231 processor.setEnvironment(env); 232 try { 233 processor.process(); 234 fail("Do not catch expected tool exception for name space missing!"); 235 } catch (Exception e) { 236 if (!(e instanceof ToolException && e.toString() 237 .indexOf("For rpc style binding, soap binding namespace (-n) must be provided") >= 0)) { 238 fail("Do not catch tool exception for binding exist, " + "catch other unexpected exception!"); 239 } 240 } 241 } 242 243 private String getLocation(String wsdlFile) { 244 return WSDLToSoapProcessorTest.class.getResource(wsdlFile).getFile(); 245 } 246 247 } 248 | Popular Tags |