Author: lmandel
Date: Tue Feb 12 19:08:10 2008
New Revision: 627228

URL: http://svn.apache.org/viewvc?rev=627228&view=rev
Log:
[WODEN-200] Created Interface1010 assertion class and added it to the 
WSDLValidator. Also created tests for this assertion class.

Added:
    
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Interface1010.java
   (with props)
    
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestInterface1010.java
   (with props)
Modified:
    
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/validation/WSDLValidator.java
    
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/AssertionTestSuite.java

Added: 
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Interface1010.java
URL: 
http://svn.apache.org/viewvc/webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Interface1010.java?rev=627228&view=auto
==============================================================================
--- 
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Interface1010.java
 (added)
+++ 
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Interface1010.java
 Tue Feb 12 19:08:10 2008
@@ -0,0 +1,74 @@
+/**
+ * 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.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.apache.woden.internal.ErrorLocatorImpl;
+import org.apache.woden.wsdl20.Description;
+import org.apache.woden.wsdl20.Interface;
+import org.apache.woden.wsdl20.validation.Assertion;
+
+/**
+ * This class represents assertion Interface-1010 from the WSDL 2.0 
specification.
+ * For details about this assertion see:
+ * http://www.w3.org/TR/2007/REC-wsdl20-20070626/#Interface-1010
+ * 
+ * @author Lawrence Mandel ([EMAIL PROTECTED])
+ */
+public class Interface1010 implements Assertion {
+
+       public final static String ID = "Interface-1010".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 void validate(Object target, ErrorReporter errorReporter) {
+               Description desc = (Description)target;
+               Interface[] interfaces = desc.getInterfaces();
+               
+               List names = new ArrayList();
+               int numInterfaces = interfaces.length;
+               for(int i = 0; i < numInterfaces; i++) {
+                       QName name = interfaces[i].getName();
+                       if(name == null)
+                               continue;
+                       if(names.contains(name)) {
+                               try {
+                                       errorReporter.reportError(new 
ErrorLocatorImpl(), ID, new Object[]{name}, ErrorReporter.SEVERITY_ERROR);
+                               }catch(WSDLException e) {
+                                       //TODO: Log problem reporting error.
+                               }
+                       }
+                       else {
+                               names.add(name);
+                       }
+               }
+       }
+}

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

Modified: 
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/validation/WSDLValidator.java
URL: 
http://svn.apache.org/viewvc/webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/validation/WSDLValidator.java?rev=627228&r1=627227&r2=627228&view=diff
==============================================================================
--- 
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/validation/WSDLValidator.java
 (original)
+++ 
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/validation/WSDLValidator.java
 Tue Feb 12 19:08:10 2008
@@ -25,6 +25,7 @@
 import org.apache.woden.internal.wsdl20.assertions.Description1002;
 import org.apache.woden.internal.wsdl20.assertions.Description1003;
 import org.apache.woden.internal.wsdl20.assertions.Interface1009;
+import org.apache.woden.internal.wsdl20.assertions.Interface1010;
 import org.apache.woden.wsdl20.Description;
 import org.apache.woden.wsdl20.Interface;
 import org.apache.woden.wsdl20.WSDLComponent;
@@ -102,6 +103,8 @@
                 new AssertionInfo(new Description1003(), 
DescriptionElement.class, null));
         fAssertions.put(Interface1009.ID, 
                 new AssertionInfo(new Interface1009(), Interface.class, null));
+        fAssertions.put(Interface1010.ID, 
+                new AssertionInfo(new Interface1010(), Description.class, 
null));
         //TODO rest of WSDL 2.0 assertions defined in the spec
     }
 

Modified: 
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=627228&r1=627227&r2=627228&view=diff
==============================================================================
--- 
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/AssertionTestSuite.java
 (original)
+++ 
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/AssertionTestSuite.java
 Tue Feb 12 19:08:10 2008
@@ -31,6 +31,7 @@
                                "Test for 
org.apache.woden.internal.wsdl20.assertions");
                //$JUnit-BEGIN$
                suite.addTestSuite(TestInterface1009.class);
+               suite.addTestSuite(TestInterface1010.class);
                //$JUnit-END$
                return suite;
        }

Added: 
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestInterface1010.java
URL: 
http://svn.apache.org/viewvc/webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestInterface1010.java?rev=627228&view=auto
==============================================================================
--- 
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestInterface1010.java
 (added)
+++ 
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestInterface1010.java
 Tue Feb 12 19:08:10 2008
