use of javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method propertyValues.
@Test
public void propertyValues() throws RepositoryException, ExecutionException, InterruptedException {
Node n = getNode(TEST_PATH);
n.setProperty("toChange", new String[] { "one", "two" }, PropertyType.STRING);
n.setProperty("toDelete", new String[] { "three", "four" }, PropertyType.STRING);
getAdminSession().save();
ExpectationListener listener = new ExpectationListener();
observationManager.addEventListener(listener, ALL_EVENTS, "/", true, null, null, false);
try {
n.setProperty("added", new String[] { "five", "six" }, PropertyType.STRING);
listener.expectValues(null, n.getProperty("added").getValues());
Value[] before = n.getProperty("toChange").getValues();
n.getProperty("toChange").setValue(new String[] { "1", "2" });
listener.expectValues(before, n.getProperty("toChange").getValues());
before = n.getProperty("toDelete").getValues();
n.getProperty("toDelete").remove();
listener.expectValues(before, null);
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());
} finally {
observationManager.removeEventListener(listener);
}
}
use of javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method testAggregate2.
@Test
public void testAggregate2() throws Exception {
assumeTrue(observationManager instanceof ObservationManagerImpl);
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter();
filter.setAbsPath("/parent");
filter.setIsDeep(true);
filter.setEventTypes(ALL_EVENTS);
filter = FilterFactory.wrap(filter).withNodeTypeAggregate(new String[] { "oak:Unstructured" }, // "file", "file/jcr:content",
new String[] { "", "**" });
// "file/jcr:content/**");
oManager.addEventListener(listener, filter);
Node parent = getAdminSession().getRootNode().addNode("parent", "nt:unstructured");
// OAK-5096: in OR mode the following event also gets sent:
listener.expect(parent.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
Node child = parent.addNode("child", "oak:Unstructured");
listener.expectAdd(child);
Node file = child.addNode("file", "nt:unstructured");
listener.expectAdd(file);
Node jcrContent = file.addNode("jcr:content", "nt:unstructured");
listener.expect(jcrContent.getPath(), "/parent/child", NODE_ADDED);
listener.expect(jcrContent.getPath() + "/jcr:primaryType", "/parent/child", PROPERTY_ADDED);
Property jcrDataProperty = jcrContent.setProperty("jcr:data", "foo");
listener.expect(jcrDataProperty.getPath(), "/parent/child", PROPERTY_ADDED);
parent.getSession().save();
List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
List<Event> unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
assertTrue("Missing events: " + missing, missing.isEmpty());
file = getAdminSession().getRootNode().getNode("parent").getNode("child").getNode("file");
jcrContent = file.getNode("jcr:content");
Property newProperty = jcrContent.setProperty("newProperty", "foo");
listener.expect(newProperty.getPath(), "/parent/child", PROPERTY_ADDED);
Property lastModifiedBy = jcrContent.setProperty("jcr:lastModifiedBy", "bar");
listener.expect(lastModifiedBy.getPath(), "/parent/child", PROPERTY_ADDED);
jcrContent.getSession().save();
Thread.sleep(2000);
missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
assertTrue("Missing events: " + missing, missing.isEmpty());
}
use of javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method testConsecutiveGlobPaths.
@Test
public void testConsecutiveGlobPaths() throws Exception {
Node testNode = getNode(TEST_PATH);
Node a1 = testNode.addNode("a1");
a1.addNode("b1").addNode("c1");
a1.addNode("b2").addNode("c2");
testNode.addNode("a2").addNode("b").addNode("c");
testNode.getSession().save();
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter();
filter.setEventTypes(ALL_EVENTS);
filter = FilterFactory.wrap(filter).withIncludeGlobPaths(TEST_PATH + "/a2/**").withIncludeGlobPaths(TEST_PATH + "/a1/**");
oManager.addEventListener(listener, filter);
ChangeProcessor cp = oManager.getChangeProcessor(listener);
assertNotNull(cp);
FilterProvider filterProvider = cp.getFilterProvider();
assertNotNull(filterProvider);
assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a1", TEST_PATH + "/a2");
listener.expectRemove(testNode.getNode("a1").getNode("b2")).remove();
listener.expectRemove(testNode.getNode("a2").getNode("b")).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());
}
use of javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method pathFilterWithTrailingSlash.
@Test
public void pathFilterWithTrailingSlash() throws Exception {
final String path = "/events/only/here";
ExpectationListener listener = new ExpectationListener();
listener.expect(new Expectation(path) {
@Override
public boolean onEvent(Event event) throws Exception {
return PathUtils.isAncestor(path, event.getPath());
}
});
observationManager.addEventListener(listener, NODE_ADDED, path + '/', true, null, null, false);
try {
Node root = getNode("/");
root.addNode("events").addNode("only").addNode("here").addNode("at");
root.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());
} finally {
observationManager.removeEventListener(listener);
}
}
use of javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method addSubtreeFilter.
@Test
public void addSubtreeFilter() throws RepositoryException, ExecutionException, InterruptedException {
assumeTrue(observationManager instanceof ObservationManagerImpl);
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
FilterBuilder builder = new FilterBuilder();
// Only generate events for the root of added sub trees
builder.condition(builder.addSubtree());
oManager.addEventListener(listener, builder.build());
Node testNode = getNode(TEST_PATH);
Node a = listener.expectAdd(testNode.addNode("a"));
a.addNode("c");
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());
}
Aggregations