use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter 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.JackrabbitEventFilter in project jackrabbit-oak by apache.
the class ObservationTest method testAggregate6.
// OAK-5096 : a specific **/*.jsp test case
@Test
public void testAggregate6() throws Exception {
OakEventFilter oef = FilterFactory.wrap(new JackrabbitEventFilter());
oef.setEventTypes(ALL_EVENTS);
oef.setIsDeep(true);
oef.withIncludeAncestorsRemove().withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "", "jcr:content" }).withIncludeGlobPaths("/**/*.jsp");
doTestAggregate6(oef, new String[] { "/" }, new String[] { "/**", "/**/*.jsp", "/**/*.jsp/**" });
oef = FilterFactory.wrap(new JackrabbitEventFilter());
oef.setEventTypes(ALL_EVENTS);
oef.setIsDeep(false);
oef.withIncludeAncestorsRemove().withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "", "jcr:content" }).withIncludeGlobPaths("/**/*.jsp");
doTestAggregate6(oef, new String[] { "/" }, new String[] { "/**", "/**/*.jsp", "/**/*.jsp/**" });
oef = FilterFactory.wrap(new JackrabbitEventFilter());
oef.setEventTypes(ALL_EVENTS);
oef.withIncludeAncestorsRemove().withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "", "jcr:content" }).withIncludeGlobPaths("**/*.jsp");
doTestAggregate6(oef, new String[] { "/" }, new String[] { "/**", "**/*.jsp", "**/*.jsp/**" });
oef = FilterFactory.wrap(new JackrabbitEventFilter());
oef.setEventTypes(ALL_EVENTS);
// without includeAncestorsRemove this time
oef.withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "", "jcr:content" }).withIncludeGlobPaths("/**/*.jsp");
doTestAggregate6(oef, new String[] { "" }, new String[] { "/**/*.jsp", "/**/*.jsp/**" });
oef = FilterFactory.wrap(new JackrabbitEventFilter());
oef.setEventTypes(ALL_EVENTS);
// without includeAncestorsRemove this time
oef.withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "", "jcr:content" }).withIncludeGlobPaths("**/*.jsp");
doTestAggregate6(oef, new String[] { "" }, new String[] { "**/*.jsp", "**/*.jsp/**" });
oef = FilterFactory.wrap(new JackrabbitEventFilter());
oef.setEventTypes(ALL_EVENTS);
oef.withIncludeAncestorsRemove().withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "", "jcr:content" }).withIncludeGlobPaths("/parent/**/*.jsp");
doTestAggregate6(oef, new String[] { "/" }, new String[] { "/parent", "/parent/**", "/parent/**/*.jsp", "/parent/**/*.jsp/**" });
oef = FilterFactory.wrap(new JackrabbitEventFilter());
oef.setEventTypes(ALL_EVENTS);
oef.withIncludeAncestorsRemove().withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "", "jcr:content" }).withIncludeGlobPaths("/parent/bar/**/*.jsp");
doTestAggregate6(oef, new String[] { "/" }, new String[] { "/parent", "/parent/bar", "/parent/bar/**", "/parent/bar/**/*.jsp", "/parent/bar/**/*.jsp/**" });
oef = FilterFactory.wrap(new JackrabbitEventFilter());
oef.setEventTypes(ALL_EVENTS);
// without includeAncestorsRemove this time
oef.withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "", "jcr:content" }).withIncludeGlobPaths("/parent/**/*.jsp");
doTestAggregate6(oef, new String[] { "/parent" }, new String[] { "/parent/**/*.jsp", "/parent/**/*.jsp/**" });
oef = FilterFactory.wrap(new JackrabbitEventFilter());
oef.setEventTypes(ALL_EVENTS);
// without includeAncestorsRemove this time
oef.withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "", "jcr:content" }).withIncludeGlobPaths("/parent/**/*.jsp", "/foo/bar/**");
doTestAggregate6(oef, new String[] { "/parent", "/foo/bar" }, new String[] { "/foo/bar/**", "/parent/**/*.jsp", "/parent/**/*.jsp/**" });
oef = FilterFactory.wrap(new JackrabbitEventFilter());
oef.setEventTypes(ALL_EVENTS);
oef.withIncludeAncestorsRemove().withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "", "jcr:content" }).withIncludeGlobPaths("/parent/**/*.jsp", "/foo/bar/**");
doTestAggregate6(oef, new String[] { "/" }, new String[] { "/parent", "/foo", "/foo/bar", "/foo/bar/**", "/parent/**", "/parent/**/*.jsp", "/parent/**/*.jsp/**" });
}
use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter 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.JackrabbitEventFilter 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());
}
use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit-oak by apache.
the class ObservationTest method includeRemovedSubtree_Globs.
@Test
public void includeRemovedSubtree_Globs() throws Exception {
assumeTrue(observationManager instanceof ObservationManagerImpl);
Node testNode = getNode(TEST_PATH);
testNode.addNode("a").addNode("b").addNode("c").addNode("d.jsp");
testNode.addNode("e").addNode("f").addNode("g.jsp");
testNode.getSession().save();
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter();
OakEventFilter oef = FilterFactory.wrap(filter);
oef.setEventTypes(ALL_EVENTS);
oef.withIncludeGlobPaths(TEST_PATH + "/a/**/*.jsp");
oef.withNodeTypeAggregate(new String[] { "nt:unstructured" }, new String[] { "" });
oef.withIncludeSubtreeOnRemove();
oManager.addEventListener(listener, oef);
// the glob is for a jsp - so we should (only) get an event for that
// but only for the properties of d.jsp that get removed, not of removal of d.jsp itself
// as that would again be reported towards the parent of d.jsp which is /a/b/c
Node dDotJsp = testNode.getNode("a").getNode("b").getNode("c").getNode("d.jsp");
listener.expect(dDotJsp.getPath() + "/jcr:primaryType", dDotJsp.getPath(), PROPERTY_REMOVED);
// but we're removing /a/b
testNode.getNode("a").getNode("b").remove();
// and for removal of /e nothing should be generated
testNode.getNode("e").remove();
testNode.getSession().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());
}
Aggregations