Search in sources :

Example 1 with Person

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

Example 2 with Person

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);
}
Also used : RuleUnits(org.kie.kogito.rules.RuleUnits) 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)

Example 3 with Person

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)));
}
Also used : RuleUnits(org.kie.kogito.rules.RuleUnits) 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)

Example 4 with Person

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());
}
Also used : RuleUnits(org.kie.kogito.rules.RuleUnits) Address(org.kie.kogito.codegen.data.Address) 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)

Example 5 with Person

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")));
}
Also used : RuleUnits(org.kie.kogito.rules.RuleUnits) 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

Person (org.kie.kogito.codegen.data.Person)32 Application (org.kie.kogito.Application)30 HashMap (java.util.HashMap)20 Test (org.junit.jupiter.api.Test)20 Model (org.kie.kogito.Model)20 Processes (org.kie.kogito.process.Processes)20 ArrayList (java.util.ArrayList)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 List (java.util.List)17 Arrays.asList (java.util.Arrays.asList)10 RuleUnits (org.kie.kogito.rules.RuleUnits)10 AdultUnit (org.kie.kogito.codegen.unit.AdultUnit)9 EnumSource (org.junit.jupiter.params.provider.EnumSource)8 DataHandle (org.kie.kogito.rules.DataHandle)5 UnitOfWork (org.kie.kogito.uow.UnitOfWork)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 DataEvent (org.kie.kogito.event.DataEvent)3 WorkItem (org.kie.kogito.process.WorkItem)3 ProcessInstanceDataEvent (org.kie.kogito.services.event.ProcessInstanceDataEvent)3 UserTaskInstanceDataEvent (org.kie.kogito.services.event.UserTaskInstanceDataEvent)3