Search in sources :

Example 36 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 37 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 38 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 39 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 40 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)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