@Test public void testEmptyRules() { ruleSet = new EmptyRuleSet(); final RuleViolations result = tested.evaluate(ruleSet, ruleEvaluationContext); assertNotNull(result); final Collection<RuleViolation> violations = (Collection<RuleViolation>) result.violations(); assertTrue(violations.isEmpty()); }
@Override public RuleViolations evaluate(final RuleSet ruleSet, final RuleEvaluationContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final Collection<Rule> rules = rulesProvider.get(ruleSet, context); if (rules.isEmpty()) { return results; } final Collection<RuleEvaluationHandler> handlers = registry.getHandlersByContext(context.getType()); final List<Optional<RuleViolations>> handlersViolations = rules.stream() .filter(rule -> !isRuleExtension().test(rule)) .map(rule -> evaluate(rule, handlers, context)) .collect(Collectors.toList()); if (context.isDefaultDeny() && !handlersViolations.stream().anyMatch(Optional::isPresent)) { return getDefaultViolationForContext(context); } handlersViolations.stream() .filter(Optional::isPresent) .map(Optional::get) .forEach(results::addViolations); rules.stream() .filter(rule -> isRuleExtension().test(rule)) .map(rule -> evaluateExtension((RuleExtension) rule, context)) .filter(Optional::isPresent) .map(Optional::get) .forEach(results::addViolations); return results; }
RuleManagerImpl implements RuleManager { @Override public RuleViolations evaluate(final RuleSet ruleSet, final RuleEvaluationContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final Collection<Rule> rules = rulesProvider.get(ruleSet, context); if (rules.isEmpty()) { return results; } final Collection<RuleEvaluationHandler> handlers = registry.getHandlersByContext(context.getType()); final List<Optional<RuleViolations>> handlersViolations = rules.stream() .filter(rule -> !isRuleExtension().test(rule)) .map(rule -> evaluate(rule, handlers, context)) .collect(Collectors.toList()); if (context.isDefaultDeny() && !handlersViolations.stream().anyMatch(Optional::isPresent)) { return getDefaultViolationForContext(context); } handlersViolations.stream() .filter(Optional::isPresent) .map(Optional::get) .forEach(results::addViolations); rules.stream() .filter(rule -> isRuleExtension().test(rule)) .map(rule -> evaluateExtension((RuleExtension) rule, context)) .filter(Optional::isPresent) .map(Optional::get) .forEach(results::addViolations); return results; } }
RuleManagerImpl implements RuleManager { @Override public RuleViolations evaluate(final RuleSet ruleSet, final RuleEvaluationContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final Collection<Rule> rules = rulesProvider.get(ruleSet, context); if (rules.isEmpty()) { return results; } final Collection<RuleEvaluationHandler> handlers = registry.getHandlersByContext(context.getType()); final List<Optional<RuleViolations>> handlersViolations = rules.stream() .filter(rule -> !isRuleExtension().test(rule)) .map(rule -> evaluate(rule, handlers, context)) .collect(Collectors.toList()); if (context.isDefaultDeny() && !handlersViolations.stream().anyMatch(Optional::isPresent)) { return getDefaultViolationForContext(context); } handlersViolations.stream() .filter(Optional::isPresent) .map(Optional::get) .forEach(results::addViolations); rules.stream() .filter(rule -> isRuleExtension().test(rule)) .map(rule -> evaluateExtension((RuleExtension) rule, context)) .filter(Optional::isPresent) .map(Optional::get) .forEach(results::addViolations); return results; } @Inject  RuleManagerImpl(final RegistryFactory registryFactory);  RuleManagerImpl(final RuleHandlerRegistry registry); }
RuleManagerImpl implements RuleManager { @Override public RuleViolations evaluate(final RuleSet ruleSet, final RuleEvaluationContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final Collection<Rule> rules = rulesProvider.get(ruleSet, context); if (rules.isEmpty()) { return results; } final Collection<RuleEvaluationHandler> handlers = registry.getHandlersByContext(context.getType()); final List<Optional<RuleViolations>> handlersViolations = rules.stream() .filter(rule -> !isRuleExtension().test(rule)) .map(rule -> evaluate(rule, handlers, context)) .collect(Collectors.toList()); if (context.isDefaultDeny() && !handlersViolations.stream().anyMatch(Optional::isPresent)) { return getDefaultViolationForContext(context); } handlersViolations.stream() .filter(Optional::isPresent) .map(Optional::get) .forEach(results::addViolations); rules.stream() .filter(rule -> isRuleExtension().test(rule)) .map(rule -> evaluateExtension((RuleExtension) rule, context)) .filter(Optional::isPresent) .map(Optional::get) .forEach(results::addViolations); return results; } @Inject  RuleManagerImpl(final RegistryFactory registryFactory);  RuleManagerImpl(final RuleHandlerRegistry registry); RuleManagerImpl setRulesProvider(final RulesProvider rulesProvider); RuleManagerImpl setRuleEvaluator(final RuleEvaluator ruleEvaluator); @Override RuleViolations evaluate(final RuleSet ruleSet,
                                   final RuleEvaluationContext context); @Override RuleHandlerRegistry registry(); @PreDestroy void destroy(); static Predicate<Rule> isRuleExtension(); static BiPredicate<Rule, RuleEvaluationHandler> isRuleTypeAllowed(); static boolean accepts(final RuleEvaluationHandler handler,
                                  final RuleEvaluationContext context); }
RuleManagerImpl implements RuleManager { @Override public RuleViolations evaluate(final RuleSet ruleSet, final RuleEvaluationContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final Collection<Rule> rules = rulesProvider.get(ruleSet, context); if (rules.isEmpty()) { return results; } final Collection<RuleEvaluationHandler> handlers = registry.getHandlersByContext(context.getType()); final List<Optional<RuleViolations>> handlersViolations = rules.stream() .filter(rule -> !isRuleExtension().test(rule)) .map(rule -> evaluate(rule, handlers, context)) .collect(Collectors.toList()); if (context.isDefaultDeny() && !handlersViolations.stream().anyMatch(Optional::isPresent)) { return getDefaultViolationForContext(context); } handlersViolations.stream() .filter(Optional::isPresent) .map(Optional::get) .forEach(results::addViolations); rules.stream() .filter(rule -> isRuleExtension().test(rule)) .map(rule -> evaluateExtension((RuleExtension) rule, context)) .filter(Optional::isPresent) .map(Optional::get) .forEach(results::addViolations); return results; } @Inject  RuleManagerImpl(final RegistryFactory registryFactory);  RuleManagerImpl(final RuleHandlerRegistry registry); RuleManagerImpl setRulesProvider(final RulesProvider rulesProvider); RuleManagerImpl setRuleEvaluator(final RuleEvaluator ruleEvaluator); @Override RuleViolations evaluate(final RuleSet ruleSet,
                                   final RuleEvaluationContext context); @Override RuleHandlerRegistry registry(); @PreDestroy void destroy(); static Predicate<Rule> isRuleExtension(); static BiPredicate<Rule, RuleEvaluationHandler> isRuleTypeAllowed(); static boolean accepts(final RuleEvaluationHandler handler,
                                  final RuleEvaluationContext context);  }