You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2018/08/01 07:58:51 UTC

svn commit: r1837215 - in /jackrabbit/oak/branches/1.8: ./ oak-jcr/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValidNamesTest.java

Author: reschke
Date: Wed Aug  1 07:58:51 2018
New Revision: 1837215

URL: http://svn.apache.org/viewvc?rev=1837215&view=rev
Log:
OAK-7196: ValidNamesTest improvements (ported to 1.8) - reverted

Modified:
    jackrabbit/oak/branches/1.8/   (props changed)
    jackrabbit/oak/branches/1.8/oak-jcr/   (props changed)
    jackrabbit/oak/branches/1.8/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValidNamesTest.java

Propchange: jackrabbit/oak/branches/1.8/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug  1 07:58:51 2018
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821027,1821130,1821140-1821141,1821178,1821237,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821617,1821663,1821665,1821668,1821681,1821847,1821975-1821983,1822107,1822121,1822201,1822207,1822527,1822723,1822808,1822850,1822934,1823135,1823163,1823169,1823172,1823655,1823669,1824196,1824198,1824253,1824255,1824896,1824962,1825065,1825362,1825381,1825442,1825448,1825466,1825470-1825471,1825475,1825523,1825525,1825561,1825619-1825621,1825651,1825654,1825992,1826079,1826090,1826096,1826216,1826237,1826338,1826516,1826532,1826551,1826560,1826638,1826640,1826730,1826932,1826957,1827423,1827472,1827486,1827977,1828439,1828529,1828948,1829527,1829534,1829546,1829569,1829854,1829864,1829987,1829998,1830019,1830160,1830171,1830197,1830347,1830748,1831157-1831158,1831163,1831374,1831560,1832258,1832376,1832379,1832535,1833308,1833347,1833833
 ,1834610,1834648-1834649,1834681,1834823,1834857-1834858,1835060,1835518,1835642,1835780,1835819,1836487,1836493
+/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821027,1821130,1821140-1821141,1821178,1821237,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821617,1821663,1821665,1821668,1821681,1821847,1821975-1821983,1822121,1822201,1822207,1822527,1822723,1822808,1822850,1822934,1823135,1823163,1823169,1823172,1823655,1823669,1824196,1824198,1824253,1824255,1824896,1824962,1825065,1825362,1825381,1825442,1825448,1825466,1825470-1825471,1825475,1825523,1825525,1825561,1825619-1825621,1825651,1825654,1825992,1826079,1826090,1826096,1826216,1826237,1826338,1826516,1826532,1826551,1826560,1826638,1826640,1826730,1826932,1826957,1827423,1827472,1827486,1827977,1828439,1828529,1828948,1829527,1829534,1829546,1829569,1829854,1829864,1829987,1829998,1830019,1830160,1830171,1830197,1830347,1830748,1831157-1831158,1831163,1831374,1831560,1832258,1832376,1832379,1832535,1833308,1833347,1833833,1834610
 ,1834648-1834649,1834681,1834823,1834857-1834858,1835060,1835518,1835642,1835780,1835819,1836487,1836493
 /jackrabbit/trunk:1345480

Propchange: jackrabbit/oak/branches/1.8/oak-jcr/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug  1 07:58:51 2018
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0/oak-jcr:1665962
-/jackrabbit/oak/trunk/oak-jcr:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821130,1821140-1821141,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821665,1821668,1821681,1821979,1822107,1822121,1822201,1822207,1822723,1822808,1822850,1822934,1823135,1823163,1823169,1824196,1824198,1824962,1825362,1825381,1825442,1825448,1825466,1825470,1825475,1825523,1825525,1825619-1825621,1825651,1825654,1825992,1826079,1826090,1826096,1826237,1826338,1826516,1826532,1826640,1826932,1826957,1827472,1827486,1827977,1829987,1830019,1830160,1830170,1833347
+/jackrabbit/oak/trunk/oak-jcr:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821130,1821140-1821141,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821665,1821668,1821681,1821979,1822121,1822201,1822207,1822723,1822808,1822850,1822934,1823135,1823163,1823169,1824196,1824198,1824962,1825362,1825381,1825442,1825448,1825466,1825470,1825475,1825523,1825525,1825619-1825621,1825651,1825654,1825992,1826079,1826090,1826096,1826237,1826338,1826516,1826532,1826640,1826932,1826957,1827472,1827486,1827977,1829987,1830019,1830160,1830170,1833347
 /jackrabbit/trunk/oak-jcr:1345480

