jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r932951 - /jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/
Date Sun, 11 Apr 2010 17:45:05 GMT
Author: thomasm
Date: Sun Apr 11 17:45:05 2010
New Revision: 932951

URL: http://svn.apache.org/viewvc?rev=932951&view=rev
Log:
Some code for a Jackrabbit 3 prototype

Added:
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestCache.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestCreateNodesTraverse.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSecurity.java
Modified:
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestBase.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNamespaceRegistry.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNextConfiguration.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNodeTypeRegistry.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java?rev=932951&r1=932950&r2=932951&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java (original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java Sun
Apr 11 17:45:05 2010
@@ -37,12 +37,16 @@ public class TestAll {
         suite.addTestSuite(TestBundle.class);
         suite.addTestSuite(TestNamespaceRegistry.class);
         suite.addTestSuite(TestNodeTypeRegistry.class);
+        suite.addTestSuite(TestSecurity.class);
+        suite.addTestSuite(TestCache.class);
+        suite.addTestSuite(TestCreateNodesTraverse.class);
 
         for (int i = 0; i < TestBase.URL.length; i++) {
             suite.addTestSuite(TestConcurrentWrite.class);
             suite.addTestSuite(TestLock.class);
             suite.addTestSuite(TestSimple.class);
             suite.addTestSuite(TestObservation.class);
+
             suite.addTestSuite(TestNextConfiguration.class);
         }
 

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestBase.java?rev=932951&r1=932950&r2=932951&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestBase.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestBase.java
Sun Apr 11 17:45:05 2010
@@ -36,6 +36,7 @@ public class TestBase extends TestCase {
     protected static int configurationId;
 
     public static final String[] URL = new String[] {
+        // "jdbc:h2:target/repos/test&log=debug",
         "jdbc:h2:target/repos/test",
         "mem:",
         "jdbc:h2:mem:test",

Added: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestCache.java?rev=932951&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestCache.java
(added)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestCache.java
Sun Apr 11 17:45:05 2010
@@ -0,0 +1,114 @@
+/*
+ * 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.j3;
+
+import java.util.HashMap;
+import org.apache.jackrabbit.j3.mc.NodeData;
+import org.apache.jackrabbit.j3.mc.Val;
+import org.apache.jackrabbit.j3.util.Cache;
+import org.apache.jackrabbit.j3.util.Constants;
+
+
+/**
+ * Test the ValueFactory
+ */
+public class TestCache extends TestBase {
+
+    public void testValLongMemory() {
+        int length = 1024 * 16;
+        Val[] array = new Val[length];
+        long mem = getMem();
+        int expected = 0;
+        for (int i = 0; i < length; i++) {
+            Val v = Val.get(i);
+            expected += v.getMemoryUsed();
+            array[i] = v;
+        }
+        log("val long expected: " + expected + " used: " + (getMem() - mem));
+    }
+
+    public void testValStringMemory() {
+        int length = 1024 * 16;
+        Val[] array = new Val[length];
+        long mem = getMem();
+        int expected = 0;
+        for (int i = 0; i < length; i++) {
+            Val v = Val.get("" + i);
+            expected += v.getMemoryUsed();
+            array[i] = v;
+        }
+        log("val string expected: " + expected + " used: " + (getMem() - mem));
+    }
+
+    public void testNodeDataMemory() {
+        int length = 16 * 1024;
+        NodeData[] array = new NodeData[length];
+        long mem = getMem();
+        int expected = 0;
+        for (int i = 0; i < length; i++) {
+            NodeData node = new NodeData(Val.get(0), null, 0);
+            expected += node.getMemoryUsed();
+            array[i] = node;
+        }
+        log("node expected: " + expected + " used: " + (getMem() - mem));
+    }
+
+
+    public void testHashMapMemory() {
+        int size = 16 * 1024;
+        HashMap<Val, Val> map = new HashMap<Val, Val>(size);
+        long mem = getMem();
+        int valMem = 0;
+        for (int i = 0; i < size; i++) {
+            Val id = Val.get("" + i);
+            valMem += id.getMemoryUsed();
+            map.put(id, id);
+        }
+        int expected = valMem + size * Constants.MEM_MAP_ENTRY;
+        log("map expected: " + expected + " used: " + (getMem() - mem));
+    }
+
+    public void testCacheMemory() {
+        int size = 4 * 1024 * 1024;
+        Cache<Val, NodeData> cache = new Cache<Val, NodeData>(size);
+        long mem = getMem();
+        for (int i = 0;; i++) {
+            Val id = Val.get("" + i);
+            NodeData node = new NodeData(id, null, 0);
+            long old = cache.getMemoryUsed();
+            int s = node.getMemoryUsed();
+            cache.put(id, node);
+            if (s + old >= size) {
+                break;
+            }
+        }
+        log("cache expected: " + size + " used: " + (getMem() - mem));
+        log("  elements: " + cache.size());
+    }
+
+    private void log(String s) {
+        // System.out.println(s);
+    }
+
+    long getMem() {
+        for (int i = 0; i < 3; i++) {
+            System.gc();
+        }
+        return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
+    }
+
+}

Added: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestCreateNodesTraverse.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestCreateNodesTraverse.java?rev=932951&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestCreateNodesTraverse.java
(added)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestCreateNodesTraverse.java
Sun Apr 11 17:45:05 2010
@@ -0,0 +1,168 @@
+/*
+ * 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.j3;
+
+import java.io.ByteArrayInputStream;
+import java.util.Calendar;
+import javax.jcr.Binary;
+import javax.jcr.ItemExistsException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.version.VersionException;
+
+/**
+ * Test creating nodes and traversing.
+ */
+public class TestCreateNodesTraverse extends TestBase {
+
+    String ct = "text/plain";
+    int nodeCount, propertyCount;
+
+    public void test() throws Exception {
+
+        long time;
+        time = System.currentTimeMillis();
+
+        createNodes(100, 4, 3, true, 2, "Hallo");
+
+        time = System.currentTimeMillis() - time;
+        // System.out.println("create: " + time);
+
+        for (int i = 0; i < 3; i++) {
+
+            time = System.currentTimeMillis();
+
+            nodeCount = propertyCount = 0;
+            traverse(session.getRootNode());
+
+            // System.out.println("  nodes: " + nodeCount + " properties: " + propertyCount);
+
+            assertEquals(3233, nodeCount);
+            assertEquals(6700, propertyCount);
+
+            nodeCount = propertyCount = 0;
+            dataStoreConsistency(session.getRootNode());
+            assertEquals(3233, nodeCount);
+
+            time = System.currentTimeMillis() - time;
+            // System.out.println("traverse: " + time);
+
+        }
+
+    }
+
+    private void createNodes(int maxDocs, int docsPerFolder, int depth, boolean createDocs,
int width, String text)
+            throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException,
+            VersionException, ConstraintViolationException, RepositoryException {
+        int doc = 0;
+        Node main = null;
+        byte[] textBytes = text.getBytes();
+        ValueFactory vf = session.getValueFactory();
+        Node root = session.getRootNode().addNode("test", "nt:folder");
+        while (doc < maxDocs) {
+            if (doc % (docsPerFolder * docsPerFolder) == 0) {
+                // new top folder
+                main = root.addNode("folder_" + doc, "nt:folder");
+                session.save();
+            }
+            Node parent = main.addNode("folder_" + doc, "nt:folder");
+            session.save();
+            int i = 0;
+            while (i < docsPerFolder) {
+                Node n = parent.addNode("file_" + doc + ".txt", "nt:file");
+                if (createDocs) {
+                    Node content = n.addNode("jcr:content", "nt:unstructured");
+                    content.setProperty("jcr:lastModified", Calendar.getInstance());
+                    content.setProperty("jcr:mimeType", "text/plain");
+                    createLevel(content, text, depth, width);
+                    session.save();
+                } else {
+                    Node content = n.addNode("jcr:content", "nt:resource");
+                    content.setProperty("jcr:lastModified", Calendar.getInstance());
+                    content.setProperty("jcr:mimeType", ct);
+                    Binary b = vf.createBinary(new ByteArrayInputStream(textBytes));
+                    content.setProperty("jcr:data", b);
+                }
+                doc++;
+                i++;
+                if (doc == maxDocs) {
+                    break;
+                }
+            }
+        }
+    }
+
+    private void createLevel(Node parent, String content, int depth, int width) throws RepositoryException
{
+        for (int i = 0; i < width; i++) {
+            Node n = parent.addNode("node" + depth + i, "nt:unstructured");
+            n.setProperty("data", content);
+            if (depth > 0) {
+                createLevel(n, content, depth - 1, width);
+            }
+        }
+    }
+
+    private void traverse(Node n) throws Exception {
+        PropertyIterator piter = n.getProperties();
+        while (piter.hasNext()) {
+            Property p = piter.nextProperty();
+            propertyCount++;
+            p.getName();
+            p.getValue();
+        }
+        NodeIterator iter = n.getNodes();
+        while (iter.hasNext()) {
+            Node next = iter.nextNode();
+            if (next.getName().equals("jcr:system")) {
+                continue;
+            }
+            nodeCount++;
+            traverse(next);
+        }
+    }
+
+    private void dataStoreConsistency(Node n) throws Exception {
+        PropertyIterator piter = n.getProperties();
+        while (piter.hasNext()) {
+            Property p = piter.nextProperty();
+            // getValue() alone opens a stream but doesn't close it
+            if (p.getType() == PropertyType.BINARY) {
+                if (p.getDefinition().isMultiple()) {
+                    Value[] values = p.getValues();
+                    for (int i = 0; i < values.length; i++) {
+                        values[i].getBinary().getStream().close();
+                    }
+                } else {
+                    p.getBinary().getStream().close();
+                }
+            }
+        }
+        NodeIterator iter = n.getNodes();
+        while (iter.hasNext()) {
+            nodeCount++;
+            dataStoreConsistency(iter.nextNode());
+        }
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNamespaceRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNamespaceRegistry.java?rev=932951&r1=932950&r2=932951&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNamespaceRegistry.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNamespaceRegistry.java
Sun Apr 11 17:45:05 2010
@@ -31,6 +31,15 @@ public class TestNamespaceRegistry exten
         assertEquals(NamespaceRegistry.PREFIX_MIX, registry.getPrefix(NamespaceRegistry.NAMESPACE_MIX));
         registry.registerNamespace("test", "TEST");
         assertEquals("TEST", registry.getURI("test"));
+        String a = registry.toString();
+        String b = "<jcr=http://www.jcp.org/jcr/1.0>" +
+            "<nt=http://www.jcp.org/jcr/nt/1.0>" +
+            "<mix=http://www.jcp.org/jcr/mix/1.0>" +
+            "<xml=http://www.w3.org/XML/1998/namespace>" +
+            "<=>" +
+            "<rep=internal>" +
+            "<test=TEST>";
+        assertEquals(b, a);
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNextConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNextConfiguration.java?rev=932951&r1=932950&r2=932951&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNextConfiguration.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNextConfiguration.java
Sun Apr 11 17:45:05 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.j3;
 
+
 /**
  * A test that switches to the next test configuration.
  */

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNodeTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNodeTypeRegistry.java?rev=932951&r1=932950&r2=932951&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNodeTypeRegistry.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestNodeTypeRegistry.java
Sun Apr 11 17:45:05 2010
@@ -13,24 +13,81 @@
  */
 package org.apache.jackrabbit.j3;
 
+import java.io.StringWriter;
+import javax.jcr.NamespaceRegistry;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeTypeTemplate;
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.j3.nodetype.CndParser;
 
 /**
  * Tests the node type registry.
  */
 public class TestNodeTypeRegistry extends TestBase {
 
-    public void test() throws RepositoryException {
+    public void testUndefineBuiltIn() throws RepositoryException {
+        NodeTypeManager m = session.getWorkspace().getNodeTypeManager();
+        try {
+            m.unregisterNodeType("nt:base");
+            fail();
+        } catch (RepositoryException e) {
+            // expected
+        }
+    }
+
+    public void testCndParser() throws Exception {
+
         Node n = session.getRootNode().addNode("testNodeType");
         NodeType nt = n.getPrimaryNodeType();
         assertEquals("nt:unstructured", nt.getName());
-//        NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
-//        NodeTypeIterator it = ntm.getAllNodeTypes();
-//        while (it.hasNext()) {
-//            nt = it.nextNodeType();
-//            System.out.println(nt.getName());
-//        }
+
+        StringWriter w = new StringWriter();
+
+        w = new StringWriter();
+        IOUtils.copy(getClass().getResourceAsStream("builtin_nodetypes.cnd"), w);
+        CndParser parser = createCndParser(session, w.toString());
+        parser.parse();
+
+        StringBuilder buff = new StringBuilder();
+        for (NodeTypeTemplate ntt : parser.getNodeTypeTemplates()) {
+            buff.append(ntt);
+        }
+        String a = buff.toString();
+        NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
+        String b = ntm.toString();
+        assertEquals(a, b);
+
+        w = new StringWriter();
+        IOUtils.copy(getClass().getResourceAsStream("test.cnd"), w);
+        parser = createCndParser(session, w.toString());
+        parser.parse();
+    }
+
+    public void testParseToString() throws Exception {
+        NodeTypeManager m = session.getWorkspace().getNodeTypeManager();
+        String cnd = m.toString();
+        CndParser parser = createCndParser(session, cnd);
+        try {
+            parser.parse();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        StringBuilder buff = new StringBuilder();
+        for (NodeTypeTemplate nt : parser.getNodeTypeTemplates()) {
+            buff.append(nt);
+        }
+        String cnd2 = buff.toString();
+        assertEquals(cnd, cnd2);
     }
+
+    private CndParser createCndParser(Session s, String cnd) throws RepositoryException {
+        NodeTypeManager ntm = s.getWorkspace().getNodeTypeManager();
+        NamespaceRegistry nsReg = s.getWorkspace().getNamespaceRegistry();
+        return new CndParser(ntm, nsReg, s.getValueFactory(), cnd);
+    }
+
 }

Added: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSecurity.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSecurity.java?rev=932951&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSecurity.java
(added)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSecurity.java
Sun Apr 11 17:45:05 2010
@@ -0,0 +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.j3;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+import javax.jcr.security.AccessControlManager;
+import javax.jcr.security.Privilege;
+import org.apache.jackrabbit.j3.security.PrivilegeImpl;
+
+/**
+ * Tests security.
+ */
+public class TestSecurity extends TestBase {
+
+    private AccessControlManager acm;
+
+    public void testAccessControlManager() throws RepositoryException {
+        acm = session.getAccessControlManager();
+        testPrivilege(false, Privilege.JCR_ADD_CHILD_NODES);
+        testPrivilege(true, Privilege.JCR_ALL);
+        testPrivilege(false, Privilege.JCR_LIFECYCLE_MANAGEMENT);
+        testPrivilege(false, Privilege.JCR_LOCK_MANAGEMENT);
+        testPrivilege(false, Privilege.JCR_MODIFY_ACCESS_CONTROL);
+        testPrivilege(false, Privilege.JCR_MODIFY_PROPERTIES);
+        testPrivilege(false, Privilege.JCR_NODE_TYPE_MANAGEMENT);
+        testPrivilege(false, Privilege.JCR_READ);
+        testPrivilege(false, Privilege.JCR_READ_ACCESS_CONTROL);
+        testPrivilege(false, Privilege.JCR_REMOVE_CHILD_NODES);
+        testPrivilege(false, Privilege.JCR_REMOVE_NODE);
+        testPrivilege(false, Privilege.JCR_RETENTION_MANAGEMENT);
+        testPrivilege(false, Privilege.JCR_VERSION_MANAGEMENT);
+        testPrivilege(true, Privilege.JCR_WRITE);
+
+        Privilege p = acm.privilegeFromName(Privilege.JCR_ALL);
+        Set<Privilege> s = new HashSet<Privilege>(Arrays.asList(p.getDeclaredAggregatePrivileges()));
+        assertEquals(9, s.size());
+        assertTrue(s.contains(acm.privilegeFromName(Privilege.JCR_READ)));
+        assertTrue(s.contains(acm.privilegeFromName(Privilege.JCR_WRITE)));
+        assertTrue(s.contains(acm.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL)));
+        assertTrue(s.contains(acm.privilegeFromName(Privilege.JCR_MODIFY_ACCESS_CONTROL)));
+        assertTrue(s.contains(acm.privilegeFromName(Privilege.JCR_LOCK_MANAGEMENT)));
+        assertTrue(s.contains(acm.privilegeFromName(Privilege.JCR_VERSION_MANAGEMENT)));
+        assertTrue(s.contains(acm.privilegeFromName(Privilege.JCR_NODE_TYPE_MANAGEMENT)));
+        assertTrue(s.contains(acm.privilegeFromName(Privilege.JCR_RETENTION_MANAGEMENT)));
+        assertTrue(s.contains(acm.privilegeFromName(Privilege.JCR_LIFECYCLE_MANAGEMENT)));
+
+        assertEquals(12, p.getAggregatePrivileges().length);
+    }
+
+    private void testPrivilege(boolean isAggregate, String name) throws RepositoryException
{
+        Privilege p = acm.privilegeFromName(name);
+        String n = p.getName();
+        String n2 = name.substring(("{" + NamespaceRegistry.NAMESPACE_JCR + "}").length());
+        assertEquals("jcr:" + n2, n);
+        assertFalse(p.isAbstract());
+        assertEquals(isAggregate, p.isAggregate());
+    }
+
+    public void testAction() {
+        int addNode = PrivilegeImpl.ADD_CHILD_NODES;
+        int setProperty = PrivilegeImpl.MODIFY_PROPERTIES;
+        int remove = PrivilegeImpl.REMOVE_NODE | setProperty;
+        int read = PrivilegeImpl.READ;
+
+        assertEquals(addNode, PrivilegeImpl.getPrivilege("add_node"));
+        assertEquals(setProperty, PrivilegeImpl.getPrivilege("set_property"));
+        assertEquals(remove, PrivilegeImpl.getPrivilege("remove"));
+        assertEquals(read, PrivilegeImpl.getPrivilege("read"));
+
+        assertEquals(addNode | setProperty | remove | read, PrivilegeImpl.getPrivilege("add_node,set_property,remove,read"));
+        assertEquals(addNode | remove | read, PrivilegeImpl.getPrivilege("add_node,remove,read"));
+
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java?rev=932951&r1=932950&r2=932951&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java
Sun Apr 11 17:45:05 2010
@@ -17,6 +17,9 @@
 package org.apache.jackrabbit.j3;
 
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
@@ -51,6 +54,28 @@ public class TestSimple extends TestBase
         root2.getNode("test").remove();
         assertFalse(root2.hasNode("test"));
 
+        // test PropertyIterator
+        PropertyIterator it = test.getProperties();
+        Property p;
+        assertTrue(it.hasNext());
+        p = it.nextProperty();
+        assertEquals("jcr:primaryType", p.getName());
+        assertEquals("nt:unstructured", p.getString());
+        assertTrue(it.hasNext());
+        p = it.nextProperty();
+        assertEquals("name", p.getName());
+        assertEquals("Hello", p.getString());
+        assertFalse(it.hasNext());
+
+        // test NodeIterator
+        session.getRootNode().addNode("test2");
+        NodeIterator nit = session.getRootNode().getNodes();
+        assertTrue(nit.hasNext());
+        assertEquals("test", nit.nextNode().getName());
+        assertTrue(nit.hasNext());
+        assertEquals("test2", nit.nextNode().getName());
+        assertFalse(nit.hasNext());
+
         createReadNodes();
 
         session2.logout();
@@ -58,6 +83,12 @@ public class TestSimple extends TestBase
 
     }
 
+    public void testReadFromCache() throws RepositoryException {
+        // 30% read absolute path
+        // 70% read relative path
+        // 10% read binaries
+    }
+
     private void createReadNodes() throws RepositoryException {
         Node root = session.getRootNode();
         // 488280 nodes:



Mime
View raw message