Search in sources :

Example 1 with Address

use of org.kie.kogito.codegen.data.Address 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 2 with Address

use of org.kie.kogito.codegen.data.Address in project kogito-runtimes by kiegroup.

the class CallActivityTaskIT method testCallActivityTaskWithExpressionsForIONested.

@Test
public void testCallActivityTaskWithExpressionsForIONested() throws Exception {
    Application app = generateCodeProcessesOnly("subprocess/CallActivityWithIOexpressionNested.bpmn2", "subprocess/CallActivitySubProcess.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.get(Processes.class).processById("ParentProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    PersonWithAddress pa = new PersonWithAddress("john", 0);
    pa.setAddress(new Address("test", null, null, null));
    parameters.put("person", pa);
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKeys("person");
    PersonWithAddress person = (PersonWithAddress) result.toMap().get("person");
    assertEquals("john", person.getName());
    assertEquals("test", person.getAddress().getStreet());
    assertEquals("new value", person.getAddress().getCity());
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    WorkItem wi = workItems.get(0);
    assertEquals("MyTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : PersonWithAddress(org.kie.kogito.codegen.data.PersonWithAddress) Address(org.kie.kogito.codegen.data.Address) HashMap(java.util.HashMap) Processes(org.kie.kogito.process.Processes) WorkItem(org.kie.kogito.process.WorkItem) HumanTaskTransition(org.jbpm.process.instance.impl.humantask.HumanTaskTransition) Model(org.kie.kogito.Model) PersonWithAddress(org.kie.kogito.codegen.data.PersonWithAddress) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Aggregations

Application (org.kie.kogito.Application)2 Address (org.kie.kogito.codegen.data.Address)2 HashMap (java.util.HashMap)1 HumanTaskTransition (org.jbpm.process.instance.impl.humantask.HumanTaskTransition)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 Model (org.kie.kogito.Model)1 Person (org.kie.kogito.codegen.data.Person)1 PersonWithAddress (org.kie.kogito.codegen.data.PersonWithAddress)1 AdultUnit (org.kie.kogito.codegen.unit.AdultUnit)1 Processes (org.kie.kogito.process.Processes)1 WorkItem (org.kie.kogito.process.WorkItem)1 RuleUnits (org.kie.kogito.rules.RuleUnits)1