Search in sources :

Example 76 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.

the class CaseServiceImplTest method testTriggerNotExistingAdHocFragment.

@Test
public void testTriggerNotExistingAdHocFragment() {
    String expectedCaseId = "UniqueID-0000000001";
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("patient", new UserImpl("john"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "description");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), "CaseWithRolesDefinition", data, roleAssignments);
    identityProvider.setName("mary");
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), "CaseWithRolesDefinition", caseFile);
    assertNotNull(caseId);
    assertEquals(expectedCaseId, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(expectedCaseId, cInstance.getCaseId());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        identityProvider.setName("john");
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(expectedCaseId, "john", Arrays.asList(Status.Reserved), new QueryContext());
        assertEquals(1, tasks.size());
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
        identityProvider.setName("mary");
        try {
            caseService.triggerAdHocFragment(expectedCaseId, "not existing", null);
            fail("There is no ad hoc fragment with name 'not existing'");
        } catch (AdHocFragmentNotFoundException e) {
        // expected
        }
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            identityProvider.setName("mary");
            caseService.cancelCase(caseId);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) QueryContext(org.kie.api.runtime.query.QueryContext) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) 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) UserImpl(org.jbpm.services.task.impl.model.UserImpl) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 77 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance 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 78 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.

the class CaseServiceImplTest method testAddSubprocessToCaseWithStage.

@Test
public void testAddSubprocessToCaseWithStage() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_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());
        CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID);
        assertNotNull(caseDef);
        assertEquals(1, caseDef.getCaseStages().size());
        assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
        CaseStage stage = caseDef.getCaseStages().iterator().next();
        // add dynamic user task to empty case instance - first by case id
        Map<String, Object> parameters = new HashMap<>();
        caseService.addDynamicSubprocessToStage(FIRST_CASE_ID, stage.getId(), 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());
        caseService.addDynamicSubprocessToStage(casePI.getId(), stage.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 : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) 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) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) UserImpl(org.jbpm.services.task.impl.model.UserImpl) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 79 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.

the class CaseServiceImplTest method testAddSubprocessToEmptyCaseAndClose.

@Test
public void testAddSubprocessToEmptyCaseAndClose() {
    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());
        caseService.closeCase(caseId, "not needed any more");
        cInstance = caseRuntimeDataService.getCaseInstanceById(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals("not needed any more", cInstance.getCompletionMessage());
        caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, Arrays.asList(2), new QueryContext());
        assertNotNull(caseProcessInstances);
        assertEquals(2, caseProcessInstances.size());
        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 : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) 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) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 80 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.

the class CaseServiceImplTest method testStartCaseWithStageAndAdHocFragments.

@Test
public void testStartCaseWithStageAndAdHocFragments() {
    Map<String, Object> data = new HashMap<>();
    data.put("name", "my first case");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_ADHOC_CASE_P_ID, data);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_ADHOC_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        assertCaseInstance(caseId, "my first case");
        Collection<AdHocFragment> availableFragments = caseRuntimeDataService.getAdHocFragmentsForCase(caseId);
        assertEquals(2, availableFragments.size());
        Map<String, AdHocFragment> mapped = mapAdHocFragments(availableFragments);
        assertEquals("HumanTaskNode", mapped.get("Adhoc 1").getType());
        assertEquals("HumanTaskNode", mapped.get("Adhoc 2").getType());
        List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        assertTask(tasks.get(0), "john", "Initial step", Status.Reserved);
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
        availableFragments = caseRuntimeDataService.getAdHocFragmentsForCase(caseId);
        assertEquals(4, availableFragments.size());
        mapped = mapAdHocFragments(availableFragments);
        assertEquals("HumanTaskNode", mapped.get("Adhoc 1").getType());
        assertEquals("HumanTaskNode", mapped.get("Adhoc 2").getType());
        assertEquals("HumanTaskNode", mapped.get("First").getType());
        assertEquals("HumanTaskNode", mapped.get("Second").getType());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) QueryFilter(org.kie.internal.query.QueryFilter) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) 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) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)121 HashMap (java.util.HashMap)95 Test (org.junit.Test)86 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)81 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)66 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)61 UserImpl (org.jbpm.services.task.impl.model.UserImpl)54 QueryContext (org.kie.api.runtime.query.QueryContext)46 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)44 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)42 TaskSummary (org.kie.api.task.model.TaskSummary)40 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)39 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)39 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)39 QueryFilter (org.kie.internal.query.QueryFilter)26 ArrayList (java.util.ArrayList)21 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)20 Collection (java.util.Collection)17 List (java.util.List)17 Map (java.util.Map)16