@Test public void testEvaluateInMinOneFailed() { when(context.getCurrentCount()).thenReturn(1); when(context.getDirection()).thenReturn(EdgeCardinalityContext.Direction.INCOMING); when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.DELETE)); RuleViolations violations = tested.evaluate(RULE_IN_MIN_1, context); assertNotNull(violations); assertTrue(violations.violations(RuleViolation.Type.WARNING).iterator().hasNext()); }
@Override public RuleViolations evaluate(final EdgeOccurrences rule, final EdgeCardinalityContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final int minOccurrences = rule.getMinOccurrences(); final int maxOccurrences = rule.getMaxOccurrences(); final int candidatesCount = context.getCurrentCount(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = rule.getDirection(); final Violation.Type type = operation .filter(CardinalityContext.Operation.ADD::equals) .isPresent() ? Violation.Type.ERROR : Violation.Type.WARNING; final int _count = !operation.isPresent() ? candidatesCount : (operation.get().equals(CardinalityContext.Operation.ADD) ? candidatesCount + 1 : (candidatesCount > 0 ? candidatesCount - 1 : 0) ); if (_count < minOccurrences) { results.addViolation(new EdgeCardinalityMinRuleViolation(context.getRoles().toString(), context.getEdgeRole(), minOccurrences, candidatesCount, direction, type)); } else if (maxOccurrences > -1 && _count > maxOccurrences) { results.addViolation(new EdgeCardinalityMaxRuleViolation(context.getRoles().toString(), context.getEdgeRole(), maxOccurrences, candidatesCount, direction, type)); } return results; }
EdgeCardinalityEvaluationHandler implements RuleEvaluationHandler<EdgeOccurrences, EdgeCardinalityContext> { @Override public RuleViolations evaluate(final EdgeOccurrences rule, final EdgeCardinalityContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final int minOccurrences = rule.getMinOccurrences(); final int maxOccurrences = rule.getMaxOccurrences(); final int candidatesCount = context.getCurrentCount(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = rule.getDirection(); final Violation.Type type = operation .filter(CardinalityContext.Operation.ADD::equals) .isPresent() ? Violation.Type.ERROR : Violation.Type.WARNING; final int _count = !operation.isPresent() ? candidatesCount : (operation.get().equals(CardinalityContext.Operation.ADD) ? candidatesCount + 1 : (candidatesCount > 0 ? candidatesCount - 1 : 0) ); if (_count < minOccurrences) { results.addViolation(new EdgeCardinalityMinRuleViolation(context.getRoles().toString(), context.getEdgeRole(), minOccurrences, candidatesCount, direction, type)); } else if (maxOccurrences > -1 && _count > maxOccurrences) { results.addViolation(new EdgeCardinalityMaxRuleViolation(context.getRoles().toString(), context.getEdgeRole(), maxOccurrences, candidatesCount, direction, type)); } return results; } }
EdgeCardinalityEvaluationHandler implements RuleEvaluationHandler<EdgeOccurrences, EdgeCardinalityContext> { @Override public RuleViolations evaluate(final EdgeOccurrences rule, final EdgeCardinalityContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final int minOccurrences = rule.getMinOccurrences(); final int maxOccurrences = rule.getMaxOccurrences(); final int candidatesCount = context.getCurrentCount(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = rule.getDirection(); final Violation.Type type = operation .filter(CardinalityContext.Operation.ADD::equals) .isPresent() ? Violation.Type.ERROR : Violation.Type.WARNING; final int _count = !operation.isPresent() ? candidatesCount : (operation.get().equals(CardinalityContext.Operation.ADD) ? candidatesCount + 1 : (candidatesCount > 0 ? candidatesCount - 1 : 0) ); if (_count < minOccurrences) { results.addViolation(new EdgeCardinalityMinRuleViolation(context.getRoles().toString(), context.getEdgeRole(), minOccurrences, candidatesCount, direction, type)); } else if (maxOccurrences > -1 && _count > maxOccurrences) { results.addViolation(new EdgeCardinalityMaxRuleViolation(context.getRoles().toString(), context.getEdgeRole(), maxOccurrences, candidatesCount, direction, type)); } return results; }  }
EdgeCardinalityEvaluationHandler implements RuleEvaluationHandler<EdgeOccurrences, EdgeCardinalityContext> { @Override public RuleViolations evaluate(final EdgeOccurrences rule, final EdgeCardinalityContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final int minOccurrences = rule.getMinOccurrences(); final int maxOccurrences = rule.getMaxOccurrences(); final int candidatesCount = context.getCurrentCount(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = rule.getDirection(); final Violation.Type type = operation .filter(CardinalityContext.Operation.ADD::equals) .isPresent() ? Violation.Type.ERROR : Violation.Type.WARNING; final int _count = !operation.isPresent() ? candidatesCount : (operation.get().equals(CardinalityContext.Operation.ADD) ? candidatesCount + 1 : (candidatesCount > 0 ? candidatesCount - 1 : 0) ); if (_count < minOccurrences) { results.addViolation(new EdgeCardinalityMinRuleViolation(context.getRoles().toString(), context.getEdgeRole(), minOccurrences, candidatesCount, direction, type)); } else if (maxOccurrences > -1 && _count > maxOccurrences) { results.addViolation(new EdgeCardinalityMaxRuleViolation(context.getRoles().toString(), context.getEdgeRole(), maxOccurrences, candidatesCount, direction, type)); } return results; }  @Override Class<EdgeOccurrences> getRuleType(); @Override Class<EdgeCardinalityContext> getContextType(); @Override boolean accepts(final EdgeOccurrences rule,
                           final EdgeCardinalityContext context); @Override RuleViolations evaluate(final EdgeOccurrences rule,
                                   final EdgeCardinalityContext context); }
EdgeCardinalityEvaluationHandler implements RuleEvaluationHandler<EdgeOccurrences, EdgeCardinalityContext> { @Override public RuleViolations evaluate(final EdgeOccurrences rule, final EdgeCardinalityContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final int minOccurrences = rule.getMinOccurrences(); final int maxOccurrences = rule.getMaxOccurrences(); final int candidatesCount = context.getCurrentCount(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = rule.getDirection(); final Violation.Type type = operation .filter(CardinalityContext.Operation.ADD::equals) .isPresent() ? Violation.Type.ERROR : Violation.Type.WARNING; final int _count = !operation.isPresent() ? candidatesCount : (operation.get().equals(CardinalityContext.Operation.ADD) ? candidatesCount + 1 : (candidatesCount > 0 ? candidatesCount - 1 : 0) ); if (_count < minOccurrences) { results.addViolation(new EdgeCardinalityMinRuleViolation(context.getRoles().toString(), context.getEdgeRole(), minOccurrences, candidatesCount, direction, type)); } else if (maxOccurrences > -1 && _count > maxOccurrences) { results.addViolation(new EdgeCardinalityMaxRuleViolation(context.getRoles().toString(), context.getEdgeRole(), maxOccurrences, candidatesCount, direction, type)); } return results; }  @Override Class<EdgeOccurrences> getRuleType(); @Override Class<EdgeCardinalityContext> getContextType(); @Override boolean accepts(final EdgeOccurrences rule,
                           final EdgeCardinalityContext context); @Override RuleViolations evaluate(final EdgeOccurrences rule,
                                   final EdgeCardinalityContext context);  }