Author: gturrell Date: Tue Jan 16 07:41:12 2007 New Revision: 496733 URL: http://svn.apache.org/viewvc?view=rev&rev=496733 Log: WODEN-51 Created unit tests for woden wsdl20 Description and DescriptionElement API methods of DescriptionImpl.
Added: incubator/woden/trunk/java/test/org/apache/woden/wsdl20/xml/DescriptionTest.java incubator/woden/trunk/java/test/org/apache/woden/wsdl20/xml/DescriptiontElementTest.java Modified: incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java Modified: incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java?view=diff&rev=496733&r1=496732&r2=496733 ============================================================================== --- incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java (original) +++ incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java Tue Jan 16 07:41:12 2007 @@ -38,6 +38,8 @@ import org.apache.woden.wsdl20.extensions.soap.SOAPBindingFaultReferenceExtensionsTest; import org.apache.woden.wsdl20.extensions.soap.SOAPBindingMessageReferenceExtensionsTest; import org.apache.woden.wsdl20.extensions.soap.SOAPBindingOperationExtensionsTest; +import org.apache.woden.wsdl20.xml.DescriptionTest; +import org.apache.woden.wsdl20.xml.DescriptiontElementTest; import org.apache.woden.wsdl20.xml.EndpointElementTest; import org.apache.woden.wsdl20.xml.EndpointTest; import org.apache.woden.wsdl20.xml.ImportElementTest; @@ -111,6 +113,8 @@ addTest(IncludeElementTest.suite()); addTest(EndpointTest.suite()); addTest(ServiceTest.suite()); + addTest(DescriptionTest.suite()); + addTest(DescriptiontElementTest.suite()); //TODO in-progress 30May06 tests for BindingOpExt and BindingMsgRefExt } Added: incubator/woden/trunk/java/test/org/apache/woden/wsdl20/xml/DescriptionTest.java URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/wsdl20/xml/DescriptionTest.java?view=auto&rev=496733 ============================================================================== --- incubator/woden/trunk/java/test/org/apache/woden/wsdl20/xml/DescriptionTest.java (added) +++ incubator/woden/trunk/java/test/org/apache/woden/wsdl20/xml/DescriptionTest.java Tue Jan 16 07:41:12 2007 @@ -0,0 +1,147 @@ +/** + * Copyright 2005 Apache Software Foundation + * + * Licensed 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 javax.xml.namespace.QName; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.woden.internal.wsdl20.DescriptionImpl; +import org.apache.woden.internal.wsdl20.ServiceImpl; +import org.apache.woden.types.NCName; +import org.apache.woden.wsdl20.Description; +import org.apache.woden.wsdl20.Endpoint; +import org.apache.woden.wsdl20.Interface; +import org.apache.woden.wsdl20.Service; + +/** + * Unit tests for the implementation of Service interface. + * + * @author Graham Turrell ([EMAIL PROTECTED]) + */ +public class DescriptionTest extends TestCase { + + private Service fEmptyService = null; + + public static Test suite() + { + return new TestSuite(DescriptionTest.class); + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + fEmptyService = new ServiceImpl(); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /* + * Test that endpoints associated with a service are correctly returned with + * getEndpoint() and getEndpoints(). + * + * Note that a service must have at least one endpoint associated. + */ + + public void testGetEndpointGetEndpoints() + { + /* Set up prereqs: + * - Service with > 1 endpoints created. + */ + ServiceElement fServiceElement = new ServiceImpl(); + EndpointElement fEndpointElement1 = fServiceElement.addEndpointElement(); + fEndpointElement1.setName(new NCName("endpoint1")); + EndpointElement fEndpointElement2 = fServiceElement.addEndpointElement(); + fEndpointElement2.setName(new NCName("endpoint2")); + Service fService = (Service) fServiceElement; + + // test getEndpoint() + Endpoint e1 = fService.getEndpoint(new NCName("endpoint1")); + assertEquals("The retrieved Endpoint object is not that which was set", e1, fEndpointElement1); + + // test getEndpoints() + Endpoint[] e = fService.getEndpoints(); + assertEquals("The incorrect number of endpoints were returned", e.length, 2); + assertEquals("First endpoint is not endpoint1", e[0], fEndpointElement1); + assertEquals("Second endpoint is not endpoint2", e[1], fEndpointElement2); + } + + /* + * Test that a service returns its (required) associated interface. + * + */ + public void testGetInterface() + { + /* Set up prereqs: + * - Description containing one named Interface; + * - Service using that same Interface. + */ + + // Description... + DescriptionElement fDescElement = new DescriptionImpl(); + + // Interface + InterfaceElement fInterfaceElement = fDescElement.addInterfaceElement(); + fInterfaceElement.setName(new NCName("interface1")); + + // Service... + ServiceElement fServiceElement = fDescElement.addServiceElement(); + fServiceElement.setName(new NCName("service1")); + fServiceElement.setInterfaceName(new QName("interface1")); + fServiceElement.setParentElement(fDescElement); + + // "create" the component model to complete the woden object hierachy references + Description fDesc = fDescElement.toComponent(); + fDesc.getServices(); // necessary to set the reference to Description in Service + + /* Test assertions: + * (Object equivalence is fine here - we check both refer to same Object) + */ + assertEquals(((Service)fServiceElement).getInterface(), (Interface) fInterfaceElement); + } + + /* + * Test that getName() correctly returns the assigned service name + */ + public void testGetName() + { + // for simplicity, the default namespace is used throughout such that the string representation of + // QName from the getter will be identical to the NCName of the setter, for the test to succeed. + ((ServiceImpl)fEmptyService).setName(new NCName("service1")); + assertEquals("The service name from getName() differs from that set.", fEmptyService.getName().toString(), "service1"); + } + + /* + * Tests that the returned class is a ServiceElement + * + */ + public void testToElement() + { + assertTrue(fEmptyService.toElement() instanceof ServiceElement); + } + +} Added: incubator/woden/trunk/java/test/org/apache/woden/wsdl20/xml/DescriptiontElementTest.java URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/wsdl20/xml/DescriptiontElementTest.java?view=auto&rev=496733 ============================================================================== --- incubator/woden/trunk/java/test/org/apache/woden/wsdl20/xml/DescriptiontElementTest.java (added) +++ incubator/woden/trunk/java/test/org/apache/woden/wsdl20/xml/DescriptiontElementTest.java Tue Jan 16 07:41:12 2007 @@ -0,0 +1,178 @@ +/** + * Copyright 2005 Apache Software Foundation + * + * Licensed 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.Map; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.woden.internal.wsdl20.DescriptionImpl; +import org.apache.woden.wsdl20.Description; +import org.apache.woden.wsdl20.extensions.ExtensionRegistry; + +/** + * Unit tests for the DescriptionElement class. + * + * @author Graham Turrell ([EMAIL PROTECTED]) + */ +public class DescriptiontElementTest extends TestCase { + + private DescriptionElement fDescriptionElement = null; + private String fPrefix1 = "prefix1"; + private String fPrefix2 = "prefix2"; + private URI fNamespace1 = null; + private URI fNamespace2 = null; + private URI fDocBaseUri = null; + + public static Test suite() + { + return new TestSuite(DescriptiontElementTest.class); + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + fDescriptionElement = new DescriptionImpl(); + fNamespace1 = new URI("http://apache.org/namespaceURIa"); + fNamespace2 = new URI("http://apache.org/namespaceURIb"); + fDocBaseUri = new URI("http://apache.org/documentbaseURI"); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + public void testSetGetDocumentBaseURI() { + fDescriptionElement.setDocumentBaseURI(fDocBaseUri); + URI retrievedUri = fDescriptionElement.getDocumentBaseURI(); + assertEquals("Retrieved document base URI differs from that set", fDocBaseUri, retrievedUri); + + } + + public void testSetGetTargetNamespace() { + fDescriptionElement.setTargetNamespace(fNamespace1); + URI retrievedTNS = fDescriptionElement.getTargetNamespace(); + assertEquals("Retrieved target Namespace URI differs from that set", fNamespace1, retrievedTNS); + } + + public void testAddGetNamespace() { + fDescriptionElement.addNamespace(fPrefix1,fNamespace1); + URI uri = fDescriptionElement.getNamespace(fPrefix1); + assertEquals("Retrieved NamespaceURI does not match that set", uri, fNamespace1); + } + + /* + * Test getNamespace() when the prefix & namespace pair has not been previously added + */ + public void testGetNullNamespace() { + assertNull("Null was not returned when a non-existent prefix was given", fDescriptionElement.getNamespace("nosuchprefix")); + } + + public void testRemoveNamespace() { + fDescriptionElement.addNamespace(fPrefix1,fNamespace1); + assertNotNull(fDescriptionElement.getNamespace(fPrefix1)); + fDescriptionElement.removeNamespace(fPrefix1); + assertNull(fDescriptionElement.getNamespace(fPrefix1)); + } + + public void testAddGetNamespaces() { + fDescriptionElement.addNamespace(fPrefix1,fNamespace1); + fDescriptionElement.addNamespace(fPrefix2,fNamespace2); + Map uriMap = fDescriptionElement.getNamespaces(); + assertEquals("Expected 2 namespaces", uriMap.size(),2); + URI uri1 = (URI)uriMap.get(fPrefix1); + URI uri2 = (URI)uriMap.get(fPrefix2); + assertEquals("Expected NamespaceURI not found", uri1, fNamespace1); + assertEquals("Expected NamespaceURI not found", uri2, fNamespace2); + } + + + public void testAddGetImportElements() { + ImportElement importElement1 = fDescriptionElement.addImportElement(); + ImportElement importElement2 = fDescriptionElement.addImportElement(); + ImportElement[] imports = fDescriptionElement.getImportElements(); + assertEquals("Expected 2 import elements", imports.length, 2); + } + + public void testAddGetIncludeElements() { + IncludeElement includeElement1 = fDescriptionElement.addIncludeElement(); + IncludeElement includeElement2 = fDescriptionElement.addIncludeElement(); + IncludeElement[] includes = fDescriptionElement.getIncludeElements(); + assertEquals("Expected 2 include elements", includes.length, 2); + } + + public void testAddGetInterfaceElements() { + InterfaceElement interfaceElement1 = fDescriptionElement.addInterfaceElement(); + InterfaceElement interfaceElement2 = fDescriptionElement.addInterfaceElement(); + InterfaceElement[] interfaces = fDescriptionElement.getInterfaceElements(); + assertEquals("Expected 2 interface elements", interfaces.length, 2); + } + + public void testAddGetBindingElements() { + BindingElement bindingElement1 = fDescriptionElement.addBindingElement(); + BindingElement bindingElement2 = fDescriptionElement.addBindingElement(); + BindingElement[] bindings = fDescriptionElement.getBindingElements(); + assertEquals("Expected 2 binding elements", bindings.length, 2); + } + + public void testAddGetServiceElements() { + ServiceElement serviceElement1 = fDescriptionElement.addServiceElement(); + ServiceElement serviceElement2 = fDescriptionElement.addServiceElement(); + ServiceElement[] services = fDescriptionElement.getServiceElements(); + assertEquals("Expected 2 service elements", services.length, 2); + } + + /* + * Call the method once to create a new TypesElement and check that its parent is the + * DecsriptionElement under test. + * Call the method again and ensure the same TypesElement object is returned. + */ + public void testGetTypesElement() { + // check first getTypesElement invocation... + TypesElement typesElement = fDescriptionElement.getTypesElement(); + assertNotNull("Method returned null but expected a TypesElement", typesElement); + + if (typesElement != null) { + assertSame("Expected DescriptionElement to be parent of the TypesElement", + typesElement.getParentElement(), fDescriptionElement); + } + // check subsequent getTypesElement invocation... + assertSame(typesElement, fDescriptionElement.getTypesElement()); + } + + public void testSetGetExtensionRegistry() { + ExtensionRegistry er = new ExtensionRegistry(); + fDescriptionElement.setExtensionRegistry(er); + ExtensionRegistry erRetrieved = fDescriptionElement.getExtensionRegistry(); + assertNotNull("Null given but ExtensionRegistry object expected", erRetrieved); + assertSame("Retrieved ExtensionRegistry object differs fromt hat set", er, erRetrieved); + } + + public void testToComponent() { + Description descComponent = fDescriptionElement.toComponent(); + assertNotNull("Null component object model unexpected", descComponent); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]