Search in sources :

Example 6 with CaseInstance

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

the class CaseServiceImplTest method testStartEmptyCaseAndDestroy.

@Test
public void testStartEmptyCaseAndDestroy() {
    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());
        caseService.destroyCase(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 : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) 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 CaseInstance

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

the class CaseServiceImplTest method testCaseAuthorization.

@Test
public void testCaseAuthorization() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("contact", new GroupImpl("HR"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "description");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(HR_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(HR_CASE_ID, cInstance.getCaseId());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        identityProvider.setName("mary");
        try {
            caseService.cancelCase(caseId);
            fail("Mary is not owner of the case so should not be allowed to cancel the case");
        } catch (SecurityException e) {
        // expected
        }
        try {
            caseService.destroyCase(caseId);
            fail("Mary is not owner of the case so should not be allowed to destroy the case");
        } catch (SecurityException e) {
        // expected
        }
        identityProvider.setName("john");
        caseService.cancelCase(caseId);
        identityProvider.setName("mary");
        try {
            caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID);
            fail("Mary is not owner of the case so should not be allowed to reopen the case");
        } catch (SecurityException e) {
        // expected
        }
        identityProvider.setName("john");
        caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID);
        cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(HR_CASE_ID, cInstance.getCaseId());
    } 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) HashMap(java.util.HashMap) GroupImpl(org.jbpm.services.task.impl.model.GroupImpl) 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 CaseInstance

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

the class CaseServiceImplTest method testAddServiceTaskToEmptyCase.

@Test
public void testAddServiceTaskToEmptyCase() {
    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());
        Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertNotNull(caseProcessInstances);
        assertEquals(1, caseProcessInstances.size());
        ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
        assertNotNull(casePI);
        assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
        String nameVar = (String) processService.getProcessInstanceVariable(casePI.getId(), "name");
        assertNotNull(nameVar);
        assertEquals("my first case", nameVar);
        // add dynamic service task to empty case instance - first by case id
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("Interface", EchoService.class.getName());
        parameters.put("Operation", "echo");
        parameters.put("ParameterType", String.class.getName());
        parameters.put("Parameter", "testing dynamic service task");
        caseService.addDynamicTask(FIRST_CASE_ID, caseService.newTaskSpec("Service Task", "task 1", parameters));
        nameVar = (String) processService.getProcessInstanceVariable(casePI.getId(), "name");
        assertNotNull(nameVar);
        assertEquals("testing dynamic service task echoed by service", nameVar);
        // second dynamic service task add by process instance id
        parameters.put("Parameter", "testing dynamic service task 2");
        caseService.addDynamicTask(casePI.getId(), caseService.newTaskSpec("Service Task", "task 2", parameters));
        nameVar = (String) processService.getProcessInstanceVariable(casePI.getId(), "name");
        assertNotNull(nameVar);
        assertEquals("testing dynamic service task 2 echoed by service", nameVar);
        Collection<NodeInstanceDesc> nodes = runtimeDataService.getProcessInstanceHistoryCompleted(casePI.getId(), new QueryContext());
        assertNotNull(nodes);
        assertEquals(4, 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] task 1"));
        assertTrue(nodesByName.containsKey("[Dynamic] task 2"));
        assertEquals("StartNode", nodesByName.get("StartProcess"));
        assertEquals("EndNode", nodesByName.get("EndProcess"));
        assertEquals("Service Task", nodesByName.get("[Dynamic] task 1"));
        assertEquals("Service Task", nodesByName.get("[Dynamic] task 2"));
    } 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) EchoService(org.jbpm.casemgmt.impl.objects.EchoService) 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 9 with CaseInstance

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

the class CaseServiceImplTest method testStartEmptyCaseWithCaseFileAndDocument.

@Test
public void testStartEmptyCaseWithCaseFileAndDocument() {
    byte[] docContent = "first case document".getBytes();
    DocumentImpl document = new DocumentImpl(UUID.randomUUID().toString(), "test case doc", docContent.length, new Date());
    document.setContent(docContent);
    Map<String, Object> data = new HashMap<>();
    data.put("name", "my first case");
    data.put("document", document);
    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());
        Object doc = cInstance.getCaseFile().getData("document");
        assertNotNull(doc);
        assertTrue(doc instanceof Document);
        Document caseDoc = (Document) doc;
        assertEquals("test case doc", caseDoc.getName());
        assertEquals(docContent.length, caseDoc.getSize());
        assertEquals(new String(docContent), new String(caseDoc.getContent()));
        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) HashMap(java.util.HashMap) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) 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 10 with CaseInstance

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

the class CaseServiceImplTest method testStartEmptyCaseChangeOwner.

@Test
public void testStartEmptyCaseChangeOwner() {
    Map<String, Object> data = new HashMap<>();
    data.put("name", "my first case");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data, new HashMap<>());
    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.removeFromCaseRole(caseId, "owner", new UserImpl("mary"));
        caseService.assignToCaseRole(caseId, "owner", new UserImpl("john"));
        identityProvider.setName("john");
        cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals("john", cInstance.getOwner());
        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) 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)

Aggregations

CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)92 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)88 Test (org.junit.Test)88 HashMap (java.util.HashMap)73 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)66 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)49 QueryContext (org.kie.api.runtime.query.QueryContext)49 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)47 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)47 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)47 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)47 UserImpl (org.jbpm.services.task.impl.model.UserImpl)47 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)46 TaskSummary (org.kie.api.task.model.TaskSummary)42 QueryFilter (org.kie.internal.query.QueryFilter)29 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)23 CaseInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl)12 ArrayList (java.util.ArrayList)10 TaskSpecification (org.jbpm.casemgmt.api.dynamic.TaskSpecification)10 CaseStatus (org.jbpm.casemgmt.api.model.CaseStatus)10