@Before @SuppressWarnings("unchecked") public void setup() throws Exception { super.setup(); final Set<String> edgeLabels = Collections.singleton(EDGE_ID); evalUtils = spy(new GraphEvaluationHandlerUtils(definitionManager)); when(context.getCandidate()).thenReturn(candidate); when(context.getEdge()).thenReturn(edge); when(edge.getContent()).thenReturn(edgeContent); when(edge.getLabels()).thenReturn(edgeLabels); when(edgeContent.getDefinition()).thenReturn(edgeDefinition); when(definitionAdapter.getId(eq(edgeDefinition))).thenReturn(DefinitionId.build(EDGE_ID)); tested = new ConnectorCardinalityEvaluationHandler(evalUtils, new EdgeCardinalityEvaluationHandler()); }
@Override public boolean accepts(final EdgeOccurrences rule, final ConnectorCardinalityContext context) { final Edge<? extends View<?>, Node> edge = context.getEdge(); final Element<? extends View<?>> candidate = context.getCandidate(); final String edgeId = evalUtils.getElementDefinitionId(edge); final Set<String> candidateRoles = evalUtils.getLabels(candidate); // Take into account that there is no need to provide the candidate count value, as not necessary // just to check if the handler accepts the runtime rule and candidates. return edgeCardinalityEvaluationHandler.accepts(rule, RuleContextBuilder.DomainContexts.edgeCardinality(candidateRoles, edgeId, -1, context.getDirection(), context.getOperation())); }
@Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final EdgeOccurrences rule, final ConnectorCardinalityContext context) { final DefaultRuleViolations result = new DefaultRuleViolations(); final Node<? extends View<?>, ? extends Edge> candidate = (Node<? extends View<?>, ? extends 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 List<? extends Edge> edges = isIncoming(direction) ? candidate.getInEdges() : candidate.getOutEdges(); final String edgeId = evalUtils.getElementDefinitionId(edge); final int count = evalUtils.countEdges(edgeId, edges); // Delegate to the domain model cardinality rule manager. result.addViolations( edgeCardinalityEvaluationHandler .evaluate(rule, RuleContextBuilder.DomainContexts.edgeCardinality(candidate.getLabels(), edgeId, count, rule.getDirection(), operation)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(edge.getUUID(), result); }
final EdgeCardinalityContext.Direction direction1 = context.getDirection(); final Edge<? extends View<?>, Node> edge1 = context.getEdge(); final Element<? extends View<?>> candidate1 = context.getCandidate(); final Graph graph1 = context.getGraph(); final Optional<CardinalityContext.Operation> operation1 = context.getOperation();