use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class CompatibilityIssuesTest method testSearchDescendentUsingXPath.
@Test
public void testSearchDescendentUsingXPath() throws Exception {
Session adminSession = getAdminSession();
String testNodePath = "/home/users/geometrixx-outdoors/emily.andrews@mailinator.com/social/relationships/following/aaron.mcdonald@mailinator.com";
Node testNode = JcrUtils.getOrCreateByPath(testNodePath, null, adminSession);
testNode.setProperty("id", "aaron.mcdonald@mailinator.com");
AccessControlManager acMgr = adminSession.getAccessControlManager();
JackrabbitAccessControlList tmpl = AccessControlUtils.getAccessControlList(acMgr, "/home/users/geometrixx-outdoors");
ValueFactory vf = adminSession.getValueFactory();
Map<String, Value> restrictions = new HashMap<String, Value>();
restrictions.put("rep:glob", vf.createValue("*/social/relationships/following/*"));
tmpl.addEntry(EveryonePrincipal.getInstance(), new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ) }, true, restrictions);
acMgr.setPolicy(tmpl.getPath(), tmpl);
adminSession.save();
Session anonymousSession = getRepository().login(new GuestCredentials());
QueryManager qm = anonymousSession.getWorkspace().getQueryManager();
Query q = qm.createQuery("/jcr:root/home//social/relationships/following//*[@id='aaron.mcdonald@mailinator.com']", Query.XPATH);
QueryResult r = q.execute();
RowIterator it = r.getRows();
Assert.assertTrue(it.hasNext());
anonymousSession.logout();
}
use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class RepositoryTest method workspaceCopyWithReferences.
@Test
public void workspaceCopyWithReferences() throws RepositoryException {
Session session = getAdminSession();
ValueFactory vf = session.getValueFactory();
Node root = session.getRootNode();
Node other = root.addNode("other");
other.addMixin("mix:referenceable");
Node src = root.addNode("src");
Node test = src.addNode("test");
test.addMixin("mix:referenceable");
src.setProperty("test", test);
src.setProperty("other", other);
src.setProperty("multi", new Value[] { vf.createValue(test), vf.createValue(other) });
session.save();
session.getWorkspace().copy("/src", "/dest");
Node dest = root.getNode("dest");
assertEquals("/dest/test", dest.getProperty("test").getNode().getPath());
assertEquals("/other", dest.getProperty("other").getNode().getPath());
Value[] refs = dest.getProperty("multi").getValues();
assertEquals(2, refs.length);
Set<String> paths = new HashSet<String>();
for (Value v : refs) {
paths.add(session.getNodeByIdentifier(v.getString()).getPath());
}
assertTrue(paths.contains("/other"));
assertTrue(paths.contains("/dest/test"));
}
use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class NodeTypeTest method removeNodeType.
@Test
public void removeNodeType() throws Exception {
Session session = getAdminSession();
Node root = session.getRootNode();
ValueFactory vf = session.getValueFactory();
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
Node n = root.addNode("q1", "nt:query");
n.setProperty("jcr:statement", vf.createValue("statement"));
n.setProperty("jcr:language", vf.createValue("language"));
session.save();
try {
manager.unregisterNodeType("nt:query");
fail();
} catch (ConstraintViolationException expected) {
// this type is referenced in content, so it can't be removed
}
n.remove();
session.save();
try {
manager.unregisterNodeType("nt:query");
// no longer referenced in content, so removal should succeed
} catch (ConstraintViolationException unexpected) {
fail();
}
}
use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class RepositoryTest method setup.
@Before
public void setup() throws RepositoryException {
Session session = getAdminSession();
ValueFactory valueFactory = session.getValueFactory();
Node root = session.getRootNode();
Node foo = root.addNode("foo");
foo.setProperty("stringProp", "stringVal");
foo.setProperty("intProp", 42);
foo.setProperty("mvProp", new Value[] { valueFactory.createValue(1), valueFactory.createValue(2), valueFactory.createValue(3) });
root.addNode("bar");
root.addNode(TEST_NODE);
session.save();
}
use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class NodeTypeTest method illegalAddNodeWithProps.
@Test(expected = ConstraintViolationException.class)
public void illegalAddNodeWithProps() throws Exception {
Session session = getAdminSession();
Node root = session.getRootNode();
ValueFactory vf = session.getValueFactory();
Node n = root.addNode("q1", "nt:query");
n.setProperty("jcr:statement", vf.createValue("statement"));
n.setProperty("jcr:language", vf.createValue("language"));
Node n2 = n.addNode("q2", "nt:query");
n2.setProperty("jcr:statement", vf.createValue("statement"));
n2.setProperty("jcr:language", vf.createValue("language"));
session.save();
}
Aggregations