@Override public boolean accepts(final RuleExtension rule, final NodeContainmentContext context) { if (!GraphUtils.hasConnections(context.getCandidate())) { //this is not necessary to check rules in case there is no connections return false; } return acceptsContainment(rule, context); }
private boolean acceptsContainment(final RuleExtension rule, final NodeContainmentContext context) { final Optional<Class<?>> parentType = getParentType(rule, context.getParent()); if (!hasParentType(rule) || !parentType.isPresent()) { return true; } final String expectedParentId = parentType.map(BindableAdapterUtils::getDefinitionId).orElse(null); final Element<? extends Definition<?>> parent = context.getParent(); final Node<? extends Definition<?>, ? extends Edge> candidate = context.getCandidate(); final String parentId = evalUtils.getElementDefinitionId(parent); return parentId.equals(expectedParentId) || hasOldParentType(candidate, expectedParentId); }
@Test @SuppressWarnings("unchecked") public void testNotAccepts() { when(ruleExtension.getTypeArguments()).thenReturn(new Class[]{DefinitionC.class}); when(containmentContext.getCandidate()).thenReturn(nodeA); when(containmentContext.getParent()).thenReturn(parentNode); assertFalse(tested.accepts(ruleExtension, containmentContext)); }
@Test @SuppressWarnings("unchecked") public void testAcceptSuccess() { when(context.getParent()).thenReturn(element); when(context.getCandidate()).thenReturn(candidate); final boolean accepts = tested.accepts(RULE, context); assertTrue(accepts); }
@Test @SuppressWarnings("unchecked") public void testAcceptFailed() { when(context.getParent()).thenReturn(parent); when(context.getCandidate()).thenReturn(candidate); final boolean accepts = tested.accepts(RULE, context); assertFalse(accepts); }
@Test @SuppressWarnings("unchecked") public void testAccepts() { when(ruleExtension.getTypeArguments()).thenReturn(new Class[]{ParentDefinition.class}); when(containmentContext.getCandidate()).thenReturn(nodeA); when(containmentContext.getParent()).thenReturn(parentNode); nodeA.getInEdges().add(edge); when(edge.getContent()).thenReturn(viewConnector); assertTrue(tested.accepts(ruleExtension, containmentContext)); }
@Test @SuppressWarnings("unchecked") public void testEvaluateSuccess() { when(context.getCandidate()).thenReturn(candidate); final RuleViolations violations = tested.evaluate(RULE, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test @SuppressWarnings("unchecked") public void testEvaluateFailed() { when(context.getCandidate()).thenReturn(candidate); final RuleViolations violations = tested.evaluate(RULE_INVALID, context); assertNotNull(violations); assertTrue(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); } }
@Test @SuppressWarnings("unchecked") public void testEvaluateParentSuccess() { when(ruleExtension.getTypeArguments()).thenReturn(new Class[]{ParentDefinition.class}); when(containmentContext.getCandidate()).thenReturn(nodeA); when(containmentContext.getParent()).thenReturn(parentNode); graphHandler.addEdge(connector, nodeA) .connectTo(connector, nodeB); final RuleViolations violations = tested.evaluate(ruleExtension, containmentContext); assertNotNull(violations); assertViolations(violations, true); }
@Test @SuppressWarnings("unchecked") public void testEvaluateParentFailed() { when(ruleExtension.getTypeArguments()).thenReturn(new Class[]{ParentDefinition.class}); when(containmentContext.getCandidate()).thenReturn(nodeA); when(containmentContext.getParent()).thenReturn(parentNode); graphHandler.addEdge(connector, nodeA) .connectTo(connector, nodeC); final RuleViolations violations = tested.evaluate(ruleExtension, containmentContext); assertNotNull(violations); assertViolations(violations, false); } }
final Graph<?, ? extends Node> graph = context.getGraph(); final Element<? extends Definition<?>> parent = context.getParent(); final Node<? extends Definition<?>, ? extends Edge> candidate = context.getCandidate();
@Override public RuleViolations evaluate(final CanContain rule, final NodeContainmentContext context) { final Element<? extends Definition<?>> source = context.getParent(); final Node<? extends Definition<?>, ? extends Edge> target = context.getCandidate(); final Set<String> candidateLabels = evalUtils.getLabels(target); final Set<String> parentLabels = evalUtils.getLabels(source); final DefaultRuleViolations result = new DefaultRuleViolations(); result.addViolations( containmentHandler .evaluate(rule, RuleContextBuilder.DomainContexts.containment(parentLabels, candidateLabels)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(target.getUUID(), result); } }
public static void verifyContainment(final NodeContainmentContext containmentContext, final Element<? extends Definition<?>> parent, final Node<? extends Definition<?>, ? extends Edge> candidate) { assertNotNull(containmentContext); final Element<? extends Definition<?>> source = containmentContext.getParent(); final Node<? extends Definition<?>, ? extends Edge> target = containmentContext.getCandidate(); assertNotNull(source); assertEquals(parent, source); assertNotNull(target); assertEquals(candidate, target); }
when(containmentContext.getCandidate()).thenReturn(nodeA); when(containmentContext.getParent()).thenReturn(parentNode);