Search in sources :

Example 1 with CaseFileItem

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

the class CaseServiceImplTest method testUserTaskToCaseWithStageCompleteCaseDataItem.

@Test
public void testUserTaskToCaseWithStageCompleteCaseDataItem() {
    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());
        Collection<CaseFileItem> caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(0, caseFileItems.size());
        Collection<CaseStageInstance> activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
        assertNotNull(activeStages);
        assertEquals(1, activeStages.size());
        caseService.addDataToCaseFile(caseId, "dataComplete", true);
        activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
        assertNotNull(activeStages);
        assertEquals(0, activeStages.size());
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(1, caseFileItems.size());
        CaseFileItem dataItem = caseFileItems.iterator().next();
        assertNotNull(dataItem);
        assertEquals(caseId, dataItem.getCaseId());
        assertEquals("dataComplete", dataItem.getName());
        assertEquals("true", dataItem.getValue());
        assertEquals(Boolean.class.getName(), dataItem.getType());
        assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
        assertNotNull(dataItem.getLastModified());
        caseService.addDataToCaseFile(caseId, "anotherDataItem", "first version");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(2, caseFileItems.size());
        dataItem = caseFileItems.iterator().next();
        assertNotNull(dataItem);
        assertEquals(caseId, dataItem.getCaseId());
        assertEquals("anotherDataItem", dataItem.getName());
        assertEquals("first version", dataItem.getValue());
        assertEquals(String.class.getName(), dataItem.getType());
        assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
        assertNotNull(dataItem.getLastModified());
        caseService.addDataToCaseFile(caseId, "anotherDataItem", "second version");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(2, caseFileItems.size());
        dataItem = caseFileItems.iterator().next();
        assertNotNull(dataItem);
        assertEquals(caseId, dataItem.getCaseId());
        assertEquals("anotherDataItem", dataItem.getName());
        assertEquals("second version", dataItem.getValue());
        assertEquals(String.class.getName(), dataItem.getType());
        assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
        assertNotNull(dataItem.getLastModified());
        caseService.removeDataFromCaseFile(caseId, "anotherDataItem");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(1, caseFileItems.size());
        identityProvider.setName("mary");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        // mary is not involved in case isntance
        assertEquals(0, caseFileItems.size());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        identityProvider.setName("john");
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) 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) UserImpl(org.jbpm.services.task.impl.model.UserImpl) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)1 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)1 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)1 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)1 CaseFileItem (org.jbpm.casemgmt.api.model.CaseFileItem)1 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)1 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)1 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)1 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)1 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)1 UserImpl (org.jbpm.services.task.impl.model.UserImpl)1 Test (org.junit.Test)1 QueryContext (org.kie.api.runtime.query.QueryContext)1 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)1