Search in sources :

Example 16 with NodeInstance

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

the class SLAComplianceIntegrationTest method testSLAonUserTaskViolated.

@Test
@Category({ UnstableOnJenkinsPrBuilder.class })
public void testSLAonUserTaskViolated() throws Exception {
    Long pid = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK_WITH_SLA_ON_TASK, new HashMap<>());
    assertProcessInstance(pid, STATE_ACTIVE, SLA_NA);
    // Yoda should have one task available with SLA
    List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    TaskSummary task = tasks.get(0);
    assertThat(tasks).hasSize(1);
    assertThat(task.getName()).isEqualTo("Hello");
    List<NodeInstance> activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
    assertThat(activeNodes).hasSize(1);
    NodeInstance taskNode = activeNodes.get(0);
    assertNodeInstance(taskNode, "Hello", SLA_PENDING);
    // Let's wait for SLA violation
    KieServerSynchronization.waitForNodeInstanceSLAViolated(queryClient, pid, taskNode.getId(), 8_000L);
    assertProcessInstance(pid, STATE_ACTIVE, SLA_NA);
    activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
    assertThat(activeNodes).hasSize(1);
    taskNode = activeNodes.get(0);
    assertNodeInstance(taskNode, "Hello", SLA_VIOLATED);
    taskClient.completeAutoProgress(CONTAINER_ID, task.getId(), USER_YODA, null);
    tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    assertThat(tasks).isEmpty();
    activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
    assertThat(activeNodes).isEmpty();
    taskNode = getNodeInstanceById(queryClient.findCompletedNodeInstances(pid, 0, 10), taskNode.getId());
    assertNodeInstance(taskNode, "Hello", SLA_VIOLATED);
    assertProcessInstance(pid, STATE_COMPLETED, SLA_NA);
}
Also used : TaskSummary(org.kie.server.api.model.instance.TaskSummary) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 17 with NodeInstance

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

the class SLAComplianceIntegrationTest method testSLAonUserTaskMet.

@Test
public void testSLAonUserTaskMet() throws Exception {
    Long pid = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK_WITH_SLA_ON_TASK, new HashMap<>());
    assertProcessInstance(pid, STATE_ACTIVE, SLA_NA);
    // Yoda should have one task available with SLA
    List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    TaskSummary task = tasks.get(0);
    assertThat(tasks).hasSize(1);
    assertThat(task.getName()).isEqualTo("Hello");
    List<NodeInstance> activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
    assertThat(activeNodes).hasSize(1);
    NodeInstance taskNode = activeNodes.get(0);
    assertNodeInstance(taskNode, "Hello", SLA_PENDING);
    taskClient.completeAutoProgress(CONTAINER_ID, task.getId(), USER_YODA, null);
    tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    assertThat(tasks).isEmpty();
    activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
    assertThat(activeNodes).isEmpty();
    taskNode = getNodeInstanceById(queryClient.findCompletedNodeInstances(pid, 0, 10), taskNode.getId());
    assertNodeInstance(taskNode, "Hello", SLA_MET);
    assertProcessInstance(pid, STATE_COMPLETED, SLA_NA);
}
Also used : TaskSummary(org.kie.server.api.model.instance.TaskSummary) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Test(org.junit.Test)

Example 18 with NodeInstance

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

the class StartProcessServiceIntegrationTest method testStartProcessFromNodeIdWithCorrelationKeyProcess.

