@Test public void testEvaluateContainmentContextOnce() { tested.evaluate(ruleSet, containmentContext); tested.evaluate(ruleSet, containmentContext); verify(ruleSet, times(1)).getRules(); verify(containmentHandler, times(2)).evaluate(eq(containmentRule), eq(containmentContext)); verify(connectionHandler, never()).evaluate(any(CanConnect.class), any(ConnectionContext.class)); }
@Test public void testEvaluateConnectionContextOnce() { tested.evaluate(ruleSet, connectionContext); tested.evaluate(ruleSet, connectionContext); verify(ruleSet, times(1)).getRules(); verify(connectionHandler, times(2)).evaluate(eq(connectionRule), eq(connectionContext)); verify(containmentHandler, never()).evaluate(any(CanContain.class), any(ContainmentContext.class)); } }
@Override public RuleViolations evaluate(final CanConnect rule, final GraphConnectionContext context) { final Edge<? extends View<?>, ? extends Node> connector = context.getConnector(); final Node<? extends View<?>, ? extends Edge> source = context.getSource().orElse(null); final Node<? extends View<?>, ? extends Edge> target = context.getTarget().orElse(null); if (source == null || target == null) { return new DefaultRuleViolations(); } final Set<String> edgeLabels = evalUtils.getLabels(connector); final Optional<Set<String>> sourceLabels = Optional.of(evalUtils.getLabels(source)); final Optional<Set<String>> targetLabels = Optional.of(evalUtils.getLabels(target)); final DefaultRuleViolations result = new DefaultRuleViolations(); edgeLabels.stream() .filter(pr -> rule.getRole().equals(pr)) .forEach(pr -> result.addViolations(connectionEvaluationHandler .evaluate(rule, RuleContextBuilder.DomainContexts.connection(pr, sourceLabels, targetLabels)))); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(connector.getUUID(), result); } }
@Test public void testEvaluateSuccess2() { final Set<String> sourceRoles = new HashSet<String>(1) {{ add("r2"); }}; final Set<String> targetRoles = new HashSet<String>(1) {{ add("o2"); }}; when(context.getConnectorRole()).thenReturn(EDGE_ID); when(context.getSourceRoles()).thenReturn(Optional.of(sourceRoles)); when(context.getTargetRoles()).thenReturn(Optional.of(targetRoles)); final RuleViolations violations = tested.evaluate(RULE, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test public void testEvaluateFailed1() { final Set<String> sourceRoles = new HashSet<String>(1) {{ add("r1"); }}; final Set<String> targetRoles = new HashSet<String>(1) {{ add("o2"); }}; when(context.getConnectorRole()).thenReturn(EDGE_ID); when(context.getSourceRoles()).thenReturn(Optional.of(sourceRoles)); when(context.getTargetRoles()).thenReturn(Optional.of(targetRoles)); final RuleViolations violations = tested.evaluate(RULE, context); assertNotNull(violations); assertTrue(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test public void testEvaluateSuccess1() { final Set<String> sourceRoles = new HashSet<String>(1) {{ add("r1"); }}; final Set<String> targetRoles = new HashSet<String>(1) {{ add("o1"); }}; when(context.getConnectorRole()).thenReturn(EDGE_ID); when(context.getSourceRoles()).thenReturn(Optional.of(sourceRoles)); when(context.getTargetRoles()).thenReturn(Optional.of(targetRoles)); final RuleViolations violations = tested.evaluate(RULE, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test public void testEvaluateFailed2() { final Set<String> sourceRoles = new HashSet<String>(1) {{ add("r2"); }}; final Set<String> targetRoles = new HashSet<String>(1) {{ add("o1"); }}; when(context.getConnectorRole()).thenReturn(EDGE_ID); when(context.getSourceRoles()).thenReturn(Optional.of(sourceRoles)); when(context.getTargetRoles()).thenReturn(Optional.of(targetRoles)); final RuleViolations violations = tested.evaluate(RULE, context); assertNotNull(violations); assertTrue(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); } }