use of org.kie.kogito.process.Processes in project kogito-runtimes by kiegroup.
the class ProcessInstanceManagementResourceTest method setup.
@SuppressWarnings({ "rawtypes", "unchecked" })
@BeforeEach
public void setup() {
responseBuilder = mock(ResponseBuilder.class);
Response response = mock(Response.class);
when((runtimeDelegate).createResponseBuilder()).thenReturn(responseBuilder);
lenient().when((responseBuilder).status(any(StatusType.class))).thenReturn(responseBuilder);
lenient().when((responseBuilder).entity(any())).thenReturn(responseBuilder);
lenient().when((responseBuilder).build()).thenReturn(response);
application = mock(Application.class);
processes = mock(Processes.class);
AbstractProcess process = mock(AbstractProcess.class);
ProcessInstances instances = mock(ProcessInstances.class);
processInstance = mock(ProcessInstance.class);
error = mock(ProcessError.class);
lenient().when(processes.processById(anyString())).thenReturn(process);
lenient().when(process.instances()).thenReturn(instances);
lenient().when(instances.findById(anyString())).thenReturn(Optional.of(processInstance));
lenient().when(processInstance.error()).thenReturn(Optional.of(error));
lenient().when(processInstance.id()).thenReturn("abc-def");
lenient().when(processInstance.status()).thenReturn(KogitoProcessInstance.STATE_ACTIVE);
lenient().when(error.failedNodeId()).thenReturn("xxxxx");
lenient().when(error.errorMessage()).thenReturn("Test error message");
lenient().when(process.get()).thenReturn(mock(KogitoWorkflowProcess.class));
lenient().when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
resource = spy(new ProcessInstanceManagementResource(processes, application));
}
use of org.kie.kogito.process.Processes in project kogito-runtimes by kiegroup.
the class BusinessRuleUnitIT method testBasicBusinessRuleUnitWithAgendaListener.
@ParameterizedTest
@MethodSource("processes")
public void testBasicBusinessRuleUnitWithAgendaListener(String bpmnPath) throws Exception {
Map<AbstractCodegenIT.TYPE, List<String>> resourcesTypeMap = new HashMap<>();
resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList(bpmnPath));
resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("org/kie/kogito/codegen/tests/BusinessRuleUnit.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("BusinessRuleUnit");
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);
}
use of org.kie.kogito.process.Processes in project kogito-runtimes by kiegroup.
the class BusinessRuleUnitIT method testBasicBusinessRuleUnitControlledByUnitOfWork.
@ParameterizedTest
@MethodSource("processes")
public void testBasicBusinessRuleUnitControlledByUnitOfWork(String bpmnPath) throws Exception {
Map<AbstractCodegenIT.TYPE, List<String>> resourcesTypeMap = new HashMap<>();
resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList(bpmnPath));
resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("org/kie/kogito/codegen/tests/BusinessRuleUnit.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("BusinessRuleUnit");
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);
}
use of org.kie.kogito.process.Processes in project kogito-runtimes by kiegroup.
the class BusinessRuleUnitIT method testBasicBusinessRuleUnit.
@ParameterizedTest
@MethodSource("processes")
public void testBasicBusinessRuleUnit(String bpmnPath) throws Exception {
Map<AbstractCodegenIT.TYPE, List<String>> resourcesTypeMap = new HashMap<>();
resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList(bpmnPath));
resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("org/kie/kogito/codegen/tests/BusinessRuleUnit.drl"));
Application app = generateCode(resourcesTypeMap);
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("BusinessRuleUnit");
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);
}
Aggregations