Search in sources :

Example 96 with Event

use of javax.jcr.observation.Event in project jackrabbit by apache.

the class GetIdentifierTest method testNodeAdded.

public void testNodeAdded() throws RepositoryException {
    Event[] events = getEvents(new Callable() {

        public void call() throws RepositoryException {
            testRootNode.addNode(nodeName1, testNodeType);
            testRootNode.getSession().save();
        }
    }, Event.NODE_ADDED);
    Node n = testRootNode.getNode(nodeName1);
    assertEquals(n.getIdentifier(), getEventByPath(events, n.getPath()).getIdentifier());
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event) RepositoryException(javax.jcr.RepositoryException)

Example 97 with Event

use of javax.jcr.observation.Event in project jackrabbit by apache.

the class GetIdentifierTest method testNodeRemoved.

public void testNodeRemoved() throws RepositoryException {
    final Node n = testRootNode.addNode(nodeName1, testNodeType);
    String path = n.getPath();
    testRootNode.getSession().save();
    String identifier = n.getIdentifier();
    Event[] events = getEvents(new Callable() {

        public void call() throws RepositoryException {
            n.remove();
            testRootNode.getSession().save();
        }
    }, Event.NODE_REMOVED);
    assertEquals(identifier, getEventByPath(events, path).getIdentifier());
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event) RepositoryException(javax.jcr.RepositoryException)

Example 98 with Event

use of javax.jcr.observation.Event in project jackrabbit by apache.

the class PropertyChangedTest method testMultiPropertyChanged.

/**
     * Tests if {@link javax.jcr.observation.Event#PROPERTY_CHANGED} are
     * triggered when multiple properties are changed.
     * @throws RepositoryException
     */
public void testMultiPropertyChanged() throws RepositoryException {
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    node.setProperty(propertyName1, "foo");
    node.setProperty(propertyName2, "bar");
    testRootNode.getSession().save();
    EventResult result = new EventResult(log);
    addEventListener(result, Event.PROPERTY_CHANGED);
    node.getProperty(propertyName1).setValue("foobar");
    node.getProperty(propertyName2).setValue("foobar");
    testRootNode.getSession().save();
    Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
    removeEventListener(result);
    checkPropertyChanged(events, new String[] { nodeName1 + "/" + propertyName1, nodeName1 + "/" + propertyName2 });
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event)

Example 99 with Event

use of javax.jcr.observation.Event in project jackrabbit by apache.

the class PropertyRemovedTest method testMultiPropertyRemoved.

/**
     * Tests if {@link javax.jcr.observation.Event#PROPERTY_REMOVED} are
     * triggered when multiple properties are removed.
     */
public void testMultiPropertyRemoved() throws RepositoryException {
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    Property prop1 = node.setProperty(propertyName1, "foo");
    Property prop2 = node.setProperty(propertyName2, "bar");
    testRootNode.getSession().save();
    EventResult result = new EventResult(log);
    addEventListener(result, Event.PROPERTY_REMOVED);
    prop1.remove();
    prop2.remove();
    testRootNode.getSession().save();
    Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
    removeEventListener(result);
    checkPropertyRemoved(events, new String[] { nodeName1 + "/" + propertyName1, nodeName1 + "/" + propertyName2 });
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event) Property(javax.jcr.Property)

Example 100 with Event

use of javax.jcr.observation.Event in project jackrabbit by apache.

the class PropertyRemovedTest method testSinglePropertyRemoved.

/**
     * Tests if a {@link javax.jcr.observation.Event#PROPERTY_REMOVED} is
     * triggered when a property is removed.
     */
public void testSinglePropertyRemoved() throws RepositoryException {
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    Property prop1 = node.setProperty(propertyName1, "foo");
    node.setProperty(propertyName2, "bar");
    testRootNode.getSession().save();
    EventResult result = new EventResult(log);
    addEventListener(result, Event.PROPERTY_REMOVED);
    prop1.remove();
    testRootNode.getSession().save();
    Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
    removeEventListener(result);
    checkPropertyRemoved(events, new String[] { nodeName1 + "/" + propertyName1 });
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event) Property(javax.jcr.Property)

Aggregations

Event (javax.jcr.observation.Event)136 Node (javax.jcr.Node)103 Test (org.junit.Test)55 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)46 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)40 RepositoryException (javax.jcr.RepositoryException)29 Session (javax.jcr.Session)20 JackrabbitEventFilter (org.apache.jackrabbit.api.observation.JackrabbitEventFilter)19 EventResult (org.apache.jackrabbit.test.api.observation.EventResult)17 EventIterator (javax.jcr.observation.EventIterator)15 Property (javax.jcr.Property)13 ObservationManager (javax.jcr.observation.ObservationManager)13 SlingRepository (org.apache.sling.jcr.api.SlingRepository)10 ArrayList (java.util.ArrayList)9 Scheduler (org.apache.sling.commons.scheduler.Scheduler)9 DistributionRequest (org.apache.sling.distribution.DistributionRequest)9 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)8 PathNotFoundException (javax.jcr.PathNotFoundException)7 EventListener (javax.jcr.observation.EventListener)7 JackrabbitObservationManager (org.apache.jackrabbit.api.observation.JackrabbitObservationManager)7