From e31385693322b1833882f383785b461a53e7617f Mon Sep 17 00:00:00 2001 From: nash Date: Fri, 3 Dec 2010 20:50:18 +0000 Subject: Refactor into framework and separate test cases, and add more tests git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1041987 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/wsdlgen/verify/DataTypes.java | 20 ++ .../java/wsdlgen/verify/impl/DataTypesImpl.java | 24 ++ .../src/main/resources/DataTypes.composite | 7 + .../src/main/resources/dynamic-sdo.composite | 31 --- .../test/java/wsdlgen/verify/BaseFramework.java | 252 +++++++++++++++++++ .../java/wsdlgen/verify/DataTypesTestCase.java | 271 +++++---------------- .../java/wsdlgen/verify/DynamicSDOTestCase.java | 173 ++++--------- 7 files changed, 399 insertions(+), 379 deletions(-) delete mode 100644 sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/resources/dynamic-sdo.composite create mode 100644 sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/BaseFramework.java (limited to 'sca-java-1.x/trunk/itest/wsdlgen-verify/src') diff --git a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/DataTypes.java b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/DataTypes.java index f3d689e725..aa6ffc6ecb 100644 --- a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/DataTypes.java +++ b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/DataTypes.java @@ -20,6 +20,8 @@ package wsdlgen.verify; import java.util.List; +import javax.jws.WebParam; +import javax.jws.soap.SOAPBinding; import commonj.sdo.DataObject; import org.osoa.sca.annotations.Remotable; @@ -30,8 +32,18 @@ public interface DataTypes { void testSimpleArrayInt(int[] simple); + void testSimpleMultiArrayInt(int[][] simple); + + void testList(List any); + void testSimpleListString(List simple); + List testReturnSimpleListString(); + + void testListByteArray(List byteArrayList); + + void testListWildcard(List wild); + void testComplex(ComplexNumber complex); void testByteArray(byte[] byteArray); @@ -39,4 +51,12 @@ public interface DataTypes { void testException() throws Exception; DataObject testDynamicSDO(); + +/* + @SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.BARE) + void testWebParam(@WebParam(name="simpleInt") int simple); + + @SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.BARE) + void testWebParamArray(@WebParam(name="arrayInt") int[] array); +*/ } diff --git a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/impl/DataTypesImpl.java b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/impl/DataTypesImpl.java index 71fc96cfc3..5cf85d1b54 100644 --- a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/impl/DataTypesImpl.java +++ b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/impl/DataTypesImpl.java @@ -20,6 +20,8 @@ package wsdlgen.verify.impl; import java.util.List; +import javax.jws.WebParam; +import javax.jws.soap.SOAPBinding; import commonj.sdo.DataObject; import wsdlgen.verify.ComplexNumber; import wsdlgen.verify.DataTypes; @@ -32,9 +34,25 @@ public class DataTypesImpl implements DataTypes { public void testSimpleArrayInt(int[] simple) { } + public void testSimpleMultiArrayInt(int[][] simple) { + } + + public void testList(List any) { + } + public void testSimpleListString(List simple) { } + public List testReturnSimpleListString() { + return null; + } + + public void testListByteArray(List byteArrayList) { + } + + public void testListWildcard(List wild) { + } + public void testComplex(ComplexNumber complex) { } @@ -47,4 +65,10 @@ public class DataTypesImpl implements DataTypes { public DataObject testDynamicSDO() { return null; } + + public void testWebParam(int simple) { + } + + public void testWebParamArray(int[] array) { + } } diff --git a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/resources/DataTypes.composite b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/resources/DataTypes.composite index a88d276036..f42c492b2d 100644 --- a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/resources/DataTypes.composite +++ b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/resources/DataTypes.composite @@ -28,4 +28,11 @@ + + + + + + + diff --git a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/resources/dynamic-sdo.composite b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/resources/dynamic-sdo.composite deleted file mode 100644 index 4dd25b46d3..0000000000 --- a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/main/resources/dynamic-sdo.composite +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - diff --git a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/BaseFramework.java b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/BaseFramework.java new file mode 100644 index 0000000000..5c45d93827 --- /dev/null +++ b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/BaseFramework.java @@ -0,0 +1,252 @@ +/* + * 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 wsdlgen.verify; + +import java.util.HashMap; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.schema.Schema; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.tuscany.sca.binding.ws.wsdlgen.WSDLServiceGenerator; +import static org.junit.Assert.assertNotNull; + +import org.w3c.dom.Attr; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Test ?wsdl works and that the returned WSDL is correct + * + * @version $Rev: 814373 $ $Date: 2009-09-13 19:06:29 +0100 (Sun, 13 Sep 2009) $ + */ +public class BaseFramework { + private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; + private static final String SCHEMA_NAME = "schema"; + private static final QName SCHEMA_QNAME = new QName(SCHEMA_NS, SCHEMA_NAME); + + private static SCADomain domain; + private static Map schemaMap; + private static PortType portType; + + private Map prefixMap; + + public BaseFramework() { + // create a new instance of this for each of the tests + prefixMap = new HashMap(); + } + + protected Element parameterElement(String methodName) { + Operation op = portType.getOperation(methodName, null, null); + Input in = op.getInput(); + Message msg = in.getMessage(); + Part part = msg.getPart(msg.getQName().getLocalPart()); + if (part == null) { + // bare parameter style + part = msg.getPart("arg0"); + return bareElement(part.getElementName()); + } else { + return schemaElement(part.getElementName()); + } + } + + protected String parameterType(String methodName) { + return parameterElement(methodName).getAttribute("type"); + } + + protected Element returnElement(String methodName) { + Operation op = portType.getOperation(methodName, null, null); + Output out = op.getOutput(); + Message msg = out.getMessage(); + Part part = msg.getPart(msg.getQName().getLocalPart()); + QName elementQName = part.getElementName(); + return schemaElement(elementQName); + } + + protected String returnType(String methodName) { + return returnElement(methodName).getAttribute("type"); + } + + protected Element faultElement(String methodName, String faultName) { + Operation op = portType.getOperation(methodName, null, null); + Fault fault = op.getFault(faultName); + Message msg = fault.getMessage(); + Part part = msg.getPart(msg.getQName().getLocalPart()); + QName elementQName = part.getElementName(); + return schemaElement(elementQName); + } + + protected String faultType(String methodName, String faultName) { + return faultElement(methodName, faultName).getAttribute("type"); + } + + private Element bareElement(QName elementQName) { + // find schema definition for wrapper element + Element schema = schemaMap.get(elementQName.getNamespaceURI()); + + // find namespace prefixes for this schema definition + NamedNodeMap attrNodes = schema.getAttributes(); + for (int i = 0; i < attrNodes.getLength(); i++) { + Attr attr = (Attr)attrNodes.item(i); + String attrName = attr.getName(); + if (attrName.startsWith("xmlns:")) { + prefixMap.put(attrName.substring(6), attr.getValue()); + } + } + + // find wrapper element definition in schema + String elementName = elementQName.getLocalPart(); + Element wrapper = null; + NodeList childNodes = schema.getElementsByTagNameNS(SCHEMA_NS, "element"); + for (int i = 0; i < childNodes.getLength(); i++) { + Node childNode = childNodes.item(i); + if (childNode instanceof Element) { + String name = ((Element)childNode).getAttribute("name"); + if (elementName.equals(name)) { + wrapper = (Element)childNode; + break; + } + } + } + return wrapper; + } + + private Element schemaElement(QName elementQName) { + Element wrapper = bareElement(elementQName); + + // find type definition for wrapper element + String typeName = wrapper.getAttribute("type"); + Element wrapperType = null; + if ("".equals(typeName)) { + NodeList childNodes = wrapper.getElementsByTagNameNS(SCHEMA_NS, "complexType"); + wrapperType = (Element)childNodes.item(0); + } else { + wrapperType = typeDefinition(typeName); + } + + return firstChild(wrapperType); + } + + protected Element typeDefinition(String typeName) { + String typePrefix = typeName.substring(0, typeName.indexOf(":")); + String typeLocalName = typeName.substring(typeName.indexOf(":") + 1); + Element typeSchema = schemaMap.get(prefixMap.get(typePrefix)); + Element typeElement = null; + NodeList childNodes = typeSchema.getElementsByTagNameNS(SCHEMA_NS, "complexType"); + for (int i = 0; i < childNodes.getLength(); i++) { + Node childNode = childNodes.item(i); + if (childNode instanceof Element) { + String name = ((Element)childNode).getAttribute("name"); + if (typeLocalName.equals(name)) { + typeElement = (Element)childNode; + break; + } + } + } + return typeElement; + } + + protected Element firstChild(Element complexType) { + // find xs:sequence child element + NodeList childNodes = complexType.getElementsByTagNameNS(SCHEMA_NS, "sequence"); + Element sequence = (Element)childNodes.item(0); + + // find first xs:element child element + childNodes = sequence.getElementsByTagNameNS(SCHEMA_NS, "element"); + return (Element)childNodes.item(0); + } + + private static void readWSDL(String serviceName) throws Exception { + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose",false); + wsdlReader.setFeature("javax.wsdl.importDocuments",true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/" + serviceName + "?wsdl"); + assertNotNull(definition); + + // find portType + Service service = definition.getService(new QName("http://verify.wsdlgen/", serviceName + "Service")); + Port port = service.getPort(serviceName + "Port"); + Binding binding = port.getBinding(); + portType = binding.getPortType(); + + // find schema definitions + Types types = definition.getTypes(); + schemaMap = new HashMap(); + for (Object ext : types.getExtensibilityElements()) { + ExtensibilityElement extElement = (ExtensibilityElement)ext; + if (SCHEMA_QNAME.equals(extElement.getElementType())) { + if (extElement instanceof Schema) { + Element schemaElement = ((Schema)extElement).getElement(); + schemaMap.put(schemaElement.getAttribute("targetNamespace"), schemaElement); + } + } + } + } + + /* + * Used for debugging DOM problems + */ + private void printDOM(Node node){ + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + Source source = new DOMSource(node); + Result result = new StreamResult(System.out); + transformer.transform(source, result); + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + protected static void start(String serviceName) throws Exception { + WSDLServiceGenerator.printWSDL = true; + domain = SCADomain.newInstance("DataTypes.composite"); + readWSDL(serviceName); + } + + protected static void stop() throws Exception { + domain.close(); + } +} diff --git a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DataTypesTestCase.java b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DataTypesTestCase.java index 3ebe40846d..a30b51f3cd 100644 --- a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DataTypesTestCase.java +++ b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DataTypesTestCase.java @@ -19,72 +19,19 @@ package wsdlgen.verify; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import javax.wsdl.Binding; -import javax.wsdl.Definition; -import javax.wsdl.Fault; -import javax.wsdl.Input; -import javax.wsdl.Message; -import javax.wsdl.Operation; -import javax.wsdl.Output; -import javax.wsdl.Part; -import javax.wsdl.Port; -import javax.wsdl.PortType; -import javax.wsdl.Service; -import javax.wsdl.Types; -import javax.wsdl.extensions.ExtensibilityElement; -import javax.wsdl.extensions.schema.Schema; -import javax.wsdl.factory.WSDLFactory; -import javax.wsdl.xml.WSDLReader; -import javax.xml.namespace.QName; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.w3c.dom.Attr; import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import org.apache.tuscany.sca.host.embedded.SCADomain; +import static org.junit.Assert.assertEquals; /** * Test ?wsdl works and that the returned WSDL is correct * * @version $Rev: 814373 $ $Date: 2009-09-13 19:06:29 +0100 (Sun, 13 Sep 2009) $ */ -public class DataTypesTestCase { - private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; - private static final String SCHEMA_NAME = "schema"; - private static final QName SCHEMA_QNAME = new QName(SCHEMA_NS, SCHEMA_NAME); - - private static SCADomain domain; - private static Map schemaMap; - private static PortType portType; - - private Map prefixMap; - - public DataTypesTestCase() { - // create a new instance of this for each of the tests - prefixMap = new HashMap(); - } +public class DataTypesTestCase extends BaseFramework { @Test public void testSimpleInt() throws Exception { @@ -98,14 +45,50 @@ public class DataTypesTestCase { assertEquals("unbounded", paramElement.getAttribute("maxOccurs")); } +/* + @Test + public void testSimpleMultiArrayInt() throws Exception { + Element paramElement = parameterElement("testSimpleMultiArrayInt"); + assertEquals("ns1:intArray", paramElement.getAttribute("type")); + assertEquals("unbounded", paramElement.getAttribute("maxOccurs")); + } +*/ + + @Test + public void testList() throws Exception { + Element paramElement = parameterElement("testList"); + assertEquals("xs:anyType", paramElement.getAttribute("type")); + assertEquals("unbounded", paramElement.getAttribute("maxOccurs")); + } + @Test - @Ignore("TUSCANY-3799") public void testSimpleListString() throws Exception { Element paramElement = parameterElement("testSimpleListString"); assertEquals("xs:string", paramElement.getAttribute("type")); assertEquals("unbounded", paramElement.getAttribute("maxOccurs")); } + @Test + public void testReturnSimpleListString() throws Exception { + Element retElement = returnElement("testReturnSimpleListString"); + assertEquals("xs:string", retElement.getAttribute("type")); + assertEquals("unbounded", retElement.getAttribute("maxOccurs")); + } + + @Test + public void testListByteArray() throws Exception { + Element paramElement = parameterElement("testListByteArray"); + assertEquals("xs:base64Binary", paramElement.getAttribute("type")); + assertEquals("unbounded", paramElement.getAttribute("maxOccurs")); + } + + @Test + public void testListWildcard() throws Exception { + Element paramElement = parameterElement("testListWildcard"); + assertEquals("xs:anyType", paramElement.getAttribute("type")); + assertEquals("unbounded", paramElement.getAttribute("maxOccurs")); + } + @Test public void testComplex() throws Exception { String paramType = parameterType("testComplex"); @@ -128,176 +111,32 @@ public class DataTypesTestCase { assertEquals("xs:anyType", returnType("testDynamicSDO")); } - private Element parameterElement(String methodName) { - Operation op = portType.getOperation(methodName, null, null); - Input in = op.getInput(); - Message msg = in.getMessage(); - Part part = msg.getPart(msg.getQName().getLocalPart()); - QName elementQName = part.getElementName(); - return schemaElement(elementQName); - } - - private String parameterType(String methodName) { - return parameterElement(methodName).getAttribute("type"); - } - - private Element returnElement(String methodName) { - Operation op = portType.getOperation(methodName, null, null); - Output out = op.getOutput(); - Message msg = out.getMessage(); - Part part = msg.getPart(msg.getQName().getLocalPart()); - QName elementQName = part.getElementName(); - return schemaElement(elementQName); - } - - private String returnType(String methodName) { - return returnElement(methodName).getAttribute("type"); - } - - private Element faultElement(String methodName, String faultName) { - Operation op = portType.getOperation(methodName, null, null); - Fault fault = op.getFault(faultName); - Message msg = fault.getMessage(); - Part part = msg.getPart(msg.getQName().getLocalPart()); - QName elementQName = part.getElementName(); - return schemaElement(elementQName); - } - - private String faultType(String methodName, String faultName) { - return faultElement(methodName, faultName).getAttribute("type"); - } - - private Element schemaElement(QName elementQName) { - // find schema definition for wrapper element - Element schema = schemaMap.get(elementQName.getNamespaceURI()); - - // find namespace prefixes for this schema definition - NamedNodeMap attrNodes = schema.getAttributes(); - for (int i = 0; i < attrNodes.getLength(); i++) { - Attr attr = (Attr)attrNodes.item(i); - String attrName = attr.getName(); - if (attrName.startsWith("xmlns:")) { - prefixMap.put(attrName.substring(6), attr.getValue()); - } - } - - // find wrapper element definition in schema - String elementName = elementQName.getLocalPart(); - Element wrapper = null; - NodeList childNodes = schema.getElementsByTagNameNS(SCHEMA_NS, "element"); - for (int i = 0; i < childNodes.getLength(); i++) { - Node childNode = childNodes.item(i); - if (childNode instanceof Element) { - String name = ((Element)childNode).getAttribute("name"); - if (elementName.equals(name)) { - wrapper = (Element)childNode; - break; - } - } - } - - // find type definition for wrapper element - String typeName = wrapper.getAttribute("type"); - Element wrapperType = null; - if ("".equals(typeName)) { - childNodes = wrapper.getElementsByTagNameNS(SCHEMA_NS, "complexType"); - wrapperType = (Element)childNodes.item(0); - } else { - wrapperType = typeDefinition(typeName); - } - - return firstChild(wrapperType); - } - - private Element typeDefinition(String typeName) { - String typePrefix = typeName.substring(0, typeName.indexOf(":")); - String typeLocalName = typeName.substring(typeName.indexOf(":") + 1); - Element typeSchema = schemaMap.get(prefixMap.get(typePrefix)); - Element typeElement = null; - NodeList childNodes = typeSchema.getElementsByTagNameNS(SCHEMA_NS, "complexType"); - for (int i = 0; i < childNodes.getLength(); i++) { - Node childNode = childNodes.item(i); - if (childNode instanceof Element) { - String name = ((Element)childNode).getAttribute("name"); - if (typeLocalName.equals(name)) { - typeElement = (Element)childNode; - break; - } - } - } - return typeElement; - } - - private Element firstChild(Element complexType) { - // find xs:sequence child element - NodeList childNodes = complexType.getElementsByTagNameNS(SCHEMA_NS, "sequence"); - Element sequence = (Element)childNodes.item(0); - - // find first xs:element child element - childNodes = sequence.getElementsByTagNameNS(SCHEMA_NS, "element"); - return (Element)childNodes.item(0); +/* + @Test + public void testWebParam() throws Exception { + Element paramElement = parameterElement("testWebParam"); + assertEquals("simpleInt", paramElement.getAttribute("name")); + assertEquals("xs:int", paramElement.getAttribute("type")); } - private static void readWSDL() throws Exception { - if (portType == null) { - InputStream inp = new URL("http://localhost:8085/DataTypes?wsdl").openStream(); - BufferedReader br = new BufferedReader(new InputStreamReader(inp)); - String line; - while((line = br.readLine()) != null) { - System.out.println(line); - } - br.close(); - - WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); - wsdlReader.setFeature("javax.wsdl.verbose",false); - wsdlReader.setFeature("javax.wsdl.importDocuments",true); - - Definition definition = wsdlReader.readWSDL("http://localhost:8085/DataTypes?wsdl"); - assertNotNull(definition); - - // find portType - Service service = definition.getService(new QName("http://verify.wsdlgen/", "DataTypesService")); - Port port = service.getPort("DataTypesPort"); - Binding binding = port.getBinding(); - portType = binding.getPortType(); - - // find schema definitions - Types types = definition.getTypes(); - schemaMap = new HashMap(); - for (Object ext : types.getExtensibilityElements()) { - ExtensibilityElement extElement = (ExtensibilityElement)ext; - if (SCHEMA_QNAME.equals(extElement.getElementType())) { - if (extElement instanceof Schema) { - Element schemaElement = ((Schema)extElement).getElement(); - schemaMap.put(schemaElement.getAttribute("targetNamespace"), schemaElement); - } - } - } - } + @Test + @Ignore + public void testWebParamArray() throws Exception { + Element paramElement = parameterElement("testWebParamArray"); + assertEquals("arrayInt", paramElement.getAttribute("name")); + assertEquals("xs:int", paramElement.getAttribute("type")); + assertEquals("unbounded", paramElement.getAttribute("maxOccurs")); } +*/ - /* - * Used for debugging DOM problems - */ - private void printDOM(Node node){ - try { - Transformer transformer = TransformerFactory.newInstance().newTransformer(); - Source source = new DOMSource(node); - Result result = new StreamResult(System.out); - transformer.transform(source, result); - } catch (Exception ex){ - ex.printStackTrace(); - } - } @BeforeClass public static void setUpBeforeClass() throws Exception { - domain = SCADomain.newInstance("DataTypes.composite"); - readWSDL(); + BaseFramework.start("DataTypes"); } @AfterClass public static void tearDownAfterClass() throws Exception { - domain.close(); + BaseFramework.stop(); } } diff --git a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DynamicSDOTestCase.java b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DynamicSDOTestCase.java index 3445d2f06b..cc2bd46a72 100644 --- a/sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DynamicSDOTestCase.java +++ b/sca-java-1.x/trunk/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DynamicSDOTestCase.java @@ -19,154 +19,63 @@ package wsdlgen.verify; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; - -import javax.wsdl.Binding; -import javax.wsdl.Definition; -import javax.wsdl.Message; -import javax.wsdl.Part; -import javax.wsdl.Operation; -import javax.wsdl.Output; -import javax.wsdl.Port; -import javax.wsdl.PortType; -import javax.wsdl.Service; -import javax.wsdl.Types; -import javax.wsdl.extensions.ExtensibilityElement; -import javax.wsdl.extensions.schema.Schema; -import javax.wsdl.factory.WSDLFactory; -import javax.wsdl.xml.WSDLReader; -import javax.xml.namespace.QName; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import junit.framework.TestCase; - +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import org.apache.tuscany.sca.host.embedded.SCADomain; +import static org.junit.Assert.assertEquals; /** - * Test ?wsdl works and that the returned WSDL has the correct endpoint + * Test ?wsdl works and that the returned WSDL is correct * * @version $Rev: 814373 $ $Date: 2009-09-13 19:06:29 +0100 (Sun, 13 Sep 2009) $ */ -public class DynamicSDOTestCase extends TestCase { - private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; - private static final String SCHEMA_NAME = "schema"; - private static final QName SCHEMA_QNAME = new QName(SCHEMA_NS, SCHEMA_NAME); - - private SCADomain domain; - - /** - * Tests ?wsdl works and produces xs:anyType for commonj.sdo.DataObject - */ - public void testDynamicSDO() throws Exception { - InputStream inp = new URL("http://localhost:8085/DataService?wsdl").openStream(); - BufferedReader br = new BufferedReader(new InputStreamReader(inp)); - String line; - while((line = br.readLine()) != null) { - System.out.println(line); - } - br.close(); - - WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); - wsdlReader.setFeature("javax.wsdl.verbose",false); - wsdlReader.setFeature("javax.wsdl.importDocuments",true); - - Definition definition = wsdlReader.readWSDL("http://localhost:8085/DataService?wsdl"); - assertNotNull(definition); - Service service = definition.getService(new QName("http://verify.wsdlgen/", - "GetDataServiceWithoutExceptionService")); - Port port = service.getPort("GetDataServiceWithoutExceptionPort"); - Binding binding = port.getBinding(); - PortType portType = binding.getPortType(); +public class DynamicSDOTestCase extends BaseFramework { - // find wrapper element for getMessageSDO return type - Operation op = portType.getOperation("getMessageSDO", null, null); - Output out = op.getOutput(); - Message msg = out.getMessage(); - Part part = msg.getPart(msg.getQName().getLocalPart()); - QName elementQName = part.getElementName(); - - // find schema definition for wrapper element - Types types = definition.getTypes(); - String elementNS = elementQName.getNamespaceURI(); - Element schema = null; - for (Object ext : types.getExtensibilityElements()) { - ExtensibilityElement extElement = (ExtensibilityElement)ext; - if (SCHEMA_QNAME.equals(extElement.getElementType())) { - if (extElement instanceof Schema) { - Element schemaElement = ((Schema)extElement).getElement(); - if (elementNS.equals(schemaElement.getAttribute("targetNamespace"))) { - schema = schemaElement; - break; - } - } - } - } - - // find wrapper element definition in schema - String elementName = elementQName.getLocalPart(); - Element wrapper = null; - NodeList childNodes = schema.getElementsByTagNameNS(SCHEMA_NS, "element"); - for (int i = 0; i < childNodes.getLength(); i++) { - Node childNode = childNodes.item(i); - if (childNode instanceof Element) { - String name = ((Element)childNode).getAttribute("name"); - if (elementName.equals(name)) { - wrapper = (Element)childNode; - break; - } - } - } - - // find xs:complexType child element - childNodes = wrapper.getElementsByTagNameNS(SCHEMA_NS, "complexType"); - Element complexType = (Element)childNodes.item(0); + @Test + public void testGetMessage() throws Exception { + assertEquals("xs:base64Binary", returnType("getMessage")); + } - // find xs:sequence child element - childNodes = complexType.getElementsByTagNameNS(SCHEMA_NS, "sequence"); - Element sequence = (Element)childNodes.item(0); + @Test + public void testGetMessageList() throws Exception { + Element retElement = returnElement("getMessageList"); + assertEquals("xs:base64Binary", retElement.getAttribute("type")); + assertEquals("unbounded", retElement.getAttribute("maxOccurs")); + } - // find xs:element child element - childNodes = sequence.getElementsByTagNameNS(SCHEMA_NS, "element"); - Element returnValue = (Element)childNodes.item(0); + @Test + public void testGetMessageSDO() throws Exception { + assertEquals("xs:anyType", returnType("getMessageSDO")); + } - // verify that return type is xs:anyType - assertEquals("xs:anyType", returnValue.getAttribute("type")); + @Test + public void testGetMessageListSDOList() throws Exception { + Element retElement = returnElement("getMessageListSDOList"); + assertEquals("xs:anyType", retElement.getAttribute("type")); + assertEquals("unbounded", retElement.getAttribute("maxOccurs")); } - /* - * Used for debugging DOM problems - */ - private void printDOM(Node node){ - try { - Transformer transformer = TransformerFactory.newInstance().newTransformer(); - Source source = new DOMSource(node); - Result result = new StreamResult(System.out); - transformer.transform(source, result); - } catch (Exception ex){ - ex.printStackTrace(); - } + @Test + public void testGetMessageListSDOArr() throws Exception { + Element retElement = returnElement("getMessageListSDOArr"); + assertEquals("xs:anyType", retElement.getAttribute("type")); + assertEquals("unbounded", retElement.getAttribute("maxOccurs")); } - @Override - protected void setUp() throws Exception { - domain = SCADomain.newInstance("dynamic-sdo.composite"); + @Test + public void testGetMessageListSDOinSDO() throws Exception { + assertEquals("xs:anyType", returnType("getMessageListSDOinSDO")); } - @Override - protected void tearDown() throws Exception { - domain.close(); + @BeforeClass + public static void setUpBeforeClass() throws Exception { + BaseFramework.start("GetDataServiceWithoutException"); } + @AfterClass + public static void tearDownAfterClass() throws Exception { + BaseFramework.stop(); + } } -- cgit v1.2.3