Search in sources :

Example 81 with PropertyIterator

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));
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator)

Example 82 with PropertyIterator

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());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) QValueValue(org.apache.jackrabbit.spi.commons.value.QValueValue) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Example 83 with PropertyIterator

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());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Example 84 with PropertyIterator

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());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) QValueValue(org.apache.jackrabbit.spi.commons.value.QValueValue) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Property(javax.jcr.Property) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 85 with PropertyIterator

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());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) QValueValue(org.apache.jackrabbit.spi.commons.value.QValueValue) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Aggregations

PropertyIterator (javax.jcr.PropertyIterator)96 Property (javax.jcr.Property)68 Node (javax.jcr.Node)57 NodeIterator (javax.jcr.NodeIterator)28 Value (javax.jcr.Value)23 Test (org.junit.Test)16 RepositoryException (javax.jcr.RepositoryException)15 Session (javax.jcr.Session)15 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)10 PathNotFoundException (javax.jcr.PathNotFoundException)8 HashMap (java.util.HashMap)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 NodeImpl (org.apache.jackrabbit.core.NodeImpl)5 PropertyImpl (org.apache.jackrabbit.core.PropertyImpl)5 NoSuchElementException (java.util.NoSuchElementException)3 AccessDeniedException (javax.jcr.AccessDeniedException)3 InvalidItemStateException (javax.jcr.InvalidItemStateException)3 ValueFormatException (javax.jcr.ValueFormatException)3 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)3