Class NodeTest
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- org.apache.jackrabbit.test.JUnitTest
-
- org.apache.jackrabbit.test.AbstractJCRTest
-
- org.apache.jackrabbit.test.api.NodeTest
-
- All Implemented Interfaces:
junit.framework.Test
public class NodeTest extends AbstractJCRTest
NodeTest
contains all test cases for thejavax.jcr.Node
that are related to writing, modifying 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, mixTitle, mixVersionable, nodeName1, nodeName2, nodeName3, nodeName4, NS_JCR_URI, NS_MIX_URI, NS_NT_URI, NS_SV_URI, ntActivity, ntBase, ntFrozenNode, ntQuery, ntUnstructured, ntVersion, ntVersionHistory, ntVersionLabels, propertyName1, propertyName2, superuser, testNodeType, testNodeTypeNoChildren, testNodeTypeTestRoot, testPath, testRoot, testRootNode, vf, workspaceName
-
-
Constructor Summary
Constructors Constructor Description NodeTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
setUp()
to be able to test the update(String) and getCorrespondingNodePath(String) methods we need an additional workspacevoid
tearDown()
remove all nodes in second workspace and log outvoid
testAddNodeConstraintViolationExceptionProperty()
Tries to add a node usingNode.addNode(String)
as a child of a property.void
testAddNodeConstraintViolationExceptionUndefinedNodeType()
Tries to add a node usingNode.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 usingNode.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
testAddNodeLackingMandatoryChildNode()
Creates a node without its mandatory child node usingNode.addNode(String, String)
and then saves.void
testAddNodeParentSave()
Creates a new node usingNode.addNode(String)
, saves usingItem.save()
on parent node.void
testAddNodePathNotFoundException()
Tries to add a node usingNode.addNode(String)
to a non existing destination node.void
testAddNodeRepositoryExceptionRelPathIndex()
Adds a new node usingNode.addNode(String)
with an index for the new name.void
testAddNodeRepositoryExceptionSaveOnNewNode()
Creates a new node usingNode.addNode(String)
, then tries to callItem.save()
on the newly node.void
testAddNodeSessionSave()
Creates a new node usingNode.addNode(String)
, saves usingSession.save()
.void
testGetCorrespondingNodePath()
Creates a node with same path in both workspaces to check ifNode.getCorrespondingNodePath(String)
works properly.void
testGetCorrespondingNodePathItemNotFoundException()
CallsNode.getCorrespondingNodePath(String)
on a node that has no corresponding node in second workspacevoid
testGetCorrespondingNodePathNoSuchWorkspaceException()
CallsNode.getCorrespondingNodePath(String )
with a non existing workspace.void
testIsModified()
Checks ifItem.isModified()
works correctly for unmodified and modified nodes.void
testIsNew()
Checks ifItem.isNew()
works correctly for new and existing, unmodified nodes.void
testIsSameMustNotCompareStates()
Tests ifItem.isSame(Item otherItem)
will return true when twoNode
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 protectedvoid
testNodeIdentity()
Tests object identity, meaning two nodes objects acquired 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:primaryTypevoid
testPrimaryTypeProtected()
Tests if jcr:primaryType is protectedvoid
testRefreshBooleanFalse()
void
testRefreshBooleanTrue()
void
testRefreshInvalidItemStateException()
Tries to callItem.refresh(boolean)
on a deleted node.void
testRemoveInvalidItemStateException()
Removes a node usingItem.remove()
with session 1, afterwards it tries the same with session 2.void
testRemoveMandatoryNode()
Creates a node with a mandatory child node usingNode.addNode(String, String)
, saves on parent node then tries to delete the mandatory child node.void
testRemoveNodeLockedItself()
Tests ifNode.remove()
does not throw aLockException
ifNode
is locked.void
testRemoveNodeParentLocked()
Tests ifNode.remove()
throws aLockException
if the parent node ofNode
is locked.void
testRemoveNodeParentSave()
Removes a node usingItem.remove()
, then saves with parent's nodesItem.save()
method.void
testRemoveNodeSessionSave()
Removes a node usingItem.remove()
, then saves usingSession.save()
method.void
testSaveConstraintViolationException()
Tries to create and save a node usingItem.save()
with an mandatory property that is not set on saving time.void
testSaveInvalidStateException()
Tries to save a node usingItem.save()
that was already deleted by an other session.void
testSaveOnNewNodeRepositoryException()
Tests if aRepositoryException
is thrown when callingNode.save()
on a newly added nodevoid
testUpdate()
Checks ifNode.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 callingNode.update(String)
after node has changed in first workspace but not been saved yet.void
testUpdateNoClone()
CallsNode.update(String)
for a node that only exists in current workspace.void
testUpdateNoSuchWorkspaceException()
Tries to useNode.update(String)
with an invalid workspace.-
Methods inherited from class org.apache.jackrabbit.test.AbstractJCRTest
checkSupportedOption, cleanUp, cleanUpTestRoot, createRandomString, ensureCanSetProperty, ensureCanSetProperty, ensureCanSetProperty, ensureKnowsNodeType, ensureLockingSupported, ensureMixinType, ensureMultipleWorkspacesSupported, getHelper, getJcrValue, getLocalName, getNonExistingWorkspaceName, getPrefix, getProperty, getProperty, getQualifiedName, getSize, isSupported, needsMixin, run
-
Methods inherited from class junit.framework.TestCase
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, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, runBare, runTest, setName, toString
-
-
-
-
Method Detail
-
setUp
public void setUp() throws Exception
to be able to test the update(String) and getCorrespondingNodePath(String) methods we need an additional workspace- Overrides:
setUp
in classAbstractJCRTest
- Throws:
Exception
-
tearDown
public void tearDown() throws Exception
remove all nodes in second workspace and log out- Overrides:
tearDown
in classAbstractJCRTest
- Throws:
Exception
-
testGetCorrespondingNodePathNoSuchWorkspaceException
public void testGetCorrespondingNodePathNoSuchWorkspaceException() throws RepositoryException
CallsNode.getCorrespondingNodePath(String )
with a non existing workspace.This should throw an
NoSuchWorkspaceException
.- Throws:
RepositoryException
-
testGetCorrespondingNodePathItemNotFoundException
public void testGetCorrespondingNodePathItemNotFoundException() throws RepositoryException, NotExecutableException
CallsNode.getCorrespondingNodePath(String)
on a node that has no corresponding node in second workspace
-
testGetCorrespondingNodePath
public void testGetCorrespondingNodePath() throws RepositoryException, NotExecutableException
Creates a node with same path in both workspaces to check ifNode.getCorrespondingNodePath(String)
works properly.
-
testUpdateInvalidItemStateException
public void testUpdateInvalidItemStateException() throws RepositoryException, NotExecutableException
Tries callingNode.update(String)
after node has changed in first workspace but not been saved yet.This should throw an
InvalidItemStateException
.Prerequisites:
javax.jcr.tck.propertyname1
name of a String property that can be modified injavax.jcr.tck.nodetype
for testing
-
testUpdateNoSuchWorkspaceException
public void testUpdateNoSuchWorkspaceException() throws RepositoryException
Tries to useNode.update(String)
with an invalid workspace.This should throw an
NoSuchWorkspaceException
.- Throws:
RepositoryException
-
testUpdateNoClone
public void testUpdateNoClone() throws RepositoryException
CallsNode.update(String)
for a node that only exists in current workspace.
In that case nothing should happen.Prerequisites:
javax.jcr.tck.propertyname1
name of a String property that can be modified injavax.jcr.tck.nodetype
for testing
- Throws:
RepositoryException
-
testUpdate
public void testUpdate() throws RepositoryException, NotExecutableException
Checks ifNode.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:
javax.jcr.tck.nodetype
must allow children of same nodetype.javax.jcr.tck.propertyname1
name of a String property that can be modified injavax.jcr.tck.nodetype
for testing
-
testAddNodeConstraintViolationExceptionUndefinedNodeType
public void testAddNodeConstraintViolationExceptionUndefinedNodeType() throws RepositoryException
Tries to add a node usingNode.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 usingNode.addNode(String)
as a child of a property.This should throw an
ConstraintViolationException
.Prerequisites:
javax.jcr.tck.propertyname1
name of a String property that can be set injavax.jcr.tck.nodetype
for testing
- Throws:
RepositoryException
-
testAddNodeItemExistsException
public void testAddNodeItemExistsException() throws RepositoryException
Tries to create a node usingNode.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:
javax.jcr.tck.NodeTest.testAddNodeItemExistsException.nodetype
node type that does not allow same name siblings and allows to add child nodes of the same type.
- Throws:
RepositoryException
-
testAddNodePathNotFoundException
public void testAddNodePathNotFoundException() throws RepositoryException
Tries to add a node usingNode.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 usingNode.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 usingNode.addNode(String)
, then tries to callItem.save()
on the newly node.This should throw an
RepositoryException
.- Throws:
RepositoryException
-
testAddNodeParentSave
public void testAddNodeParentSave() throws RepositoryException
Creates a new node usingNode.addNode(String)
, saves usingItem.save()
on parent node. Uses a second session to verify if the node has been saved.- Throws:
RepositoryException
-
testAddNodeSessionSave
public void testAddNodeSessionSave() throws RepositoryException
Creates a new node usingNode.addNode(String)
, saves usingSession.save()
. Uses a second session to verify if the node has been saved.- Throws:
RepositoryException
-
testAddNodeLackingMandatoryChildNode
public void testAddNodeLackingMandatoryChildNode() throws RepositoryException
Creates a node without its mandatory child node usingNode.addNode(String, String)
and then saves.This should throw a
ConstraintViolationException
.Prerequisites:
javax.jcr.tck.NodeTest.testAddNodeLackingMandatoryChildNode.nodetype2
a node type that has a mandatory child node
- Throws:
RepositoryException
-
testRemoveMandatoryNode
public void testRemoveMandatoryNode() throws RepositoryException
Creates a node with a mandatory child node usingNode.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 nodejavax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodetype3
nodetype of the mandatory child nodejavax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodename3
name of the mandatory child node
- Throws:
RepositoryException
-
testRemoveInvalidItemStateException
public void testRemoveInvalidItemStateException() throws RepositoryException
Removes a node usingItem.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 usingItem.remove()
, then saves with parent's nodesItem.save()
method.- Throws:
RepositoryException
-
testRemoveNodeSessionSave
public void testRemoveNodeSessionSave() throws RepositoryException
Removes a node usingItem.remove()
, then saves usingSession.save()
method.- Throws:
RepositoryException
-
testRemoveNodeLockedItself
public void testRemoveNodeLockedItself() throws LockException, NotExecutableException, RepositoryException
Tests ifNode.remove()
does not throw aLockException
ifNode
is locked.The test creates a node
nodeName1
of typetestNodeType
undertestRoot
and locks the node with the superuser session. Then the test removesnodeName1
.
-
testRemoveNodeParentLocked
public void testRemoveNodeParentLocked() throws LockException, NotExecutableException, RepositoryException
Tests ifNode.remove()
throws aLockException
if the parent node ofNode
is locked.The test creates a node
nodeName1
of typetestNodeType
undertestRoot
, adds a child nodenodeName2
and locks it with the superuser session. Then the test tries to remove thenodeName2
.
-
testNodeIdentity
public void testNodeIdentity() throws RepositoryException
Tests object identity, meaning two nodes objects acquired through the same session must have the same properties and states.Prerequisites:
javax.jcr.tck.nodetype
must allow children of same node typejavax.jcr.tck.propertyname1
name of a String property that can be set injavax.jcr.tck.nodetype
for testing
- Throws:
RepositoryException
-
testIsSameMustNotCompareStates
public void testIsSameMustNotCompareStates() throws RepositoryException
Tests ifItem.isSame(Item otherItem)
will return true when twoNode
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 ifItem.isModified()
works correctly for unmodified and modified nodes.- Throws:
RepositoryException
-
testIsNew
public void testIsNew() throws RepositoryException
Checks ifItem.isNew()
works correctly for new and existing, unmodified nodes.- Throws:
RepositoryException
-
testRefreshInvalidItemStateException
public void testRefreshInvalidItemStateException() throws RepositoryException
Tries to callItem.refresh(boolean)
on a deleted node.This should throw an
InvalidItemStateException
.- Throws:
RepositoryException
-
testRefreshBooleanFalse
public void testRefreshBooleanFalse() throws RepositoryException
Checks ifItem.refresh(boolean refresh)
works properly withrefresh
set tofalse
.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
Prerequisites:
javax.jcr.tck.nodetype
must accept children of same nodetype
- Throws:
RepositoryException
-
testRefreshBooleanTrue
public void testRefreshBooleanTrue() throws RepositoryException
Checks ifItem.refresh(boolean refresh)
works properly withrefresh
set totrue
.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
Prerequisites:
javax.jcr.tck.nodetype
must accept children of same nodetype
- Throws:
RepositoryException
-
testSaveInvalidStateException
public void testSaveInvalidStateException() throws RepositoryException
Tries to save a node usingItem.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 .
InvalidItemStateException
.Prerequisites:
javax.jcr.tck.nodetype
must accept children of same nodetype
- Throws:
RepositoryException
-
testSaveConstraintViolationException
public void testSaveConstraintViolationException() throws RepositoryException
Tries to create and save a node usingItem.save()
with an mandatory property that is not set on saving time.Prerequisites:
javax.jcr.tck.Node.testSaveConstraintViolationException.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 aRepositoryException
is thrown when callingNode.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
-
-