use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class ReferenceIndexTest method basicReferenceHandling.
@Test
public void basicReferenceHandling() throws Exception {
NodeState root = INITIAL_CONTENT;
NodeBuilder builder = root.builder();
NodeState before = builder.getNodeState();
builder.child("a").setProperty(createProperty("foo", "u1", Type.REFERENCE));
builder.child("b").setProperty(createProperty("foo", "u1", Type.REFERENCE));
builder.child("c").setProperty(createProperty("foo", "u2", Type.WEAKREFERENCE));
NodeState after = builder.getNodeState();
EditorHook hook = new EditorHook(new IndexUpdateProvider(new ReferenceEditorProvider()));
NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
FilterImpl f = createFilter(indexed, NT_BASE);
f.restrictProperty("*", Operator.EQUAL, newReference("u1"), PropertyType.REFERENCE);
assertFilter(f, new ReferenceIndex(), indexed, of("/a", "/b"));
FilterImpl f2 = createFilter(indexed, NT_BASE);
f2.restrictProperty("*", Operator.EQUAL, newReference("u2"), PropertyType.WEAKREFERENCE);
assertFilter(f2, new ReferenceIndex(), indexed, of("/c"));
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class TypeEditorTest method ignoreHidden.
@Test
public void ignoreHidden() throws CommitFailedException {
EditorHook hook = new EditorHook(new TypeEditorProvider());
NodeState root = INITIAL_CONTENT;
NodeBuilder builder = root.builder();
NodeState before = builder.getNodeState();
builder.child(":hidden");
NodeState after = builder.getNodeState();
hook.processCommit(before, after, CommitInfo.EMPTY);
before = after;
builder.child(":hidden").setProperty("prop", "value");
after = builder.getNodeState();
hook.processCommit(before, after, CommitInfo.EMPTY);
before = after;
builder.getChildNode(":hidden").remove();
after = builder.getNodeState();
hook.processCommit(before, after, CommitInfo.EMPTY);
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class TypeEditorTest method changeNodeTypeWExtraNodes.
@Test
public void changeNodeTypeWExtraNodes() 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").child("unstructured_child").setProperty(JCR_PRIMARYTYPE, "nt:unstructured", Type.NAME);
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 nodes");
} 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 changeNodeTypeNewBroken.
@Test
public void changeNodeTypeNewBroken() 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:folder", Type.NAME);
builder.child("testcontent").setProperty("extra", "information");
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());
}
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class NodeStoreTest method addExistingNodeJCRLastModified.
@Test
public void addExistingNodeJCRLastModified() throws CommitFailedException {
CommitHook hook = new CompositeHook(new ConflictHook(JcrConflictHandler.createJcrConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
NodeBuilder b1 = store.getRoot().builder();
NodeBuilder b2 = store.getRoot().builder();
Calendar calendar = Calendar.getInstance();
b1.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
calendar.add(Calendar.MINUTE, 1);
b2.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
b1.setChildNode("conflict");
b2.setChildNode("conflict");
store.merge(b1, hook, CommitInfo.EMPTY);
store.merge(b2, hook, CommitInfo.EMPTY);
}
Aggregations