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 lm...@apache.org on 2008/02/12 19:53:33 UTC

svn commit: r627031 - in /webservices/woden/branches/woden62: src/org/apache/woden/internal/ src/org/apache/woden/internal/wsdl20/assertions/ test/org/apache/woden/internal/wsdl20/assertions/ test/org/apache/woden/tests/

Author: lmandel
Date: Tue Feb 12 10:53:30 2008
New Revision: 627031

URL: http://svn.apache.org/viewvc?rev=627031&view=rev
Log:
[Woden-198] Created Interface1009 assertion class and test class. Created assertion test suite.

Added:
    webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Interface1009.java   (with props)
    webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/
    webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/AssertionTestSuite.java   (with props)
    webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestInterface1009.java   (with props)
Modified:
    webservices/woden/branches/woden62/src/org/apache/woden/internal/Messages.properties
    webservices/woden/branches/woden62/test/org/apache/woden/tests/AllWodenTestsDOM.java

Modified: webservices/woden/branches/woden62/src/org/apache/woden/internal/Messages.properties
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden62/src/org/apache/woden/internal/Messages.properties?rev=627031&r1=627030&r2=627031&view=diff
==============================================================================
--- webservices/woden/branches/woden62/src/org/apache/woden/internal/Messages.properties (original)
+++ webservices/woden/branches/woden62/src/org/apache/woden/internal/Messages.properties Tue Feb 12 10:53:30 2008
@@ -220,7 +220,7 @@
 # For each Endpoint component in the {endpoints} property of a Service component, the {binding} property MUST either be a Binding component with an unspecified {interface} property or a Binding component with an {interface} property equal to the {interface} property of the Service component.
 Endpoint-1062 = The binding ''{0}'' specified for this endpoint specifies the interface ''{1}'' and not the interface ''{2}'' specified by the service. The binding specified for this endpoint must either not specify an interface or specify the same interface as the service.
 
-Interface-1009 = This interface extends itself via the extended interface ''{0}''. An interface cannot appear in the list of interfaces it extends.
+Interface-1009 = The interface ''{0}'' appears in the list of interfaces it extends.
 Interface-1009.ref = 2.2.1
 Interface-1009.assertion = To avoid circular definitions, an interface MUST NOT appear as an element of the set of interfaces it extends, either directly or indirectly.
 

Added: webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Interface1009.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Interface1009.java?rev=627031&view=auto
==============================================================================
--- webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Interface1009.java (added)
+++ webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Interface1009.java Tue Feb 12 10:53:30 2008
@@ -0,0 +1,80 @@
+/**
+ * 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.internal.wsdl20.assertions;
+
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.apache.woden.internal.ErrorLocatorImpl;
+import org.apache.woden.wsdl20.Interface;
+import org.apache.woden.wsdl20.validation.Assertion;
+
+/**
+ * This class represents assertion Interface-1009 from the WSDL 2.0 specification.
+ * For details about this assertion see:
+ * http://www.w3.org/TR/2007/REC-wsdl20-20070626/#Interface-1009
+ * 
+ * @author Lawrence Mandel (lmandel@apache.org)
+ */
+public class Interface1009 implements Assertion {
+
+	private final static String ID = "Interface-1009".intern();
+	
+	/* (non-Javadoc)
+	 * @see org.apache.woden.wsdl20.validation.Assertion#getAssertionID()
+	 */
+	public String getAssertionID() {
+		return ID;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.woden.wsdl20.validation.Assertion#validate(java.lang.Object, org.apache.woden.ErrorReporter)
+	 */
+	public boolean validate(Object target, ErrorReporter errorReporter) {
+		Interface interfac = (Interface)target;
+		Interface[] extendedInterfaces = interfac.getExtendedInterfaces();
+		if(containsInterface(interfac, extendedInterfaces)) {
+			try {
+				errorReporter.reportError(new ErrorLocatorImpl(), ID , new Object[]{interfac.getName()}, ErrorReporter.SEVERITY_ERROR);
+			}catch(WSDLException e) {
+				//TODO: Log problem reporting error.
+			}
+			return false;
+		}
+		return true;
+	}
+	
+	/**
+	   * Check whether the specified interface is in the list of extended interfaces.
+	   * 
+	   * @param interfac The interface that should be checked to see if it is in the list of exteneded interfaces. 
+	   * @param extendedInterfaces An array of interfaces representing the list of extended interfaces.
+	   * @return true if the interface is in the list of extended interfaces, false otherwise.
+	   */
+	private boolean containsInterface(Interface interfac, Interface[] extendedInterfaces) {
+		boolean foundInterface = false;
+		
+		int numExtInterfaces = extendedInterfaces.length;
+		for(int i = 0; i < numExtInterfaces && !foundInterface; i++) {
+		  if(interfac.equals(extendedInterfaces[i]))
+		    foundInterface = true;
+		  else if(containsInterface(interfac, extendedInterfaces[i].getExtendedInterfaces()))
+			foundInterface = true;
+		}
+		return foundInterface;
+	  }
+
+}

Propchange: webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Interface1009.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/AssertionTestSuite.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/AssertionTestSuite.java?rev=627031&view=auto
==============================================================================
--- webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/AssertionTestSuite.java (added)
+++ webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/AssertionTestSuite.java Tue Feb 12 10:53:30 2008
@@ -0,0 +1,38 @@
+/**
+ * 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.internal.wsdl20.assertions;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * The assertion test suite contains all of the assertion tests.
+ * 
+ * @author Lawrence Mandel (lmandel@apache.org)
+ */
+public class AssertionTestSuite {
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite(
+				"Test for org.apache.woden.internal.wsdl20.assertions");
+		//$JUnit-BEGIN$
+		suite.addTestSuite(TestInterface1009.class);
+		//$JUnit-END$
+		return suite;
+	}
+
+}

