@Override public boolean accepts(final CanContain rule, final ContainmentContext context) { return context.getParentRoles().contains(rule.getRole()); }
@Test public void testAccepts() { Set<String> candidateRoles = Collections.singleton("role2"); Set<String> parentRoles = Collections.singleton(PARENT_ID); when(context.getParentRoles()).thenReturn(parentRoles); when(context.getCandidateRoles()).thenReturn(candidateRoles); assertTrue(tested.accepts(RULE, context)); parentRoles = Collections.singleton("otherParent"); when(context.getParentRoles()).thenReturn(parentRoles); assertFalse(tested.accepts(RULE, context)); }
@Test public void testEvaluateSuccess() { final Set<String> candidateRoles = new HashSet<String>(1) {{ add("role2"); }}; when(context.getParentRoles()).thenReturn(PARENT_ROLES); when(context.getCandidateRoles()).thenReturn(candidateRoles); final RuleViolations violations = tested.evaluate(RULE, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test public void testEvaluateFailed() { final Set<String> candidateRoles = new HashSet<String>(1) {{ add("role4"); }}; when(context.getParentRoles()).thenReturn(PARENT_ROLES); when(context.getCandidateRoles()).thenReturn(candidateRoles); final RuleViolations violations = tested.evaluate(RULE, context); assertNotNull(violations); assertTrue(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); } }