jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r472823 - /jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/
Date Thu, 09 Nov 2006 09:13:48 GMT
Author: angela
Date: Thu Nov  9 01:13:48 2006
New Revision: 472823

URL: http://svn.apache.org/viewvc?view=rev&rev=472823
Log:
work in progress

- some tests for remove/move

Added:
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveReferenceableTest.java
  (with props)
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTest.java
  (with props)
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveItemTest.java
  (with props)
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNewNodeTest.java
  (with props)
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNodeTest.java
  (with props)
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemovePropertyTest.java
  (with props)
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveReferenceableNodeTest.java
  (with props)

Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveReferenceableTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveReferenceableTest.java?view=auto&rev=472823
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveReferenceableTest.java
(added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveReferenceableTest.java
Thu Nov  9 01:13:48 2006
@@ -0,0 +1,100 @@
+/*
+ * 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.NotExecutableException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+
+/**
+ * <code>MoveReferenceableTest</code>...
+ */
+public class MoveReferenceableTest extends MoveTest {
+
+    private static Logger log = LoggerFactory.getLogger(MoveReferenceableTest.class);
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        if (!moveNode.canAddMixin(mixReferenceable)) {
+            throw new NotExecutableException("Cannot add mix:referencable to node to be moved.");
+        }
+        // prepare move-node
+        moveNode.addMixin(mixReferenceable);
+        moveNode.save();
+    }
+
+    /**
+     * Test if a moved referenceable node still has the same uuid.
+     */
+    public void testMovedReferenceable() throws RepositoryException, NotExecutableException
{
+
+        String uuid = moveNode.getUUID();
+        //move the node
+        superuser.move(moveNode.getPath(), destinationPath);
+        assertEquals("After successful moving a referenceable node node, the uuid must not
have changed.", uuid, moveNode.getUUID());
+    }
+
+    /**
+     * Same as {@link #testMovedReferenceable()}, but calls save before
+     * executing the comparison.
+     */
+    public void testMovedReferenceable2() throws RepositoryException, NotExecutableException
{
+
+        String uuid = moveNode.getUUID();
+        //move the node
+        superuser.move(moveNode.getPath(), destinationPath);
+        superuser.save();
+        assertEquals("After successful moving a referenceable node node, the uuid must not
have changed.", uuid, moveNode.getUUID());
+    }
+
+    /**
+     * Test if a moved referenceable node returns the same item than the moved
+     * node.
+     */
+    public void testAccessMovedReferenceableByUUID() throws RepositoryException, NotExecutableException
{
+
+        String uuid = moveNode.getUUID();
+        //move the node
+        superuser.move(moveNode.getPath(), destinationPath);
+
+        Node n = superuser.getNodeByUUID(uuid);
+        assertTrue("After successful moving a referenceable node node, accessing the node
by uuid must return the same node.", n.isSame(moveNode));
+        // NOTE: implementation specific test
+        assertTrue("After successful moving a referenceable node node, accessing the node
by uuid be the identical node.", n == moveNode);
+    }
+
+    /**
+     * Same as {@link #testAccessMovedReferenceableByUUID()} but calls save()
+     * before accessing the node again.
+     */
+    public void testAccessMovedReferenceableByUUID2() throws RepositoryException, NotExecutableException
{
+
+        String uuid = moveNode.getUUID();
+        //move the node
+        superuser.move(moveNode.getPath(), destinationPath);
+        superuser.save();
+
+        Node n = superuser.getNodeByUUID(uuid);
+        assertTrue("After successful moving a referenceable node node, accessing the node
by uuid must return the same node.", n.isSame(moveNode));
+        // NOTE: implementation specific test
+        assertTrue("After successful moving a referenceable node node, accessing the node
by uuid be the identical node.", n == moveNode);
+    }
+}
\ No newline at end of file

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

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

Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTest.java?view=auto&rev=472823
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTest.java
(added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTest.java
Thu Nov  9 01:13:48 2006
@@ -0,0 +1,247 @@
+/*
+ * 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.test.NotExecutableException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Item;
+
+/**
+ * <code>MoveTest</code>...
+ */
+public class MoveTest extends AbstractJCRTest {
+
+    private static Logger log = LoggerFactory.getLogger(MoveTest.class);
+
+    protected Node srcParentNode;
+    protected Node destParentNode;
+    protected Node moveNode;
+
+    protected String destinationPath;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // create parent node
+        srcParentNode = testRootNode.addNode(nodeName1, testNodeType);
+        // create node to be moved
+        moveNode = srcParentNode.addNode(nodeName2, testNodeType);
+        // create a node that will serve as new parent
+        destParentNode = testRootNode.addNode(nodeName3, testNodeType);
+        // save the new nodes
+        testRootNode.save();
+
+        destinationPath = destParentNode.getPath() + "/" + nodeName2;
+    }
+
+    public void testMoveRoot() throws RepositoryException {
+        Node root = superuser.getRootNode();
+        try {
+            superuser.move(root.getPath(), destinationPath);
+            fail("Moving the root node must fail with RepositoryException.");
+        } catch (RepositoryException e) {
+            // OK
+        }
+    }
+
+    public void testMoveBelowDescendant() throws RepositoryException {
+        try {
+            superuser.move(srcParentNode.getPath(), moveNode.getPath() + "/" + nodeName2);
+            fail("Moving the ancestor node below descendant must fail with RepositoryException.");
+        } catch (RepositoryException e) {
+            // OK
+        }
+    }
+
+    public void testMoveDestinationWithIndex() throws RepositoryException {
+        try {
+            superuser.move(moveNode.getPath(), destinationPath + "[1]");
+            fail("Moving to destination with index must fail with RepositoryException.");
+        } catch (RepositoryException e) {
+            // OK
+        }
+    }
+
+    /**
+     * Test if a moved node returns the specified destination path and by the
+     * way test, if the moved node is still valid.
+     */
+    public void testMovedNodeGetPath() throws RepositoryException, NotExecutableException
{
+        String oldPath = moveNode.getPath();
+
+        if (destParentNode.hasNode(nodeName2)) {
+            throw new NotExecutableException("Move destination already contains a child node
with name " + nodeName2);
+        }
+        //move the node
+        superuser.move(oldPath,destinationPath);
+        assertEquals("After successful move the moved node must return the destination path.",
destinationPath, moveNode.getPath());
+    }
+
+    /**
+     * Same as {@link #testMovedNodeGetPath()}, but calls save prior to the
+     * test.
+     */
+    public void testMovedNodeGetPath2() throws RepositoryException, NotExecutableException
{
+        String oldPath = moveNode.getPath();
+
+        if (destParentNode.hasNode(nodeName2)) {
+            throw new NotExecutableException("Move destination already contains a child node
with name " + nodeName2);
+        }
+        //move the node
+        superuser.move(oldPath, destParentNode.getPath() + "/" + nodeName2);
+        superuser.save();
+        assertEquals("After successful move the moved node must return the destination path.",
destinationPath, moveNode.getPath());
+    }
+
+    /**
+     * Test if a moved node is not accessible by its old path any more
+     */
+    public void testAccessMovedNodeByOldPath() throws RepositoryException, NotExecutableException
{
+        NodeIterator it = srcParentNode.getNodes(moveNode.getName());
+        int cnt = 0;
+        while (it.hasNext()) {
+            it.nextNode();
+            cnt++;
+        }
+        if (cnt > 1) {
+            throw new NotExecutableException("Move source parent has multiple child nodes
with name " + moveNode.getName());
+        }
+
+        String oldPath = moveNode.getPath();
+
+        //move the node
+        superuser.move(oldPath, destinationPath);
+        try {
+            superuser.getItem(oldPath);
+            fail("A moved node must not be accessible by its old path any more.");
+        } catch (PathNotFoundException e) {
+            // ok.
+        }
+    }
+
+    /**
+     * Same as {@link #testAccessMovedNodeByOldPath()} but calls save() prior to
+     * the test.
+     */
+    public void testAccessMovedNodeByOldPath2() throws RepositoryException, NotExecutableException
{
+        NodeIterator it = srcParentNode.getNodes(moveNode.getName());
+        int cnt = 0;
+        while (it.hasNext()) {
+            it.nextNode();
+            cnt++;
+        }
+        if (cnt > 1) {
+           throw new NotExecutableException("Move source parent has multiple child nodes
with name " + moveNode.getName());
+        }
+
+        String oldPath = moveNode.getPath();
+
+        //move the node
+        superuser.move(oldPath, destinationPath);
+        superuser.save();
+        try {
+            superuser.getItem(oldPath);
+            fail("A moved node must not be accessible by its old path any more.");
+        } catch (PathNotFoundException e) {
+            // ok.
+        }
+    }
+
+    /**
+     * Test if the accessing the moved node from the session returns the same
+     * Node object, than the Node which was moved before.
+     *
+     * @throws RepositoryException
+     * @throws NotExecutableException
+     */
+    public void testMovedNodeIsSame() throws RepositoryException, NotExecutableException
{
+        if (destParentNode.hasNode(nodeName2)) {
+            throw new NotExecutableException(destParentNode + " already has child node "
+ ". Test cannot be preformed if SNS is present.");
+        }
+
+        String oldPath = moveNode.getPath();
+        String newPath = destParentNode.getPath() + "/" + nodeName2;
+
+        //move the node
+        superuser.move(oldPath, destinationPath);
+        Item movedItem = superuser.getItem(newPath);
+        assertTrue("Moved Node must be the same after the move.", movedItem.isSame(moveNode));
+        // NOTE: implementation specific test
+        assertTrue("After successful moving a referenceable node node, accessing the node
by uuid be the identical node.", movedItem == moveNode);
+    }
+
+    /**
+     * Same as {@link #testMovedNodeIsSame()}, but calls save() before executing
+     * the comparison.
+     *
+     * @throws RepositoryException
+     * @throws NotExecutableException
+     */
+    public void testMovedNodeIsSame2() throws RepositoryException, NotExecutableException
{
+        if (destParentNode.hasNode(nodeName2)) {
+            throw new NotExecutableException(destParentNode + " already has child node "
+ ". Test cannot be preformed if SNS is present.");
+        }
+
+        String oldPath = moveNode.getPath();
+
+        //move the node
+        superuser.move(oldPath, destinationPath);
+        superuser.save();
+
+        Item movedItem = superuser.getItem(destinationPath);
+        assertTrue("Moved Node must be the same after the move.", movedItem.isSame(moveNode));
+        // NOTE: implementation specific test
+        assertTrue("After successful moving a referenceable node node, accessing the node
by uuid be the identical node.", movedItem == moveNode);
+    }
+
+    /**
+     * Test if after the move, <code>Node.getParent()</code> returns the
+     * destination parent.
+     *
+     * @throws RepositoryException
+     */
+    public void testMovedNodeParent() throws RepositoryException {
+        //move the node
+        superuser.move(moveNode.getPath(), destinationPath);
+        assertTrue("Parent of moved node must be the destination parent node.", moveNode.getParent().isSame(destParentNode));
+        // NOTE: implementation specific test
+        assertTrue("After successful moving a referenceable node node, accessing the node
by uuid be the identical node.", moveNode.getParent() == destParentNode);
+    }
+
+    /**
+     * Same as {@link #testMovedNodeParent()}, but calls save before executing
+     * the comparison.
+     *
+     * @throws RepositoryException
+     */
+    public void testMovedNodeParent2() throws RepositoryException {
+        //move the node
+        superuser.move(moveNode.getPath(), destinationPath);
+        superuser.save();
+
+        assertTrue("Parent of moved node must be the destination parent node.", moveNode.getParent().isSame(destParentNode));
+        // NOTE: implementation specific test
+        assertTrue("After successful moving a referenceable node node, accessing the node
by uuid be the identical node.", moveNode.getParent() == destParentNode);
+    }
+}
\ No newline at end of file

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

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

Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveItemTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveItemTest.java?view=auto&rev=472823
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveItemTest.java
(added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveItemTest.java
Thu Nov  9 01:13:48 2006
@@ -0,0 +1,175 @@
+/*
+ * 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.test.NotExecutableException;
+
+import javax.jcr.Item;
+import javax.jcr.ItemExistsException;
+import javax.jcr.RepositoryException;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.version.VersionException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.lock.LockException;
+
+/**
+ * <code>RemoveItemTest</code>...
+ */
+public abstract class RemoveItemTest extends AbstractJCRTest {
+
+    private static Logger log = LoggerFactory.getLogger(RemoveItemTest.class);
+
+    protected Item removeItem;
+    protected String removePath;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        removeItem = createRemoveItem();
+        removePath = removeItem.getPath();
+    }
+
+    protected abstract Item createRemoveItem() throws NotExecutableException, RepositoryException,
LockException, ConstraintViolationException, ItemExistsException, NoSuchNodeTypeException,
VersionException;
+
+    /**
+     * Transiently removes a persisted item using {@link javax.jcr.Item#remove()}
+     * and test, whether that item cannot be access from the session any more.
+     */
+    public void testRemoveItem() throws RepositoryException {
+        removeItem.remove();
+
+        // check if the node has been properly removed
+        try {
+            superuser.getItem(removePath);
+            fail("A transiently removed item should no longer be accessible from the session.");
+        } catch (PathNotFoundException e) {
+            // ok , works as expected
+        }
+    }
+
+    /**
+     * Same as {@link #testRemoveItem()}, but calls save() (persisting the removal)
+     * before executing the test.
+     */
+    public void testRemoveItem2() throws RepositoryException, NotExecutableException {
+        removeItem.remove();
+        testRootNode.save();
+        try {
+            superuser.getItem(removePath);
+            fail("Persistently removed node should no longer be accessible from the session.");
+        } catch (PathNotFoundException e) {
+            // ok , works as expected
+        }
+    }
+    /**
+     * Test if a node, that has been transiently removed is not 'New'.
+     */
+    public void testNotNewRemovedItem() throws RepositoryException {
+        removeItem.remove();
+        assertFalse("Transiently removed node must not be 'new'.", removeItem.isNew());
+    }
+
+    /**
+     * Same as {@link #testNotNewRemovedItem()} but calls save() before
+     * executing the test.
+     */
+    public void testNotNewRemovedItem2() throws RepositoryException {
+        removeItem.remove();
+        testRootNode.save();
+        assertFalse("Removed node must not be 'new'.", removeItem.isNew());
+    }
+
+    /**
+     * Test if a node, that has be transiently remove is not 'Modified'.
+     */
+    public void testNotModifiedRemovedItem() throws RepositoryException {
+        removeItem.remove();
+        assertFalse("Transiently removed node must not be 'modified'.", removeItem.isModified());
+    }
+
+    /**
+     * Same as {@link #testNotModifiedRemovedItem()} but calls save() before
+     * executing the test.
+     */
+    public void testNotModifiedRemovedItem2() throws RepositoryException {
+        removeItem.remove();
+        testRootNode.save();
+        assertFalse("Removed node must not be 'modified'.", removeItem.isModified());
+    }
+
+    /**
+     * A removed item must throw InvalidItemStateException upon any call to an
+     * item specific method.
+     */
+    public void testInvalidStateRemovedItem() throws RepositoryException {
+        removeItem.remove();
+        try {
+            removeItem.getName();
+            fail("Calling getName() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            removeItem.getPath();
+            fail("Calling getPath() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            removeItem.save();
+            fail("Calling save() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+    }
+
+    /**
+     * Same as {@link #testInvalidStateRemovedItem()} but calls save() before
+     * executing the test.
+     */
+    public void testInvalidStateRemovedItem2() throws RepositoryException {
+        removeItem.remove();
+        testRootNode.save();
+        try {
+            removeItem.getName();
+            fail("Calling getName() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            removeItem.getPath();
+            fail("Calling getPath() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            removeItem.save();
+            fail("Calling save() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+    }
+}
\ No newline at end of file

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

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

Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNewNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNewNodeTest.java?view=auto&rev=472823
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNewNodeTest.java
(added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNewNodeTest.java
Thu Nov  9 01:13:48 2006
@@ -0,0 +1,115 @@
+/*
+ * $Id$
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.jackrabbit.jcr2spi;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.InvalidItemStateException;
+
+/**
+ * <code>RemoveNodeTest</code>...
+ */
+public class RemoveNewNodeTest extends AbstractJCRTest {
+
+    private static Logger log = LoggerFactory.getLogger(RemoveNewNodeTest.class);
+
+    protected Node removeNode;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        if (testRootNode.hasNode(nodeName1)) {
+            throw new NotExecutableException("Parent node must not yet contain a child node
'" + nodeName1 + "'.");
+        }
+        removeNode = testRootNode.addNode(nodeName1, testNodeType);
+    }
+
+    /**
+     * Removes a transient node using {@link javax.jcr.Node#remove()}.
+     */
+    public void testRemoveNode() throws RepositoryException {
+        // create the transient node
+        removeNode.remove();
+        try {
+            testRootNode.getNode(nodeName1);
+            fail("Removed transient node should no longer be accessible from parent node.");
+        } catch (PathNotFoundException e) {
+            // ok , works as expected
+        }
+    }
+
+    /**
+     * Test if a node, that has be transiently added and removed is not 'New'.
+     */
+    public void testNotNewRemovedNode() throws RepositoryException {
+        removeNode.remove();
+        assertFalse("Removed transient node must not be 'new'.", removeNode.isNew());
+    }
+
+    /**
+     * Test if a node, that has be transiently added and removed is not 'Modified'.
+     */
+    public void testNotModifiedRemovedNode() throws RepositoryException {
+        removeNode.remove();
+        assertFalse("Removed transient node must not be 'modified'.", removeNode.isModified());
+    }
+
+    /**
+     * A removed transient node must throw InvalidItemStateException upon any call to a
+     * node specific method.
+     */
+    public void testInvalidStateRemovedNode() throws RepositoryException {
+        removeNode.remove();
+        try {
+            removeNode.getName();
+            fail("Calling getName() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            removeNode.getPath();
+            fail("Calling getPath() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            removeNode.getPrimaryNodeType();
+            fail("Calling getPrimaryNodeType() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            removeNode.getProperty(jcrPrimaryType);
+            fail("Calling getProperty(String) on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            removeNode.save();
+            fail("Calling save() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+    }
+}

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

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

Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNodeTest.java?view=auto&rev=472823
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNodeTest.java
(added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNodeTest.java
Thu Nov  9 01:13:48 2006
@@ -0,0 +1,121 @@
+/*
+ * 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.NotExecutableException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.Item;
+
+/**
+ * <code>RemoveNodeTest</code>...
+ */
+public class RemoveNodeTest extends RemoveItemTest {
+
+    private static Logger log = LoggerFactory.getLogger(RemoveNodeTest.class);
+
+    protected Item createRemoveItem() throws NotExecutableException, RepositoryException
{
+        if (testRootNode.hasNode(nodeName1)) {
+            throw new NotExecutableException("Parent node must not yet contain a child node
'" + nodeName1 + "'.");
+        }
+        Node removeNode = testRootNode.addNode(nodeName1, testNodeType);
+        // make sure the new node is persisted.
+        testRootNode.save();
+
+        return removeNode;
+    }
+
+    /**
+     * Transiently removes a persisted node using {@link javax.jcr.Node#remove()}
+     * and test, whether that node cannot be access from its parent.
+     */
+    public void testRemoveNode() throws RepositoryException {
+        removeItem.remove();
+
+        // check if the node has been properly removed
+        try {
+            testRootNode.getNode(nodeName1);
+            fail("Transiently removed node should no longer be accessible from parent node.");
+        } catch (PathNotFoundException e) {
+            // ok , works as expected
+        }
+    }
+
+    /**
+     * Same as {@link #testRemoveNode()}, but calls save() (persisting the removal)
+     * before executing the test.
+     */
+    public void testRemoveNode2() throws RepositoryException, NotExecutableException {
+        removeItem.remove();
+        testRootNode.save();
+        try {
+            testRootNode.getNode(nodeName1);
+            fail("Persistently removed node should no longer be accessible from parent node.");
+        } catch (PathNotFoundException e) {
+            // ok , works as expected
+        }
+    }
+
+    /**
+     * A removed node must throw InvalidItemStateException upon any call to a
+     * node specific method.
+     */
+    public void testInvalidStateRemovedNode() throws RepositoryException {
+        removeItem.remove();
+        try {
+            ((Node)removeItem).getPrimaryNodeType();
+            fail("Calling getPrimaryNodeType() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            ((Node)removeItem).getProperty(jcrPrimaryType);
+            fail("Calling getProperty(String) on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+    }
+
+    /**
+     * Same as {@link #testInvalidStateRemovedNode()} but calls save() before
+     * executing the test.
+     */
+    public void testInvalidStateRemovedNode2() throws RepositoryException {
+        removeItem.remove();
+        testRootNode.save();
+
+        try {
+            ((Node)removeItem).getPrimaryNodeType();
+            fail("Calling getPrimaryNodeType() on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            ((Node)removeItem).getProperty(jcrPrimaryType);
+            fail("Calling getProperty(String) on a removed node must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+    }
+}
\ No newline at end of file

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

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

Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemovePropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemovePropertyTest.java?view=auto&rev=472823
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemovePropertyTest.java
(added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemovePropertyTest.java
Thu Nov  9 01:13:48 2006
@@ -0,0 +1,126 @@
+/*
+ * $Id$
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.jackrabbit.jcr2spi;
+
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.Property;
+import javax.jcr.Item;
+import javax.jcr.ItemExistsException;
+import javax.jcr.version.VersionException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.lock.LockException;
+
+/**
+ * <code>RemoveNodeTest</code>...
+ */
+public class RemovePropertyTest extends RemoveItemTest {
+
+    private static Logger log = LoggerFactory.getLogger(RemovePropertyTest.class);
+
+    protected Item createRemoveItem() throws NotExecutableException, RepositoryException,
LockException, ConstraintViolationException, ItemExistsException, NoSuchNodeTypeException,
VersionException {
+        Property removeProperty;
+        if (testRootNode.hasProperty(propertyName1)) {
+            removeProperty = testRootNode.getProperty(propertyName1);
+            if (removeProperty.getDefinition().isProtected() || removeProperty.getDefinition().isMandatory())
{
+                throw new NotExecutableException("Property to be remove must be mandatory
nor protected '" + propertyName1 + "'.");
+            }
+        } else {
+            removeProperty = testRootNode.setProperty(propertyName1, "anyString");
+        }
+        // make sure the new node is persisted.
+        testRootNode.save();
+        return removeProperty;
+    }
+
+    /**
+     * Transiently removes a persisted property using {@link Property#remove()}
+     * and test, whether that property cannot be access from its parent.
+     */
+    public void testRemoveProperty() throws RepositoryException {
+        removeItem.remove();
+        // check if the property has been properly removed
+        try {
+            testRootNode.getProperty(propertyName1);
+            fail("Transiently removed property should no longer be accessible from parent
node.");
+        } catch (PathNotFoundException e) {
+            // ok , works as expected
+        }
+    }
+
+    /**
+     * Same as {@link #testRemoveProperty()}, but calls save() (persisting the removal)
+     * before executing the test.
+     */
+    public void testRemoveProperty2() throws RepositoryException, NotExecutableException
{
+        removeItem.remove();
+        testRootNode.save();
+        try {
+            testRootNode.getProperty(propertyName1);
+            fail("Permanently removed property should no longer be accessible from parent
node.");
+        } catch (PathNotFoundException e) {
+            // ok , works as expected
+        }
+    }
+
+    /**
+     * A removed property must throw InvalidItemStateException upon any call to a
+     * property specific method.
+     */
+    public void testInvalidStateRemovedProperty() throws RepositoryException {
+        removeItem.remove();
+
+        try {
+            ((Property)removeItem).getType();
+            fail("Calling getType() on a removed property must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            ((Property)removeItem).getValue();
+            fail("Calling getValue() on a removed property must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+    }
+
+    /**
+     * Same as {@link #testInvalidStateRemovedProperty()} but calls save() before
+     * executing the test.
+     */
+    public void testInvalidStateRemovedProperty2() throws RepositoryException {
+        removeItem.remove();
+        testRootNode.save();
+                try {
+            ((Property)removeItem).getType();
+            fail("Calling getType() on a removed property must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+
+        try {
+            ((Property)removeItem).getValue();
+            fail("Calling getValue() on a removed property must throw InvalidItemStateException.");
+        } catch (InvalidItemStateException e) {
+            //ok
+        }
+    }
+}

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

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

Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveReferenceableNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveReferenceableNodeTest.java?view=auto&rev=472823
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveReferenceableNodeTest.java
(added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveReferenceableNodeTest.java
Thu Nov  9 01:13:48 2006
@@ -0,0 +1,79 @@
+/*
+ * $Id$
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.jackrabbit.jcr2spi;
+
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Item;
+import javax.jcr.Node;
+
+/**
+ * <code>RemoveNodeTest</code>...
+ */
+public class RemoveReferenceableNodeTest extends RemoveNodeTest {
+
+    private static Logger log = LoggerFactory.getLogger(RemoveReferenceableNodeTest.class);
+
+    private String uuid;
+
+    protected Item createRemoveItem() throws NotExecutableException, RepositoryException
{
+        Node removeItem = (Node) super.createRemoveItem();
+        // assert removeNode is referenceable
+        if (!removeItem.isNodeType(mixReferenceable)) {
+            if (!removeItem.canAddMixin(mixReferenceable)) {
+                throw new NotExecutableException("Cannot make remove-node '" + nodeName1
+ "' mix:referenceable.");
+            }
+            removeItem.addMixin(mixReferenceable);
+        }
+
+        // make sure the new node is persisted.
+        testRootNode.save();
+        uuid = removeItem.getUUID();
+        return removeItem;
+    }
+
+    /**
+     * Transiently removes a persisted node using {@link javax.jcr.Node#remove()}
+     * and test, whether that node cannot be access by the UUID any more.
+     */
+    public void testAccessByUUID() throws RepositoryException {
+        removeItem.remove();
+        // check if the node has been properly removed
+        try {
+            superuser.getNodeByUUID(uuid);
+            fail("Permanently removed node should no longer be accessible from parent node.");
+        } catch (ItemNotFoundException e) {
+            // ok , works as expected
+        }
+    }
+
+    /**
+     * Same as {@link #testRemoveNode()}, but calls save() before executing the
+     * test.
+     */
+    public void testAccessByUUID2() throws RepositoryException, NotExecutableException {
+        removeItem.remove();
+        testRootNode.save();
+        try {
+            superuser.getNodeByUUID(uuid);
+            fail("Transiently removed node should no longer be accessible from parent node.");
+        } catch (ItemNotFoundException e) {
+            // ok , works as expected
+        }
+    }
+}

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

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



Mime
View raw message