Search in sources :

Example 6 with ProcessInstance

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

the class QueryClientIntegrationTest method testFindProcessInstancesByContainerId.

@Test
public void testFindProcessInstancesByContainerId() {
    final Long processInstanceId = startProcess(CONTAINER_ID, PROCESS_WITH_SIGNAL_ID);
    final List<Integer> statuses = Arrays.asList(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE);
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("containerId", CONTAINER_ID);
    parameters.put("page", "0");
    parameters.put("pageSize", "10");
    parameters.put("status", statuses);
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("query");
    executionServerCommand.setOperation("findProcessInstancesByContainerId");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(List.class);
    final List<ProcessInstance> processInstances = (List<ProcessInstance>) response;
    Assertions.assertThat(processInstances).isNotEmpty();
    final List<Long> processInstancesIds = processInstances.stream().map(p -> p.getId()).collect(Collectors.toList());
    Assertions.assertThat(processInstancesIds).contains(processInstanceId);
    sendSignalToProcessInstance(CONTAINER_ID, processInstanceId, SIGNAL_NAME);
}
Also used : Arrays(java.util.Arrays) List(java.util.List) QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) HashMap(java.util.HashMap) Test(org.junit.Test) Collectors(java.util.stream.Collectors) HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) List(java.util.List) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Example 7 with ProcessInstance

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

the class QueryClientIntegrationTest method testFindProcessInstanceByInitiator.

@Test
public void testFindProcessInstanceByInitiator() {
    final Long processInstanceId = startProcess(CONTAINER_ID, PROCESS_WITH_SIGNAL_ID);
    final List<Integer> statuses = Arrays.asList(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE);
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("initiator", INITIATOR);
    parameters.put("status", statuses);
    parameters.put("page", "0");
    parameters.put("pageSize", "10");
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("query");
    executionServerCommand.setOperation("findProcessInstancesByInitiator");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(List.class);
    final List<ProcessInstance> processInstances = (List<ProcessInstance>) response;
    Assertions.assertThat(processInstances).isNotEmpty();
    final List<Long> processInstancesIds = processInstances.stream().map(p -> p.getId()).collect(Collectors.toList());
    Assertions.assertThat(processInstancesIds).contains(processInstanceId);
    sendSignalToProcessInstance(CONTAINER_ID, processInstanceId, SIGNAL_NAME);
}
Also used : Arrays(java.util.Arrays) List(java.util.List) QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) HashMap(java.util.HashMap) Test(org.junit.Test) Collectors(java.util.stream.Collectors) HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) List(java.util.List) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Example 8 with ProcessInstance

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

the class RuntimeDataServiceIntegrationTest method testGetProcessInstanceByCorrelationKeyPaging.

@Test
public void testGetProcessInstanceByCorrelationKeyPaging() throws Exception {
    CorrelationKeyFactory correlationKeyFactory = KieInternalServices.Factory.get().newCorrelationKeyFactory();
    String businessKey = "simple-key";
    CorrelationKey key = correlationKeyFactory.newCorrelationKey(businessKey);
    // Start and abort 2 processes to be sure that there are processes to be returned.
    Map<String, Object> parameters = new HashMap<String, Object>();
    Long processInstanceId1 = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, key, parameters);
    processClient.abortProcessInstance(CONTAINER_ID, processInstanceId1);
    Long processInstanceId2 = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, key, parameters);
    processClient.abortProcessInstance(CONTAINER_ID, processInstanceId2);
    List<ProcessInstance> processInstancesPage0 = queryClient.findProcessInstancesByCorrelationKey(key, 0, 1);
    List<ProcessInstance> processInstancesPage1 = queryClient.findProcessInstancesByCorrelationKey(key, 1, 1);
    assertEquals(1, processInstancesPage0.size());
    assertEquals(1, processInstancesPage1.size());
    assertNotEquals("Process instances are same! Paging doesn't work.", processInstancesPage0.get(0).getId(), processInstancesPage1.get(0).getId());
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) HashMap(java.util.HashMap) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 9 with ProcessInstance

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

the class RuntimeDataServiceIntegrationTest method testGetProcessInstancesByInitiatorSortedByName.

@Test
public void testGetProcessInstancesByInitiatorSortedByName() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    List<Long> processInstanceIds = createProcessInstances(parameters);
    try {
        List<ProcessInstance> instances = queryClient.findProcessInstancesByInitiator(USER_YODA, null, 0, 3, SORT_BY_PROCESS_ID, true);
        assertNotNull(instances);
        assertEquals(3, instances.size());
        for (ProcessInstance instance : instances) {
            assertTrue(processInstanceIds.contains(instance.getId()));
            assertEquals(PROCESS_ID_SIGNAL_PROCESS, instance.getProcessId());
        }
        instances = queryClient.findProcessInstancesByInitiator(USER_YODA, null, 1, 3, SORT_BY_PROCESS_ID, true);
        assertNotNull(instances);
        assertEquals(2, instances.size());
        for (ProcessInstance instance : instances) {
            assertTrue(processInstanceIds.contains(instance.getId()));
            assertEquals(PROCESS_ID_USERTASK, instance.getProcessId());
        }
        instances = queryClient.findProcessInstancesByInitiator(USER_YODA, null, 0, 10, SORT_BY_PROCESS_ID, false);
        assertNotNull(instances);
        assertEquals(5, instances.size());
        for (int i = 0; i < instances.size(); i++) {
            if (i < 2) {
                assertEquals(PROCESS_ID_USERTASK, instances.get(i).getProcessId());
            } else {
                assertEquals(PROCESS_ID_SIGNAL_PROCESS, instances.get(i).getProcessId());
            }
        }
    } finally {
        abortProcessInstances(processInstanceIds);
    }
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 10 with ProcessInstance

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

the class RuntimeDataServiceIntegrationTest method testGetProcessInstanceWithVariables.

@Test
public void testGetProcessInstanceWithVariables() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    Object person = createPersonInstance(USER_JOHN);
    parameters.put("personData", person);
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_SIGNAL_PROCESS, parameters);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId.longValue() > 0);
    try {
        ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId, true);
        assertNotNull(processInstance);
        assertEquals(processInstanceId, processInstance.getId());
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.getState().intValue());
        assertEquals(PROCESS_ID_SIGNAL_PROCESS, processInstance.getProcessId());
        assertEquals("signalprocess", processInstance.getProcessName());
        assertEquals("1.0", processInstance.getProcessVersion());
        assertEquals(CONTAINER_ID, processInstance.getContainerId());
        assertEquals("signalprocess", processInstance.getProcessInstanceDescription());
        assertEquals(TestConfig.getUsername(), processInstance.getInitiator());
        assertEquals(-1l, processInstance.getParentId().longValue());
        assertNotNull(processInstance.getCorrelationKey());
        assertNotNull(processInstance.getDate());
        Map<String, Object> variables = processInstance.getVariables();
        assertNotNull(variables);
        assertEquals(4, variables.size());
        assertTrue(variables.containsKey("stringData"));
        assertTrue(variables.containsKey("personData"));
        assertTrue(variables.containsKey("initiator"));
        assertTrue(variables.containsKey("nullAccepted"));
        String stringVar = (String) variables.get("stringData");
        Object personVar = variables.get("personData");
        String initiator = (String) variables.get("initiator");
        assertNotNull(personVar);
        assertEquals(person.toString(), personVar);
        assertNotNull(stringVar);
        assertEquals("waiting for signal", stringVar);
        assertNotNull(initiator);
        assertEquals(TestConfig.getUsername(), initiator);
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : HashMap(java.util.HashMap) 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