jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1151440 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
Date Wed, 27 Jul 2011 12:16:26 GMT
Author: thomasm
Date: Wed Jul 27 12:16:25 2011
New Revision: 1151440

URL: http://svn.apache.org/viewvc?rev=1151440&view=rev
Log:
Simplify tests.

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1151440&r1=1151439&r2=1151440&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Wed Jul 27 12:16:25 2011
@@ -180,7 +180,11 @@ public class MemoryKernelImpl implements
                 } else {
                     throw new AssertionError("position: " + position);
                 }
-                to = PathUtils.concat(fromRoot, target);
+                if (PathUtils.isAbsolute(target)) {
+                    to = PathUtils.relativize("/", target);
+                } else {
+                    to = PathUtils.concat(fromRoot, target);
+                }
                 boolean inPlaceRename = false;
                 if (rename) {
                     if (PathUtils.getParentPath(from).equals(PathUtils.getParentPath(to)))
{
@@ -198,7 +202,7 @@ public class MemoryKernelImpl implements
                 }
                 break;
             default:
-                throw new AssertionError("token type: " + t.getTokenType());
+                throw new AssertionError("token: " + (char) t.getTokenType());
             }
         }
         return w.toString();

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java?rev=1151440&r1=1151439&r2=1151440&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
Wed Jul 27 12:16:25 2011
@@ -29,86 +29,129 @@ public class MoveNodeTest extends TestCa
 
     private MicroKernel mk;
 
+    private String head;
+
     public void setUp() throws Exception {
         mk = MicroKernelFactory.getInstance(URL);
+        head = mk.getHeadRevision();
+        commit("/", "+ \"test\": {\"a\":{}, \"b\":{}, \"c\":{}}");
+        commit("/", "+ \"test2\": {}");
+
+        int todoTestJournal;
+
     }
 
     public void tearDown() throws InterruptedException {
         mk.dispose();
     }
 
