You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2011/12/14 19:29:48 UTC

svn commit: r1214397 - in /jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/api: ./ MicroKernelTest.java

Author: stefan
Date: Wed Dec 14 18:29:48 2011
New Revision: 1214397

URL: http://svn.apache.org/viewvc?rev=1214397&view=rev
Log:
MicroKernel api test case

Added:
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/api/
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/api/MicroKernelTest.java

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/api/MicroKernelTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/api/MicroKernelTest.java?rev=1214397&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/api/MicroKernelTest.java (added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/api/MicroKernelTest.java Wed Dec 14 18:29:48 2011
@@ -0,0 +1,259 @@
+/*
+ * 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.mk.api;
+
+import junit.framework.Assert;
+import org.apache.jackrabbit.mk.MultiMkTestBase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(Parameterized.class)
+public class MicroKernelTest extends MultiMkTestBase {
+
+    public MicroKernelTest(String url) {
+        super(url);
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+
+        String head = mk.getHeadRevision();
+        mk.commit("/", "+\"test\" : {" +
+                "\"stringProp\":\"stringVal\"," +
+                "\"intProp\":42," +
+                "\"floatProp\":42.2," +
+                "\"multiIntProp\":[1,2,3]} ", head, "");
+    }
+
+    @Test
+    public void getNodes() {
+        String head = mk.getHeadRevision();
+
+        String json = mk.getNodes("/test", head, 0, 0, -1);
+        assertTrue(json.contains("stringProp"));
+    }
+
+    @Test
+    public void missingName() {
+        String head = mk.getHeadRevision();
+
+        assertTrue(mk.nodeExists("/test", head));
+        try {
+            String path = "/test/";
+            mk.getNodes(path, head);
+            Assert.fail("Success with invalid path: " + path);
+        } catch (IllegalArgumentException e) {
+            // expected
+        } catch (MicroKernelException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void addNodeWithRelativePath() {
+        String head = mk.getHeadRevision();
+
+        head = mk.commit("/", "+\"foo\" : {} \n+\"foo/bar\" : {}", head, "");
+        assertTrue(mk.nodeExists("/foo", head));
+        assertTrue(mk.nodeExists("/foo/bar", head));
+    }
+
+    @Test
+    public void commitWithEmptyPath() {
+        String head = mk.getHeadRevision();
+
+        head = mk.commit("", "+\"/ene\" : {}\n+\"/ene/mene\" : {}\n+\"/ene/mene/muh\" : {}", head, "");
+        assertTrue(mk.nodeExists("/ene/mene/muh", head));
+    }
+
+    @Test
+    public void addPropertyWithRelativePath() {
+        String head = mk.getHeadRevision();
+
+        head = mk.commit("/",
+                "+\"fuu\" : {} \n" +
+                        "^\"fuu/bar\" : 42", head, "");
+        String n = mk.getNodes("/fuu", head);
+        assertEquals("{\"bar\":42,\":childNodeCount\":0}", n);
+    }
+
+    @Test
+    public void addMultipleNodes() {
+        String head = mk.getHeadRevision();
+
+        long millis = System.currentTimeMillis();
+        String node1 = "n1_" + millis;
+        String node2 = "n2_" + millis;
+        head = mk.commit("/", "+\"" + node1 + "\" : {} \r+\"" + node2 + "\" : {}\n", head, "");
+        assertTrue(mk.nodeExists('/' + node1, head));
+        assertTrue(mk.nodeExists('/' + node2, head));
+    }
+
+    @Test
+    public void addDeepNodes() {
+        String head = mk.getHeadRevision();
+
+        head = mk.commit("/",
+                "+\"a\" : {} \r" +
+                        "+\"a/b\" : {} \r" +
+                        "+\"a/b/c\" : {} \r" +
+                        "+\"a/b/c/d\" : {} \r",
+                head, "");
+
+        assertTrue(mk.nodeExists("/a", head));
+        assertTrue(mk.nodeExists("/a/b", head));
+        assertTrue(mk.nodeExists("/a/b/c", head));
+        assertTrue(mk.nodeExists("/a/b/c/d", head));
+    }
+
+    @Test
+    public void addItemsIncrementally() {
+        if (url.startsWith("mem:")) {
+            // todo MemoryKernelImpl fails, investigate & fix test/impl
+            return;
+        }
+        String head = mk.getHeadRevision();
+
+        String node = "n_" + System.currentTimeMillis();
+
+        head = mk.commit("/",
+                "+\"" + node + "\" : {} \r" +
+                        "+\"" + node + "/child1\" : {} \r" +
+                        "+\"" + node + "/child2\" : {} \r" +
+                        "+\"" + node + "/child1/grandchild11\" : {} \r" +
+                        "^\"" + node + "/prop1\" : 41\r" +
+                        "^\"" + node + "/child1/prop2\" : 42\r" +
+                        "^\"" + node + "/child1/grandchild11/prop3\" : 43",
+                head, "");
+
+        String json = mk.getNodes('/' + node, head, 3, 0, -1);
+        assertEquals("{\"prop1\":41,\":childNodeCount\":2," +
+                "\"child1\":{\"prop2\":42,\":childNodeCount\":1," +
+                "\"grandchild11\":{\"prop3\":43,\":childNodeCount\":0}}," +
+                "\"child2\":{\":childNodeCount\":0}}", json);
+    }
+
+    @Test
+    public void removeNode() {
+        String head = mk.getHeadRevision();
+        String node = "removeNode_" + System.currentTimeMillis();
+
+        head = mk.commit("/", "+\"" + node + "\" : {\"child\":{}}", head, "");
+
+        head = mk.commit('/' + node, "-\"child\"", head, "");
+        String json = mk.getNodes('/' + node, head);
+        assertEquals("{\":childNodeCount\":0}", json);
+    }
+
+    @Test
+    public void moveNode() {
+        String head = mk.getHeadRevision();
+        String node = "moveNode_" + System.currentTimeMillis();
+        String movedNode = "movedNode_" + System.currentTimeMillis();
+        head = mk.commit("/", "+\"" + node + "\" : {}", head, "");
+
+        head = mk.commit("/", ">\"" + node + "\" : \"" + movedNode + '\"', head, "");
+        assertFalse(mk.nodeExists('/' + node, head));
+        assertTrue(mk.nodeExists('/' + movedNode, head));
+    }
+
+    @Test
+    public void overwritingMove() {
+        String head = mk.getHeadRevision();
+
+        head = mk.commit("/", "+\"a\" : {} \r+\"b\" : {} \r", head, "");
+        try {
+            mk.commit("/", ">\"a\" : \"b\"  ", head, "");
+        }
+        catch (MicroKernelException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void conflictingMove() {
+        String head = mk.getHeadRevision();
+
+        head = mk.commit("/", "+\"a\" : {} \r+\"b\" : {}\n", head, "");
+
+        String r1 = mk.commit("/", ">\"a\" : \"b/a\"", head, "");
+        assertFalse(mk.nodeExists("/a", r1));
+        assertTrue(mk.nodeExists("/b", r1));
+        assertTrue(mk.nodeExists("/b/a", r1));
+
+        try {
+            mk.commit("/", ">\"b\" : \"a/b\"", head, "");
+        }
+        catch (MicroKernelException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void conflictingAddDelete() {
+        String head = mk.getHeadRevision();
+
+        head = mk.commit("/", "+\"a\" : {} \r+\"b\" : {}\n", head, "");
+
+        String r1 = mk.commit("/", "-\"b\" \r +\"a/x\" : {}", head, "");
+        assertFalse(mk.nodeExists("/b", r1));
+        assertTrue(mk.nodeExists("/a", r1));
+        assertTrue(mk.nodeExists("/a/x", r1));
+
+        try {
+            mk.commit("/", "-\"a\" \r +\"b/x\" : {}", head, "");
+        }
+        catch (MicroKernelException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void reorderNode() {
+        if (!url.startsWith("mem:")) {
+            // todo provide node reorder-support (MicroKernelImpl)
+            return;
+        }
+        String head = mk.getHeadRevision();
+        String node = "reorderNode_" + System.currentTimeMillis();
+        head = mk.commit("/", "+\"" + node + "\" : {\"a\":{}, \"b\":{}, \"c\":{}}", head, "");
+        System.out.println(mk.getNodes('/' + node, head).replaceAll("\"", "").replaceAll(":childNodeCount:.", ""));
+
+        head = mk.commit("/", ">\"" + node + "/a\" : {\"before\":\"" + node + "/c\"}", head, "");
+        System.out.println(mk.getNodes('/' + node, head).replaceAll("\"", "").replaceAll(":childNodeCount:.", ""));
+    }
+
+    @Test
+    public void removeProperty() {
+        String head = mk.getHeadRevision();
+        long t = System.currentTimeMillis();
+        String node = "removeProperty_" + t;
+
+        head = mk.commit("/", "+\"" + node + "\" : {\"prop\":\"value\"}", head, "");
+
+        head = mk.commit("/", "^\"" + node + "/prop\" : null", head, "");
+        String json = mk.getNodes('/' + node, head);
+        assertEquals("{\":childNodeCount\":0}", json);
+    }
+}