Modified: jackrabbit/oak/branches/1.8/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValidNamesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValidNamesTest.java?rev=1837215&r1=1837214&r2=1837215&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.8/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValidNamesTest.java (original)
+++ jackrabbit/oak/branches/1.8/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValidNamesTest.java Wed Aug  1 07:58:51 2018
@@ -18,20 +18,20 @@ package org.apache.jackrabbit.oak.jcr;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.Map;
 import java.util.UUID;
 
 import javax.jcr.ItemExistsException;
-import javax.jcr.NamespaceException;
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import com.google.common.collect.Maps;
+
 import org.apache.jackrabbit.oak.fixture.NodeStoreFixture;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.junit.After;
@@ -39,8 +39,6 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.Maps;
-
 public class ValidNamesTest extends AbstractRepositoryTest {
 
     private static final String TEST_NODE = "test_node";
@@ -53,14 +51,12 @@ public class ValidNamesTest extends Abst
     private String testPrefix;
     private String testNsUri;
 
-    private static char[] SURROGATE_PAIR = Character.toChars(0x1f4a9);
-
     public ValidNamesTest(NodeStoreFixture fixture) {
         super(fixture);
     }
 
     @Before
-    public void setup() throws NamespaceException, RepositoryException {
+    public void setup() throws RepositoryException {
         Repository repo = createRepository(fixture);
         Session session = repo.login(getAdminCredentials());
         Node root = session.getRootNode();
@@ -110,89 +106,89 @@ public class ValidNamesTest extends Abst
     }
 
     @Test
-    public void testSimple() {
+    public void testSimple() throws RepositoryException {
         nameTest("foo");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testDot() {
-        unsupportedNameTest(".", ItemExistsException.class);
+    @Test(expected = ItemExistsException.class)
+    public void testDot() throws RepositoryException {
+        nameTest(".");
     }
 
     @Test
-    public void testDotFoo() {
+    public void testDotFoo() throws RepositoryException {
         nameTest(".foo");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testDotDot() {
-        unsupportedNameTest("..", ItemExistsException.class);
+    @Test(expected = ItemExistsException.class)
+    public void testDotDot() throws RepositoryException {
+        nameTest("..");
     }
 
     @Test
-    public void testDotDotFoo() {
+    public void testDotDotFoo() throws RepositoryException {
         nameTest("..foo");
     }
 
     @Test
-    public void testTrailingDot() {
+    public void testTrailingDot() throws RepositoryException {
         nameTest("foo.");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testLeadingBlank() {
-        unsupportedNameTest(" foo", RepositoryException.class);
+    @Test(expected = RepositoryException.class)
+    public void testLeadingBlank() throws RepositoryException {
+        nameTest(" foo");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testTrailingBlank() {
-        unsupportedNameTest("foo ", RepositoryException.class);
+    @Test(expected = RepositoryException.class)
+    public void testTrailingBlank() throws RepositoryException {
+        nameTest("foo ");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testEnclosedSlash() {
-        unsupportedNameTest("foo/bar", PathNotFoundException.class);
+    @Test(expected = PathNotFoundException.class)
+    public void testEnclosedSlash() throws RepositoryException {
+        nameTest("foo/bar");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testEnclosedPipe() {
-        unsupportedNameTest("foo|bar", PathNotFoundException.class);
+    @Test(expected = PathNotFoundException.class)
+    public void testEnclosedPipe() throws RepositoryException {
+        nameTest("foo|bar");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testEnclosedStar() {
-        unsupportedNameTest("foo*bar", PathNotFoundException.class);
+    @Test(expected = PathNotFoundException.class)
+    public void testEnclosedStar() throws RepositoryException {
+        nameTest("foo*bar");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testEnclosedOpenBracket() {
-        unsupportedNameTest("foo[bar", PathNotFoundException.class);
+    @Test(expected = PathNotFoundException.class)
+    public void testEnclosedOpenBracket() throws RepositoryException {
+        nameTest("foo[bar");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testEnclosedCloseBracket() {
-        unsupportedNameTest("foo]bar", PathNotFoundException.class);
+    @Test(expected = PathNotFoundException.class)
+    public void testEnclosedCloseBracket() throws RepositoryException {
+        nameTest("foo]bar");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testLeadingColon() {
-        unsupportedNameTest(":foo", RepositoryException.class);
+    @Test(expected = RepositoryException.class)
+    public void testLeadingColon() throws RepositoryException {
+        nameTest(":foo");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testEnclosedUnmappedNsColon() {
-        unsupportedNameTest(unmappedNsPrefix + ":bar", RepositoryException.class);
+    @Test(expected = RepositoryException.class)
+    public void testEnclosedUnmappedNsColon() throws RepositoryException {
+        nameTest(unmappedNsPrefix + ":bar");
     }
 
     // TODO seems to be a bug
@@ -203,12 +199,12 @@ public class ValidNamesTest extends Abst
     }
 
     @Test
-    public void testSingleEnclosedOpenCurly() {
+    public void testSingleEnclosedOpenCurly() throws RepositoryException {
         nameTest("foo{bar");
     }
 
     @Test
-    public void testSingleEnclosedCloseCurly() {
+    public void testSingleEnclosedCloseCurly() throws RepositoryException {
         nameTest("foo}bar");
     }
 
@@ -219,9 +215,9 @@ public class ValidNamesTest extends Abst
     }
 
     // TODO: questionable exception
-    @Test
-    public void testNonUriInCurlys() {
-        unsupportedNameTest("{/}bar", RepositoryException.class);
+    @Test(expected = RepositoryException.class)
+    public void testNonUriInCurlys() throws RepositoryException {
+        nameTest("{/}bar");
     }
 
     @Test
@@ -231,114 +227,87 @@ public class ValidNamesTest extends Abst
     }
 
     // TODO: questionable exception
-    @Test
-    public void testValidNamespaceUriInCurlysWrongPlace() {
-        unsupportedNameTest("x{" + testNsUri + "}foo", RepositoryException.class);
+    @Test(expected = RepositoryException.class)
+    public void testValidNamespaceUriInCurlysWrongPlace() throws RepositoryException {
+        nameTest("x{" + testNsUri + "}foo");
     }
 
     // TODO: questionable exception
-    @Test
-    public void testValidNamespaceUriInCurlysNoLocalName() {
-        unsupportedNameTest("{" + testNsUri + "}", RepositoryException.class);
+    @Test(expected = RepositoryException.class)
+    public void testValidNamespaceUriInCurlysNoLocalName() throws RepositoryException {
+        nameTest("{" + testNsUri + "}");
     }
 
-    // TODO this should actually pass
-    @Test
-    public void testQualifiedNameWithUnmappedNsUri() {
+    // TODO better exception - or maybe this should pass?
+    @Test(expected = RepositoryException.class)
+    public void testQualifiedNameWithUnmappedNsUri() throws RepositoryException {
         String ns = "urn:uuid:" + UUID.randomUUID().toString();
-        unsupportedNameTest("{" + ns + "}foo", RepositoryException.class);
+        Node n = nameTest("{" + ns + "}foo");
+        String pref = n.getSession().getNamespacePrefix(ns);
+        assertEquals(pref + ":foo", n.getName());
     }
 
     @Test
-    public void testEnclosedPercent() {
+    public void testEnclosedPercent() throws RepositoryException {
         nameTest("foo%bar");
     }
 
     @Test
-    public void testEnclosedBlank() {
+    public void testEnclosedBlank() throws RepositoryException {
         nameTest("foo bar");
     }
 
-    @Test
-    public void testEnclosedTab() {
-        unsupportedNameTest("foo\tbar", RepositoryException.class);
+    @Test(expected = RepositoryException.class)
+    public void testEnclosedTab() throws RepositoryException {
+        nameTest("foo\tbar");
     }
 
-    @Test
-    public void testEnclosedLf() {
-        unsupportedNameTest("foo\nbar", RepositoryException.class);
+    @Test(expected = RepositoryException.class)
+    public void testEnclosedLf() throws RepositoryException {
+        nameTest("foo\nbar");
     }
 
-    @Test
-    public void testEnclosedCr() {
-        unsupportedNameTest("foo\rbar", RepositoryException.class);
+    @Test(expected = RepositoryException.class)
+    public void testEnclosedCr() throws RepositoryException {
+        nameTest("foo\rbar");
     }
 
     @Test
-    public void testEnclosedNonBreakingSpace() {
+    public void testEnclosedNonBreakingSpace() throws RepositoryException {
         nameTest("foo\u00a0bar");
     }
 
     // OAK-4587
-    @Test
-    public void testEnclosedIdeographicSpace() {
-        unsupportedNameTest("foo\u3000bar", RepositoryException.class);
+    @Test(expected = RepositoryException.class)
+    public void testEnclosedIdeographicSpace() throws RepositoryException {
+        nameTest("foo\u3000bar");
     }
 
     @Test
-    public void testUnpairedHighSurrogateEnd() {
+    public void testUnpairedSurrogate() throws RepositoryException {
         // see OAK-5506
         org.junit.Assume.assumeFalse(super.fixture.toString().toLowerCase().contains("segment"));
-        nameTest("foo" + SURROGATE_PAIR[0]);
+        nameTest("foo\ud800");
     }
 
     @Test
-    public void testUnpairedLowSurrogateStart() {
-        // see OAK-5506
-        org.junit.Assume.assumeFalse(super.fixture.toString().toLowerCase().contains("segment"));
-        nameTest(SURROGATE_PAIR[1] + "foo");
+    public void testSurrogate() throws RepositoryException {
+        nameTest("foo\uD83D\uDCA9");
     }
 
-    @Test
-    public void testUnpairedSurrogateInside() {
-        // see OAK-5506
-        org.junit.Assume.assumeFalse(super.fixture.toString().toLowerCase().contains("segment"));
-        nameTest("foo" + SURROGATE_PAIR[0] + "bar");
-        nameTest("foo" + SURROGATE_PAIR[1] + "bar");
-    }
-
-    @Test
-    public void testSurrogate() {
-        nameTest("foo" + new String(SURROGATE_PAIR));
-    }
-
-    private Node nameTest(String nodeName) {
+    private Node nameTest(String nodeName) throws RepositoryException {
+        Node n = testNode.addNode(nodeName);
+        testNode.getSession().save();
         try {
-            Node n = testNode.addNode(nodeName);
-            testNode.getSession().save();
-            Node p = testNode.getSession().getNode(n.getPath());
-            assertTrue("nodes should be the same", p.isSame(n));
-            assertEquals("paths should be equal", p.getPath(), n.getPath());
-            return p;
+            return testNode.getSession().getNode(n.getPath());
         } catch (RepositoryException ex) {
             fail(ex.getMessage());
             return null;
         }
     }
 
-    private void unsupportedNameTest(String nodeName, Class<? extends RepositoryException> clazz) {
-        try {
-            testNode.addNode(nodeName);
-            testNode.getSession().save();
-            fail("should have failed with " + clazz);
-        }
-        catch (RepositoryException ex) {
-            assertTrue("should have failed with " + clazz + ", but got " + ex.getClass(), clazz.isAssignableFrom(ex.getClass()));
-        }
-    }
-
-    private Repository createRepository(NodeStoreFixture fixture) throws RepositoryException
-            {
+    private Repository createRepository(NodeStoreFixture fixture)
+            throws RepositoryException {
         NodeStore ns = null;
         for (Map.Entry<NodeStoreFixture, NodeStore> e : STORES.entrySet()) {
             if (e.getKey().getClass().equals(fixture.getClass())) {