Search in sources :

Example 81 with NodeState

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

the class TypeEditorTest method addNamedPropertyWithBadRequiredType.

@Test
public void addNamedPropertyWithBadRequiredType() {
    EditorHook hook = new EditorHook(new TypeEditorProvider());
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeState before = builder.getNodeState();
    NodeBuilder testNode = builder.child("testNode");
    testNode.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, Type.NAME);
    testNode.setProperty(JCR_MIXINTYPES, ImmutableList.of("mix:title"), Type.NAMES);
    testNode.setProperty("jcr:title", true);
    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 82 with NodeState

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

the class TypeEditorTest method requiredTypeIsUndefined.

@Test
public void requiredTypeIsUndefined() throws CommitFailedException {
    EditorHook hook = new EditorHook(new TypeEditorProvider());
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeState before = builder.getNodeState();
    builder.setProperty("any", "title");
    NodeState after = builder.getNodeState();
    hook.processCommit(before, after, CommitInfo.EMPTY);
    builder.setProperty("any", 134.34, Type.DOUBLE);
    hook.processCommit(after, builder.getNodeState(), CommitInfo.EMPTY);
}
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) Test(org.junit.Test)

Example 83 with NodeState

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

the class TypeEditorTest method malformedUUID.

@Test
public void malformedUUID() throws CommitFailedException {
    EditorHook hook = new EditorHook(new TypeEditorProvider());
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeState before = builder.getNodeState();
    builder.child("testcontent").setProperty(JCR_PRIMARYTYPE, "nt:unstructured", Type.NAME);
    builder.child("testcontent").setProperty("jcr:uuid", "not-a-uuid");
    NodeState after = builder.getNodeState();
    root = hook.processCommit(before, after, CommitInfo.EMPTY);
    builder = root.builder();
    before = builder.getNodeState();
    builder.child("testcontent").setProperty(JCR_MIXINTYPES, ImmutableList.of(MIX_REFERENCEABLE), Type.NAMES);
    try {
        hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
        fail("should not be able to change mixin due to illegal uuid format");
    } 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 84 with NodeState

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

the class TypeEditorTest method changeNodeTypeWExtraProps.

@Test
public void changeNodeTypeWExtraProps() throws CommitFailedException {
    EditorHook hook = new EditorHook(new TypeEditorProvider());
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeState before = builder.getNodeState();
    builder.child("testcontent").setProperty(JCR_PRIMARYTYPE, "nt:unstructured", Type.NAME);
    builder.child("testcontent").setProperty("extra", "information");
    NodeState after = builder.getNodeState();
    root = hook.processCommit(before, after, CommitInfo.EMPTY);
    builder = root.builder();
    before = builder.getNodeState();
    builder.child("testcontent").setProperty(JCR_PRIMARYTYPE, "nt:folder", Type.NAME);
    try {
        hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
        fail("should not be able to change node type due to extra properties");
    } 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 85 with NodeState

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

the class TypeEditorTest method changeNamedPropertyToBadRequiredType.

@Test
public void changeNamedPropertyToBadRequiredType() {
    EditorHook hook = new EditorHook(new TypeEditorProvider());
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeBuilder testNode = builder.child("testNode");
    testNode.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, Type.NAME);
    testNode.setProperty(JCR_MIXINTYPES, ImmutableList.of("mix:title"), Type.NAMES);
    testNode.setProperty("jcr:title", "title");
    NodeState before = builder.getNodeState();
    testNode.setProperty("jcr:title", true);
    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)

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