jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r157755 - in incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api: NodeAddMixinTest.java NodeCanAddMixinTest.java NodeMixinUtil.java NodeRemoveMixinTest.java TestAll.java
Date Wed, 16 Mar 2005 14:04:19 GMT
Author: mreutegg
Date: Wed Mar 16 06:04:17 2005
New Revision: 157755

URL: http://svn.apache.org/viewcvs?view=rev&rev=157755
Log:
Test cases for Node.addMixin() Node.canAddMixin() and Node.removeMixin()

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeAddMixinTest.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeMixinUtil.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeAddMixinTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeAddMixinTest.java?view=auto&rev=157755
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeAddMixinTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeAddMixinTest.java
Wed Mar 16 06:04:17 2005
@@ -0,0 +1,209 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.version.VersionException;
+import javax.jcr.lock.LockException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Node;
+import javax.jcr.Value;
+import javax.jcr.Repository;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+
+/**
+ * <code>NodeAddMixinTest</code> contains the test cases for the method
+ * <code>Node.AddMixin(String)</code>.
+ *
+ * @test
+ * @sources NodeAddMixinTest.java
+ * @executeClass org.apache.jackrabbit.test.api.NodeAddMixinTest
+ * @keywords level2
+ */
+public class NodeAddMixinTest extends AbstractJCRTest {
+
+    /**
+     * Tests if <code>Node.addMixin(String mixinName)</code> adds the requested
+     * mixin and stores it in property <code>jcr:mixinTypes</code>
+     */
+    public void testAddSuccessfully()
+            throws NotExecutableException, RepositoryException {
+
+        Session session = testRootNode.getSession();
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        node.addMixin(mixinName);
+
+        // test if mixin is written to property jcr:mixinTypes immediately
+        Value mixinValues[] = node.getProperty(jcrMixinTypes).getValues();
+        if (mixinValues.length != 1) {
+            fail("Mixin node must be added to property " +
+                    jcrMixinTypes + " immediately.");
+        }
+        assertEquals("Mixin was not properly assigned to property " + jcrMixinTypes + ":
",
+                mixinName,
+                mixinValues[0].getString());
+
+
+        // it is implementation-specific if a added mixin is available
+        // before or after save therefore save before further tests
+        testRootNode.save();
+
+        // test if added mixin is available by node.getMixinNodeTypes()
+        NodeType mixins[] = node.getMixinNodeTypes();
+        if (mixins.length != 1) {
+            fail("Mixin node not added.");
+        }
+        assertEquals("Mixin was not properly assigned: ",
+                mixinName,
+                mixins[0].getName());
+
+    }
+
+    /**
+     * Tests if <code>Node.addMixin(String mixinName)</code> throws a
+     * <code>NoSuchNodeTypeException</code> if <code>mixinName</code>
is not the
+     * name of an existing mixin node type
+     */
+    public void testAddNonExisting() throws RepositoryException {
+        Session session = testRootNode.getSession();
+        String nonExistingMixinName = NodeMixinUtil.getNonExistingMixinName(session);
+
+        Node node = testRootNode.addNode(nodeName1);
+
+        try {
+            node.addMixin(nonExistingMixinName);
+            fail("Node.addMixin(String mixinName) must throw a " +
+                    "NoSuchNodeTypeException if mixinName is an unknown mixin type");
+        } catch (NoSuchNodeTypeException e) {
+            // success
+        }
+    }
+
+
+    /**
+     * Tests if <code>Node.addMixin(String mixinName)</code> throws a
+     * <code>LockException</code> if <code>Node</code> is locked
+     * <p/>
+     * The test creates a node <code>nodeName1</code> of type
+     * <code>testNodeType</code> under <code>testRoot</code> and
locks the node
+     * with the superuser session. Then the test tries to add a mixin to
+     * <code>nodeName1</code>  with the readWrite <code>Session</code>.
+     */
+    public void testLocked()
+            throws NotExecutableException, RepositoryException {
+
+        Session session = testRootNode.getSession();
+
+        if (session.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) ==
null) {
+            throw new NotExecutableException("Locking is not supported.");
+        }
+
+        // create a node that is lockable
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        // or try to make it lockable if it is not
+        if (!node.isNodeType(mixLockable)) {
+            if (node.canAddMixin(mixLockable)) {
+                node.addMixin(mixLockable);
+            } else {
+                throw new NotExecutableException("Node " + nodeName1 + " is not lockable
and does not " +
+                        "allow to add mix:lockable");
+            }
+        }
+        testRootNode.save();
+
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        // remove first slash of path to get rel path to root
+        String pathRelToRoot = node.getPath().substring(1);
+
+        // access node through another session to lock it
+        Session session2 = helper.getSuperuserSession();
+        Node node2 = session2.getRootNode().getNode(pathRelToRoot);
+        node2.lock(true, true);
+
+        try {
+            node.addMixin(mixinName);
+            fail("Node.addMixin(String mixinName) must throw a LockException " +
+                    "if the node is locked.");
+        } catch (LockException e) {
+            // success
+        }
+
+        // unlock to remove node at tearDown()
+        node2.unlock();
+    }
+
+    /**
+     * Tests if <code>Node.addMixin(String mixinName)</code> throws a
+     * <code>VersionException</code> if <code>Node</code> is checked-in.
+     * <p/>
+     * The test creates a node <code>nodeName1</code> of type
+     * <code>testNodeType</code> under <code>testRoot</code> and
checks it in.
+     * Then the test tries to add a mixin to <code>nodeName1</code>.
+     */
+    public void testCheckedIn()
+            throws NotExecutableException, RepositoryException {
+
+        Session session = testRootNode.getSession();
+
+        if (session.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) ==
null) {
+            throw new NotExecutableException("Versioning is not supported.");
+        }
+
+        // create a node that is versionable
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        // or try to make it versionable if it is not
+        if (!node.isNodeType(mixVersionable)) {
+            if (node.canAddMixin(mixVersionable)) {
+                node.addMixin(mixVersionable);
+            } else {
+                throw new NotExecutableException("Node " + nodeName1 + " is not versionable
and does not " +
+                        "allow to add mix:versionable");
+            }
+        }
+        testRootNode.save();
+
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        node.checkin();
+
+        try {
+            node.addMixin(mixinName);
+            fail("Node.addMixin(String mixinName) must throw a VersionException " +
+                    "if the node is checked-in.");
+        } catch (VersionException e) {
+            // success
+        }
+    }
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeAddMixinTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java?view=auto&rev=157755
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java
Wed Mar 16 06:04:17 2005
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+
+/**
+ * <code>NodeCanAddMixinTest</code> contains the test cases for the method
+ * <code>Node.canAddMixin(String)</code>.
+ *
+ * @test
+ * @sources NodeCanAddMixinTest.java
+ * @executeClass org.apache.jackrabbit.test.api.NodeCanAddMixinTest
+ * @keywords level2
+ */
+public class NodeCanAddMixinTest extends AbstractJCRTest {
+
+    /**
+     * Tests if <code>Node.canAddMixin(String mixinName)</code> throws a
+     * <code>LockException</code> if <code>Node</code> is locked
+     */
+    public void testLocked()
+            throws ConstraintViolationException, NotExecutableException, RepositoryException
{
+
+        Session session = testRootNode.getSession();
+
+        if (session.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) ==
null) {
+            throw new NotExecutableException("Locking is not supported.");
+        }
+
+        // create a node that is lockable
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        // or try to make it lockable if it is not
+        if (!node.isNodeType(mixLockable)) {
+            if (node.canAddMixin(mixLockable)) {
+                node.addMixin(mixLockable);
+            } else {
+                throw new NotExecutableException("Node " + nodeName1 + " is not lockable
and does not " +
+                        "allow to add mix:lockable");
+            }
+        }
+        testRootNode.save();
+
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        // remove first slash of path to get rel path to root
+        String pathRelToRoot = node.getPath().substring(1);
+
+        // access node through another session to lock it
+        Session session2 = helper.getSuperuserSession();
+        Node node2 = session2.getRootNode().getNode(pathRelToRoot);
+        node2.lock(true, true);
+
+        assertFalse("Node.canAddMixin(String mixinName) must return false " +
+                "if the node is locked.",
+                node.canAddMixin(mixinName));
+
+        node2.unlock();
+        session2.logout();
+    }
+
+    /**
+     * Tests if <code>Node.canAddMixin(String mixinName)</code> throws a
+     * <code>VersionException</code> if <code>Node</code> is checked-in
+     */
+    public void testCheckedIn()
+            throws ConstraintViolationException, NotExecutableException, RepositoryException
{
+
+        Session session = testRootNode.getSession();
+
+        if (session.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) ==
null) {
+            throw new NotExecutableException("Versioning is not supported.");
+        }
+
+        // create a node that is versionable
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        // or try to make it versionable if it is not
+        if (!node.isNodeType(mixVersionable)) {
+            if (node.canAddMixin(mixVersionable)) {
+                node.addMixin(mixVersionable);
+            } else {
+                throw new NotExecutableException("Node " + nodeName1 + " is not versionable
and does not " +
+                        "allow to add mix:versionable");
+            }
+        }
+        testRootNode.save();
+
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        node.checkin();
+
+        assertFalse("Node.canAddMixin(String mixinName) must return false " +
+                "if the node is checked-in.",
+                node.canAddMixin(mixinName));
+    }
+
+    /**
+     * Tests if <code>Node.canAddMixin(String mixinName)</code> throws a
+     * <code>NoSuchNodeTypeException</code> if <code>mixinName</code>
is not the
+     * name of an existing mixin node type
+     */
+    public void testNonExisting() throws RepositoryException {
+        Session session = testRootNode.getSession();
+        String nonExistingMixinName = NodeMixinUtil.getNonExistingMixinName(session);
+
+        Node node = testRootNode.addNode(nodeName1);
+
+        try {
+            node.canAddMixin(nonExistingMixinName);
+            fail("Node.canAddMixin(String mixinName) must throw a " +
+                    "NoSuchNodeTypeException if mixinName is an unknown mixin type");
+        } catch (NoSuchNodeTypeException e) {
+            // success
+        }
+    }
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeMixinUtil.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeMixinUtil.java?view=auto&rev=157755
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeMixinUtil.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeMixinUtil.java
Wed Mar 16 06:04:17 2005
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.test.api;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Node;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeTypeIterator;
+
+/**
+ * Utility class to locate mixins in the NodeTyeManager.
+ */
+public class NodeMixinUtil {
+
+    /**
+     * @return the name of a mixin node type that can be added by the requested
+     *         <code>node</code>
+     */
+    public static String getAddableMixinName(Session session, Node node)
+            throws RepositoryException {
+
+        NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator mixins = manager.getMixinNodeTypes();
+
+        while (mixins.hasNext()) {
+            String name = mixins.nextNodeType().getName();
+            if (node.canAddMixin(name)) {
+                return name;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * @return a string that is not the name of a mixin type
+     */
+    public static String getNonExistingMixinName(Session session)
+            throws RepositoryException {
+
+        NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator mixins = manager.getMixinNodeTypes();
+        StringBuffer s = new StringBuffer("X");
+        while (mixins.hasNext()) {
+            s.append(mixins.nextNodeType().getName());
+        }
+        return s.toString().replaceAll(":", "");
+    }
+
+
+}

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeMixinUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java?view=auto&rev=157755
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java
Wed Mar 16 06:04:17 2005
@@ -0,0 +1,237 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.version.VersionException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Repository;
+
+/**
+ * <code>NodeRemoveMixinTest</code> contains the test cases for the method
+ * <code>Node.removeMixin(String)</code>.
+ *
+ * @test
+ * @sources NodeRemoveMixinTest.java
+ * @executeClass org.apache.jackrabbit.test.api.NodeRemoveMixinTest
+ * @keywords level2
+ */
+public class NodeRemoveMixinTest extends AbstractJCRTest {
+
+    /**
+     * Tests if <code>Node.removeMixin(String mixinName)</code> removes the
+     * requested mixin properly
+     */
+    public void testRemoveSuccessfully()
+            throws NotExecutableException, RepositoryException {
+
+        Session session = testRootNode.getSession();
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        node.addMixin(mixinName);
+        testRootNode.save();
+
+        try {
+            node.removeMixin(mixinName);
+        } catch (ConstraintViolationException e) {
+            /**
+             * In some implementations it may not be possible to remove mixin node
+             * types (short of removing the node itself). In these cases this
+             * method will throw a ConstraintViolationException.
+             */
+            throw new NotExecutableException("Repository does not support remove of mixin.");
+        }
+
+        // test if mixin is removed from property jcr:mixinTypes immediately
+        // it is implementation-specific, if the property is removed completely
+        // or set to an empty array when removing the last mixin type
+        try {
+            Property mixinProps = node.getProperty(jcrMixinTypes);
+
+            // getValues() returns an empty array
+            assertTrue("Node.removeMixin(String mixinName) did not remove mixin from " +
+                    "property " + jcrMixinTypes + ".",
+                    mixinProps.getValues().length == 0);
+        } catch (PathNotFoundException e) {
+            // success (property jcr:mixinTypes has been completely removed)
+        }
+
+        // it is implementation-specific if a removed mixin isn't available
+        // before or after save therefore save before further tests
+        testRootNode.save();
+
+        // test if removed mixin isn't available anymore by node.getMixinNodeTypes()
+        assertTrue("removeMixin(String mixinName) did not remove mixin.",
+                node.getMixinNodeTypes().length == 0);
+    }
+
+    /**
+     * Tests if <code>Node.removeMixin(String mixinName)</code> throws a
+     * NoSuchNodeTypeException <code>Node</code> does not have assigned the
+     * requested mixin
+     */
+    public void testNotAssigned()
+            throws NotExecutableException, RepositoryException {
+
+        Session session = testRootNode.getSession();
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        node.addMixin(mixinName);
+        testRootNode.save();
+
+        String notAssignedMixin = NodeMixinUtil.getAddableMixinName(session, node);
+        if (notAssignedMixin == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        try {
+            node.removeMixin(notAssignedMixin);
+            fail("Node.removeMixin(String mixinName) must throw a " +
+                    "NoSuchNodeTypeException if Node does not have the " +
+                    "specified mixin.");
+        } catch (NoSuchNodeTypeException e) {
+            // success
+        }
+    }
+
+    /**
+     * Tests if <code>Node.removeMixin(String mixinName)</code> throws a
+     * <code>LockException</code> if <code>Node</code> is locked.
+     * <p/>
+     * The test creates a node <code>nodeName1</code> of type
+     * <code>testNodeType</code> under <code>testRoot</code>, adds
a mixin and
+     * then locks the node with the superuser session. Then the test tries to
+     * remove the before added mixin readWrite <code>Session</code>.
+     */
+    public void testLocked()
+            throws ConstraintViolationException, NotExecutableException, RepositoryException
{
+
+        Session session = testRootNode.getSession();
+
+        if (session.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) ==
null) {
+            throw new NotExecutableException("Locking is not supported.");
+        }
+
+        // create a node that is lockable
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        // or try to make it lockable if it is not
+        if (!node.isNodeType(mixLockable)) {
+            if (node.canAddMixin(mixLockable)) {
+                node.addMixin(mixLockable);
+            } else {
+                throw new NotExecutableException("Node " + nodeName1 + " is not lockable
and does not " +
+                        "allow to add mix:lockable");
+            }
+        }
+        testRootNode.save();
+
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        node.addMixin(mixinName);
+        testRootNode.save();
+
+        // remove first slash of path to get rel path to root
+        String pathRelToRoot = node.getPath().substring(1);
+
+        // access node through another session to lock it
+        Session session2 = helper.getSuperuserSession();
+        Node node2 = session2.getRootNode().getNode(pathRelToRoot);
+        node2.lock(true, true);
+
+        try {
+            node.removeMixin(mixinName);
+            fail("Node.removeMixin(String mixinName) must throw a " +
+                    "LockException if the node is locked.");
+        } catch (LockException e) {
+            // success
+        }
+
+        // unlock to remove node at tearDown()
+        node2.unlock();
+        session2.logout();
+    }
+
+    /**
+     * Tests if <code>Node.removeMixin(String mixinName)</code> throws a
+     * <code>VersionException</code> if <code>Node</code> is checked-in
+     * <p/>
+     * The test creates a node <code>nodeName1</code> of type
+     * <code>testNodeType</code> under <code>testRoot</code>, adds
a mixin and
+     * then checks it in. Then the test tries to remove the added.
+     */
+    public void testCheckedIn()
+            throws ConstraintViolationException, NotExecutableException, RepositoryException
{
+
+        Session session = testRootNode.getSession();
+
+        if (session.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) ==
null) {
+            throw new NotExecutableException("Versioning is not supported.");
+        }
+
+        // create a node that is versionable
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        // or try to make it versionable if it is not
+        if (!node.isNodeType(mixVersionable)) {
+            if (node.canAddMixin(mixVersionable)) {
+                node.addMixin(mixVersionable);
+            } else {
+                throw new NotExecutableException("Node " + nodeName1 + " is not versionable
and does not " +
+                        "allow to add mix:versionable");
+            }
+        }
+        testRootNode.save();
+
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        node.addMixin(mixinName);
+        testRootNode.save();
+        node.checkin();
+
+        try {
+            node.removeMixin(mixinName);
+            fail("Node.removeMixin(String mixinName) must throw a " +
+                    "VersionException if the node is checked-in.");
+        } catch (VersionException e) {
+            // success
+        }
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java?view=diff&r1=157754&r2=157755
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java Wed Mar
16 06:04:17 2005
@@ -95,6 +95,10 @@
         suite.addTestSuite(PropertyItemIsModifiedTest.class);
         suite.addTestSuite(PropertyItemIsNewTest.class);
 
+        suite.addTestSuite(NodeAddMixinTest.class);
+        suite.addTestSuite(NodeCanAddMixinTest.class);
+        suite.addTestSuite(NodeRemoveMixinTest.class);
+
         return suite;
     }
 }



Mime
View raw message