PrivilegeValidator extends DefaultValidator implements PrivilegeConstants { @Override public Validator childNodeDeleted(String name, NodeState before) throws CommitFailedException { if (isPrivilegeDefinition(before)) { throw new CommitFailedException(CONSTRAINT, 42, "Attempt to un-register privilege " + name); } else { return null; } } PrivilegeValidator(@NotNull Root before, @NotNull Root after, @NotNull TreeProvider treeProvider); @Override void propertyAdded(PropertyState after); @Override void propertyChanged(PropertyState before, PropertyState after); @Override void propertyDeleted(PropertyState before); @Override Validator childNodeAdded(String name, NodeState after); @Override Validator childNodeChanged(String name, NodeState before, NodeState after); @Override Validator childNodeDeleted(String name, NodeState before);  }
@Test public void testOtherNodeDeleted() throws Exception { NodeState ns = mock(NodeState.class); PrivilegeValidator validator = createPrivilegeValidator(); assertNull(validator.childNodeDeleted("test", ns)); when(ns.getProperty(JCR_PRIMARYTYPE)).thenReturn(PropertyStates.createProperty(JCR_PRIMARYTYPE, NT_OAK_UNSTRUCTURED, Type.NAME)); assertNull(validator.childNodeDeleted("test", ns)); }
@Test(expected = CommitFailedException.class) public void testChildNodeDeleted() throws Exception { try { root.getTree(PRIVILEGES_PATH).getChild(JCR_READ).remove(); root.commit(); } catch (CommitFailedException e) { throw assertCommitFailed(e, 42); } }