Search in sources :

Example 21 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class ProcessServiceIntegrationTest method testCallActivityProcess.

@Test
public void testCallActivityProcess() {
    Map<String, Object> parameters = new HashMap<String, Object>();
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_CALL_EVALUATION, parameters);
    try {
        assertNotNull(processInstanceId);
        assertTrue(processInstanceId.longValue() > 0);
        // Process instance is running and is active.
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.getState().intValue());
        List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertEquals(1, tasks.size());
        taskClient.completeAutoProgress(CONTAINER_ID, tasks.get(0).getId(), USER_YODA, null);
        List<ProcessInstance> instances = processClient.findProcessInstancesByParent(CONTAINER_ID, processInstanceId, 0, 10);
        assertEquals(1, instances.size());
        ProcessInstance childInstance = instances.get(0);
        assertNotNull(childInstance);
        assertEquals(PROCESS_ID_EVALUATION, childInstance.getProcessId());
        assertEquals(processInstanceId, childInstance.getParentId());
        List<NodeInstance> activeNodes = queryClient.findActiveNodeInstances(processInstanceId, 0, 10);
        assertEquals(1, activeNodes.size());
        NodeInstance active = activeNodes.get(0);
        assertEquals("Call Evaluation", active.getName());
        assertEquals("SubProcessNode", active.getNodeType());
        assertEquals(childInstance.getId(), active.getReferenceId());
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        // Process instance is now aborted.
        processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ABORTED, processInstance.getState().intValue());
        processInstance = processClient.getProcessInstance(CONTAINER_ID, childInstance.getId());
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ABORTED, processInstance.getState().intValue());
        // no more active instances
        instances = processClient.findProcessInstancesByParent(CONTAINER_ID, processInstanceId, 0, 10);
        assertEquals(0, instances.size());
        instances = processClient.findProcessInstancesByParent(CONTAINER_ID, processInstanceId, Arrays.asList(3), 0, 10);
        assertEquals(1, instances.size());
    } catch (Exception e) {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        fail(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) NodeInstance(org.kie.server.api.model.instance.NodeInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

Example 22 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class ProcessServiceIntegrationTest method testProcessInstanceWithTimer.

@Test(timeout = 60 * 1000)
public void testProcessInstanceWithTimer() throws Exception {
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("timer", "1s");
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_TIMER, parameters);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId.longValue() > 0);
    try {
        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 : HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

Example 23 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class ProcessServiceIntegrationTest method testAbortExistingProcess.

@Test()
public void testAbortExistingProcess() {
    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);
        // Process instance is running and is active.
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.getState().intValue());
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        // Process instance is now aborted.
        processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ABORTED, processInstance.getState().intValue());
    } catch (Exception e) {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        fail(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

Example 24 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class ProcessServiceIntegrationTest method testSignalContainer.

@Test
@Category({ UnstableOnJenkinsPrBuilder.class })
public void testSignalContainer() {
    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, "Signal1", person);
        processClient.signal(CONTAINER_ID, "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)

Example 25 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class ProcessUserTaskServicesSecurityIntegrationTest method testNonAllowedUserForStartingProcessCanCompleteTask.

@Test
public void testNonAllowedUserForStartingProcessCanCompleteTask() throws Exception {
    try {
        Long processInstanceId = startProcessAsAdministrator(PROCESS_ID_USERTASK_SECURED);
        changeUser(USER_YODA);
        List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertThat(taskList).isNotNull().hasSize(1);
        Long taskId = taskList.get(0).getId();
        taskClient.startTask(CONTAINER_ID_SECURED, taskId, USER_YODA);
        taskClient.completeAutoProgress(CONTAINER_ID_SECURED, taskId, USER_YODA, new HashMap<String, Object>());
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID_SECURED, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(STATE_COMPLETED, processInstance.getState().intValue());
    } finally {
        changeUser(TestConfig.getUsername());
    }
}
Also used : TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) 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