Search in sources :

Example 81 with Event

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

the class GetIdentifierTest method testNodeMoved.

public void testNodeMoved() throws RepositoryException {
    final Node n = testRootNode.addNode(nodeName1, testNodeType);
    testRootNode.getSession().save();
    Event[] events = getEvents(new Callable() {

        public void call() throws RepositoryException {
            superuser.getWorkspace().move(n.getPath(), testRoot + "/" + nodeName2);
        }
    }, Event.NODE_MOVED);
    String path = testRootNode.getNode(nodeName2).getPath();
    assertEquals(n.getIdentifier(), getEventByPath(events, path).getIdentifier());
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event) RepositoryException(javax.jcr.RepositoryException)

Example 82 with Event

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

the class GetIdentifierTest method testPropertyChanged.

public void testPropertyChanged() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    final Property prop = n.setProperty(propertyName1, "test");
    testRootNode.getSession().save();
    Event[] events = getEvents(new Callable() {

        public void call() throws RepositoryException {
            prop.setValue("modified");
            testRootNode.getSession().save();
        }
    }, Event.PROPERTY_CHANGED);
    assertEquals(n.getIdentifier(), getEventByPath(events, prop.getPath()).getIdentifier());
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property)

Example 83 with Event

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

the class GetInfoTest method testNodeRemoved.

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

        public void call() throws RepositoryException {
            n.remove();
            testRootNode.getSession().save();
        }
    }, Event.NODE_REMOVED);
    for (int i = 0; i < events.length; i++) {
        Set<?> unexpectedKeys = getUnexpectedKeys(events[i].getInfo());
        assertEquals("info map must be empty", 0, unexpectedKeys.size());
    }
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event) RepositoryException(javax.jcr.RepositoryException)

Example 84 with Event

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

the class GetInfoTest method testPropertyRemoved.

public void testPropertyRemoved() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    final Property prop = n.setProperty(propertyName1, "test");
    testRootNode.getSession().save();
    Event[] events = getEvents(new Callable() {

        public void call() throws RepositoryException {
            Session s = prop.getSession();
            prop.remove();
            s.save();
        }
    }, Event.PROPERTY_REMOVED);
    for (int i = 0; i < events.length; i++) {
        Set<?> unexpectedKeys = getUnexpectedKeys(events[i].getInfo());
        assertEquals("info map must be empty: " + unexpectedKeys, 0, unexpectedKeys.size());
    }
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 85 with Event

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

the class EventJournalTest method testPersist.

public void testPersist() throws RepositoryException, NotExecutableException {
    Node n1 = testRootNode.addNode(nodeName1);
    journal = getEventJournal(Event.PERSIST, testRoot, true, null, null);
    skipToNow();
    superuser.save();
    boolean hasPersistEvents = journal.hasNext();
    if (!hasPersistEvents) {
        throw new NotExecutableException("repository does not appear to provide PERSIST events");
    }
    journal = getEventJournal(ALL_TYPES | Event.PERSIST, testRoot, true, null, null);
    skipToNow();
    // add another child node
    Node n3 = testRootNode.addNode(nodeName2);
    String target = n1.getPath();
    n1.remove();
    superuser.save();
    // move it
    superuser.getWorkspace().move(n3.getPath(), target);
    // remove it again
    n3 = superuser.getNode(target);
    n3.remove();
    superuser.save();
    int persistCount = 0;
    Event e = null;
    while (journal.hasNext()) {
        e = journal.nextEvent();
        if (e.getType() == Event.PERSIST) {
            persistCount += 1;
        }
    }
    assertEquals(3, persistCount);
    // last event should be persist
    assertEquals(Event.PERSIST, e.getType());
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Event(javax.jcr.observation.Event)

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