use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.
the class ProcessSearchServiceIntegrationTest method testFindTaskWithAndEqualsToFilter.
@Test
public void testFindTaskWithAndEqualsToFilter() throws Exception {
Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION);
Assertions.assertThat(processInstanceId).isNotNull();
ProcessInstance process = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
Assertions.assertThat(process).isNotNull();
HashMap<ProcessInstanceField, Comparable<?>> compareList = new HashMap<>();
compareList.put(ProcessInstanceField.PROCESSID, process.getProcessId());
compareList.put(ProcessInstanceField.EXTERNALID, CONTAINER_ID);
compareList.put(ProcessInstanceField.PROCESSINSTANCEID, processInstanceId);
compareList.put(ProcessInstanceField.PROCESSINSTANCEDESCRIPTION, process.getProcessInstanceDescription());
compareList.put(ProcessInstanceField.CORRELATIONKEY, process.getCorrelationKey());
compareList.put(ProcessInstanceField.USER_IDENTITY, USER_YODA);
compareList.put(ProcessInstanceField.PARENTPROCESSINSTANCEID, process.getParentId());
compareList.put(ProcessInstanceField.STATUS, process.getState());
compareList.put(ProcessInstanceField.PROCESSVERSION, process.getProcessVersion());
compareList.put(ProcessInstanceField.PROCESSNAME, process.getProcessName());
List<Long> resultsIds = new ArrayList<>();
List<ProcessInstance> results = queryClient.findProcessInstancesWithFilters(QUERY_NAME, createQueryFilterAndEqualsTo(compareList), 0, 100);
for (ProcessInstance res : results) {
resultsIds.add(res.getId());
}
Assertions.assertThat(results).isNotNull();
Assertions.assertThat(results).isNotEmpty();
Assertions.assertThat(resultsIds).contains(process.getId());
ProcessInstance instance = results.stream().filter(processInstance -> processInstance.getId().equals(process.getId())).findFirst().orElse(null);
Assertions.assertThat(instance).isNotNull();
Assertions.assertThat(instance.getContainerId()).isEqualTo(CONTAINER_ID);
Assertions.assertThat(instance.getId()).isEqualTo(processInstanceId);
Assertions.assertThat(instance.getProcessName()).isEqualTo(process.getProcessName());
Assertions.assertThat(instance.getCorrelationKey()).isEqualTo(process.getCorrelationKey());
Assertions.assertThat(instance.getInitiator()).isEqualTo(USER_YODA);
Assertions.assertThat(instance.getProcessInstanceDescription()).isEqualTo(process.getProcessInstanceDescription());
Assertions.assertThat(instance.getParentId()).isEqualTo(process.getParentId());
Assertions.assertThat(instance.getState()).isEqualTo(process.getState());
Assertions.assertThat(instance.getProcessVersion()).isEqualTo(process.getProcessVersion());
Assertions.assertThat(instance.getProcessId()).isEqualTo(process.getProcessId());
}
use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.
the class ProcessServiceIntegrationTest method testSignalProcessInstanceByCorrelationKey.
@Test
public void testSignalProcessInstanceByCorrelationKey() {
Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_SIGNAL_PROCESS);
assertNotNull(processInstanceId);
assertTrue(processInstanceId > 0);
ProcessInstance pi = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
CorrelationKeyFactory correlationKeyFactory = KieInternalServices.Factory.get().newCorrelationKeyFactory();
CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(pi.getCorrelationKey());
try {
checkAvailableSignals(CONTAINER_ID, processInstanceId);
Object person = createPersonInstance(USER_JOHN);
processClient.signalProcessInstanceByCorrelationKey(CONTAINER_ID, correlationKey, "Signal1", person);
processClient.signalProcessInstanceByCorrelationKey(CONTAINER_ID, correlationKey, "Signal2", "My custom string event");
// only can be completed if they receive both signals
assertThat(processClient.getProcessInstance(CONTAINER_ID, processInstanceId).getState(), is(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED));
} catch (Exception e) {
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
fail(e.getMessage());
}
}
use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.
the class ProcessServiceIntegrationTest method testWorkItemOperationComplete.
@Test
public void testWorkItemOperationComplete() throws Exception {
Map<String, Object> parameters = new HashMap<String, Object>();
Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
try {
assertNotNull(processInstanceId);
assertTrue(processInstanceId.longValue() > 0);
// Completing human task so we can move in process flow to work item.
// User task shouldn't be handled as work item because in such case it doesn't behave consistently:
// i.e. leaving open tasks after finishing process instance.
List<String> status = Arrays.asList(Status.Ready.toString());
List<TaskSummary> taskList = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, status, 0, 10);
assertEquals(1, taskList.size());
TaskSummary taskSummary = taskList.get(0);
taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
taskClient.completeTask(CONTAINER_ID, taskSummary.getId(), USER_YODA, null);
TaskInstance userTask = taskClient.findTaskById(taskSummary.getId());
assertNotNull(userTask);
assertEquals("Evaluate items?", userTask.getName());
assertEquals(Status.Completed.toString(), userTask.getStatus());
List<WorkItemInstance> workItems = processClient.getWorkItemByProcessInstance(CONTAINER_ID, processInstanceId);
assertNotNull(workItems);
assertEquals(1, workItems.size());
WorkItemInstance workItemInstance = workItems.get(0);
assertNotNull(workItemInstance);
processClient.completeWorkItem(CONTAINER_ID, processInstanceId, workItemInstance.getId(), parameters);
ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
assertNotNull(processInstance);
assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.getState().intValue());
} catch (Exception e) {
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
throw e;
} finally {
changeUser(TestConfig.getUsername());
}
}
use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.
the class ProcessServiceIntegrationTest method testStartProcessInstanceWithAsyncNodes.
@Test(timeout = 60 * 1000)
public void testStartProcessInstanceWithAsyncNodes() throws Exception {
List<String> status = new ArrayList<String>();
status.add(STATUS.QUEUED.toString());
status.add(STATUS.RUNNING.toString());
status.add(STATUS.DONE.toString());
int originalJobCount = jobServicesClient.getRequestsByStatus(status, 0, 1000).size();
Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_ASYNC_SCRIPT);
assertNotNull(processInstanceId);
assertTrue(processInstanceId.longValue() > 0);
try {
// async node is executed as a job
List<RequestInfoInstance> jobs = jobServicesClient.getRequestsByStatus(status, 0, 1000);
assertNotNull(jobs);
assertEquals(originalJobCount + 1, jobs.size());
// wait for process instance to be completed
KieServerSynchronization.waitForProcessInstanceToFinish(processClient, CONTAINER_ID, processInstanceId);
ProcessInstance pi = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
assertNotNull(pi);
assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, pi.getState().intValue());
} catch (Exception e) {
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
fail(e.getMessage());
}
}
use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.
the class ProcessServiceIntegrationTest method testSignalContainerAlias.
@Test
@Category({ UnstableOnJenkinsPrBuilder.class })
public void testSignalContainerAlias() {
Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_SIGNAL_PROCESS);
assertNotNull(processInstanceId);
assertTrue(processInstanceId > 0);
try {
checkAvailableSignals(CONTAINER_ID, processInstanceId);
Object person = createPersonInstance(USER_JOHN);
processClient.signal(CONTAINER_ID_ALIAS, "Signal1", person);
processClient.signal(CONTAINER_ID_ALIAS, "Signal2", "My custom string event");
ProcessInstance pi = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
assertNotNull(pi);
assertEquals(STATE_COMPLETED, pi.getState().intValue());
} catch (Exception e) {
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
fail(e.getMessage());
}
}
Aggregations