Propchange: webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/AssertionTestSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestInterface1009.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestInterface1009.java?rev=627031&view=auto
==============================================================================
--- webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestInterface1009.java (added)
+++ webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestInterface1009.java Tue Feb 12 10:53:30 2008
@@ -0,0 +1,166 @@
+/**
+ * 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.internal.wsdl20.assertions;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import junit.framework.TestCase;
+
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.internal.wsdl20.InterfaceImpl;
+import org.apache.woden.tests.TestErrorHandler;
+import org.apache.woden.types.NCName;
+import org.apache.woden.wsdl20.Description;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
+import org.apache.woden.wsdl20.xml.InterfaceElement;
+
+/**
+ * Test class for assertion class Interface1009.
+ * 
+ * @author Lawrence Mandel (lmandel@apache.org)
+ */
+public class TestInterface1009 extends TestCase {
+
+	private WSDLFactory factory = null;
+	private Interface1009 assertion = new Interface1009();
+	private ErrorReporter reporter;
+	private TestErrorHandler handler;
+	
+	@Override
+	protected void setUp() throws Exception {
+	    try {
+	        factory = WSDLFactory.newInstance();
+	    } catch (WSDLException e) {
+	        fail("Can't instantiate the WSDLFactory object.");
+	    }
+	    
+	    handler = new TestErrorHandler();
+	    reporter = factory.newWSDLReader().getErrorReporter();
+		reporter.setErrorHandler(handler);
+	}
+
+	/**
+	 * Test that the assertion returns true for an interface that 
+	 * extends no other interfaces.
+	 */
+	public void testNoInterfaceExtension() {
+		DescriptionElement descEl = factory.newDescription();
+		Description descComp = descEl.toComponent();
+		InterfaceImpl interfac = (InterfaceImpl)descEl.addInterfaceElement();
+		interfac.setName(new NCName("name"));
+		if(!assertion.validate(interfac, reporter)) {
+			fail("Assertion Interface1009 false for an interface that extends no other interfaces.");
+		}
+	}
+	
+	/**
+	 * Test that the assertion returns false if the interface is in the direct list.
+	 */
+	public void testInterfaceExtendsItselfDirectly() {
+		DescriptionElement descEl = factory.newDescription();
+		Description descComp = descEl.toComponent();
+		try {
+			descEl.setTargetNamespace(new URI("http://testnamespace"));
+		} catch(URISyntaxException e) {
+			// Do nothing.
+		}
+		  
+		InterfaceImpl interfac = (InterfaceImpl)descEl.addInterfaceElement();
+		interfac.setName(new NCName("name1"));
+		
+	    interfac.addExtendedInterfaceName(interfac.getName());
+	      
+	    // init Interface's ref to its Description, needed for interface extension.
+	    descComp.getInterfaces(); 
+		  
+	    if(assertion.validate(interfac, reporter)) {
+	    	fail("Assertion Interface1009 returned true for an interface that directly extends itself.");
+	    }
+	}
+	
+	/**
+	 * Test that the assertion returns false if the interface is in the indirect list.
+	 */
+	public void testInterfaceExtendsItselfIndirectly() {
+		DescriptionElement descEl = factory.newDescription();
+		Description descComp = descEl.toComponent();
+		try {
+			descEl.setTargetNamespace(new URI("http://testnamespace"));
+		} catch(URISyntaxException e) {
+			// Do nothing.
+		}
+		InterfaceImpl interfac = (InterfaceImpl)descEl.addInterfaceElement();
+		interfac.setName(new NCName("name1"));
+		InterfaceImpl interfac2 = (InterfaceImpl)descEl.addInterfaceElement();
+		interfac2.setName(new NCName("name2"));
+	      
+		interfac.addExtendedInterfaceName(interfac2.getName());
+		interfac2.addExtendedInterfaceName(interfac.getName());
+	      
+		// init Interface's ref to its Description, needed for interface extension.
+		descComp.getInterfaces(); 
+		  
+		if(assertion.validate(interfac, reporter)) {
+			fail("Assertion Interface1009 returned true for an interface that indirectly extends itself.");
+		}
+	}
+	
+	/**
+	 * Test that the assertion returns true if the interface is not 
+	 * in the direct or indirect list of extended interfaces.
+	 */
+	public void testInterfaceExtendsOtherInterfaces() {
+		DescriptionElement descEl = factory.newDescription();
+		Description descComp = descEl.toComponent();
+	      
+		try {
+			descEl.setTargetNamespace(new URI("http://testnamespace"));
+		} catch(URISyntaxException e) {
+			// Do nothing.
+		}
+	      
+		// Create an interface, set it to extend to other interfaces and have
+		// one of those interfaces extend a fourth interface.
+		InterfaceElement interfac = descEl.addInterfaceElement();
+		interfac.setName(new NCName("name1"));
+	      
+		InterfaceElement interfac2 = descEl.addInterfaceElement();
+		interfac2.setName(new NCName("name2"));
+
+		interfac.addExtendedInterfaceName(interfac2.getName());
+	      
+		InterfaceElement interfac3 = descEl.addInterfaceElement();
+		interfac3.setName(new NCName("name3"));
+	      
+		interfac.addExtendedInterfaceName(interfac3.getName());
+	      
+		InterfaceElement interfac4 = descEl.addInterfaceElement();
+		interfac4.setName(new NCName("name4"));
+	      
+		interfac2.addExtendedInterfaceName(interfac4.getName());
+	        
+		// init Interface's ref to its Description, needed for interface extension.
+		descComp.getInterfaces(); 
+		  
+		if(!assertion.validate(interfac, reporter)) {
+			fail("Assertion Interface1009 returned false for an interface that is not in the list of exteneded interfaces.");
+		}
+	}
+}

