1 package org.objectweb.celtix.tools.processors.wsdl2; 2 3 import java.io.File ; 4 import java.lang.reflect.Method ; 5 import java.lang.reflect.Modifier ; 6 import java.net.URLClassLoader ; 7 8 import javax.jws.HandlerChain; 9 import javax.jws.Oneway; 10 import javax.jws.WebMethod; 11 import javax.jws.WebParam; 12 import javax.jws.WebResult; 13 import javax.jws.WebService; 14 import javax.jws.soap.SOAPBinding; 15 import javax.xml.ws.Holder; 16 import javax.xml.ws.RequestWrapper; 17 import javax.xml.ws.ResponseWrapper; 18 19 import org.objectweb.celtix.tools.WSDLToJava; 20 import org.objectweb.celtix.tools.common.ToolConstants; 21 import org.objectweb.celtix.tools.processors.ProcessorTestBase; 22 import org.objectweb.celtix.tools.utils.AnnotationUtil; 23 24 public class WSDLToJavaProcessorTest extends ProcessorTestBase { 25 private WSDLToJavaProcessor processor = new WSDLToJavaProcessor(); 26 private URLClassLoader classLoader; 27 28 public void setUp() throws Exception { 29 super.setUp(); 30 File classFile = new java.io.File (output.getCanonicalPath() + "/classes"); 31 classFile.mkdir(); 32 System.setProperty("java.class.path", getClassPath() + classFile.getCanonicalPath() 33 + File.separatorChar); 34 classLoader = AnnotationUtil.getClassLoader(Thread.currentThread().getContextClassLoader()); 35 env.put(ToolConstants.CFG_COMPILE, "compile"); 36 env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath()); 37 env.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath() + "/classes"); 38 } 39 40 public void tearDown() { 41 super.tearDown(); 42 processor = null; 43 44 } 45 46 public void testRPCLit() throws Exception { 47 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_rpc_lit.wsdl")); 48 processor.setEnvironment(env); 49 processor.process(); 50 51 assertNotNull(output); 52 53 File org = new File (output, "org"); 54 assertTrue(org.exists()); 55 File objectweb = new File (org, "objectweb"); 56 assertTrue(objectweb.exists()); 57 File helloworldsoaphttp = new File (objectweb, "hello_world_rpclit"); 58 assertTrue(helloworldsoaphttp.exists()); 59 File types = new File (helloworldsoaphttp, "types"); 60 assertTrue(types.exists()); 61 File [] files = helloworldsoaphttp.listFiles(); 62 assertEquals(3, files.length); 63 files = types.listFiles(); 64 assertEquals(files.length, 3); 65 66 Class clz = classLoader.loadClass("org.objectweb.hello_world_rpclit.GreeterRPCLit"); 67 68 SOAPBinding soapBindingAnno = AnnotationUtil.getPrivClassAnnotation(clz, SOAPBinding.class); 69 assertEquals("LITERAL", soapBindingAnno.use().toString()); 70 assertEquals("RPC", soapBindingAnno.style().toString()); 71 72 assertEquals("Generate operation error", 3, clz.getMethods().length); 73 74 Class paraClass = classLoader.loadClass("org.objectweb.hello_world_rpclit.types.MyComplexStruct"); 75 Method method = clz.getMethod("sendReceiveData", new Class [] {paraClass}); 76 assertEquals("MyComplexStruct", method.getReturnType().getSimpleName()); 77 } 78 79 public void testAsynMethod() throws Exception { 80 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_async.wsdl")); 81 processor.setEnvironment(env); 82 processor.process(); 83 84 assertNotNull(output); 85 86 File org = new File (output, "org"); 87 assertTrue(org.exists()); 88 File objectweb = new File (org, "objectweb"); 89 assertTrue(objectweb.exists()); 90 File async = new File (objectweb, "hello_world_async_soap_http"); 91 assertTrue(async.exists()); 92 93 File [] files = async.listFiles(); 94 assertEquals(3, files.length); 95 96 Class clz = classLoader.loadClass("org.objectweb.hello_world_async_soap_http.GreeterAsync"); 97 Method method1 = clz.getMethod("greetMeSometimeAsync", new Class [] {java.lang.String .class, 98 javax.xml.ws.AsyncHandler.class}); 99 WebMethod webMethodAnno1 = AnnotationUtil.getPrivMethodAnnotation(method1, WebMethod.class); 100 101 assertEquals(method1.getName() + "()" + " Annotation : WebMethod.operationName ", "greetMeSometime", 102 webMethodAnno1.operationName()); 103 104 java.lang.reflect.Method method2 = clz.getMethod("greetMeSometimeAsync", 105 new Class [] {java.lang.String .class}); 106 WebMethod webMethodAnno2 = AnnotationUtil.getPrivMethodAnnotation(method2, WebMethod.class); 107 assertEquals(method2.getName() + "()" + " Annotation : WebMethod.operationName ", "greetMeSometime", 108 webMethodAnno2.operationName()); 109 110 } 111 112 public void testHelloWorld() throws Exception { 113 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world.wsdl")); 114 processor.setEnvironment(env); 115 processor.process(); 116 117 assertNotNull(output); 118 119 File org = new File (output, "org"); 120 assertTrue(org.exists()); 121 File objectweb = new File (org, "objectweb"); 122 assertTrue(objectweb.exists()); 123 File helloworldsoaphttp = new File (objectweb, "hello_world_soap_http"); 124 assertTrue(helloworldsoaphttp.exists()); 125 File types = new File (helloworldsoaphttp, "types"); 126 assertTrue(types.exists()); 127 File [] files = helloworldsoaphttp.listFiles(); 128 assertEquals(6, files.length); 129 files = types.listFiles(); 130 assertEquals(17, files.length); 131 132 Class clz = classLoader.loadClass("org.objectweb.hello_world_soap_http.Greeter"); 133 assertTrue("class " + clz.getName() + " modifier is not public", Modifier 134 .isPublic(clz.getModifiers())); 135 assertTrue("class " + clz.getName() + " modifier is interface", 136 Modifier.isInterface(clz.getModifiers())); 137 138 WebService webServiceAnn = AnnotationUtil.getPrivClassAnnotation(clz, WebService.class); 139 assertEquals("Greeter", webServiceAnn.name()); 140 141 Method method = clz.getMethod("sayHi", new Class [] {}); 142 WebMethod webMethodAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebMethod.class); 143 assertEquals(method.getName() + "()" + " Annotation : WebMethod.operationName ", "sayHi", 144 webMethodAnno.operationName()); 145 146 RequestWrapper requestWrapperAnn = AnnotationUtil.getPrivMethodAnnotation(method, 147 RequestWrapper.class); 148 149 assertEquals("org.objectweb.hello_world_soap_http.types.SayHi", requestWrapperAnn.className()); 150 151 ResponseWrapper resposneWrapperAnn = AnnotationUtil.getPrivMethodAnnotation(method, 152 ResponseWrapper.class); 153 154 assertEquals("sayHiResponse", resposneWrapperAnn.localName()); 155 156 WebResult webResultAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebResult.class); 157 158 assertEquals("responseType", webResultAnno.name()); 159 160 method = clz.getMethod("greetMe", new Class [] {String .class}); 161 assertEquals("String", method.getReturnType().getSimpleName()); 162 WebParam webParamAnn = AnnotationUtil.getWebParam(method, "requestType"); 163 assertEquals("http://objectweb.org/hello_world_soap_http/types", webParamAnn.targetNamespace()); 164 165 method = clz.getMethod("greetMeOneWay", new Class [] {String .class}); 166 Oneway oneWayAnn = AnnotationUtil.getPrivMethodAnnotation(method, Oneway.class); 167 assertNotNull("OneWay Annotation is not generated", oneWayAnn); 168 assertEquals("void", method.getReturnType().getSimpleName()); 169 170 method = clz.getMethod("greetMeSometime", new Class [] {String .class}); 171 assertEquals("String", method.getReturnType().getSimpleName()); 172 173 method = clz.getMethod("testDocLitFault", new Class [] {java.lang.String .class}); 174 assertEquals("void", method.getReturnType().getSimpleName()); 175 assertEquals("Exception class is not generated ", 2, method.getExceptionTypes().length); 176 177 method = clz.getMethod("testDocLitBare", new Class [] {java.lang.String .class}); 178 webResultAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebResult.class); 179 assertEquals("out", webResultAnno.partName()); 180 SOAPBinding soapBindingAnno = AnnotationUtil.getPrivMethodAnnotation(method, SOAPBinding.class); 181 assertEquals("BARE", soapBindingAnno.parameterStyle().toString()); 182 assertEquals("BareDocumentResponse", method.getReturnType().getSimpleName()); 183 184 185 } 186 187 public void testDocLitHolder() throws Exception { 188 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/mapping-doc-literal.wsdl")); 189 processor.setEnvironment(env); 190 processor.process(); 191 192 assertNotNull(output); 193 194 File org = new File (output, "org"); 195 assertTrue(org.exists()); 196 File objectweb = new File (org, "objectweb"); 197 assertTrue(objectweb.exists()); 198 File mapping = new File (objectweb, "mapping"); 199 assertTrue(mapping.exists()); 200 File [] files = mapping.listFiles(); 201 assertEquals(6, files.length); 202 203 Class clz = classLoader.loadClass("org.objectweb.mapping.SomethingServer"); 204 Method method = clz.getMethod("doSomething", new Class [] {int.class, javax.xml.ws.Holder.class, 205 javax.xml.ws.Holder.class}); 206 assertEquals("boolean", method.getReturnType().getSimpleName()); 207 WebParam webParamAnno = AnnotationUtil.getWebParam(method, "y"); 208 assertEquals("INOUT", webParamAnno.mode().name()); 209 webParamAnno = AnnotationUtil.getWebParam(method, "z"); 210 assertEquals("OUT", webParamAnno.mode().name()); 211 212 } 213 214 public void testSchemaImport() throws Exception { 215 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_schema_import.wsdl")); 216 processor.setEnvironment(env); 217 processor.process(); 218 219 assertNotNull(output); 220 221 File org = new File (output, "org"); 222 assertTrue(org.exists()); 223 File objectweb = new File (org, "objectweb"); 224 assertTrue(objectweb.exists()); 225 File [] files = objectweb.listFiles(); 226 assertEquals(2, files.length); 227 File helloworldsoaphttp = new File (objectweb, "hello_world_soap_http"); 228 assertTrue(helloworldsoaphttp.exists()); 229 File types = new File (helloworldsoaphttp, "types"); 230 assertTrue(types.exists()); 231 files = helloworldsoaphttp.listFiles(); 232 assertEquals(1, files.length); 233 files = types.listFiles(); 234 assertEquals(files.length, 10); 235 File schemaImport = new File (objectweb, "schema_import"); 236 assertTrue(schemaImport.exists()); 237 files = schemaImport.listFiles(); 238 assertEquals(3, files.length); 239 240 Class clz = classLoader.loadClass("org.objectweb.schema_import.Greeter"); 241 assertEquals(4, clz.getMethods().length); 242 243 Method method = clz.getMethod("pingMe", new Class [] {}); 244 assertEquals("void", method.getReturnType().getSimpleName()); 245 assertEquals("Exception class is not generated ", 1, method.getExceptionTypes().length); 246 247 } 248 249 public void testExternalJaxbBinding() throws Exception { 250 String [] args = new String []{"-d", output.getCanonicalPath(), 251 "-b", getLocation("/wsdl/hello_world_schema_import.xjb"), 252 getLocation("/wsdl/hello_world_schema_import.wsdl")}; 253 WSDLToJava.main(args); 254 255 assertNotNull(output); 256 257 File org = new File (output, "org"); 258 assertTrue(org.exists()); 259 File objectweb = new File (org, "objectweb"); 260 assertTrue(objectweb.exists()); 261 File [] files = objectweb.listFiles(); 262 assertEquals(11, files.length); 263 File schemaImport = new File (objectweb, "schema_import"); 264 assertTrue(schemaImport.exists()); 265 files = schemaImport.listFiles(); 266 assertEquals(3, files.length); 267 } 268 269 public void testExceptionNameCollision() throws Exception { 270 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/InvoiceServer.wsdl")); 271 processor.setEnvironment(env); 272 processor.process(); 273 274 assertNotNull(output); 275 276 File org = new File (output, "org"); 277 assertTrue(org.exists()); 278 File objectweb = new File (org, "objectweb"); 279 assertTrue(objectweb.exists()); 280 File invoiceserver = new File (objectweb, "invoiceserver"); 281 assertTrue(invoiceserver.exists()); 282 File invoice = new File (objectweb, "invoice"); 283 assertTrue(invoice.exists()); 284 285 File exceptionCollision = new File (invoiceserver, "NoSuchCustomerFault_Exception.java"); 286 assertTrue(exceptionCollision.exists()); 287 288 File [] files = invoiceserver.listFiles(); 289 assertEquals(12, files.length); 290 files = invoice.listFiles(); 291 assertEquals(files.length, 9); 292 293 Class clz = classLoader.loadClass("org.objectweb.invoiceserver.InvoiceServer"); 294 assertEquals(3, clz.getMethods().length); 295 296 Method method = clz.getMethod("getInvoicesForCustomer", new Class [] {String .class, String .class}); 297 assertEquals("NoSuchCustomerFault_Exception", method.getExceptionTypes()[0].getSimpleName()); 298 299 } 300 301 public void testAllNameCollision() throws Exception { 302 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_collision.wsdl")); 303 env.setPackageName("org.objectweb"); 304 processor.setEnvironment(env); 305 processor.process(); 306 307 assertNotNull(output); 308 309 File org = new File (output, "org"); 310 assertTrue(org.exists()); 311 File objectweb = new File (org, "objectweb"); 312 assertTrue(objectweb.exists()); 313 314 File [] files = objectweb.listFiles(); 315 assertEquals(13, files.length); 316 317 File typeCollision = new File (objectweb, "Greeter_Type.java"); 318 assertTrue(typeCollision.exists()); 319 File exceptionCollision = new File (objectweb, "Greeter_Exception.java"); 320 assertTrue(exceptionCollision.exists()); 321 File serviceCollision = new File (objectweb, "Greeter_Service.java"); 322 assertTrue(serviceCollision.exists()); 323 324 Class clz = classLoader.loadClass("org.objectweb.Greeter"); 325 assertTrue("SEI class Greeter modifier should be interface", clz.isInterface()); 326 327 clz = classLoader.loadClass("org.objectweb.Greeter_Exception"); 328 clz = classLoader.loadClass("org.objectweb.Greeter_Service"); 329 } 330 331 public void testHelloWorldExternalBindingFile() throws Exception { 332 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_jaxws_base.wsdl")); 333 env.put(ToolConstants.CFG_BINDING, getLocation("/wsdl/hello_world_jaxws_binding.wsdl")); 334 processor.setEnvironment(env); 335 processor.process(); 336 337 assertNotNull(output); 338 339 File org = new File (output, "org"); 340 assertTrue(org.exists()); 341 File objectweb = new File (org, "objectweb"); 342 assertTrue(objectweb.exists()); 343 344 347 Class clz = classLoader.loadClass("org.objectweb.hello_world_async_soap_http.GreeterAsync"); 348 assertEquals(3, clz.getMethods().length); 349 350 } 351 352 public void testSoapHeader() throws Exception { 353 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/soap_header.wsdl")); 354 env.setPackageName("org.objectweb"); 355 processor.setEnvironment(env); 356 processor.process(); 357 358 assertNotNull(output); 359 360 File org = new File (output, "org"); 361 assertTrue(org.exists()); 362 File objectweb = new File (org, "objectweb"); 363 assertTrue(objectweb.exists()); 364 365 File [] files = objectweb.listFiles(); 366 assertEquals(11, files.length); 367 368 Class clz = classLoader.loadClass("org.objectweb.HeaderTester"); 369 assertEquals(3, clz.getMethods().length); 370 371 SOAPBinding soapBindingAnno = AnnotationUtil.getPrivClassAnnotation(clz, SOAPBinding.class); 372 assertEquals("BARE", soapBindingAnno.parameterStyle().name()); 373 assertEquals("LITERAL", soapBindingAnno.use().name()); 374 assertEquals("DOCUMENT", soapBindingAnno.style().name()); 375 376 Class para = classLoader.loadClass("org.objectweb.InoutHeader"); 377 378 Method method = clz.getMethod("inoutHeader", new Class [] {para, Holder.class}); 379 380 soapBindingAnno = AnnotationUtil.getPrivMethodAnnotation(method, SOAPBinding.class); 381 assertEquals("BARE", soapBindingAnno.parameterStyle().name()); 382 WebParam webParamAnno = AnnotationUtil.getWebParam(method, "SOAPHeaderInfo"); 383 assertEquals("INOUT", webParamAnno.mode().name()); 384 assertEquals(true, webParamAnno.header()); 385 assertEquals("header_info", webParamAnno.partName()); 386 387 } 388 389 public void testHolderHeader() throws Exception { 390 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_holder.wsdl")); 391 processor.setEnvironment(env); 392 processor.process(); 393 394 Class clz = classLoader.loadClass("org.objectweb.hello_world_holder.Greeter"); 395 assertEquals(1, clz.getMethods().length); 396 397 SOAPBinding soapBindingAnno = AnnotationUtil.getPrivClassAnnotation(clz, SOAPBinding.class); 398 assertEquals("BARE", soapBindingAnno.parameterStyle().name()); 399 assertEquals("LITERAL", soapBindingAnno.use().name()); 400 assertEquals("DOCUMENT", soapBindingAnno.style().name()); 401 402 Class para = classLoader.loadClass("org.objectweb.hello_world_holder.types.GreetMe"); 403 Method method = clz.getMethod("sayHi", new Class [] {para, Holder.class}); 404 assertEquals("SayHi", method.getReturnType().getSimpleName()); 405 406 WebParam webParamAnno = AnnotationUtil.getWebParam(method, "greetMe"); 407 assertEquals(true, webParamAnno.header()); 408 409 webParamAnno = AnnotationUtil.getWebParam(method, "sayHi"); 410 assertEquals("INOUT", webParamAnno.mode().name()); 411 412 } 413 414 415 416 417 public void testNamespacePackageMapping1() throws Exception { 418 env.setPackageName("org.celtix"); 419 env.addNamespacePackageMap("http://objectweb.org/hello_world_soap_http/types", "org.objectweb.types"); 420 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world.wsdl")); 421 processor.setEnvironment(env); 422 processor.process(); 423 424 assertNotNull(output); 425 426 File org = new File (output, "org"); 427 assertTrue(org.exists()); 428 File objectweb = new File (org, "objectweb"); 429 assertTrue(objectweb.exists()); 430 File types = new File (objectweb, "types"); 431 assertTrue(types.exists()); 432 433 File [] files = objectweb.listFiles(); 434 assertEquals(1, files.length); 435 files = types.listFiles(); 436 assertEquals(17, files.length); 437 438 Class clz = classLoader.loadClass("org.celtix.Greeter"); 439 assertTrue("Generate " + clz.getName() + "error", clz.isInterface()); 440 clz = classLoader.loadClass("org.objectweb.types.GreetMe"); 441 } 442 443 public void testNamespacePackageMapping2() throws Exception { 444 env.setPackageName("org.celtix"); 445 env.addNamespacePackageMap("http://objectweb.org/hello_world_soap_http", "org.objectweb"); 446 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world.wsdl")); 447 processor.setEnvironment(env); 448 processor.process(); 449 450 assertNotNull(output); 451 452 File org = new File (output, "org"); 453 assertTrue(org.exists()); 454 File objectweb = new File (org, "objectweb"); 455 assertTrue(objectweb.exists()); 456 File celtix = new File (org, "celtix"); 457 assertTrue(celtix.exists()); 458 459 File [] files = objectweb.listFiles(); 460 assertEquals(5, files.length); 461 files = celtix.listFiles(); 462 assertEquals(17, files.length); 463 464 Class clz = classLoader.loadClass("org.celtix.GreetMe"); 465 assertTrue("Generate " + clz.getName() + "error", Modifier.isPublic(clz.getModifiers())); 466 clz = classLoader.loadClass("org.objectweb.Greeter"); 467 } 468 469 public void testNamespacePackageMapping3() throws Exception { 470 env.addNamespacePackageMap("http://objectweb.org/hello_world_soap_http", "org.celtix"); 471 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world.wsdl")); 472 processor.setEnvironment(env); 473 processor.process(); 474 475 assertNotNull(output); 476 477 File org = new File (output, "org"); 478 assertTrue(org.exists()); 479 File objectweb = new File (org, "objectweb"); 480 assertTrue(objectweb.exists()); 481 File helloworldsoaphttp = new File (objectweb, "hello_world_soap_http"); 482 assertTrue(helloworldsoaphttp.exists()); 483 File types = new File (helloworldsoaphttp, "types"); 484 assertTrue(types.exists()); 485 File [] files = types.listFiles(); 486 assertEquals(files.length, 17); 487 488 File celtix = new File (org, "celtix"); 489 files = celtix.listFiles(); 490 assertEquals(5, files.length); 491 492 Class clz = classLoader.loadClass("org.celtix.Greeter"); 493 assertTrue("Generate " + clz.getName() + "error", clz.isInterface()); 494 } 495 496 public void testWSAddress() throws Exception { 497 env.addNamespacePackageMap("http://objectweb.org/hello_world_soap_http", "ws.address"); 498 env.put(ToolConstants.CFG_BINDING, getLocation("/wsdl/ws_address_binding.wsdl")); 499 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_addr.wsdl")); 500 processor.setEnvironment(env); 501 processor.process(); 502 503 assertNotNull(output); 504 505 File ws = new File (output, "ws"); 506 assertTrue(ws.exists()); 507 File address = new File (ws, "address"); 508 assertTrue(address.exists()); 509 510 File [] files = address.listFiles(); 511 assertEquals(4, files.length); 512 File handlerConfig = new File (address, "Greeter_handler.xml"); 513 assertTrue(handlerConfig.exists()); 514 515 Class clz = classLoader.loadClass("ws.address.Greeter"); 516 HandlerChain handlerChainAnno = AnnotationUtil.getPrivClassAnnotation(clz, HandlerChain.class); 517 assertEquals("Greeter_handler.xml", handlerChainAnno.file()); 518 assertNotNull("Handler chain xml generate fail!", classLoader 519 .findResource("ws/address/Greeter_handler.xml")); 520 } 521 522 public void testSupportXMLBindingBare() throws Exception { 523 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/xml_http_bare.wsdl")); 524 processor.setEnvironment(env); 525 processor.process(); 526 527 } 528 529 public void testSupportXMLBindingWrapped() throws Exception { 530 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/xml_http_wrapped.wsdl")); 531 processor.setEnvironment(env); 532 processor.process(); 533 } 534 535 public void testRouterWSDL() throws Exception { 536 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/router.wsdl")); 537 processor.setEnvironment(env); 538 processor.process(); 539 } 540 541 542 543 544 public void testExcludeNSWithPackageName() throws Exception { 545 546 String [] args = new String []{"-d", output.getCanonicalPath(), 547 "-nexclude", 548 "http://objectweb.org/test/types=com.iona", 549 "-nexclude", 550 "http://objectweb.org/Invoice", 551 getLocation("/wsdl/hello_world_exclude.wsdl")}; 552 WSDLToJava.main(args); 553 554 assertNotNull(output); 555 File com = new File (output, "com"); 556 assertTrue(com.exists()); 557 File iona = new File (com, "iona"); 558 assertTrue(iona.exists()); 559 File [] files = iona.listFiles(); 560 assertEquals(17, files.length); 561 562 File org = new File (output, "org"); 563 File objectweb = new File (org, "objectweb"); 564 File invoice = new File (objectweb, "Invoice"); 565 assertTrue(!invoice.exists()); 566 567 } 568 569 public void testExcludeNSWithoutPackageName() throws Exception { 570 571 String [] args = new String []{"-d", output.getCanonicalPath(), 572 "-nexclude", 573 "http://objectweb.org/test/types", 574 getLocation("/wsdl/hello_world_exclude.wsdl")}; 575 WSDLToJava.main(args); 576 577 assertNotNull(output); 578 File com = new File (output, "test"); 579 assertTrue(!com.exists()); 580 581 } 582 583 584 public void testCommandLine() throws Exception { 585 String [] args = new String []{"-compile", "-d", output.getCanonicalPath(), 586 "-classdir", output.getCanonicalPath() + "/classes", 587 "-p", 588 "org.celtix", 589 "-p", 590 "http://objectweb.org/hello_world_soap_http/types=org.objectweb.types", 591 "-client", 592 "-server", 593 "-impl", 594 getLocation("/wsdl/hello_world.wsdl")}; 595 WSDLToJava.main(args); 596 597 Class clz = classLoader.loadClass("org.celtix.Greeter"); 598 assertTrue("Generate " + clz.getName() + "error", clz.isInterface()); 599 clz = classLoader.loadClass("org.objectweb.types.GreetMe"); 600 } 601 602 603 public void testDefaultLoadNSMappingOFF() throws Exception { 604 String [] args = new String []{"-dns", "false", 605 "-d", output.getCanonicalPath(), 606 getLocation("/wsdl/basic_callback.wsdl")}; 607 608 WSDLToJava.main(args); 609 610 assertNotNull(output); 611 File org = new File (output, "org"); 612 assertTrue(org.exists()); 613 File w3 = new File (org, "w3"); 614 assertTrue(w3.exists()); 615 File p2005 = new File (w3, "_2005"); 616 assertTrue(p2005.exists()); 617 File p08 = new File (p2005, "_08"); 618 assertTrue(p08.exists()); 619 File address = new File (p08, "addressing"); 620 assertTrue(address.exists()); 621 622 File [] files = address.listFiles(); 623 assertEquals(11, files.length); 624 } 625 626 public void testDefaultLoadNSMappingON() throws Exception { 627 String [] args = new String []{"-d", output.getCanonicalPath(), 628 getLocation("/wsdl/basic_callback.wsdl")}; 629 630 WSDLToJava.main(args); 631 632 assertNotNull(output); 633 File org = new File (output, "org"); 634 assertTrue(org.exists()); 635 File objectweb = new File (org, "objectweb"); 636 assertTrue(objectweb.exists()); 637 File celtix = new File (objectweb, "celtix"); 638 assertTrue(celtix.exists()); 639 File ws = new File (celtix, "ws"); 640 assertTrue(ws.exists()); 641 File address = new File (ws, "addressing"); 642 assertTrue(address.exists()); 643 644 File [] files = address.listFiles(); 645 assertEquals(11, files.length); 646 } 647 648 public void testWithNoService() throws Exception { 649 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/helloworld-noservice.wsdl")); 650 processor.setEnvironment(env); 651 processor.process(); 652 Class clz = classLoader.loadClass("org.apache.tuscany.samples.helloworldaxis.HelloWorldServiceImpl"); 653 Method method = clz.getMethod("getGreetings", new Class [] {java.lang.String .class}); 654 WebResult webResultAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebResult.class); 655 assertEquals("http://helloworldaxis.samples.tuscany.apache.org", webResultAnno.targetNamespace()); 656 assertEquals("response", webResultAnno.partName()); 657 assertEquals("getGreetingsResponse", webResultAnno.name()); 658 659 WebParam webParamAnno = AnnotationUtil.getWebParam(method, "getGreetings"); 660 assertEquals("http://helloworldaxis.samples.tuscany.apache.org", webParamAnno.targetNamespace()); 661 assertEquals("request", webParamAnno.partName()); 662 assertEquals("getGreetings", webParamAnno.name()); 663 664 } 665 666 667 public void testWithNoBinding() throws Exception { 668 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/helloworld-nobinding.wsdl")); 669 processor.setEnvironment(env); 670 processor.process(); 671 Class clz = classLoader.loadClass("org.apache.tuscany.samples.helloworldaxis.HelloWorldServiceImpl"); 672 673 SOAPBinding soapBindingAnno = AnnotationUtil.getPrivClassAnnotation(clz, SOAPBinding.class); 674 assertNull("SOAPBinding Annotation should be null", soapBindingAnno); 675 676 677 Method method = clz.getMethod("getGreetings", new Class [] {java.lang.String .class}); 678 WebResult webResultAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebResult.class); 679 assertEquals("http://helloworldaxis.samples.tuscany.apache.org", webResultAnno.targetNamespace()); 680 assertEquals("", webResultAnno.partName()); 681 assertEquals("return", webResultAnno.name()); 682 683 WebParam webParamAnno = AnnotationUtil.getWebParam(method, "request"); 684 assertNotNull("WebParam should be annotated", webParamAnno); 685 686 687 } 688 689 690 691 692 693 private String getLocation(String wsdlFile) { 694 return WSDLToJavaProcessorTest.class.getResource(wsdlFile).getFile(); 695 } 696 697 } 698 | Popular Tags |