use of org.kie.kogito.codegen.unit.AdultUnit 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.unit.AdultUnit in project kogito-runtimes by kiegroup.
the class RuleUnitCompilerIT method testRuleUnitQuery.
@ParameterizedTest
@EnumSource(SessionType.class)
public void testRuleUnitQuery(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);
Class<? extends RuleUnitQuery<List<String>>> queryClass = (Class<? extends RuleUnitQuery<List<String>>>) application.getClass().getClassLoader().loadClass("org.kie.kogito.codegen.unit.AdultUnitQueryFindAdults");
List<String> results = instance.executeQuery(queryClass);
assertEquals(2, results.size());
assertTrue(results.containsAll(asList("Mario", "Marilena")));
}
use of org.kie.kogito.codegen.unit.AdultUnit in project kogito-runtimes by kiegroup.
the class RuleUnitCompilerIT method checckPropertyReactvity.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void checckPropertyReactvity(boolean usePropertyReactivity) throws Exception {
// KOGITO-5101
KogitoBuildContext context = newContext();
if (!usePropertyReactivity) {
context.setApplicationProperty(PropertySpecificOption.PROPERTY_NAME, PropertySpecificOption.DISABLED.toString());
}
Application application = createApplication(context, "org/kie/kogito/codegen/unit/RuleUnitNoPropReact.drl");
AdultUnit adults = new AdultUnit();
Person mario = new Person("Mario", 45);
adults.getPersons().add(mario);
RuleUnit<AdultUnit> unit = application.get(RuleUnits.class).create(AdultUnit.class);
RuleUnitInstance<AdultUnit> instance = unit.createInstance(adults);
instance.fire();
assertEquals(usePropertyReactivity ? 46 : 50, mario.getAge());
}
use of org.kie.kogito.codegen.unit.AdultUnit 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.unit.AdultUnit 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