@Test @SuppressWarnings("unchecked") public void testEvaluateInNoLimit() { when(evalUtils.countEdges(anyString(), any(List.class))).thenReturn(0); when(context.getDirection()).thenReturn(EdgeCardinalityContext.Direction.INCOMING); when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD)); RuleViolations violations = tested.evaluate(RULE_IN_NO_LIMIT, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final EdgeOccurrences rule, final ConnectorCardinalityContext context) { final GraphEvaluationState.ConnectorCardinalityState cardinalityState = context.getState().getConnectorCardinalityState(); final DefaultRuleViolations result = new DefaultRuleViolations(); final Node<? extends View<?>, Edge> candidate = (Node<? extends View<?>, Edge>) context.getCandidate(); final Edge<? extends View<?>, Node> edge = context.getEdge(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = context.getDirection(); final Collection<? extends Edge> edges = isIncoming(direction) ? cardinalityState.getIncoming(candidate) : cardinalityState.getOutgoing(candidate); final String edgeId = evalUtils.getElementDefinitionId(edge); final int count = evalUtils.countEdges(edgeId, edges); result.addViolations( edgeCardinalityEvaluationHandler .evaluate(rule, RuleEvaluationContextBuilder.DomainContexts.edgeCardinality(candidate.getLabels(), edgeId, count, rule.getDirection(), operation)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(edge.getUUID(), result); }
ConnectorCardinalityEvaluationHandler implements RuleEvaluationHandler<EdgeOccurrences, ConnectorCardinalityContext> { @Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final EdgeOccurrences rule, final ConnectorCardinalityContext context) { final GraphEvaluationState.ConnectorCardinalityState cardinalityState = context.getState().getConnectorCardinalityState(); final DefaultRuleViolations result = new DefaultRuleViolations(); final Node<? extends View<?>, Edge> candidate = (Node<? extends View<?>, Edge>) context.getCandidate(); final Edge<? extends View<?>, Node> edge = context.getEdge(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = context.getDirection(); final Collection<? extends Edge> edges = isIncoming(direction) ? cardinalityState.getIncoming(candidate) : cardinalityState.getOutgoing(candidate); final String edgeId = evalUtils.getElementDefinitionId(edge); final int count = evalUtils.countEdges(edgeId, edges); result.addViolations( edgeCardinalityEvaluationHandler .evaluate(rule, RuleEvaluationContextBuilder.DomainContexts.edgeCardinality(candidate.getLabels(), edgeId, count, rule.getDirection(), operation)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(edge.getUUID(), result); } }
ConnectorCardinalityEvaluationHandler implements RuleEvaluationHandler<EdgeOccurrences, ConnectorCardinalityContext> { @Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final EdgeOccurrences rule, final ConnectorCardinalityContext context) { final GraphEvaluationState.ConnectorCardinalityState cardinalityState = context.getState().getConnectorCardinalityState(); final DefaultRuleViolations result = new DefaultRuleViolations(); final Node<? extends View<?>, Edge> candidate = (Node<? extends View<?>, Edge>) context.getCandidate(); final Edge<? extends View<?>, Node> edge = context.getEdge(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = context.getDirection(); final Collection<? extends Edge> edges = isIncoming(direction) ? cardinalityState.getIncoming(candidate) : cardinalityState.getOutgoing(candidate); final String edgeId = evalUtils.getElementDefinitionId(edge); final int count = evalUtils.countEdges(edgeId, edges); result.addViolations( edgeCardinalityEvaluationHandler .evaluate(rule, RuleEvaluationContextBuilder.DomainContexts.edgeCardinality(candidate.getLabels(), edgeId, count, rule.getDirection(), operation)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(edge.getUUID(), result); } @Inject  ConnectorCardinalityEvaluationHandler(final DefinitionManager definitionManager,
                                                 final EdgeCardinalityEvaluationHandler edgeCardinalityEvaluationHandler);   ConnectorCardinalityEvaluationHandler(final GraphEvaluationHandlerUtils evalUtils,
                                          final EdgeCardinalityEvaluationHandler edgeCardinalityEvaluationHandler); }
ConnectorCardinalityEvaluationHandler implements RuleEvaluationHandler<EdgeOccurrences, ConnectorCardinalityContext> { @Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final EdgeOccurrences rule, final ConnectorCardinalityContext context) { final GraphEvaluationState.ConnectorCardinalityState cardinalityState = context.getState().getConnectorCardinalityState(); final DefaultRuleViolations result = new DefaultRuleViolations(); final Node<? extends View<?>, Edge> candidate = (Node<? extends View<?>, Edge>) context.getCandidate(); final Edge<? extends View<?>, Node> edge = context.getEdge(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = context.getDirection(); final Collection<? extends Edge> edges = isIncoming(direction) ? cardinalityState.getIncoming(candidate) : cardinalityState.getOutgoing(candidate); final String edgeId = evalUtils.getElementDefinitionId(edge); final int count = evalUtils.countEdges(edgeId, edges); result.addViolations( edgeCardinalityEvaluationHandler .evaluate(rule, RuleEvaluationContextBuilder.DomainContexts.edgeCardinality(candidate.getLabels(), edgeId, count, rule.getDirection(), operation)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(edge.getUUID(), result); } @Inject  ConnectorCardinalityEvaluationHandler(final DefinitionManager definitionManager,
                                                 final EdgeCardinalityEvaluationHandler edgeCardinalityEvaluationHandler);   ConnectorCardinalityEvaluationHandler(final GraphEvaluationHandlerUtils evalUtils,
                                          final EdgeCardinalityEvaluationHandler edgeCardinalityEvaluationHandler); @Override Class<EdgeOccurrences> getRuleType(); @Override Class<ConnectorCardinalityContext> getContextType(); @Override @SuppressWarnings("unchecked") boolean accepts(final EdgeOccurrences rule,
                           final ConnectorCardinalityContext context); @Override @SuppressWarnings("unchecked") RuleViolations evaluate(final EdgeOccurrences rule,
                                   final ConnectorCardinalityContext context); }
ConnectorCardinalityEvaluationHandler implements RuleEvaluationHandler<EdgeOccurrences, ConnectorCardinalityContext> { @Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final EdgeOccurrences rule, final ConnectorCardinalityContext context) { final GraphEvaluationState.ConnectorCardinalityState cardinalityState = context.getState().getConnectorCardinalityState(); final DefaultRuleViolations result = new DefaultRuleViolations(); final Node<? extends View<?>, Edge> candidate = (Node<? extends View<?>, Edge>) context.getCandidate(); final Edge<? extends View<?>, Node> edge = context.getEdge(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = context.getDirection(); final Collection<? extends Edge> edges = isIncoming(direction) ? cardinalityState.getIncoming(candidate) : cardinalityState.getOutgoing(candidate); final String edgeId = evalUtils.getElementDefinitionId(edge); final int count = evalUtils.countEdges(edgeId, edges); result.addViolations( edgeCardinalityEvaluationHandler .evaluate(rule, RuleEvaluationContextBuilder.DomainContexts.edgeCardinality(candidate.getLabels(), edgeId, count, rule.getDirection(), operation)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(edge.getUUID(), result); } @Inject  ConnectorCardinalityEvaluationHandler(final DefinitionManager definitionManager,
                                                 final EdgeCardinalityEvaluationHandler edgeCardinalityEvaluationHandler);   ConnectorCardinalityEvaluationHandler(final GraphEvaluationHandlerUtils evalUtils,
                                          final EdgeCardinalityEvaluationHandler edgeCardinalityEvaluationHandler); @Override Class<EdgeOccurrences> getRuleType(); @Override Class<ConnectorCardinalityContext> getContextType(); @Override @SuppressWarnings("unchecked") boolean accepts(final EdgeOccurrences rule,
                           final ConnectorCardinalityContext context); @Override @SuppressWarnings("unchecked") RuleViolations evaluate(final EdgeOccurrences rule,
                                   final ConnectorCardinalityContext context);  }