001: package org.objectweb.celtix.tools.processors.java2;
002:
003: import java.io.File;
004:
005: import javax.wsdl.Definition;
006: import javax.wsdl.Service;
007: import javax.xml.namespace.QName;
008:
009: import org.objectweb.celtix.helpers.WSDLHelper;
010: import org.objectweb.celtix.tools.common.ToolConstants;
011: import org.objectweb.celtix.tools.processors.ProcessorTestBase;
012: import org.objectweb.celtix.tools.processors.wsdl2.WSDLToJavaProcessor;
013:
014: public class JavaToWSDLProcessorTest extends ProcessorTestBase {
015:
016: private JavaToWSDLProcessor j2wProcessor;
017: private WSDLToJavaProcessor wj2Processor;
018: private String tns = "org.objectweb.asyn_lit";
019: private String serviceName = "celtixService";
020: private WSDLHelper wsdlHelper = new WSDLHelper();
021: private File classFile;
022:
023: public void setUp() throws Exception {
024: super .setUp();
025: wj2Processor = new WSDLToJavaProcessor();
026: j2wProcessor = new JavaToWSDLProcessor();
027: classFile = new java.io.File(output.getCanonicalPath()
028: + "/classes");
029: classFile.mkdir();
030: System.setProperty("java.class.path", getClassPath()
031: + classFile.getCanonicalPath() + File.separatorChar);
032: }
033:
034: public void tearDown() {
035: super .tearDown();
036: j2wProcessor = null;
037: wj2Processor = null;
038: }
039:
040: public void testAsyn() throws Exception {
041:
042: env.put(ToolConstants.CFG_COMPILE, "compile");
043: env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
044: env.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath()
045: + "/classes");
046: env.put(ToolConstants.CFG_WSDLURL,
047: getLocation("/wsdl/hello_world_async.wsdl"));
048: wj2Processor.setEnvironment(env);
049: wj2Processor.process();
050:
051: env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath()
052: + "/asyn.wsdl");
053: env
054: .put(ToolConstants.CFG_CLASSNAME,
055: "org.objectweb.hello_world_async_soap_http.GreeterAsync");
056: env.put(ToolConstants.CFG_TNS, tns);
057: env.put(ToolConstants.CFG_SERVICENAME, serviceName);
058: j2wProcessor.setEnvironment(env);
059: j2wProcessor.process();
060:
061: File wsdlFile = new File(output, "asyn.wsdl");
062: assertTrue("Fail to generate wsdl file", wsdlFile.exists());
063:
064: Definition def = wsdlHelper.getDefinition(wsdlFile);
065: Service wsdlService = def
066: .getService(new QName(tns, serviceName));
067: assertNotNull("Generate WSDL Service Error", wsdlService);
068:
069: File schemaFile = new File(output, "schema1.xsd");
070: assertTrue("Fail to generate schema file", schemaFile.exists());
071:
072: }
073:
074: public void testDocWrapparBare() throws Exception {
075: env.put(ToolConstants.CFG_COMPILE, "compile");
076: env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
077: env.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath()
078: + "/classes");
079: env.put(ToolConstants.CFG_WSDLURL,
080: getLocation("/wsdl/hello_world_doc_wrapped_bare.wsdl"));
081: wj2Processor.setEnvironment(env);
082: wj2Processor.process();
083:
084: env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath()
085: + "/doc_wrapped_bare.wsdl");
086: env.put(ToolConstants.CFG_CLASSNAME,
087: "org.objectweb.hello_world_doc_wrapped_bare.Greeter");
088: env.put(ToolConstants.CFG_TNS, tns);
089: env.put(ToolConstants.CFG_SERVICENAME, serviceName);
090: j2wProcessor.setEnvironment(env);
091: j2wProcessor.process();
092:
093: File wsdlFile = new File(output, "doc_wrapped_bare.wsdl");
094: assertTrue("Fail to generate wsdl file", wsdlFile.exists());
095:
096: Definition def = wsdlHelper.getDefinition(wsdlFile);
097: Service wsdlService = def
098: .getService(new QName(tns, serviceName));
099: assertNotNull("Generate WSDL Service Error", wsdlService);
100:
101: File schemaFile = new File(output, "schema1.xsd");
102: assertTrue("Fail to generate schema file", schemaFile.exists());
103:
104: }
105:
106: public void testDocLitUseClassPathFlag() throws Exception {
107: env.put(ToolConstants.CFG_COMPILE, "compile");
108: env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
109: env.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath()
110: + "/classes");
111: env.put(ToolConstants.CFG_WSDLURL,
112: getLocation("/wsdl/hello_world_doc_lit.wsdl"));
113: wj2Processor.setEnvironment(env);
114: wj2Processor.process();
115:
116: System.setProperty("java.class.path", "");
117: env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath()
118: + "/doc_lit.wsdl");
119: env.put(ToolConstants.CFG_CLASSNAME,
120: "org.objectweb.hello_world_doc_lit.Greeter");
121: env.put(ToolConstants.CFG_TNS, tns);
122: env.put(ToolConstants.CFG_CLASSPATH, classFile
123: .getCanonicalPath());
124: env.put(ToolConstants.CFG_SERVICENAME, serviceName);
125: j2wProcessor.setEnvironment(env);
126: j2wProcessor.process();
127: File wsdlFile = new File(output, "doc_lit.wsdl");
128: assertTrue("Generate Wsdl Fail", wsdlFile.exists());
129:
130: Definition def = wsdlHelper.getDefinition(wsdlFile);
131: Service wsdlService = def
132: .getService(new QName(tns, serviceName));
133: assertNotNull("Generate WSDL Service Error", wsdlService);
134:
135: File schemaFile = new File(output, "schema1.xsd");
136: assertTrue("Generate schema file Fail", schemaFile.exists());
137:
138: }
139:
140: public void testRPCLit() throws Exception {
141: env.put(ToolConstants.CFG_COMPILE, "compile");
142: env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
143: env.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath()
144: + "/classes");
145: env.put(ToolConstants.CFG_WSDLURL,
146: getLocation("/wsdl/hello_world_rpc_lit.wsdl"));
147: wj2Processor.setEnvironment(env);
148: wj2Processor.process();
149:
150: env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath()
151: + "/rpc_lit.wsdl");
152: env.put(ToolConstants.CFG_CLASSNAME,
153: "org.objectweb.hello_world_rpclit.GreeterRPCLit");
154: env.put(ToolConstants.CFG_TNS, tns);
155: env.put(ToolConstants.CFG_SERVICENAME, serviceName);
156:
157: j2wProcessor.setEnvironment(env);
158: j2wProcessor.process();
159: File wsdlFile = new File(output, "rpc_lit.wsdl");
160: assertTrue(wsdlFile.exists());
161:
162: Definition def = wsdlHelper.getDefinition(wsdlFile);
163: Service wsdlService = def
164: .getService(new QName(tns, serviceName));
165: assertNotNull("Generate WSDL Service Error", wsdlService);
166:
167: File schemaFile = new File(output, "schema1.xsd");
168: assertTrue(schemaFile.exists());
169: File schemaFile2 = new File(output, "schema2.xsd");
170: assertTrue(schemaFile2.exists());
171: }
172:
173: private String getLocation(String wsdlFile) {
174: return JavaToWSDLProcessorTest.class.getResource(wsdlFile)
175: .getFile();
176: }
177:
178: }
|