org.apache.jackrabbit.test.api
Class NodeTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.jackrabbit.test.JUnitTest
              extended by org.apache.jackrabbit.test.AbstractJCRTest
                  extended by org.apache.jackrabbit.test.api.NodeTest
All Implemented Interfaces:
junit.framework.Test

public class NodeTest
extends AbstractJCRTest

NodeTest contains all test cases for the javax.jcr.Node that are related to writing, modifing or deleting nodes (level 2 of the specification).


Field Summary
 
Fields inherited from class org.apache.jackrabbit.test.AbstractJCRTest
isReadOnly, jcrBaseVersion, jcrCopiedFrom, jcrCreated, jcrFrozenNode, jcrFrozenUuid, jcrIsCheckedOut, jcrlockIsDeep, jcrLockOwner, jcrMergeFailed, jcrMixinTypes, jcrPredecessors, jcrPrimaryType, jcrRootVersion, jcrSuccessors, jcrSystem, jcrUUID, jcrVersionHistory, mixLockable, mixReferenceable, mixShareable, mixSimpleVersionable, mixVersionable, nodeName1, nodeName2, nodeName3, nodeName4, NS_JCR_URI, NS_MIX_URI, NS_NT_URI, NS_SV_URI, ntBase, ntFrozenNode, ntQuery, ntUnstructured, ntVersion, ntVersionHistory, ntVersionLabels, propertyName1, propertyName2, superuser, testNodeType, testNodeTypeNoChildren, testPath, testRoot, testRootNode, vf, workspaceName
 
Fields inherited from class org.apache.jackrabbit.test.JUnitTest
log
 
Constructor Summary
NodeTest()
           
 
Method Summary
 void setUp()
          to be able to test the update(String) and getCorrespondingNodePath(String) methods we need an addtional workspace
 void tearDown()
          remove all nodes in second workspace and log out
 void testAddNodeConstraintViolationExceptionProperty()
          Tries to add a node using Node.addNode(String) as a child of a property.
 void testAddNodeConstraintViolationExceptionUndefinedNodeType()
          Tries to add a node using Node.addNode(String) where node type can not be determined by parent (nt:base is used as parent nodetype).
 void testAddNodeItemExistsException()
          Tries to create a node using Node.addNode(String, String) at a location where there is already a node with same name and the parent does not allow same name siblings.
 void testAddNodeParentSave()
          Creates a new node using Node.addNode(String) , saves using Item.save() on parent node.
 void testAddNodePathNotFoundException()
          Tries to add a node using Node.addNode(String) to a non existing destination node.
 void testAddNodeRepositoryExceptionRelPathIndex()
          Adds a new node using Node.addNode(String) with an index for the new name.
 void testAddNodeRepositoryExceptionSaveOnNewNode()
          Creates a new node using Node.addNode(String), then tries to call Item.save() on the newly node.
 void testAddNodeSessionSave()
          Creates a new node using Node.addNode(String) , saves using Session.save().
 void testGetCorrespondingNodePath()
          Creates a node with same path in both workspaces to check if Node.getCorrespondingNodePath(String) works properly.
 void testGetCorrespondingNodePathItemNotFoundException()
          Calls Node.getCorrespondingNodePath(String) on a node that has no corresponding node in second workspace
 void testGetCorrespondingNodePathNoSuchWorkspaceException()
          Calls Node.getCorrespondingNodePath(String ) with a non existing workspace.
 void testIsModified()
          Checks if Item.isModified() works correcty for unmodified and modified nodes.
 void testIsNew()
          Checks if Item.isNew() works correctly for new and existing, unmodified nodes.
 void testIsSameMustNotCompareStates()
          Tests if Item.isSame(Item otherItem) will return true when two Node objects representing the same actual repository item have been retrieved through two different sessions and one has been modified.
 void testMixinTypesProtected()
          Tests if jcr:mixinTypes is protected
 void testNodeIdentity()
          Tests object identity, meaning two nodes objects accuired through the same session must have the same properties and states.
 void testNodeSave()
          Creates a new node, saves it uses second session to verify if node has been added.
 void testPrimaryType()
          Tests if the primary node type is properly stored in jcr:primaryType
 void testPrimaryTypeProtected()
          Tests if jcr:primaryType is protected
 void testRefreshBooleanFalse()
          Checks if Item.refresh(boolean refresh) works properly with refresh set to false.
 void testRefreshBooleanTrue()
          Checks if Item.refresh(boolean refresh) works properly with refresh set to true.
 void testRefreshInvalidItemStateException()
          Tries to call Item.refresh(boolean) on a deleted node.
 void testRemoveInvalidItemStateException()
          Removes a node using Item.remove() with session 1, afterwards it tries the same with session 2.
 void testRemoveMandatoryNode()
          Creates a node with a mandatory child node using Node.addNode(String, String), saves on parent node then tries to delete the mandatory child node.
 void testRemoveNodeLockedItself()
          Tests if Node.remove() does not throw a LockException if Node is locked.
 void testRemoveNodeParentLocked()
          Tests if Node.remove() throws a LockException if the parent node of Node is locked.
 void testRemoveNodeParentSave()
          Removes a node using Item.remove(), then saves with parent's nodes Item.save() method.
 void testRemoveNodeSessionSave()
          Removes a node using Item.remove(), then saves using Session.save() method.
 void testSaveContstraintViolationException()
          Tries to create and save a node using Item.save() with an mandatory property that is not set on saving time.
 void testSaveInvalidStateException()
          Tries to save a node using Item.save() that was already deleted by an other session.
 void testSaveOnNewNodeRepositoryException()
          Tests if a RepositoryException is thrown when calling Node.save() on a newly added node
 void testUpdate()
          Checks if Node.update(String) works properly by creating the same node in two workspaces one with a child node the other with a property set.
 void testUpdateInvalidItemStateException()
          Tries calling Node.update(String) after node has changed in first workspace but not been saved yet.
 void testUpdateNoClone()
          Calls Node.update(String) for a node that only exists in current workspace.
 void testUpdateNoSuchWorkspaceException()
          Tries to use Node.update(String) with an invalid workspace.
 
