use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project jackrabbit-oak by apache.
the class ObservationTest method deepNodeTypeMixinHierarchy.
@Test
public void deepNodeTypeMixinHierarchy() throws Exception {
NodeTypeManager ntm = getAdminSession().getWorkspace().getNodeTypeManager();
NodeTypeTemplate parentMixin = ntm.createNodeTypeTemplate();
parentMixin.setName("parentmixin");
parentMixin.setMixin(true);
ntm.registerNodeType(parentMixin, false);
NodeTypeTemplate childMixin = ntm.createNodeTypeTemplate();
childMixin.setName("childmixin");
childMixin.setMixin(true);
childMixin.setDeclaredSuperTypeNames(new String[] { "parentmixin" });
ntm.registerNodeType(childMixin, false);
NodeTypeTemplate mytype = ntm.createNodeTypeTemplate();
mytype.setName("mytype");
mytype.setMixin(false);
mytype.setDeclaredSuperTypeNames(new String[] { "childmixin" });
NodeDefinitionTemplate child = ntm.createNodeDefinitionTemplate();
child.setName("*");
child.setDefaultPrimaryTypeName("nt:base");
child.setRequiredPrimaryTypeNames(new String[] { "nt:base" });
List<NodeDefinition> children = mytype.getNodeDefinitionTemplates();
children.add(child);
ntm.registerNodeType(mytype, false);
getAdminSession().save();
// create a fresh session here to catch the above new node type definitions
observingSession = createAdminSession();
observationManager = observingSession.getWorkspace().getObservationManager();
JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter().setAbsPath("/").setIsDeep(true).setNodeTypes(new String[] { "parentmixin" }).setEventTypes(ALL_EVENTS);
oManager.addEventListener(listener, filter);
Node n = getNode(TEST_PATH).addNode("n", "mytype");
listener.expect(n.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
Node m = n.addNode("m", "nt:unstructured");
listener.expect(m.getPath(), NODE_ADDED);
getAdminSession().save();
Thread.sleep(1000);
List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
List<Event> unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project jackrabbit-oak by apache.
the class ObservationTest method parentPathExclude.
@Test
public void parentPathExclude() throws ExecutionException, InterruptedException, RepositoryException {
assumeTrue(observationManager instanceof JackrabbitObservationManager);
Node n = getNode(TEST_PATH).addNode("n");
getAdminSession().save();
JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter().setAbsPath(n.getPath()).setIsDeep(true).setExcludedPaths(n.getParent().getPath()).setEventTypes(ALL_EVENTS);
oManager.addEventListener(listener, filter);
n.addNode("n1");
getAdminSession().save();
List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
List<Event> unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project jackrabbit-oak by apache.
the class ObservationTest method noDuplicates.
@Test
public void noDuplicates() throws ExecutionException, InterruptedException, RepositoryException {
assumeTrue(observationManager instanceof JackrabbitObservationManager);
JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter().setAdditionalPaths(TEST_PATH + "/a", TEST_PATH + "/a").setEventTypes(NODE_ADDED);
oManager.addEventListener(listener, filter);
Node testNode = getNode(TEST_PATH);
Node b = testNode.addNode("a").addNode("b");
b.addNode("c");
Node y = testNode.addNode("x").addNode("y");
y.addNode("z");
listener.expect(b.getPath(), NODE_ADDED);
testNode.getSession().save();
List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
List<Event> unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
Aggregations