@Override public boolean accepts(final CanDock rule, final NodeDockingContext context) { final Set<String> parentLabels = evalUtils.getLabels(context.getParent()); // As for acceptance checking, the delegated handler only needs the parent node id, no need // to calculate roles for the candidate node, so using an empty set. return dockingHandler.accepts(rule, RuleContextBuilder.DomainContexts.docking(parentLabels, Collections.emptySet())); }
@Before public void setup() throws Exception { tested = new DockingEvaluationHandler(); }
@Test public void testEvaluateSuccess() { final Set<String> candidateRoles = new HashSet<String>(1) {{ add("drole2"); }}; 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("drole4"); }}; 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()); } }
@Override public RuleViolations evaluate(final CanDock rule, final NodeDockingContext context) { final Node<? extends Definition<?>, ? extends Edge> target = context.getCandidate(); final Set<String> parentLabels = evalUtils.getLabels(context.getParent()); final Set<String> candidateLabels = evalUtils.getLabels(target); final DefaultRuleViolations result = new DefaultRuleViolations(); result.addViolations( dockingHandler .evaluate(rule, RuleContextBuilder.DomainContexts.docking(parentLabels, candidateLabels)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(target.getUUID(), result); } }
@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("anotherParent"); when(context.getParentRoles()).thenReturn(parentRoles); assertFalse(tested.accepts(RULE, context)); }