use of javax.jcr.PropertyIterator 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 javax.jcr.PropertyIterator in project jackrabbit by apache.
the class NodeReadMethodsTest method locateNodeWithReference.
/**
* Returns the first descendant of <code>node</code> which has a property of
* type {@link javax.jcr.PropertyType#REFERENCE} set and is <b>not</b>
* multivalued.
*
* @param node <code>Node</code> to start traversal.
* @return first node with a property of PropertType.REFERENCE
*/
private Node locateNodeWithReference(Node node) throws RepositoryException {
PropertyIterator properties = node.getProperties();
while (properties.hasNext()) {
Property p = properties.nextProperty();
if (p.getType() == PropertyType.REFERENCE && !p.getDefinition().isMultiple()) {
return node;
}
}
NodeIterator nodes = node.getNodes();
while (nodes.hasNext()) {
Node returnedNode = locateNodeWithReference(nodes.nextNode());
if (returnedNode != null) {
return returnedNode;
}
}
return null;
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class GetWeakReferencesTest method testSingleValueWithName.
public void testSingleValueWithName() throws RepositoryException {
Value weakRef = vf.createValue(target, true);
referring.setProperty(propertyName1, weakRef);
superuser.save();
PropertyIterator it = target.getWeakReferences(propertyName1);
assertTrue("no weak references returned", it.hasNext());
Property p = it.nextProperty();
assertEquals("wrong weak reference property", referring.getProperty(propertyName1).getPath(), p.getPath());
assertFalse("no more weak references expected", it.hasNext());
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class GetWeakReferencesTest method testMultiValuesWithName.
public void testMultiValuesWithName() throws RepositoryException {
Value weakRef = vf.createValue(target, true);
Value[] refs = new Value[] { weakRef, weakRef };
referring.setProperty(propertyName1, refs);
superuser.save();
PropertyIterator it = target.getWeakReferences(propertyName1);
assertTrue("no weak references returned", it.hasNext());
Property p = it.nextProperty();
assertEquals("wrong weak reference property", referring.getProperty(propertyName1).getPath(), p.getPath());
assertFalse("no more weak references expected", it.hasNext());
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class GetWeakReferencesTest method testSingleValue.
public void testSingleValue() throws RepositoryException {
Value weakRef = vf.createValue(target, true);
referring.setProperty(propertyName1, weakRef);
superuser.save();
PropertyIterator it = target.getWeakReferences();
assertTrue("no weak references returned", it.hasNext());
Property p = it.nextProperty();
assertEquals("wrong weak reference property", referring.getProperty(propertyName1).getPath(), p.getPath());
assertFalse("no more weak references expected", it.hasNext());
}
Aggregations