Methods inherited from class org.apache.jackrabbit.test.AbstractJCRTest
checkSupportedOption, cleanUp, cleanUpTestRoot, createRandomString, ensureCanSetProperty, ensureCanSetProperty, ensureCanSetProperty, ensureKnowsNodeType, ensureMixinType, ensureMultipleWorkspacesSupported, getHelper, getJcrValue, getLocalName, getNonExistingWorkspaceName, getProperty, getProperty, getSize, isSupported, needsMixin, run
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NodeTest

public NodeTest()
Method Detail

setUp

public void setUp()
           throws Exception
to be able to test the update(String) and getCorrespondingNodePath(String) methods we need an addtional workspace

Overrides:
setUp in class AbstractJCRTest
Throws:
Exception

tearDown

public void tearDown()
              throws Exception
remove all nodes in second workspace and log out

Overrides:
tearDown in class AbstractJCRTest
Throws:
Exception

testGetCorrespondingNodePathNoSuchWorkspaceException

public void testGetCorrespondingNodePathNoSuchWorkspaceException()
                                                          throws RepositoryException
Calls Node.getCorrespondingNodePath(String ) with a non existing workspace.

This should throw an NoSuchWorkspaceException.

Throws:
RepositoryException

testGetCorrespondingNodePathItemNotFoundException

public void testGetCorrespondingNodePathItemNotFoundException()
                                                       throws RepositoryException,
                                                              NotExecutableException
Calls Node.getCorrespondingNodePath(String) on a node that has no corresponding node in second workspace

Throws:
RepositoryException
NotExecutableException

testGetCorrespondingNodePath

public void testGetCorrespondingNodePath()
                                  throws RepositoryException,
                                         NotExecutableException
Creates a node with same path in both workspaces to check if Node.getCorrespondingNodePath(String) works properly.

Throws:
RepositoryException
NotExecutableException

testUpdateInvalidItemStateException

public void testUpdateInvalidItemStateException()
                                         throws RepositoryException,
                                                NotExecutableException
Tries calling Node.update(String) after node has changed in first workspace but not been saved yet.

This should throw an InvalidItemStateException.

Prerequisites:

Throws:
RepositoryException
NotExecutableException

testUpdateNoSuchWorkspaceException

public void testUpdateNoSuchWorkspaceException()
                                        throws RepositoryException
Tries to use Node.update(String) with an invalid workspace.

This should throw an NoSuchWorkspaceException.

Throws:
RepositoryException

testUpdateNoClone

public void testUpdateNoClone()
                       throws RepositoryException
Calls Node.update(String) for a node that only exists in current workspace.

In that case nothing should happen.

Prerequisites:

Throws:
RepositoryException

testUpdate

