Search in sources :

Example 71 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class CacheValidatorProviderTest method testChangePrimaryType.

@Test
public void testChangePrimaryType() throws RepositoryException {
    for (Authorizable a : authorizables) {
        try {
            NodeUtil node = new NodeUtil(getAuthorizableTree(a));
            NodeUtil cache = node.addChild("childNode", JcrConstants.NT_UNSTRUCTURED);
            root.commit();
            cache.setName(JcrConstants.JCR_PRIMARYTYPE, CacheConstants.NT_REP_CACHE);
            cache.setLong(CacheConstants.REP_EXPIRATION, 1);
            root.commit();
            fail("Changing primary type of residual node below an user/group to rep:Cache must fail.");
        } catch (CommitFailedException e) {
            assertTrue(e.isConstraintViolation());
            assertEquals(34, e.getCode());
        } finally {
            root.refresh();
        }
    }
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 72 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class CacheValidatorProviderTest method testNestedCache.

@Test
public void testNestedCache() throws Exception {
    NodeUtil cache = new NodeUtil(getCache(getTestUser()));
    try {
        NodeUtil c = cache.getOrAddChild(CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE);
        c.setLong(CacheConstants.REP_EXPIRATION, 223);
        root.commit(CacheValidatorProvider.asCommitAttributes());
        fail("Creating nested cache must fail.");
    } catch (CommitFailedException e) {
        assertTrue(e.isConstraintViolation());
        assertEquals(34, e.getCode());
    } finally {
        root.refresh();
    }
}
Also used : CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 73 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class CacheValidatorProviderTest method testCreateCacheByName.

@Test
public void testCreateCacheByName() throws RepositoryException {
    for (Authorizable a : authorizables) {
        try {
            NodeUtil node = new NodeUtil(getAuthorizableTree(a));
            node.addChild(CacheConstants.REP_CACHE, JcrConstants.NT_UNSTRUCTURED);
            root.commit();
            fail("Creating rep:cache node below a user or group must fail.");
        } catch (CommitFailedException e) {
            assertTrue(e.isConstraintViolation());
            assertEquals(34, e.getCode());
        } finally {
            root.refresh();
        }
    }
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 74 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class CacheValidatorProviderTest method testModifyCache.

@Test
public void testModifyCache() throws Exception {
    List<PropertyState> props = new ArrayList();
    props.add(PropertyStates.createProperty(CacheConstants.REP_EXPIRATION, 25));
    props.add(PropertyStates.createProperty(CacheConstants.REP_GROUP_PRINCIPAL_NAMES, EveryonePrincipal.NAME));
    props.add(PropertyStates.createProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME));
    props.add(PropertyStates.createProperty("residualProp", "anyvalue"));
    Tree cache = getCache(getTestUser());
    for (PropertyState prop : props) {
        try {
            cache.setProperty(prop);
            root.commit(CacheValidatorProvider.asCommitAttributes());
            fail("Modifying rep:cache node below a user or group must fail.");
        } catch (CommitFailedException e) {
            assertTrue(e.isConstraintViolation());
            assertEquals(34, e.getCode());
        } finally {
            root.refresh();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 75 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class CacheValidatorProviderTest method testCreateCacheBelowProfile.

@Test
public void testCreateCacheBelowProfile() throws Exception {
    try {
        NodeUtil node = new NodeUtil(getAuthorizableTree(getTestUser()));
        NodeUtil child = node.addChild("profile", NodeTypeConstants.NT_OAK_UNSTRUCTURED);
        child.addChild(CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE).setLong(CacheConstants.REP_EXPIRATION, 23);
        root.commit(CacheValidatorProvider.asCommitAttributes());
        fail("Creating rep:cache node below a user or group must fail.");
    } catch (CommitFailedException e) {
        assertTrue(e.isConstraintViolation());
        assertEquals(34, e.getCode());
    } finally {
        root.refresh();
    }
}
Also used : CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)246 Test (org.junit.Test)166 Tree (org.apache.jackrabbit.oak.api.Tree)75 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)66 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)60 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)59 Root (org.apache.jackrabbit.oak.api.Root)48 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)42 RepositoryException (javax.jcr.RepositoryException)17 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)13 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)13 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)12 Nonnull (javax.annotation.Nonnull)10 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)10 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)10 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)10 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)9 ArrayList (java.util.ArrayList)8 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)8 UserManager (org.apache.jackrabbit.api.security.user.UserManager)7