Search in sources :

Example 6 with CaseInstanceImpl

use of org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.

the class CaseServiceImplTest method testStartThenReopenEmptyCase.

@Test
public void testStartThenReopenEmptyCase() {
    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(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals("my first case", cInstance.getCaseDescription());
        long firstCaseProcessInstanceId = ((CaseInstanceImpl) cInstance).getProcessInstanceId();
        caseService.cancelCase(caseId);
        CaseInstance instance = caseService.getCaseInstance(caseId);
        Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
        caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
        cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals("my first case", cInstance.getCaseDescription());
        long secondCaseProcessInstanceId = ((CaseInstanceImpl) cInstance).getProcessInstanceId();
        assertTrue(secondCaseProcessInstanceId > firstCaseProcessInstanceId);
        caseService.destroyCase(caseId);
        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) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) HashMap(java.util.HashMap) 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 7 with CaseInstanceImpl

use of org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.

the class CaseServiceImplTest method testStartEmptyCaseUsingCaseFileOwnerAsLoggedInUser.

@Test
public void testStartEmptyCaseUsingCaseFileOwnerAsLoggedInUser() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("mary"));
    Map<String, Object> data = new HashMap<>();
    data.put("name", "my first case");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data, roleAssignments);
    identityProvider.setName("mary");
    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("mary", cInstance.getOwner());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        String initiator = (String) processService.getProcessInstanceVariable(((CaseInstanceImpl) cInstance).getProcessInstanceId(), "initiator");
        assertEquals("mary", initiator);
        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 : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) HashMap(java.util.HashMap) UserImpl(org.jbpm.services.task.impl.model.UserImpl) 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 8 with CaseInstanceImpl

use of org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.

the class CaseServiceImplTest method testStartThenReopenEmptyCaseUpdateDescription.

@Test
public void testStartThenReopenEmptyCaseUpdateDescription() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals("#{name}", cInstance.getCaseDescription());
        long firstCaseProcessInstanceId = ((CaseInstanceImpl) cInstance).getProcessInstanceId();
        caseService.cancelCase(caseId);
        CaseInstance instance = caseService.getCaseInstance(caseId);
        Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
        Map<String, Object> data = new HashMap<>();
        data.put("name", "my first case");
        caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
        cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals("my first case", cInstance.getCaseDescription());
        long secondCaseProcessInstanceId = ((CaseInstanceImpl) cInstance).getProcessInstanceId();
        assertTrue(secondCaseProcessInstanceId > firstCaseProcessInstanceId);
        caseService.destroyCase(caseId);
        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 : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) HashMap(java.util.HashMap) 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 9 with CaseInstanceImpl

use of org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl 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 10 with CaseInstanceImpl

use of org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.

the class CaseServiceImplTest method testStartEmptyCaseWithCaseFile.

@Test
public void testStartEmptyCaseWithCaseFile() {
    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, true, false, false, false);
        assertNotNull(cInstance);
        assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
        assertNotNull(cInstance.getCaseFile());
        assertEquals("my first case", cInstance.getCaseFile().getData("name"));
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        Collection<VariableDesc> vars = runtimeDataService.getVariablesCurrentState(((CaseInstanceImpl) cInstance).getProcessInstanceId());
        assertNotNull(vars);
        assertEquals(3, vars.size());
        Map<String, Object> mappedVars = vars.stream().collect(toMap(v -> v.getVariableId(), v -> v.getNewValue()));
        assertEquals("my first case", mappedVars.get("caseFile_name"));
        assertEquals(FIRST_CASE_ID, mappedVars.get("CaseId"));
        assertEquals("john", mappedVars.get("initiator"));
        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 : TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) Date(java.util.Date) CommentSortBy(org.jbpm.casemgmt.api.model.instance.CommentSortBy) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) LoggerFactory(org.slf4j.LoggerFactory) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) KieInternalServices(org.kie.internal.KieInternalServices) Assertions(org.assertj.core.api.Assertions) AuthorizationManager(org.jbpm.casemgmt.api.auth.AuthorizationManager) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) Collection(java.util.Collection) UUID(java.util.UUID) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) Assert.assertFalse(org.junit.Assert.assertFalse) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) Person(org.jbpm.bpmn2.objects.Person) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) Status(org.kie.api.task.model.Status) UserImpl(org.jbpm.services.task.impl.model.UserImpl) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) HashMap(java.util.HashMap) QueryFilter(org.kie.internal.query.QueryFilter) ArrayList(java.util.ArrayList) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) StageStatus(org.jbpm.casemgmt.api.model.instance.StageStatus) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) VariableDesc(org.jbpm.services.api.model.VariableDesc) CorrelationKey(org.kie.internal.process.CorrelationKey) Assert.assertNotNull(org.junit.Assert.assertNotNull) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) GroupImpl(org.jbpm.services.task.impl.model.GroupImpl) MilestoneStatus(org.jbpm.casemgmt.api.model.instance.MilestoneStatus) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) Assert.assertNull(org.junit.Assert.assertNull) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) Document(org.jbpm.document.Document) EchoService(org.jbpm.casemgmt.impl.objects.EchoService) Collections(java.util.Collections) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) Assert.assertEquals(org.junit.Assert.assertEquals) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) HashMap(java.util.HashMap) VariableDesc(org.jbpm.services.api.model.VariableDesc) 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

CaseInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl)12 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)11 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)11 Test (org.junit.Test)11 HashMap (java.util.HashMap)8 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)8 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)8 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)8 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)8 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)8 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)8 TaskSummary (org.kie.api.task.model.TaskSummary)5 QueryFilter (org.kie.internal.query.QueryFilter)5 UserImpl (org.jbpm.services.task.impl.model.UserImpl)4 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)3 TaskSpecification (org.jbpm.casemgmt.api.dynamic.TaskSpecification)2 CaseMilestoneInstance (org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance)2 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)2 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)2 QueryContext (org.kie.api.runtime.query.QueryContext)2