Search in sources :

Example 86 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class TypeEditorTest method changeMandatoryPropertyToBadRequiredType.

@Test
public void changeMandatoryPropertyToBadRequiredType() {
    EditorHook hook = new EditorHook(new TypeEditorProvider());
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeBuilder acl = builder.child(AccessControlConstants.REP_POLICY);
    acl.setProperty(JCR_PRIMARYTYPE, AccessControlConstants.NT_REP_ACL, Type.NAME);
    NodeBuilder ace = acl.child("first");
    ace.setProperty(JCR_PRIMARYTYPE, AccessControlConstants.NT_REP_GRANT_ACE, Type.NAME);
    ace.setProperty(AccessControlConstants.REP_PRINCIPAL_NAME, EveryonePrincipal.NAME);
    ace.setProperty(AccessControlConstants.REP_PRIVILEGES, ImmutableList.of(PrivilegeConstants.JCR_READ), Type.NAMES);
    NodeState before = builder.getNodeState();
    // change to invalid type
    ace.setProperty(AccessControlConstants.REP_PRIVILEGES, ImmutableList.of(PrivilegeConstants.JCR_READ), Type.STRINGS);
    try {
        hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
        fail();
    } catch (CommitFailedException e) {
        assertTrue(e.isConstraintViolation());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 87 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class TypeEditorTest method addMandatoryPropertyWithBadRequiredType.

@Test
public void addMandatoryPropertyWithBadRequiredType() {
    EditorHook hook = new EditorHook(new TypeEditorProvider());
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeState before = builder.getNodeState();
    NodeBuilder acl = builder.child(AccessControlConstants.REP_POLICY);
    acl.setProperty(JCR_PRIMARYTYPE, AccessControlConstants.NT_REP_ACL, Type.NAME);
    NodeBuilder ace = acl.child("first");
    ace.setProperty(JCR_PRIMARYTYPE, AccessControlConstants.NT_REP_GRANT_ACE, Type.NAME);
    ace.setProperty(AccessControlConstants.REP_PRINCIPAL_NAME, EveryonePrincipal.NAME);
    ace.setProperty(AccessControlConstants.REP_PRIVILEGES, ImmutableList.of(PrivilegeConstants.JCR_READ), Type.STRINGS);
    try {
        hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
        fail();
    } catch (CommitFailedException e) {
        assertTrue(e.isConstraintViolation());
        assertEquals(55, e.getCode());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 88 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class EmptyCugTreePermissionTest method testJcrSystemPermissions.

@Test
public void testJcrSystemPermissions() throws Exception {
    NodeState system = rootState.getChildNode(JcrConstants.JCR_SYSTEM);
    TreePermission systemTp = tp.getChildPermission(JcrConstants.JCR_SYSTEM, system);
    assertCugPermission(systemTp, false);
    assertCugPermission(pp.getTreePermission(root.getTree("/jcr:system"), tp), false);
    NodeState versionStore = system.getChildNode(VersionConstants.JCR_VERSIONSTORAGE);
    TreePermission versionStoreTp = systemTp.getChildPermission(VersionConstants.JCR_VERSIONSTORAGE, versionStore);
    assertCugPermission(versionStoreTp, false);
    assertCugPermission(pp.getTreePermission(root.getTree(VersionConstants.VERSION_STORE_PATH), systemTp), false);
    NodeState nodeTypes = system.getChildNode(NodeTypeConstants.JCR_NODE_TYPES);
    TreePermission nodeTypesTp = systemTp.getChildPermission(NodeTypeConstants.JCR_NODE_TYPES, nodeTypes);
    assertSame(TreePermission.NO_RECOURSE, nodeTypesTp);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) TreePermission(org.apache.jackrabbit.oak.spi.security.authorization.permission.TreePermission) Test(org.junit.Test)

Example 89 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class CugUtilTest method testHasCugNodeState.

@Test
public void testHasCugNodeState() throws Exception {
    assertTrue(CugUtil.hasCug(getNodeState(root.getTree(SUPPORTED_PATH))));
    assertFalse(CugUtil.hasCug((NodeState) null));
    for (String path : new String[] { PathUtils.ROOT_PATH, INVALID_PATH, UNSUPPORTED_PATH, SUPPORTED_PATH + "/subtree", SUPPORTED_PATH2, SUPPORTED_PATH3 }) {
        assertFalse(CugUtil.hasCug(getNodeState(root.getTree(path))));
    }
    new NodeUtil(root.getTree(SUPPORTED_PATH2)).addChild(REP_CUG_POLICY, NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    assertTrue(CugUtil.hasCug(getNodeState(root.getTree(SUPPORTED_PATH2))));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 90 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class DocumentRootBuilder method reset.

/**
     * Reset this builder by creating a new branch and setting the head
     * state of that branch as the new base state of this builder.
     */
NodeState reset() {
    branch = store.createBranch(store.getRoot());
    NodeState head = branch.getHead();
    reset(head);
    return head;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState)

Aggregations

NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)580 Test (org.junit.Test)375 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)254 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)69 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)46 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)45 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)43 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)39 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)36 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)33 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)32 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)29 Nonnull (javax.annotation.Nonnull)28 Tree (org.apache.jackrabbit.oak.api.Tree)23 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.upgrade.util.NodeStateTestUtils.getNodeState)23 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)19 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)18 ArrayList (java.util.ArrayList)17 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)16 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)15