jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1071573 - in /jackrabbit/trunk/jackrabbit-webdav/src: main/java/org/apache/jackrabbit/webdav/xml/ test/java/org/apache/jackrabbit/webdav/xml/
Date Thu, 17 Feb 2011 11:05:58 GMT
Author: angela
Date: Thu Feb 17 11:05:57 2011
New Revision: 1071573

URL: http://svn.apache.org/viewvc?rev=1071573&view=rev
Log:
JCR-2888 - Namespace comparison in Namespace.java doesn't work, if a node return null, but
it expects an empty string

Added:
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/NamespaceTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/TestAll.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/Namespace.java

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/Namespace.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/Namespace.java?rev=1071573&r1=1071572&r2=1071573&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/Namespace.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/Namespace.java
Thu Feb 17 11:05:57 2011
@@ -26,9 +26,9 @@ public class Namespace {
 
     private static Logger log = LoggerFactory.getLogger(Namespace.class);
 
-    public static final Namespace EMPTY_NAMESPACE = Namespace.getNamespace("","");
-    public static final Namespace XML_NAMESPACE = Namespace.getNamespace("xml", "http://www.w3.org/XML/1998/namespace");
-    public static final Namespace XMLNS_NAMESPACE = Namespace.getNamespace("xmlns", "http://www.w3.org/2000/xmlns/");
+    public static final Namespace EMPTY_NAMESPACE = new Namespace("","");
+    public static final Namespace XML_NAMESPACE = new Namespace("xml", "http://www.w3.org/XML/1998/namespace");
+    public static final Namespace XMLNS_NAMESPACE = new Namespace("xmlns", "http://www.w3.org/2000/xmlns/");
 
     private final String prefix;
     private final String uri;
@@ -64,8 +64,18 @@ public class Namespace {
         return uri;
     }
 
+    /**
+     * Returns <code>true</code> if the a <code>Namespace</code>
built from the
+     * specified <code>namespaceURI</code> is equal to this namespace object.
+     *
+     * @param namespaceURI A namespace URI to be compared to this namespace instance.
+     * @return true if the a <code>Namespace</code> built from the
+     * specified <code>namespaceURI</code> is equal to this namespace object;
+     * false otherwise.
+     */
     public boolean isSame(String namespaceURI) {
-        return uri.equals(namespaceURI);
+        Namespace other = getNamespace(namespaceURI);
+        return this.equals(other);
     }
 
     //-------------------------------------------------------------< Object >---

Added: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/NamespaceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/NamespaceTest.java?rev=1071573&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/NamespaceTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/NamespaceTest.java
Thu Feb 17 11:05:57 2011
@@ -0,0 +1,94 @@
+/*
+ * 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.jackrabbit.webdav.xml;
+
+import junit.framework.TestCase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <code>NamespaceTest</code>...
+ */
+public class NamespaceTest extends TestCase {
+
+    /**
+     * logger instance
+     */
+    private static final Logger log = LoggerFactory.getLogger(NamespaceTest.class);
+
+    public void testGetNamespace() {
+        assertEquals(Namespace.EMPTY_NAMESPACE, Namespace.getNamespace("", ""));
+        assertEquals(Namespace.EMPTY_NAMESPACE, Namespace.getNamespace(null, null));
+        assertEquals(Namespace.XML_NAMESPACE, Namespace.getNamespace(Namespace.XML_NAMESPACE.getPrefix(),
Namespace.XML_NAMESPACE.getURI()));
+        assertEquals(Namespace.XMLNS_NAMESPACE, Namespace.getNamespace(Namespace.XMLNS_NAMESPACE.getPrefix(),
Namespace.XMLNS_NAMESPACE.getURI()));
+
+        Map<String, String> m = new HashMap<String, String>();
+        m.put("foo", "http://foo.org/ns/foo");
+        m.put("", "http://foo.org/ns/foo");
+        m.put("off", "http://foo.org/ns/foo");
+        m.put("off", "");
+
+        for (String prefix: m.keySet()) {
+            String uri = m.get(prefix);
+            Namespace ns = Namespace.getNamespace(prefix, uri);
+            assertEquals(prefix, ns.getPrefix());
+            assertEquals(uri, ns.getURI());
+            assertEquals(ns, Namespace.getNamespace(prefix, uri));
+        }
+    }
+
+    public void testIsSame() {
+        Map<String, Namespace> same = new HashMap<String, Namespace>();
+        same.put("http://foo.org/ns/foo", Namespace.getNamespace("foo", "http://foo.org/ns/foo"));
+        same.put("http://foo.org/ns/foo", Namespace.getNamespace("abc", "http://foo.org/ns/foo"));
+        same.put("http://foo.org/ns/foo", Namespace.getNamespace("", "http://foo.org/ns/foo"));
+        same.put("http://foo.org/ns/foo", Namespace.getNamespace(null, "http://foo.org/ns/foo"));
+        same.put("", Namespace.EMPTY_NAMESPACE);
+        same.put(null, Namespace.EMPTY_NAMESPACE);
+        same.put(Namespace.XML_NAMESPACE.getURI(), Namespace.XML_NAMESPACE);
+        same.put(Namespace.XMLNS_NAMESPACE.getURI(), Namespace.XMLNS_NAMESPACE);
+
+        for (String nsURI : same.keySet()) {
+            assertTrue(nsURI, same.get(nsURI).isSame(nsURI));
+        }
+
+        Map<String, Namespace> notSame = new HashMap<String, Namespace>();
+        notSame.put("http://foo.org/ns/abc", Namespace.getNamespace("foo", "http://foo.org/ns/foo"));
+        notSame.put("", Namespace.getNamespace("abc", "http://foo.org/ns/foo"));
+        notSame.put(null, Namespace.getNamespace("", "http://foo.org/ns/foo"));
+        notSame.put("http://foo.org/ns/abc", Namespace.EMPTY_NAMESPACE);
+        notSame.put(Namespace.XML_NAMESPACE.getURI(), Namespace.EMPTY_NAMESPACE);
+        notSame.put(Namespace.EMPTY_NAMESPACE.getURI(), Namespace.XML_NAMESPACE);
+        notSame.put(Namespace.XMLNS_NAMESPACE.getURI(), Namespace.XML_NAMESPACE);
+        notSame.put(Namespace.XML_NAMESPACE.getURI(), Namespace.XMLNS_NAMESPACE);
+
+        for (String nsURI : notSame.keySet()) {
+            assertFalse(notSame.get(nsURI).isSame(nsURI));
+        }
+    }
+
+    public void testEquals() {
+        assertEquals(Namespace.EMPTY_NAMESPACE, Namespace.getNamespace("prefix", ""));
+        assertEquals(Namespace.EMPTY_NAMESPACE, Namespace.getNamespace("prefix", null));
+
+        assertFalse(Namespace.EMPTY_NAMESPACE.equals(Namespace.getNamespace("", "something")));
+        assertFalse(Namespace.EMPTY_NAMESPACE.equals(Namespace.getNamespace(null, "something")));
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/NamespaceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/NamespaceTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/TestAll.java?rev=1071573&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/TestAll.java
(added)
+++ jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/TestAll.java
Thu Feb 17 11:05:57 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.jackrabbit.webdav.xml;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all testcases for package org.apache.jackrabbit.webdav.xml.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("org.apache.jackrabbit.webdav.xml tests");
+
+        suite.addTestSuite(NamespaceTest.class);
+
+        return suite;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/xml/TestAll.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message