5152535455565758596061
} @Test public void testEmptyPortfolioIsReturnedWhenAllNodesAreDenied() { SimplePortfolioNode root = nodeTree(1, nodeTree(2, nodeTree(4)), nodeTree(3)); Portfolio pf = new SimplePortfolio("node-1", root); Portfolio portfolio = new NodeCheckingPortfolioFilter(createDenyNodeChecker()).generateRestrictedPortfolio(pf); assertThat(portfolio.getRootNode().size(), is(0));
7475767778798081828384
3 is denied 4 is allowed Portfolio should just contain 1, 2 & 4 (1 is a restricted version though) */ SimplePortfolioNode root = nodeTree(1, nodeTree(2), nodeTree(3), nodeTree(4)); Portfolio pf = new SimplePortfolio("node-1", root); Map<Integer, PortfolioPermission> permissions = ImmutableMap.of( 1, ALLOW, 2, ALLOW,
111112113114115116117118119120121
3 is denied 4 is denied Portfolio should just contain 2 */ SimplePortfolioNode root = nodeTree(1, nodeTree(2), nodeTree(3), nodeTree(4)); Portfolio pf = new SimplePortfolio("node-1", root); Map<Integer, PortfolioPermission> permissions = ImmutableMap.of( 1, ALLOW, 2, ALLOW,
149150151152153154155156157158159
6 is allowed 7 is allowed Portfolio should just contain 5, 6, 7 */ SimplePortfolioNode root = nodeTree(1, nodeTree(2, nodeTree(5, nodeTree(6), nodeTree(7))),
214215216217218219220221222223224
17 is allowed Portfolio should contain 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 17 */ SimplePortfolioNode root = nodeTree(1, nodeTree(2, nodeTree(4, nodeTree(9), nodeTree(10)),
353637383940414243
} /* package */ static SimplePortfolioNode nodeTree(int id, PortfolioNode... children) { String nodeId = "node-" + id; SimplePortfolioNode node = new SimplePortfolioNode(UniqueId.of("TEST", nodeId), nodeId); node.addChildNodes(Arrays.asList(children)); return node; }
313233343536373839
public class PortfolioPermissionCheckerTest { @Test public void testNonExistentNodeIsDenied() { SimplePortfolioNode node = new SimplePortfolioNode("not in the portfolio"); PortfolioPermissionChecker checker = new PortfolioPermissionChecker(new SimplePortfolio("test"), createAllowNodeChecker()); assertThat(checker.permissionCheck(node), is(DENY)); }
3940414243444546474849
} @Test public void testSingleNodeWithAllow() { SimplePortfolioNode node = new SimplePortfolioNode(); PortfolioPermissionChecker checker = new PortfolioPermissionChecker(new SimplePortfolio("test", node), createAllowNodeChecker()); assertThat(checker.permissionCheck(node), is(ALLOW));
5051525354555657585960
} @Test public void testSingleNodeWithDeny() { SimplePortfolioNode node = new SimplePortfolioNode(); PortfolioPermissionChecker checker = new PortfolioPermissionChecker(new SimplePortfolio("test", node), createDenyNodeChecker()); assertThat(checker.permissionCheck(node), is(DENY));
6162636465666768697071
} @Test public void testAllChildrenAllowMeansParentAllows() { SimplePortfolioNode root = nodeTree(1, nodeTree(2), nodeTree(3), nodeTree(4));