jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1421803 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
Date Fri, 14 Dec 2012 11:38:54 GMT
Author: jukka
Date: Fri Dec 14 11:38:53 2012
New Revision: 1421803

URL: http://svn.apache.org/viewvc?rev=1421803&view=rev
Log:
OAK-509: Item names starting with '{X}' cause RepositoryException

Better testing of GlobalNameMapper

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java?rev=1421803&r1=1421802&r2=1421803&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
Fri Dec 14 11:38:53 2012
@@ -26,15 +26,26 @@ import javax.annotation.Nonnull;
 
 /**
  * Name mapper with no local prefix remappings. URI to prefix mappings
- * are read from the repository when needed.
+ * are read from the repository when for transforming expanded JCR names
+ * to prefixed Oak names.
+ * <p>
+ * Note that even though this class could be used to verify that all prefixed
+ * names have valid prefixes, we explicitly don't do that since this is a
+ * fairly performance-sensitive part of the codebase and since normally the
+ * NameValidator and other consistency checks already ensure that all names
+ * being committed or already in the repository should be valid. A separate
+ * consistency check can be used if needed to locate and fix any Oak names
+ * with invalid namespace prefixes.
  */
 public abstract class GlobalNameMapper implements NameMapper {
 
     @Override @Nonnull
     public String getJcrName(@Nonnull String oakName) {
+        // Sanity checks, can be turned to assertions if needed for performance
         checkNotNull(oakName);
         checkArgument(!oakName.startsWith(":")); // hidden name
         checkArgument(!oakName.startsWith("{")); // expanded name
+
         return oakName;
     }
 

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java?rev=1421803&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
Fri Dec 14 11:38:53 2012
@@ -0,0 +1,98 @@
+/*
+ * 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.oak.namepath;
+
+import java.util.Map;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class GlobalNameMapperTest {
+
+    private static final Map<String, String> NAMESPACES = ImmutableMap.of(
+            "jcr", "http://www.jcp.org/jcr/1.0",
+            "nt", "http://www.jcp.org/jcr/nt/1.0",
+            "mix", "http://www.jcp.org/jcr/mix/1.0",
+            "foo", "http://www.example.com/foo",
+            "quu", "http://www.example.com/quu");
+
+    private NameMapper mapper = new GlobalNameMapper() {
+        @Override
+        protected Map<String, String> getNamespaceMap() {
+            return NAMESPACES;
+        }
+    };
+
+    @Test
+    public void testEmptyName() {
+        assertEquals("", mapper.getJcrName(""));
+        assertEquals("", mapper.getOakName(""));
+    }
+
+
+    @Test
+    public void testSimpleNames() {
+        assertEquals("foo", mapper.getOakName("foo"));
+        assertEquals("foo", mapper.getJcrName("foo"));
+        assertEquals("foo ", mapper.getOakName("foo "));
+        assertEquals("foo ", mapper.getJcrName("foo "));
+        assertEquals(" foo ", mapper.getOakName(" foo "));
+        assertEquals(" foo ", mapper.getJcrName(" foo "));
+        assertEquals("foo.bar", mapper.getOakName("foo.bar"));
+        assertEquals("foo.bar", mapper.getJcrName("foo.bar"));
+        assertEquals(".", mapper.getOakName("."));
+        assertEquals(".", mapper.getJcrName("."));
+        assertEquals("..", mapper.getOakName(".."));
+        assertEquals("..", mapper.getJcrName(".."));
+        assertEquals("/", mapper.getOakName("/"));
+        assertEquals("/", mapper.getJcrName("/"));
+        assertEquals(" ", mapper.getOakName(" "));
+        assertEquals(" ", mapper.getJcrName(" "));
+    }
+
+    @Test
+    public void testExpandedNames() {
+        assertEquals("foo", mapper.getOakName("{}foo"));
+        assertEquals("{foo", mapper.getOakName("{foo"));
+        assertEquals("{foo}", mapper.getOakName("{foo}"));
+        assertEquals("{0} foo", mapper.getOakName("{0} foo")); // OAK-509
+        assertEquals("{", mapper.getOakName("{"));
+        assertEquals("nt:base", mapper.getOakName("{http://www.jcp.org/jcr/nt/1.0}base"));
+        assertEquals("foo:bar", mapper.getOakName("{http://www.example.com/foo}bar"));
+        assertEquals("quu:bar", mapper.getOakName("{http://www.example.com/quu}bar"));
+        assertNull(mapper.getOakName("{http://www.example.com/bar}bar"));
+    }
+
+    @Test
+    public void testPrefixedNames() {
+        assertEquals("nt:base", mapper.getOakName("nt:base"));
+        assertEquals("nt:base", mapper.getJcrName("nt:base"));
+        assertEquals("foo: bar", mapper.getOakName("foo: bar"));
+        assertEquals("foo: bar", mapper.getJcrName("foo: bar"));
+        assertEquals("quu:bar ", mapper.getOakName("quu:bar "));
+        assertEquals("quu:bar ", mapper.getJcrName("quu:bar "));
+
+        // unknown prefixes are only captured by the NameValidator
+        assertEquals("unknown:bar", mapper.getOakName("unknown:bar"));
+        assertEquals("unknown:bar", mapper.getJcrName("unknown:bar"));
+    }
+
+}



Mime
View raw message