use of org.kie.kogito.codegen.data.Person 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")));
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class RuleUnitCompilerIT method testRuleUnitQueryWithNoRules.
@ParameterizedTest
@EnumSource(SessionType.class)
public void testRuleUnitQueryWithNoRules(SessionType sessionType) throws Exception {
Application application = createApplication(sessionType, "org/kie/kogito/codegen/unit/RuleUnitQueryNoRules.drl");
AdultUnit adults = new AdultUnit();
adults.getPersons().add(new Person("Mario", 45).setAdult(true));
adults.getPersons().add(new Person("Marilena", 47).setAdult(true));
adults.getPersons().add(new Person("Sofia", 7).setAdult(true));
RuleUnit<AdultUnit> unit = application.get(RuleUnits.class).create(AdultUnit.class);
RuleUnitInstance<AdultUnit> instance = unit.createInstance(adults);
List<Integer> results = instance.executeQuery("FindAdultsAge").stream().map(m -> m.get("$sum")).map(Integer.class::cast).collect(toList());
assertEquals(1, results.size());
assertThat(results).containsExactlyInAnyOrder(99);
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class RuleUnitCompilerIT method testRuleUnitQueryOnPrimitive.
@ParameterizedTest
@EnumSource(SessionType.class)
public void testRuleUnitQueryOnPrimitive(SessionType sessionType) throws Exception {
Application application = createApplication(sessionType, "org/kie/kogito/codegen/unit/RuleUnitQuery.drl");
AdultUnit adults = new AdultUnit();
adults.getPersons().add(new Person("Mario", 45));
adults.getPersons().add(new Person("Marilena", 47));
adults.getPersons().add(new Person("Sofia", 7));
RuleUnit<AdultUnit> unit = application.get(RuleUnits.class).create(AdultUnit.class);
RuleUnitInstance<AdultUnit> instance = unit.createInstance(adults);
List<Integer> results = instance.executeQuery("FindAdultsAge").stream().map(m -> m.get("$age")).map(Integer.class::cast).collect(toList());
assertEquals(2, results.size());
assertTrue(results.containsAll(asList(45, 47)));
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class RuleUnitCompilerIT method test2PatternsOopath.
@ParameterizedTest
@EnumSource(SessionType.class)
public void test2PatternsOopath(SessionType sessionType) throws Exception {
Application application = createApplication(sessionType, "org/kie/kogito/codegen/unit/TwoPatternsQuery.drl");
AdultUnit adults = new AdultUnit();
Person mario = new Person("Mario", 42);
mario.addAddress(new Address("Milano"));
Person mark = new Person("Mark", 40);
mark.addAddress(new Address("London"));
Person edson = new Person("Edson", 37);
edson.addAddress(new Address("Toronto"));
adults.getPersons().add(mario);
adults.getPersons().add(mark);
adults.getPersons().add(edson);
RuleUnit<AdultUnit> unit = application.get(RuleUnits.class).create(AdultUnit.class);
RuleUnitInstance<AdultUnit> instance = unit.createInstance(adults);
List<Person> results = instance.executeQuery("FindPeopleInMilano").stream().map(m -> m.get("$p")).map(Person.class::cast).collect(toList());
assertEquals(1, results.size());
assertEquals("Mario", results.get(0).getName());
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class RuleUnitCompilerIT method testRuleUnitDelete.
@ParameterizedTest
@EnumSource(SessionType.class)
public void testRuleUnitDelete(SessionType sessionType) throws Exception {
Application application = createApplication(sessionType, "org/kie/kogito/codegen/unit/RuleUnitDelete.drl");
AdultUnit adults = new AdultUnit();
adults.getPersons().add(new Person("Mario", 45));
adults.getPersons().add(new Person("Marilena", 47));
adults.getPersons().add(new Person("Sofia", 7));
RuleUnit<AdultUnit> unit = application.get(RuleUnits.class).create(AdultUnit.class);
RuleUnitInstance<AdultUnit> instance = unit.createInstance(adults);
instance.fire();
List<String> results = adults.getResults().getResults();
assertEquals(2, results.size());
assertTrue(results.containsAll(asList("Mario", "Marilena")));
}
Aggregations