use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class AtomicCounterEditorTest method noHookInWhiteboard.
@Test
public void noHookInWhiteboard() throws CommitFailedException, InterruptedException, ExecutionException {
NodeStore store = new MemoryNodeStore();
MyExecutor exec1 = new MyExecutor();
Whiteboard board = new DefaultWhiteboard();
EditorHook hook1 = new EditorHook(new TestableACEProvider(CLUSTER_1, exec1, store, board));
NodeBuilder builder, root;
PropertyState p;
root = store.getRoot().builder();
builder = root.child("c");
builder = setMixin(builder);
builder = incrementBy(builder, INCREMENT_BY_1);
store.merge(root, hook1, CommitInfo.EMPTY);
// as we're providing all the information we expect the counter not to be consolidated for
// as long as the scheduled process has run
builder = store.getRoot().builder().getChildNode("c");
assertTrue(builder.exists());
p = builder.getProperty(PREFIX_PROP_REVISION + CLUSTER_1.getInstanceId());
assertNotNull(p);
assertEquals(1, p.getValue(LONG).longValue());
p = builder.getProperty(PREFIX_PROP_COUNTER + CLUSTER_1.getInstanceId());
assertNotNull(p);
assertEquals(1, p.getValue(LONG).longValue());
p = builder.getProperty(PROP_COUNTER);
assertEquals(1, p.getValue(LONG).longValue());
assertTrue("without a registered hook it should have fell to sync", exec1.isEmpty());
// fetching the latest store state to see the changes
builder = store.getRoot().builder().getChildNode("c");
assertTrue("the counter node should exists", builder.exists());
assertCounterNodeState(builder, ImmutableSet.of(PREFIX_PROP_COUNTER + CLUSTER_1.getInstanceId(), PREFIX_PROP_REVISION + CLUSTER_1.getInstanceId()), 1);
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook 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());
}
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook 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);
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook 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());
}
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook 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());
}
}
Aggregations