use of org.jeasy.rules.api.Rules in project easy-rules by j-easy.
the class InferenceRulesEngineTest method testCandidateOrdering.
@Test
public void testCandidateOrdering() throws Exception {
// Given
Facts facts = new Facts();
facts.put("foo", true);
facts.put("bar", true);
DummyRule dummyRule = new DummyRule();
AnotherDummyRule anotherDummyRule = new AnotherDummyRule();
Rules rules = new Rules(dummyRule, anotherDummyRule);
RulesEngine rulesEngine = new InferenceRulesEngine();
// When
rulesEngine.fire(rules, facts);
// Then
assertThat(dummyRule.isExecuted()).isTrue();
assertThat(anotherDummyRule.isExecuted()).isTrue();
assertThat(dummyRule.getTimestamp()).isLessThanOrEqualTo(anotherDummyRule.getTimestamp());
}
use of org.jeasy.rules.api.Rules in project easy-rules by j-easy.
the class InferenceRulesEngineTest method testCandidateSelection.
@Test
public void testCandidateSelection() throws Exception {
// Given
Facts facts = new Facts();
facts.put("foo", true);
DummyRule dummyRule = new DummyRule();
AnotherDummyRule anotherDummyRule = new AnotherDummyRule();
Rules rules = new Rules(dummyRule, anotherDummyRule);
RulesEngine rulesEngine = new InferenceRulesEngine();
// When
rulesEngine.fire(rules, facts);
// Then
assertThat(dummyRule.isExecuted()).isTrue();
assertThat(anotherDummyRule.isExecuted()).isFalse();
}
use of org.jeasy.rules.api.Rules in project easy-rules by j-easy.
the class BasicRuleTest method testSortSequence.
@Test
public void testSortSequence() {
FirstRule rule1 = new FirstRule();
SecondRule rule2 = new SecondRule();
ThirdRule rule3 = new ThirdRule();
rules = new Rules(rule1, rule2, rule3);
rulesEngine.check(rules, facts);
assertThat(rules).containsSequence(rule1, rule3, rule2);
}
use of org.jeasy.rules.api.Rules in project easy-rules by j-easy.
the class FactInjectionTest method whenFactTypeDoesNotMatchParameterType_thenShouldThrowRuntimeException.
@Test(expected = RuntimeException.class)
public void whenFactTypeDoesNotMatchParameterType_thenShouldThrowRuntimeException() throws Exception {
// Given
Facts facts = new Facts();
facts.put("age", "foo");
Rules rules = new Rules(new AgeRule());
RulesEngine rulesEngine = new DefaultRulesEngine();
// When
rulesEngine.fire(rules, facts);
// Then
// expected exception
}
use of org.jeasy.rules.api.Rules in project easy-rules by j-easy.
the class FactInjectionTest method whenADeclaredFactIsMissingInEvaluateMethod_thenTheRuleShouldNotBeExecuted.
@Test
public void whenADeclaredFactIsMissingInEvaluateMethod_thenTheRuleShouldNotBeExecuted() throws Exception {
// Given
Facts facts = new Facts();
AgeRule ageRule = new AgeRule();
Rules rules = new Rules(ageRule);
RulesEngine rulesEngine = new DefaultRulesEngine();
// When
rulesEngine.fire(rules, facts);
// Then
assertThat(ageRule.isExecuted()).isFalse();
}
Aggregations