Search in sources :

Example 81 with ValueFactory

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();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Query(javax.jcr.query.Query) HashMap(java.util.HashMap) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) Value(javax.jcr.Value) QueryManager(javax.jcr.query.QueryManager) GuestCredentials(javax.jcr.GuestCredentials) Session(javax.jcr.Session) Test(org.junit.Test)

Example 82 with ValueFactory

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"));
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) QValueValue(org.apache.jackrabbit.spi.commons.value.QValueValue) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) ValueFactory(javax.jcr.ValueFactory) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Session(javax.jcr.Session) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 83 with ValueFactory

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();
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ValueFactory(javax.jcr.ValueFactory) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 84 with ValueFactory

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();
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) Session(javax.jcr.Session) Before(org.junit.Before)

Example 85 with ValueFactory

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();
}
Also used : Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

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