Search in sources :

Example 6 with JackrabbitObservationManager

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());
}
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 7 with JackrabbitObservationManager

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());
}
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 8 with JackrabbitObservationManager

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());
}
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)

Aggregations

JackrabbitObservationManager (org.apache.jackrabbit.api.observation.JackrabbitObservationManager)8 Node (javax.jcr.Node)7 Event (javax.jcr.observation.Event)7 JackrabbitEventFilter (org.apache.jackrabbit.api.observation.JackrabbitEventFilter)7 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)6 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)6 Test (org.junit.Test)6 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 OakEventFilter (org.apache.jackrabbit.oak.jcr.observation.filter.OakEventFilter)1 FilterBuilder (org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder)1 EventResult (org.apache.jackrabbit.test.api.observation.EventResult)1