NodeTypePattern implements RestrictionPattern { @Override public boolean matches(@NotNull Tree tree, @Nullable PropertyState property) { return nodeTypeNames.contains(TreeUtil.getPrimaryTypeName(tree)); } NodeTypePattern(@NotNull Iterable<String> nodeTypeNames); @Override boolean matches(@NotNull Tree tree, @Nullable PropertyState property); @Override boolean matches(@NotNull String path); @Override boolean matches(); @Override int hashCode(); @Override String toString(); @Override boolean equals(Object obj);  }
@Test public void testMatchesItem() throws Exception { Tree rootTree = root.getTree("/"); for (String ntName : ntNames) { Tree testTree = TreeUtil.addChild(rootTree, "name", ntName); assertTrue(pattern.matches(testTree, null)); assertTrue(pattern.matches(testTree, PropertyStates.createProperty("a", Boolean.FALSE))); assertTrue(pattern.matches(testTree, PropertyStates.createProperty("f", "anyval"))); testTree.remove(); } }
@Test public void testNotMatchesItem() throws Exception { Tree rootTree = root.getTree("/"); List<String> notMatching = ImmutableList.of(NodeTypeConstants.NT_OAK_RESOURCE, NodeTypeConstants.NT_OAK_UNSTRUCTURED, JcrConstants.NT_VERSION); for (String ntName : notMatching) { Tree testTree = TreeUtil.addChild(rootTree, "name", ntName); assertFalse(pattern.matches(testTree, null)); assertFalse(pattern.matches(testTree, PropertyStates.createProperty("a", Boolean.FALSE))); assertFalse(pattern.matches(testTree, PropertyStates.createProperty("f", "anyval"))); testTree.remove(); } }
@Test public void testMatchesPath() { List<String> notMatching = ImmutableList.of("/", "/a", "/b", "/c", "/d/e/a", "/a/b/c/d/b", "/test/c", "/d", "/b/d", "/d/e/f", "/c/b/abc"); for (String p : notMatching) { assertFalse(pattern.matches(p)); } }
@Test public void testMatchesNull() { assertFalse(pattern.matches()); }