use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class PropertyReadMethodsTest method setUp.
/**
* Sets up the fixture for this test.
*/
protected void setUp() throws Exception {
isReadOnly = true;
super.setUp();
session = getHelper().getReadOnlySession();
testRootNode = session.getRootNode().getNode(testPath);
PropertyIterator properties = testRootNode.getProperties();
try {
property = properties.nextProperty();
} catch (NoSuchElementException e) {
fail("Any node must have at least one property set: jcr:primaryType");
}
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class PropertyTypeTest method typeCheckChildren.
private void typeCheckChildren(Node parentNode) throws RepositoryException {
NodeIterator nodes = parentNode.getNodes();
while (nodes.hasNext()) {
Node node = nodes.nextNode();
PropertyIterator props = node.getProperties();
while (props.hasNext()) {
Property prop = props.nextProperty();
int reqType = prop.getDefinition().getRequiredType();
int type = PropertyType.UNDEFINED;
boolean isEmptyMultipleArray = false;
if (prop.getDefinition().isMultiple()) {
if (prop.getValues().length > 0) {
type = prop.getValues()[0].getType();
} else {
isEmptyMultipleArray = true;
}
} else {
type = prop.getValue().getType();
}
if (!isEmptyMultipleArray && reqType != PropertyType.UNDEFINED) {
assertFalse("The type of a property must not " + "be UNDEFINED", type == PropertyType.UNDEFINED);
assertEquals("The type of a property has to match " + "the type of the property definition.", type, reqType);
}
}
typeCheckChildren(node);
}
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class ReferencePropertyTest method testPropValue.
/**
* Tests if the referenced node has this property in its referers list in
* case the property is not transient. Also tests in theis case that the
* node retrieved by property.getNode() is the same as the one retrieved by
* session.getNodeByUUID() .
*/
public void testPropValue() throws RepositoryException {
Node referenced = session.getNodeByUUID(prop.getString());
PropertyIterator referers = referenced.getReferences();
if (!prop.isNew()) {
boolean found = false;
while (referers.hasNext()) {
Property propp = referers.nextProperty();
if (propp.isSame(prop)) {
found = true;
}
}
assertTrue("Referencing property of node " + referenced.getName() + " not found.", found);
assertTrue("Referenced node retrieved with getNode is different " + "from the node retrieved with getNodeByUUID", referenced.isSame(referencedNode));
} else {
log.println("Reference property " + prop.getName() + " is in transient state.");
}
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class NodeReadMethodsTest method testHasProperty.
/**
* Test if hasProperty(String relPath) returns true if a required property
* exists and false if it doesn't. Tested node: root
*/
public void testHasProperty() throws NotExecutableException, RepositoryException {
Node node = testRootNode;
PropertyIterator properties = node.getProperties();
StringBuffer notExistingPropertyName = new StringBuffer();
while (properties.hasNext()) {
Property p = properties.nextProperty();
assertTrue("node.hasProperty(\"relPath\") returns false " + "although property at relPath is existing", node.hasProperty(p.getName()));
notExistingPropertyName.append(p.getName() + "X");
}
if (notExistingPropertyName.toString().equals("")) {
fail("Root node must at least have one property: jcr:primaryType");
}
assertFalse("node.hasProperty(\"relPath\") returns true " + "although property at relPath is not existing", node.hasProperty(notExistingPropertyName.toString().replaceAll(":", "")));
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class ConcurrentReadWriteTest method testReadWrite.
public void testReadWrite() throws RepositoryException {
final List uuids = new ArrayList();
for (int i = 0; i < NUM_NODES; i++) {
Node n = testRootNode.addNode("node" + i);
n.addMixin(mixReferenceable);
uuids.add(n.getUUID());
}
final List exceptions = Collections.synchronizedList(new ArrayList());
final long[] numReads = new long[] { 0 };
testRootNode.save();
Thread t = new Thread(new Runnable() {
public void run() {
try {
runTask(new Task() {
public void execute(Session session, Node test) throws RepositoryException {
Random rand = new Random();
long start = System.currentTimeMillis();
long reads = 0;
while (System.currentTimeMillis() < start + RUN_NUM_SECONDS * 1000) {
String uuid = (String) uuids.get(rand.nextInt(uuids.size()));
Node n = session.getNodeByUUID(uuid);
try {
for (PropertyIterator it = n.getProperties(); it.hasNext(); ) {
Property p = it.nextProperty();
if (p.isMultiple()) {
p.getValues();
} else {
p.getValue();
}
}
} catch (InvalidItemStateException e) {
// ignore
}
reads++;
}
synchronized (numReads) {
numReads[0] += reads;
}
}
}, NUM_THREADS, testRoot);
} catch (RepositoryException e) {
exceptions.add(e);
}
}
});
t.start();
long numWrites = 0;
while (t.isAlive()) {
Random rand = new Random();
String uuid = (String) uuids.get(rand.nextInt(uuids.size()));
Node n = superuser.getNodeByUUID(uuid);
if (n.hasProperty("test")) {
n.getProperty("test").remove();
} else {
n.setProperty("test", "hello world");
}
n.save();
numWrites++;
}
log.println("#writes performed: " + numWrites);
log.println("#reads performed: " + numReads[0]);
if (!exceptions.isEmpty()) {
fail(((RepositoryException) exceptions.get(0)).getMessage());
}
}
Aggregations