You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2007/02/20 08:57:02 UTC

svn commit: r509446 - in /jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit: jcr2spi/SNSIndexTest.java test/TestNodeWrite.java

Author: angela
Date: Mon Feb 19 23:57:01 2007
New Revision: 509446

URL: http://svn.apache.org/viewvc?view=rev&rev=509446
Log:
- more tests related to SNS
- TestNodeWrite is TestCase

Added:
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SNSIndexTest.java   (with props)
Modified:
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/test/TestNodeWrite.java

Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SNSIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SNSIndexTest.java?view=auto&rev=509446
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SNSIndexTest.java (added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SNSIndexTest.java Mon Feb 19 23:57:01 2007
@@ -0,0 +1,180 @@
+/*
+ * 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.jcr2spi;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.name.Path;
+
+import javax.jcr.*;
+
+/**
+ * <code>SNSIndexTest</code>...
+ */
+public class SNSIndexTest extends AbstractJCRTest {
+
+    private static Logger log = LoggerFactory.getLogger(SNSIndexTest.class);
+
+    private String snsName;
+
+    private Node parent;
+
+    private Node sns1;
+    private Node sns2;
+    private Node sns3;
+    private Node sns4;
+
+    private String snsPath;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        snsName = nodeName2;
+
+        parent = testRootNode.addNode(nodeName1, testNodeType);
+        // create sns-siblings
+        sns1 = parent.addNode(snsName, testNodeType);
+        sns2 = parent.addNode(snsName, testNodeType);
+        sns3 = parent.addNode(snsName, testNodeType);
+        sns4 = parent.addNode(snsName, testNodeType);
+
+        testRootNode.save();
+
+        snsPath = testRootNode.getPath() + "/" + nodeName1 + "/" + snsName;
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /**
+     * Test if index of the created nodes are as expected.
+     */
+    public void testIndex() throws RepositoryException {
+        checkIndex(sns1, Path.INDEX_DEFAULT);
+        checkIndex(sns2, Path.INDEX_DEFAULT + 1);
+        checkIndex(sns3, Path.INDEX_DEFAULT + 2);
+        checkIndex(sns4, Path.INDEX_DEFAULT + 3);
+    }
+
+    /**
+     * Test if index of the created nodes are as expected if they are accessed
+     * by another session.
+     */
+    public void testIndexByOtherSession() throws RepositoryException {
+        Session otherSession = helper.getReadOnlySession();
+        for (int index = Path.INDEX_DEFAULT; index < 4; index++) {
+            Node sns = (Node) otherSession.getItem(buildPath(index));
+            checkIndex(sns, index);
+        }
+    }
+
+    /**
+     * Test if passing an bigger index throws exception
+     */
+    public void testNonExistingIndex() throws RepositoryException {
+        try {
+            superuser.getItem(buildPath(10));
+            fail("Accessing item with non-existing index must throw PathNotFoundException.");
+        } catch (PathNotFoundException e) {
+            // ok
+        }
+    }
+
+    /**
+     * Test if accessing a child node by sns-Name, the node with the default
+     * index is returned.
+     */
+    public void testDefaultIndex() throws RepositoryException {
+        Node sns = parent.getNode(snsName);
+        checkIndex(sns, Path.INDEX_DEFAULT);
+    }
+
+    /**
+     * Test if index of any node is correctly set, if the node is accessed
+     * without loading SNSs with lower index before
+     */
+    public void testNodeEntriesFilledCorrectly() throws RepositoryException {
+        Session otherSession = helper.getReadOnlySession();
+        Node sns = (Node) otherSession.getItem(buildPath(3));
+        checkIndex(sns, 3);
+
+        sns = (Node) otherSession.getItem(buildPath(2));
+        checkIndex(sns, 2);
+
+        sns = (Node) otherSession.getItem(buildPath(4));
+        checkIndex(sns, 4);
+
+        // check 3 again
+        sns = (Node) otherSession.getItem(buildPath(3));
+        checkIndex(sns, 3);
+
+        // check default
+        sns = (Node) otherSession.getItem(buildPath(1));
+        checkIndex(sns, 1);
+    }
+
+    /**
+     * Test if accessing the created nodes by name really returns all nodes.
+     */
+    public void testGetNodesByName() throws RepositoryException {
+        NodeIterator it = parent.getNodes(snsName);
+        long size = it.getSize();
+        if (size != -1) {
+            assertTrue("4 SNSs have been added -> but iterator size is " + size + ".", size == 4);
+        }
+        int expectedIndex = 1;
+        while (it.hasNext()) {
+            Node sns = it.nextNode();
+            checkIndex(sns, expectedIndex);
+            expectedIndex++;
+        }
+        assertTrue("4 SNSs have been added -> but iterator size is " + size + ".", size == 4);
+    }
+
+    /**
+     * Test if accessing the created nodes by name really returns all nodes.
+     */
+    public void testGetNodesByNameByOtherSession() throws RepositoryException {
+        Session otherSession = helper.getReadOnlySession();
+        NodeIterator it = ((Node) otherSession.getItem(parent.getPath())).getNodes(snsName);
+        long size = it.getSize();
+        if (size != -1) {
+            assertTrue("4 SNSs have been added -> but iterator size is " + size + ".", size == 4);
+        }
+        int expectedIndex = 1;
+        while (it.hasNext()) {
+            Node sns = it.nextNode();
+            checkIndex(sns, expectedIndex);
+            expectedIndex++;
+        }
+        assertTrue("4 SNSs have been added -> but iterator size is " + size + ".", size == 4);
+
+    }
+
+    private String buildPath(int index) {
+        return snsPath + "[" + index + "]";
+    }
+
+    private static void checkIndex(Node node, int expectedIndex) throws RepositoryException {
+        int index = node.getIndex();
+        if (index != expectedIndex) {
+            fail("Unexpected index " + index + ". Expected index was " + expectedIndex);
+        }
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SNSIndexTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SNSIndexTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/test/TestNodeWrite.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/test/TestNodeWrite.java?view=diff&rev=509446&r1=509445&r2=509446
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/test/TestNodeWrite.java (original)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/test/TestNodeWrite.java Mon Feb 19 23:57:01 2007
@@ -30,11 +30,12 @@
 import org.apache.jackrabbit.test.api.NodeRemoveMixinTest;
 import junit.framework.Test;
 import junit.framework.TestSuite;
+import junit.framework.TestCase;
 
 /**
  * <code>TestNodeWrite</code>...
  */
-public class TestNodeWrite {
+public class TestNodeWrite extends TestCase {
 
     private static Logger log = LoggerFactory.getLogger(TestNodeWrite.class);