Author: lmandel
Date: Tue Mar 11 08:32:44 2008
New Revision: 635975

URL: http://svn.apache.org/viewvc?rev=635975&view=rev
Log:
[WODEN-201] Fixed NPE for target namespace with the urn scheme. Added unit test 
for this case.

Added:
    
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestDescription1001.java
   (with props)
Modified:
    
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Description1001.java
    
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/AssertionTestSuite.java

Modified: 
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Description1001.java
URL: 
http://svn.apache.org/viewvc/webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Description1001.java?rev=635975&r1=635974&r2=635975&view=diff
==============================================================================
--- 
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Description1001.java
 (original)
+++ 
webservices/woden/branches/woden62/src/org/apache/woden/internal/wsdl20/assertions/Description1001.java
 Tue Mar 11 08:32:44 2008
@@ -1,3 +1,19 @@
+/**
+ * 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.io.FileNotFoundException;
@@ -11,8 +27,22 @@
 import org.apache.woden.wsdl20.validation.WodenContext;
 import org.apache.woden.wsdl20.xml.DescriptionElement;
 
+/**
+ * This class represents assertion Description-1001 from the WSDL 2.0 
specification.
+ * For details about this assertion see:
+ * http://www.w3.org/TR/2007/REC-wsdl20-20070626/#Description-1001
+ * 
+ * @author John Kaputin ([EMAIL PROTECTED])
+ * @author Lawrence Mandel ([EMAIL PROTECTED])
+ */
 public class Description1001 implements Assertion {
 
+       /**
+        * A list of URI schemes for which this assertion will attempt to check 
if
+        * the target namespace is dereferencable. 
+        */
+       private static String searchableSchemes = "http,ftp,file";
+       
     public String getId() {
         return "Description-1001".intern();
     }
@@ -24,8 +54,15 @@
         try {
             URI resolvedUri = wodenCtx.getUriResolver().resolveURI(tns);
             URI uri = resolvedUri != null ? resolvedUri : tns;
-            URL url = uri.toURL();
-            Object o = url.getContent();
+            String scheme = uri.getScheme();
+            
+            // Only check if the scheme is a type that we can locate.
+            // TODO: See if the searchable schemes should be extensible.
+            Object o = null;
+            if(searchableSchemes.contains(scheme)) {
+               URL url = uri.toURL();
+               o = url.getContent();
+            }
             if(o == null) {
                 wodenCtx.getErrorReporter().reportError(
                         new ErrorLocatorImpl(), getId(), new Object[] {tns}, 
ErrorReporter.SEVERITY_WARNING);

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=635975&r1=635974&r2=635975&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 Mar 11 08:32:44 2008
@@ -30,6 +30,7 @@
                TestSuite suite = new TestSuite(
                                "Test for 
org.apache.woden.internal.wsdl20.assertions");
                //$JUnit-BEGIN$
+               suite.addTestSuite(TestDescription1001.class);
                suite.addTestSuite(TestInterface1009.class);
                suite.addTestSuite(TestInterface1010.class);
                //$JUnit-END$

Added: 
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestDescription1001.java
URL: 
http://svn.apache.org/viewvc/webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestDescription1001.java?rev=635975&view=auto
==============================================================================
--- 
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestDescription1001.java
 (added)
+++ 
webservices/woden/branches/woden62/test/org/apache/woden/internal/wsdl20/assertions/TestDescription1001.java
 Tue Mar 11 08:32:44 2008
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0 
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+package org.apache.woden.internal.wsdl20.assertions;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.WSDLReader;
+import org.apache.woden.internal.resolver.SimpleURIResolver;
+import org.apache.woden.tests.TestErrorHandler;
+import org.apache.woden.wsdl20.validation.WodenContext;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
+
+/**
+ * Test class for assertion class Description1001.
+ * 
+ * @author Lawrence Mandel ([EMAIL PROTECTED])
+ */
+public class TestDescription1001 extends TestCase {
+
+       private WSDLFactory factory = null;
+       private Description1001 assertion = new Description1001();
+       private ErrorReporter reporter;
+       private TestErrorHandler handler;
+       private WodenContext wodenContext;
+       
+       protected void setUp() throws Exception {
+           try {
+               factory = WSDLFactory.newInstance();
+           } catch (WSDLException e) {
+               fail("Can't instantiate the WSDLFactory object.");
+           }
+           
+           WSDLReader reader = factory.newWSDLReader();
+        reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
+           reporter = reader.getErrorReporter();
+        handler = new TestErrorHandler();
+           reporter.setErrorHandler(handler);
+               wodenContext = new WodenContextImpl(reporter, new 
SimpleURIResolver());
+       }
+       
+       protected void tearDown() throws Exception {
+               factory = null;
+               reporter = null;
+               handler = null;
+               wodenContext = null;
+       }
+
+       /**
+        * Test that the assertion passes for an interface that 
+        * extends no other interfaces.
+        */
+       public void testTargetNamespaceSchemeurn() {
+               DescriptionElement descEl = factory.newDescription();
+               descEl.setTargetNamespace(URI.create("urn:sample"));
+
+               try {
+                       assertion.validate(descEl, wodenContext);
+               } catch(WSDLException e){
+                       fail("Assertion Description1001 threw the following 
WSDLException for target namespace urn:sample: " + e.toString());
+               }
+               if(handler.errorMessageHasBeenReported()) {
+                       fail("Assertion Description1001 fails incorrectly for 
an target namespace with the scheme urn.");
+               }
+               else if(!handler.messageHasBeenReported()) {
+                       fail("Assertion Description1001 did not report a 
warning for a target namespace with the scheme urn.");
+               }
+       }
+}

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



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

Reply via email to