Search in sources :

Example 46 with Property

use of javax.jcr.Property in project jackrabbit by apache.

the class NameTest method testExpandedNameItem.

/**
     * Test if the name of property created with an expanded name is properly
     * return as standard JCR name.
     * 
     * @throws RepositoryException
     */
public void testExpandedNameItem() throws RepositoryException {
    String propName = getExpandedName(propertyName1);
    Property p = testRootNode.setProperty(propName, getJcrValue(superuser, RepositoryStub.PROP_PROP_VALUE1, RepositoryStub.PROP_PROP_TYPE1, "test"));
    assertEquals(propertyName1, p.getName());
}
Also used : Property(javax.jcr.Property)

Example 47 with Property

use of javax.jcr.Property in project jackrabbit-oak by apache.

the class ConcurrentEveryoneACLTest method beforeSuite.

@Override
public void beforeSuite() throws Exception {
    Session session = loginWriter();
    AccessControlManager acMgr = session.getAccessControlManager();
    Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
    final Node root = session.getRootNode().addNode(ROOT_NODE_NAME, "nt:unstructured");
    for (int i = 0; i < NODE_COUNT; i++) {
        Node node = root.addNode("node" + i, "nt:unstructured");
        for (int j = 0; j < NODE_COUNT; j++) {
            Node newNode = node.addNode("node" + j, "nt:unstructured");
            JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, newNode.getPath());
            acl.addEntry(EveryonePrincipal.getInstance(), privileges, true);
            acMgr.setPolicy(newNode.getPath(), acl);
        }
        session.save();
    }
    // deny everyone on root node
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, root.getPath());
    acl.addEntry(EveryonePrincipal.getInstance(), privileges, false);
    acMgr.setPolicy(root.getPath(), acl);
    session.save();
    final int[] numACEs = new int[1];
    ItemVisitor v = new TraversingItemVisitor.Default() {

        @Override
        protected void entering(Node node, int i) throws RepositoryException {
            if (node.isNodeType(AccessControlConstants.NT_REP_ACE)) {
                numACEs[0]++;
            }
            super.entering(node, i);
        }

        @Override
        protected void entering(Property prop, int i) throws RepositoryException {
            super.entering(prop, i);
        }
    };
    v.visit(root);
    System.out.println("Num ACEs: " + numACEs[0]);
    session.logout();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) ItemVisitor(javax.jcr.ItemVisitor) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) Node(javax.jcr.Node) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 48 with Property

use of javax.jcr.Property in project jackrabbit by apache.

the class GCConcurrentTest method testGC.

public void testGC() throws Exception {
    Node root = testRootNode;
    Session session = root.getSession();
    GCThread gc = new GCThread(session);
    Thread gcThread = new Thread(gc, "Datastore Garbage Collector");
    int len = 10 * getTestScale();
    boolean started = false;
    for (int i = 0; i < len; i++) {
        if (!started && i > 5 + len / 100) {
            started = true;
            gcThread.start();
        }
        Node n = node(root, "test" + i);
        ValueFactory vf = session.getValueFactory();
        n.setProperty("data", vf.createBinary(randomInputStream(i)));
        session.save();
        LOG.debug("saved: " + i);
    }
    Thread.sleep(10);
    for (int i = 0; i < len; i++) {
        Node n = root.getNode("test" + i);
        Property p = n.getProperty("data");
        InputStream in = p.getBinary().getStream();
        InputStream expected = randomInputStream(i);
        checkStreams(expected, in);
        n.remove();
        LOG.debug("removed: " + i);
        session.save();
    }
    Thread.sleep(10);
    gc.setStop(true);
    Thread.sleep(10);
    gcThread.join();
    gc.throwException();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 49 with Property

use of javax.jcr.Property in project jackrabbit by apache.

the class CopyValueTest method doTestCopy.

private void doTestCopy(int length) throws Exception {
    Node root = superuser.getRootNode();
    if (root.hasNode("testCopy")) {
        root.getNode("testCopy").remove();
        superuser.save();
    }
    Node testRoot = root.addNode("testCopy");
    Node n = testRoot.addNode("a");
    superuser.save();
    byte[] data = new byte[length + 1];
    ValueFactory vf = superuser.getValueFactory();
    n.setProperty("data", vf.createBinary(new ByteArrayInputStream(data)));
    superuser.save();
    data = new byte[length];
    n.setProperty("data", vf.createBinary(new ByteArrayInputStream(data)));
    Property p = testRoot.getNode("a").getProperty("data");
    assertEquals(length, p.getLength());
    superuser.getWorkspace().copy("/testCopy/a", "/testCopy/b");
    assertEquals(length, p.getLength());
    p = testRoot.getNode("b").getProperty("data");
    assertEquals(length + 1, p.getLength());
    testRoot.remove();
    superuser.save();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) Property(javax.jcr.Property)

Example 50 with Property

use of javax.jcr.Property in project jackrabbit by apache.

the class AcReadWriteTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // create some nodes below the test root in order to apply ac-stuff
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    Node cn1 = node.addNode(nodeName2, testNodeType);
    Property cp1 = node.setProperty(propertyName1, "anyValue");
    Node cn2 = node.addNode(nodeName3, testNodeType);
    Property ccp1 = cn1.setProperty(propertyName1, "childNodeProperty");
    Node n2 = testRootNode.addNode(nodeName2, testNodeType);
    superuser.save();
    path = node.getPath();
    childNPath = cn1.getPath();
    childNPath2 = cn2.getPath();
    childPPath = cp1.getPath();
    childchildPPath = ccp1.getPath();
    siblingPath = n2.getPath();
}
Also used : Node(javax.jcr.Node) Property(javax.jcr.Property)

Aggregations

Property (javax.jcr.Property)445 Node (javax.jcr.Node)252 Value (javax.jcr.Value)99 Test (org.junit.Test)87 Session (javax.jcr.Session)78 PropertyIterator (javax.jcr.PropertyIterator)68 RepositoryException (javax.jcr.RepositoryException)64 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)47 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)37 ValueFormatException (javax.jcr.ValueFormatException)34 QValue (org.apache.jackrabbit.spi.QValue)29 ArrayList (java.util.ArrayList)24 NodeIterator (javax.jcr.NodeIterator)24 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)23 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)20 Item (javax.jcr.Item)19 PathNotFoundException (javax.jcr.PathNotFoundException)17 InvalidItemStateException (javax.jcr.InvalidItemStateException)16 Version (javax.jcr.version.Version)16 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)15