Search in sources :

Example 6 with NodeInstance

use of org.kie.server.api.model.instance.NodeInstance 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 7 with NodeInstance

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

the class ProcessUserTaskServicesSecurityIntegrationTest method testNonAllowedUserCannotStartProcessFromNodeIdsWithCorrelationKey.

@Test
public void testNonAllowedUserCannotStartProcessFromNodeIdsWithCorrelationKey() throws Exception {
    Map<String, Object> parameters = new HashMap<>();
    Long processInstanceId = startProcessAsAdministrator(PROCESS_ID_USERTASK_SECURED);
    try {
        processClient.abortProcessInstance(CONTAINER_ID_SECURED, processInstanceId);
        List<NodeInstance> list = this.processClient.findNodeInstancesByType(CONTAINER_ID_SECURED, 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;
        changeUser(USER_YODA);
        assertClientException(() -> processClient.startProcessFromNodeIds(CONTAINER_ID_SECURED, PROCESS_ID_USERTASK_SECURED, firstKey, parameters, nodeIds), 403, String.format(NO_PERMISSION_MSG, USER_YODA));
    } finally {
        if (processInstanceId != null)
            abortProcessAsAdministrator(processInstanceId);
        changeUser(TestConfig.getUsername());
    }
}
Also used : HashMap(java.util.HashMap) CorrelationKey(org.kie.internal.process.CorrelationKey) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Test(org.junit.Test)

Example 8 with NodeInstance

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

the class CaseManagementRuntimeDataServiceBase method getActiveNodes.

public NodeInstanceList getActiveNodes(String containerId, String caseId, Integer page, Integer pageSize) {
    Collection<NodeInstanceDesc> activeNodeInstances = caseRuntimeDataService.getActiveNodesForCase(caseId, ConvertUtils.buildQueryContext(page, pageSize));
    List<NodeInstance> activeNodes = ConvertUtils.transformNodeInstance(activeNodeInstances);
    NodeInstanceList activeNodesList = new NodeInstanceList(activeNodes);
    return activeNodesList;
}
Also used : NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) NodeInstance(org.kie.server.api.model.instance.NodeInstance) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList)

Example 9 with NodeInstance

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

the class CaseRuntimeDataServiceIntegrationTest method testGetCaseInstanceCarInsuranceClaimCaseWithData.

@Test
public void testGetCaseInstanceCarInsuranceClaimCaseWithData() {
    String caseId = startCarInsuranceClaimCase(USER_YODA, USER_JOHN, USER_YODA);
    CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId, true, true, true, true);
    assertCarInsuranceCaseInstance(caseInstance, caseId, USER_YODA);
    KieServerAssert.assertNullOrEmpty("Milestones should be empty.", caseInstance.getMilestones());
    // Assert case file
    assertNotNull(caseInstance.getCaseFile());
    assertEquals("first case started", caseInstance.getCaseFile().getData().get("s"));
    // Assert role assignments
    assertNotNull(caseInstance.getRoleAssignments());
    assertEquals(4, caseInstance.getRoleAssignments().size());
    CaseRoleAssignment ownerRole = caseInstance.getRoleAssignments().get(0);
    assertEquals("owner", ownerRole.getName());
    assertEquals(1, ownerRole.getUsers().size());
    assertEquals(USER_YODA, ownerRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", ownerRole.getGroups());
    CaseRoleAssignment insuredRole = caseInstance.getRoleAssignments().get(1);
    assertEquals("insured", insuredRole.getName());
    assertEquals(1, insuredRole.getUsers().size());
    assertEquals(USER_YODA, insuredRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", insuredRole.getGroups());
    CaseRoleAssignment assessorRole = caseInstance.getRoleAssignments().get(2);
    assertEquals("assessor", assessorRole.getName());
    assertEquals(USER_YODA, assessorRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", assessorRole.getGroups());
    CaseRoleAssignment insuranceRepresentativeRole = caseInstance.getRoleAssignments().get(3);
    assertEquals("insuranceRepresentative", insuranceRepresentativeRole.getName());
    assertEquals(1, insuranceRepresentativeRole.getUsers().size());
    assertEquals(USER_JOHN, insuranceRepresentativeRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", insuranceRepresentativeRole.getGroups());
    // Assert stages
    assertNotNull(caseInstance.getStages());
    assertEquals(1, caseInstance.getStages().size());
    CaseStage stage = caseInstance.getStages().get(0);
    assertNotNull(stage.getIdentifier());
    assertEquals("Build claim report", stage.getName());
    assertEquals("Active", stage.getStatus());
    List<NodeInstance> activeNodes = stage.getActiveNodes();
    assertEquals(1, activeNodes.size());
    assertEquals("Provide accident information", activeNodes.get(0).getName());
    assertEquals("HumanTaskNode", activeNodes.get(0).getNodeType());
    assertEquals(2, stage.getAdHocFragments().size());
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseRoleAssignment(org.kie.server.api.model.cases.CaseRoleAssignment) CaseStage(org.kie.server.api.model.cases.CaseStage) NodeInstance(org.kie.server.api.model.instance.NodeInstance) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 10 with NodeInstance

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

the class ProcessInstanceAdminServiceIntegrationTest method assertSLAComplianceAfterWaiting.

private void assertSLAComplianceAfterWaiting(Long pid, int slaCompliance, int waitingTime) throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    assertFalse(latch.await(waitingTime, TimeUnit.SECONDS));
    List<NodeInstance> activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
    assertThat(activeNodes).hasSize(1);
    assertEquals("SLA compliance should be " + slaCompliance + " after updating the timer and waiting " + waitingTime + " seconds", slaCompliance, activeNodes.get(0).getSlaCompliance().intValue());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) 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