use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testCaseRolesWithQueries.
@Test
public void testCaseRolesWithQueries() {
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(CaseStatus.OPEN.getId(), cInstance.getStatus().intValue());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
// only john is now included in case roles
Collection<CaseInstance> instances = caseRuntimeDataService.getCaseInstancesAnyRole(null, new QueryContext());
assertNotNull(instances);
assertEquals(0, instances.size());
List<CaseStatus> status = Arrays.asList(CaseStatus.CANCELLED);
instances = caseRuntimeDataService.getCaseInstancesAnyRole(status, new QueryContext());
assertNotNull(instances);
assertFalse("Opened case was returned when searching for cancelled case instances.", instances.stream().anyMatch(n -> n.getCaseId().equals(caseId)));
status = Arrays.asList(CaseStatus.OPEN);
instances = caseRuntimeDataService.getCaseInstancesAnyRole(status, new QueryContext());
assertNotNull(instances);
assertEquals(1, instances.size());
instances = caseRuntimeDataService.getCaseInstancesByRole(null, status, new QueryContext());
assertNotNull(instances);
assertEquals(0, instances.size());
instances = caseRuntimeDataService.getCaseInstancesByRole("owner", status, new QueryContext());
assertNotNull(instances);
assertEquals(1, instances.size());
identityProvider.setName("mary");
instances = caseRuntimeDataService.getCaseInstancesByRole("owner", status, new QueryContext());
assertNotNull(instances);
assertEquals("Mary shouldn't be owner of any opened case instance.", 0, instances.size());
identityProvider.setRoles(Arrays.asList("HR"));
instances = caseRuntimeDataService.getCaseInstancesByRole("contact", status, new QueryContext());
assertNotNull(instances);
assertEquals(1, instances.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);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class StageCompletionConditionTest method testCaseDataVariableCompleteTask.
@Test
public void testCaseDataVariableCompleteTask() {
Map<String, Object> data = new HashMap<>();
data.put("continue", false);
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_DATA_BOOLEAN, data, Collections.emptyMap());
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_DATA_BOOLEAN, caseFile);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
assertCaseInstanceActive(caseId);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary insideTask = tasks.get(0);
assertThat(insideTask.getName()).isEqualTo(INSIDE_TASK);
userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
assertCaseInstanceActive(caseId);
caseService.addDataToCaseFile(caseId, "continue", true);
assertCaseInstanceNotActive(caseId);
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class StageCompletionConditionTest method testCaseFileVariableWithProcessVariable.
@Test
public void testCaseFileVariableWithProcessVariable() {
Map<String, Object> data = new HashMap<>();
data.put("continue", false);
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_AND_PROCESS_VARIABLE, data, Collections.emptyMap());
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_AND_PROCESS_VARIABLE, caseFile);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
assertCaseInstanceActive(caseId);
CaseInstance caseInstance = caseService.getCaseInstance(caseId);
assertThat(caseInstance).isNotNull();
Long processInstanceId = ((CaseInstanceImpl) caseInstance).getProcessInstanceId();
processService.setProcessVariable(processInstanceId, "continue", true);
assertCaseInstanceActive(caseId);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary insideTask = tasks.get(0);
assertThat(insideTask.getName()).isEqualTo(INSIDE_TASK);
userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
assertCaseInstanceActive(caseId);
caseService.addDataToCaseFile(caseId, "continue", true);
assertCaseInstanceActive(caseId);
caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getCaseStages()).hasSize(1);
String stageId = caseInstance.getCaseStages().iterator().next().getId();
TaskSpecification dynamicTaskSpecification = caseService.newHumanTaskSpec(DYNAMIC_TASK, "", USER, null, Collections.emptyMap());
caseService.addDynamicTaskToStage(caseId, stageId, dynamicTaskSpecification);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary dynamicTask = tasks.get(0);
assertThat(dynamicTask.getName()).isEqualTo(DYNAMIC_TASK);
userTaskService.completeAutoProgress(dynamicTask.getId(), USER, null);
assertCaseInstanceNotActive(caseId);
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class StageCompletionConditionTest method testCaseFileVariable.
@Test
public void testCaseFileVariable() {
Map<String, Object> data = new HashMap<>();
data.put("continue", false);
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_VARIABLE, data, Collections.emptyMap());
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_VARIABLE, caseFile);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
assertCaseInstanceActive(caseId);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary insideTask = tasks.get(0);
assertThat(insideTask.getName()).isEqualTo(INSIDE_TASK);
userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
assertCaseInstanceActive(caseId);
caseService.addDataToCaseFile(caseId, "continue", true);
assertCaseInstanceActive(caseId);
CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getCaseStages()).hasSize(1);
String stageId = caseInstance.getCaseStages().iterator().next().getId();
TaskSpecification dynamicTaskSpecification = caseService.newHumanTaskSpec(DYNAMIC_TASK, "", USER, null, Collections.emptyMap());
caseService.addDynamicTaskToStage(caseId, stageId, dynamicTaskSpecification);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary dynamicTask = tasks.get(0);
assertThat(dynamicTask.getName()).isEqualTo(DYNAMIC_TASK);
userTaskService.completeAutoProgress(dynamicTask.getId(), USER, null);
assertCaseInstanceNotActive(caseId);
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class StageCompletionConditionTest method testCaseDataVariableInteger.
@Test
public void testCaseDataVariableInteger() {
Map<String, Object> data = new HashMap<>();
data.put("continue", 0);
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_DATA_INTEGER, data, Collections.emptyMap());
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_DATA_INTEGER, caseFile);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
assertCaseInstanceActive(caseId);
caseService.addDataToCaseFile(caseId, "continue", 1);
assertCaseInstanceNotActive(caseId);
}
Aggregations