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);
}
}
}
Aggregations