You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by sa...@apache.org on 2009/09/01 07:50:51 UTC
svn commit: r809833 [8/10] - in /webservices/woden/trunk/java/woden-tests:
./ src/ src/main/ src/main/resources/ src/main/resources/META-INF/
src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/
src/test/java/org/apache/woden/ src/test...
Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/InterfaceMessageReferenceElementTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/InterfaceMessageReferenceElementTest.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/InterfaceMessageReferenceElementTest.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/InterfaceMessageReferenceElementTest.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.wsdl20.xml;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.net.URI;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.internal.schema.InlinedSchemaImpl;
+import org.apache.woden.internal.wsdl20.InterfaceMessageReferenceImpl;
+import org.apache.woden.schema.InlinedSchema;
+import org.apache.woden.types.NCName;
+import org.apache.woden.types.QNameTokenUnion;
+import org.apache.woden.wsdl20.enumeration.Direction;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.xerces.parsers.DOMParser;
+import org.apache.xerces.xni.parser.XMLInputSource;
+import org.w3c.dom.Document;
+
+
+
+/**
+ * Unit tests for the InterfaceMessageReferenceElement class.
+ *
+ * @author Graham Turrell (gturrell@apache.org)
+ */
+public class InterfaceMessageReferenceElementTest extends TestCase {
+
+ private InterfaceMessageReferenceElement fMessageReferenceElement = null;
+
+ public static Test suite()
+ {
+ return new TestSuite(InterfaceMessageReferenceElementTest.class);
+
+ }
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ fMessageReferenceElement = new InterfaceMessageReferenceImpl();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ /*
+ * Test that a (mandatory) direction can be successfully set and retrieved
+ */
+ public void testSetGetDirection()
+ {
+ // Default case
+ assertNull("The retrieved Direction when unset should be null", fMessageReferenceElement.getDirection());
+
+ fMessageReferenceElement.setDirection(Direction.OUT);
+ assertEquals("The retrieved MessageReference direction is not that which was set",
+ Direction.OUT, fMessageReferenceElement.getDirection());
+ }
+
+ /*
+ * Test that the (Mandatory) message label attribute ("messageLabel") can be successfully set and retrieved
+ */
+ public void testSetGetMessageLabel()
+ {
+ NCName messageRefNCName = new NCName("messageRefName");
+ fMessageReferenceElement.setMessageLabel(messageRefNCName);
+ assertEquals("The retrieved messageLabel is not that which was set",
+ messageRefNCName, fMessageReferenceElement.getMessageLabel());
+ }
+
+ /*
+ * Test that the optional attribute ("element") can be successfully set and retrieved
+ */
+ public void testSetGetElement()
+ {
+ //test with type qname.
+ QNameTokenUnion element = new QNameTokenUnion(new QName("ElementName"));
+ fMessageReferenceElement.setElement(element);
+ assertEquals("The retrieved 'element' attribute is not that which was set",
+ element, fMessageReferenceElement.getElement());
+
+ //test with type token.
+ QNameTokenUnion token = QNameTokenUnion.ANY;
+ fMessageReferenceElement.setElement(token);
+ assertEquals("The retrieved 'element' attribute is not that which was set",
+ token, fMessageReferenceElement.getElement());
+ }
+
+ /*
+ * Test that the optional schema element declaration can be successfully retrieved if
+ * the QNameTokenUnion is of type qname and if it is of type token, that there is no
+ * element declaration returned.
+ *
+ * TODO Need to check model structure for XmlSchema
+ */
+
+ public void testGetXmlSchemaElement() throws Exception
+ {
+ WSDLFactory factory = null;
+ try {
+ factory = WSDLFactory.newInstance();
+ } catch (WSDLException e) {
+ fail("Can't instantiate the WSDLFactory object.");
+ }
+
+ // Create the DescriptionElement->InterfaceElement->InterfaceOperationElement->InterfaceMessageReferenceElement hierarchy
+ DescriptionElement descriptionElement = factory.newDescription();
+ InterfaceElement interfaceElement = descriptionElement.addInterfaceElement();
+ InterfaceOperationElement interfaceOperationElement = interfaceElement.addInterfaceOperationElement();
+ InterfaceMessageReferenceElement messageReference = interfaceOperationElement.addInterfaceMessageReferenceElement();
+
+ // Default case:
+ XmlSchemaElement retrievedElement = messageReference.getXmlSchemaElement();
+ assertNull("Should return null if 'element' attribute is not set", retrievedElement);
+
+ // Case 1 - (with 'element' set to #any)
+ messageReference.setElement(QNameTokenUnion.ANY);
+ retrievedElement = messageReference.getXmlSchemaElement();
+ assertNull("Should return null if 'element' attribute is #any", retrievedElement);
+
+ // Case 2 - (with 'element' set to #none)
+ messageReference.setElement(QNameTokenUnion.NONE);
+ retrievedElement = messageReference.getXmlSchemaElement();
+ assertNull("Should return null if 'element' attribute is #none", retrievedElement);
+
+ // Case 3 - (with 'element' set to #other)
+ messageReference.setElement(QNameTokenUnion.OTHER);
+ retrievedElement = messageReference.getXmlSchemaElement();
+ assertNull("Should return null if 'element' attribute is #other", retrievedElement);
+
+ // Case 4 - (with 'element' set to the qname of a schema element declaration)
+ TypesElement typesElement = descriptionElement.addTypesElement(); //throws WSDLException
+ InlinedSchema schema = new InlinedSchemaImpl();
+ String schemaString = "<schema xmlns=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.sample.org\">"
+ + "<complexType name=\"myType\">"
+ + "<sequence>"
+ + "<element name=\"element\" type=\"string\"/>"
+ + "</sequence>"
+ + "</complexType>"
+ + "<element name=\"myElement\" type=\"string\"/>"
+ + "</schema>";
+ DOMParser builder = new DOMParser();
+ Reader reader = new StringReader(schemaString);
+ XMLInputSource is = new XMLInputSource(null,null,null,reader,null);
+ builder.parse(is); //throws IOException
+ Document schemaDoc1 = builder.getDocument();
+ XmlSchemaCollection xsc = new XmlSchemaCollection();
+ XmlSchema xs1 = xsc.read(schemaDoc1.getDocumentElement());
+ schema.setSchemaDefinition(xs1);
+ URI schemaNS = URI.create("http://www.sample.org");
+ schema.setNamespace(schemaNS);
+ typesElement.addSchema(schema);
+
+ QName elemQN = new QName("http://www.sample.org","myElement");
+ XmlSchemaElement expectedElement = xs1.getElementByName(elemQN);
+
+ messageReference.setElement(new QNameTokenUnion(elemQN));
+ retrievedElement = messageReference.getXmlSchemaElement();
+ assertEquals("The 'element' qname should resolve to the expected XML Schema element declaration",
+ expectedElement, retrievedElement);
+ }
+}
Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/InterfaceOperationElementTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/InterfaceOperationElementTest.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/InterfaceOperationElementTest.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/InterfaceOperationElementTest.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,241 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.wsdl20.xml;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.internal.wsdl20.DescriptionImpl;
+import org.apache.woden.types.NCName;
+
+/**
+ * Unit tests for the InterfaceOperationElement class.
+ *
+ * @author Graham Turrell (gturrell@apache.org)
+ */
+
+public class InterfaceOperationElementTest extends TestCase {
+
+ // create a parent Description to hang the Interfaces off
+ private DescriptionElement fDescriptionElement = null;
+ private InterfaceElement fInterfaceElement = null;
+ private InterfaceOperationElement fInterfaceOperationElement = null;
+ private URI fStyleURI1 = null;
+ private URI fStyleURI2 = null;
+ private URI fPattern = null;
+
+ public static Test suite()
+ {
+ return new TestSuite(InterfaceOperationElementTest.class);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ WSDLFactory factory = null;
+ try {
+ factory = WSDLFactory.newInstance();
+ } catch (WSDLException e) {
+ fail("Can't instantiate the WSDLFactory object.");
+ }
+
+ fDescriptionElement = factory.newDescription();
+ fInterfaceElement = fDescriptionElement.addInterfaceElement();
+ fInterfaceOperationElement = fInterfaceElement.addInterfaceOperationElement();
+ fStyleURI1 = new URI("http://www.w3.org/0000/00/apacheStyle");
+ fStyleURI2 = new URI("http://www.w3.org/0000/00/anotherApacheStyle");
+ fPattern = new URI("http://www.w3.org/0000/00/wsdl/in-out");
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ /*
+ * Mandatory attribute ("name")
+ * - setName()
+ * - getName()
+ */
+ public void testGetSetName()
+ {
+ fInterfaceOperationElement.setName(new NCName("interfaceOperationName"));
+ QName retrievedName = fInterfaceOperationElement.getName();
+ assertEquals("Retrieved InterfaceOperationElement name does not match that set -", "interfaceOperationName", retrievedName.toString());
+ }
+
+ /*
+ * Mandatory attribute ("pattern") (message exchange pattern)
+ * - setPattern()
+ * - getPattern()
+ */
+ public void testGetSetPattern()
+ {
+ fInterfaceOperationElement.setPattern(fPattern);
+ URI uri = fInterfaceOperationElement.getPattern();
+ assertEquals("Retrieved InterfaceOperationElement mep does not match that set -", fPattern, uri);
+ }
+
+ /*
+ * Optional attribute ("style")
+ * style comprises a list of URIs
+ * - getStyle() returns the list
+ * - addStyleURI() adds to the list
+ * - removeStyleURI() removes from the list
+ */
+ public void testAddGetRemoveStyle()
+ {
+ // check the default:
+ URI[] style = fInterfaceOperationElement.getStyle();
+ assertNotNull(style);
+ assertEquals("Retrieved InterfaceOperationElement style should be empty if none set -", 0, style.length);
+
+ // addStyleURI() a couple of times
+ fInterfaceOperationElement.addStyleURI(fStyleURI1);
+ fInterfaceOperationElement.addStyleURI(fStyleURI2);
+
+ // getStyle()
+ style = fInterfaceOperationElement.getStyle();
+ assertNotNull(style);
+ assertEquals("Unexpected number of URIs in the style -", 2, style.length);
+ // check that all added URIs appear in the style
+ List sdL = Arrays.asList(style);
+ assertTrue(sdL.contains(fStyleURI1));
+ assertTrue(sdL.contains(fStyleURI2));
+
+ // removeStyleURI()
+ fInterfaceOperationElement.removeStyleURI(fStyleURI1);
+ fInterfaceOperationElement.removeStyleURI(fStyleURI2);
+ style = fInterfaceOperationElement.getStyle();
+ assertNotNull(style);
+ assertEquals("Unexpected number of URIs in the style -", 0, style.length);
+ }
+
+ /*
+ * References to Optional child elements "infault" and "outfault"
+ * - addInterfaceFaultReferenceElement()
+ * - getInterfaceFaultReferenceElements()
+ * - removeInterfaceFaultReferenceElement()
+ */
+ public void testAddGetRemoveInterfaceFaultReferenceElements()
+ {
+ // check the default:
+ InterfaceFaultReferenceElement[] ifreArray = fInterfaceOperationElement.getInterfaceFaultReferenceElements();
+ assertNotNull("Expected an array of InterfaceFaultReferenceElement.", ifreArray);
+ assertEquals("Retrieved InterfaceFaultReferenceElement group should be empty if none set -", 0, ifreArray.length);
+
+ // addInterfaceFaultReferenceElement() - create some InterfaceFaultReferenceElements
+ InterfaceFaultReferenceElement ifre1 = fInterfaceOperationElement.addInterfaceFaultReferenceElement();
+ InterfaceFaultReferenceElement ifre2 = fInterfaceOperationElement.addInterfaceFaultReferenceElement();
+
+ // getInterfaceFaultReferenceElements()
+ ifreArray = fInterfaceOperationElement.getInterfaceFaultReferenceElements();
+ assertNotNull("Expected an array of InterfaceFaultReferenceElement.", ifreArray);
+ assertEquals("Retrieved InterfaceFaultReferenceElement group should be same number as those set -", 2, ifreArray.length);
+
+ // verify all fault references returned
+ List ifreL = Arrays.asList(ifreArray);
+ assertTrue(ifreL.contains(ifre1));
+ assertTrue(ifreL.contains(ifre2));
+
+ // removeInterfaceFaultReferenceElement()
+ // 1 - attempt to remove an unadded IFRE
+ InterfaceFaultReferenceElement ifre3 = null;
+ fInterfaceOperationElement.removeInterfaceFaultReferenceElement(ifre3);
+ ifreArray = fInterfaceOperationElement.getInterfaceFaultReferenceElements();
+ assertNotNull("Expected an array of InterfaceFaultReferenceElement.", ifreArray);
+ assertEquals("Retrieved InterfaceFaultReferenceElement group should be same number as those set -", 2, ifreArray.length);
+
+ // 2- remove all added
+ fInterfaceOperationElement.removeInterfaceFaultReferenceElement(ifre1);
+ fInterfaceOperationElement.removeInterfaceFaultReferenceElement(ifre2);
+ ifreArray = fInterfaceOperationElement.getInterfaceFaultReferenceElements();
+ assertNotNull("Expected an array of InterfaceFaultReferenceElement.", ifreArray);
+ assertEquals("Retrieved InterfaceFaultReferenceElement group should be empty if all removed -", 0, ifreArray.length);
+
+ //3 - attempt to remove previously removed from empty list
+ fInterfaceOperationElement.removeInterfaceFaultReferenceElement(ifre2);
+ ifreArray = fInterfaceOperationElement.getInterfaceFaultReferenceElements();
+ assertNotNull("Expected an array of InterfaceFaultReferenceElement.", ifreArray);
+ assertEquals("Retrieved InterfaceFaultReferenceElement group should be empty if all removed -", 0, ifreArray.length);
+ }
+
+ /*
+ * References to Optional child elements "input" and "output"
+ * - addInterfaceMessageReferenceElement()
+ * - getInterfaceMessageReferenceElements()
+ * - removeInterfaceMessageReferenceElement()
+ */
+ public void testAddGetRemoveInterfaceMessageReferenceElements()
+ {
+ // check the default:
+ InterfaceMessageReferenceElement[] imreArray = fInterfaceOperationElement.getInterfaceMessageReferenceElements();
+ assertNotNull("Expected an array of InterfaceMessageReferenceElement.", imreArray);
+ assertEquals("Retrieved InterfaceFaultReferenceElement group should be empty if none set -", 0, imreArray.length);
+
+ // addInterfaceMessageReferenceElement() - create some addInterfaceMessageReferenceElements
+ InterfaceMessageReferenceElement imre1 = fInterfaceOperationElement.addInterfaceMessageReferenceElement();
+ InterfaceMessageReferenceElement imre2 = fInterfaceOperationElement.addInterfaceMessageReferenceElement();
+
+ // getInterfaceMessageReferenceElements()
+ imreArray = fInterfaceOperationElement.getInterfaceMessageReferenceElements();
+ assertNotNull("Expected an array of InterfaceMessageReferenceElement.", imreArray);
+ assertEquals("Retrieved InterfaceMessageReferenceElement group should be same number as those set -", 2, imreArray.length);
+
+ // verify all fault references returned
+ List imreL = Arrays.asList(imreArray);
+ assertTrue(imreL.contains(imre1));
+ assertTrue(imreL.contains(imre2));
+
+ // removeInterfaceMessageReferenceElement()
+ // 1 - attempt to remove an unadded IMRE
+ InterfaceMessageReferenceElement imre3 = null;
+ fInterfaceOperationElement.removeInterfaceMessageReferenceElement(imre3);
+ imreArray = fInterfaceOperationElement.getInterfaceMessageReferenceElements();
+ assertNotNull("Expected an array of InterfaceMessageReferenceElement.", imreArray);
+ assertEquals("Retrieved InterfaceMessageReferenceElement group should be same number as those set -", 2, imreArray.length);
+
+ // 2- remove all added
+ fInterfaceOperationElement.removeInterfaceMessageReferenceElement(imre1);
+ fInterfaceOperationElement.removeInterfaceMessageReferenceElement(imre2);
+ imreArray = fInterfaceOperationElement.getInterfaceMessageReferenceElements();
+ assertNotNull("Expected an array of InterfaceMessageReferenceElement.", imreArray);
+ assertEquals("Retrieved InterfaceMessageReferenceElement group should be empty if all removed -", 0, imreArray.length);
+
+ //3 - attempt to remove previously removed from empty list
+ fInterfaceOperationElement.removeInterfaceMessageReferenceElement(imre2);
+ imreArray = fInterfaceOperationElement.getInterfaceMessageReferenceElements();
+ assertNotNull("Expected an array of InterfaceMessageReferenceElement.", imreArray);
+ assertEquals("Retrieved InterfaceMessageReferenceElement group should be empty if all removed -", 0, imreArray.length);
+ }
+}
Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/NameAttributeTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/NameAttributeTest.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/NameAttributeTest.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/NameAttributeTest.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.wsdl20.xml;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.internal.wsdl20.DescriptionImpl;
+import org.apache.woden.types.NCName;
+
+public class NameAttributeTest extends TestCase {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(NameAttributeTest.class);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(NameAttributeTest.class);
+ }
+
+ /**
+ * Create an InterfaceElement but don't add it to a DescriptionElement
+ * and ensure that getQName() returns a QName with a namespace value
+ * of the emptystring.
+ */
+ public void testNamespaceOfGetNameReturnValue() {
+ WSDLFactory factory = null;
+ try {
+ factory = WSDLFactory.newInstance();
+ } catch (WSDLException e) {
+ fail("Can't instantiate the WSDLFactory object.");
+ }
+
+ DescriptionElement de = factory.newDescription();
+ InterfaceElement ie = de.addInterfaceElement();
+ ie.setName(new NCName("foo"));
+ String namespace = ie.getName().getNamespaceURI();
+ assertTrue("namespace value should be \"\" but is " + namespace, namespace.equals(""));
+ }
+}
Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/ServiceElementTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/ServiceElementTest.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/ServiceElementTest.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/ServiceElementTest.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,179 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.wsdl20.xml;
+
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.ErrorHandler;
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.WSDLReader;
+import org.apache.woden.internal.wsdl20.DescriptionImpl;
+import org.apache.woden.internal.wsdl20.ServiceImpl;
+import org.apache.woden.tests.TestErrorHandler;
+import org.apache.woden.types.NCName;
+import org.apache.woden.wsdl20.Description;
+
+/**
+ * Functional verification test of org.apache.woden.wsdl20.xml.ServiceElement.
+ * Checks that the expected API behaviour is supported by the implementation.
+ *
+ * @author jkaputin@apache.org
+ */
+public class ServiceElementTest extends TestCase
+{
+ private WSDLFactory fFactory = null;
+ private WSDLReader fReader = null;
+ private ErrorHandler fHandler = null;
+ private DescriptionElement fParsedDesc = null;
+ private ServiceElement fParsedService = null;
+
+ private String fTargetNS = "http://ws.apache.woden/service";
+ private QName fQName = new QName("urn:woden","dummy");
+
+ public static Test suite()
+ {
+ return new TestSuite(ServiceElementTest.class);
+ }
+
+ protected void setUp() throws Exception
+ {
+ fFactory = WSDLFactory.newInstance();
+ fReader = fFactory.newWSDLReader();
+ fHandler = new TestErrorHandler();
+ fReader.getErrorReporter().setErrorHandler(fHandler);
+
+ URL wsdlURL = getClass().getClassLoader().getResource(
+ "org/apache/woden/wsdl20/xml/resources/ServiceElementTest.wsdl");
+ assertNotNull("Failed to find the WSDL document on the classpath.", wsdlURL);
+
+ Description descComp = fReader.readWSDL(wsdlURL.toString());
+ assertNotNull("The reader did not return a description.", descComp);
+ fParsedDesc = descComp.toElement();
+
+ fParsedService = fParsedDesc.getServiceElements()[0];
+ assertNotNull("The description does not contain a service.", fParsedService);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ fFactory = null;
+ fReader = null;
+ fHandler = null;
+ fParsedDesc = null;
+ fParsedService = null;
+ }
+
+ /**
+ * Test that the getName method returns the expected QName parsed from a WSDL document.
+ */
+ public void testGetNameParsed()
+ {
+ QName qname = fParsedService.getName();
+ assertNotNull("ServiceElement.getName() returned null, but a QName was expected.",
+ qname);
+
+ QName expectedQN = new QName(fTargetNS, "service1");
+ assertTrue("QName returned by ServiceElement.getName() was not the one expected.",
+ expectedQN.equals(qname));
+ }
+
+ /**
+ * Test that the QName specified on the setName method is returned by getName.
+ */
+ public void testSetAndGetName() throws Exception
+ {
+ WSDLFactory factory = null;
+ try {
+ factory = WSDLFactory.newInstance();
+ } catch (WSDLException e) {
+ fail("Can't instantiate the WSDLFactory object.");
+ }
+
+ DescriptionElement descElem = factory.newDescription();
+ descElem.setTargetNamespace(new URI("urn:woden"));
+ ServiceElement service = descElem.addServiceElement();
+ service.setName(new NCName(fQName.getLocalPart()));
+ assertTrue("QName returned by ServiceElement.getName() was not the one set by setName().",
+ fQName.equals(service.getName()));
+ }
+
+ /**
+ * Test that the getInterfaceName method returns the QName of the interface
+ * associated with this service, as specified by the "interface" attribute
+ * of the <service> element in a parsed WSDL document.
+ */
+ public void testGetInterfaceNameParsed()
+ {
+ QName qname = fParsedService.getInterfaceName();
+ assertNotNull("ServiceElement.getInterfaceName() returned null, but a QName was expected.",
+ qname);
+
+ QName expectedQN = new QName(fTargetNS, "interface1");
+ assertTrue("QName returned by ServiceElement.getInterfaceName() was not the one expected.",
+ expectedQN.equals(fParsedService.getInterfaceName()));
+ }
+
+ /**
+ * Test that the QName specified on the setInterfaceName method is returned by
+ * the getInterfaceName method.
+ */
+ public void testSetAndGetInterfaceName()
+ {
+ ServiceElement service = new ServiceImpl();
+ service.setInterfaceName(fQName);
+ QName returnedQN = service.getInterfaceName();
+ assertTrue("QName returned by ServiceElement.getInterfaceName() was not the one set by setInterfaceName().",
+ returnedQN.equals(fQName));
+ }
+
+ /**
+ * Test that the getInterfaceElement method returns an InterfaceElement
+ * defined within the description, that is referred to by QName in the
+ * "interface" attribute of the <service> element of a parsed WSDL
+ * document. This tests that the QName is correctly dereferenced to an object.
+ */
+ public void testGetInterfaceElementParsed()
+ {
+ InterfaceElement interfaceDefined = fParsedDesc.getInterfaceElements()[0];
+ InterfaceElement interfaceReferred = fParsedService.getInterfaceElement();
+ assertNotNull("ServiceElement.getInterfaceElement() returned null, but an InterfaceElement was expected.",
+ interfaceReferred);
+
+ assertTrue("The InterfaceElement returned by ServiceElement.getInterfaceElement() was not the one expected.",
+ interfaceReferred == interfaceDefined);
+ }
+
+ /**
+ * Test that the getEndpointElements method returns an array of the EndpointElements
+ * defined as <endpoint> child elements of the <service> element in
+ * a parsed WSDL document.
+ */
+ public void testGetEndpointElementsParsed()
+ {
+ EndpointElement[] endpoints = fParsedService.getEndpointElements();
+ assertTrue("ServiceElement.getEndpointElements() did not return 3 endpoints, as expected.",
+ endpoints.length == 3);
+ }
+}
Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/TypesElementTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/TypesElementTest.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/TypesElementTest.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/TypesElementTest.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,170 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.wsdl20.xml;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.internal.schema.ImportedSchemaImpl;
+import org.apache.woden.internal.schema.InlinedSchemaImpl;
+import org.apache.woden.internal.wsdl20.TypesImpl;
+import org.apache.woden.schema.ImportedSchema;
+import org.apache.woden.schema.InlinedSchema;
+import org.apache.woden.schema.Schema;
+
+/**
+ * Unit tests for the TypesElement class.
+ *
+ * @author Graham Turrell (gturrell@apache.org)
+ */
+
+public class TypesElementTest extends TestCase {
+
+ private DescriptionElement fDescriptionElement = null;
+ private TypesElement fTypesElement = null;
+ private Schema fInlinedSchema1 = null;
+ private Schema fInlinedSchema2 = null;
+ private Schema fImportedSchema1 = null;
+ private Schema fImportedSchema2 = null;
+ private final String TNS = "http://example.org";
+
+ public static Test suite()
+ {
+ return new TestSuite(TypesElementTest.class);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ WSDLFactory factory = null;
+ factory = WSDLFactory.newInstance();
+ fDescriptionElement = factory.newDescription();
+ fDescriptionElement.setTargetNamespace(URI.create(TNS));
+ fTypesElement = fDescriptionElement.addTypesElement();
+ fInlinedSchema1 = new InlinedSchemaImpl();
+ fInlinedSchema2 = new InlinedSchemaImpl();
+ fImportedSchema1 = new ImportedSchemaImpl();
+ fImportedSchema2 = new ImportedSchemaImpl();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ /*
+ * Test adding both Inlined and Imported schema objects
+ */
+ public void testAddGetSchemas()
+ {
+ Schema[] schemas = fTypesElement.getSchemas();
+ assertEquals(0, schemas.length);
+ fTypesElement.addSchema(fImportedSchema1);
+ fTypesElement.addSchema(fImportedSchema2);
+ fTypesElement.addSchema(fInlinedSchema1);
+ fTypesElement.addSchema(fInlinedSchema2);
+ schemas = fTypesElement.getSchemas();
+ assertNotNull(schemas);
+ assertEquals(4, schemas.length);
+ }
+
+ public void testRemoveSchema()
+ {
+ Schema[] schemas = null;
+ Schema randomSchema = new ImportedSchemaImpl();
+
+ // remove from empty list
+ fTypesElement.removeSchema(randomSchema);
+ schemas = fTypesElement.getSchemas();
+ assertEquals(0, schemas.length);
+
+
+ fTypesElement.addSchema(fImportedSchema1);
+ fTypesElement.addSchema(fImportedSchema2);
+ fTypesElement.addSchema(fInlinedSchema1);
+ fTypesElement.addSchema(fInlinedSchema2);
+ fTypesElement.removeSchema(fInlinedSchema2);
+ schemas = fTypesElement.getSchemas();
+ assertEquals(3, schemas.length);
+ fTypesElement.removeSchema(fImportedSchema1);
+ schemas = fTypesElement.getSchemas();
+ assertEquals(2, schemas.length);
+
+ // attempt to remove an un-added schema
+ fTypesElement.removeSchema(randomSchema);
+ schemas = fTypesElement.getSchemas();
+ assertEquals(2, schemas.length); // number should be unchanged
+
+ fTypesElement.removeSchema(fImportedSchema2);
+ fTypesElement.removeSchema(fInlinedSchema1);
+ schemas = fTypesElement.getSchemas();
+ assertEquals(0, schemas.length);
+ }
+
+ public void testGetImportedSchemas()
+ {
+ fTypesElement.addSchema(fImportedSchema1);
+ fTypesElement.addSchema(fImportedSchema2);
+ fTypesElement.addSchema(fInlinedSchema1);
+ fTypesElement.addSchema(fInlinedSchema2);
+
+ ImportedSchema[] schemas = fTypesElement.getImportedSchemas();
+ assertEquals(2, schemas.length);
+
+ // verify object equivalence
+ List schemaL = Arrays.asList(schemas);
+ assertTrue(schemaL.contains(fImportedSchema1));
+ assertTrue(schemaL.contains(fImportedSchema2));
+
+ }
+
+ public void testGetInlinedSchemas()
+ {
+ fTypesElement.addSchema(fImportedSchema1);
+ fTypesElement.addSchema(fImportedSchema2);
+ fTypesElement.addSchema(fInlinedSchema1);
+ fTypesElement.addSchema(fInlinedSchema2);
+
+ InlinedSchema[] schemas = fTypesElement.getInlinedSchemas();
+ assertEquals(2, schemas.length);
+
+ // verify object equivalence
+ List schemaL = Arrays.asList(schemas);
+ assertTrue(schemaL.contains(fInlinedSchema1));
+ assertTrue(schemaL.contains(fInlinedSchema2));
+ }
+
+ public void testSetGetTypeSystem()
+ {
+ String typeSystem = "http://www.w3.org/2001/XMLSchema";
+ fTypesElement.setTypeSystem(typeSystem);
+ assertEquals(typeSystem, fTypesElement.getTypeSystem());
+ }
+
+}
Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/WSDLElementTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/WSDLElementTest.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/WSDLElementTest.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/xml/WSDLElementTest.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,422 @@
+package org.apache.woden.wsdl20.xml;
+
+import java.net.URI;
+
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.types.NamespaceDeclaration;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
+import org.apache.woden.wsdl20.xml.InterfaceElement;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class WSDLElementTest extends TestCase {
+ private String prefix1 = "prefix1";
+ private String prefix2 = "prefix2";
+ private String prefix3 = "prefix3";
+ private String prefix4 = "prefix4";
+ private String prefix5 = "prefix5";
+ private String prefix6 = "prefix6";
+ private String nonExistantPrefix = "nonExistantPrefix";
+ private URI namespace1 = null;
+ private URI namespace2 = null;
+ private URI namespace3 = null;
+ private URI namespace4 = null;
+ private URI namespace5 = null;
+ private URI namespace6 = null;
+ private URI nonExistantNamespace = null;
+ private WSDLFactory factory = null;
+
+ public static Test suite()
+ {
+ return new TestSuite(WSDLElementTest.class);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ try {
+ factory = WSDLFactory.newInstance();
+ } catch (WSDLException e) {
+ fail("Can't instantiate the WSDLFactory object.");
+ }
+
+ namespace1 = new URI("http://apache.org/namespaceURIa");
+ namespace2 = new URI("http://apache.org/namespaceURIb");
+ namespace3 = new URI("http://apache.org/namespaceURIc");
+ namespace4 = new URI("http://apache.org/namespaceURId");
+ namespace5 = new URI("http://apache.org/namespaceURIe");
+ namespace6 = new URI("http://apache.org/namespaceURIf");
+ nonExistantNamespace = new URI("http://apache.org/nonExistantNamespace");
+ }
+
+ public void testAddGetNamespace() {
+ DescriptionElement descriptionElement = factory.newDescription();
+ descriptionElement.addNamespace(prefix1,namespace1);
+ descriptionElement.addNamespace(null, namespace2);
+
+ //Get namespace and prefix on description
+ URI uri = descriptionElement.getNamespaceURI(prefix1);
+ assertEquals("Retrieved NamespaceURI does not match that set", namespace1, uri);
+
+ String prefix = descriptionElement.getNamespacePrefix(namespace1);
+ assertEquals("Retrieved NamespacePrefix does not match that set", prefix1, prefix);
+
+ //Get default namespace
+ uri = descriptionElement.getNamespaceURI("");
+ assertEquals("Default NamespaceURI does not match that set", namespace2, uri);
+
+ //Get undefined namespace and prefix.
+ assertNull("Null was not returned when a non-existent namespace prefix was given", descriptionElement.getNamespaceURI(nonExistantPrefix));
+ assertNull("Null was not returned when a non-existent namespace URI was given", descriptionElement.getNamespacePrefix(nonExistantNamespace));
+
+ InterfaceElement interfaceElement = descriptionElement.addInterfaceElement();
+ interfaceElement.addNamespace(prefix3, namespace3);
+
+ //Get namespace and prefix on description
+ uri = interfaceElement.getNamespaceURI(prefix1);
+ assertEquals("Retrieved NamespaceURI does not match that set", namespace1, uri);
+
+ prefix = interfaceElement.getNamespacePrefix(namespace1);
+ assertEquals("Retrieved NamespacePrefix does not match that set", prefix1, prefix);
+
+ //Get default namespace on description
+ uri = interfaceElement.getNamespaceURI("");
+ assertEquals("Default NamespaceURI does not match that set", namespace2, uri);
+
+ //Get namespace and prefix on interface
+ uri = interfaceElement.getNamespaceURI(prefix3);
+ assertEquals("Retrieved NamespaceURI does not match that set", namespace3, uri);
+
+ prefix = interfaceElement.getNamespacePrefix(namespace3);
+ assertEquals("Retrieved NamespacePrefix does not match that set", prefix3, prefix);
+
+ //Get undefined namespace and prefix.
+ assertNull("Null was not returned when a non-existent namespace prefix was given", interfaceElement.getNamespaceURI(nonExistantPrefix));
+ assertNull("Null was not returned when a non-existent namespace URI was given", interfaceElement.getNamespacePrefix(nonExistantNamespace));
+
+ InterfaceFaultElement interfaceFaultElement = interfaceElement.addInterfaceFaultElement();
+ interfaceFaultElement.addNamespace(prefix4, namespace4);
+
+ //Get namespace and prefix on description
+ uri = interfaceFaultElement.getNamespaceURI(prefix1);
+ assertEquals("Retrieved NamespaceURI does not match that set", namespace1, uri);
+
+ prefix = interfaceFaultElement.getNamespacePrefix(namespace1);
+ assertEquals("Retrieved NamespacePrefix does not match that set", prefix1, prefix);
+
+ //Get default namespace on description
+ uri = interfaceFaultElement.getNamespaceURI("");
+ assertEquals("Default NamespaceURI does not match that set", namespace2, uri);
+
+ //Get namespace and prefix on interface
+ uri = interfaceFaultElement.getNamespaceURI(prefix3);
+ assertEquals("Retrieved NamespaceURI does not match that set", namespace3, uri);
+
+ prefix = interfaceFaultElement.getNamespacePrefix(namespace3);
+ assertEquals("Retrieved NamespacePrefix does not match that set", prefix3, prefix);
+
+ //Get namespace and prefix on interface fault
+ uri = interfaceFaultElement.getNamespaceURI(prefix4);
+ assertEquals("Retrieved NamespaceURI does not match that set", namespace4, uri);
+
+ prefix = interfaceFaultElement.getNamespacePrefix(namespace4);
+ assertEquals("Retrieved NamespacePrefix does not match that set", prefix4, prefix);
+
+ //Get undefined namespace and prefix.
+ assertNull("Null was not returned when a non-existent namespace prefix was given", interfaceFaultElement.getNamespaceURI(nonExistantPrefix));
+ assertNull("Null was not returned when a non-existent namespace URI was given", interfaceFaultElement.getNamespacePrefix(nonExistantNamespace));
+
+ BindingElement bindingElement = descriptionElement.addBindingElement();
+ bindingElement.addNamespace(prefix5, namespace5);
+
+ //Get namespace and prefix on description
+ uri = bindingElement.getNamespaceURI(prefix1);
+ assertEquals("Retrieved NamespaceURI does not match that set", namespace1, uri);
+
+ prefix = bindingElement.getNamespacePrefix(namespace1);
+ assertEquals("Retrieved NamespacePrefix does not match that set", prefix1, prefix);
+
+ //Get default namespace on description
+ uri = bindingElement.getNamespaceURI("");
+ assertEquals("Default NamespaceURI does not match that set", namespace2, uri);
+
+ //Get namespace and prefix on binding
+ uri = bindingElement.getNamespaceURI(prefix5);
+ assertEquals("Retrieved NamespaceURI does not match that set", namespace5, uri);
+
+ prefix = bindingElement.getNamespacePrefix(namespace5);
+ assertEquals("Retrieved NamespacePrefix does not match that set", prefix5, prefix);
+
+ //Get undefined namespace and prefix.
+ assertNull("Null was not returned when a non-existent namespace prefix was given", bindingElement.getNamespaceURI(nonExistantPrefix));
+ assertNull("Null was not returned when a non-existent namespace URI was given", bindingElement.getNamespacePrefix(nonExistantNamespace));
+
+ BindingFaultElement bindingFaultElement = bindingElement.addBindingFaultElement();
+ bindingFaultElement.addNamespace(prefix6, namespace6);
+
+ //Get namespace and prefix on description
+ uri = bindingFaultElement.getNamespaceURI(prefix1);
+ assertEquals("Retrieved NamespaceURI does not match that set", namespace1, uri);
+
+ prefix = bindingFaultElement.getNamespacePrefix(namespace1);
+ assertEquals("Retrieved NamespacePrefix does not match that set", prefix1, prefix);
+
+ //Get default namespace on description
+ uri = bindingFaultElement.getNamespaceURI("");
+ assertEquals("Default NamespaceURI does not match that set", namespace2, uri);
+
+ //Get namespace and prefix on binding
+ uri = bindingFaultElement.getNamespaceURI(prefix5);
+ assertEquals("Retrieved NamespaceURI does not match that set", namespace5, uri);
+
+ prefix = bindingFaultElement.getNamespacePrefix(namespace5);
+ assertEquals("Retrieved NamespacePrefix does not match that set", prefix5, prefix);
+
+ //Get namespace and prefix on binding fault
+ uri = bindingFaultElement.getNamespaceURI(prefix6);
+ assertEquals("Retrieved NamespaceURI does not match that set", namespace6, uri);
+
+ prefix = bindingFaultElement.getNamespacePrefix(namespace6);
+ assertEquals("Retrieved NamespacePrefix does not match that set", prefix6, prefix);
+
+ //Get undefined namespace and prefix.
+ assertNull("Null was not returned when a non-existent namespace prefix was given", bindingFaultElement.getNamespaceURI(nonExistantPrefix));
+ assertNull("Null was not returned when a non-existent namespace URI was given", bindingFaultElement.getNamespacePrefix(nonExistantNamespace));
+ }
+
+ public void testRemoveNamespace() {
+ //Build up wsdl20 element model.
+ DescriptionElement descriptionElement = factory.newDescription();
+ descriptionElement.addNamespace(prefix1,namespace1);
+ assertNotNull(descriptionElement.getNamespaceURI(prefix1));
+ assertNotNull(descriptionElement.getNamespacePrefix(namespace1));
+
+ TypesElement typesElement = null;
+ try {
+ typesElement = descriptionElement.addTypesElement();
+ } catch (WSDLException e) {
+ //This will never happen as I've only added one types element to the description in since creating it 8 lines above.
+ fail("Unexpected exception was thrown: " + e.getMessage()); //But in case...
+ }
+ typesElement.addNamespace(prefix2, namespace2);
+ assertNotNull(typesElement.getNamespaceURI(prefix2));
+ assertNotNull(typesElement.getNamespacePrefix(namespace2));
+ assertNotNull(typesElement.getNamespaceURI(prefix1));
+ assertNotNull(typesElement.getNamespacePrefix(namespace1));
+
+ DocumentationElement documentationElement = typesElement.addDocumentationElement();
+ documentationElement.addNamespace(prefix3, namespace3);
+ assertNotNull(documentationElement.getNamespaceURI(prefix3));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace3));
+ assertNotNull(documentationElement.getNamespaceURI(prefix2));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace2));
+ assertNotNull(documentationElement.getNamespaceURI(prefix1));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace1));
+
+ //Remove non existant namespace.
+ typesElement.removeNamespace(nonExistantPrefix);
+ assertNotNull(documentationElement.getNamespaceURI(prefix3));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace3));
+ assertNotNull(documentationElement.getNamespaceURI(prefix2));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace2));
+ assertNotNull(documentationElement.getNamespaceURI(prefix1));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace1));
+
+ descriptionElement.removeNamespace(nonExistantPrefix);
+ assertNotNull(documentationElement.getNamespaceURI(prefix3));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace3));
+ assertNotNull(documentationElement.getNamespaceURI(prefix2));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace2));
+ assertNotNull(documentationElement.getNamespaceURI(prefix1));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace1));
+
+ documentationElement.removeNamespace(nonExistantPrefix);
+ assertNotNull(documentationElement.getNamespaceURI(prefix3));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace3));
+ assertNotNull(documentationElement.getNamespaceURI(prefix2));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace2));
+ assertNotNull(documentationElement.getNamespaceURI(prefix1));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace1));
+
+ //Remove namespaces one at a time.
+ descriptionElement.removeNamespace(prefix1);
+ descriptionElement.removeNamespace(prefix2);
+ descriptionElement.removeNamespace(prefix3);
+ assertNotNull(documentationElement.getNamespaceURI(prefix3));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace3));
+ assertNotNull(documentationElement.getNamespaceURI(prefix2));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace2));
+ assertNull(documentationElement.getNamespaceURI(prefix1));
+ assertNull(documentationElement.getNamespacePrefix(namespace1));
+
+ typesElement.removeNamespace(prefix2);
+ typesElement.removeNamespace(prefix3);
+ assertNotNull(documentationElement.getNamespaceURI(prefix3));
+ assertNotNull(documentationElement.getNamespacePrefix(namespace3));
+ assertNull(documentationElement.getNamespaceURI(prefix2));
+ assertNull(documentationElement.getNamespacePrefix(namespace2));
+ assertNull(documentationElement.getNamespaceURI(prefix1));
+ assertNull(documentationElement.getNamespacePrefix(namespace1));
+
+ documentationElement.removeNamespace(prefix3);
+ assertNull(documentationElement.getNamespaceURI(prefix3));
+ assertNull(documentationElement.getNamespacePrefix(namespace3));
+ assertNull(documentationElement.getNamespaceURI(prefix2));
+ assertNull(documentationElement.getNamespacePrefix(namespace2));
+ assertNull(documentationElement.getNamespaceURI(prefix1));
+ assertNull(documentationElement.getNamespacePrefix(namespace1));
+ }
+
+ public void testGetDeclaredAndInScopeNamespaces() {
+ //Test flags
+ boolean ns1;
+ boolean ns2;
+ boolean ns3;
+ boolean ns4;
+ boolean ns5;
+ boolean ns6;
+
+ NamespaceDeclaration[] namespaces;
+
+ //Description with two namespaces.
+ DescriptionElement descriptionElement = factory.newDescription();
+ descriptionElement.addNamespace(prefix1,namespace1);
+ descriptionElement.addNamespace(prefix2,namespace2);
+ //Service on description with two name spaces.
+ ServiceElement serviceElement = descriptionElement.addServiceElement();
+ serviceElement.addNamespace(prefix3, namespace3);
+ serviceElement.addNamespace(prefix4, namespace4);
+ //Endpoint on description with two namespaces
+ EndpointElement endpointElement = serviceElement.addEndpointElement();
+ endpointElement.addNamespace(prefix5, namespace5);
+ endpointElement.addNamespace(prefix6, namespace6);
+
+ //Get description declared name spaces.
+ namespaces = descriptionElement.getDeclaredNamespaces();
+ assertEquals("Expected 2 namespaces", namespaces.length, 2);
+
+ ns1 = false;
+ ns2 = false;
+ for(int i=0; i<namespaces.length; i++) {
+ if (namespaces[i].getNamespaceURI().equals(namespace1) && namespaces[i].getPrefix().equals(prefix1))
+ ns1 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace2) && namespaces[i].getPrefix().equals(prefix2))
+ ns2 = true;
+ }
+
+ assertTrue("Expected NamespaceURI not found", ns1);
+ assertTrue("Expected NamespaceURI not found", ns2);
+
+ //Get description in scope namespaces.
+ namespaces = descriptionElement.getInScopeNamespaces();
+ assertEquals("Expected 2 namespaces", namespaces.length, 2);
+
+ ns1 = false;
+ ns2 = false;
+ for(int i=0; i<namespaces.length; i++) {
+ if (namespaces[i].getNamespaceURI().equals(namespace1) && namespaces[i].getPrefix().equals(prefix1))
+ ns1 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace2) && namespaces[i].getPrefix().equals(prefix2))
+ ns2 = true;
+ }
+
+ assertTrue("Expected NamespaceURI not found", ns1);
+ assertTrue("Expected NamespaceURI not found", ns2);
+
+ //Get service declared name spaces.
+ namespaces = serviceElement.getDeclaredNamespaces();
+ assertEquals("Expected 2 namespaces", namespaces.length, 2);
+
+ ns3 = false;
+ ns4 = false;
+ for(int i=0; i<namespaces.length; i++) {
+ if (namespaces[i].getNamespaceURI().equals(namespace3) && namespaces[i].getPrefix().equals(prefix3))
+ ns3 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace4) && namespaces[i].getPrefix().equals(prefix4))
+ ns4 = true;
+ }
+
+ assertTrue("Expected NamespaceURI not found", ns3);
+ assertTrue("Expected NamespaceURI not found", ns4);
+
+ //Get service in scope namespaces.
+ namespaces = serviceElement.getInScopeNamespaces();
+ assertEquals("Expected 4 namespaces", namespaces.length, 4);
+
+ ns1 = false;
+ ns2 = false;
+ ns3 = false;
+ ns4 = false;
+ for(int i=0; i<namespaces.length; i++) {
+ if (namespaces[i].getNamespaceURI().equals(namespace1) && namespaces[i].getPrefix().equals(prefix1))
+ ns1 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace2) && namespaces[i].getPrefix().equals(prefix2))
+ ns2 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace3) && namespaces[i].getPrefix().equals(prefix3))
+ ns3 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace4) && namespaces[i].getPrefix().equals(prefix4))
+ ns4 = true;
+ }
+
+ assertTrue("Expected NamespaceURI not found", ns1);
+ assertTrue("Expected NamespaceURI not found", ns2);
+ assertTrue("Expected NamespaceURI not found", ns3);
+ assertTrue("Expected NamespaceURI not found", ns4);
+
+ //Get endpoint declared name spaces.
+ namespaces = endpointElement.getDeclaredNamespaces();
+ assertEquals("Expected 2 namespaces", namespaces.length, 2);
+
+ ns5 = false;
+ ns6 = false;
+ for(int i=0; i<namespaces.length; i++) {
+ if (namespaces[i].getNamespaceURI().equals(namespace5) && namespaces[i].getPrefix().equals(prefix5))
+ ns5 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace6) && namespaces[i].getPrefix().equals(prefix6))
+ ns6 = true;
+ }
+
+ assertTrue("Expected NamespaceURI not found", ns5);
+ assertTrue("Expected NamespaceURI not found", ns6);
+
+ //Get endpoint in scope namespaces.
+ namespaces = endpointElement.getInScopeNamespaces();
+ assertEquals("Expected 6 namespaces", namespaces.length, 6);
+
+ ns1 = false;
+ ns2 = false;
+ ns3 = false;
+ ns4 = false;
+ ns5 = false;
+ ns6 = false;
+
+ for(int i=0; i<namespaces.length; i++) {
+ if (namespaces[i].getNamespaceURI().equals(namespace1) && namespaces[i].getPrefix().equals(prefix1))
+ ns1 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace2) && namespaces[i].getPrefix().equals(prefix2))
+ ns2 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace3) && namespaces[i].getPrefix().equals(prefix3))
+ ns3 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace4) && namespaces[i].getPrefix().equals(prefix4))
+ ns4 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace5) && namespaces[i].getPrefix().equals(prefix5))
+ ns5 = true;
+ if (namespaces[i].getNamespaceURI().equals(namespace6) && namespaces[i].getPrefix().equals(prefix6))
+ ns6 = true;
+ }
+
+ assertTrue("Expected NamespaceURI not found", ns1);
+ assertTrue("Expected NamespaceURI not found", ns2);
+ assertTrue("Expected NamespaceURI not found", ns3);
+ assertTrue("Expected NamespaceURI not found", ns4);
+ assertTrue("Expected NamespaceURI not found", ns5);
+ assertTrue("Expected NamespaceURI not found", ns6);
+ }
+}
Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/xml/IntOrTokenAttrTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/xml/IntOrTokenAttrTest.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/xml/IntOrTokenAttrTest.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/xml/IntOrTokenAttrTest.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,161 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.xml;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.ErrorInfo;
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.XMLElement;
+import org.apache.woden.internal.ErrorReporterImpl;
+import org.apache.woden.internal.xml.IntOrTokenAnyAttrImpl;
+import org.apache.woden.tests.TestErrorHandler;
+
+/**
+ * Functional verification test of IntOrTokenAttr.
+ * Checks that the expected API behaviour is supported by the implementation.
+ *
+ * @author jkaputin@apache.org
+ */
+public class IntOrTokenAttrTest extends TestCase
+{
+ private ErrorReporter reporter;
+ private TestErrorHandler handler;
+ private XMLElement el = null; //Element arg not used to initialize this attr
+ private QName qn = new QName("http://wsdl/http","code","whttp");
+ private IntOrTokenAttr attr = null;
+
+ public static Test suite()
+ {
+
+ return new TestSuite(IntOrTokenAttrTest.class);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ handler = new TestErrorHandler();
+ reporter = WSDLFactory.newInstance().newWSDLReader().getErrorReporter();
+ reporter.setErrorHandler(handler);
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ handler = null;
+ reporter = null;
+ attr = null;
+ }
+
+ public void testAttributeType() throws Exception
+ {
+ String attrVal = "#any";
+ attr = new IntOrTokenAnyAttrImpl(el, qn, attrVal, reporter);
+ String expectedQN = qn.toString();
+ String actualQN = attr.getAttributeType().toString();
+ assertEquals("Expected attribute type qname '" + expectedQN + "' but actual qname was '" + actualQN + "'.",
+ expectedQN,
+ actualQN );
+ }
+
+ public void testValidToken() throws Exception
+ {
+ String attrVal = "#any";
+ attr = new IntOrTokenAnyAttrImpl(el, qn, attrVal, reporter);
+
+ assertTrue("isValid() should return true", attr.isValid());
+ assertTrue("getContent() should return instance of 'String' but actual object type was '" + attr.getContent().getClass().getName() + "'.",
+ attr.getContent() instanceof String);
+ assertEquals("Expected toExternalForm() to return '" + attrVal + "' but actual value was '" + attr.toExternalForm() + "'.",
+ attrVal,
+ attr.toExternalForm() );
+
+ assertTrue("isToken() should return true", attr.isToken());
+ assertEquals("Expected getToken() to return the string '#any', but actual string was '" + attr.getToken() + "'.",
+ "#any",
+ attr.getToken() );
+ assertFalse("isInt() should return false", attr.isInt());
+ assertNull("getInt() should return null", attr.getInt());
+ }
+
+ public void testValidInt() throws Exception
+ {
+ String attrVal = "123";
+ attr = new IntOrTokenAnyAttrImpl(el, qn, attrVal, reporter);
+
+ assertTrue("isValid() should return true", attr.isValid());
+ assertTrue("getContent() should return instance of 'Integer' but actual object type was '" + attr.getContent().getClass().getName() + "'.",
+ attr.getContent() instanceof Integer);
+ assertEquals("Expected toExternalForm() to return '" + attrVal + "' but actual value was '" + attr.toExternalForm() + "'.",
+ attrVal,
+ attr.toExternalForm() );
+
+ assertTrue("isInt() should return true", attr.isInt());
+ assertEquals("Expected getInt() to return 123, but actual value was '" + attr.getInt() + "'.",
+ new Integer("123"),
+ attr.getInt() );
+ assertFalse("isToken() should return false", attr.isToken());
+ assertNull("getToken() should return null", attr.getToken());
+ }
+
+ public void testInvalidValue() throws Exception
+ {
+ String attrVal = "#rubbish";
+ attr = new IntOrTokenAnyAttrImpl(el, qn, attrVal, reporter);
+
+ ErrorInfo errInfo = (ErrorInfo)handler.errors.get("WSDL512");
+ assertNotNull("An error should have been reported", errInfo);
+ assertEquals("Error 'WSDL512' expected but error reported was '" + errInfo.getKey() + "'.",
+ "WSDL512",
+ errInfo.getKey());
+
+ assertFalse("isValid() should return false", attr.isValid());
+ assertFalse("isInt() should return false", attr.isInt());
+ assertFalse("isToken() should return false", attr.isToken());
+ assertNull("getInt() should return null", attr.getInt());
+ assertNull("getToken() should return null", attr.getToken());
+ }
+
+ public void testNullValue() throws Exception
+ {
+ String attrVal = null;
+ attr = new IntOrTokenAnyAttrImpl(el, qn, attrVal, reporter);
+
+ ErrorInfo errInfo = (ErrorInfo)handler.errors.get("WSDL512");
+ assertNotNull("An error should have been reported", errInfo);
+ assertEquals("Error 'WSDL512' expected but error reported was '" + errInfo.getKey() + "'.",
+ "WSDL512",
+ errInfo.getKey());
+
+ assertFalse("isValid() should return false", attr.isValid());
+ assertFalse("isInt() should return false", attr.isInt());
+ assertFalse("isToken() should return false", attr.isToken());
+ assertNull("getInt() should return null", attr.getInt());
+ assertNull("getToken() should return null", attr.getToken());
+ }
+}
Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/xml/TokenAttrTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/xml/TokenAttrTest.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/xml/TokenAttrTest.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/xml/TokenAttrTest.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.xml;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.ErrorInfo;
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.XMLElement;
+import org.apache.woden.internal.ErrorReporterImpl;
+import org.apache.woden.internal.xml.TokenAttrImpl;
+import org.apache.woden.tests.TestErrorHandler;
+
+/**
+ * Functional verification test of TokenAttr.
+ * Checks that the expected API behaviour is supported by the implementation.
+ *
+ * @author jkaputin@apache.org
+ */
+public class TokenAttrTest extends TestCase
+{
+ private ErrorReporter reporter;
+ private TestErrorHandler handler;
+ private XMLElement el = null; //Element arg not used to initialize this attr
+ private QName qn = new QName("http://wsdl/http","authenticationScheme","whttp");
+ private TokenAttr attr = null;
+
+ public static Test suite()
+ {
+ return new TestSuite(TokenAttrTest.class);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ handler = new TestErrorHandler();
+ reporter = WSDLFactory.newInstance().newWSDLReader().getErrorReporter();
+ reporter.setErrorHandler(handler);
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ handler = null;
+ reporter = null;
+ attr = null;
+ }
+
+ public void testAttributeType() throws Exception
+ {
+ String attrVal = "#any";
+ attr = new TokenAttrImpl(el, qn, attrVal, reporter);
+ String expectedQN = qn.toString();
+ String actualQN = attr.getAttributeType().toString();
+ assertEquals("Expected attribute type qname '" + expectedQN + "' but actual qname was '" + actualQN + "'.",
+ expectedQN,
+ actualQN );
+ }
+
+ public void testValidToken() throws Exception
+ {
+ String attrVal = "#any";
+ attr = new TokenAttrImpl(el, qn, attrVal, reporter);
+ assertTrue("isValid() should return true", attr.isValid());
+
+ assertNotNull("getToken() should not return null", attr.getToken());
+ assertEquals("Expected attribute value '#any' from getToken(), but actual value was '" + attr.getToken() + "'.",
+ "#any",
+ attr.getToken() );
+ assertTrue("Expected attribute value object to be a 'String' but actual object type was '" + attr.getContent().getClass().getName() + "'.",
+ attr.getContent() instanceof String);
+ assertTrue("Expected external form '#any' but actual was '" + attr.toExternalForm() + "'.",
+ "#any".equals(attr.toExternalForm()) );
+ }
+
+ public void testNullValue() throws Exception
+ {
+ String attrVal = null;
+ attr = new TokenAttrImpl(el, qn, attrVal, reporter);
+
+ ErrorInfo errInfo = (ErrorInfo)handler.errors.get("WSDL508");
+ assertNotNull("An error should have been reported", errInfo);
+ assertEquals("Error 'WSDL508' expected but error reported was '" + errInfo.getKey() + "'.",
+ "WSDL508",
+ errInfo.getKey());
+
+ assertNull("Attribute value is not null", attr.getToken());
+ assertFalse("Attribute value should not be valid", attr.isValid());
+ }
+
+}
Added: webservices/woden/trunk/java/woden-tests/src/test/java/testcase/documentation/extension/DocExtensionNoNSTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/testcase/documentation/extension/DocExtensionNoNSTest.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/testcase/documentation/extension/DocExtensionNoNSTest.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/testcase/documentation/extension/DocExtensionNoNSTest.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,94 @@
+/**
+ * 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 testcase.documentation.extension;
+
+import java.net.URL;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.ErrorHandler;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.WSDLReader;
+import org.apache.woden.resolver.SimpleURIResolverTest;
+import org.apache.woden.tests.TestErrorHandler;
+import org.apache.woden.wsdl20.Description;
+import org.apache.woden.wsdl20.extensions.UnknownExtensionElement;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
+import org.apache.woden.wsdl20.xml.DocumentationElement;
+
+/**
+ * Test that when no default namespace is declared in the WSDL,
+ * that documentation extension elements with no namespace are
+ * represented correctly - they should return a null NS uri.
+ */
+public class DocExtensionNoNSTest extends TestCase {
+
+ public static Test suite()
+ {
+ return new TestSuite(DocExtensionNoNSTest.class);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testNSUriIsNull() throws Exception {
+ URL wsdlURL = getClass().getClassLoader().getResource("testcase/documentation/extension/resources/nonamespace.wsdl");
+ assertNotNull("Failed to find nonamespace.wsdl on the classpath",wsdlURL);
+
+ WSDLFactory factory = WSDLFactory.newInstance();
+ WSDLReader reader = factory.newWSDLReader();
+ ErrorHandler handler = new TestErrorHandler();
+ reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
+ reader.getErrorReporter().setErrorHandler(handler);
+ Description descComp = reader.readWSDL(wsdlURL.toString());
+ assertNotNull("The reader did not return a WSDL description.", descComp);
+ DescriptionElement desc = descComp.toElement();
+
+ DocumentationElement doc = null;
+ UnknownExtensionElement ee = null;
+
+ //wsdl:description
+ doc = desc.getDocumentationElements()[0];
+ ee = (UnknownExtensionElement)doc.getExtensionElements()[0];
+ assertNull(ee.getElement().getNamespaceURI());
+
+ //wsdl:types
+ doc=desc.getTypesElement().getDocumentationElements()[0];
+ ee = (UnknownExtensionElement)doc.getExtensionElements()[0];
+ assertNull(ee.getElement().getNamespaceURI());
+
+ //wsdl:interface
+ doc=desc.getInterfaceElements()[0].getDocumentationElements()[0];
+ ee = (UnknownExtensionElement)doc.getExtensionElements()[0];
+ assertNull(ee.getElement().getNamespaceURI());
+
+ //wsdl:binding
+ doc=desc.getBindingElements()[0].getDocumentationElements()[0];
+ ee = (UnknownExtensionElement)doc.getExtensionElements()[0];
+ assertNull(ee.getElement().getNamespaceURI());
+
+ //wsdl:service
+ doc=desc.getServiceElements()[0].getDocumentationElements()[0];
+ ee = (UnknownExtensionElement)doc.getExtensionElements()[0];
+ assertNull(ee.getElement().getNamespaceURI());
+ }
+
+}
Added: webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensions.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensions.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensions.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensions.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,27 @@
+/**
+ * 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 testcase.extensions.foo;
+
+import org.apache.woden.wsdl20.extensions.ComponentExtensionContext;
+
+public interface FooBindingExtensions extends ComponentExtensionContext {
+
+ public Integer getFooBar();
+
+ public String getFooBaz();
+
+}
Added: webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensionsImpl.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensionsImpl.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensionsImpl.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensionsImpl.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,87 @@
+/**
+ * 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 testcase.extensions.foo;
+
+import java.net.URI;
+
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.wsdl20.WSDLComponent;
+import org.apache.woden.wsdl20.extensions.BaseComponentExtensionContext;
+import org.apache.woden.wsdl20.extensions.ExtensionProperty;
+import org.apache.woden.wsdl20.xml.WSDLElement;
+import org.apache.woden.xml.StringAttr;
+
+public class FooBindingExtensionsImpl extends BaseComponentExtensionContext
+ implements FooBindingExtensions {
+
+ public FooBindingExtensionsImpl(WSDLComponent parent,
+ URI extNamespace, ErrorReporter errReporter) {
+
+ super(parent, extNamespace, errReporter);
+ }
+
+ /* ************************************************************
+ * Methods declared by ComponentExtensionContext
+ *
+ * These are the abstract methods inherited from BaseComponentExtensionContext,
+ * to be implemented by this subclass.
+ * ************************************************************/
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.wsdl20.extensions.ComponentExtensionContext#getProperties()
+ */
+ public ExtensionProperty[] getProperties() {
+
+ return new ExtensionProperty[] {
+ getProperty(FooConstants.PROP_FOO_BAR),
+ getProperty(FooConstants.PROP_FOO_BAZ)};
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.wsdl20.extensions.ComponentExtensionContext#getProperty(java.lang.String)
+ */
+ public ExtensionProperty getProperty(String propertyName) {
+
+ if(FooConstants.PROP_FOO_BAR.equals(propertyName)) {
+ return newExtensionProperty(FooConstants.PROP_FOO_BAR, getFooBar());
+
+ } else if(FooConstants.PROP_FOO_BAZ.equals(propertyName)) {
+ return newExtensionProperty(FooConstants.PROP_FOO_BAZ, getFooBaz());
+
+ } else {
+ return null; //the specified property name does not exist
+ }
+
+ }
+
+ /* ************************************************************
+ * Additional methods declared by FooBindingExtensions
+ * ************************************************************/
+
+ public Integer getFooBar() {
+ FooOddAttr def = (FooOddAttr) ((WSDLElement) getParent()).getExtensionAttribute(FooConstants.Q_ATTR_BAR);
+ return def != null ? new Integer(def.getValue()) : null;
+ }
+
+ public String getFooBaz() {
+ StringAttr def = (StringAttr) ((WSDLElement) getParent()).getExtensionAttribute(FooConstants.Q_ATTR_BAZ);
+ return def != null ? def.getString() : null;
+ }
+
+}
Added: webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensionsTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensionsTest.java?rev=809833&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensionsTest.java (added)
+++ webservices/woden/trunk/java/woden-tests/src/test/java/testcase/extensions/foo/FooBindingExtensionsTest.java Tue Sep 1 05:50:45 2009
@@ -0,0 +1,119 @@
+/**
+ * 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 testcase.extensions.foo;
+
+import java.net.URL;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.WSDLReader;
+import org.apache.woden.tests.TestErrorHandler;
+import org.apache.woden.wsdl20.Binding;
+import org.apache.woden.wsdl20.Description;
+import org.apache.woden.wsdl20.extensions.ExtensionRegistry;
+
+/**
+ * @author Peter Danielsen
+ *
+ */
+public class FooBindingExtensionsTest extends TestCase {
+
+ private WSDLReader fReader;
+ private Binding[] fBindings = null;
+ private String fWsdlPath = "testcase/extensions/foo/resources/FooBindingExtensions.wsdl";
+ private TestErrorHandler testErrorHandler = null;
+
+ public static Test suite() {
+ return new TestSuite(FooBindingExtensionsTest.class);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ System.setProperty(ExtensionRegistry.REGISTRAR_PROPERTY,
+ "testcase.extensions.foo.FooExtensionRegistrar");
+ WSDLFactory factory = WSDLFactory.newInstance();
+ fReader = factory.newWSDLReader();
+ testErrorHandler = new TestErrorHandler();
+ //Don't set validation on, as the testcase WSDL is not intended to be a valid WSDL 2.0 doc.
+ fReader.getErrorReporter().setErrorHandler(testErrorHandler);
+
+
+ URL wsdlURL = getClass().getClassLoader().getResource(fWsdlPath);
+ assertNotNull("Failed to find the WSDL document on the classpath using the path: " + fWsdlPath + ".",
+ wsdlURL);
+
+ Description descComp = fReader.readWSDL(wsdlURL.toString());
+ assertNotNull("The reader did not return a WSDL description.", descComp);
+
+ fBindings = descComp.getBindings();
+ assertEquals("The Description should contain 2 Binding components.", 2, fBindings.length);
+ }
+
+ /**
+ * Test that the value for the {bar} property returned by the <code>getFooBar</code>
+ * method matches the expected value parsed from the WSDL.
+ */
+ public void testGetFooBar() {
+ Binding binding = null;
+ FooBindingExtensions exts = null;
+ binding = fBindings[0];
+ exts = (FooBindingExtensions)binding
+ .getComponentExtensionContext(FooConstants.NS_URI_FOO);
+ assertNotNull("The Binding '" + binding.getName() + "' does not contain an FooBindingExtensions object.",
+ exts);
+ Integer actual = exts.getFooBar();
+ assertEquals("Unexpected number of errors", 1, testErrorHandler.numErrors);
+ assertEquals("Unexpected error key", "Errors: FOO-001 \n", testErrorHandler.getSummaryOfMessageKeys());
+
+ binding = fBindings[1];
+ exts = (FooBindingExtensions)binding
+ .getComponentExtensionContext(FooConstants.NS_URI_FOO);
+ assertNotNull("The Binding '" + binding.getName() + "' does not contain an FooBindingExtensions object.",
+ exts);
+
+ actual = exts.getFooBar();
+ assertNotNull("The value for bar was null", actual);
+ assertEquals("Unexpected value for bar.", 3, actual.intValue());
+ }
+
+ /**
+ * Test that the value for the {baz} property returned by the <code>getFooBaz</code>
+ * method matches the expected value parsed from the WSDL.
+ */
+ public void testGetFooBaz() {
+ Binding binding1 = fBindings[1];
+ FooBindingExtensions exts = (FooBindingExtensions)binding1
+ .getComponentExtensionContext(FooConstants.NS_URI_FOO);
+ assertNotNull("The Binding '" + binding1.getName() + "' does not contain an FooBindingExtensions object.",
+ exts);
+
+ String actual = exts.getFooBaz();
+ assertNotNull("The value for bar was null", actual);
+ assertEquals("Unexpected value for baz.", "john", actual);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org