You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2012/10/31 15:06:13 UTC

svn commit: r1404144 [2/5] - in /jackrabbit/branches/2.2: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/management/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation/ jac...

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentWorkspaceCopyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentWorkspaceCopyTest.java?rev=1404144&r1=1404143&r2=1404144&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentWorkspaceCopyTest.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentWorkspaceCopyTest.java Wed Oct 31 14:06:06 2012
@@ -1,119 +1,119 @@
-/*
- * 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.core;
-
-import org.apache.jackrabbit.test.AbstractJCRTest;
-
-import javax.jcr.NodeIterator;
-import javax.jcr.Session;
-import javax.jcr.RepositoryException;
-import java.util.Random;
-
-
-public class ConcurrentWorkspaceCopyTest extends AbstractJCRTest {
-
-    private static final int NUM_ITERATIONS = 40;
-    private static final int NUM_SESSIONS = 2;
-
-    static final String TARGET_NAME = "copy of src";
-    String sourcePath;
-    String destParentPath;
-    String destPath;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        // create a parent node where allowSameNameSiblings is set to false
-        destParentPath =
-                testRootNode.addNode("destParent",
-                        "nt:folder").getPath();
-        destPath = destParentPath + "/" + TARGET_NAME;
-        // create a source node
-        sourcePath = testRootNode.addNode("src", "nt:folder").getPath();
-
-        testRootNode.getSession().save();
-    }
-
-    public void testConcurrentCopy() throws Exception {
-        for (int n = 0; n < NUM_ITERATIONS; n++) {
-            // cleanup
-            while (superuser.nodeExists(destPath)) {
-                superuser.getNode(destPath).remove();
-                superuser.save();
-            }
-
-            Thread[] threads = new Thread[NUM_SESSIONS];
-            for (int i = 0; i < threads.length; i++) {
-                // create new session
-                Session session = getHelper().getSuperuserSession();
-                String id = "session#" + i;
-                TestSession ts = new TestSession(id, session);
-                Thread t = new Thread(ts);
-                t.setName(id);
-                t.start();
-                threads[i] = t;
-            }
-            for (int i = 0; i < threads.length; i++) {
-                threads[i].join();
-            }
-
-            NodeIterator results = superuser.getNode(destParentPath).getNodes(TARGET_NAME);
-
-            assertEquals(1, results.getSize());
-        }
-    }
-
-
-    // -------------------------------------------------------< inner classes >
-    class TestSession implements Runnable {
-
-        Session session;
-        String identity;
-        Random r;
-
-        TestSession(String identity, Session s) {
-            session = s;
-            this.identity = identity;
-            r = new Random();
-        }
-
-        private void randomSleep() {
-            long l = r.nextInt(90) + 20;
-            try {
-                Thread.sleep(l);
-            } catch (InterruptedException ie) {
-            }
-        }
-
-        public void run() {
-
-            try {
-                session.getWorkspace().copy(sourcePath, destPath);
-                session.save();
-
-                randomSleep();
-            } catch (RepositoryException e) {
-                // expected
-            } finally {
-                session.logout();
-            }
-
-        }
-    }
-
+/*
+ * 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.core;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import javax.jcr.NodeIterator;
+import javax.jcr.Session;
+import javax.jcr.RepositoryException;
+import java.util.Random;
+
+
+public class ConcurrentWorkspaceCopyTest extends AbstractJCRTest {
+
+    private static final int NUM_ITERATIONS = 40;
+    private static final int NUM_SESSIONS = 2;
+
+    static final String TARGET_NAME = "copy of src";
+    String sourcePath;
+    String destParentPath;
+    String destPath;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // create a parent node where allowSameNameSiblings is set to false
+        destParentPath =
+                testRootNode.addNode("destParent",
+                        "nt:folder").getPath();
+        destPath = destParentPath + "/" + TARGET_NAME;
+        // create a source node
+        sourcePath = testRootNode.addNode("src", "nt:folder").getPath();
+
+        testRootNode.getSession().save();
+    }
+
+    public void testConcurrentCopy() throws Exception {
+        for (int n = 0; n < NUM_ITERATIONS; n++) {
+            // cleanup
+            while (superuser.nodeExists(destPath)) {
+                superuser.getNode(destPath).remove();
+                superuser.save();
+            }
+
+            Thread[] threads = new Thread[NUM_SESSIONS];
+            for (int i = 0; i < threads.length; i++) {
+                // create new session
+                Session session = getHelper().getSuperuserSession();
+                String id = "session#" + i;
+                TestSession ts = new TestSession(id, session);
+                Thread t = new Thread(ts);
+                t.setName(id);
+                t.start();
+                threads[i] = t;
+            }
+            for (int i = 0; i < threads.length; i++) {
+                threads[i].join();
+            }
+
+            NodeIterator results = superuser.getNode(destParentPath).getNodes(TARGET_NAME);
+
+            assertEquals(1, results.getSize());
+        }
+    }
+
+
+    // -------------------------------------------------------< inner classes >
+    class TestSession implements Runnable {
+
+        Session session;
+        String identity;
+        Random r;
+
+        TestSession(String identity, Session s) {
+            session = s;
+            this.identity = identity;
+            r = new Random();
+        }
+
+        private void randomSleep() {
+            long l = r.nextInt(90) + 20;
+            try {
+                Thread.sleep(l);
+            } catch (InterruptedException ie) {
+            }
+        }
+
+        public void run() {
+
+            try {
+                session.getWorkspace().copy(sourcePath, destPath);
+                session.save();
+
+                randomSleep();
+            } catch (RepositoryException e) {
+                // expected
+            } finally {
+                session.logout();
+            }
+
+        }
+    }
+
 }
\ No newline at end of file

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentWorkspaceCopyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveAtRootTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NPEandCMETest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/OverlappingNodeAddTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/OverlappingNodeAddTest.java?rev=1404144&r1=1404143&r2=1404144&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/OverlappingNodeAddTest.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/OverlappingNodeAddTest.java Wed Oct 31 14:06:06 2012
@@ -1,132 +1,132 @@
-/*
- * 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.core;
-
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.Node;
-import javax.jcr.Session;
-
-import org.apache.jackrabbit.test.AbstractJCRTest;
-
-public class OverlappingNodeAddTest extends AbstractJCRTest {
-
-    private Node testfolder;
-    private Session s1;
-    private Session s2;
-
-    public void setUp() throws Exception {
-        super.setUp();
-        testfolder = testRootNode.addNode("container", "nt:folder");
-        s1 = testfolder.getSession();
-        s2 = getHelper().getReadWriteSession();
-        s1.save();
-    }
-
-    /**
-     * Performs add operations on a single node (no SNS) through 2 sessions
-     */
-    public void testWith2Folders() throws Exception {
-
-        boolean bWasSaved = false;
-
-        String testpath = testfolder.getPath();
-
-        Node f1 = s1.getNode(testpath).addNode("folder", "nt:folder");
-        Node c1 = f1.addNode("a", "nt:file");
-        Node r1 = c1.addNode("jcr:content", "nt:resource");
-        r1.setProperty("jcr:data", "foo");
-
-        Node f2 = s2.getNode(testpath).addNode("folder", "nt:folder");
-        Node c2 = f2.addNode("b", "nt:file");
-        Node r2 = c2.addNode("jcr:content", "nt:resource");
-        r2.setProperty("jcr:data", "bar");
-
-        s1.save();
-
-        String s1FolderId = f1.getIdentifier();
-
-        try {
-            s2.save();
-            bWasSaved = true;
-        } catch (InvalidItemStateException ex) {
-            // expected
-
-            // retry; adding refresh doesn't change anything here
-            try {
-                s2.save();
-
-                bWasSaved = true;
-
-            } catch (InvalidItemStateException ex2) {
-                // we would be cool with this
-            }
-        }
-
-        // we don't have changes in s1, so the keepChanges flag should be
-        // irrelevant
-        s1.refresh(false);
-
-        // be nice and get a new Node instance
-        Node newf1 = s1.getNode(testpath + "/folder");
-
-        // if bWasSaved it should now be visible to Session 1
-        assertEquals("'b' was saved, so session 1 should see it", bWasSaved,
-                newf1.hasNode("b"));
-
-        // 'a' was saved by Session 1 earlier on
-        if (!newf1.hasNode("a")) {
-            String message = "child node 'a' not present";
-
-            if (bWasSaved && !s1FolderId.equals(newf1.getIdentifier())) {
-                message += ", and also the folder's identifier changed from "
-                        + s1FolderId + " to " + newf1.getIdentifier();
-            }
-
-            Node oldf1 = null;
-
-            try {
-                oldf1 = s1.getNodeByIdentifier(s1FolderId);
-            } catch (ItemNotFoundException ex) {
-                message += "; node with id "
-                        + s1FolderId
-                        + " can't be retrieved using getNodeByIdentifier either";
-            }
-
-            if (oldf1 != null) {
-                try {
-                    oldf1.getPath();
-                } catch (Exception ex) {
-                    message += "; node with id "
-                            + s1FolderId
-                            + " can be retrieved using getNodeByIdentifier, but getPath() fails with: "
-                            + ex.getMessage();
-                }
-            }
-
-            fail(message);
-        }
-    }
-
-    protected void tearDown() throws Exception {
-        if (s2 != null) {
-            s2.logout();
-            s2 = null;
-        }
-        super.tearDown();
-    }
-}
+/*
+ * 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.core;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+public class OverlappingNodeAddTest extends AbstractJCRTest {
+
+    private Node testfolder;
+    private Session s1;
+    private Session s2;
+
+    public void setUp() throws Exception {
+        super.setUp();
+        testfolder = testRootNode.addNode("container", "nt:folder");
+        s1 = testfolder.getSession();
+        s2 = getHelper().getReadWriteSession();
+        s1.save();
+    }
+
+    /**
+     * Performs add operations on a single node (no SNS) through 2 sessions
+     */
+    public void testWith2Folders() throws Exception {
+
+        boolean bWasSaved = false;
+
+        String testpath = testfolder.getPath();
+
+        Node f1 = s1.getNode(testpath).addNode("folder", "nt:folder");
+        Node c1 = f1.addNode("a", "nt:file");
+        Node r1 = c1.addNode("jcr:content", "nt:resource");
+        r1.setProperty("jcr:data", "foo");
+
+        Node f2 = s2.getNode(testpath).addNode("folder", "nt:folder");
+        Node c2 = f2.addNode("b", "nt:file");
+        Node r2 = c2.addNode("jcr:content", "nt:resource");
+        r2.setProperty("jcr:data", "bar");
+
+        s1.save();
+
+        String s1FolderId = f1.getIdentifier();
+
+        try {
+            s2.save();
+            bWasSaved = true;
+        } catch (InvalidItemStateException ex) {
+            // expected
+
+            // retry; adding refresh doesn't change anything here
+            try {
+                s2.save();
+
+                bWasSaved = true;
+
+            } catch (InvalidItemStateException ex2) {
+                // we would be cool with this
+            }
+        }
+
+        // we don't have changes in s1, so the keepChanges flag should be
+        // irrelevant
+        s1.refresh(false);
+
+        // be nice and get a new Node instance
+        Node newf1 = s1.getNode(testpath + "/folder");
+
+        // if bWasSaved it should now be visible to Session 1
+        assertEquals("'b' was saved, so session 1 should see it", bWasSaved,
+                newf1.hasNode("b"));
+
+        // 'a' was saved by Session 1 earlier on
+        if (!newf1.hasNode("a")) {
+            String message = "child node 'a' not present";
+
+            if (bWasSaved && !s1FolderId.equals(newf1.getIdentifier())) {
+                message += ", and also the folder's identifier changed from "
+                        + s1FolderId + " to " + newf1.getIdentifier();
+            }
+
+            Node oldf1 = null;
+
+            try {
+                oldf1 = s1.getNodeByIdentifier(s1FolderId);
+            } catch (ItemNotFoundException ex) {
+                message += "; node with id "
+                        + s1FolderId
+                        + " can't be retrieved using getNodeByIdentifier either";
+            }
+
+            if (oldf1 != null) {
+                try {
+                    oldf1.getPath();
+                } catch (Exception ex) {
+                    message += "; node with id "
+                            + s1FolderId
+                            + " can be retrieved using getNodeByIdentifier, but getPath() fails with: "
+                            + ex.getMessage();
+                }
+            }
+
+            fail(message);
+        }
+    }
+
+    protected void tearDown() throws Exception {
+        if (s2 != null) {
+            s2.logout();
+            s2 = null;
+        }
+        super.tearDown();
+    }
+}

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/OverlappingNodeAddTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/SessionGarbageCollectedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ShareableNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/UserPerWorkspaceSecurityManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/DbClusterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/ConcurrentGcTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreAPITest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/LazyFileInputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/OpenFilesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/WriteWhileReadingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/TestAll.java?rev=1404144&r1=1404143&r2=1404144&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/TestAll.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/TestAll.java Wed Oct 31 14:06:06 2012
@@ -1,44 +1,44 @@
-/*
- * 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.core.fs;
-
-import org.apache.jackrabbit.core.fs.db.DerbyFileSystemTest;
-import org.apache.jackrabbit.core.fs.local.LocalFileSystemTest;
-import org.apache.jackrabbit.core.fs.mem.MemoryFileSystemTest;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test suite that includes all test cases for this module.
- */
-public class TestAll extends TestCase {
-
-    /**
-     * Returns a test suite that executes all tests inside this package.
-     *
-     * @return a test suite that executes all tests inside this package
-     */
-    public static Test suite() {
-        TestSuite suite = new TestSuite("FileSystem tests");
-        suite.addTestSuite(DerbyFileSystemTest.class);
-        suite.addTestSuite(LocalFileSystemTest.class);
-        suite.addTestSuite(MemoryFileSystemTest.class);
-        return suite;
-    }
-}
+/*
+ * 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.core.fs;
+
+import org.apache.jackrabbit.core.fs.db.DerbyFileSystemTest;
+import org.apache.jackrabbit.core.fs.local.LocalFileSystemTest;
+import org.apache.jackrabbit.core.fs.mem.MemoryFileSystemTest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all test cases for this module.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a test suite that executes all tests inside this package.
+     *
+     * @return a test suite that executes all tests inside this package
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("FileSystem tests");
+        suite.addTestSuite(DerbyFileSystemTest.class);
+        suite.addTestSuite(LocalFileSystemTest.class);
+        suite.addTestSuite(MemoryFileSystemTest.class);
+        return suite;
+    }
+}

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/NodeIdTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/NodeIdTest.java?rev=1404144&r1=1404143&r2=1404144&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/NodeIdTest.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/NodeIdTest.java Wed Oct 31 14:06:06 2012
@@ -1,106 +1,106 @@
-/*
- * 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.core.id;
-
-import junit.framework.TestCase;
-
-public class NodeIdTest extends TestCase {
-
-    private static final NodeId[] ids = {
-        new NodeId(), // random id
-        new NodeId(0, 0),
-        new NodeId(-1, -1),
-        new NodeId("cafebabe-cafe-babe-cafe-babecafebabe")
-    };
-
-    public void testDenotesNode() {
-        for (NodeId id : ids) {
-            assertTrue(id.denotesNode());
-        }
-    }
-
-    public void testGetMostAndLeastSignificantBits() {
-        for (NodeId id : ids) {
-            long msb = id.getMostSignificantBits();
-            long lsb = id.getLeastSignificantBits();
-            assertEquals(id, new NodeId(msb, lsb));
-        }
-    }
-
-    public void testGetRawBytes() {
-        for (NodeId id : ids) {
-            assertEquals(id, new NodeId(id.getRawBytes()));
-        }
-    }
-
-    public void testToString() {
-        for (NodeId id : ids) {
-            assertEquals(id, new NodeId(id.toString()));
-        }
-    }
-
-    public void testCompareTo() {
-        for (NodeId id : ids) {
-            assertEquals(0, id.compareTo(id));
-        }
-
-        NodeId[] ordered = {
-                new NodeId(-1, -1),
-                new NodeId(-1, 0),
-                new NodeId(0, -1),
-                new NodeId(0, 0),
-                new NodeId(0, 1),
-                new NodeId(1, 0),
-                new NodeId(1, 1)
-        };
-        for (int i = 0; i < ordered.length; i++) {
-            for (int j = 0; j < i; j++) {
-                assertEquals(1, ordered[i].compareTo(ordered[j]));
-            }
-            assertEquals(0, ordered[i].compareTo(ordered[i]));
-            for (int j = i + 1; j < ordered.length; j++) {
-                assertEquals(-1, ordered[i].compareTo(ordered[j]));
-            }
-        }
-    }
-
-    public void testUuidFormat() {
-        long maxHigh = 0, maxLow = 0, minHigh = -1L, minLow = -1L;
-        for (int i = 0; i < 100; i++) {
-            NodeId id = new NodeId();
-            assertUuidFormat(id);
-            maxHigh |= id.getMostSignificantBits();
-            maxLow |= id.getLeastSignificantBits();
-            minHigh &= id.getMostSignificantBits();
-            minLow &= id.getLeastSignificantBits();
-        }
-        NodeId max = new NodeId(maxHigh, maxLow);
-        assertEquals("ffffffff-ffff-4fff-bfff-ffffffffffff", max.toString());
-        NodeId min = new NodeId(minHigh, minLow);
-        assertEquals("00000000-0000-4000-8000-000000000000", min.toString());
-    }
-
-    private void assertUuidFormat(NodeId id) {
-        long high = id.getMostSignificantBits();
-        long low = id.getLeastSignificantBits();
-        long high2 = (high & (~0xf000L)) | 0x4000L; // version 4 (random)
-        assertEquals(high, high2);
-        long low2 = (low & 0x3fffffffffffffffL) | 0x8000000000000000L; // variant (Leach-Salz)
-        assertEquals(low, low2);
-    }
-
-}
+/*
+ * 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.core.id;
+
+import junit.framework.TestCase;
+
+public class NodeIdTest extends TestCase {
+
+    private static final NodeId[] ids = {
+        new NodeId(), // random id
+        new NodeId(0, 0),
+        new NodeId(-1, -1),
+        new NodeId("cafebabe-cafe-babe-cafe-babecafebabe")
+    };
+
+    public void testDenotesNode() {
+        for (NodeId id : ids) {
+            assertTrue(id.denotesNode());
+        }
+    }
+
+    public void testGetMostAndLeastSignificantBits() {
+        for (NodeId id : ids) {
+            long msb = id.getMostSignificantBits();
+            long lsb = id.getLeastSignificantBits();
+            assertEquals(id, new NodeId(msb, lsb));
+        }
+    }
+
+    public void testGetRawBytes() {
+        for (NodeId id : ids) {
+            assertEquals(id, new NodeId(id.getRawBytes()));
+        }
+    }
+
+    public void testToString() {
+        for (NodeId id : ids) {
+            assertEquals(id, new NodeId(id.toString()));
+        }
+    }
+
+    public void testCompareTo() {
+        for (NodeId id : ids) {
+            assertEquals(0, id.compareTo(id));
+        }
+
+        NodeId[] ordered = {
+                new NodeId(-1, -1),
+                new NodeId(-1, 0),
+                new NodeId(0, -1),
+                new NodeId(0, 0),
+                new NodeId(0, 1),
+                new NodeId(1, 0),
+                new NodeId(1, 1)
+        };
+        for (int i = 0; i < ordered.length; i++) {
+            for (int j = 0; j < i; j++) {
+                assertEquals(1, ordered[i].compareTo(ordered[j]));
+            }
+            assertEquals(0, ordered[i].compareTo(ordered[i]));
+            for (int j = i + 1; j < ordered.length; j++) {
+                assertEquals(-1, ordered[i].compareTo(ordered[j]));
+            }
+        }
+    }
+
+    public void testUuidFormat() {
+        long maxHigh = 0, maxLow = 0, minHigh = -1L, minLow = -1L;
+        for (int i = 0; i < 100; i++) {
+            NodeId id = new NodeId();
+            assertUuidFormat(id);
+            maxHigh |= id.getMostSignificantBits();
+            maxLow |= id.getLeastSignificantBits();
+            minHigh &= id.getMostSignificantBits();
+            minLow &= id.getLeastSignificantBits();
+        }
+        NodeId max = new NodeId(maxHigh, maxLow);
+        assertEquals("ffffffff-ffff-4fff-bfff-ffffffffffff", max.toString());
+        NodeId min = new NodeId(minHigh, minLow);
+        assertEquals("00000000-0000-4000-8000-000000000000", min.toString());
+    }
+
+    private void assertUuidFormat(NodeId id) {
+        long high = id.getMostSignificantBits();
+        long low = id.getLeastSignificantBits();
+        long high2 = (high & (~0xf000L)) | 0x4000L; // version 4 (random)
+        assertEquals(high, high2);
+        long low2 = (low & 0x3fffffffffffffffL) | 0x8000000000000000L; // variant (Leach-Salz)
+        assertEquals(low, low2);
+    }
+
+}

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/NodeIdTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/TestAll.java?rev=1404144&r1=1404143&r2=1404144&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/TestAll.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/TestAll.java Wed Oct 31 14:06:06 2012
@@ -1,38 +1,38 @@
-/*
- * 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.core.id;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test suite that includes all test cases for the id module.
- */
-public class TestAll extends TestCase {
-
-    /**
-     * Returns a test suite that executes all tests inside this package.
-     *
-     * @return a test suite that executes all tests inside this package
-     */
-    public static Test suite() {
-        TestSuite suite = new TestSuite("Identifier tests");
-        suite.addTestSuite(NodeIdTest.class);
-        return suite;
-    }
-}
+/*
+ * 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.core.id;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all test cases for the id module.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a test suite that executes all tests inside this package.
+     *
+     * @return a test suite that executes all tests inside this package
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Identifier tests");
+        suite.addTestSuite(NodeIdTest.class);
+        return suite;
+    }
+}

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/ItemSequenceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/NodeImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/NodeImplTest.java?rev=1404144&r1=1404143&r2=1404144&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/NodeImplTest.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/NodeImplTest.java Wed Oct 31 14:06:06 2012
@@ -1,93 +1,93 @@
-/*
- * 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.core.integration;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.version.Version;
-
-import org.apache.jackrabbit.test.AbstractJCRTest;
-
-/**
- * Integration tests for the Node implementation in Jackrabbit core.
- */
-public class NodeImplTest extends AbstractJCRTest {
-
-    private Node node;
-
-    protected void setUp() throws Exception {
-        super.setUp();
-        node = testRootNode.addNode("testNodeImpl", "nt:unstructured");
-        testRootNode.save();
-    }
-
-    protected void tearDown() throws Exception {
-        node.remove();
-        testRootNode.save();
-        super.tearDown();
-    }
-
-    /**
-     * Test case for JCR-1389.
-     * 
-     * @see <a href="https://issues.apache.org/jira/browse/JCR-1389">JCR-1389</a>
-     */
-    public void testSetEmptyMultiValueProperty() throws RepositoryException {
-        Property property =
-            node.setProperty("test", new Value[0], PropertyType.LONG);
-        assertEquals(
-                "JCR-1389: setProperty(name, new Value[0], PropertyType.LONG)"
-                + " loses property type",
-                PropertyType.LONG, property.getType());
-    }
-
-    /**
-     * Test case for JCR-1227.
-     * 
-     * @see <a href="https://issues.apache.org/jira/browse/JCR-1227">JCR-1227</a>
-     */
-    public void testRestoreEmptyMultiValueProperty() throws Exception {
-        node.addMixin("mix:versionable");
-        node.setProperty("test", new Value[0], PropertyType.LONG);
-        node.save();
-        assertEquals(PropertyType.LONG, node.getProperty("test").getType());
-
-        Version version = node.checkin();
-        assertEquals(PropertyType.LONG, node.getProperty("test").getType());
-
-        node.restore(version, false);
-        assertEquals(
-                "JCR-1227: Restore of empty multivalue property always"
-                + " changes property type to String",
-                PropertyType.LONG, node.getProperty("test").getType());
-
-        node.checkout();
-        node.setProperty("test", new Value[0], PropertyType.BOOLEAN);
-        node.save();
-        assertEquals(PropertyType.BOOLEAN, node.getProperty("test").getType());
-
-        node.restore(version, false);
-        assertEquals(
-                "JCR-1227: Restore of empty multivalue property always"
-                + " changes property type to String",
-                PropertyType.LONG, node.getProperty("test").getType());
-    }
-
-}
+/*
+ * 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.core.integration;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.version.Version;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * Integration tests for the Node implementation in Jackrabbit core.
+ */
+public class NodeImplTest extends AbstractJCRTest {
+
+    private Node node;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        node = testRootNode.addNode("testNodeImpl", "nt:unstructured");
+        testRootNode.save();
+    }
+
+    protected void tearDown() throws Exception {
+        node.remove();
+        testRootNode.save();
+        super.tearDown();
+    }
+
+    /**
+     * Test case for JCR-1389.
+     * 
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-1389">JCR-1389</a>
+     */
+    public void testSetEmptyMultiValueProperty() throws RepositoryException {
+        Property property =
+            node.setProperty("test", new Value[0], PropertyType.LONG);
+        assertEquals(
+                "JCR-1389: setProperty(name, new Value[0], PropertyType.LONG)"
+                + " loses property type",
+                PropertyType.LONG, property.getType());
+    }
+
+    /**
+     * Test case for JCR-1227.
+     * 
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-1227">JCR-1227</a>
+     */
+    public void testRestoreEmptyMultiValueProperty() throws Exception {
+        node.addMixin("mix:versionable");
+        node.setProperty("test", new Value[0], PropertyType.LONG);
+        node.save();
+        assertEquals(PropertyType.LONG, node.getProperty("test").getType());
+
+        Version version = node.checkin();
+        assertEquals(PropertyType.LONG, node.getProperty("test").getType());
+
+        node.restore(version, false);
+        assertEquals(
+                "JCR-1227: Restore of empty multivalue property always"
+                + " changes property type to String",
+                PropertyType.LONG, node.getProperty("test").getType());
+
+        node.checkout();
+        node.setProperty("test", new Value[0], PropertyType.BOOLEAN);
+        node.save();
+        assertEquals(PropertyType.BOOLEAN, node.getProperty("test").getType());
+
+        node.restore(version, false);
+        assertEquals(
+                "JCR-1227: Restore of empty multivalue property always"
+                + " changes property type to String",
+                PropertyType.LONG, node.getProperty("test").getType());
+    }
+
+}

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/NodeImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/TreeTraverserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/VersioningTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/VersioningTest.java?rev=1404144&r1=1404143&r2=1404144&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/VersioningTest.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/VersioningTest.java Wed Oct 31 14:06:06 2012
@@ -1,215 +1,215 @@
-/*
- * 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.core.integration;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.jcr.Node;
-import javax.jcr.Session;
-import javax.jcr.version.Version;
-
-import org.apache.jackrabbit.test.AbstractJCRTest;
-
-/**
- * Versioning tests.
- */
-public class VersioningTest extends AbstractJCRTest {
-
-    private Node n1;
-    private Node n2;
-
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        Session s1 = getHelper().getSuperuserSession();
-        n1 = s1.getRootNode().addNode("VersioningTest");
-        n1.addMixin(mixVersionable);
-        n1.getSession().save();
-
-        Session s2 = getHelper().getSuperuserSession(workspaceName);
-        s2.getWorkspace().clone(
-                s1.getWorkspace().getName(), n1.getPath(),
-                "/VersioningTest", true);
-        n2 = s2.getRootNode().getNode("VersioningTest");
-    }
-
-    protected void tearDown() throws Exception {
-        super.tearDown();
-
-        Session s1 = n1.getSession();
-        n1.remove();
-        s1.save();
-        s1.logout();
-
-        Session s2 = n2.getSession();
-        n2.remove();
-        s2.save();
-        s2.logout();
-    }
-
-    /**
-     * Tests that the version tree documented in
-     * AbstractVersionManager.calculateCheckinVersionName() can be
-     * constructed and has the expected version names.
-     * <p>
-     * Note that this test case needs to be modified if the version naming
-     * algorithm ever gets changed.
-     */
-    public void testVersionGraph() throws Exception {
-        Version vR = n1.getBaseVersion();
-
-        Version v10 = n1.checkin();
-        n1.checkout();
-        Version v11 = n1.checkin();
-        n1.checkout();
-        Version v12 = n1.checkin();
-        n1.checkout();
-        Version v13 = n1.checkin();
-        n1.checkout();
-        Version v14 = n1.checkin();
-        n1.checkout();
-        Version v15 = n1.checkin();
-        n1.checkout();
-        Version v16 = n1.checkin();
-
-        n1.restore(v12, true);
-        n1.checkout();
-        Version v120 = n1.checkin();
-        n1.checkout();
-        Version v121 = n1.checkin();
-        n1.checkout();
-        Version v122 = n1.checkin();
-
-        n1.restore(v12, true);
-        n1.checkout();
-        Version v1200 = n1.checkin();
-
-        n1.restore(v121, true);
-        n1.checkout();
-        Version v1210 = n1.checkin();
-        n1.checkout();
-        Version v1211 = n1.checkin();
-
-        // x.0 versions can be created if the newly created versionable
-        // node is cloned to another workspace before the first checkin
-        Version v20 = n2.checkin();
-
-        // Multiple branches can be merged using multiple workspaces
-        n2.restore(v122, true);
-        n1.restore(v16, true);
-        n1.checkout();
-        n1.merge(n2.getSession().getWorkspace().getName(), true);
-        n1.doneMerge(v122);
-        Version v17 = n1.checkin();
-
-        assertEquals("jcr:rootVersion", vR.getName());
-        assertPredecessors("", vR);
-        assertSuccessors("1.0 2.0", vR);
-        assertEquals("1.0", v10.getName());
-        assertPredecessors("jcr:rootVersion", v10);
-        assertSuccessors("1.1", v10);
-        assertEquals("1.1", v11.getName());
-        assertPredecessors("1.0", v11);
-        assertSuccessors("1.2", v11);
-        assertEquals("1.2", v12.getName());
-        assertPredecessors("1.1", v12);
-        assertSuccessors("1.3 1.2.0 1.2.0.0", v12);
-        assertEquals("1.3", v13.getName());
-        assertPredecessors("1.2", v13);
-        assertSuccessors("1.4", v13);
-        assertEquals("1.4", v14.getName());
-        assertPredecessors("1.3", v14);
-        assertSuccessors("1.5", v14);
-        assertEquals("1.5", v15.getName());
-        assertPredecessors("1.4", v15);
-        assertSuccessors("1.6", v15);
-        assertEquals("1.6", v16.getName());
-        assertPredecessors("1.5", v16);
-        assertSuccessors("1.7", v16);
-        assertEquals("1.7", v17.getName());
-        assertPredecessors("1.6 1.2.2", v17);
-        assertSuccessors("", v17);
-
-        assertEquals("1.2.0", v120.getName());
-        assertPredecessors("1.2", v120);
-        assertSuccessors("1.2.1", v120);
-        assertEquals("1.2.1", v121.getName());
-        assertPredecessors("1.2.0", v121);
-        assertSuccessors("1.2.2 1.2.1.0", v121);
-        assertEquals("1.2.2", v122.getName());
-        assertPredecessors("1.2.1", v122);
-        assertSuccessors("1.7", v122);
-
-        assertEquals("1.2.0.0", v1200.getName());
-        assertPredecessors("1.2", v1200);
-        assertSuccessors("", v1200);
-
-        assertEquals("1.2.1.0", v1210.getName());
-        assertPredecessors("1.2.1", v1210);
-        assertSuccessors("1.2.1.1", v1210);
-        assertEquals("1.2.1.1", v1211.getName());
-        assertPredecessors("1.2.1.0", v1211);
-        assertSuccessors("", v1211);
-
-        assertEquals("2.0", v20.getName());
-        assertPredecessors("jcr:rootVersion", v20);
-        assertSuccessors("", v20);
-    }
-
-    private void assertPredecessors(String expected, Version version)
-            throws Exception {
-        Set predecessors = new HashSet();
-        if (expected.length() > 0) {
-            predecessors.addAll(Arrays.asList(expected.split(" ")));
-        }
-        Version[] versions = version.getPredecessors();
-        for (int i = 0; i < versions.length; i++) {
-            if (!predecessors.remove(versions[i].getName())) {
-                fail("Version " + version.getName()
-                        + " has an unexpected predessor "
-                        + versions[i].getName());
-            }
-        }
-        if (!predecessors.isEmpty()) {
-            fail("Version " + version.getName()
-                    + " does not have all expected predecessors");
-        }
-    }
-
-    private void assertSuccessors(String expected, Version version)
-            throws Exception {
-        Set successors = new HashSet();
-        if (expected.length() > 0) {
-            successors.addAll(Arrays.asList(expected.split(" ")));
-        }
-        Version[] versions = version.getSuccessors();
-        for (int i = 0; i < versions.length; i++) {
-            if (!successors.remove(versions[i].getName())) {
-                fail("Version " + version.getName()
-                        + " has an unexpected successor "
-                        + versions[i].getName());
-            }
-        }
-        if (!successors.isEmpty()) {
-            fail("Version " + version.getName()
-                    + " does not have all expected successors");
-        }
-    }
-
-}
+/*
+ * 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.core.integration;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+import javax.jcr.version.Version;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * Versioning tests.
+ */
+public class VersioningTest extends AbstractJCRTest {
+
+    private Node n1;
+    private Node n2;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        Session s1 = getHelper().getSuperuserSession();
+        n1 = s1.getRootNode().addNode("VersioningTest");
+        n1.addMixin(mixVersionable);
+        n1.getSession().save();
+
+        Session s2 = getHelper().getSuperuserSession(workspaceName);
+        s2.getWorkspace().clone(
+                s1.getWorkspace().getName(), n1.getPath(),
+                "/VersioningTest", true);
+        n2 = s2.getRootNode().getNode("VersioningTest");
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+
+        Session s1 = n1.getSession();
+        n1.remove();
+        s1.save();
+        s1.logout();
+
+        Session s2 = n2.getSession();
+        n2.remove();
+        s2.save();
+        s2.logout();
+    }
+
+    /**
+     * Tests that the version tree documented in
+     * AbstractVersionManager.calculateCheckinVersionName() can be
+     * constructed and has the expected version names.
+     * <p>
+     * Note that this test case needs to be modified if the version naming
+     * algorithm ever gets changed.
+     */
+    public void testVersionGraph() throws Exception {
+        Version vR = n1.getBaseVersion();
+
+        Version v10 = n1.checkin();
+        n1.checkout();
+        Version v11 = n1.checkin();
+        n1.checkout();
+        Version v12 = n1.checkin();
+        n1.checkout();
+        Version v13 = n1.checkin();
+        n1.checkout();
+        Version v14 = n1.checkin();
+        n1.checkout();
+        Version v15 = n1.checkin();
+        n1.checkout();
+        Version v16 = n1.checkin();
+
+        n1.restore(v12, true);
+        n1.checkout();
+        Version v120 = n1.checkin();
+        n1.checkout();
+        Version v121 = n1.checkin();
+        n1.checkout();
+        Version v122 = n1.checkin();
+
+        n1.restore(v12, true);
+        n1.checkout();
+        Version v1200 = n1.checkin();
+
+        n1.restore(v121, true);
+        n1.checkout();
+        Version v1210 = n1.checkin();
+        n1.checkout();
+        Version v1211 = n1.checkin();
+
+        // x.0 versions can be created if the newly created versionable
+        // node is cloned to another workspace before the first checkin
+        Version v20 = n2.checkin();
+
+        // Multiple branches can be merged using multiple workspaces
+        n2.restore(v122, true);
+        n1.restore(v16, true);
+        n1.checkout();
+        n1.merge(n2.getSession().getWorkspace().getName(), true);
+        n1.doneMerge(v122);
+        Version v17 = n1.checkin();
+
+        assertEquals("jcr:rootVersion", vR.getName());
+        assertPredecessors("", vR);
+        assertSuccessors("1.0 2.0", vR);
+        assertEquals("1.0", v10.getName());
+        assertPredecessors("jcr:rootVersion", v10);
+        assertSuccessors("1.1", v10);
+        assertEquals("1.1", v11.getName());
+        assertPredecessors("1.0", v11);
+        assertSuccessors("1.2", v11);
+        assertEquals("1.2", v12.getName());
+        assertPredecessors("1.1", v12);
+        assertSuccessors("1.3 1.2.0 1.2.0.0", v12);
+        assertEquals("1.3", v13.getName());
+        assertPredecessors("1.2", v13);
+        assertSuccessors("1.4", v13);
+        assertEquals("1.4", v14.getName());
+        assertPredecessors("1.3", v14);
+        assertSuccessors("1.5", v14);
+        assertEquals("1.5", v15.getName());
+        assertPredecessors("1.4", v15);
+        assertSuccessors("1.6", v15);
+        assertEquals("1.6", v16.getName());
+        assertPredecessors("1.5", v16);
+        assertSuccessors("1.7", v16);
+        assertEquals("1.7", v17.getName());
+        assertPredecessors("1.6 1.2.2", v17);
+        assertSuccessors("", v17);
+
+        assertEquals("1.2.0", v120.getName());
+        assertPredecessors("1.2", v120);
+        assertSuccessors("1.2.1", v120);
+        assertEquals("1.2.1", v121.getName());
+        assertPredecessors("1.2.0", v121);
+        assertSuccessors("1.2.2 1.2.1.0", v121);
+        assertEquals("1.2.2", v122.getName());
+        assertPredecessors("1.2.1", v122);
+        assertSuccessors("1.7", v122);
+
+        assertEquals("1.2.0.0", v1200.getName());
+        assertPredecessors("1.2", v1200);
+        assertSuccessors("", v1200);
+
+        assertEquals("1.2.1.0", v1210.getName());
+        assertPredecessors("1.2.1", v1210);
+        assertSuccessors("1.2.1.1", v1210);
+        assertEquals("1.2.1.1", v1211.getName());
+        assertPredecessors("1.2.1.0", v1211);
+        assertSuccessors("", v1211);
+
+        assertEquals("2.0", v20.getName());
+        assertPredecessors("jcr:rootVersion", v20);
+        assertSuccessors("", v20);
+    }
+
+    private void assertPredecessors(String expected, Version version)
+            throws Exception {
+        Set predecessors = new HashSet();
+        if (expected.length() > 0) {
+            predecessors.addAll(Arrays.asList(expected.split(" ")));
+        }
+        Version[] versions = version.getPredecessors();
+        for (int i = 0; i < versions.length; i++) {
+            if (!predecessors.remove(versions[i].getName())) {
+                fail("Version " + version.getName()
+                        + " has an unexpected predessor "
+                        + versions[i].getName());
+            }
+        }
+        if (!predecessors.isEmpty()) {
+            fail("Version " + version.getName()
+                    + " does not have all expected predecessors");
+        }
+    }
+
+    private void assertSuccessors(String expected, Version version)
+            throws Exception {
+        Set successors = new HashSet();
+        if (expected.length() > 0) {
+            successors.addAll(Arrays.asList(expected.split(" ")));
+        }
+        Version[] versions = version.getSuccessors();
+        for (int i = 0; i < versions.length; i++) {
+            if (!successors.remove(versions[i].getName())) {
+                fail("Version " + version.getName()
+                        + " has an unexpected successor "
+                        + versions[i].getName());
+            }
+        }
+        if (!successors.isEmpty()) {
+            fail("Version " + version.getName()
+                    + " does not have all expected successors");
+        }
+    }
+
+}

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/VersioningTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/benchmark/SimpleBench.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/lock/LockTimeoutTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/AutoFixCorruptNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/JoinTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/LimitedAccessQueryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2OuterJoinTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2TooManyClausesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/DecimalConvertTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SQL2IndexingAggregateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/CryptedSimpleCredentialsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NodeCreationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImporterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/state/DefaultISMLockingDeadlockTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/CooperativeFileLockTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/value/InternalValueFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/value/InternalValueTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/value/PathTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/value/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/AnonymousConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-client/src/main/java/org/apache/jackrabbit/client/RepositoryFactoryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-client/src/test/java/org/apache/jackrabbit/client/RepositoryFactoryImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-client/src/test/java/org/apache/jackrabbit/client/RepositoryFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/NamespaceHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/NamespaceHelper.java?rev=1404144&r1=1404143&r2=1404144&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/NamespaceHelper.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/NamespaceHelper.java Wed Oct 31 14:06:06 2012
@@ -1,243 +1,243 @@
-/*
- * 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.commons;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.jcr.NamespaceException;
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.jackrabbit.util.XMLChar;
-
-/**
- * Helper class for working with JCR namespaces.
- *
- * @since Jackrabbit JCR Commons 1.5
- */
-public class NamespaceHelper {
-
-    /**
-     * The <code>jcr</code> namespace URI.
-     */
-    public static final String JCR = "http://www.jcp.org/jcr/1.0";
-
-    /**
-     * The <code>nt</code> namespace URI.
-     */
-    public static final String NT = "http://www.jcp.org/jcr/nt/1.0";
-
-    /**
-     * The <code>mix</code> namespace URI.
-     */
-    public static final String MIX = "http://www.jcp.org/jcr/mix/1.0";
-
-    /**
-     * Current session.
-     */
-    private final Session session;
-
-    /**
-     * Creates a namespace helper for the given session.
-     *
-     * @param session current session
-     */
-    public NamespaceHelper(Session session) {
-        this.session = session;
-    }
-
-    /**
-     * Returns a map containing all prefix to namespace URI mappings of
-     * the current session. The returned map is newly allocated and can
-     * can be freely modified by the caller.
-     *
-     * @see Session#getNamespacePrefixes()
-     * @return namespace mappings
-     * @throws RepositoryException if the namespaces could not be retrieved
-     */
-    public Map getNamespaces() throws RepositoryException {
-        Map namespaces = new HashMap();
-        String[] prefixes = session.getNamespacePrefixes();
-        for (int i = 0; i < prefixes.length; i++) {
-            namespaces.put(prefixes[i], session.getNamespaceURI(prefixes[i]));
-        }
-        return namespaces;
-    }
-
-    /**
-     * Returns the prefix mapped to the given namespace URI in the current
-     * session, or <code>null</code> if the namespace does not exist.
-     *
-     * @see Session#getNamespacePrefix(String)
-     * @param uri namespace URI
-     * @return namespace prefix, or <code>null</code>
-     * @throws RepositoryException if the namespace could not be retrieved
-     */
-    public String getPrefix(String uri) throws RepositoryException {
-        try {
-            return session.getNamespacePrefix(uri);
-        } catch (NamespaceException e) {
-            return null;
-        }
-    }
-
-    /**
-     * Returns the namespace URI mapped to the given prefix in the current
-     * session, or <code>null</code> if the namespace does not exist.
-     *
-     * @see Session#getNamespaceURI(String)
-     * @param uri namespace URI
-     * @return namespace prefix, or <code>null</code>
-     * @throws RepositoryException if the namespace could not be retrieved
-     */
-    public String getURI(String prefix) throws RepositoryException {
-        try {
-            return session.getNamespaceURI(prefix);
-        } catch (NamespaceException e) {
-            return null;
-        }
-    }
-
-    /**
-     * Returns the prefixed JCR name for the given namespace URI and local
-     * name in the current session.
-     *
-     * @param uri namespace URI
-     * @param name local name
-     * @return prefixed JCR name
-     * @throws NamespaceException if the namespace does not exist
-     * @throws RepositoryException if the namespace could not be retrieved
-     */
-    public String getJcrName(String uri, String name)
-            throws NamespaceException, RepositoryException {
-        if (uri != null && uri.length() > 0) {
-            return session.getNamespacePrefix(uri) + ":" + name;
-        } else {
-            return name;
-        }
-    }
-
-    /**
-     * Replaces the standard <code>jcr</code>, <code>nt</code>, or
-     * <code>mix</code> prefix in the given name with the prefix
-     * mapped to that namespace in the current session.
-     * <p>
-     * The purpose of this method is to make it easier to write
-     * namespace-aware code that uses names in the standard JCR namespaces.
-     * For example:
-     * <pre>
-     *     node.getProperty(helper.getName("jcr:data"));
-     * </pre>
-     *
-     * @param name prefixed name using the standard JCR prefixes
-     * @return prefixed name using the current session namespace mappings
-     * @throws IllegalArgumentException if the prefix is unknown
-     * @throws RepositoryException if the namespace could not be retrieved
-     */
-    public String getJcrName(String name)
-            throws IllegalArgumentException, RepositoryException {
-        String standardPrefix;
-        String currentPrefix;
-
-        if (name.startsWith("jcr:")) {
-            standardPrefix = "jcr";
-            currentPrefix = session.getNamespacePrefix(JCR);
-        } else if (name.startsWith("nt:")) {
-            standardPrefix = "nt";
-            currentPrefix = session.getNamespacePrefix(NT);
-        } else if (name.startsWith("mix:")) {
-            standardPrefix = "mix";
-            currentPrefix = session.getNamespacePrefix(MIX);
-        } else {
-            throw new IllegalArgumentException("Unknown prefix: " + name);
-        }
-
-        if (currentPrefix.equals(standardPrefix)) {
-            return name;
-        } else {
-            return currentPrefix + name.substring(standardPrefix.length());
-        }
-    }
-
-    /**
-     * Safely registers the given namespace. If the namespace already exists,
-     * then the prefix mapped to the namespace in the current session is
-     * returned. Otherwise the namespace is registered to the namespace
-     * registry. If the given prefix is already registered for some other
-     * namespace or otherwise invalid, then another prefix is automatically
-     * generated. After the namespace has been registered, the prefix mapped
-     * to it in the current session is returned.
-     *
-     * @see NamespaceRegistry#registerNamespace(String, String)
-     * @param prefix namespace prefix
-     * @param uri namespace URI
-     * @return namespace prefix in the current session
-     * @throws RepositoryException if the namespace could not be registered
-     */
-    public String registerNamespace(String prefix, String uri)
-            throws RepositoryException {
-        NamespaceRegistry registry =
-            session.getWorkspace().getNamespaceRegistry();
-        try {
-            // Check if the namespace is registered
-            registry.getPrefix(uri);
-        } catch (NamespaceException e1) {
-             // Replace troublesome prefix hints
-            if (prefix == null || prefix.length() == 0
-                    || prefix.toLowerCase().startsWith("xml")
-                    || !XMLChar.isValidNCName(prefix)) {
-                prefix = "ns"; // ns, ns2, ns3, ns4, ...
-            }
-
-            // Loop until an unused prefix is found
-            try {
-                String base = prefix;
-                for (int i = 2; true; i++) {
-                    registry.getURI(prefix);
-                    prefix = base + i;
-                }
-            } catch (NamespaceException e2) {
-                // Exit the loop
-            } 
-
-            // Register the namespace
-            registry.registerNamespace(prefix, uri);
-        }
-
-        return session.getNamespacePrefix(uri);
-    }
-
-    /**
-     * Safely registers all namespaces in the given map from
-     * prefixes to namespace URIs.
-     *
-     * @param namespaces namespace mappings
-     * @throws RepositoryException if the namespaces could not be registered
-     */
-    public void registerNamespaces(Map namespaces) throws RepositoryException {
-        Iterator iterator = namespaces.entrySet().iterator();
-        while (iterator.hasNext()) {
-            Map.Entry entry = (Map.Entry) iterator.next();
-            registerNamespace(
-                    (String) entry.getKey(), (String) entry.getValue());
-        }
-    }
-
-}
+/*
+ * 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.commons;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.util.XMLChar;
+
+/**
+ * Helper class for working with JCR namespaces.
+ *
+ * @since Jackrabbit JCR Commons 1.5
+ */
+public class NamespaceHelper {
+
+    /**
+     * The <code>jcr</code> namespace URI.
+     */
+    public static final String JCR = "http://www.jcp.org/jcr/1.0";
+
+    /**
+     * The <code>nt</code> namespace URI.
+     */
+    public static final String NT = "http://www.jcp.org/jcr/nt/1.0";
+
+    /**
+     * The <code>mix</code> namespace URI.
+     */
+    public static final String MIX = "http://www.jcp.org/jcr/mix/1.0";
+
+    /**
+     * Current session.
+     */
+    private final Session session;
+
+    /**
+     * Creates a namespace helper for the given session.
+     *
+     * @param session current session
+     */
+    public NamespaceHelper(Session session) {
+        this.session = session;
+    }
+
+    /**
+     * Returns a map containing all prefix to namespace URI mappings of
+     * the current session. The returned map is newly allocated and can
+     * can be freely modified by the caller.
+     *
+     * @see Session#getNamespacePrefixes()
+     * @return namespace mappings
+     * @throws RepositoryException if the namespaces could not be retrieved
+     */
+    public Map getNamespaces() throws RepositoryException {
+        Map namespaces = new HashMap();
+        String[] prefixes = session.getNamespacePrefixes();
+        for (int i = 0; i < prefixes.length; i++) {
+            namespaces.put(prefixes[i], session.getNamespaceURI(prefixes[i]));
+        }
+        return namespaces;
+    }
+
+    /**
+     * Returns the prefix mapped to the given namespace URI in the current
+     * session, or <code>null</code> if the namespace does not exist.
+     *
+     * @see Session#getNamespacePrefix(String)
+     * @param uri namespace URI
+     * @return namespace prefix, or <code>null</code>
+     * @throws RepositoryException if the namespace could not be retrieved
+     */
+    public String getPrefix(String uri) throws RepositoryException {
+        try {
+            return session.getNamespacePrefix(uri);
+        } catch (NamespaceException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Returns the namespace URI mapped to the given prefix in the current
+     * session, or <code>null</code> if the namespace does not exist.
+     *
+     * @see Session#getNamespaceURI(String)
+     * @param uri namespace URI
+     * @return namespace prefix, or <code>null</code>
+     * @throws RepositoryException if the namespace could not be retrieved
+     */
+    public String getURI(String prefix) throws RepositoryException {
+        try {
+            return session.getNamespaceURI(prefix);
+        } catch (NamespaceException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Returns the prefixed JCR name for the given namespace URI and local
+     * name in the current session.
+     *
+     * @param uri namespace URI
+     * @param name local name
+     * @return prefixed JCR name
+     * @throws NamespaceException if the namespace does not exist
+     * @throws RepositoryException if the namespace could not be retrieved
+     */
+    public String getJcrName(String uri, String name)
+            throws NamespaceException, RepositoryException {
+        if (uri != null && uri.length() > 0) {
+            return session.getNamespacePrefix(uri) + ":" + name;
+        } else {
+            return name;
+        }
+    }
+
+    /**
+     * Replaces the standard <code>jcr</code>, <code>nt</code>, or
+     * <code>mix</code> prefix in the given name with the prefix
+     * mapped to that namespace in the current session.
+     * <p>
+     * The purpose of this method is to make it easier to write
+     * namespace-aware code that uses names in the standard JCR namespaces.
+     * For example:
+     * <pre>
+     *     node.getProperty(helper.getName("jcr:data"));
+     * </pre>
+     *
+     * @param name prefixed name using the standard JCR prefixes
+     * @return prefixed name using the current session namespace mappings
+     * @throws IllegalArgumentException if the prefix is unknown
+     * @throws RepositoryException if the namespace could not be retrieved
+     */
+    public String getJcrName(String name)
+            throws IllegalArgumentException, RepositoryException {
+        String standardPrefix;
+        String currentPrefix;
+
+        if (name.startsWith("jcr:")) {
+            standardPrefix = "jcr";
+            currentPrefix = session.getNamespacePrefix(JCR);
+        } else if (name.startsWith("nt:")) {
+            standardPrefix = "nt";
+            currentPrefix = session.getNamespacePrefix(NT);
+        } else if (name.startsWith("mix:")) {
+            standardPrefix = "mix";
+            currentPrefix = session.getNamespacePrefix(MIX);
+        } else {
+            throw new IllegalArgumentException("Unknown prefix: " + name);
+        }
+
+        if (currentPrefix.equals(standardPrefix)) {
+            return name;
+        } else {
+            return currentPrefix + name.substring(standardPrefix.length());
+        }
+    }
+
+    /**
+     * Safely registers the given namespace. If the namespace already exists,
+     * then the prefix mapped to the namespace in the current session is
+     * returned. Otherwise the namespace is registered to the namespace
+     * registry. If the given prefix is already registered for some other
+     * namespace or otherwise invalid, then another prefix is automatically
+     * generated. After the namespace has been registered, the prefix mapped
+     * to it in the current session is returned.
+     *
+     * @see NamespaceRegistry#registerNamespace(String, String)
+     * @param prefix namespace prefix
+     * @param uri namespace URI
+     * @return namespace prefix in the current session
+     * @throws RepositoryException if the namespace could not be registered
+     */
+    public String registerNamespace(String prefix, String uri)
+            throws RepositoryException {
+        NamespaceRegistry registry =
+            session.getWorkspace().getNamespaceRegistry();
+        try {
+            // Check if the namespace is registered
+            registry.getPrefix(uri);
+        } catch (NamespaceException e1) {
+             // Replace troublesome prefix hints
+            if (prefix == null || prefix.length() == 0
+                    || prefix.toLowerCase().startsWith("xml")
+                    || !XMLChar.isValidNCName(prefix)) {
+                prefix = "ns"; // ns, ns2, ns3, ns4, ...
+            }
+
+            // Loop until an unused prefix is found
+            try {
+                String base = prefix;
+                for (int i = 2; true; i++) {
+                    registry.getURI(prefix);
+                    prefix = base + i;
+                }
+            } catch (NamespaceException e2) {
+                // Exit the loop
+            } 
+
+            // Register the namespace
+            registry.registerNamespace(prefix, uri);
+        }
+
+        return session.getNamespacePrefix(uri);
+    }
+
+    /**
+     * Safely registers all namespaces in the given map from
+     * prefixes to namespace URIs.
+     *
+     * @param namespaces namespace mappings
+     * @throws RepositoryException if the namespaces could not be registered
+     */
+    public void registerNamespaces(Map namespaces) throws RepositoryException {
+        Iterator iterator = namespaces.entrySet().iterator();
+        while (iterator.hasNext()) {
+            Map.Entry entry = (Map.Entry) iterator.next();
+            registerNamespace(
+                    (String) entry.getKey(), (String) entry.getValue());
+        }
+    }
+
+}

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/NamespaceHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/BTreeManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/ItemSequence.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/NodeSequence.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/PropertySequence.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/Rank.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/Sequence.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/SizedIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/TreeManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/TreeTraverser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/LazyIteratorChain.java
------------------------------------------------------------------------------
    svn:eol-style = native