@Test()
public void testStartProcessFromNodeIdWithCorrelationKeyProcess() {
    Map<String, Object> parameters = new HashMap<>();
    Long processInstanceId = processClient.startProcess(CONTAINER_ID_RESTART, PROCESS_ID_RESTART, parameters);
    try {
        assertNotNull(processInstanceId);
        assertTrue(processInstanceId > 0);
        // Process instance is running and is active.
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID_RESTART, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.getState().intValue());
        processClient.abortProcessInstance(CONTAINER_ID_RESTART, processInstanceId);
        List<NodeInstance> list = this.processClient.findNodeInstancesByType(CONTAINER_ID_RESTART, processInstanceId, "ABORTED", 0, 10);
        String[] nodeIds = list.stream().map(NodeInstance::getNodeId).toArray(String[]::new);
        CorrelationKeyFactory correlationKeyFactory = KieInternalServices.Factory.get().newCorrelationKeyFactory();
        CorrelationKey firstKey = correlationKeyFactory.newCorrelationKey("mysimlekey");
        processInstanceId = null;
        processInstanceId = processClient.startProcessFromNodeIds(CONTAINER_ID_RESTART, PROCESS_ID_RESTART, firstKey, parameters, nodeIds);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.getState().intValue());
        ProcessInstance pi = processClient.getProcessInstance(CONTAINER_ID_RESTART, processInstanceId);
        assertThat(pi.getCorrelationKey(), is("mysimlekey"));
        processClient.abortProcessInstance(CONTAINER_ID_RESTART, processInstanceId);
    } catch (Exception e) {
        if (processInstanceId != null) {
            processClient.abortProcessInstance(CONTAINER_ID_RESTART, processInstanceId);
        }
        fail(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) CorrelationKey(org.kie.internal.process.CorrelationKey) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Test(org.junit.Test)

Example 19 with NodeInstance

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

the class StartProcessServiceIntegrationTest method testStartProcessFromNodeId.

@Test()
public void testStartProcessFromNodeId() {
    Map<String, Object> parameters = new HashMap<>();
    Long processInstanceId = processClient.startProcess(CONTAINER_ID_RESTART, PROCESS_ID_RESTART, parameters);
    try {
        assertNotNull(processInstanceId);
        assertTrue(processInstanceId > 0);
        // Process instance is running and is active.
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID_RESTART, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.getState().intValue());
        processClient.abortProcessInstance(CONTAINER_ID_RESTART, processInstanceId);
        List<NodeInstance> list = this.processClient.findNodeInstancesByType(CONTAINER_ID_RESTART, processInstanceId, "ABORTED", 0, 10);
        String[] nodeIds = list.stream().map(NodeInstance::getNodeId).toArray(String[]::new);
        processInstanceId = null;
        processInstanceId = processClient.startProcessFromNodeIds(CONTAINER_ID_RESTART, PROCESS_ID_RESTART, parameters, nodeIds);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.getState().intValue());
        list = this.processClient.findNodeInstancesByType(CONTAINER_ID_RESTART, processInstanceId, "START", 0, 10);
        assertNotNull(list);
        assertThat(list.size(), is(1));
        assertThat(list.get(0).getName(), is("Human Task"));
        processClient.abortProcessInstance(CONTAINER_ID_RESTART, processInstanceId);
    } catch (Exception e) {
        if (processInstanceId != null) {
            processClient.abortProcessInstance(CONTAINER_ID_RESTART, processInstanceId);
        }
        fail(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Test(org.junit.Test)

Example 20 with NodeInstance

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

the class ProcessInstanceAdminServiceIntegrationTest method assertSlaComplianceAndDueDate.

private void assertSlaComplianceAndDueDate(Long pid, Date dueDate, String entryType, int slaCompliance) {
    List<NodeInstance> nodes = processClient.findNodeInstancesByType(CONTAINER_ID, pid, entryType, 0, 10);
    NodeInstance userTask = nodes.stream().filter(n -> USER_TASK_NAME.equals(n.getName())).findFirst().orElseThrow(() -> new RuntimeException("Node '" + USER_TASK_NAME + "' not found as entryType " + entryType));
    assertEquals(slaCompliance, userTask.getSlaCompliance().intValue());
    assertThat(userTask.getSlaDueDate()).isCloseTo(dueDate, 2000);
}
Also used : NodeInstance(org.kie.server.api.model.instance.NodeInstance)

Aggregations

NodeInstance (org.kie.server.api.model.instance.NodeInstance)23 Test (org.junit.Test)16 HashMap (java.util.HashMap)12 TaskSummary (org.kie.server.api.model.instance.TaskSummary)6 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)4 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)4 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)3 ArrayList (java.util.ArrayList)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 Category (org.junit.experimental.categories.Category)2 CorrelationKey (org.kie.internal.process.CorrelationKey)2 NodeInstanceList (org.kie.server.api.model.instance.NodeInstanceList)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1