Search in sources :

Example 1 with PersonsUnit

use of org.kie.kogito.codegen.unit.PersonsUnit in project kogito-runtimes by kiegroup.

the class RuleUnitCompilerIT method testRuleUnitExecutor.

@ParameterizedTest
@EnumSource(SessionType.class)
public void testRuleUnitExecutor(SessionType sessionType) throws Exception {
    Application application = createApplication(sessionType, "org/kie/kogito/codegen/unit/RuleUnit.drl", "org/kie/kogito/codegen/unit/PersonsUnit.drl");
    DataStore<Person> persons = DataSource.createStore();
    persons.add(new Person("Mario", 45));
    persons.add(new Person("Marilena", 17));
    persons.add(new Person("Sofia", 7));
    RuleUnit<AdultUnit> adultUnit = application.get(RuleUnits.class).create(AdultUnit.class);
    AdultUnit adultData18 = new AdultUnit(persons, 18);
    RuleUnitInstance<AdultUnit> adultUnitInstance18 = adultUnit.createInstance(adultData18, "adult18");
    AdultUnit adultData21 = new AdultUnit(persons, 21);
    RuleUnitInstance<AdultUnit> adultUnitInstance21 = adultUnit.createInstance(adultData21, "adult21");
    RuleUnit<PersonsUnit> personsUnit = application.get(RuleUnits.class).create(PersonsUnit.class);
    personsUnit.createInstance(new PersonsUnit(persons)).fire();
    assertEquals(2, adultData18.getResults().getResults().size());
    assertTrue(adultData18.getResults().getResults().containsAll(asList("Mario", "Marilena")));
    assertEquals(1, adultData21.getResults().getResults().size());
    assertTrue(adultData21.getResults().getResults().containsAll(asList("Mario")));
}
Also used : RuleUnits(org.kie.kogito.rules.RuleUnits) PersonsUnit(org.kie.kogito.codegen.unit.PersonsUnit) AdultUnit(org.kie.kogito.codegen.unit.AdultUnit) Application(org.kie.kogito.Application) Person(org.kie.kogito.codegen.data.Person) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 Application (org.kie.kogito.Application)1 Person (org.kie.kogito.codegen.data.Person)1 AdultUnit (org.kie.kogito.codegen.unit.AdultUnit)1 PersonsUnit (org.kie.kogito.codegen.unit.PersonsUnit)1 RuleUnits (org.kie.kogito.rules.RuleUnits)1