-    public void test() {
-
-        String head = mk.getHeadRevision();
-
-        head = mk.commit("/", "+ \"test\" : {\"a\":{}, \"b\":{}, \"c\":{}}", head, null);
-        head = mk.commit("/", "+ \"test2\" : {}", head, null);
-        head = mk.commit("/", "+ \"test3\" : {}", head, null);
-        String s;
-
-        s = mk.getNodes("/test", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{,a:{},b:{},c:{}}", s);
-        System.out.println(s);
+    public void testOrder() {
+        assertEquals("{a,b,c}", getNode("/test"));
+    }
 
-        // rename /test/b to /test/b1 and back
-        head = mk.commit("/", "> \"test/b\" : \"test/b1\"", head, null);
-        s = mk.getNodes("/test", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{,a:{},b1:{},c:{}}", s);
-        head = mk.commit("/", "> \"test/b1\" : \"test/b\"", head, null);
-        s = mk.getNodes("/test", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{,a:{},b:{},c:{}}", s);
+    public void testRename() {
+        // rename /test/b
+        commit("/", "> \"test/b\": \"test/b1\"");
+        assertEquals("{a,b1,c}", getNode("/test"));
+        // and back
+        commit("/", "> \"test/b1\": \"test/b\"");
+        assertEquals("{a,b,c}", getNode("/test"));
+    }
 
+    public void testReorderBefore() {
         // order c before b
-        head = mk.commit("/", "> \"test/c\" : {\"before\": \"test/b\"}", head, null);
-        s = mk.getNodes("/test", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{,a:{},c:{},b:{}}", s);
+        commit("/", "> \"test/c\": {\"before\": \"test/b\"}");
+        assertEquals("{a,c,b}", getNode("/test"));
+        // and now b before a
+        commit("/", "> \"test/b\": {\"before\": \"test/a\"}");
+        assertEquals("{b,a,c}", getNode("/test"));
+    }
 
-        // order a after c
-        head = mk.commit("/", "> \"test/a\" : {\"after\": \"test/c\"}", head, null);
-        s = mk.getNodes("/test", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{,c:{},a:{},b:{}}", s);
+    public void testReorderAfter() {
+        // order a after b
+        commit("/", "> \"test/a\": {\"after\": \"test/b\"}");
+        assertEquals("{b,a,c}", getNode("/test"));
+        // and now a after c
+        commit("/", "> \"test/a\": {\"after\": \"test/c\"}");
+        assertEquals("{b,c,a}", getNode("/test"));
+        // and now a after a (a no-op)
+        commit("/", "> \"test/a\": {\"after\": \"test/a\"}");
+        assertEquals("{b,c,a}", getNode("/test"));
+    }
 
+    public void testMoveFirst() {
         // move /test/a to /test2/a (rename is not supported in this way)
-        head = mk.commit("/", "> \"test/a\" : {\"first\": \"test2\"}", head, null);
-        s = mk.getNodes("/test", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{,c:{},b:{}}", s);
-        s = mk.getNodes("/test2", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{,a:{}}", s);
+        commit("/", "> \"test/a\": {\"first\": \"test2\"}");
+        assertEquals("{b,c}", getNode("/test"));
+        assertEquals("{a}", getNode("/test2"));
+        // move /test/c to /test2
+        commit("/", "> \"test/c\": {\"first\": \"test2\"}");
+        assertEquals("{b}", getNode("/test"));
+        assertEquals("{c,a}", getNode("/test2"));
+    }
 
+    public void testMoveBefore() {
         // move /test/b to /test2/b, before any other nodes in /test2
-        head = mk.commit("/", "> \"test/b\" : {\"first\": \"test2\"}", head, null);
-        s = mk.getNodes("/test", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{,c:{}}", s);
-        s = mk.getNodes("/test2", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{,b:{},a:{}}", s);
+        commit("/", "> \"test/b\": {\"first\": \"test2\"}");
+        assertEquals("{a,c}", getNode("/test"));
+        assertEquals("{b}", getNode("/test2"));
+        // move /test/c to /test2, before b
+        commit("/", "> \"test/c\": {\"before\": \"test2/b\"}");
+        assertEquals("{a}", getNode("/test"));
+        assertEquals("{c,b}", getNode("/test2"));
+    }
 
-        // move /test/c to /test2, after b
-        head = mk.commit("/", "> \"test/c\" : {\"after\": \"test2/b\"}", head, null);
-        s = mk.getNodes("/test", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{}", s);
-        s = mk.getNodes("/test2", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{,b:{},c:{},a:{}}", s);
+    public void testMoveAfter() {
+        // move /test/c to /test2
+        commit("/", "> \"test/c\": \"test2/c\"");
+        assertEquals("{a,b}", getNode("/test"));
+        assertEquals("{c}", getNode("/test2"));
+        // move /test/a to /test2, after c
+        commit("/", "> \"test/a\": {\"after\": \"test2/c\"}");
+        assertEquals("{b}", getNode("/test"));
+        assertEquals("{c,a}", getNode("/test2"));
+        // move /test/b to /test2, after c
+        commit("/", "> \"test/b\": {\"after\": \"test2/c\"}");
+        assertEquals("{}", getNode("/test"));
+        assertEquals("{c,b,a}", getNode("/test2"));
+    }
 
-        // move /test2/a to /test2, as last
-        head = mk.commit("/", "> \"test2/b\" : {\"last\": \"test2\"}", head, null);
-        s = mk.getNodes("/test2", head);
-        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
-        assertEquals("{,c:{},a:{},b:{}}", s);
+    public void testMoveLast() {
+        // move /test/a to /test2, as last
+        commit("/", "> \"test/b\": {\"last\": \"test2\"}");
+        assertEquals("{a,c}", getNode("/test"));
+        assertEquals("{b}", getNode("/test2"));
+        // move /test/c to /test2, as last
+        commit("/", "> \"test/c\": {\"last\": \"test2\"}");
+        assertEquals("{a}", getNode("/test"));
+        assertEquals("{b,c}", getNode("/test2"));
+    }
 
-        mk.dispose();
+    public void testMove() {
+        // move /test/b to /test2
+        commit("/", "> \"test/b\": \"/test2/b\"");
+        assertEquals("{a,c}", getNode("/test"));
+        assertEquals("{b}", getNode("/test2"));
+        // move /test/a to /test2
+        commit("/", "> \"test/a\": \"test2/a1\"");
+        assertEquals("{c}", getNode("/test"));
+        assertEquals("{b,a1}", getNode("/test2"));
+        // move /test/c to /test2
+        commit("/", "> \"test/c\": \"test2/c\"");
+        assertEquals("{}", getNode("/test"));
+        assertEquals("{b,a1,c}", getNode("/test2"));
+    }
 
-        System.out.println("");
+    private void commit(String root, String diff) {
+        head = mk.commit(root, diff, head, null);
+    }
+
+    private String getNode(String node) {
+        String s = mk.getNodes(node, mk.getHeadRevision());
+        s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
+        s = s.replaceAll("\\{\\,", "\\{").replaceAll("\\,\\}", "\\}");
+        s = s.replaceAll("\\:\\{\\}", "");
+        return s;
     }
 
 }
\ No newline at end of file



Mime
View raw message