use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class PropertyTest method testPropertyIteratorSize.
public void testPropertyIteratorSize() throws Exception {
Node n = testRootNode.addNode("unstructured", JcrConstants.NT_UNSTRUCTURED);
n.setProperty("foo", "a");
n.setProperty("foo-1", "b");
n.setProperty("bar", "b");
n.setProperty("cat", "c");
superuser.save();
//Extra 1 for jcr:primaryType
PropertyIterator pitr = n.getProperties();
assertEquals(4 + 1, pitr.getSize());
assertEquals(4 + 1, Iterators.size(pitr));
pitr = n.getProperties("foo*");
assertEquals(2, pitr.getSize());
assertEquals(2, Iterators.size(pitr));
pitr = n.getProperties(new String[] { "foo*", "cat*" });
assertEquals(3, pitr.getSize());
assertEquals(3, Iterators.size(pitr));
}
use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class RepositoryTest method getNamedReferences.
@Test
public void getNamedReferences() throws RepositoryException {
Session session = getAdminSession();
Node referee = getNode("/foo");
referee.addMixin("mix:referenceable");
Value value = session.getValueFactory().createValue(referee);
getNode(TEST_PATH).setProperty("reference1", value);
getNode("/bar").setProperty("reference2", value);
session.save();
PropertyIterator refs = referee.getReferences("reference1");
assertTrue(refs.hasNext());
Property p = refs.nextProperty();
assertEquals("reference1", p.getName());
assertFalse(refs.hasNext());
}
use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class RepositoryTest method getWeakReferences.
@Test
public void getWeakReferences() throws RepositoryException {
Session session = getAdminSession();
Node referee = getNode("/foo");
referee.addMixin("mix:referenceable");
getNode(TEST_PATH).setProperty("weak-reference", session.getValueFactory().createValue(referee, true));
session.save();
PropertyIterator refs = referee.getWeakReferences();
assertTrue(refs.hasNext());
Property p = refs.nextProperty();
assertEquals("weak-reference", p.getName());
assertFalse(refs.hasNext());
}
use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class RepositoryTest method getProperties.
@Test
public void getProperties() throws RepositoryException {
Set<String> propertyNames = new HashSet<String>() {
{
add("intProp");
add("mvProp");
add("added");
}
};
Set<String> values = new HashSet<String>() {
{
add("added");
add("1");
add("2");
add("3");
add("42");
}
};
Node node = getNode("/foo");
// transiently added
node.setProperty("added", "added");
// transiently removed
node.getProperty("stringProp").remove();
// transiently removed...
node.getProperty("intProp").remove();
// ...and added again
node.setProperty("intProp", 42);
PropertyIterator properties = node.getProperties();
assertEquals(4, properties.getSize());
while (properties.hasNext()) {
Property p = properties.nextProperty();
if (JcrConstants.JCR_PRIMARYTYPE.equals(p.getName())) {
continue;
}
assertTrue(propertyNames.remove(p.getName()));
if (p.isMultiple()) {
for (Value v : p.getValues()) {
assertTrue(values.remove(v.getString()));
}
} else {
assertTrue(values.remove(p.getString()));
}
}
assertTrue(propertyNames.isEmpty());
assertTrue(values.isEmpty());
}
use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class RepositoryTest method getNamedWeakReferences.
@Test
public void getNamedWeakReferences() throws RepositoryException {
Session session = getAdminSession();
Node referee = getNode("/foo");
referee.addMixin("mix:referenceable");
Value value = session.getValueFactory().createValue(referee, true);
getNode(TEST_PATH).setProperty("weak-reference1", value);
getNode("/bar").setProperty("weak-reference2", value);
session.save();
PropertyIterator refs = referee.getWeakReferences("weak-reference1");
assertTrue(refs.hasNext());
Property p = refs.nextProperty();
assertEquals("weak-reference1", p.getName());
assertFalse(refs.hasNext());
}
Aggregations