Search in sources :

Example 41 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 42 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 43 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 44 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 45 with NodeState

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

the class CommitContextTest method attributeAddedByCommitHook.

@Test
public void attributeAddedByCommitHook() throws Exception {
    repository = new Oak(store).with(new OpenSecurityProvider()).with(observer).with(new CommitHook() {

        @Nonnull
        @Override
        public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
            CommitContext attrs = (CommitContext) info.getInfo().get(CommitContext.NAME);
            assertNotNull(attrs);
            attrs.set("foo", "bar");
            return after;
        }
    }).createContentRepository();
    session = newSession();
    Root root = session.getLatestRoot();
    Tree tree = root.getTree("/");
    tree.setProperty("a", 1);
    root.commit();
    assertNotNull(observer.info);
    CommitContext attrs = (CommitContext) observer.info.getInfo().get(CommitContext.NAME);
    assertNotNull(attrs.get("foo"));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Root(org.apache.jackrabbit.oak.api.Root) Nonnull(javax.annotation.Nonnull) Oak(org.apache.jackrabbit.oak.Oak) Tree(org.apache.jackrabbit.oak.api.Tree) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Aggregations

NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)779 Test (org.junit.Test)498 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)335 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)94 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)61 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)60 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)54 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)48 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)46 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)41 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)36 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)33 Nonnull (javax.annotation.Nonnull)32 Tree (org.apache.jackrabbit.oak.api.Tree)29 ArrayList (java.util.ArrayList)25 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.plugins.migration.NodeStateTestUtils.getNodeState)23 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.upgrade.util.NodeStateTestUtils.getNodeState)23 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)22 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)22 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)17