Search in sources :

Example 21 with Facts

use of org.jeasy.rules.api.Facts in project easy-rules by j-easy.

the class MVELActionTest method testMVELActionExecution.

@Test
public void testMVELActionExecution() throws Exception {
    // given
    Action markAsAdult = new MVELAction("person.setAdult(true);");
    Facts facts = new Facts();
    Person foo = new Person("foo", 20);
    facts.put("person", foo);
    // when
    markAsAdult.execute(facts);
    // then
    assertThat(foo.isAdult()).isTrue();
}
Also used : Action(org.jeasy.rules.api.Action) Facts(org.jeasy.rules.api.Facts) Test(org.junit.Test)

Example 22 with Facts

use of org.jeasy.rules.api.Facts in project easy-rules by j-easy.

the class MVELConditionTest method testMVELExpressionEvaluation.

@Test
public void testMVELExpressionEvaluation() throws Exception {
    // given
    Condition isAdult = new MVELCondition("person.age > 18");
    Facts facts = new Facts();
    facts.put("person", new Person("foo", 20));
    // when
    boolean evaluationResult = isAdult.evaluate(facts);
    // then
    assertThat(evaluationResult).isTrue();
}
Also used : Condition(org.jeasy.rules.api.Condition) Facts(org.jeasy.rules.api.Facts) Test(org.junit.Test)

Example 23 with Facts

use of org.jeasy.rules.api.Facts in project tutorials by eugenp.

the class Launcher method main.

public static void main(String... args) {
    // create facts
    Facts facts = new Facts();
    // create rules
    Rules rules = new Rules();
    rules.register(new HelloWorldRule());
    // create a rules engine and fire rules on known facts
    RulesEngine rulesEngine = new DefaultRulesEngine();
    rulesEngine.fire(rules, facts);
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Aggregations

Facts (org.jeasy.rules.api.Facts)23 Rules (org.jeasy.rules.api.Rules)16 RulesEngine (org.jeasy.rules.api.RulesEngine)13 Test (org.junit.Test)13 DefaultRulesEngine (org.jeasy.rules.core.DefaultRulesEngine)5 Method (java.lang.reflect.Method)2 Rule (org.jeasy.rules.annotation.Rule)2 Action (org.jeasy.rules.api.Action)2 Condition (org.jeasy.rules.api.Condition)2 File (java.io.File)1 Rule (org.jeasy.rules.api.Rule)1 InferenceRulesEngine (org.jeasy.rules.core.InferenceRulesEngine)1 RuleBuilder (org.jeasy.rules.core.RuleBuilder)1 RulesEngineParameters (org.jeasy.rules.core.RulesEngineParameters)1 MVELRule (org.jeasy.rules.mvel.MVELRule)1 Before (org.junit.Before)1