Search in sources :

Example 16 with ProcessInstance

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());
}
Also used : ProcessInstanceField(org.kie.server.api.model.definition.ProcessInstanceField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 17 with ProcessInstance

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());
    }
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

Example 18 with ProcessInstance

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());
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) WorkItemInstance(org.kie.server.api.model.instance.WorkItemInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 19 with ProcessInstance

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());
    }
}
Also used : RequestInfoInstance(org.kie.server.api.model.instance.RequestInfoInstance) ArrayList(java.util.ArrayList) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

Example 20 with ProcessInstance

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());
    }
}
Also used : ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)125 Test (org.junit.Test)97 HashMap (java.util.HashMap)75 TaskSummary (org.kie.server.api.model.instance.TaskSummary)31 ArrayList (java.util.ArrayList)24 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)22 KieServicesException (org.kie.server.api.exception.KieServicesException)17 ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)11 List (java.util.List)9 QueryServicesClient (org.kie.server.client.QueryServicesClient)9 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)9 Category (org.junit.experimental.categories.Category)7 CorrelationKey (org.kie.internal.process.CorrelationKey)7 CorrelationKeyFactory (org.kie.internal.process.CorrelationKeyFactory)7 ProcessServicesClient (org.kie.server.client.ProcessServicesClient)7 Arrays (java.util.Arrays)6 Map (java.util.Map)6 Assertions (org.assertj.core.api.Assertions)6 After (org.junit.After)6 TaskInstance (org.kie.server.api.model.instance.TaskInstance)6