Author: stefanegli
Date: Thu Feb 9 15:47:19 2017
New Revision: 1782350
URL: http://svn.apache.org/viewvc?rev=1782350&view=rev
Log:
OAK-5619 : includeAncestorsRemove_Unrelated test extended to cover more cases -
still ignored
Modified:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/observation/ObservationTest.java
Modified:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/observation/ObservationTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/observation/ObservationTest.java?rev=1782350&r1=1782349&r2=1782350&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/observation/ObservationTest.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/observation/ObservationTest.java
Thu Feb 9 15:47:19 2017
@@ -42,6 +42,7 @@ import static org.junit.Assert.assertArr
import static org.junit.Assume.assumeTrue;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -1548,45 +1549,171 @@ public class ObservationTest extends Abs
@Test
@Ignore("OAK-5619")
public void includeAncestorsRemove_Unrelated() throws Exception {
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/b/c/d"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/unrelated/child", "/a/b/c/unrelated",
+ "/a/b/unrelated/child", "/a/b/unrelated",
"/a/unrelated/child", "/a/unrelated",
+ "/a"},
+ new String[] {"/a"},
+ new String[] {});
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/b/c/d"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/unrelated/child", "/a/b/c/unrelated",
+ "/a/b/unrelated/child", "/a/b/unrelated",
"/a/unrelated/child", "/a/unrelated",
+ "/a/b"},
+ new String[] {"/a/b"},
+ new String[] {});
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/b/c/d"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/unrelated/child", "/a/b/c/unrelated",
+ "/a/b/unrelated/child", "/a/b/unrelated",
"/a/unrelated/child", "/a/unrelated",
+ "/a/b/c"},
+ new String[] {"/a/b/c"},
+ new String[] {});
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/b/c/d"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/unrelated/child", "/a/b/c/unrelated",
+ "/a/b/unrelated/child", "/a/b/unrelated",
"/a/unrelated/child", "/a/unrelated",
+ "/a/b/c/d"},
+ new String[] {"/a/b/c/d"},
+ new String[] {"/a/b/c/d/jcr:primaryType"});
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/b/c/d/*.html"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/unrelated/child", "/a/b/c/unrelated",
+ "/a/b/unrelated/child", "/a/b/unrelated",
"/a/unrelated/child", "/a/unrelated",
+ "/a/b/c/d"},
+ new String[] {"/a/b/c/d"},
+ new String[] {});
+
+ // and some glob tests:
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/b/*/d"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/unrelated/child", "/a/b/c/unrelated",
+ "/a/b/related/unrelatedchild", "/a/b/related",
"/a/unrelated/child", "/a/unrelated",
+ "/a"},
+ new String[] {"/a", "/a/b/related"},
+ new String[] {});
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/b/**/d"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/related/child", "/a/b/c/related",
+ "/a/b/related/child", "/a/b/related",
"/a/unrelated/child", "/a/unrelated",
+ "/a"},
+ new String[] {"/a", "/a/b/related", "/a/b/related/child",
"/a/b/c/related/child", "/a/b/c/related"},
+ new String[] {});
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/b/**/d/*.html"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/related/child", "/a/b/c/related",
+ "/a/b/related/child", "/a/b/related",
"/a/unrelated/child", "/a/unrelated",
+ "/a"},
+ new String[] {"/a", "/a/b/related", "/a/b/related/child",
"/a/b/c/related/child", "/a/b/c/related"},
+ new String[] {});
+
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/*/c/d"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/unrelated/child", "/a/b/c/unrelated",
+ "/a/b/unrelated/child", "/a/b/unrelated",
"/a/related/unrelatedchild", "/a/related",
+ "/a/b"},
+ new String[] {"/a/b", "/a/related"},
+ new String[] {});
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/**/c/d"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/related/child", "/a/b/c/related",
+ "/a/b/related/child", "/a/b/related",
"/a/related/relatedchild", "/a/related",
+ "/a/b"},
+ new String[] {"/a/b", "/a/related/relatedchild", "/a/related",
"/a/b/related/child", "/a/b/related", "/a/b/c/related/child", "/a/b/c/related"},
+ new String[] {});
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/*/c/*.html"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/unrelated/child", "/a/b/c/unrelated",
+ "/a/b/unrelated/child", "/a/b/unrelated",
"/a/related/unrelatedchild", "/a/related",
+ "/a/b/c/x.html", "/a/b"},
+ new String[] {"/a/b", "/a/related", "/a/b/c/x.html"},
+ new String[] {"/a/b/c/x.html/jcr:primaryType"});
+ doIncludeAncestorsRemove_Unrelated(
+ new String[] {"/a/**/c/*.html"},
+ new String[] {"/unrelated/child", "/unrelated",
"/a/b/c/related/child", "/a/b/c/related",
+ "/a/b/related/child", "/a/b/related",
"/a/related/child", "/a/related",
+ "/a/b"},
+ new String[] {"/a/b", "/a/related/child", "/a/related",
"/a/b/related/child", "/a/b/related", "/a/b/c/related/child", "/a/b/c/related",
"/a/b/c/related/child", "/a/b/c/related"},
+ new String[] {});
+ }
+
+ private void doIncludeAncestorsRemove_Unrelated(String[] absPaths,
+ String[] createAndRemoveNodes, String[] expectedRemoveNodeEvents,
String[] expectedRemovePropertyEvents) throws Exception {
assumeTrue(observationManager instanceof ObservationManagerImpl);
ObservationManagerImpl oManager = (ObservationManagerImpl)
observationManager;
- // [/conf/global/settings/granite/operations/maintenance,
/libs/settings/granite/operations/maintenance,
/apps/settings/granite/operations/maintenance]
- JackrabbitEventFilter filterWithAncestorsRemove = new
JackrabbitEventFilter();
- filterWithAncestorsRemove.setEventTypes(ALL_EVENTS);
- filterWithAncestorsRemove.setAbsPath(TEST_PATH + "/a/b/c/d");
+ OakEventFilter filterWithAncestorsRemove = FilterFactory.wrap(new
JackrabbitEventFilter());
+ filterWithAncestorsRemove.setEventTypes(NODE_REMOVED |
PROPERTY_REMOVED);
+ assertTrue(absPaths.length >= 1);
+ String[] additionalPaths = new String[absPaths.length];
+ System.arraycopy(absPaths, 0, additionalPaths, 0, absPaths.length);
+ if (!absPaths[0].contains("*")) {
+ filterWithAncestorsRemove.setAbsPath(absPaths[0]);
+ if (absPaths.length > 1) {
+ additionalPaths = new String[absPaths.length - 1];
+ System.arraycopy(absPaths, 1, additionalPaths, 0,
absPaths.length - 1);
+ }
+ }
+ filterWithAncestorsRemove.withIncludeGlobPaths(additionalPaths);
filterWithAncestorsRemove.setIsDeep(true);
- filterWithAncestorsRemove =
FilterFactory.wrap(filterWithAncestorsRemove).withIncludeAncestorsRemove();
+ filterWithAncestorsRemove =
filterWithAncestorsRemove.withIncludeAncestorsRemove();
ExpectationListener listenerWithAncestorsRemove = new
ExpectationListener();
oManager.addEventListener(listenerWithAncestorsRemove,
filterWithAncestorsRemove);
- JackrabbitEventFilter filterWithoutAncestorsRemove = new
JackrabbitEventFilter();
- filterWithoutAncestorsRemove.setEventTypes(ALL_EVENTS);
- filterWithoutAncestorsRemove.setAbsPath(TEST_PATH + "/a/b/c/d");
+ OakEventFilter filterWithoutAncestorsRemove = FilterFactory.wrap(new
JackrabbitEventFilter());
+ filterWithoutAncestorsRemove.setEventTypes(NODE_REMOVED);
+ if (!absPaths[0].contains("*")) {
+ filterWithoutAncestorsRemove.setAbsPath(absPaths[0]);
+ }
+ filterWithoutAncestorsRemove.withIncludeGlobPaths(additionalPaths);
filterWithoutAncestorsRemove.setIsDeep(true);
ExpectationListener listenerWithoutAncestorsRemove = new
ExpectationListener();
oManager.addEventListener(listenerWithoutAncestorsRemove,
filterWithoutAncestorsRemove);
Session session = getAdminSession();
- session.getRootNode().addNode("unrelated");
+ for (String path : createAndRemoveNodes) {
+ Iterator<String> it = PathUtils.elements(path).iterator();
+ Node node = session.getRootNode();
+ while(it.hasNext()) {
+ String elem = it.next();
+ if (!node.hasNode(elem)) {
+ node = node.addNode(elem);
+ } else {
+ node = node.getNode(elem);
+ }
+ }
+ }
session.save();
- session.getRootNode().getNode("unrelated").remove();
- Node testNode = session.getRootNode().getNode(TEST_NODE);
- listenerWithAncestorsRemove.expect(testNode.getPath(), NODE_REMOVED);
- testNode.remove();
- session.save();
+ for (String nodePath : expectedRemoveNodeEvents) {
+ listenerWithAncestorsRemove.expect(nodePath, NODE_REMOVED);
+ }
+ for (String propertyPath : expectedRemovePropertyEvents) {
+ listenerWithAncestorsRemove.expect(propertyPath, PROPERTY_REMOVED);
+ }
+
+ for (String path : createAndRemoveNodes) {
+ Iterator<String> it = PathUtils.elements(path).iterator();
+ Node node = session.getRootNode();
+ while(it.hasNext()) {
+ String elem = it.next();
+ node = node.getNode(elem);
+ }
+ node.remove();
+ session.save();
+ }
Thread.sleep(1000);
List<Expectation> missing =
listenerWithoutAncestorsRemove.getMissing(TIME_OUT, TimeUnit.SECONDS);
List<Event> unexpected =
listenerWithoutAncestorsRemove.getUnexpected();
- assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
- assertTrue("Missing events: " + missing, missing.isEmpty());
+ assertTrue("Unexpected events (listenerWithoutAncestorsRemove): " +
unexpected, unexpected.isEmpty());
+ assertTrue("Missing events (listenerWithoutAncestorsRemove): " +
missing, missing.isEmpty());
missing = listenerWithAncestorsRemove.getMissing(TIME_OUT,
TimeUnit.SECONDS);
unexpected = listenerWithAncestorsRemove.getUnexpected();
- assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
- assertTrue("Missing events: " + missing, missing.isEmpty());
+ assertTrue("Unexpected events (listenerWithAncestorsRemove): " +
unexpected, unexpected.isEmpty());
+ assertTrue("Missing events (listenerWithAncestorsRemove): " + missing,
missing.isEmpty());
}
@Test