public void testUpdate()
                throws RepositoryException,
                       NotExecutableException
Checks if Node.update(String) works properly by creating the same node in two workspaces one with a child node the other with a property set.

Calling update() on the node with properties, should remove the properties and add the child node.

Prerequisites:

Throws:
RepositoryException
NotExecutableException

testAddNodeConstraintViolationExceptionUndefinedNodeType

public void testAddNodeConstraintViolationExceptionUndefinedNodeType()
                                                              throws RepositoryException
Tries to add a node using Node.addNode(String) where node type can not be determined by parent (nt:base is used as parent nodetype).

This should throw a ConstraintViolationException.

Throws:
RepositoryException

testAddNodeConstraintViolationExceptionProperty

public void testAddNodeConstraintViolationExceptionProperty()
                                                     throws RepositoryException
Tries to add a node using Node.addNode(String) as a child of a property.

This should throw an ConstraintViolationException.

Prerequisites:

Throws:
RepositoryException

testAddNodeItemExistsException

public void testAddNodeItemExistsException()
                                    throws RepositoryException
Tries to create a node using Node.addNode(String, String) at a location where there is already a node with same name and the parent does not allow same name siblings.

This should throw an ItemExistsException.

Prerequisites:

Throws:
RepositoryException

testAddNodePathNotFoundException

public void testAddNodePathNotFoundException()
                                      throws RepositoryException
Tries to add a node using Node.addNode(String) to a non existing destination node.

This should throw an PathNotFoundException.

Throws:
RepositoryException

testAddNodeRepositoryExceptionRelPathIndex

public void testAddNodeRepositoryExceptionRelPathIndex()
                                                throws RepositoryException
Adds a new node using Node.addNode(String) with an index for the new name.

This should throw an RepositoryException.

Throws:
RepositoryException

testAddNodeRepositoryExceptionSaveOnNewNode

public void testAddNodeRepositoryExceptionSaveOnNewNode()
                                                 throws RepositoryException
Creates a new node using Node.addNode(String), then tries to call Item.save() on the newly node.

This should throw an RepositoryException.

Throws:
RepositoryException

testAddNodeParentSave

public void testAddNodeParentSave()
                           throws RepositoryException
Creates a new node using Node.addNode(String) , saves using Item.save() on parent node. Uses a second session to verify if the node has been safed.

Throws:
RepositoryException

testAddNodeSessionSave

public void testAddNodeSessionSave()
                            throws RepositoryException
Creates a new node using Node.addNode(String) , saves using Session.save(). Uses a second session to verify if the node has been safed.

Throws:
RepositoryException

testRemoveMandatoryNode

public void testRemoveMandatoryNode()
                             throws RepositoryException
Creates a node with a mandatory child node using Node.addNode(String, String), saves on parent node then tries to delete the mandatory child node.

This should throw a ConstraintViolationException.

Prerequisites:

  • javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodetype2 a node type that has a mandatory child node
  • javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodetype3 nodetype of the mandatory child node
  • javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodename3 name of the mandatory child node

Throws:
RepositoryException

testRemoveInvalidItemStateException

public void testRemoveInvalidItemStateException()
                                         throws RepositoryException
Removes a node using Item.remove() with session 1, afterwards it tries the same with session 2.

This should throw an InvalidItemStateException.

Throws:
RepositoryException

testRemoveNodeParentSave

public void testRemoveNodeParentSave()
                              throws RepositoryException
Removes a node using Item.remove(), then saves with parent's nodes Item.save() method.

Throws:
RepositoryException

testRemoveNodeSessionSave

public void testRemoveNodeSessionSave()
                               throws RepositoryException
Removes a node using Item.remove(), then saves using Session.save() method.

Throws:
RepositoryException

testRemoveNodeLockedItself

public void testRemoveNodeLockedItself()
                                throws LockException,
                                       NotExecutableException,
                                       RepositoryException
Tests if Node.remove() does not throw a LockException if Node is locked.

The test creates a node nodeName1 of type testNodeType under testRoot and locks the node with the superuser session. Then the test removes nodeName1.

Throws:
LockException
NotExecutableException
RepositoryException

testRemoveNodeParentLocked

public void testRemoveNodeParentLocked()
                                throws LockException,
                                       NotExecutableException,
                                       RepositoryException
Tests if Node.remove() throws a LockException if the parent node of Node is locked.

The test creates a node nodeName1 of type testNodeType under testRoot, adds a child node nodeName2 and locks it with the superuser session. Then the test tries to remove the nodeName2.

