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")));
}
Aggregations