Modified: incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java?view=diff&rev=533699&r1=533698&r2=533699 ============================================================================== --- incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java (original) +++ incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java Mon Apr 30 04:29:53 2007 @@ -20,7 +20,6 @@ package org.apache.cxf.tools.java2wsdl.processor; import java.io.File; -import java.io.FileInputStream; import javax.wsdl.Definition; import javax.wsdl.Port; @@ -31,7 +30,6 @@ import org.apache.cxf.binding.soap.Soap11; import org.apache.cxf.binding.soap.Soap12; import org.apache.cxf.binding.soap.SoapBindingConfiguration; -import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.helpers.WSDLHelper; import org.apache.cxf.tools.common.ProcessorTestBase; import org.apache.cxf.tools.common.ToolConstants; @@ -43,7 +41,6 @@ import org.apache.cxf.tools.wsdlto.core.PluginLoader; import org.apache.cxf.tools.wsdlto.frontend.jaxws.JAXWSContainer; import org.junit.After; -import org.junit.Ignore; import org.junit.Test; public class JavaToProcessorTest extends ProcessorTestBase { @@ -273,49 +270,5 @@ File responseWrapperClass = new File(output, pkgBase + "/AddResponse.java"); assertTrue(requestWrapperClass.exists()); assertTrue(responseWrapperClass.exists()); - } - - @Test - @Ignore - public void testGenWrapperInAnotherPackage() throws Exception { - env.put(ToolConstants.CFG_CLASSNAME, - "org.apache.cxf.tools.fortest.withannotation.doc.GreeterNoWrapperBean"); - env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/my_greeter_no_wrapper.wsdl"); - - processor.setEnvironment(env); - processor.process(); - - String pkgBase = "org/apache/cxf"; - File requestWrapperClass = new File(output, pkgBase + "/SayHi.java"); - File responseWrapperClass = new File(output, pkgBase + "/SayHiResponse.java"); - assertTrue(requestWrapperClass.exists()); - assertTrue(responseWrapperClass.exists()); - - responseWrapperClass = new File(output, pkgBase + "/EchoDataBeanResponse.java"); - assertTrue(requestWrapperClass.exists()); - //The EchoDataBeanResponse object NEEDS to import the TestDataBean. Thus, the - //package string should be in there someplace. - String contents = IOUtils.toString(new FileInputStream(responseWrapperClass)); - assertTrue(contents.indexOf("org.apache.cxf.tools.fortest.withannotation.doc") != -1); - } - - // REVISIT: CXF-610 - // Ref: DOC-LIT-WRAPPED this.testDataBase() - // RPC-LIT JaxwsServiceBuilderRPCTest.testGreeter() - @Test - @Ignore - public void testGenWrapperWithStringArray() throws Exception { - env.put(ToolConstants.CFG_CLASSNAME, - "org.apache.cxf.tools.fortest.withannotation.doc.GreeterStringArray"); - env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/my_greeter_string_array.wsdl"); - - processor.setEnvironment(env); - processor.process(); - - String pkgBase = "org/apache/cxf/tools/fortest/withannotation/doc/jaxws"; - File requestWrapperClass = new File(output, pkgBase + "/SayHi.java"); - File responseWrapperClass = new File(output, pkgBase + "/SayHiResponse.java"); - assertTrue(requestWrapperClass.exists()); - assertTrue(responseWrapperClass.exists()); } }
Added: incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapperTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapperTest.java?view=auto&rev=533699 ============================================================================== --- incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapperTest.java (added) +++ incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapperTest.java Mon Apr 30 04:29:53 2007 @@ -0,0 +1,165 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.tools.java2wsdl.processor.internal.jaxws; + +import java.lang.reflect.Method; +import java.util.List; + +import junit.framework.TestCase; +import org.apache.cxf.service.model.MessageInfo; +import org.apache.cxf.service.model.OperationInfo; +import org.apache.cxf.service.model.ServiceInfo; +import org.apache.cxf.tools.common.model.JavaClass; +import org.apache.cxf.tools.common.model.JavaField; +import org.apache.cxf.tools.common.model.JavaMethod; +import org.junit.Test; + +public class RequestWrapperTest extends TestCase { + JaxwsServiceBuilder builder = new JaxwsServiceBuilder(); + + private OperationInfo getOperation(Class clz, String opName) { + builder.setServiceClass(clz); + ServiceInfo serviceInfo = builder.build(); + + for (OperationInfo op : serviceInfo.getInterface().getOperations()) { + if (op.getUnwrappedOperation() != null + && op.hasInput() && opName.equals(op.getName().getLocalPart())) { + return op; + } + } + return null; + } + + @Test + public void testBuildRequestFields() { + // Test String[] + Class testingClass = org.apache.cxf.tools.fortest.withannotation.doc.GreeterArray.class; + OperationInfo opInfo = getOperation(testingClass, "sayStringArray"); + assertNotNull(opInfo); + + RequestWrapper requestWrapper = new RequestWrapper(); + + MessageInfo message = opInfo.getUnwrappedOperation().getInput(); + Method method = (Method)opInfo.getProperty("operation.method"); + + List<JavaField> fields = requestWrapper.buildFields(method, message); + assertEquals(1, fields.size()); + JavaField field = fields.get(0); + assertEquals("arg0", field.getName()); + assertEquals("String[]", field.getType()); + + // Test int[] + + opInfo = getOperation(testingClass, "sayIntArray"); + assertNotNull(opInfo); + + message = opInfo.getUnwrappedOperation().getInput(); + method = (Method) opInfo.getProperty("operation.method"); + + fields = requestWrapper.buildFields(method, message); + assertEquals(1, fields.size()); + field = fields.get(0); + assertEquals("arg0", field.getName()); + assertEquals("int[]", field.getType()); + + // Test TestDataBean[] + + opInfo = getOperation(testingClass, "sayTestDataBeanArray"); + assertNotNull(opInfo); + + message = opInfo.getUnwrappedOperation().getInput(); + method = (Method) opInfo.getProperty("operation.method"); + + fields = requestWrapper.buildFields(method, message); + assertEquals(1, fields.size()); + field = fields.get(0); + assertEquals("arg0", field.getName()); + assertEquals("org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean[]", field.getType()); + } + + @Test + public void testNoAnnotationNoClass() throws Exception { + String pkgName = "org.apache.cxf.tools.fortest.classnoanno.docwrapped"; + Class testingClass = Class.forName(pkgName + ".Stock"); + + OperationInfo opInfo = getOperation(testingClass, "getPrice"); + Wrapper wrapper = new RequestWrapper(); + wrapper.setOperationInfo(opInfo); + + assertTrue(wrapper.isWrapperAbsent()); + assertTrue(wrapper.isToDifferentPackage()); + assertFalse(wrapper.isWrapperBeanClassNotExist()); + assertEquals(pkgName + ".jaxws", wrapper.getJavaClass().getPackageName()); + assertEquals("GetPrice", wrapper.getJavaClass().getName()); + + JavaClass jClass = wrapper.buildWrapperBeanClass(); + assertNotNull(jClass); + List<JavaField> jFields = jClass.getFields(); + + assertEquals(1, jFields.size()); + assertEquals("arg0", jFields.get(0).getName()); + assertEquals("java.lang.String", jFields.get(0).getClassName()); + + List<JavaMethod> jMethods = jClass.getMethods(); + assertEquals(2, jMethods.size()); + + JavaMethod jMethod = jMethods.get(0); + assertEquals("getArg0", jMethod.getName()); + assertTrue(jMethod.getParameterListWithoutAnnotation().isEmpty()); + + jMethod = jMethods.get(1); + assertEquals("setArg0", jMethod.getName()); + assertEquals(1, jMethod.getParameterListWithoutAnnotation().size()); + assertEquals("java.lang.String newArg0", jMethod.getParameterListWithoutAnnotation().get(0)); + } + + @Test + public void testWithAnnotationNoClass() throws Exception { + String pkgName = "org.apache.cxf.tools.fortest.withannotation.doc"; + Class testingClass = Class.forName(pkgName + ".Stock"); + + OperationInfo opInfo = getOperation(testingClass, "getPrice"); + Wrapper wrapper = new RequestWrapper(); + wrapper.setOperationInfo(opInfo); + + assertFalse(wrapper.isWrapperAbsent()); + assertTrue(wrapper.isToDifferentPackage()); + assertFalse(wrapper.isWrapperBeanClassNotExist()); + assertEquals(pkgName + ".jaxws", wrapper.getJavaClass().getPackageName()); + assertEquals("GetPrice", wrapper.getJavaClass().getName()); + } + + @Test + public void testWithAnnotationWithClass() throws Exception { + String pkgName = "org.apache.cxf.tools.fortest.withannotation.doc"; + Class testingClass = Class.forName(pkgName + ".Greeter"); + + OperationInfo opInfo = getOperation(testingClass, "sayHi"); + + Wrapper wrapper = new RequestWrapper(); + wrapper.setOperationInfo(opInfo); + + assertFalse(wrapper.isWrapperAbsent()); + assertTrue(wrapper.isToDifferentPackage()); + assertFalse(wrapper.isWrapperBeanClassNotExist()); + assertEquals(pkgName, wrapper.getJavaClass().getPackageName()); + assertEquals("SayHi", wrapper.getJavaClass().getName()); + } +} Added: incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapperTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapperTest.java?view=auto&rev=533699 ============================================================================== --- incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapperTest.java (added) +++ incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapperTest.java Mon Apr 30 04:29:53 2007 @@ -0,0 +1,101 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.tools.java2wsdl.processor.internal.jaxws; + +import java.lang.reflect.Method; + +import junit.framework.TestCase; +import org.apache.cxf.service.model.MessageInfo; +import org.apache.cxf.service.model.OperationInfo; +import org.apache.cxf.service.model.ServiceInfo; +import org.apache.cxf.tools.common.model.JavaField; +import org.junit.Test; + +public class ResponseWrapperTest extends TestCase { + JaxwsServiceBuilder builder = new JaxwsServiceBuilder(); + + private OperationInfo getOperation(Class clz, String opName) { + builder.setServiceClass(clz); + ServiceInfo serviceInfo = builder.build(); + + for (OperationInfo op : serviceInfo.getInterface().getOperations()) { + if (op.getUnwrappedOperation() != null + && op.hasInput() && opName.equals(op.getName().getLocalPart())) { + return op; + } + } + return null; + } + + @Test + public void testBuildFields() { + // Test String[] + Class testingClass = org.apache.cxf.tools.fortest.withannotation.doc.GreeterArray.class; + OperationInfo opInfo = getOperation(testingClass, "sayStringArray"); + assertNotNull(opInfo); + + ResponseWrapper responseWrapper = new ResponseWrapper(); + + MessageInfo message = opInfo.getUnwrappedOperation().getOutput(); + Method method = (Method)opInfo.getProperty("operation.method"); + + JavaField field = responseWrapper.buildFields(method, message).get(0); + assertEquals("_return", field.getName()); + assertEquals("String[]", field.getType()); + + // Test int[] + + opInfo = getOperation(testingClass, "sayIntArray"); + assertNotNull(opInfo); + + message = opInfo.getUnwrappedOperation().getOutput(); + method = (Method) opInfo.getProperty("operation.method"); + + field = responseWrapper.buildFields(method, message).get(0); + assertEquals("_return", field.getName()); + assertEquals("int[]", field.getType()); + + // Test TestDataBean[] + + opInfo = getOperation(testingClass, "sayTestDataBeanArray"); + assertNotNull(opInfo); + + message = opInfo.getUnwrappedOperation().getOutput(); + method = (Method) opInfo.getProperty("operation.method"); + + field = responseWrapper.buildFields(method, message).get(0); + assertEquals("_return", field.getName()); + assertEquals("org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean[]", field.getType()); + } + + @Test + public void testWithAnnotationWithClass() throws Exception { + String pkgName = "org.apache.cxf.tools.fortest.withannotation.doc"; + Class testingClass = Class.forName(pkgName + ".Greeter"); + + OperationInfo opInfo = getOperation(testingClass, "sayHi"); + + Wrapper wrapper = new ResponseWrapper(); + wrapper.setOperationInfo(opInfo); + assertEquals(pkgName, wrapper.getJavaClass().getPackageName()); + assertEquals("SayHiResponse", wrapper.getJavaClass().getName()); + + } +}
