use of org.jeasy.rules.api.Rules in project easy-rules by j-easy.
the class FactInjectionTest method rulesShouldBeExecutedWhenFactsAreCorrectlyInjected.
@Test
public void rulesShouldBeExecutedWhenFactsAreCorrectlyInjected() throws Exception {
// Given
Facts facts = new Facts();
facts.put("rain", true);
facts.put("age", 18);
WeatherRule weatherRule = new WeatherRule();
AgeRule ageRule = new AgeRule();
Rules rules = new Rules(weatherRule, ageRule);
// When
RulesEngine rulesEngine = new DefaultRulesEngine();
rulesEngine.fire(rules, facts);
// Then
assertThat(ageRule.isExecuted()).isTrue();
assertThat(weatherRule.isExecuted()).isTrue();
}
use of org.jeasy.rules.api.Rules in project easy-rules by j-easy.
the class NullFactAnnotationParameterTest method testNullFact.
@Test
public void testNullFact() {
Rules rules = new Rules();
rules.register(new AnnotatedParametersRule());
Facts facts = new Facts();
facts.put("fact1", new Object());
facts.put("fact2", null);
Map<org.jeasy.rules.api.Rule, Boolean> results = rulesEngine.check(rules, facts);
for (boolean b : results.values()) {
Assert.assertTrue(b);
}
}
use of org.jeasy.rules.api.Rules in project easy-rules by j-easy.
the class NullFactAnnotationParameterTest method testMissingFact.
@Test
public void testMissingFact() {
Rules rules = new Rules();
rules.register(new AnnotatedParametersRule());
Facts facts = new Facts();
facts.put("fact1", new Object());
Map<org.jeasy.rules.api.Rule, Boolean> results = rulesEngine.check(rules, facts);
for (boolean b : results.values()) {
Assert.assertFalse(b);
}
}
use of org.jeasy.rules.api.Rules in project easy-rules by j-easy.
the class Launcher method main.
public static void main(String[] args) {
// define facts
Facts facts = new Facts();
facts.put("rain", true);
// define rules
WeatherRule weatherRule = new WeatherRule();
Rules rules = new Rules();
rules.register(weatherRule);
// fire rules on known facts
RulesEngine rulesEngine = new DefaultRulesEngine();
rulesEngine.fire(rules, facts);
}
use of org.jeasy.rules.api.Rules in project easy-rules by j-easy.
the class Launcher method main.
public static void main(String[] args) {
// define facts
Facts facts = new Facts();
facts.put("temperature", 30);
// define rules
Rule airConditioningRule = new RuleBuilder().name("air conditioning rule").when(itIsHot()).then(decreaseTemperature()).build();
Rules rules = new Rules();
rules.register(airConditioningRule);
// fire rules on known facts
RulesEngine rulesEngine = new InferenceRulesEngine();
rulesEngine.fire(rules, facts);
}
Aggregations