@@ -0,0 +1,193 @@
+/**
+ * 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.Interface;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
+import org.apache.woden.wsdl20.xml.InterfaceElement;
+
+/**
+ * Test class for assertion class Interface1009.
+ * 
+ * @author Lawrence Mandel ([EMAIL PROTECTED])
+ */
+public class TestInterface1010 extends TestCase {
+
+       private WSDLFactory factory = null;
+       private Interface1010 assertion = new Interface1010();
+       private ErrorReporter reporter;
+       private TestErrorHandler handler;
+       
+       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);
+       }
+       
+       protected void tearDown() throws Exception {
+               factory = null;
+               reporter = null;
+               handler = null;
+       }
+
+       /**
+        * Test that the assertion passes for an empty list of interfaces.
+        */
+       public void testNoInterfaces() {
+               DescriptionElement descEl = factory.newDescription();
+               Description descComp = descEl.toComponent();
+             
+               try {
+                       descEl.setTargetNamespace(new 
URI("http://testnamespace";));
+               } catch(URISyntaxException e) {
+                       // Do nothing.
+               }
+             
+               assertion.validate(descComp, reporter);
+               if(handler.errorMessageHasBeenReported()) {
+                       fail("Assertion Interface1010 failed incorrectly with 
no interfaces specified.");
+               }
+       }
+       
+       /**
+        * Test that the assertion passes when only one interface is defined.
+        */
+       public void testOneInterface() {
+               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"));
+               
+               assertion.validate(descComp, reporter);
+               
+               if(handler.errorMessageHasBeenReported()) {
+                       fail("Assertion Interface1010 failed incorrectly with a 
single interface defined.");
+               }
+       }
+       
+       /**
+        * Test that the assertion passes for a list of interfaces that 
contains no duplicate names.
+        */
+       public void testMultipleInterfaceNoDuplicateNames() {
+               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"));
+               InterfaceImpl interfac3 = 
(InterfaceImpl)descEl.addInterfaceElement();
+               interfac3.setName(new NCName("name3"));
+                 
+               assertion.validate(descComp, reporter);
+               
+               if(handler.errorMessageHasBeenReported()) {
+                       fail("Assertion Interface1010 failed incorrectly with 
multiple interfaces defined with no duplicate names.");
+               }
+       }
+       
+       /**
+        * Test that the assertion fails for two interfaces that are defined 
with the same NCName object.
+        */
+       public void testDuplicateInterfaceNCNames() {
+               DescriptionElement descEl = factory.newDescription();
+               Description descComp = descEl.toComponent();
+             
+               try {
+                       descEl.setTargetNamespace(new 
URI("http://testnamespace";));
+               } catch(URISyntaxException e) {
+                       // Do nothing.
+               }
+               
+               NCName name = new NCName("name");
+               InterfaceImpl interfac = 
(InterfaceImpl)descEl.addInterfaceElement();
+               interfac.setName(name);
+               InterfaceImpl interfac2 = 
(InterfaceImpl)descEl.addInterfaceElement();
+               interfac2.setName(name);
+               // Need to create an extended interface otherwise the component 
model treats the
+               // two interfaces as equal and only adds one to the set.
+               InterfaceImpl interfac3 = 
(InterfaceImpl)descEl.addInterfaceElement();
+               interfac3.setName(new NCName("name3"));
+               interfac2.addExtendedInterfaceName(interfac3.getName());
+                 
+               assertion.validate(descComp, reporter);
+                 
+               if(!handler.errorMessageHasBeenReported()) {
+                   fail("Assertion Interface1010 passed incorrectly for two 
interfaces defined with the same NCName.");
+               }
+       }
+       
+       /**
+        * Test that the assertion fails for two interfaces that are defined 
with the same name.
+        */
+       public void testDuplicateInterfaceNames() {
+               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("name"));
+               InterfaceImpl interfac2 = 
(InterfaceImpl)descEl.addInterfaceElement();
+               interfac2.setName(new NCName("name"));
+               // Need to create an extended interface otherwise the component 
model treats the
+               // two interfaces as equal and only adds one to the set.
+               InterfaceImpl interfac3 = 
(InterfaceImpl)descEl.addInterfaceElement();
+               interfac3.setName(new NCName("name3"));
+               interfac2.addExtendedInterfaceName(interfac3.getName());
+                 
+               assertion.validate(descComp, reporter);
+                 
+               if(!handler.errorMessageHasBeenReported()) {
+                   fail("Assertion Interface1010 passed incorrectly for two 
interfaces defined with the same name.");
+               }
+       }
+       
+}

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



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to