Propchange: webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestInterface1009.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/woden/branches/woden62/test/org/apache/woden/tests/AllWodenTestsDOM.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden62/test/org/apache/woden/tests/AllWodenTestsDOM.java?rev=627031&r1=627030&r2=627031&view=diff
==============================================================================
--- webservices/woden/branches/woden62/test/org/apache/woden/tests/AllWodenTestsDOM.java (original)
+++ webservices/woden/branches/woden62/test/org/apache/woden/tests/AllWodenTestsDOM.java Tue Feb 12 10:53:30 2008
@@ -23,6 +23,7 @@
 import org.apache.woden.WSDLFactoryTest;
 import org.apache.woden.WSDLReaderTest;
 import org.apache.woden.internal.ReaderFeaturesTest;
+import org.apache.woden.internal.wsdl20.assertions.AssertionTestSuite;
 import org.apache.woden.internal.wsdl20.validation.WSDLComponentValidatorTest;
 import org.apache.woden.internal.wsdl20.validation.WSDLDocumentValidatorTest;
 import org.apache.woden.resolver.SimpleURIResolverTest;
@@ -111,6 +112,7 @@
 	addTestSuite(ReaderFeaturesTest.class);
 	addTest(WSDLDocumentValidatorTest.suite());
 	addTest(WSDLComponentValidatorTest.suite());
+	addTest(AssertionTestSuite.suite());
     addTest(ServiceElementTest.suite());
     addTest(EndpointElementTest.suite());
     addTest(NameAttributeTest.suite());



---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org