Throws:
LockException
NotExecutableException
RepositoryException

testNodeIdentity

public void testNodeIdentity()
                      throws RepositoryException
Tests object identity, meaning two nodes objects accuired through the same session must have the same properties and states.

Prerequisites:

  • javax.jcr.tck.nodetype must allow children of same node type
  • javax.jcr.tck.propertyname1 name of a String property that can be set in javax.jcr.tck.nodetype for testing

Throws:
RepositoryException

testIsSameMustNotCompareStates

public void testIsSameMustNotCompareStates()
                                    throws RepositoryException
Tests if Item.isSame(Item otherItem) will return true when two Node objects representing the same actual repository item have been retrieved through two different sessions and one has been modified.

Throws:
RepositoryException

testIsModified

public void testIsModified()
                    throws RepositoryException
Checks if Item.isModified() works correcty for unmodified and modified nodes.

Throws:
RepositoryException

testIsNew

public void testIsNew()
               throws RepositoryException
Checks if Item.isNew() works correctly for new and existing, unmodified nodes.

Throws:
RepositoryException

testRefreshInvalidItemStateException

public void testRefreshInvalidItemStateException()
                                          throws RepositoryException
Tries to call Item.refresh(boolean) on a deleted node.

This should throw an InvalidItemStateException.

Throws:
RepositoryException

testRefreshBooleanFalse

public void testRefreshBooleanFalse()
                             throws RepositoryException
Checks if Item.refresh(boolean refresh) works properly with refresh set to false.

Procedure:

  • Creates two nodes with session 1
  • Modifies node 1 with session 1 by adding a child node
  • Get node 2 with session 2
  • Modifies node 2 with session 2 by adding a child node
  • saves session 2 changes using Item.save()
  • calls Node.refresh(false) on root node in session 1
Session 1 changes should be cleared and session 2 changes should now be visible to session 1.

Prerequisites:

  • javax.jcr.tck.nodetype must accept children of same nodetype

Throws:
RepositoryException

testRefreshBooleanTrue

public void testRefreshBooleanTrue()
                            throws RepositoryException
Checks if Item.refresh(boolean refresh) works properly with refresh set to true.

Procedure:

  • Creates two nodes with session 1
  • Modifies node 1 with session 1 by adding a child node
  • Get node 2 with session 2
  • Modifies node 2 with session 2 by adding a child node
  • saves session 2 changes using Item.save()
  • calls Node.refresh(true) on root node in session 1
Session 1 changes and session 2 changes now be visible to session 1.

Prerequisites:

  • javax.jcr.tck.nodetype must accept children of same nodetype

Throws:
RepositoryException

testSaveInvalidStateException

public void testSaveInvalidStateException()
                                   throws RepositoryException
Tries to save a node using Item.save() that was already deleted by an other session.

Procedure:

  • Creates a new node with session 1, saves it, adds a child node.
  • Access new node with session 2,deletes the node, saves it.
  • Session 1 tries to save modifications using Node.save() on root node .
This should throw an InvalidItemStateException.

Prerequisites:

  • javax.jcr.tck.nodetype must accept children of same nodetype

Throws:
RepositoryException

testSaveContstraintViolationException

public void testSaveContstraintViolationException()
                                           throws RepositoryException
Tries to create and save a node using Item.save() with an mandatory property that is not set on saving time.

Prerequisites:

  • javax.jcr.tck.Node.testSaveContstraintViolationException.nodetype2 must reference a nodetype that has at least one property that is mandatory but not autocreated

Throws:
RepositoryException

testNodeSave

public void testNodeSave()
                  throws RepositoryException
Creates a new node, saves it uses second session to verify if node has been added.

Throws:
RepositoryException

testSaveOnNewNodeRepositoryException

public void testSaveOnNewNodeRepositoryException()
                                          throws Exception
Tests if a RepositoryException is thrown when calling Node.save() on a newly added node

Throws:
Exception

testPrimaryType

public void testPrimaryType()
                     throws Exception
Tests if the primary node type is properly stored in jcr:primaryType

Throws:
Exception

testPrimaryTypeProtected

public void testPrimaryTypeProtected()
                              throws Exception
Tests if jcr:primaryType is protected

Throws:
Exception

testMixinTypesProtected

public void testMixinTypesProtected()
                             throws Exception
Tests if jcr:mixinTypes is protected

Throws:
Exception


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.