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);
}
}
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);
}
}
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();
}
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);
}
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));
}
Aggregations