NestedCugHook implements PostValidationHook, CugConstants { @NotNull @Override public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) { NodeBuilder builder = after.builder(); after.compareAgainstBaseState(before, new Diff(before, builder)); deletedCUGs.clear(); moveSources.clear(); return builder.getNodeState(); }  @NotNull @Override NodeState processCommit(NodeState before, NodeState after, CommitInfo info); @Override String toString();  }
@Test public void testHiddenChildNodeAdded() throws Exception { NestedCugHook nch = new NestedCugHook(); NodeState before = getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH)); NodeState after = spy(before); NodeState child = mock(NodeState.class); Iterable newCnes = Collections.singleton(new MemoryChildNodeEntry(":hidden", child)); Iterable cnes = Iterables.concat(newCnes, before.getChildNodeEntries()); when(after.getChildNodeEntries()).thenReturn(cnes); when(after.getChildNode(":hidden")).thenReturn(child); nch.processCommit(before, after, new CommitInfo("sid", null)); verify(child, never()).getProperty(anyString()); }
@Test public void testHiddenChildNodeChanged() { NestedCugHook nch = new NestedCugHook(); NodeState nodeState = getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH)); NodeState after = spy(nodeState); NodeState before = spy(nodeState); NodeState child = mock(NodeState.class); Iterable hidden = Collections.singleton(new MemoryChildNodeEntry(":hidden", child)); Iterable cnes = Iterables.concat(hidden, nodeState.getChildNodeEntries()); when(before.getChildNodeEntries()).thenReturn(cnes); when(before.getChildNode(":hidden")).thenReturn(child); NodeState child2 = when(mock(NodeState.class).exists()).thenReturn(true).getMock(); hidden = Collections.singleton(new MemoryChildNodeEntry(":hidden", child2)); cnes = Iterables.concat(hidden, nodeState.getChildNodeEntries()); when(after.getChildNodeEntries()).thenReturn(cnes); when(after.getChildNode(":hidden")).thenReturn(child2); nch.processCommit(before, after, new CommitInfo("sid", null)); verify(child, never()).getProperty(anyString()); verify(child2, never()).getProperty(anyString()); }
@Test public void testHiddenChildNodeDeleted() { NestedCugHook nch = new NestedCugHook(); NodeState after = getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH)); NodeState before = spy(after); NodeState child = mock(NodeState.class); Iterable deletedCnes = Collections.singleton(new MemoryChildNodeEntry(":hidden", child)); Iterable cnes = Iterables.concat(deletedCnes, after.getChildNodeEntries()); when(before.getChildNodeEntries()).thenReturn(cnes); when(before.getChildNode(":hidden")).thenReturn(child); nch.processCommit(before, after, new CommitInfo("sid", null)); verify(child, never()).getProperty(anyString()); }
@Test public void testRemoveWithInvalidHiddenNestedCugEntry() throws Exception { createCug("/content", getTestGroupPrincipal()); createCug("/content/subtree", EveryonePrincipal.getInstance()); root.commit(); removeCug("/content", false); NodeState after = getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH)); NodeBuilder before = new MemoryNodeBuilder(getTreeProvider().asNodeState(adminSession.getLatestRoot().getTree(PathUtils.ROOT_PATH))); NodeBuilder cugNode = before.getChildNode("content").getChildNode("rep:cugPolicy"); cugNode.setProperty(HIDDEN_NESTED_CUGS, ImmutableList.of("/nested/out/of/hierarchy", "/content/subtree"), Type.STRINGS); NestedCugHook nch = new NestedCugHook(); nch.processCommit(before.getNodeState(), after, new CommitInfo("sid", null)); }
@Test public void testRemoveWithMissingHiddenNestedCugEntry() throws Exception { createCug("/content", getTestGroupPrincipal()); createCug("/content/subtree", EveryonePrincipal.getInstance()); root.commit(); removeCug("/content/subtree", false); NodeBuilder after = new MemoryNodeBuilder(getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH))); NodeBuilder cugNode = after.getChildNode("content").getChildNode("rep:cugPolicy"); cugNode.setProperty(HIDDEN_NESTED_CUGS, ImmutableList.of(), Type.STRINGS); NodeState before = getTreeProvider().asNodeState(adminSession.getLatestRoot().getTree(PathUtils.ROOT_PATH)); NestedCugHook nch = new NestedCugHook(); nch.processCommit(before, after.getNodeState(), new CommitInfo("sid", null)); }
@Test public void testRemoveWithMissingHiddenNestedCugEntry2() throws Exception { createCug("/content", getTestGroupPrincipal()); createCug("/content/subtree", EveryonePrincipal.getInstance()); root.commit(); removeCug("/content/subtree", false); removeCug("/content", false); NodeState after = getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH)); NodeBuilder before = new MemoryNodeBuilder(getTreeProvider().asNodeState(adminSession.getLatestRoot().getTree(PathUtils.ROOT_PATH))); NodeBuilder cugNode = before.getChildNode("content").getChildNode("rep:cugPolicy"); cugNode.setProperty(HIDDEN_NESTED_CUGS, ImmutableList.of(), Type.STRINGS); NestedCugHook nch = new NestedCugHook(); nch.processCommit(before.getNodeState(), after, new CommitInfo("sid", null)); }
@Test public void testRemoveWithMissingHiddenNestedCugProperty() throws Exception { createCug("/content", getTestGroupPrincipal()); createCug("/content/subtree", EveryonePrincipal.getInstance()); root.commit(); removeCug("/content/subtree", false); removeCug("/content", false); NodeState after = getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH)); NodeBuilder before = new MemoryNodeBuilder(getTreeProvider().asNodeState(adminSession.getLatestRoot().getTree(PathUtils.ROOT_PATH))); NodeBuilder cugNode = before.getChildNode("content").getChildNode("rep:cugPolicy"); cugNode.removeProperty(HIDDEN_NESTED_CUGS); NestedCugHook nch = new NestedCugHook(); nch.processCommit(before.getNodeState(), after, new CommitInfo("sid", null)); }
@Test public void testRemoveWithMissingHiddenNestedCugEntryAtRootNode() throws Exception { createCug("/content", getTestGroupPrincipal()); createCug("/content/subtree", EveryonePrincipal.getInstance()); root.commit(); removeCug("/content", false); NodeBuilder after = new MemoryNodeBuilder(getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH))); after.setProperty(HIDDEN_NESTED_CUGS, ImmutableList.of(), Type.STRINGS); after.setProperty(HIDDEN_TOP_CUG_CNT, 0); NodeState before = getTreeProvider().asNodeState(adminSession.getLatestRoot().getTree(PathUtils.ROOT_PATH)); NestedCugHook nch = new NestedCugHook(); nch.processCommit(before, after.getNodeState(), new CommitInfo("sid", null)); }
@Test public void testRemoveWithMissingNestedCugPolicy() throws Exception { createCug("/content", getTestGroupPrincipal()); createCug("/content/subtree", EveryonePrincipal.getInstance()); root.commit(); removeCug("/content", false); NodeState rootState = getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH)); NodeState afterSubtree = spy(NodeStateUtils.getNode(rootState, "content/subtree")); when(afterSubtree.hasChildNode("rep:cugPolicy")).thenReturn(false); NodeState afterContent = spy(rootState.getChildNode("content")); when(afterContent.getChildNode("subtree")).thenReturn(afterSubtree); NodeState after = spy(rootState); when(after.getChildNode("content")).thenReturn(afterContent); NodeState before = getTreeProvider().asNodeState(adminSession.getLatestRoot().getTree(PathUtils.ROOT_PATH)); NestedCugHook nch = new NestedCugHook(); nch.processCommit(before, after, new CommitInfo("sid", null)); }