CugContext implements Context, CugConstants { @Override public boolean definesLocation(@NotNull TreeLocation location) { PropertyState p = location.getProperty(); Tree tree = (p == null) ? location.getTree() : location.getParent().getTree(); if (tree != null) { return (p == null) ? definesTree(tree) : definesProperty(tree, p); } else { String path = location.getPath(); return REP_CUG_POLICY.equals(Text.getName(path)) || path.endsWith(REP_CUG_POLICY + '/' + REP_PRINCIPAL_NAMES); } } private  CugContext(); @Override boolean definesProperty(@NotNull Tree parent, @NotNull PropertyState property); @Override boolean definesContextRoot(@NotNull Tree tree); @Override boolean definesTree(@NotNull Tree tree); @Override boolean definesLocation(@NotNull TreeLocation location); @Override boolean definesInternal(@NotNull Tree tree);  }
@Test public void testDefinesLocation() { assertTrue(CugContext.INSTANCE.definesLocation(TreeLocation.create(root, CUG_PATH))); assertTrue(CugContext.INSTANCE.definesLocation(TreeLocation.create(root, CUG_PATH + "/" + CugConstants.REP_PRINCIPAL_NAMES))); List<String> existingNoCug = ImmutableList.of( "/content", "/content/a", "/content/rep:policy" ); for (String path : existingNoCug) { assertFalse(path, CugContext.INSTANCE.definesLocation(TreeLocation.create(root, path))); assertFalse(path, CugContext.INSTANCE.definesLocation(TreeLocation.create(root, path + "/" + CugConstants.REP_PRINCIPAL_NAMES))); } List<String> nonExistingCug = ImmutableList.of( "/content/rep:cugPolicy", UNSUPPORTED_PATH + "/rep:cugPolicy"); for (String path : nonExistingCug) { assertTrue(path, CugContext.INSTANCE.definesLocation(TreeLocation.create(root, path))); assertTrue(path, CugContext.INSTANCE.definesLocation(TreeLocation.create(root, path + "/" + CugConstants.REP_PRINCIPAL_NAMES))); assertFalse(path, CugContext.INSTANCE.definesLocation(TreeLocation.create(root, path + "/" + JcrConstants.JCR_PRIMARYTYPE))); } }