Search in sources :

Example 26 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.

the class CaseServiceImplTest method testAddSubprocessToEmptyCase.

@Test
public void testAddSubprocessToEmptyCase() {
    Map<String, Object> data = new HashMap<>();
    data.put("name", "my first case");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        // add dynamic user task to empty case instance - first by case id
        Map<String, Object> parameters = new HashMap<>();
        caseService.addDynamicSubprocess(FIRST_CASE_ID, SUBPROCESS_P_ID, parameters);
        // second task add by process instance id
        Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertNotNull(caseProcessInstances);
        assertEquals(2, caseProcessInstances.size());
        ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
        assertNotNull(casePI);
        assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
        Collection<NodeInstanceDesc> nodes = runtimeDataService.getProcessInstanceHistoryCompleted(casePI.getId(), new QueryContext());
        assertNotNull(nodes);
        assertEquals(3, nodes.size());
        Map<String, String> nodesByName = nodes.stream().collect(toMap(NodeInstanceDesc::getName, NodeInstanceDesc::getNodeType));
        assertTrue(nodesByName.containsKey("StartProcess"));
        assertTrue(nodesByName.containsKey("EndProcess"));
        assertTrue(nodesByName.containsKey("[Dynamic] Sub Process"));
        assertEquals("StartNode", nodesByName.get("StartProcess"));
        assertEquals("EndNode", nodesByName.get("EndProcess"));
        assertEquals("SubProcessNode", nodesByName.get("[Dynamic] Sub Process"));
        caseService.addDynamicSubprocess(casePI.getId(), SUBPROCESS_P_ID, parameters);
        // let's verify that there are three process instances related to this case
        caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertNotNull(caseProcessInstances);
        assertEquals(3, caseProcessInstances.size());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : HashMap(java.util.HashMap) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 27 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.

the class CaseServiceImplTest method testStartCaseWithoutStartNode.

@Test
public void testStartCaseWithoutStartNode() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), NO_START_NODE_CASE_P_ID);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(((CaseInstanceImpl) cInstance).getProcessInstanceId(), new org.kie.api.runtime.query.QueryContext());
        assertNotNull(activeNodes);
        assertEquals(1, activeNodes.size());
        NodeInstanceDesc active = activeNodes.iterator().next();
        assertEquals("Initial step", active.getName());
        List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary task = tasks.get(0);
        userTaskService.completeAutoProgress(task.getId(), "john", new HashMap<>());
        activeNodes = runtimeDataService.getProcessInstanceHistoryActive(((CaseInstanceImpl) cInstance).getProcessInstanceId(), new org.kie.api.runtime.query.QueryContext());
        assertNotNull(activeNodes);
        assertEquals(1, activeNodes.size());
        active = activeNodes.iterator().next();
        assertEquals("stage", active.getName());
        caseService.cancelCase(caseId);
        CaseInstance instance = caseService.getCaseInstance(caseId);
        Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
        caseId = null;
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : QueryContext(org.kie.api.runtime.query.QueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) TaskSummary(org.kie.api.task.model.TaskSummary) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 28 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.

the class ETransactionTest method testStartProcessCommit.

@Test
public void testStartProcessCommit() throws Exception {
    UserTransaction ut = InitialContext.doLookup(USER_TRANSACTION_NAME);
    ut.begin();
    Long processInstanceId = null;
    ProcessInstanceDesc processDesc = null;
    List<NodeInstanceDesc> processInstanceHistory = null;
    try {
        processInstanceId = startProcessInstance(PROCESS_ID);
        checkProcessInstanceIsActive(processInstanceId);
    } catch (Exception e) {
        ut.rollback();
        throw e;
    }
    ut.commit();
    checkProcessInstanceIsActive(processInstanceId);
}
Also used : UserTransaction(javax.transaction.UserTransaction) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractRuntimeEJBServicesTest(org.jbpm.test.container.AbstractRuntimeEJBServicesTest) Test(org.junit.Test)

Example 29 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.

the class ETransactionTest method testStartProcessRollback.

@Test
public void testStartProcessRollback() throws Exception {
    UserTransaction ut = InitialContext.doLookup(USER_TRANSACTION_NAME);
    ut.begin();
    Long processInstanceId = null;
    ProcessInstanceDesc processDesc = null;
    List<NodeInstanceDesc> processInstanceHistory = null;
    try {
        processInstanceId = startProcessInstance(PROCESS_ID);
        checkProcessInstanceIsActive(processInstanceId);
    } catch (Exception e) {
        ut.rollback();
        throw e;
    }
    ut.rollback();
    try {
        processDesc = runtimeDataService.getProcessInstanceById(processInstanceId);
        Assertions.assertThat(processDesc).isNull();
        processInstanceHistory = getProcessInstanceHistory(processInstanceId);
        Assertions.assertThat(processInstanceHistory).isNullOrEmpty();
    } catch (NullPointerException npe) {
        LOGGER.error("Non-XA database thrown NPE on process started before rollback", npe);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractRuntimeEJBServicesTest(org.jbpm.test.container.AbstractRuntimeEJBServicesTest) Test(org.junit.Test)

Example 30 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.

the class ETransactionTest method checkProcessInstanceIsActive.

private void checkProcessInstanceIsActive(Long processInstanceId) {
    ProcessInstanceDesc processDesc = runtimeDataService.getProcessInstanceById(processInstanceId);
    Assertions.assertThat(processDesc).isNotNull();
    Assertions.assertThat(processDesc.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<NodeInstanceDesc> processInstanceHistory = getProcessInstanceHistory(processInstanceId);
    Assertions.assertThat(processInstanceHistory).isNotNull().isNotEmpty();
}
Also used : ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc)

Aggregations

NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)45 Test (org.junit.Test)40 QueryContext (org.kie.api.runtime.query.QueryContext)29 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)20 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)19 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)15 HashMap (java.util.HashMap)14 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)12 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)9 TaskSummary (org.kie.api.task.model.TaskSummary)9 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)8 WorkItem (org.kie.api.runtime.process.WorkItem)8 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)7 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)6 QueryFilter (org.kie.internal.query.QueryFilter)6 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)4 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)4 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)4 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)4 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)4