use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class BusinessRuleUnitIT method testRemovingOtherVariableFromAutoGeneratedRuleUnit.
@Test
public void testRemovingOtherVariableFromAutoGeneratedRuleUnit() throws Exception {
Map<AbstractCodegenIT.TYPE, List<String>> resourcesTypeMap = new HashMap<>();
resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("ruletask/ExampleGenerated.bpmn"));
resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("ruletask/Generated.drl"));
Application app = generateCode(resourcesTypeMap);
Process<? extends Model> process = app.get(Processes.class).processById("ruletask.ExampleGenerated");
HashMap<String, Object> map = new HashMap<>();
map.put("singleString", "hello");
map.put("singlePerson", new Person("John", 60));
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"));
instance.start();
result = instance.variables().toMap();
Person john = new Person("John", 60);
john.setAdult(true);
assertEquals(john, result.get("singlePerson"));
assertNull(result.get("singleString"));
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class BusinessRuleUnitIT method outputMappingNullCollection.
@Test
@DisplayName("Should throw an exception when a null collection variable is mapped as output of a datasource")
public void outputMappingNullCollection() 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)));
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"));
assertNull(result.get("emptyList"));
instance.start();
assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ERROR);
assertThat(instance.error().get().errorMessage()).contains("Null collection variable used as an output variable");
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class BusinessRuleUnitIT method inputMappingNullCollection.
@Test
@DisplayName("Should throw an exception when a null collection variable is mapped as input of a datasource")
public void inputMappingNullCollection() 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", null);
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"));
assertNull(result.get("emptyList"));
instance.start();
assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ERROR);
assertThat(instance.error().get().errorMessage()).contains("The input collection variable of a data source cannot be null");
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class BusinessRuleUnitIT method ioMappingAutoGeneratedRuleUnit.
@Test
public void ioMappingAutoGeneratedRuleUnit() throws Exception {
Map<AbstractCodegenIT.TYPE, List<String>> resourcesTypeMap = new HashMap<>();
resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("ruletask/ExampleGenerated.bpmn"));
resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("ruletask/Generated.drl"));
Application app = generateCode(resourcesTypeMap);
Process<? extends Model> process = app.get(Processes.class).processById("ruletask.ExampleGenerated");
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"));
instance.start();
result = instance.variables().toMap();
Person yoko = new Person("Yoko", 86);
yoko.setAdult(true);
assertEquals(yoko, result.get("singlePerson"));
}
use of org.kie.kogito.codegen.data.Person in project kogito-runtimes by kiegroup.
the class BusinessRuleTaskIT method testBasicBusinessRuleTaskControlledByUnitOfWork.
@Test
public void testBasicBusinessRuleTaskControlledByUnitOfWork() 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 List<String> startedProcesses = new ArrayList<>();
// add custom event listener that collects data
app.config().get(ProcessConfig.class).processEventListeners().listeners().add(new DefaultKogitoProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
startedProcesses.add(((KogitoProcessInstance) event.getProcessInstance()).getStringId());
}
});
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
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);
// since the unit of work has not been finished yet not listeners where invoked
assertThat(startedProcesses).hasSize(0);
uow.end();
// after unit of work has been ended listeners are invoked
assertThat(startedProcesses).hasSize(1);
}
Aggregations