use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class NodeTest method testRemoveNodeParentLocked.
/**
* Tests if <code>Node.remove()</code> throws a <code>LockException</code>
* if the parent node of <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 child node
* <code>nodeName2</code> and locks it with the superuser session. Then the
* test tries to remove the <code>nodeName2</code>.
*/
public void testRemoveNodeParentLocked() throws LockException, NotExecutableException, RepositoryException {
Session session = testRootNode.getSession();
if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
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
ensureMixinType(node, mixLockable);
// create a child node
Node subNode = node.addNode(nodeName2, testNodeType);
testRootNode.getSession().save();
// lock the node
// 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 = getHelper().getSuperuserSession();
try {
Node node2 = session2.getRootNode().getNode(pathRelToRoot);
node2.lock(true, true);
try {
subNode.remove();
session.save();
fail("Removal of a Node must throw a LockException upon remove() " + "or upon save() if the parent of the node is locked");
} catch (LockException e) {
// success
}
// unlock to remove node at tearDown()
node2.unlock();
} finally {
session2.logout();
}
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class NodeAddMixinTest method testLocked.
/**
* 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 (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
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
ensureMixinType(node, mixLockable);
testRootNode.getSession().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 = getHelper().getSuperuserSession();
try {
Node node2 = session2.getRootNode().getNode(pathRelToRoot);
node2.lock(true, true);
try {
// implementation specific: either throw LockException upon
// addMixin or upon save.
node.addMixin(mixinName);
node.save();
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();
} finally {
session2.logout();
}
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class NodeCanAddMixinTest method testLocked.
/**
* 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 (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
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
ensureMixinType(node, mixLockable);
testRootNode.getSession().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 = getHelper().getSuperuserSession();
try {
Node node2 = session2.getRootNode().getNode(pathRelToRoot);
node2.lock(true, true);
node.refresh(false);
assertFalse("Node.canAddMixin(String mixinName) must return false " + "if the node is locked.", node.canAddMixin(mixinName));
node2.unlock();
} finally {
session2.logout();
}
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class NodeReadMethodsTest method testGetReferences.
public void testGetReferences() throws NotExecutableException, RepositoryException {
Node node = locateNodeWithReference(testRootNode);
if (node == null) {
throw new NotExecutableException("Workspace does not contain a node with a reference property set");
}
PropertyIterator properties = node.getProperties();
while (properties.hasNext()) {
Property p = properties.nextProperty();
if (p.getType() == PropertyType.REFERENCE && !p.getDefinition().isMultiple()) {
Node referencedNode = p.getNode();
PropertyIterator refs = referencedNode.getReferences();
boolean referenceFound = false;
while (refs.hasNext()) {
Property ref = refs.nextProperty();
if (ref.isSame(p)) {
referenceFound = true;
}
}
assertTrue("Correct reference not found", referenceFound);
}
}
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class NodeReadMethodsTest method testGetNodesNamePattern.
/**
* Test getNodes(String namePattern) with all possible patterns. Tested
* node: root - NotExecutableException is thrown when root node has no sub
* nodes.
*/
public void testGetNodesNamePattern() throws NotExecutableException, RepositoryException {
// get root node and build an ArrayList of its sub nodes
Node node = testRootNode;
if (!node.hasNodes()) {
throw new NotExecutableException("Workspace does not have sufficient content for this test. " + "Root node must have at least one child node.");
}
NodeIterator allNodesIt = node.getNodes();
List<Node> allNodes = new ArrayList<Node>();
while (allNodesIt.hasNext()) {
Node n = allNodesIt.nextNode();
allNodes.add(n);
}
// test if an empty NodeIterator is returned
// when the pattern is not matching any child node
String pattern0 = "";
NodeIterator nodes0 = node.getNodes(pattern0);
try {
nodes0.nextNode();
fail("An empty NodeIterator must be returned if pattern does" + "not match any child node.");
} catch (NoSuchElementException e) {
// success
}
// all further tests are using root's first sub node
Node firstNode = allNodes.get(0);
// test pattern "*"
String pattern1 = "*";
String assertString1 = "node.getNodes(\"" + pattern1 + "\"): ";
NodeIterator nodes1 = node.getNodes(pattern1);
// test if the number of found nodes is correct
assertEquals(assertString1 + "number of nodes found: ", allNodes.size(), getSize(nodes1));
// test pattern "nodeName"
String pattern2 = firstNode.getName();
String assertString2 = "node.getNodes(\"" + pattern2 + "\"): ";
// test if the names of the found nodes are matching the pattern
NodeIterator nodes2 = node.getNodes(pattern2);
while (nodes2.hasNext()) {
Node n = nodes2.nextNode();
assertEquals(assertString2 + "name comparison failed: ", firstNode.getName(), n.getName());
}
// test if the number of found nodes is correct
int numExpected2 = 0;
for (int i = 0; i < allNodes.size(); i++) {
Node n = allNodes.get(i);
if (n.getName().equals(firstNode.getName())) {
numExpected2++;
}
}
nodes2 = node.getNodes(pattern2);
assertEquals(assertString2 + "number of nodes found: ", numExpected2, getSize(nodes2));
// test pattern "nodeName|nodeName"
String pattern3 = firstNode.getName() + "|" + firstNode.getName();
String assertString3 = "node.getNodes(\"" + pattern3 + "\"): ";
// test if the names of the found nodes are matching the pattern
NodeIterator nodes3 = node.getNodes(pattern3);
while (nodes3.hasNext()) {
Node n = nodes3.nextNode();
assertEquals(assertString2 + "name comparison failed: ", firstNode.getName(), n.getName());
}
// test if the number of found nodes is correct
int numExpected3 = 0;
for (int i = 0; i < allNodes.size(); i++) {
Node n = allNodes.get(i);
if (n.getName().equals(firstNode.getName())) {
numExpected3++;
}
}
nodes3 = node.getNodes(pattern3);
assertEquals(assertString3 + "number of nodes found: ", numExpected3, getSize(nodes3));
// test pattern "*odeNam*"
if (firstNode.getName().length() > 2) {
String name = firstNode.getName();
String shortenName = name.substring(1, name.length() - 1);
String pattern4 = "*" + shortenName + "*";
String assertString4 = "node.getNodes(\"" + pattern4 + "\"): ";
// test if the names of the found nodes are matching the pattern
NodeIterator nodes4 = node.getNodes(pattern4);
while (nodes4.hasNext()) {
Node n = nodes4.nextNode();
assertTrue(assertString4 + "name comparison failed: *" + shortenName + "* not found in " + n.getName(), n.getName().indexOf(shortenName) != -1);
}
// test if the number of found nodes is correct
int numExpected4 = 0;
for (int i = 0; i < allNodes.size(); i++) {
Node n = allNodes.get(i);
if (n.getName().indexOf(shortenName) != -1) {
numExpected4++;
}
}
nodes4 = node.getNodes(pattern4);
assertEquals(assertString4 + "number of nodes found: ", numExpected4, getSize(nodes4));
}
}
Aggregations