use of org.jeasy.rules.api.Facts 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.Facts in project easy-rules by j-easy.
the class RuleProxy method evaluateMethod.
private Object evaluateMethod(final Object[] args) throws IllegalAccessException, InvocationTargetException {
Facts facts = (Facts) args[0];
Method conditionMethod = getConditionMethod();
try {
List<Object> actualParameters = getActualParameters(conditionMethod, facts);
// validated upfront
return conditionMethod.invoke(target, actualParameters.toArray());
} catch (NoSuchFactException e) {
LOGGER.info("Rule '{}' has been evaluated to false due to a declared but missing fact '{}' in {}", getTargetClass().getName(), e.getMissingFact(), facts);
return false;
} catch (IllegalArgumentException e) {
String error = "Types of injected facts in method '%s' in rule '%s' do not match parameters types";
throw new RuntimeException(format(error, conditionMethod.getName(), getTargetClass().getName()), e);
}
}
use of org.jeasy.rules.api.Facts in project easy-rules by j-easy.
the class MVELActionTest method testMVELFunctionExecution.
@Test
public void testMVELFunctionExecution() throws Exception {
// given
Action printAction = new MVELAction("def hello() { System.out.println(\"Hello from MVEL!\"); }; hello();");
Facts facts = new Facts();
// when
printAction.execute(facts);
// then
assertThat(systemOutRule.getLog()).contains("Hello from MVEL!");
}
use of org.jeasy.rules.api.Facts in project easy-rules by j-easy.
the class MVELConditionTest method whenDeclaredFactIsNotPresent_thenShouldReturnFalse.
@Test
public void whenDeclaredFactIsNotPresent_thenShouldReturnFalse() throws Exception {
// given
Condition isHot = new MVELCondition("temperature > 30");
Facts facts = new Facts();
// when
boolean evaluationResult = isHot.evaluate(facts);
// then
assertThat(evaluationResult).isFalse();
}
use of org.jeasy.rules.api.Facts in project easy-rules by j-easy.
the class RuleProxy method executeMethod.
private Object executeMethod(final Object[] args) throws IllegalAccessException, InvocationTargetException {
Facts facts = (Facts) args[0];
for (ActionMethodOrderBean actionMethodBean : getActionMethodBeans()) {
Method actionMethod = actionMethodBean.getMethod();
List<Object> actualParameters = getActualParameters(actionMethod, facts);
actionMethod.invoke(target, actualParameters.toArray());
}
return null;
}
Aggregations