use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class BusinessRuleUnitIT method ioMapping.
@Test
public void ioMapping() throws Exception {
Map<AbstractCodegenIT.TYPE, List<String>> resourcesTypeMap = new HashMap<>();
resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("ruletask/ExampleP.bpmn"));
resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("ruletask/Example.drl"));
Application app = generateCode(resourcesTypeMap);
Process<? extends Model> process = app.get(Processes.class).processById("ruletask.ExampleP");
HashMap<String, Object> map = new HashMap<>();
map.put("singleString", "hello");
map.put("singlePerson", new Person("Yoko", 86));
map.put("manyPersons", asList(new Person("Paul", 77), new Person("Ringo", 79)));
map.put("emptyList", new ArrayList<>());
Model model = process.createModel();
model.fromMap(map);
ProcessInstance<? extends Model> instance = process.createInstance(model);
Model variables = instance.variables();
Map<String, Object> result = variables.toMap();
assertNull(result.get("emptyString"));
assertNull(result.get("emptyPerson"));
assertThat((Collection) result.get("emptyList")).isEmpty();
instance.start();
result = instance.variables().toMap();
assertEquals("hello", result.get("emptyString"));
Person yoko = new Person("Yoko", 86);
yoko.setAdult(true);
assertEquals(yoko, result.get("emptyPerson"));
Person paul = new Person("Paul", 77);
paul.setAdult(true);
Person ringo = new Person("Ringo", 79);
ringo.setAdult(true);
assertEquals(asList(paul, ringo), result.get("emptyList"));
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class CallActivityTaskIT method testCallActivityTaskWithExpressionsForIO.
@Test
public void testCallActivityTaskWithExpressionsForIO() throws Exception {
Application app = generateCodeProcessesOnly("subprocess/CallActivityWithIOexpression.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<>();
parameters.put("person", new Person("john", 0));
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");
Person person = (Person) result.toMap().get("person");
assertEquals("new value", person.getName());
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);
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class EmbeddedSubProcessIT method testEmbeddedSubProcessWithUserTaskAndVariableScopes.
@Test
public void testEmbeddedSubProcessWithUserTaskAndVariableScopes() throws Exception {
Application app = generateCodeProcessesOnly("subprocess/EmbeddedSubProcessWithUserTask.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("embeddedWithUserTask");
Person person = new Person("john", 25);
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("person", person);
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> tasks = processInstance.workItems();
assertThat(tasks).hasSize(1);
WorkItem wi = processInstance.workItem(tasks.get(0).getId());
assertThat(wi).isNotNull();
assertThat(wi.getParameters()).containsKey("person");
assertThat(wi.getParameters()).extracting("person").isEqualTo(person);
processInstance.completeWorkItem(tasks.get(0).getId(), new HashMap<>(Collections.singletonMap("person", new Person("mary", 20))));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class EventSubProcessIT method testEventSignalSubProcessWithData.
@Test
public void testEventSignalSubProcessWithData() throws Exception {
Application app = generateCodeProcessesOnly("event-subprocess/EventSubprocessSignalWithData.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("EventSubprocessSignal");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
processInstance.send(Sig.of("MySignal", new Person("john", 20)));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKeys("person");
Person person = (Person) result.toMap().get("person");
assertThat(person).isNotNull();
assertThat(person.getName()).isEqualTo("john");
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class BusinessRuleTaskIT method testBasicBusinessRuleTaskWithAgendaListener.
@Test
public void testBasicBusinessRuleTaskWithAgendaListener() throws Exception {
Map<AbstractCodegenIT.TYPE, List<String>> resourcesTypeMap = new HashMap<>();
resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("ruletask/BusinessRuleTask.bpmn2"));
resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("ruletask/BusinessRuleTask.drl"));
Application app = generateCode(resourcesTypeMap);
assertThat(app).isNotNull();
final AtomicInteger counter = new AtomicInteger();
app.config().get(RuleConfig.class).ruleEventListeners().agendaListeners().add(new DefaultAgendaEventListener() {
@Override
public void afterMatchFired(AfterMatchFiredEvent event) {
counter.incrementAndGet();
}
});
Process<? extends Model> p = app.get(Processes.class).processById("BusinessRuleTask");
Model m = p.createModel();
m.fromMap(Collections.singletonMap("person", new Person("john", 25)));
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKey("person");
assertThat(result.toMap().get("person")).isNotNull().hasFieldOrPropertyWithValue("adult", true);
assertThat(counter.get()).isEqualTo(1);
}
Aggregations