http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java b/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java deleted file mode 100644 index e6e0fbb..0000000 --- a/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java +++ /dev/null @@ -1,359 +0,0 @@ -/* - * Copyright (C) 2003 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. Authorship - * of the modifications may be determined from the ChangeLog placed at - * the end of this file. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - **************************************************************** - * Source code information - * ----------------------- - * Filename $RCSfile: XMLSplitterSerialisationHelper.java,v $ - * Revision $Revision: 1.2 $ - * Release status $State: Exp $ - * Last modified on $Date: 2008/08/08 10:28:08 $ - * by $Author: stain $ - * Created on 16-May-2006 - *****************************************************************/ -package net.sf.taverna.wsdl.xmlsplitter; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import net.sf.taverna.wsdl.parser.ArrayTypeDescriptor; -import net.sf.taverna.wsdl.parser.AttributeTypeDescriptor; -import net.sf.taverna.wsdl.parser.BaseTypeDescriptor; -import net.sf.taverna.wsdl.parser.ComplexTypeDescriptor; -import net.sf.taverna.wsdl.parser.TypeDescriptor; - -import org.apache.log4j.Logger; -import org.jdom.Content; -import org.jdom.Element; -import org.jdom.Namespace; - -/** - * A helper class that supports the XMLOutputSplitter and XMLInputSplitter, - * providing the ability for each to be serialised/deserialised to and from the - * extensions XML for the ScuflModel XML when storing a workflow. This XML - * describes the TypeDescriptor tree that the Splitter wraps. - * - * @author Stuart Owen - * @author Asger Askov-Bleking - * - */ - -public class XMLSplitterSerialisationHelper { - - public final static Namespace XScuflNS = Namespace.getNamespace("s", - "http://org.embl.ebi.escience/xscufl/0.1alpha"); - - private static Logger logger = Logger - .getLogger(XMLSplitterSerialisationHelper.class); - - /** - * Generates the extensions XML that describes the TypeDescriptor to allow - * an XMLInputSplitter or XMLOutputSplitter to be reconstructed using - * consumeXML. - */ - public static Element typeDescriptorToExtensionXML(TypeDescriptor descriptor) { - Element result = new Element("extensions", XScuflNS); - Element type = null; - if (descriptor instanceof ComplexTypeDescriptor) { - type = constructElementForComplexType( - (ComplexTypeDescriptor) descriptor, new ArrayList<String>()); - } - else if (descriptor instanceof ArrayTypeDescriptor) { - type = constructElementForArrayType( - (ArrayTypeDescriptor) descriptor, new ArrayList<String>()); - } - result.addContent(type); - return result; - } - - /** - * Generates the TypeDescriptor structurefrom the extensions XML element - * provided. This assumes that the root of the structure is <complextype/>. - * This will be the same xml generated by provideXML. - */ - public static TypeDescriptor extensionXMLToTypeDescriptor(Element element) { - Element child = (Element) element.getChildren().get(0); - return buildTypeDescriptorFromElement(child, - new HashMap<String, TypeDescriptor>()); - } - - private static Element constructElementForArrayType( - ArrayTypeDescriptor descriptor, List<String> existingsTypes) { - Element result = new Element("arraytype", XScuflNS); - if (existingsTypes.contains(descriptor.getQname().toString())) { - result.setAttribute("id", descriptor.getQname().toString()); - populateElement(result, descriptor); - result.removeAttribute("qname"); - } else { - existingsTypes.add(descriptor.getQname().toString()); - populateElement(result, descriptor); - Element elementType = new Element("elementtype", XScuflNS); - if (descriptor.getElementType() instanceof ComplexTypeDescriptor) { - elementType.addContent(constructElementForComplexType( - (ComplexTypeDescriptor) descriptor.getElementType(), - existingsTypes)); - } else if (descriptor.getElementType() instanceof ArrayTypeDescriptor) { - elementType.addContent(constructElementForArrayType( - (ArrayTypeDescriptor) descriptor.getElementType(), - existingsTypes)); - } else if (descriptor.getElementType() instanceof BaseTypeDescriptor) { - Element element = new Element("basetype", XScuflNS); - populateElement(element, descriptor.getElementType()); - elementType.addContent(element); - } - result.addContent(elementType); - } - return result; - } - - private static Element constructElementForComplexType( - ComplexTypeDescriptor descriptor, List<String> existingsTypes) { - Element result = new Element("complextype", XScuflNS); - if (existingsTypes.contains(descriptor.getQname().toString())) { - result.setAttribute("id", descriptor.getQname().toString()); - populateElement(result, descriptor); - result.removeAttribute("qname"); - } else { - existingsTypes.add(descriptor.getQname().toString()); - populateElement(result, descriptor); - Element elements = new Element("elements", XScuflNS); - for (TypeDescriptor desc : descriptor.getElements()) { - Element element = null; - if (desc instanceof ComplexTypeDescriptor) { - element = constructElementForComplexType( - (ComplexTypeDescriptor) desc, existingsTypes); - } else if (desc instanceof ArrayTypeDescriptor) { - element = constructElementForArrayType( - (ArrayTypeDescriptor) desc, existingsTypes); - } else if (desc instanceof BaseTypeDescriptor) { - element = new Element("basetype", XScuflNS); - populateElement(element, desc); - } - if (element != null) - elements.addContent(element); - } - result.addContent(elements); - List<TypeDescriptor> attributeDescriptors = descriptor.getAttributes(); - if (attributeDescriptors != null && attributeDescriptors.size() > 0) { - Element attributes = new Element("attributes", XScuflNS); - for (TypeDescriptor desc : attributeDescriptors) { - Element attribute = new Element("attribute", XScuflNS); - populateElement(attribute, desc); - attributes.addContent(attribute); - } - result.addContent(attributes); - } - } - return result; - } - - private static void populateElement(Element element, - TypeDescriptor descriptor) { - element.setAttribute("optional", String - .valueOf(descriptor.isOptional())); - element.setAttribute("unbounded", String.valueOf(descriptor - .isUnbounded())); - if (descriptor instanceof ArrayTypeDescriptor) { - element.setAttribute("wrapped", String - .valueOf(((ArrayTypeDescriptor) descriptor).isWrapped())); - } - element.setAttribute("typename", descriptor.getType()); - element.setAttribute("name", descriptor.getName() == null ? "" - : descriptor.getName()); - element.setAttribute("qname", descriptor.getQname().toString()); - if (descriptor.getDocumentation() != null){ - Element annotationElement = - new Element("annotation", Namespace.getNamespace("xsd", "http://www.w3.org/2001/XMLSchema")); - Element documentationElemenet = - new Element("documentation", Namespace.getNamespace("xsd", "http://www.w3.org/2001/XMLSchema")); - documentationElemenet.setText(descriptor.getDocumentation()); - annotationElement.addContent(documentationElemenet); - element.addContent(annotationElement); - } - - } - - private static TypeDescriptor buildTypeDescriptorFromElement( - Element element, HashMap<String, TypeDescriptor> existingsTypes) { - TypeDescriptor result = null; - if (element.getAttributeValue("id") != null) { - TypeDescriptor stored = existingsTypes.get(element - .getAttributeValue("id")); - if (stored == null) - logger.fatal("Missing reference to parent type with id=" - + element.getAttributeValue("id")); - else { - result = createFromCache(stored, element); - } - } - - if (result == null) { - if (element.getName().equalsIgnoreCase("complextype")) { - result = new ComplexTypeDescriptor(); - populateDescriptor(element, result); - existingsTypes.put(result.getQname().toString(), result); - Element elements = element.getChild("elements", XScuflNS); - for (Iterator<?> iterator = elements.getChildren().iterator(); iterator - .hasNext();) { - Element childElement = (Element) iterator.next(); - ((ComplexTypeDescriptor) result).getElements().add( - buildTypeDescriptorFromElement(childElement, - existingsTypes)); - } - Element attributes = element.getChild("attributes", XScuflNS); - if (attributes != null) { - for (Iterator<?> iterator = attributes.getChildren().iterator(); iterator - .hasNext();) { - Element childElement = (Element) iterator.next(); - ((ComplexTypeDescriptor) result).getAttributes().add( - buildTypeDescriptorFromElement(childElement, - existingsTypes)); - } - } - - } else if (element.getName().equalsIgnoreCase("arraytype")) { - - result = new ArrayTypeDescriptor(); - populateDescriptor(element, result); - existingsTypes.put(result.getQname().toString(), result); - Element elementType = element.getChild("elementtype", XScuflNS); - ((ArrayTypeDescriptor) result) - .setElementType(buildTypeDescriptorFromElement( - (Element) elementType.getChildren().get(0), - existingsTypes)); - if (element.getAttribute("wrapped") != null) { - ((ArrayTypeDescriptor) result).setWrapped(element - .getAttributeValue("wrapped").equalsIgnoreCase( - "true")); - } else { - // prior to the addition of the wrapped attribute, in the - // majority of cases an array - // would not be wrapped if it was flagged as unbounded. - ((ArrayTypeDescriptor) result).setWrapped(!result - .isUnbounded()); - } - - } else if (element.getName().equalsIgnoreCase("basetype")) { - result = new BaseTypeDescriptor(); - populateDescriptor(element, result); - } else if (element.getName().equalsIgnoreCase("attribute")) { - result = new AttributeTypeDescriptor(); - populateDescriptor(element, result); - } else if (element.getName().equalsIgnoreCase("attribute")) { - result = new AttributeTypeDescriptor(); - populateDescriptor(element, result); - } - } - - return result; - } - - /** - * Performs a shallow copy of the descriptor stored, but updates its name, - * isbounded and optional This means that descriptors of the same type do - * not need to be repeated throught the stored XML but also takes into - * account parameters of the same type may have different name and - * attributes to that stored - * - * @param descriptor - * @param element - * @return - */ - private static TypeDescriptor createFromCache(TypeDescriptor descriptor, - Element element) { - TypeDescriptor result = null; - if (descriptor instanceof ArrayTypeDescriptor) { - ArrayTypeDescriptor array = new ArrayTypeDescriptor(); - array.setQname(descriptor.getQname()); - array.setElementType(((ArrayTypeDescriptor) descriptor) - .getElementType()); - array.setWrapped(((ArrayTypeDescriptor) descriptor).isWrapped()); - result = array; - } else if (descriptor instanceof ComplexTypeDescriptor) { - ComplexTypeDescriptor complex = new ComplexTypeDescriptor(); - complex.setQname(descriptor.getQname()); - complex.setElements(((ComplexTypeDescriptor) descriptor) - .getElements()); - result = complex; - } else { - throw new IllegalArgumentException("Unexpected type descriptor: " - + descriptor); - } - result.setType(descriptor.getType()); - - String name = element.getAttributeValue("name"); - result.setName(name != null ? name : descriptor.getName()); - - String optional = element.getAttributeValue("optional"); - if (optional != null) { - result.setOptional(optional.equalsIgnoreCase("true")); - } else { - result.setOptional(descriptor.isOptional()); - } - - String unbounded = element.getAttributeValue("unbounded"); - if (unbounded != null) { - result.setUnbounded(unbounded.equalsIgnoreCase("true")); - } else { - result.setUnbounded(descriptor.isUnbounded()); - } - - return result; - } - - private static void populateDescriptor(Element element, - TypeDescriptor result) { - result.setName(element.getAttributeValue("name")); - result.setType(element.getAttributeValue("typename")); - result.setOptional(element.getAttributeValue("optional") - .equalsIgnoreCase("true")); - result.setUnbounded(element.getAttributeValue("unbounded") - .equalsIgnoreCase("true")); - - Element annotationChild = - element.getChild("annotation", Namespace.getNamespace("xsd", "http://www.w3.org/2001/XMLSchema")); - if (annotationChild != null){ - List documentationChildren = annotationChild - .getChildren("documentation", Namespace.getNamespace("xsd", "http://www.w3.org/2001/XMLSchema")); - - String documentation = ""; - for (Object documentationChild : documentationChildren) { - documentation += ((Element)documentationChild).getText(); - } - if (!documentation.isEmpty()){ - result.setDocumentation(documentation); - } - } - - // qname has been added since 1.3.2-RC1 so need to test if missing for - // older workflows - // if missing it is resolved to an empty namespace and typename: - // {}typename - String qname = element.getAttributeValue("qname"); - if (qname != null) - result.setQnameFromString(qname); - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/TypeDescriptorTest.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/TypeDescriptorTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/TypeDescriptorTest.java deleted file mode 100644 index c7be469..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/TypeDescriptorTest.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (C) 2003 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. Authorship - * of the modifications may be determined from the ChangeLog placed at - * the end of this file. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - **************************************************************** - * Source code information - * ----------------------- - * Filename $RCSfile: TypeDescriptorTest.java,v $ - * Revision $Revision: 1.2 $ - * Release status $State: Exp $ - * Last modified on $Date: 2007/11/30 12:13:38 $ - * by $Author: sowen70 $ - * Created on 17-May-2006 - *****************************************************************/ -package net.sf.taverna.wsdl.parser; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -public class TypeDescriptorTest extends TestCase { - - // array of strings - public void testRetrieveSignitureForArrayDescriptor() { - ArrayTypeDescriptor desc = new ArrayTypeDescriptor(); - desc.setName("AnArray"); - desc.setType("arrayofstring"); - - BaseTypeDescriptor base = new BaseTypeDescriptor(); - base.setName(""); - base.setType("string"); - - desc.setElementType(base); - - String[] names = new String[1]; - Class<?>[] types = new Class[1]; - - List<TypeDescriptor> params = new ArrayList<TypeDescriptor>(); - params.add(desc); - TypeDescriptor.retrieveSignature(params, names, types); - - assertEquals("AnArray", names[0]); - assertEquals(String[].class, types[0]); - } - - // array of strings, but type for array is defined as string - // (which is logically warped, but some wsdl's describe their string arrays - // this way). - public void testRetrieveSignitureForArrayDescriptor3() { - ArrayTypeDescriptor desc = new ArrayTypeDescriptor(); - desc.setName("AnArray"); - desc.setType("string"); - - BaseTypeDescriptor base = new BaseTypeDescriptor(); - base.setName(""); - base.setType("string"); - - desc.setElementType(base); - - String[] names = new String[1]; - Class<?>[] types = new Class[1]; - - List<TypeDescriptor> params = new ArrayList<TypeDescriptor>(); - params.add(desc); - TypeDescriptor.retrieveSignature(params, names, types); - - assertEquals("AnArray", names[0]); - assertEquals(String[].class, types[0]); - } - - // array of complex types - public void testRetrieveSignitureForArrayDescriptor2() { - ArrayTypeDescriptor desc = new ArrayTypeDescriptor(); - desc.setName("AnArray"); - desc.setType("complextype"); - - ComplexTypeDescriptor complex = new ComplexTypeDescriptor(); - complex.setName("complex"); - complex.setType("complextype"); - - desc.setElementType(complex); - - String[] names = new String[1]; - Class<?>[] types = new Class[1]; - - List<TypeDescriptor> params = new ArrayList<TypeDescriptor>(); - params.add(desc); - TypeDescriptor.retrieveSignature(params, names, types); - - assertEquals("AnArray", names[0]); - assertEquals(org.w3c.dom.Element.class, types[0]); - } - - public void testForCyclicTrue() { - ComplexTypeDescriptor a = new ComplexTypeDescriptor(); - a.setName("a"); - a.setType("outertype"); - - ComplexTypeDescriptor b = new ComplexTypeDescriptor(); - b.setName("b"); - b.setType("middletype"); - - ComplexTypeDescriptor c = new ComplexTypeDescriptor(); - c.setName("c"); - c.setType("innertype"); - - a.getElements().add(b); - b.getElements().add(c); - c.getElements().add(a); - - assertTrue("should be identified as cyclic", TypeDescriptor.isCyclic(a)); - } - - public void testForCyclicTrueWithArray() { - ComplexTypeDescriptor a = new ComplexTypeDescriptor(); - a.setName("a"); - a.setType("outertype"); - - ArrayTypeDescriptor b = new ArrayTypeDescriptor(); - b.setName("b"); - b.setType("arraytype"); - - ComplexTypeDescriptor c = new ComplexTypeDescriptor(); - c.setName("c"); - c.setType("innertype"); - - a.getElements().add(b); - b.setElementType(c); - c.getElements().add(a); - - assertTrue("should be identified as cyclic", TypeDescriptor.isCyclic(a)); - } - - public void testForCyclicFalse() { - ComplexTypeDescriptor a = new ComplexTypeDescriptor(); - a.setName("a"); - a.setType("person"); - - ComplexTypeDescriptor b = new ComplexTypeDescriptor(); - b.setName("b"); - b.setType("name"); - - ComplexTypeDescriptor c = new ComplexTypeDescriptor(); - c.setName("c"); - c.setType("age"); - - a.getElements().add(b); - a.getElements().add(c); - - assertFalse("should be not identified as cyclic", TypeDescriptor - .isCyclic(a)); - } - - public void testQNameAsString() { - ComplexTypeDescriptor a = new ComplexTypeDescriptor(); - a.setQnameFromString("{URI}localPart"); - assertEquals("URI", a.getQname().getNamespaceURI()); - assertEquals("localPart", a.getQname().getLocalPart()); - - a = new ComplexTypeDescriptor(); - a.setQnameFromString("{}localPart"); - assertEquals("", a.getQname().getNamespaceURI()); - assertEquals("localPart", a.getQname().getLocalPart()); - } - - public void testBaseTypeKnownSigniture() { - TypeDescriptor decimal=new BaseTypeDescriptor(); - decimal.setName("adecimal"); - decimal.setType("decimal"); - - List<TypeDescriptor> params=new ArrayList<TypeDescriptor>(); - String [] names=new String[1]; - Class<?> [] types=new Class[1]; - params.add(decimal); - TypeDescriptor.retrieveSignature(params, names, types); - - assertEquals("should only be 1 type",1,types.length); - assertEquals("should only be 1 name",1,names.length); - - assertEquals("name should be adecimal","adecimal",names[0]); - assertEquals("type should be double",Double.TYPE,types[0]); - } - - public void testBaseTypeUnrecognisedSigniture() { - TypeDescriptor date=new BaseTypeDescriptor(); - date.setName("adate"); - date.setType("date"); - - List<TypeDescriptor> params=new ArrayList<TypeDescriptor>(); - String [] names=new String[1]; - Class<?> [] types=new Class[1]; - params.add(date); - TypeDescriptor.retrieveSignature(params, names, types); - - assertEquals("should only be 1 type",1,types.length); - assertEquals("should only be 1 name",1,names.length); - - assertEquals("name should be adecimal","adate",names[0]); - assertEquals("type should be string",String.class,types[0]); - } - - public void testComplex() { - TypeDescriptor complex=new ComplexTypeDescriptor(); - complex.setName("acomplex"); - complex.setType("complextype"); - - List<TypeDescriptor> params=new ArrayList<TypeDescriptor>(); - String [] names=new String[1]; - Class<?> [] types=new Class[1]; - params.add(complex); - TypeDescriptor.retrieveSignature(params, names, types); - - assertEquals("should only be 1 type",1,types.length); - assertEquals("should only be 1 name",1,names.length); - - assertEquals("name should be adecimal","acomplex",names[0]); - assertEquals("type should be string",org.w3c.dom.Element.class,types[0]); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSDLParserTest.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSDLParserTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSDLParserTest.java deleted file mode 100644 index f111619..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSDLParserTest.java +++ /dev/null @@ -1,295 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.wsdl.parser; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.net.URL; -import java.util.List; - -import javax.wsdl.Operation; -import javax.xml.namespace.QName; - -import net.sf.taverna.wsdl.testutils.WSDLTestHelper; - -import org.junit.Test; - -public class WSDLParserTest { - - @Test - public void testGetOperations() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl")); - List<Operation> operations = parser.getOperations(); - assertEquals( - "wrong number of operations found (wsdl may have changed)", 12, - operations.size()); - Operation op = operations.get(0); - assertEquals("wrong name for first operation", "run_eGquery", op - .getName()); - assertEquals("wrong style", "document", parser.getStyle()); - } - - private String wsdlResourcePath(String wsdlName) throws Exception { - return WSDLTestHelper.wsdlResourcePath(wsdlName); - } - - @Test - public void testGetActionURI() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl")); - String actionURI = parser.getSOAPActionURI("run_eInfo"); - assertEquals("action uri is wrong", "einfo", actionURI); - } - - @Test - public void testComplexTypeFromImport() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl")); - - List<TypeDescriptor> inputs = parser - .getOperationInputParameters("run_eInfo"); - List<TypeDescriptor> outputs = parser - .getOperationOutputParameters("run_eInfo"); - assertEquals("wrong number of inputs", 1, inputs.size()); - assertEquals("wrong number of outputs", 1, outputs.size()); - assertTrue("input should be complex", - inputs.get(0) instanceof ComplexTypeDescriptor); - ComplexTypeDescriptor complexTypeDesc = (ComplexTypeDescriptor) inputs - .get(0); - assertEquals("wrong name", "parameters", complexTypeDesc.getName()); - assertEquals("wrong number of elements", 3, complexTypeDesc - .getElements().size()); - - TypeDescriptor typeDesc = complexTypeDesc - .getElements().get(0); - - assertEquals("wrong name", "db", typeDesc.getName()); - assertEquals("wrong type", "string", typeDesc.getType()); - assertTrue("db should be optional", typeDesc.isOptional()); - assertFalse("db should not be unbounded", typeDesc.isUnbounded()); - - typeDesc = complexTypeDesc.getElements().get(1); - assertEquals("wrong name", "tool", typeDesc.getName()); - assertEquals("wrong type", "string", typeDesc.getType()); - assertTrue("tool should be optional", typeDesc.isOptional()); - assertFalse("tool should not be unbounded", typeDesc.isUnbounded()); - - typeDesc = complexTypeDesc.getElements().get(2); - assertEquals("wrong name", "email", typeDesc.getName()); - assertEquals("wrong type", "string", typeDesc.getType()); - assertTrue("email should be optional", typeDesc.isOptional()); - assertFalse("email should not be unbounded", typeDesc.isUnbounded()); - } - - @Test - public void testNestedComplexTypes() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("bind.wsdl")); - - List<TypeDescriptor> inputs = parser - .getOperationInputParameters("BIVGetComplexRecord"); - List<TypeDescriptor> outputs = parser - .getOperationOutputParameters("BIVGetComplexRecord"); - - assertEquals("wrong number of inputs", 1, inputs.size()); - assertEquals("wrong number of outputs", 1, outputs.size()); - - assertEquals("wrong name for input", "bid", (inputs - .get(0)).getName()); - assertEquals("wrong type for input", "int", (inputs - .get(0)).getType()); - - assertEquals("wrong name for output", "BIVComplex", - (outputs.get(0)).getName()); - assertEquals("wrong type for output", "BIVComplex", - (outputs.get(0)).getType()); - assertTrue("wrong descriptor class for output", - outputs.get(0) instanceof ComplexTypeDescriptor); - - ComplexTypeDescriptor typeDesc = (ComplexTypeDescriptor) outputs.get(0); - assertEquals("wrong number of inner elements", 3, typeDesc - .getElements().size()); - assertEquals("wrong name for first element", "bid", - (typeDesc.getElements().get(0)).getName()); - assertEquals("wrong name for 2nd element", "spokeModel", - (typeDesc.getElements().get(1)).getName()); - assertEquals("wrong name for 3rd element", "subunit", - (typeDesc.getElements().get(2)).getName()); - - assertTrue("3rd element should be instance of ArrayTypeDescriptor", - typeDesc.getElements().get(2) instanceof ArrayTypeDescriptor); - ArrayTypeDescriptor arrayTypeDesc = (ArrayTypeDescriptor) typeDesc - .getElements().get(2); - - assertEquals("wrong type for 3rd element", "BIVMolecule", arrayTypeDesc - .getType()); - - typeDesc = (ComplexTypeDescriptor) arrayTypeDesc.getElementType(); - - assertEquals("wrong type for 3rd element", "BIVMolecule", typeDesc - .getType()); - - assertEquals("wrong number of elements in nested complex type", 7, - typeDesc.getElements().size()); - assertEquals("wrong name for first element", "id", - (typeDesc.getElements().get(0)).getName()); - assertEquals("wrong type for first element", "int", - (typeDesc.getElements().get(0)).getType()); - - assertEquals("wrong name for last element", "smid-hits", - (typeDesc.getElements().get(6)).getName()); - assertEquals("wrong type for last element", "int", - (typeDesc.getElements().get(6)).getType()); - } - - @Test - public void testMissingStyleInBinding() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("SBWReader.wsdl")); - assertEquals("Style should default to document if missing", "document", - parser.getStyle()); - } - - @Test - public void testBaseTypes() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("bind.wsdl")); - - List<TypeDescriptor> inputs = parser - .getOperationInputParameters("BIVGetRecord"); - assertEquals("wrong number of inputs", 1, inputs.size()); - assertTrue("should not be base type", - inputs.get(0) instanceof BaseTypeDescriptor); - assertEquals("wrong name", "bid", (inputs.get(0)) - .getName()); - assertEquals("wrong type", "int", (inputs.get(0)) - .getType()); - } - - @Test - public void testArrayType() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("bind.wsdl")); - - List<TypeDescriptor> inputs = parser - .getOperationInputParameters("BIVGetRecords"); - List<TypeDescriptor> outputs = parser - .getOperationOutputParameters("BIVGetRecords"); - assertEquals("wrong number of inputs", 1, inputs.size()); - assertTrue("input should be of AArrayTypeDescriptor", - inputs.get(0) instanceof ArrayTypeDescriptor); - - ArrayTypeDescriptor arrayTypeDesc = (ArrayTypeDescriptor) inputs.get(0); - - assertEquals("wrong name", "ids", arrayTypeDesc.getName()); - assertEquals("wrong type", "ArrayOf_xsd_int", arrayTypeDesc.getType()); - - TypeDescriptor typeDesc = arrayTypeDesc.getElementType(); - - assertTrue("element should be of type BaseTypeDescriptor", - typeDesc instanceof BaseTypeDescriptor); - assertEquals("wrong type", "int", typeDesc.getType()); - - assertEquals("wrong number of outputs", 1, outputs.size()); - - assertTrue("output should be of ArrayTypeDescriptor", - outputs.get(0) instanceof ArrayTypeDescriptor); - - arrayTypeDesc = (ArrayTypeDescriptor) outputs.get(0); - assertEquals("wrong name", "BIVRecords", arrayTypeDesc.getName()); - assertEquals("wrong type", "ArrayOfBIVRecord", arrayTypeDesc.getType()); - - typeDesc = arrayTypeDesc.getElementType(); - - assertEquals("wrong type", "BIVRecord", typeDesc.getType()); - } - - @Test - public void testGoVizNoOutputs() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("GoViz.wsdl")); - - List<TypeDescriptor> inputs = parser - .getOperationInputParameters("destroySession"); - List<TypeDescriptor> outputs = parser - .getOperationOutputParameters("destroySession"); - - assertEquals("wrong number of inputs", 1, inputs.size()); - assertEquals("wrong number of outputs", 0, outputs.size()); - - TypeDescriptor typeDesc = inputs.get(0); - assertTrue("input should be BaseType", - typeDesc instanceof BaseTypeDescriptor); - assertEquals("wrong name", "sessionID", typeDesc.getName()); - assertEquals("wrong type", "string", typeDesc.getType()); - } - - @Test - public void testGetUseEncoded() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("bind.wsdl")); - String use = parser.getUse("BIVGetRecords"); - assertEquals("use should be encoded", "encoded", use); - } - - @Test - public void testGetUseLiteral() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl")); - String use = parser.getUse("run_eInfo"); - assertEquals("use should be literal", "literal", use); - } - - @Test - public void testGetOperationNamespace() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("CurrencyExchangeService.wsdl")); - String operationNamespace = parser.getOperationNamespaceURI("getRate"); - assertEquals("operation namespace is wrong", - "urn:xmethods-CurrencyExchange", operationNamespace); - } - - @Test - public void testGetOperationNamespace2() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl")); - String operationNamespace = parser - .getOperationNamespaceURI("run_eInfo"); - assertEquals("operation namespace is wrong", - "http://www.ncbi.nlm.nih.gov/soap/eutils/einfo", - operationNamespace); - } - - @Test - public void testGetOperationElementQName() throws Exception { - WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl")); - QName operationQName = parser.getOperationQname("run_eInfo"); - assertEquals("element name is wrong", "eInfoRequest", operationQName - .getLocalPart()); - assertEquals("operation namespace is wrong", - "http://www.ncbi.nlm.nih.gov/soap/eutils/einfo", operationQName - .getNamespaceURI()); - } - - @Test - public void testGetOperationElementQName2() throws Exception { - URL tav744Url = getClass().getResource( - "/net/sf/taverna/wsdl/parser/TAV-744/InstrumentService__.wsdl"); - WSDLParser parser = new WSDLParser(tav744Url.toExternalForm()); - QName operationQName = parser.getOperationQname("getList"); - assertEquals("operation element name is wrong", "GetListRequest", - operationQName.getLocalPart()); - assertEquals("operation namespace is wrong", - "http://InstrumentService.uniparthenope.it/InstrumentService", - operationQName.getNamespaceURI()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSRFParserTest.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSRFParserTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSRFParserTest.java deleted file mode 100644 index 8c6cede..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSRFParserTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.wsdl.parser; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.net.URL; - -import org.junit.Before; -import org.junit.Test; - -/** - * Check that WSDLParser can detect WSRF. - * Tests {@link WSDLParser#checkWSRF()} - * - * @author Stian Soiland-Reyes - * - */ -public class WSRFParserTest { - - private URL counterServiceWSDL; - private WSDLParser wsdlParser; - - @Before - public void findWSDL() { - String path = "wsrf/counterService/CounterService_.wsdl"; - counterServiceWSDL = getClass().getResource(path); - assertNotNull("Coult not find test WSDL " + path, counterServiceWSDL); - } - - @Test - public void isWSRF() throws Exception { - wsdlParser = new WSDLParser(counterServiceWSDL.toExternalForm()); - assertTrue("Not recognized as WSRF service", wsdlParser.isWsrfService()); - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/EncodedBodyBuilderTest.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/EncodedBodyBuilderTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/EncodedBodyBuilderTest.java deleted file mode 100644 index 141305b..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/EncodedBodyBuilderTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.wsdl.soap; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import net.sf.taverna.wsdl.parser.WSDLParser; -import net.sf.taverna.wsdl.testutils.LocationConstants; -import net.sf.taverna.wsdl.testutils.WSDLTestHelper; - -import org.apache.axis.message.SOAPBodyElement; -import org.junit.Test; - - -public class EncodedBodyBuilderTest implements LocationConstants { - - private String wsdlResourcePath(String wsdlName) throws Exception { - return WSDLTestHelper.wsdlResourcePath(wsdlName); - } - - @Test - public void testSimpleCase() throws Exception { - Map<String,Object> inputMap = new HashMap<String, Object>(); - - BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-rpcencoded.wsdl"), "countString"); - - assertTrue("Wrong type of builder created",builder instanceof EncodedBodyBuilder); - - inputMap.put("str", "Roger Ramjet"); - SOAPBodyElement body = builder.build(inputMap); - - String xml = body.getAsString(); - - assertTrue("Contents of body are not as expected: actual body:"+xml,xml.contains("<str xsi:type=\"xsd:string\">Roger Ramjet</str>")); - } - - @Test - public void testStringArray() throws Exception { - Map<String,Object> inputMap = new HashMap<String, Object>(); - - BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-rpcencoded.wsdl"), "countStringArray"); - - assertTrue("Wrong type of builder created",builder instanceof EncodedBodyBuilder); - List<String> array=new ArrayList<String>(); - array.add("one"); - array.add("two"); - array.add("three"); - inputMap.put("array", array); - SOAPBodyElement body = builder.build(inputMap); - - String xml = body.getAsString(); - - assertTrue("Contents of body are not as expected: actual body:"+xml,xml.contains("<string>one</string><string>two</string><string>three</string>")); - } - - @Test - public void testComplexType() throws Exception { - BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-rpcencoded.wsdl"), "personToString"); - - assertTrue("Wrong type of builder created",builder instanceof EncodedBodyBuilder); - - String p = "<Person xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><name xsi:type=\"xsd:string\">bob</name><age xsi:type=\"xsd:int\">12</age></Person>"; - - Map<String,Object> inputMap = new HashMap<String, Object>(); - - inputMap.put("p",p); - SOAPBodyElement body = builder.build(inputMap); - - String xml = body.getAsString(); - - System.out.println(xml); - - assertTrue("Type definition of Person is missing",xml.contains("<p xsi:type=\"ns1:Person\">")); - assertFalse("There shouldn't be ns2 declaration",xml.contains("xmlns:ns2")); - assertTrue("Missing data content",xml.contains("<name xsi:type=\"xsd:string\">bob</name><age xsi:type=\"xsd:int\">12</age>")); - - } - - protected BodyBuilder createBuilder(String wsdl, String operation) throws Exception { - WSDLParser parser = new WSDLParser(wsdl); - - return BodyBuilderFactory.instance().create(parser, operation, parser.getOperationInputParameters(operation)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/LiteralBodyBuilderTest.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/LiteralBodyBuilderTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/LiteralBodyBuilderTest.java deleted file mode 100644 index 340f885..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/LiteralBodyBuilderTest.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.wsdl.soap; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.namespace.QName; - -import net.sf.taverna.wsdl.parser.WSDLParser; -import net.sf.taverna.wsdl.testutils.LocationConstants; -import net.sf.taverna.wsdl.testutils.WSDLTestHelper; - -import org.apache.axis.message.SOAPBodyElement; -import org.junit.Ignore; -import org.junit.Test; -import org.w3c.dom.Node; - -public class LiteralBodyBuilderTest implements LocationConstants{ - - private String wsdlResourcePath(String wsdlName) throws Exception { - return WSDLTestHelper.wsdlResourcePath(wsdlName); - } - - @Test - public void testUnqualifiedNamespaces() throws Exception { - BodyBuilder builder = createBuilder(wsdlResourcePath("whatizit.wsdl"), "queryPmid"); - - assertTrue("Is is the wrong type, it should be LiteralBodyBuilder",builder instanceof LiteralBodyBuilder); - - String parameters = "<parameters xmlns=\"http://www.ebi.ac.uk/webservices/whatizit/ws\"><pipelineName xmlns=\"\">swissProt</pipelineName><pmid xmlns=\"\">1234</pmid></parameters>"; - Map<String,Object> inputMap = new HashMap<String, Object>(); - inputMap.put("parameters", parameters); - - SOAPBodyElement body = builder.build(inputMap); - - String xml = body.getAsString(); - - assertTrue("Content of body is incorrect in the definition of the pipelineName and pmid:"+xml,xml.contains("<pipelineName xmlns=\"\">swissProt</pipelineName><pmid xmlns=\"\">1234</pmid>")); - assertTrue("Wrapping element should have its namespace declared",xml.contains("<ns1:queryPmid")); - } - - @Test - public void testQualifiedUnwrapped() throws Exception { - BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-unwrapped.wsdl"), "countString"); - - assertTrue("Is is the wrong type, it should be LiteralBodyBuilder",builder instanceof LiteralBodyBuilder); - Map<String,Object>inputMap = new HashMap<String, Object>(); - inputMap.put("str", "bob"); - - String xml = builder.build(inputMap).getAsString(); - - assertEquals("XML should containe qualifed namespace for str",xml,"<ns1:str xmlns:ns1=\"http://testing.org\">bob</ns1:str>"); - } - - @Test - public void testUnwrappedSimple() throws Exception { - BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-unwrapped.wsdl"), "countString"); - - assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder); - - Map<String,Object> inputMap = new HashMap<String, Object>(); - inputMap.put("str", "12345"); - - SOAPBodyElement body = builder.build(inputMap); - - assertEquals("Input element should be named str:","str",body.getNodeName()); - assertEquals("Value should be 12345:","12345",body.getFirstChild().getNextSibling().getNodeValue()); - } - - @Test - public void testUnwrappedArray() throws Exception { - BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-unwrapped.wsdl"), "countStringArray"); - - assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder); - - Map<String,Object> inputMap = new HashMap<String, Object>(); - inputMap.put("array", "<array><item>1</item><item>2</item><item>3</item></array>"); - - SOAPBodyElement body = builder.build(inputMap); - - String xml = body.getAsString(); - assertEquals("Outer element should be named array. xml = "+xml,"array",body.getNodeName()); - - Node itemElement = body.getFirstChild().getNextSibling(); - assertEquals("Array element should be named item. xml = "+xml,"item",itemElement.getNodeName()); - assertEquals("First Array element should have the value '1'. xml = "+xml,"1",itemElement.getFirstChild().getNodeValue()); - } - - @Test - public void testOperationElementNameEUtils() throws Exception { - BodyBuilder builder = createBuilder(wsdlResourcePath("eutils/eutils_lite.wsdl"), "run_eInfo"); - - assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder); - Map<String,Object> inputMap = new HashMap<String, Object>(); - inputMap.put("parameters", - // Note: Don't use xmlns="" as it would also affect <parameters> - // - which should not affect the namespace of the soap body - // element. The element qname of the SOAPBodyElement should be - // determined by the schema only - "<parameters xmlns:e='http://www.ncbi.nlm.nih.gov/soap/eutils/einfo'>" - + "<e:db>database</e:db>" + "<e:tool>myTool</e:tool>" - + "<e:email>nob...@nowhere.net</e:email>" - + "</parameters>"); - SOAPBodyElement body = builder.build(inputMap); - assertEquals("QName of SOAP body's element did not match expected qname ", - new QName("http://www.ncbi.nlm.nih.gov/soap/eutils/einfo", "eInfoRequest"), - body.getQName()); - } - - @Test - public void testOperationElementNameTAV744() throws Exception { - URL tav744Url = getClass().getResource( - "/net/sf/taverna/wsdl/parser/TAV-744/InstrumentService__.wsdl"); - - BodyBuilder builder = createBuilder(tav744Url.toExternalForm(), "getList"); - - assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder); - Map<String,Object> inputMap = new HashMap<String, Object>(); - // No inputs - SOAPBodyElement body = builder.build(inputMap); - assertEquals("QName of SOAP body's element did not match expected qname ", - new QName("http://InstrumentService.uniparthenope.it/InstrumentService", "GetListRequest"), - body.getQName()); - } - - @Test - public void testRPCLiteral() throws Exception { - BodyBuilder builder = createBuilder(wsdlResourcePath("MyService-rpc-literal.wsdl"), "countString"); - - assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder); - - Map<String,Object> inputMap = new HashMap<String, Object>(); - inputMap.put("str", "abcdef"); - - SOAPBodyElement body = builder.build(inputMap); - - assertEquals("Outer element should be named countString","countString",body.getNodeName()); - Node strNode = body.getFirstChild(); - assertEquals("Inner element should be called 'str'","str",strNode.getNodeName()); - assertEquals("str content should be abcdef","abcdef",strNode.getFirstChild().getNextSibling().getNodeValue()); - } - - protected BodyBuilder createBuilder(String wsdl, String operation) throws Exception { - WSDLParser parser = new WSDLParser(wsdl); - return BodyBuilderFactory.instance().create(parser, operation, parser.getOperationInputParameters(operation)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseEncodedTest.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseEncodedTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseEncodedTest.java deleted file mode 100644 index ab5e7a2..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseEncodedTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2003 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. Authorship - * of the modifications may be determined from the ChangeLog placed at - * the end of this file. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - **************************************************************** - * Source code information - * ----------------------- - * Filename $RCSfile: SOAPResponseEncodedTest.java,v $ - * Revision $Revision: 1.4 $ - * Release status $State: Exp $ - * Last modified on $Date: 2008/08/29 16:15:54 $ - * by $Author: sowen70 $ - * Created on 08-May-2006 - *****************************************************************/ -package net.sf.taverna.wsdl.soap; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import net.sf.taverna.wsdl.parser.WSDLParser; -import net.sf.taverna.wsdl.testutils.LocationConstants; -import net.sf.taverna.wsdl.testutils.WSDLTestHelper; - -import org.apache.axis.message.SOAPBodyElement; -import org.junit.Test; -import org.w3c.dom.Document; - -public class SOAPResponseEncodedTest implements LocationConstants { - private String wsdlResourcePath(String wsdlName) throws Exception { - return WSDLTestHelper.wsdlResourcePath(wsdlName); - } - - @SuppressWarnings("unchecked") - @Test - public void testSimpleRPC() throws Exception { - - WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("ma.wsdl")); - - String xml1 = "<ns1:whatGeneInStageResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"urn:hgu.webservice.services\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><whatGeneInStageReturn soapenc:arrayType=\"ns2:GeneExpressedQueryShortDetails[0]\" xsi:type=\"soapenc:Array\" xmlns:ns2=\"http://SubmissionQuery.WSDLGenerated.hgu\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><agene xsi:type=\"string\">a gene</agene></whatGeneInStageReturn></ns1:whatGeneInStageResponse>"; - - List<SOAPBodyElement> response = new ArrayList<SOAPBodyElement>(); - - DocumentBuilder builder = DocumentBuilderFactory.newInstance() - .newDocumentBuilder(); - Document doc = builder.parse(new ByteArrayInputStream(xml1.getBytes())); - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - SOAPResponseEncodedParser parser = new SOAPResponseEncodedParser(wsdlParser.getOperationOutputParameters("whatGeneInStage")); - parser.setStripAttributes(true); - - Map outputMap = parser.parse(response); - - assertNotNull("no output map returned", outputMap); - - assertEquals("map should contain 1 element", 1, outputMap.size()); - - Object result = outputMap.get("whatGeneInStageReturn"); - - assertNotNull( - "output map should have contained entry for 'whatGeneInStageReturn'", - result); - - assertEquals("output data should be a string", String.class, result.getClass()); - - assertEquals( - "incorrect xml content in output", - "<whatGeneInStageReturn><agene>a gene</agene></whatGeneInStageReturn>", - result.toString()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseLiteralTest.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseLiteralTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseLiteralTest.java deleted file mode 100644 index f756371..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseLiteralTest.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2003 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. Authorship - * of the modifications may be determined from the ChangeLog placed at - * the end of this file. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - **************************************************************** - * Source code information - * ----------------------- - * Filename $RCSfile: SOAPResponseLiteralTest.java,v $ - * Revision $Revision: 1.2 $ - * Release status $State: Exp $ - * Last modified on $Date: 2007/11/30 12:13:37 $ - * by $Author: sowen70 $ - * Created on 11-May-2006 - *****************************************************************/ -package net.sf.taverna.wsdl.soap; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import net.sf.taverna.wsdl.parser.BaseTypeDescriptor; -import net.sf.taverna.wsdl.parser.ComplexTypeDescriptor; -import net.sf.taverna.wsdl.parser.TypeDescriptor; - -import org.apache.axis.message.SOAPBodyElement; -import org.junit.Test; -import org.w3c.dom.Document; - -public class SOAPResponseLiteralTest{ - - @SuppressWarnings("unchecked") - @Test - public void testLiteralParserResultInTextBlock() throws Exception { - List response = new ArrayList(); - String xml = "<testResponse><out><data name="a">some data</data><data name="b">some more data</data></out></testResponse>"; - DocumentBuilder builder = DocumentBuilderFactory.newInstance() - .newDocumentBuilder(); - Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes())); - - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - TypeDescriptor descriptor = new ComplexTypeDescriptor(); - descriptor.setName("testResponse"); - - SOAPResponseLiteralParser parser = new SOAPResponseLiteralParser( - Collections.singletonList(descriptor)); - - Map outputMap = parser.parse(response); - - assertNotNull("no output map returned", outputMap); - assertEquals("map should contain 1 element", 1, outputMap.size()); - - Object testResponse = outputMap.get("testResponse"); - - assertNotNull("there should be an output named 'testReponse'", - testResponse); - assertEquals("output data should be a string", String.class, - testResponse.getClass()); - - assertEquals( - "xml is wrong", - "<testResponse><out><data name="a">some data</data><data name="b">some more data</data></out></testResponse>", - testResponse.toString()); - } - - @SuppressWarnings("unchecked") - @Test - public void testLiteralParser() throws Exception { - List response = new ArrayList(); - String xml = "<testResponse><out><data name=\"a\">some data</data><data name=\"b\">some more data</data></out></testResponse>"; - DocumentBuilder builder = DocumentBuilderFactory.newInstance() - .newDocumentBuilder(); - Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes())); - - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - TypeDescriptor descriptor = new ComplexTypeDescriptor(); - descriptor.setName("testResponse"); - - SOAPResponseLiteralParser parser = new SOAPResponseLiteralParser( - Collections.singletonList(descriptor)); - - Map outputMap = parser.parse(response); - - assertNotNull("no output map returned", outputMap); - assertEquals("map should contain 1 element", 1, outputMap.size()); - - Object testResponse = outputMap.get("testResponse"); - - assertNotNull("there should be an output named 'testReponse'", - testResponse); - assertEquals("output data should be a string", String.class, - testResponse.getClass()); - - assertEquals( - "xml is wrong", - "<testResponse><out><data name=\"a\">some data</data><data name=\"b\">some more data</data></out></testResponse>", - testResponse.toString()); - } - - @SuppressWarnings("unchecked") - @Test - public void testUnwrappedLiteralResponseParsing() throws Exception { - List response = new ArrayList(); - - String xml = "<getStringReturn xmlns=\"http://testing.org\">a string</getStringReturn>"; - DocumentBuilder builder = DocumentBuilderFactory.newInstance() - .newDocumentBuilder(); - Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes())); - - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - TypeDescriptor descriptor = new BaseTypeDescriptor(); - descriptor.setName("getStringReturn"); - - SOAPResponseLiteralParser parser = new SOAPResponsePrimitiveLiteralParser( - Collections.singletonList(descriptor)); - - Map outputMap = parser.parse(response); - - assertNotNull("no output map returned", outputMap); - assertEquals("map should contain 1 element", 1, outputMap.size()); - - Object stringReturn = outputMap.get("getStringReturn"); - - assertEquals("value of data returned is wrong","a string",stringReturn.toString()); - } - - @SuppressWarnings("unchecked") - @Test - public void testEmptyResponse() throws Exception { - List response = new ArrayList(); - - TypeDescriptor descriptor = new BaseTypeDescriptor(); - descriptor.setName("getStringReturn"); - - SOAPResponseLiteralParser parser = new SOAPResponseLiteralParser( - Collections.singletonList(descriptor)); - - Map outputMap = parser.parse(response); - - assertNotNull("no output map returned", outputMap); - assertEquals("map should contain 1 element", 0, outputMap.size()); - } - -} - http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseMultiRefTest.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseMultiRefTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseMultiRefTest.java deleted file mode 100644 index 87390c3..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseMultiRefTest.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (C) 2003 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. Authorship - * of the modifications may be determined from the ChangeLog placed at - * the end of this file. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - **************************************************************** - * Source code information - * ----------------------- - * Filename $RCSfile: SOAPResponseMultiRefTest.java,v $ - * Revision $Revision: 1.4 $ - * Release status $State: Exp $ - * Last modified on $Date: 2008/08/29 16:15:54 $ - * by $Author: sowen70 $ - * Created on 08-May-2006 - *****************************************************************/ -package net.sf.taverna.wsdl.soap; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import net.sf.taverna.wsdl.parser.ComplexTypeDescriptor; -import net.sf.taverna.wsdl.parser.TypeDescriptor; -import net.sf.taverna.wsdl.parser.WSDLParser; -import net.sf.taverna.wsdl.testutils.LocationConstants; -import net.sf.taverna.wsdl.testutils.WSDLTestHelper; - -import org.apache.axis.message.SOAPBodyElement; -import org.junit.Test; -import org.w3c.dom.Document; - -public class SOAPResponseMultiRefTest implements LocationConstants { - - private String wsdlResourcePath(String wsdlName) throws Exception { - return WSDLTestHelper.wsdlResourcePath(wsdlName); - } - - @SuppressWarnings("unchecked") - @Test - public void testMultiRef() throws Exception { - WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("TestServices-rpcencoded.wsdl")); - - List response = new ArrayList(); - - String xml1 = "<ns1:getPersonResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"urn:testing\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><getPersonReturn href=\"#id0\"/></ns1:getPersonResponse>"; - String xml2 = "<multiRef id=\"id0\" soapenc:root=\"0\" soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><age xsi:type=\"soapenc:string\">5</age><name xsi:type=\"soapenc:string\">bob</name></multiRef>"; - - DocumentBuilder builder = DocumentBuilderFactory.newInstance() - .newDocumentBuilder(); - Document doc = builder.parse(new ByteArrayInputStream(xml1.getBytes())); - - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - doc = builder.parse(new ByteArrayInputStream(xml2.getBytes())); - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser( - wsdlParser.getOperationOutputParameters("getPerson")); - parser.setStripAttributes(true); - Map outputMap = parser.parse(response); - - assertNotNull("no output map returned", outputMap); - - assertEquals("map should contain 1 element", 1, outputMap.size()); - - Object getPersonReturn = outputMap - .get("getPersonReturn"); - - assertNotNull( - "output map should have contained entry for 'getPersonReturn'", - getPersonReturn); - - assertEquals("output data should be a string", String.class, - getPersonReturn.getClass()); - - assertEquals( - "unexpected xml content in output", - "<getPersonReturn><age>5</age><name>bob</name></getPersonReturn>", - getPersonReturn.toString()); - - } - - @SuppressWarnings("unchecked") - @Test - public void testMultiRefReturnNamespaced() throws Exception { - WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("TestServices-rpcencoded.wsdl")); - - List response = new ArrayList(); - - String xml1 = "<ns1:getPersonResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"urn:testing\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><ns1:getPersonReturn xmlns:ns1=\"urn:testing\" href=\"#id0\"/></ns1:getPersonResponse>"; - String xml2 = "<multiRef id=\"id0\" soapenc:root=\"0\" soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><age xsi:type=\"soapenc:string\">5</age><name xsi:type=\"soapenc:string\">bob</name></multiRef>"; - - DocumentBuilder builder = DocumentBuilderFactory.newInstance() - .newDocumentBuilder(); - Document doc = builder.parse(new ByteArrayInputStream(xml1.getBytes())); - - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - doc = builder.parse(new ByteArrayInputStream(xml2.getBytes())); - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser( - wsdlParser.getOperationOutputParameters("getPerson")); - parser.setStripAttributes(true); - Map outputMap = parser.parse(response); - - assertNotNull("no output map returned", outputMap); - - assertEquals("map should contain 1 element", 1, outputMap.size()); - - Object getPersonReturn = outputMap - .get("getPersonReturn"); - - assertNotNull( - "output map should have contained entry for 'getPersonReturn'", - getPersonReturn); - - assertEquals("output data should be a string", String.class, - getPersonReturn.getClass()); - - assertEquals( - "unexpected xml content in output", - "<getPersonReturn><age>5</age><name>bob</name></getPersonReturn>", - getPersonReturn.toString()); - } - - @SuppressWarnings("unchecked") - @Test - public void testNestedReferences() throws Exception { - - //only the name is important. - TypeDescriptor descriptor = new ComplexTypeDescriptor(); - descriptor.setName("result"); - SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser( - Collections.singletonList(descriptor)); - - - String xml1 = "<response><result><creatures href=\"#id0\"/></result></response>"; - String xml2 = "<multiref id=\"id0\"><item href=\"#id1\"/><item href=\"#id2\"/></multiref>"; - String xml3 = "<multiref id=\"id1\"><creature>monkey</creature></multiref>"; - String xml4 = "<multiref id=\"id2\"><creature>frog</creature></multiref>"; - - List response = new ArrayList(); - - DocumentBuilder builder = DocumentBuilderFactory.newInstance() - .newDocumentBuilder(); - Document doc = builder.parse(new ByteArrayInputStream(xml1.getBytes())); - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - doc = builder.parse(new ByteArrayInputStream(xml2.getBytes())); - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - doc = builder.parse(new ByteArrayInputStream(xml3.getBytes())); - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - doc = builder.parse(new ByteArrayInputStream(xml4.getBytes())); - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - - parser.setStripAttributes(true); - - Map outputMap = parser.parse(response); - - assertNotNull("no output map returned", outputMap); - - assertEquals("map should contain 1 element", 1, outputMap.size()); - - Object result = outputMap.get("result"); - - assertNotNull("output map should have contained entry for 'result'", - result); - - assertEquals("output data should be a string", String.class, result - .getClass()); - - assertEquals( - "incorrect xml content in output", - "<result><creatures><item><creature>monkey</creature></item><item><creature>frog</creature></item></creatures></result>", - result.toString()); - - } - - @SuppressWarnings("unchecked") - @Test - public void testFailOnCyclic() throws Exception { - List outputNames = new ArrayList(); - outputNames.add("attachmentList"); - outputNames.add("result"); - - String xml1 = "<response><result><item href=\"#id0\"/></result></response>"; - String xml2 = "<multiref id=\"id0\"><item href=\"#id1\"/></multiref>"; - String xml3 = "<multiref id=\"id1\"><item href=\"#id0\"/></multiref>"; - - List response = new ArrayList(); - - DocumentBuilder builder = DocumentBuilderFactory.newInstance() - .newDocumentBuilder(); - Document doc = builder.parse(new ByteArrayInputStream(xml1.getBytes())); - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - doc = builder.parse(new ByteArrayInputStream(xml2.getBytes())); - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - doc = builder.parse(new ByteArrayInputStream(xml3.getBytes())); - response.add(new SOAPBodyElement(doc.getDocumentElement())); - - SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser( - outputNames); - parser.setStripAttributes(true); - - try { - parser.parse(response); - fail("CyclicReferenceException should have been thrown"); - } catch (CyclicReferenceException e) { - - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseParserFactoryTest.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseParserFactoryTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseParserFactoryTest.java deleted file mode 100644 index 2faf887..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseParserFactoryTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.wsdl.soap; - -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import net.sf.taverna.wsdl.parser.WSDLParser; -import net.sf.taverna.wsdl.testutils.LocationConstants; -import net.sf.taverna.wsdl.testutils.WSDLTestHelper; - -import org.junit.Test; - -public class SOAPResponseParserFactoryTest implements LocationConstants { - - private String wsdlResourcePath(String wsdlName) throws Exception { - return WSDLTestHelper.wsdlResourcePath(wsdlName); - } - - //tests that the factory always returns a SOAPResponseLiteralParser regardless of the - //output mime type, if the use is set to 'literal' (unwrapped/literal) - @Test - public void testLiteralUnwrappedParserForNonXMLOutput() throws Exception { - SOAPResponseParserFactory factory = SOAPResponseParserFactory.instance(); - List<String> response = new ArrayList<String>(); - WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("TestServices-unwrapped.wsdl")); - - SOAPResponseParser parser = factory.create(response, "literal", "document", wsdlParser.getOperationOutputParameters("getString")); - - assertTrue("The parser is the wrong type, it was:"+parser.getClass().getSimpleName(),parser instanceof SOAPResponsePrimitiveLiteralParser); - } - - //an additional test using another unwrapped/literal wsdl that returns a primative type - @Test - public void testLiteralUnwrappedAlternativeWSDL() throws Exception { - SOAPResponseParserFactory factory = SOAPResponseParserFactory.instance(); - List<String> response = new ArrayList<String>(); - WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("prodoric.wsdl")); - - SOAPResponseParser parser = factory.create(response, "literal", "document", wsdlParser.getOperationOutputParameters("hello")); - - assertTrue("The parser is the wrong type, it was:"+parser.getClass().getSimpleName(),parser instanceof SOAPResponsePrimitiveLiteralParser); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/testutils/LocationConstants.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/testutils/LocationConstants.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/testutils/LocationConstants.java deleted file mode 100644 index 437820f..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/testutils/LocationConstants.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.wsdl.testutils; - -/** - * A definition of constants for base locations of external resources used for testing. - * - * @author Stuart Owen - * - */ -public interface LocationConstants { - - public static final String WSDL_RESOURCE_BASE="/testwsdls/"; -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/testutils/WSDLTestHelper.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/testutils/WSDLTestHelper.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/testutils/WSDLTestHelper.java deleted file mode 100644 index 66c91ff..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/testutils/WSDLTestHelper.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.wsdl.testutils; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import net.sf.taverna.wsdl.parser.WSDLParserTest; - -public class WSDLTestHelper implements LocationConstants { - - public static String wsdlResourcePath(String resourceName) throws Exception { - return WSDLParserTest.class.getResource(WSDL_RESOURCE_BASE+resourceName).toExternalForm(); - } - - public String getResourceContentsString(String resourceName) throws Exception { - InputStream stream = WSDLTestHelper.class.getResourceAsStream("/"+resourceName); - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - String content=""; - String line=""; - while( (line = reader.readLine()) != null) { - content+=line; - } - - reader.close(); - - return content; - - } - - - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2e8f451e/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/xmlsplitter/XMLInputSplitterTest.java ---------------------------------------------------------------------- diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/xmlsplitter/XMLInputSplitterTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/xmlsplitter/XMLInputSplitterTest.java deleted file mode 100644 index 9be24c4..0000000 --- a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/xmlsplitter/XMLInputSplitterTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.wsdl.xmlsplitter; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.HashMap; -import java.util.Map; - -import net.sf.taverna.wsdl.parser.TypeDescriptor; -import net.sf.taverna.wsdl.parser.WSDLParser; -import net.sf.taverna.wsdl.testutils.LocationConstants; -import net.sf.taverna.wsdl.testutils.WSDLTestHelper; - -import org.junit.Ignore; -import org.junit.Test; - -public class XMLInputSplitterTest implements LocationConstants { - - @Test - public void testExecute() throws Exception { - WSDLParser parser = new WSDLParser(WSDLTestHelper.wsdlResourcePath("eutils/eutils_lite.wsdl")); - TypeDescriptor descriptor = parser.getOperationInputParameters("run_eInfo").get(0); - XMLInputSplitter splitter = new XMLInputSplitter(descriptor,new String[]{"db","tool","email"},new String[]{"text/plain","text/plain","text/plain"},new String[]{"output"}); - Map<String,Object> inputMap = new HashMap<String, Object>(); - inputMap.put("db", "pubmed"); - inputMap.put("email", "bob.monkho...@itv.com"); - Map<String,String> outputMap = splitter.execute(inputMap); - assertNotNull("there should be an output named 'output'",outputMap.containsKey("output")); - String xml = outputMap.get("output"); - assertTrue(xml.startsWith("<parameters xmlns=\"http://www.ncbi.nlm.nih.gov/soap/eutils/einfo\">")); - assertTrue(xml.contains("<db>pubmed</db>")); - assertTrue(! xml.contains("<tool")); - assertTrue(xml.contains("<email>bob.monkho...@itv.com</email>")); - } - - - @Test - public void testOptional() throws Exception { - WSDLParser parser = new WSDLParser(WSDLTestHelper.wsdlResourcePath("VSOi.wsdl")); - TypeDescriptor descriptor = parser.getOperationInputParameters("Query").get(0); - XMLInputSplitter splitter = new XMLInputSplitter(descriptor,new String[]{"version","block"},new String[]{"text/plain","text/plain"},new String[]{"output"}); - Map<String,Object> inputMap = new HashMap<String, Object>(); - // connect none of the inputs - Map<String,String> outputMap = splitter.execute(inputMap); - assertNotNull("there should be an output named 'output'",outputMap.containsKey("output")); - String xml = outputMap.get("output"); - // empty string as <block> as it is not nillable - assertTrue(xml.contains("<block xmlns=\"\"></block>")); - // minOccurs=0 - so it should not be there - assertTrue(! xml.contains("<version>")); - } - - - @Test - public void testNillable() throws Exception { - WSDLParser parser = new WSDLParser(WSDLTestHelper.wsdlResourcePath("VSOi.wsdl")); - TypeDescriptor descriptor = parser.getOperationInputParameters("Query").get(0); - XMLInputSplitter splitter = new XMLInputSplitter(descriptor,new String[]{"version","block"},new String[]{"text/plain","text/plain"},new String[]{"output"}); - Map<String,Object> inputMap = new HashMap<String, Object>(); - // Magic string meaning insert xsi:nil=true - inputMap.put("version", "xsi:nil"); - Map<String,String> outputMap = splitter.execute(inputMap); - assertNotNull("there should be an output named 'output'",outputMap.containsKey("output")); - String xml = outputMap.get("output"); - System.out.println(xml); - // empty string as <block> as it is not nillable - assertTrue(xml.contains("<block xmlns=\"\"></block>")); - // FIXME: Should not really allow nil=true here, as version is not nillable! - assertTrue(xml.contains("<version xmlns=\"\" " + - "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + - "xsi:nil=\"true\" />")); - } - - -}