Search in sources :

Example 21 with JackrabbitEventFilter

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());
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Event(javax.jcr.observation.Event) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 22 with JackrabbitEventFilter

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/**" });
}
Also used : JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) OakEventFilter(org.apache.jackrabbit.oak.jcr.observation.filter.OakEventFilter) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 23 with JackrabbitEventFilter

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());
}
Also used : JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 24 with JackrabbitEventFilter

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());
}
Also used : JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 25 with JackrabbitEventFilter

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());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) OakEventFilter(org.apache.jackrabbit.oak.jcr.observation.filter.OakEventFilter) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Aggregations

JackrabbitEventFilter (org.apache.jackrabbit.api.observation.JackrabbitEventFilter)25 Node (javax.jcr.Node)19 Event (javax.jcr.observation.Event)19 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)19 Test (org.junit.Test)19 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)18 JackrabbitObservationManager (org.apache.jackrabbit.api.observation.JackrabbitObservationManager)7 FilterProvider (org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider)6 OakEventFilter (org.apache.jackrabbit.oak.jcr.observation.filter.OakEventFilter)5 Property (javax.jcr.Property)3 Session (javax.jcr.Session)2 ArrayList (java.util.ArrayList)1 RepositoryException (javax.jcr.RepositoryException)1 NodeDefinition (javax.jcr.nodetype.NodeDefinition)1 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)1 ObservationManager (javax.jcr.observation.ObservationManager)1 ExcludeExternal (org.apache.jackrabbit.oak.plugins.observation.ExcludeExternal)1 EventResult (org.apache.jackrabbit.test.api.observation.EventResult)1