Search in sources :

Example 46 with ValueFactory

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

the class TestTwoGetStreams method testTwoGetStreams.

/**
     * Test reading from two concurrently opened streams.
     */
public void testTwoGetStreams() throws Exception {
    Node root = superuser.getRootNode();
    ValueFactory vf = superuser.getValueFactory();
    root.setProperty("p1", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH)));
    root.setProperty("p2", vf.createBinary(new RandomInputStream(2, STREAM_LENGTH)));
    superuser.save();
    InputStream i1 = root.getProperty("p1").getBinary().getStream();
    InputStream i2 = root.getProperty("p2").getBinary().getStream();
    assertEquals("p1", i1, new RandomInputStream(1, STREAM_LENGTH));
    assertEquals("p2", i2, new RandomInputStream(2, STREAM_LENGTH));
    try {
        i1.close();
    } catch (IOException e) {
        log.info("Could not close first input stream: ", e);
    }
    try {
        i2.close();
    } catch (IOException e) {
        log.info("Could not close second input stream: ", e);
    }
}
Also used : InputStream(java.io.InputStream) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) IOException(java.io.IOException)

Example 47 with ValueFactory

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

the class TestTwoGetStreams method testTwoStreamsFromSamePropertyConcurrently.

/**
     * Tests reading concurrently from two different streams coming from the
     * same property.
     */
public void testTwoStreamsFromSamePropertyConcurrently() throws Exception {
    Node root = superuser.getRootNode();
    ValueFactory vf = superuser.getValueFactory();
    root.setProperty("p1", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH)));
    superuser.save();
    InputStream i1 = root.getProperty("p1").getBinary().getStream();
    InputStream i2 = root.getProperty("p1").getBinary().getStream();
    assertEquals("Streams are different", i1, i2);
    try {
        i1.close();
    } catch (IOException e) {
        log.info("Could not close first input stream: ", e);
    }
    try {
        i2.close();
    } catch (IOException e) {
        log.info("Could not close second input stream: ", e);
    }
}
Also used : InputStream(java.io.InputStream) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) IOException(java.io.IOException)

Example 48 with ValueFactory

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

the class WriteWhileReadingTest method test.

public void test() throws Exception {
    Node root = superuser.getRootNode();
    ValueFactory vf = superuser.getValueFactory();
    // store a binary in the data store
    root.setProperty("p1", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH)));
    superuser.save();
    // read from the binary, but don't close the file
    Value v1 = root.getProperty("p1").getValue();
    InputStream in = v1.getBinary().getStream();
    in.read();
    // store the same content at a different place -
    // this will change the last modified date of the file
    root.setProperty("p2", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH)));
    superuser.save();
    in.close();
}
Also used : InputStream(java.io.InputStream) Node(javax.jcr.Node) Value(javax.jcr.Value) ValueFactory(javax.jcr.ValueFactory)

Example 49 with ValueFactory

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

the class ItemSequenceTest method testPropertySequence.

public void testPropertySequence() throws RepositoryException, IOException {
    Comparator<String> order = Rank.<String>comparableComparator();
    TreeManager treeManager = new BTreeManager(testNode, 2, 4, order, true);
    PropertySequence properties = ItemSequence.createPropertySequence(treeManager, errorHandler);
    List<String> words = loadWords();
    Collections.shuffle(words);
    ValueFactory vFactory = testNode.getSession().getValueFactory();
    addAll(properties, words, vFactory);
    checkTreeProperty(testNode, 2, 4, order);
    Collections.shuffle(words);
    checkLookup(properties, words);
    Collections.shuffle(words);
    List<String> toRemove = take(words.size() / 5, words);
    removeAll(properties, toRemove);
    checkNotFound(properties, toRemove);
    checkLookup(properties, words);
    removeAll(properties, words);
    assertEmpty(properties);
}
Also used : PropertySequence(org.apache.jackrabbit.commons.flat.PropertySequence) TreeManager(org.apache.jackrabbit.commons.flat.TreeManager) BTreeManager(org.apache.jackrabbit.commons.flat.BTreeManager) ValueFactory(javax.jcr.ValueFactory) BTreeManager(org.apache.jackrabbit.commons.flat.BTreeManager)

Example 50 with ValueFactory

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

the class MoveTest method testMoveNodeWithGlobRestriction.

public void testMoveNodeWithGlobRestriction() throws Exception {
    Session testSession = getTestSession();
    AccessControlManager testAcMgr = getTestACManager();
    ValueFactory vf = superuser.getValueFactory();
    /*
        precondition:
        testuser must have READ-only permission on test-node and below
        */
    checkReadOnly(path);
    checkReadOnly(childNPath);
    Node node3 = superuser.getNode(childNPath).addNode(nodeName3);
    superuser.save();
    String node3Path = node3.getPath();
    Privilege[] privileges = privilegesFromName(NameConstants.JCR_READ.toString());
    // permissions defined @ path
    // restriction: remove read priv to nodeName3 node
    Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, childNPath));
    restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/" + nodeName3));
    withdrawPrivileges(childNPath, privileges, restrictions);
    assertFalse(testSession.nodeExists(node3Path));
    assertFalse(testAcMgr.hasPrivileges(node3Path, privileges));
    String movedChildNPath = path + "/movedNode";
    String movedNode3Path = movedChildNPath + "/" + node3.getName();
    superuser.move(childNPath, movedChildNPath);
    superuser.save();
    assertFalse(testSession.nodeExists(movedNode3Path));
    assertFalse(testAcMgr.hasPrivileges(movedNode3Path, privileges));
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) HashMap(java.util.HashMap) Node(javax.jcr.Node) Value(javax.jcr.Value) ValueFactory(javax.jcr.ValueFactory) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session)

Aggregations

ValueFactory (javax.jcr.ValueFactory)105 Value (javax.jcr.Value)51 Node (javax.jcr.Node)50 Session (javax.jcr.Session)40 Test (org.junit.Test)17 RepositoryException (javax.jcr.RepositoryException)16 InputStream (java.io.InputStream)13 AccessControlManager (javax.jcr.security.AccessControlManager)13 HashMap (java.util.HashMap)12 Privilege (javax.jcr.security.Privilege)12 Property (javax.jcr.Property)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Query (javax.jcr.query.Query)8 Calendar (java.util.Calendar)7 QueryManager (javax.jcr.query.QueryManager)7 RowIterator (javax.jcr.query.RowIterator)7 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)7 NodeIterator (javax.jcr.NodeIterator)6 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)6 IOException (java.io.IOException)5