1 package org.objectweb.celtix.tools.processors.java2; 2 3 import java.io.File ; 4 5 import javax.wsdl.Definition; 6 import javax.wsdl.Service; 7 import javax.xml.namespace.QName ; 8 9 import org.objectweb.celtix.helpers.WSDLHelper; 10 import org.objectweb.celtix.tools.common.ToolConstants; 11 import org.objectweb.celtix.tools.processors.ProcessorTestBase; 12 import org.objectweb.celtix.tools.processors.wsdl2.WSDLToJavaProcessor; 13 14 public class JavaToWSDLProcessorTest extends ProcessorTestBase { 15 16 private JavaToWSDLProcessor j2wProcessor; 17 private WSDLToJavaProcessor wj2Processor; 18 private String tns = "org.objectweb.asyn_lit"; 19 private String serviceName = "celtixService"; 20 private WSDLHelper wsdlHelper = new WSDLHelper(); 21 private File classFile; 22 23 public void setUp() throws Exception { 24 super.setUp(); 25 wj2Processor = new WSDLToJavaProcessor(); 26 j2wProcessor = new JavaToWSDLProcessor(); 27 classFile = new java.io.File (output.getCanonicalPath() + "/classes"); 28 classFile.mkdir(); 29 System.setProperty("java.class.path", getClassPath() + classFile.getCanonicalPath() 30 + File.separatorChar); 31 } 32 33 public void tearDown() { 34 super.tearDown(); 35 j2wProcessor = null; 36 wj2Processor = null; 37 } 38 39 public void testAsyn() throws Exception { 40 41 env.put(ToolConstants.CFG_COMPILE, "compile"); 42 env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath()); 43 env.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath() + "/classes"); 44 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_async.wsdl")); 45 wj2Processor.setEnvironment(env); 46 wj2Processor.process(); 47 48 49 env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/asyn.wsdl"); 50 env.put(ToolConstants.CFG_CLASSNAME, "org.objectweb.hello_world_async_soap_http.GreeterAsync"); 51 env.put(ToolConstants.CFG_TNS, tns); 52 env.put(ToolConstants.CFG_SERVICENAME, serviceName); 53 j2wProcessor.setEnvironment(env); 54 j2wProcessor.process(); 55 56 File wsdlFile = new File (output, "asyn.wsdl"); 57 assertTrue("Fail to generate wsdl file", wsdlFile.exists()); 58 59 Definition def = wsdlHelper.getDefinition(wsdlFile); 60 Service wsdlService = def.getService(new QName (tns, serviceName)); 61 assertNotNull("Generate WSDL Service Error", wsdlService); 62 63 File schemaFile = new File (output, "schema1.xsd"); 64 assertTrue("Fail to generate schema file", schemaFile.exists()); 65 66 } 67 68 public void testDocWrapparBare() throws Exception { 69 env.put(ToolConstants.CFG_COMPILE, "compile"); 70 env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath()); 71 env.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath() + "/classes"); 72 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_doc_wrapped_bare.wsdl")); 73 wj2Processor.setEnvironment(env); 74 wj2Processor.process(); 75 76 77 env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/doc_wrapped_bare.wsdl"); 78 env.put(ToolConstants.CFG_CLASSNAME, "org.objectweb.hello_world_doc_wrapped_bare.Greeter"); 79 env.put(ToolConstants.CFG_TNS, tns); 80 env.put(ToolConstants.CFG_SERVICENAME, serviceName); 81 j2wProcessor.setEnvironment(env); 82 j2wProcessor.process(); 83 84 File wsdlFile = new File (output, "doc_wrapped_bare.wsdl"); 85 assertTrue("Fail to generate wsdl file", wsdlFile.exists()); 86 87 Definition def = wsdlHelper.getDefinition(wsdlFile); 88 Service wsdlService = def.getService(new QName (tns, serviceName)); 89 assertNotNull("Generate WSDL Service Error", wsdlService); 90 91 File schemaFile = new File (output, "schema1.xsd"); 92 assertTrue("Fail to generate schema file", schemaFile.exists()); 93 94 } 95 96 97 public void testDocLitUseClassPathFlag() throws Exception { 98 env.put(ToolConstants.CFG_COMPILE, "compile"); 99 env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath()); 100 env.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath() + "/classes"); 101 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_doc_lit.wsdl")); 102 wj2Processor.setEnvironment(env); 103 wj2Processor.process(); 104 105 System.setProperty("java.class.path", ""); 106 env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/doc_lit.wsdl"); 107 env.put(ToolConstants.CFG_CLASSNAME, "org.objectweb.hello_world_doc_lit.Greeter"); 108 env.put(ToolConstants.CFG_TNS, tns); 109 env.put(ToolConstants.CFG_CLASSPATH, classFile.getCanonicalPath()); 110 env.put(ToolConstants.CFG_SERVICENAME, serviceName); 111 j2wProcessor.setEnvironment(env); 112 j2wProcessor.process(); 113 File wsdlFile = new File (output, "doc_lit.wsdl"); 114 assertTrue("Generate Wsdl Fail", wsdlFile.exists()); 115 116 Definition def = wsdlHelper.getDefinition(wsdlFile); 117 Service wsdlService = def.getService(new QName (tns, serviceName)); 118 assertNotNull("Generate WSDL Service Error", wsdlService); 119 120 File schemaFile = new File (output, "schema1.xsd"); 121 assertTrue("Generate schema file Fail", schemaFile.exists()); 122 123 } 124 125 public void testRPCLit() throws Exception { 126 env.put(ToolConstants.CFG_COMPILE, "compile"); 127 env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath()); 128 env.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath() + "/classes"); 129 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_rpc_lit.wsdl")); 130 wj2Processor.setEnvironment(env); 131 wj2Processor.process(); 132 133 env.put(ToolConstants.CFG_OUTPUTFILE, 134 output.getPath() + "/rpc_lit.wsdl"); 135 env.put(ToolConstants.CFG_CLASSNAME, "org.objectweb.hello_world_rpclit.GreeterRPCLit"); 136 env.put(ToolConstants.CFG_TNS, tns); 137 env.put(ToolConstants.CFG_SERVICENAME, serviceName); 138 139 j2wProcessor.setEnvironment(env); 140 j2wProcessor.process(); 141 File wsdlFile = new File (output, "rpc_lit.wsdl"); 142 assertTrue(wsdlFile.exists()); 143 144 Definition def = wsdlHelper.getDefinition(wsdlFile); 145 Service wsdlService = def.getService(new QName (tns, serviceName)); 146 assertNotNull("Generate WSDL Service Error", wsdlService); 147 148 149 File schemaFile = new File (output, "schema1.xsd"); 150 assertTrue(schemaFile.exists()); 151 File schemaFile2 = new File (output, "schema2.xsd"); 152 assertTrue(schemaFile2.exists()); 153 } 154 155 156 private String getLocation(String wsdlFile) { 157 return JavaToWSDLProcessorTest.class.getResource(wsdlFile).getFile(); 158 } 159 160 } 161 | Popular Tags |