Search in sources :

Example 31 with PropertyIterator

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");
    }
}
Also used : PropertyIterator(javax.jcr.PropertyIterator) NoSuchElementException(java.util.NoSuchElementException)

Example 32 with PropertyIterator

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

Example 33 with PropertyIterator

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

Example 34 with PropertyIterator

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

Example 35 with PropertyIterator

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());
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) RepositoryException(javax.jcr.RepositoryException) Random(java.util.Random) List(java.util.List) ArrayList(java.util.ArrayList) Property(javax.jcr.Property) Session(javax.jcr.Session)

Aggregations

PropertyIterator (javax.jcr.PropertyIterator)130 Property (javax.jcr.Property)97 Node (javax.jcr.Node)79 NodeIterator (javax.jcr.NodeIterator)31 RepositoryException (javax.jcr.RepositoryException)28 Value (javax.jcr.Value)28 Session (javax.jcr.Session)21 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)19 HashSet (java.util.HashSet)14 PathNotFoundException (javax.jcr.PathNotFoundException)13 HashMap (java.util.HashMap)12 AccessDeniedException (javax.jcr.AccessDeniedException)7 Item (javax.jcr.Item)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 JSONObject (org.codehaus.jettison.json.JSONObject)5 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)4 AccessControlException (java.security.AccessControlException)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 RepositoryFileDaoReferentialIntegrityException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException)4