Return-Path: Delivered-To: apmail-ws-woden-dev-archive@www.apache.org Received: (qmail 21912 invoked from network); 1 Sep 2009 05:51:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Sep 2009 05:51:25 -0000 Received: (qmail 90081 invoked by uid 500); 1 Sep 2009 05:51:25 -0000 Delivered-To: apmail-ws-woden-dev-archive@ws.apache.org Received: (qmail 90032 invoked by uid 500); 1 Sep 2009 05:51:25 -0000 Mailing-List: contact woden-dev-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: woden-dev@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list woden-dev@ws.apache.org Received: (qmail 90023 invoked by uid 500); 1 Sep 2009 05:51:25 -0000 Delivered-To: apmail-ws-woden-cvs@ws.apache.org Received: (qmail 90020 invoked by uid 99); 1 Sep 2009 05:51:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 05:51:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 05:51:14 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D52B62388907; Tue, 1 Sep 2009 05:50:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r809833 [4/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... Date: Tue, 01 Sep 2009 05:50:51 -0000 To: woden-cvs@ws.apache.org From: sagara@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090901055054.D52B62388907@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingFaultTest.java URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingFaultTest.java?rev=809833&view=auto ============================================================================== --- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingFaultTest.java (added) +++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingFaultTest.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 org.apache.woden.wsdl20; + +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.BindingFaultImpl; +import org.apache.woden.internal.wsdl20.DescriptionImpl; +import org.apache.woden.types.NCName; +import org.apache.woden.wsdl20.xml.BindingElement; +import org.apache.woden.wsdl20.xml.BindingFaultElement; +import org.apache.woden.wsdl20.xml.BindingOperationElement; +import org.apache.woden.wsdl20.xml.DescriptionElement; +import org.apache.woden.wsdl20.xml.InterfaceElement; +import org.apache.woden.wsdl20.xml.InterfaceFaultElement; + +/** + * Unit tests for the BindingFault class. + * + * @author Graham Turrell (gturrell@apache.org) + */ +public class BindingFaultTest extends TestCase { + + private BindingFaultElement fFaultElement = null; + private BindingFault fFault = null; + + public static Test suite() + { + return new TestSuite(BindingFaultTest.class); + + } + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + fFaultElement = new BindingFaultImpl(); + fFault = (BindingFault) fFaultElement; + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /* + * Test that the (Mandatory) InterfaceFault can be successfully retrieved. + */ + public void testGetInterfaceFault() + { + WSDLFactory factory = null; + try { + factory = WSDLFactory.newInstance(); + } catch (WSDLException e) { + fail("Can't instantiate the WSDLFactory object."); + } + + DescriptionElement descriptionElement = factory.newDescription(); + + // Create the BindingElement<->InterfaceElement->InterfaceFaultElement hierarchy + BindingElement bindingElement = descriptionElement.addBindingElement(); + bindingElement.setInterfaceName(new QName("interface1")); + bindingElement.setName(new NCName("binding1")); + + InterfaceElement interfaceElement = descriptionElement.addInterfaceElement(); + interfaceElement.setName(new NCName("interface1")); + + InterfaceFaultElement iffElement = interfaceElement.addInterfaceFaultElement(); + iffElement.setName(new NCName("fault1")); + + // Create the BindingOperationElement->BindingFaultReferenceElement hierarchy + BindingOperationElement bopElement = bindingElement.addBindingOperationElement(); + bopElement.setRef(new QName("operation1")); + fFaultElement = bindingElement.addBindingFaultElement(); + fFaultElement.setRef(new QName("fault1")); + + Description descComp = descriptionElement.toComponent(); + descComp.getBindings(); // this triggers setting the link to description in the binding + + BindingFault bf = (BindingFault)fFaultElement; + + InterfaceFault retrievedFault = bf.getInterfaceFault(); + assertEquals("The retrieved InterfaceFaultElement is not that which was set", + iffElement, retrievedFault); + } + + /* + * toElement() + */ + public void testToElement() + { + assertEquals(fFaultElement, fFault.toElement()); + } + +} Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingMessageReferenceTest.java URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingMessageReferenceTest.java?rev=809833&view=auto ============================================================================== --- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingMessageReferenceTest.java (added) +++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingMessageReferenceTest.java Tue Sep 1 05:50:45 2009 @@ -0,0 +1,122 @@ +/** + * 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; + +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.BindingMessageReferenceImpl; +import org.apache.woden.internal.wsdl20.DescriptionImpl; +import org.apache.woden.types.NCName; +import org.apache.woden.wsdl20.xml.BindingElement; +import org.apache.woden.wsdl20.xml.BindingMessageReferenceElement; +import org.apache.woden.wsdl20.xml.BindingOperationElement; +import org.apache.woden.wsdl20.xml.DescriptionElement; +import org.apache.woden.wsdl20.xml.InterfaceElement; +import org.apache.woden.wsdl20.xml.InterfaceMessageReferenceElement; +import org.apache.woden.wsdl20.xml.InterfaceOperationElement; + +/** + * Unit tests for the BindingMessageReference class. + * + * @author Graham Turrell (gturrell@apache.org) + */ +public class BindingMessageReferenceTest extends TestCase { + + private BindingMessageReferenceElement fBindingMessageRefElement = null; + private BindingMessageReference fBindingMessageRef = null; + + public static Test suite() + { + return new TestSuite(BindingMessageReferenceTest.class); + + } + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + fBindingMessageRefElement = new BindingMessageReferenceImpl(); + fBindingMessageRef = (BindingMessageReference) fBindingMessageRefElement; + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /* + * Test that the (Mandatory) InterfaceMessageReference can be successfully retrieved. + * - getInterfaceMessageReference() + * + */ + public void testGetInterfaceMessageReference() + { + WSDLFactory factory = null; + try { + factory = WSDLFactory.newInstance(); + } catch (WSDLException e) { + fail("Can't instantiate the WSDLFactory object."); + } + + DescriptionElement descriptionElement = factory.newDescription(); + + // Create the BindingElement<->InterfaceElement->InterfaceOperationElement->InterfaceMessageReferenceElement hierarchy + BindingElement bindingElement = descriptionElement.addBindingElement(); + bindingElement.setInterfaceName(new QName("interface1")); + + InterfaceElement interfaceElement = descriptionElement.addInterfaceElement(); + interfaceElement.setName(new NCName("interface1")); + + InterfaceOperationElement ifopElement = interfaceElement.addInterfaceOperationElement(); + ifopElement.setName(new NCName("operation1")); + InterfaceMessageReferenceElement ifmrElement = ifopElement.addInterfaceMessageReferenceElement(); + ifmrElement.setMessageLabel(new NCName("MessageRef1MessageLabel")); + + // Create the BindingOperationElement->BindingMessageReferenceElement hierarchy + BindingOperationElement bopElement = bindingElement.addBindingOperationElement(); + bopElement.setRef(new QName("operation1")); + fBindingMessageRefElement = bopElement.addBindingMessageReferenceElement(); + fBindingMessageRefElement.setMessageLabel(new NCName("MessageRef1MessageLabel")); + + Description descComp = descriptionElement.toComponent(); + descComp.getBindings(); // this triggers setting the link to description in the binding + + fBindingMessageRef = (BindingMessageReference) fBindingMessageRefElement; + InterfaceMessageReference retrievedMessage = fBindingMessageRef.getInterfaceMessageReference(); + assertEquals("The retrieved InterfaceMessageReference is not that which was set", + ifmrElement, retrievedMessage); + } + + /* + * toElement() + */ + public void testToElement() + { + assertEquals(fBindingMessageRefElement, fBindingMessageRef.toElement()); + } + +} Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingOperationTest.java URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingOperationTest.java?rev=809833&view=auto ============================================================================== --- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingOperationTest.java (added) +++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingOperationTest.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; + +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; +import org.apache.woden.wsdl20.xml.BindingElement; +import org.apache.woden.wsdl20.xml.BindingFaultReferenceElement; +import org.apache.woden.wsdl20.xml.BindingMessageReferenceElement; +import org.apache.woden.wsdl20.xml.BindingOperationElement; +import org.apache.woden.wsdl20.xml.DescriptionElement; +import org.apache.woden.wsdl20.xml.InterfaceElement; +import org.apache.woden.wsdl20.xml.InterfaceOperationElement; + +/** + * Unit tests for the BindingOperation class. + * + * @author Graham Turrell (gturrell@apache.org) + */ + +public class BindingOperationTest extends TestCase { + + // create a parent Description to hang the Binding hierarchy off + private DescriptionElement fDescriptionElement = null; + private BindingElement fBindingElement = null; + private BindingOperationElement fBindingOperationElement = null; + private BindingOperation fBindingOperation = null; + + public static Test suite() + { + return new TestSuite(BindingOperationTest.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(); + fBindingElement = fDescriptionElement.addBindingElement(); + fBindingOperationElement = fBindingElement.addBindingOperationElement(); + fBindingOperation = (BindingOperation) fBindingOperationElement; + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /* + * References to Optional child elements "infault" and "outfault" in the infoset + * - getBindingFaultReferences() + */ + public void testGetBindingFaultReferences() + { + // create some BindingFaultReferenceElements + BindingFaultReferenceElement bfre1 = fBindingOperationElement.addBindingFaultReferenceElement(); + BindingFaultReferenceElement bfre2 = fBindingOperationElement.addBindingFaultReferenceElement(); + + fDescriptionElement.toComponent(); + + // getBindingFaultReferences() + BindingFaultReference[] bfrArray = fBindingOperation.getBindingFaultReferences(); + assertNotNull("Expected an array of BindingFaultReference.", bfrArray); + assertEquals("Retrieved BindingFaultReference group should be same number as those set -", 2, bfrArray.length); + + // verify all fault references returned + List bfreL = Arrays.asList(bfrArray); + assertTrue(bfreL.contains(bfre1)); + assertTrue(bfreL.contains(bfre2)); + } + + /* + * References to Optional child elements "input" and "output" int the infoset + * - getBindingMessageReferences() + */ + public void testGetBindingMessageReferences() + { + // create some BindingMessageReferenceElements + BindingMessageReferenceElement bmre1 = fBindingOperationElement.addBindingMessageReferenceElement(); + BindingMessageReferenceElement bmre2 = fBindingOperationElement.addBindingMessageReferenceElement(); + + fDescriptionElement.toComponent(); + + // getBindingMessageReferences() + BindingMessageReference[] bmrArray = fBindingOperation.getBindingMessageReferences(); + assertNotNull("Expected an array of BindingMessageReference.", bmrArray); + assertEquals("Retrieved BindingMessageReference group should be same number as those set -", 2, bmrArray.length); + + // verify all fault references returned + List bmreL = Arrays.asList(bmrArray); + assertTrue(bmreL.contains(bmre1)); + assertTrue(bmreL.contains(bmre2)); + } + + /* + * Utility method to find the InterfaceOperation referenced by the (Mandatory) "ref" attribute in the infoset + * - getInterfaceOperation() + */ + public void testGetInterfaceOperation() + { + // Create and name an Interface Element + InterfaceElement interfaceElement = fDescriptionElement.addInterfaceElement(); + interfaceElement.setName(new NCName("interface1")); + + // Create a binding from the description + fBindingElement = fDescriptionElement.addBindingElement(); + fBindingElement.setInterfaceName(new QName("interface1")); + + //Create and name an Interface Operation Element + InterfaceOperationElement intOpElement = interfaceElement.addInterfaceOperationElement(); + intOpElement.setName(new NCName("interfaceOperation1")); + + fBindingOperationElement = fBindingElement.addBindingOperationElement(); + fBindingOperationElement.setRef(new QName("interfaceOperation1")); + + Description descComp = fDescriptionElement.toComponent(); + descComp.getBindings(); // this triggers setting the link to description in the binding + + fBindingOperation = (BindingOperation) fBindingOperationElement; + + InterfaceOperation retrievedIntOp = fBindingOperation.getInterfaceOperation(); + assertEquals("Retrieved Interface Element was not that expected -", intOpElement, retrievedIntOp); + } + + /* + * toElement() + */ + public void testToElement() + { + assertEquals(fBindingOperationElement, fBindingOperation.toElement()); + } +} Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingTest.java URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingTest.java?rev=809833&view=auto ============================================================================== --- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingTest.java (added) +++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/BindingTest.java Tue Sep 1 05:50:45 2009 @@ -0,0 +1,220 @@ +/** + * 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; + +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; +import org.apache.woden.wsdl20.xml.BindingElement; +import org.apache.woden.wsdl20.xml.BindingFaultElement; +import org.apache.woden.wsdl20.xml.BindingOperationElement; +import org.apache.woden.wsdl20.xml.DescriptionElement; +import org.apache.woden.wsdl20.xml.InterfaceElement; + +/** + * Unit tests for the Binding class. + * + * @author Graham Turrell (gturrell@apache.org) + */ +public class BindingTest extends TestCase { + + // create a parent Description to hang the Bindings off + private DescriptionElement fDescriptionElement = null; + private BindingElement fBindingElement = null; + private Binding fBinding = null; + private URI fTypeURI = null; + + public static Test suite() + { + return new TestSuite(BindingTest.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(); + fBindingElement = fDescriptionElement.addBindingElement(); + fBindingElement.setName(new NCName("binding")); + //fBinding = (Binding) fBindingElement; + fTypeURI = new URI("http://www.w3.org/0000/00/apacheType"); + fBinding = fDescriptionElement.toComponent().getBinding(new QName("binding")); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /* (optional) "interface" attribute + * - getInterfaceElement() + */ + public void testGetInterface() + { + // check the default: + Interface retrievedInterface = fBinding.getInterface(); + assertNull("Retrieved Interface should be null if none set -", retrievedInterface); + + WSDLFactory factory = null; + try { + factory = WSDLFactory.newInstance(); + } catch (WSDLException e) { + fail("Can't instantiate the WSDLFactory object."); + } + + // Create and name an Interface Element + DescriptionElement desc = factory.newDescription(); + InterfaceElement interfaceElement = desc.addInterfaceElement(); + interfaceElement.setName(new NCName("interface1")); + + // Create a binding from the description + fBindingElement = desc.addBindingElement(); + fBindingElement.setName(new NCName("binding1")); + desc.toComponent(); + Binding binding = desc.toComponent().getBinding(new QName("binding1")); + + // getInterface() - interface attribute unspecified, but hierarchy in place: + retrievedInterface = binding.getInterface(); + assertNull("Retrieved Interface should be null if interface attribute unspecified -", retrievedInterface); + + // getInterface() - interface attribute specified, and hierarchy in place: + // Set the "interface" attribute to reference the new Interface Element + // (have to recreate whole desc hierarchy as toComponent() will not rerun if already run!) + desc = factory.newDescription(); + interfaceElement = desc.addInterfaceElement(); + interfaceElement.setName(new NCName("interface1")); + fBindingElement = desc.addBindingElement(); + fBindingElement.setName(new NCName("binding1")); + fBindingElement.setInterfaceName(new QName("interface1")); + + //fDescriptionElement.toComponent(); + + binding = desc.toComponent().getBinding(new QName("binding1")); + //fBinding = (Binding)fBindingElement; + + retrievedInterface = binding.getInterface(); + assertEquals("Retrieved Interface was not that expected -", interfaceElement, retrievedInterface); + } + + /* + * Mandatory attribute ("name") + * - getName() + */ + public void testGetName() + { + fBindingElement.setName(new NCName("BindingName")); + QName uri = fBinding.getName(); + assertNotNull(uri); + assertEquals("Retrieved Binding name does not match that set -", "BindingName", uri.toString()); + } + + /* + * Mandatory attribute ("type") + * - getType() + */ + public void testGetType() + { + fBindingElement.setType(fTypeURI); + URI uri = fBinding.getType(); + assertEquals("Retrieved Binding type attribute does not match that set -", fTypeURI, uri); + } + + /* + * Optional element ("fault") + * - getBindingFaults() + */ + public void testGetBindingFaults() + { + // check the default: + BindingFault[] bfArray = fBinding.getBindingFaults(); + assertNotNull("Expected an array of BindingFaults -", bfArray); + assertEquals("Retrieved BindingFaultElement group should be empty if none set -", 0, bfArray.length); + + // addBindingFaultElement() + BindingFaultElement bfe1 = fBindingElement.addBindingFaultElement(); + BindingFaultElement bfe2 = fBindingElement.addBindingFaultElement(); + + // getBindingFaultElements() + bfArray = fBinding.getBindingFaults(); + assertNotNull("Expected an array of BindingFaults -", bfArray); + assertEquals("Incorrect number of retrieved BindingFaults -", 2, bfArray.length); + + // verify all Fault objects returned + List bfeL = Arrays.asList(bfArray); + assertTrue(bfeL.contains(bfe1)); + assertTrue(bfeL.contains(bfe2)); + } + + /* + * Optional element ("operation") + * - getBindingOperations() + */ + public void testGetBindingOperations() + { + // check the default: + BindingOperation[] bopArray = fBinding.getBindingOperations(); + assertNotNull("Expected an array of BindingOperations -", bopArray); + assertEquals("Retrieved BindingOperation group should be empty if none set -", 0, bopArray.length); + + // addBindingOperationElement() + BindingOperationElement bop1 = fBindingElement.addBindingOperationElement(); + BindingOperationElement bop2 = fBindingElement.addBindingOperationElement(); + + // getBindingOperations() + bopArray = fBinding.getBindingOperations(); + assertNotNull("Expected an array of BindingOperation -", bopArray); + assertEquals("Incorrect number of retrieved BindingOperations -", 2, bopArray.length); + + // verify all Operation objects returned + List ifopL = Arrays.asList(bopArray); + assertTrue(ifopL.contains(bop1)); + assertTrue(ifopL.contains(bop2)); + } + + /* + * toElement() + */ + public void testToElement() + { + assertEquals(fBindingElement, fBinding.toElement()); + } + +} Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/DescriptionTest.java URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/DescriptionTest.java?rev=809833&view=auto ============================================================================== --- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/DescriptionTest.java (added) +++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/DescriptionTest.java Tue Sep 1 05:50:45 2009 @@ -0,0 +1,240 @@ +/** + * 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; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.net.URI; +import java.net.URISyntaxException; + +import javax.xml.namespace.QName; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.woden.WSDLFactory; +import org.apache.woden.internal.schema.InlinedSchemaImpl; +import org.apache.woden.internal.wsdl20.DescriptionImpl; +import org.apache.woden.internal.wsdl20.ElementDeclarationImpl; +import org.apache.woden.internal.wsdl20.TypeDefinitionImpl; +import org.apache.woden.schema.InlinedSchema; +import org.apache.woden.types.NCName; +import org.apache.woden.wsdl20.xml.BindingElement; +import org.apache.woden.wsdl20.xml.DescriptionElement; +import org.apache.woden.wsdl20.xml.InterfaceElement; +import org.apache.woden.wsdl20.xml.ServiceElement; +import org.apache.woden.wsdl20.xml.TypesElement; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.apache.xerces.parsers.DOMParser; +import org.apache.xerces.xni.parser.XMLInputSource; +import org.w3c.dom.Document; + +/** + * Unit tests for the Description component API. + * + * @author Graham Turrell (gturrell@apache.org) + */ +public class DescriptionTest extends TestCase { + + private Description fDescription = null; + private DescriptionElement fDescriptionElement = null; + private BindingElement fBindingElement = null; + private InterfaceElement fInterfaceElement = null; + private ServiceElement fServiceElement = null; + + public static Test suite() + { + return new TestSuite(DescriptionTest.class); + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + WSDLFactory factory = WSDLFactory.newInstance(); + fDescriptionElement = factory.newDescription(); + fBindingElement = fDescriptionElement.addBindingElement(); + fBindingElement.setName(new NCName("bindingName")); + fInterfaceElement = fDescriptionElement.addInterfaceElement(); + fInterfaceElement.setName(new NCName("interfaceName")); + fServiceElement = fDescriptionElement.addServiceElement(); + fServiceElement.setName(new NCName("serviceName")); + + //Create a test schema + InlinedSchema schema = new InlinedSchemaImpl(); + XmlSchema xs1 = null; + URI schemaNS = null; + + String schemaString = "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + DOMParser builder = new DOMParser(); + Reader reader = new StringReader(schemaString); + XMLInputSource is = new XMLInputSource(null, null, null, reader, null); + try { + builder.parse(is); + } catch(IOException e) { + fail("There was an IOException whilst trying to parse the sample schema."); + } + Document schemaDoc1 = builder.getDocument(); + XmlSchemaCollection xsc = new XmlSchemaCollection(); + xs1 = xsc.read(schemaDoc1.getDocumentElement()); + schema.setSchemaDefinition(xs1); + + //Add it to the typesElement. + TypesElement typesEl = fDescriptionElement.addTypesElement(); + typesEl.addSchema(schema); + + fDescription = fDescriptionElement.toComponent(); + + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + + public void testGetBinding() + { + Binding retrievedBinding = fDescription.getBinding(new QName("bindingName")); + assertNotNull(retrievedBinding); + assertEquals(fBindingElement, retrievedBinding.toElement()); + + Binding noBinding = fDescription.getBinding(new QName("noBinding")); + assertNull(noBinding); + + QName nullQName = null; + Binding nullBinding = fDescription.getBinding(nullQName); + assertNull(nullBinding); + } + + public void testGetBindings() + { + Binding[] retrievedBindings = fDescription.getBindings(); + assertNotNull(retrievedBindings); + assertEquals(1, retrievedBindings.length); + } + + public void testGetElementDeclaration() + { + ElementDeclaration ed = fDescription.getElementDeclaration(new QName("myEd")); + assertNotNull(ed); + + // non-existent ElementDeclaration... + ed = fDescription.getElementDeclaration(new QName("doesNotExist")); + assertNull(ed); + } + + + public void testGetElementDeclarations() + { + ElementDeclaration[] eds = fDescription.getElementDeclarations(); + assertNotNull(eds); + assertEquals(1, eds.length); + + // TODO - test for when no Element Declarations ? + } + + /* + * Test that a service returns its (required) associated interface. + * + */ + public void testGetInterface() + { + Interface retrievedIf = fDescription.getInterface(new QName("interfaceName")); + assertNotNull(retrievedIf); + assertEquals(fInterfaceElement, retrievedIf.toElement()); // TODO - a fair test or a rash assumption?! + + // non-existent interface + retrievedIf = fDescription.getInterface(new QName("noSuchInterface")); + assertNull(retrievedIf); + + // null interface name + QName nullQName = null; + retrievedIf = fDescription.getInterface(nullQName); + assertNull(retrievedIf); + } + + public void testGetInterfaces() + { + Interface[] retrievedIfs = fDescription.getInterfaces(); + assertEquals(1, retrievedIfs.length); + } + + public void testGetService() + { + Service retrievedService = fDescription.getService(new QName("serviceName")); + assertNotNull(retrievedService); + + // non-existent service + retrievedService = fDescription.getService(new QName("noSuchService")); + assertNull(retrievedService); + + // null service name + QName nullQName = null; + retrievedService = fDescription.getService(nullQName); + assertNull(retrievedService); + } + + public void testGetServices() + { + Service[] services = fDescription.getServices(); + assertEquals(1, services.length); + } + + public void testGetTypeDefinition() + { + TypeDefinition td = fDescription.getTypeDefinition(new QName("myTypeDef")); + assertNotNull(td); + + // non-existent TypeDefinition... + td = fDescription.getTypeDefinition(new QName("doesNotExist")); + assertNull(td); + } + + public void testGetTypeDefinitions() + { + TypeDefinition[] tds = fDescription.getTypeDefinitions(); + assertNotNull(tds); + assertEquals(1, tds.length); + } + + /* + * Tests that the returned class is a DescriptionElement + * + */ + public void testToElement() + { + assertTrue(fDescription.toElement() instanceof DescriptionElement); + } + +} Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/ElementDeclarationTest.java URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/ElementDeclarationTest.java?rev=809833&view=auto ============================================================================== --- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/ElementDeclarationTest.java (added) +++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/ElementDeclarationTest.java Tue Sep 1 05:50:45 2009 @@ -0,0 +1,102 @@ +/** + * 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; + +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.internal.wsdl20.ElementDeclarationImpl; + +/** + * Unit tests for the implementation of ElementDeclaration interface. + * + * @author Graham Turrell (gturrell@apache.org) + */ +public class ElementDeclarationTest extends TestCase { + + private ElementDeclaration fElementDeclaration = null; + private URI fTypeSystem = null; + + public static Test suite() + { + return new TestSuite(ElementDeclarationTest.class); + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + + fElementDeclaration = new ElementDeclarationImpl(); + fTypeSystem = new URI("http://www.w3.org/2001/XMLSchema"); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /* + * Test that getContent() correctly returns the assigned ElementDeclaration content object + */ + public void testGetContent() + { + String content = "edContentObject"; + ((ElementDeclarationImpl) fElementDeclaration).setContent(content); + assertEquals("The ElementDeclaration content Object differs from that set -", content, fElementDeclaration.getContent()); + } + + /* + * Test that getContentModel() correctly returns the assigned ElementDeclaration content model reference + */ + public void testGetContentModel() + { + String contentModel = ElementDeclaration.API_APACHE_WS_XS; // one of the presets available + ((ElementDeclarationImpl) fElementDeclaration).setContentModel(contentModel); + assertEquals("The ElementDeclaration content model String differs from that set -", contentModel, fElementDeclaration.getContentModel()); + } + + /* + * Test that getName() correctly returns the assigned ElementDeclaration name + */ + public void testGetName() + { + ((ElementDeclarationImpl)fElementDeclaration).setName(new QName("edName")); + assertEquals("The ElementDeclaration name QName differs from that set-", "edName", fElementDeclaration.getName().toString()); + } + + /* + * Test that getSystem() correctly returns the assigned ElementDeclaration type system + */ + public void testGetSystem() + { + ((ElementDeclarationImpl) fElementDeclaration).setSystem(fTypeSystem); + assertEquals("The ElementDeclaration type system URI differs from that set-", fTypeSystem, fElementDeclaration.getSystem()); + } + + +} Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/EndpointTest.java URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/EndpointTest.java?rev=809833&view=auto ============================================================================== --- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/EndpointTest.java (added) +++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/EndpointTest.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.wsdl20; + +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.wsdl20.DescriptionImpl; +import org.apache.woden.internal.wsdl20.EndpointImpl; +import org.apache.woden.types.NCName; +import org.apache.woden.wsdl20.xml.BindingElement; +import org.apache.woden.wsdl20.xml.DescriptionElement; +import org.apache.woden.wsdl20.xml.EndpointElement; +import org.apache.woden.wsdl20.xml.ServiceElement; + +/** + * Unit tests for the ImportElement class. + * + * @author Graham Turrell (gturrell@apache.org) + */ +public class EndpointTest extends TestCase { + + private EndpointImpl fEndpointImpl = null; + private Endpoint fEndpoint = null; + private URI fURI = null; + private QName fBindingQName = null; + private NCName fBindingNCName = null; + private NCName fName = null; + + public static Test suite() + { + return new TestSuite(EndpointTest.class); + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + fURI = new URI("http://apache.org/endpointURI"); + fEndpointImpl = new EndpointImpl(); + fEndpoint = fEndpointImpl; + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + fURI = null; + fEndpointImpl = null; + fEndpoint = null; + fBindingQName = null; + fBindingNCName = null; + fName = null; + } + + /* + * Test getAddress() when the (optional) address attribute is set (specified) + */ + public void testGetAddress() + { + fEndpointImpl.setAddress(fURI); + assertEquals(fEndpoint.getAddress(), fURI); // java.net.URI overrides Object.equals() + } + + /* + * Test getAddress() when the (optional) address attribute is unspecified + */ + public void testDefaultGetAddress() + { + assertNull(fEndpoint.getAddress()); + } + + /* + * The Binding with fBindingName is obtained from the Description element associated with the Endpoint's Service + * + */ + public void testGetBinding() + { + /* + * Test setup : work with the Infoset view for the creation of the + * necessary prerequisite partial hierarchy + * Note create the minimum necessary wsdl20 objects + */ + + WSDLFactory factory = null; + try { + factory = WSDLFactory.newInstance(); + } catch (WSDLException e) { + fail("Can't instantiate the WSDLFactory object."); + } + + // Description... + DescriptionElement fDescElement = factory.newDescription(); + + // Binding... + fBindingQName = new QName("binding1"); + BindingElement fBindingElement = fDescElement.addBindingElement(); + fBindingNCName = new NCName("binding1"); + NCName fServiceNCName = new NCName("service1"); + QName fServiceQName = new QName("service1"); + NCName fEndpointNCname = new NCName("endpoint1"); + fBindingElement.setName(fBindingNCName); + + // Service... (attach our Endpoint to a Service parented by our Description) + ServiceElement fServiceElement = fDescElement.addServiceElement(); + fServiceElement.setName(fServiceNCName); + + // Endpoint... + EndpointElement fEndpointElement = fServiceElement.addEndpointElement(); + fEndpointElement.setName(fEndpointNCname); + fEndpointElement.setBindingName(fBindingQName); + + // Component model creation + Description fDesc = fDescElement.toComponent(); + Endpoint fDerivedEndpoint = fDesc.getService(fServiceQName).getEndpoint(fEndpointNCname); + + assertEquals(fDerivedEndpoint.getBinding().getName(), fBindingQName); // just compare QNames + } + + public void testGetName() + { + fName = new NCName("endpoint_name"); + fEndpointImpl.setName(fName); + assertEquals(fEndpoint.getName(), fName); + } + + /* + * Tests that the returned class is precisely an EndpointElement (ie not a subclass) + * + */ + public void testToElement() + { + assertTrue(fEndpoint.toElement() instanceof EndpointElement); + } + +} \ No newline at end of file Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceFaultReferenceTest.java URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceFaultReferenceTest.java?rev=809833&view=auto ============================================================================== --- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceFaultReferenceTest.java (added) +++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceFaultReferenceTest.java Tue Sep 1 05:50:45 2009 @@ -0,0 +1,132 @@ +/** + * 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; + +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.internal.wsdl20.InterfaceFaultReferenceImpl; +import org.apache.woden.types.NCName; +import org.apache.woden.wsdl20.enumeration.Direction; +import org.apache.woden.wsdl20.xml.DescriptionElement; +import org.apache.woden.wsdl20.xml.InterfaceElement; +import org.apache.woden.wsdl20.xml.InterfaceFaultElement; +import org.apache.woden.wsdl20.xml.InterfaceFaultReferenceElement; +import org.apache.woden.wsdl20.xml.InterfaceOperationElement; + +/** + * Unit tests for the InterfaceFaultReference class. + * + * @author Graham Turrell (gturrell@apache.org) + */ +public class InterfaceFaultReferenceTest extends TestCase { + + private InterfaceFaultReferenceElement fFaultReferenceElement = null; + private InterfaceFaultReference fFaultReferenceComp = null; + + public static Test suite() + { + return new TestSuite(InterfaceFaultReferenceTest.class); + } + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + fFaultReferenceElement = new InterfaceFaultReferenceImpl(); + fFaultReferenceElement.setDirection(Direction.OUT); + fFaultReferenceComp = (InterfaceFaultReference)fFaultReferenceElement; + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /* + * Test that a (mandatory) direction can be successfully set and retrieved + */ + public void testSetGetDirection() + { + assertEquals("The retrieved FaultReference direction is not that which was set", + Direction.OUT, fFaultReferenceComp.getDirection()); + } + + /* + * Test that the (Mandatory) message label attribute ("messageLabel") can be successfully set and retrieved + */ + public void testGetMessageLabel() + { + NCName faultRefNCName = new NCName("faultRefName"); + fFaultReferenceElement.setMessageLabel(faultRefNCName); + assertEquals("The retrieved Fault Reference name is not that which was set", + faultRefNCName, fFaultReferenceComp.getMessageLabel()); + } + + /* + * Test that the (Mandatory) InterfaceFault can be successfully retrieved. + * The fault reference is to an Interface Fault associated with the grandparent InterfaceElement. + */ + public void testGetInterfaceFault() + { + WSDLFactory factory = null; + try { + factory = WSDLFactory.newInstance(); + } catch (WSDLException e) { + fail("Can't instantiate the WSDLFactory object."); + } + + // Create the DescriptionElement->InterfaceElement->InterfaceOperationElement->InterfaceFaultReference hierarchy + DescriptionElement desc = factory.newDescription(); + InterfaceElement interfaceElement = desc.addInterfaceElement(); + InterfaceOperationElement interfaceOperationElement = interfaceElement.addInterfaceOperationElement(); + + // Add an InterfaceFault to the InterfaceElement + InterfaceFaultElement faultElement = interfaceElement.addInterfaceFaultElement(); + faultElement.setName(new NCName("Fault1")); + + // create the InterfaceFaultReference to test + InterfaceFaultReferenceElement faultReference = interfaceOperationElement.addInterfaceFaultReferenceElement(); + faultReference.setRef(new QName("Fault1")); + + // An alternative here would be to create a Description element on with to hang the + // hierarchy, call toComponent() on this and extract the InterfaceFaultReference from this. + // However this inadvertently tests the Description class which is out of scope for this unit test. + InterfaceFault retrievedFault = ((InterfaceFaultReference)faultReference).getInterfaceFault(); + + assertEquals("The retrieved InterfaceFault is not that which was set", + (InterfaceFault)faultElement, retrievedFault); + } + + /* + * toElement() + */ + public void testToElement() + { + assertEquals(fFaultReferenceElement, fFaultReferenceComp.toElement()); + } +} Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceFaultTest.java URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceFaultTest.java?rev=809833&view=auto ============================================================================== --- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceFaultTest.java (added) +++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceFaultTest.java Tue Sep 1 05:50:45 2009 @@ -0,0 +1,197 @@ +/** + * 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; + +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.Constants; +import org.apache.woden.internal.wsdl20.DescriptionImpl; +import org.apache.woden.internal.wsdl20.ElementDeclarationImpl; +import org.apache.woden.schema.InlinedSchema; +import org.apache.woden.types.NCName; +import org.apache.woden.types.QNameTokenUnion; +import org.apache.woden.wsdl20.xml.DescriptionElement; +import org.apache.woden.wsdl20.xml.InterfaceElement; +import org.apache.woden.wsdl20.xml.InterfaceFaultElement; +import org.apache.woden.wsdl20.xml.TypesElement; +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 InterfaceFault class. + * + * @author Graham Turrell (gturrell@apache.org) + */ +public class InterfaceFaultTest extends TestCase { + + private InterfaceFaultElement fFaultElement = null; + private InterfaceFault fFault = null; + private DescriptionElement fDescriptionElement = null; + private Description fDescription = null; + private InterfaceElement fInterfaceElement = null; + private final String FAULT_NAME = "faultName"; + private final String INTF_NAME = "interfaceName"; + private final String TNS = "http://example.org"; + + public static Test suite() + { + return new TestSuite(InterfaceFaultTest.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(); + fDescriptionElement.setTargetNamespace(URI.create(TNS)); + fInterfaceElement = fDescriptionElement.addInterfaceElement(); + fInterfaceElement.setName(new NCName(INTF_NAME)); + fFaultElement = fInterfaceElement.addInterfaceFaultElement(); + fFaultElement.setName(new NCName(FAULT_NAME)); + fFaultElement.setElement(new QNameTokenUnion(new QName(FAULT_NAME))); + fDescription = fDescriptionElement.toComponent(); + Interface iface = fDescription.getInterface(new QName(TNS,INTF_NAME)); + fFault = iface.getInterfaceFault(new QName(TNS,FAULT_NAME)); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /* + * Test that a (Mandatory) Name QName can be successfully retrieved + */ + public void testGetName() + { + QName faultName = new QName(TNS, FAULT_NAME); + fDescription = fDescriptionElement.toComponent(); + fFault = fDescription.getInterface(new QName(TNS, INTF_NAME)).getInterfaceFault(new QName(TNS, FAULT_NAME)); + assertEquals("The retrieved fault name is not that which was set", + faultName, fFault.getName()); + } + + /* + * Test that the (Mandatory) Message Content Model property can be successfully retrieved + */ + public void testGetMessageContentModel() + { + Description desc = fDescriptionElement.toComponent(); + InterfaceFault fault = desc.getInterfaces()[0].getInterfaceFaults()[0]; + + fFaultElement.setElement(QNameTokenUnion.ANY); + assertEquals("The retrieved Message Content Model is not #any", + Constants.NMTOKEN_ANY, fault.getMessageContentModel()); + + fFaultElement.setElement(QNameTokenUnion.NONE); + assertEquals("The retrieved Message Content Model is not #none", + Constants.NMTOKEN_NONE, fault.getMessageContentModel()); + + fFaultElement.setElement(QNameTokenUnion.OTHER); + assertEquals("The retrieved Message Content Model is not #other", + Constants.NMTOKEN_OTHER, fault.getMessageContentModel()); + + fFaultElement.setElement(null); + assertEquals("The retrieved Message Content Model is not #other", + Constants.NMTOKEN_OTHER, fault.getMessageContentModel()); + + fFaultElement.setElement(new QNameTokenUnion(new QName("elementName"))); + assertEquals("The retrieved Message Content Model is not #element", + Constants.NMTOKEN_ELEMENT, fault.getMessageContentModel()); + } + + /* + * Test that an (optional) ElementDecalaration can be successfully retrieved + */ + public void testGetElementDeclaration() throws Exception + { + fFaultElement.setName(new NCName(FAULT_NAME)); + fDescription = fDescriptionElement.toComponent(); + Interface iface = fDescription.getInterface(new QName(TNS,INTF_NAME)); + InterfaceFault fault = iface.getInterfaceFault(new QName(TNS,FAULT_NAME)); + assertNotNull(fault); + + // Default case + assertNull("When 'element' attribute is omitted, no ElementDeclaration should be present", fault.getElementDeclaration()); + + // Test that the expected ElementDeclaration is returned + TypesElement typesElement = fDescriptionElement.addTypesElement(); //throws WSDLException + InlinedSchema schema = new InlinedSchemaImpl(); + String schemaString = "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + 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"); + + fFaultElement.setElement(new QNameTokenUnion(elemQN)); + ElementDeclaration elemDecl = fault.getElementDeclaration(); + + assertEquals("The ElementDeclaration did not match the qname in the 'element' attribute", + elemQN, elemDecl.getName()); + } + + /* + * toElement() + */ + public void testToElement() + { + assertEquals(fFaultElement, fFault.toElement()); + } + +} Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceMessageReferenceTest.java URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceMessageReferenceTest.java?rev=809833&view=auto ============================================================================== --- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceMessageReferenceTest.java (added) +++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceMessageReferenceTest.java Tue Sep 1 05:50:45 2009 @@ -0,0 +1,205 @@ +/** + * 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; + +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.Constants; +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.woden.wsdl20.xml.DescriptionElement; +import org.apache.woden.wsdl20.xml.InterfaceElement; +import org.apache.woden.wsdl20.xml.InterfaceMessageReferenceElement; +import org.apache.woden.wsdl20.xml.InterfaceOperationElement; +import org.apache.woden.wsdl20.xml.TypesElement; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.apache.xerces.parsers.DOMParser; +import org.apache.xerces.xni.parser.XMLInputSource; +import org.w3c.dom.Document; + + + +/** + * Unit tests for the InterfaceMessageReference class. + * + * @author Graham Turrell (gturrell@apache.org) + */ +public class InterfaceMessageReferenceTest extends TestCase { + + private DescriptionElement fDescriptionElement = null; + private InterfaceElement fInterfaceElement = null; + private InterfaceOperationElement fInterfaceOperationElement = null; + private InterfaceMessageReferenceElement fMessageReferenceElement = null; + private final String TNS = "http://example.org"; + private final String INTF_NAME = "interfaceName"; + private final String OPER_NAME = "operationName"; + + public static Test suite() + { + return new TestSuite(InterfaceMessageReferenceTest.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(); + fDescriptionElement.setTargetNamespace(URI.create(TNS)); + fInterfaceElement = fDescriptionElement.addInterfaceElement(); + fInterfaceElement.setName(new NCName(INTF_NAME)); + fInterfaceOperationElement = fInterfaceElement.addInterfaceOperationElement(); + fInterfaceOperationElement.setName(new NCName(OPER_NAME)); + fMessageReferenceElement = fInterfaceOperationElement.addInterfaceMessageReferenceElement(); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /* + * Test that a (mandatory) direction can be successfully retrieved + */ + public void testGetDirection() + { + fMessageReferenceElement.setDirection(Direction.OUT); + Description desc = fDescriptionElement.toComponent(); + InterfaceMessageReference msgRef = desc.getInterfaces()[0].getInterfaceOperations()[0].getInterfaceMessageReferences()[0]; + assertEquals("The retrieved direction is not that which was set", + Direction.OUT, msgRef.getDirection()); + } + + /* + * Test that the (Mandatory) message label attribute ("messageLabel") can be successfully retrieved + */ + public void testGetMessageLabel() + { + NCName messageRefNCName = new NCName("messageRefName"); + fMessageReferenceElement.setMessageLabel(messageRefNCName); + Description desc = fDescriptionElement.toComponent(); + InterfaceMessageReference msgRef = desc.getInterfaces()[0].getInterfaceOperations()[0].getInterfaceMessageReferences()[0]; + assertEquals("The retrieved message label is not that which was set", + messageRefNCName, msgRef.getMessageLabel()); + } + + /* + * Test that the (Mandatory) Message Content Model property can be successfully retrieved + */ + public void testGetMessageContentModel() + { + Description desc = fDescriptionElement.toComponent(); + InterfaceMessageReference msgRef = desc.getInterfaces()[0].getInterfaceOperations()[0].getInterfaceMessageReferences()[0]; + + fMessageReferenceElement.setElement(QNameTokenUnion.ANY); + assertEquals("The retrieved Message Content Model is not #any", + Constants.NMTOKEN_ANY, msgRef.getMessageContentModel()); + + fMessageReferenceElement.setElement(QNameTokenUnion.NONE); + assertEquals("The retrieved Message Content Model is not #none", + Constants.NMTOKEN_NONE, msgRef.getMessageContentModel()); + + fMessageReferenceElement.setElement(QNameTokenUnion.OTHER); + assertEquals("The retrieved Message Content Model is not #other", + Constants.NMTOKEN_OTHER, msgRef.getMessageContentModel()); + + fMessageReferenceElement.setElement(new QNameTokenUnion(new QName("elementName"))); + assertEquals("The retrieved Message Content Model is not #element", + Constants.NMTOKEN_ELEMENT, msgRef.getMessageContentModel()); + } + + /* + * Test that an (optional) ElementDecalaration can be successfully retrieved + */ + public void testGetElementDeclaration() throws Exception + { + Description desc = fDescriptionElement.toComponent(); + Interface iface = desc.getInterface(new QName(TNS,INTF_NAME)); + InterfaceOperation oper = iface.getInterfaceOperation(new QName(TNS,OPER_NAME)); + InterfaceMessageReference msgRef = oper.getInterfaceMessageReferences()[0]; + assertNotNull(msgRef); + + // Default case + assertNull("When 'element' attribute is omitted, no ElementDeclaration should be present", msgRef.getElementDeclaration()); + + // Test that the expected ElementDeclaration is returned + TypesElement typesElement = fDescriptionElement.addTypesElement(); //throws WSDLException + InlinedSchema schema = new InlinedSchemaImpl(); + String schemaString = "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + 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"); + + fMessageReferenceElement.setElement(new QNameTokenUnion(elemQN)); + ElementDeclaration elemDecl = msgRef.getElementDeclaration(); + + assertEquals("The ElementDeclaration did not match the qname in the 'element' attribute", + elemQN, elemDecl.getName()); + } + + + /* + * toElement() - test that the infoset element view of this component can be retreived + */ + public void testToElement() + { + Description desc = fDescriptionElement.toComponent(); + InterfaceMessageReference msgRef = desc.getInterfaces()[0].getInterfaceOperations()[0].getInterfaceMessageReferences()[0]; + assertEquals(fMessageReferenceElement, msgRef.toElement()); + } +} Added: webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceOperationTest.java URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceOperationTest.java?rev=809833&view=auto ============================================================================== --- webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceOperationTest.java (added) +++ webservices/woden/trunk/java/woden-tests/src/test/java/org/apache/woden/wsdl20/InterfaceOperationTest.java Tue Sep 1 05:50:45 2009 @@ -0,0 +1,213 @@ +/** + * 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; + +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.ErrorReporterImpl; +import org.apache.woden.internal.wsdl20.DescriptionImpl; +import org.apache.woden.types.NCName; +import org.apache.woden.wsdl20.extensions.ExtensionRegistry; +import org.apache.woden.wsdl20.xml.DescriptionElement; +import org.apache.woden.wsdl20.xml.InterfaceElement; +import org.apache.woden.wsdl20.xml.InterfaceFaultReferenceElement; +import org.apache.woden.wsdl20.xml.InterfaceMessageReferenceElement; +import org.apache.woden.wsdl20.xml.InterfaceOperationElement; + +/** + * Unit tests for the InterfaceOperation class. + * + * @author Graham Turrell (gturrell@apache.org) + */ +public class InterfaceOperationTest extends TestCase { + + // create a parent Description to hang the Interfaces off + private DescriptionElement fDescriptionElement = null; + private Description fDescription = null; + private InterfaceElement fInterfaceElement = null; + private InterfaceOperationElement fInterfaceOperationElement = null; + private InterfaceOperation fInterfaceOperation = null; + private final String INTF_NAME = "interfaceOperationName"; + private final String INTOP_NAME = "faultName"; + private URI fPattern = null; + private URI fStyleURI1 = null; + private URI fStyleURI2 = null; + + public static Test suite() + { + return new TestSuite(InterfaceOperationTest.class); + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + WSDLFactory factory = null; + try { + factory = WSDLFactory.newInstance(); + } catch (WSDLException e) { + fail("Can't instantiate the WSDLFactory object."); + } + + super.setUp(); + fDescriptionElement = factory.newDescription(); + fInterfaceElement = fDescriptionElement.addInterfaceElement(); + fInterfaceElement.setName(new NCName(INTF_NAME)); + fInterfaceOperationElement = fInterfaceElement.addInterfaceOperationElement(); + fInterfaceOperationElement.setName(new NCName(INTOP_NAME)); + + fPattern = new URI("http://www.w3.org/0000/00/wsdl/in-out"); + fInterfaceOperationElement.setPattern(fPattern); + + fDescription = fDescriptionElement.toComponent(); + + Interface iface = fDescription.getInterface(new QName(INTF_NAME)); + fInterfaceOperation = iface.getInterfaceOperation(new QName(INTOP_NAME)); + + fStyleURI1 = new URI("http://www.w3.org/0000/00/apacheStyle"); + fStyleURI2 = new URI("http://www.w3.org/0000/00/anotherApacheStyle"); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /* + * Mandatory attribute ("name") + * - getName() + */ + public void testGetName() + { + QName retrievedName = fInterfaceOperation.getName(); + assertEquals("Retrieved InterfaceOperation name does not match that set -", INTOP_NAME, retrievedName.toString()); + } + + /* + * Mandatory attribute ("pattern") (message exchange pattern) + * - getMessageExchangePattern() + */ + public void testGetMessageExchangePattern() + { + URI uri = fInterfaceOperation.getMessageExchangePattern(); + assertEquals("Retrieved InterfaceOperation mep does not match that set -", fPattern, uri); + } + + /* + * Optional attribute ("style") + * style comprises a list of URIs + * - getStyle() returns the list + */ + public void testGetStyle() + { + // check the default: + URI[] style = fInterfaceOperation.getStyle(); + assertNotNull(style); + assertEquals("Retrieved InterfaceOperation style should be empty if none set -", 0, style.length); + + // add some uri's a couple of times + fInterfaceOperationElement.addStyleURI(fStyleURI1); + fInterfaceOperationElement.addStyleURI(fStyleURI2); + fDescription = fDescriptionElement.toComponent(); + + // getStyle() + style = fInterfaceOperation.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)); + } + + /* + * References to Optional child elements "infault" and "outfault" + * - getInterfaceFaultReferences() + */ + public void testGetInterfaceFaultReferences() + { + // check the default: + InterfaceFaultReference[] ifrArray = fInterfaceOperation.getInterfaceFaultReferences(); + assertNotNull("Expected an array of InterfaceFaultReference.", ifrArray); + assertEquals("Retrieved InterfaceFaultReferenceElement group should be empty if none set -", 0, ifrArray.length); + + // create some InterfaceFaultReferenceElements + InterfaceFaultReferenceElement ifr1 = fInterfaceOperationElement.addInterfaceFaultReferenceElement(); + InterfaceFaultReferenceElement ifr2 = fInterfaceOperationElement.addInterfaceFaultReferenceElement(); + fDescription = fDescriptionElement.toComponent(); + + // getInterfaceFaultReferenceElements() + ifrArray = fInterfaceOperation.getInterfaceFaultReferences(); + assertNotNull("Expected an array of InterfaceFaultReference.", ifrArray); + assertEquals("Retrieved InterfaceFaultReference group should be same number as those set -", 2, ifrArray.length); + + // verify all fault references returned + List ifreL = Arrays.asList(ifrArray); + assertTrue(ifreL.contains(ifr1)); + assertTrue(ifreL.contains(ifr2)); + } + + /* + * References to (Optional) child elements "input" and "output" + * - getInterfaceMessageReferences() + */ + public void testGetInterfaceMessageReferences() + { + // check the default: + InterfaceMessageReference[] imrArray = fInterfaceOperation.getInterfaceMessageReferences(); + assertNotNull("Expected an array of InterfaceMessageReference.", imrArray); + assertEquals("Retrieved InterfaceFaultReference group should be empty if none set -", 0, imrArray.length); + + // create some InterfaceMessageReferenceElements + InterfaceMessageReferenceElement imre1 = fInterfaceOperationElement.addInterfaceMessageReferenceElement(); + InterfaceMessageReferenceElement imre2 = fInterfaceOperationElement.addInterfaceMessageReferenceElement(); + fDescription = fDescriptionElement.toComponent(); + + // getInterfaceMessageReferences() + imrArray = fInterfaceOperation.getInterfaceMessageReferences(); + assertNotNull("Expected an array of InterfaceMessageReference.", imrArray); + assertEquals("Retrieved InterfaceMessageReference group should be same number as those set -", 2, imrArray.length); + + // verify all fault references returned + List imreL = Arrays.asList(imrArray); + assertTrue(imreL.contains(imre1)); + assertTrue(imreL.contains(imre2)); + } + + /* + * toElement() + */ + public void testToElement() + { + assertEquals(fInterfaceOperationElement, fInterfaceOperation.toElement()); + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org For additional commands, e-mail: woden-dev-help@ws.apache.org