use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseAndClose.
@Test
public void testStartEmptyCaseAndClose() {
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.closeCase(caseId, "not needed any more");
cInstance = caseRuntimeDataService.getCaseInstanceById(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals("not needed any more", cInstance.getCompletionMessage());
caseId = null;
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class StageCompletionConditionTest method testAutoCompleteDynamicSubProcess.
@Test
public void testAutoCompleteDynamicSubProcess() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_AUTOCOMPLETE);
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);
CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getCaseStages()).hasSize(1);
String stageId = caseInstance.getCaseStages().iterator().next().getId();
caseService.addDynamicSubprocessToStage(caseId, stageId, USER_TASK_PROCESS, Collections.emptyMap());
userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
assertCaseInstanceActive(caseId);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary dynamicTask = tasks.get(0);
assertThat(dynamicTask.getName()).isEqualTo(HELLO_TASK);
userTaskService.completeAutoProgress(dynamicTask.getId(), USER, null);
assertCaseInstanceNotActive(caseId);
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class StageCompletionConditionTest method testProcessVariable.
@Test
public void testProcessVariable() {
Map<String, Object> data = new HashMap<>();
data.put("continue", false);
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_PROCESS_VARIABLE, data, Collections.emptyMap());
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_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", false);
caseService.addDataToCaseFile(caseId, "continue", true);
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);
processService.setProcessVariable(processInstanceId, "continue", true);
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.CaseInstance in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartCaseWithSubCaseDestroySubCase.
@Test
public void testStartCaseWithSubCaseDestroySubCase() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
roleAssignments.put("manager", new UserImpl("mary"));
Map<String, Object> data = new HashMap<>();
data.put("name", "John Doe");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), BASIC_SUB_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), BASIC_SUB_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(SUB_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
caseService.triggerAdHocFragment(caseId, "Sub Case", null);
Collection<CaseInstance> caseInstances = caseRuntimeDataService.getCaseInstances(new QueryContext());
assertNotNull(caseInstances);
assertEquals(2, caseInstances.size());
Map<String, CaseInstance> byCaseId = caseInstances.stream().collect(toMap(CaseInstance::getCaseId, c -> c));
assertTrue(byCaseId.containsKey(SUB_CASE_ID));
assertTrue(byCaseId.containsKey(HR_CASE_ID));
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(HR_CASE_ID, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("Hello1", tasks.get(0).getName());
CaseFileInstance mainCaseFile = caseService.getCaseFileInstance(caseId);
assertNotNull(mainCaseFile);
assertNull(mainCaseFile.getData("subCaseId"));
caseService.destroyCase(HR_CASE_ID);
mainCaseFile = caseService.getCaseFileInstance(caseId);
assertNotNull(mainCaseFile);
assertEquals(HR_CASE_ID, mainCaseFile.getData("subCaseId"));
assertEquals("John Doe", mainCaseFile.getData("outcome"));
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartProcessWithSubCaseDestroySubCase.
@Test
public void testStartProcessWithSubCaseDestroySubCase() {
Long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), PROCESS_TO_CASE_P_ID);
assertNotNull(processInstanceId);
try {
// check if case was created from within the process
CaseInstance cInstance = caseService.getCaseInstance(HR_CASE_ID);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Map<String, Object> processVariables = processService.getProcessInstanceVariables(processInstanceId);
assertNull(processVariables.get("CaseId"));
assertNull(processVariables.get("outcome"));
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(HR_CASE_ID, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("Hello1", tasks.get(0).getName());
caseService.destroyCase(HR_CASE_ID);
processVariables = processService.getProcessInstanceVariables(processInstanceId);
assertEquals(HR_CASE_ID, processVariables.get("CaseId"));
assertEquals("process2case", processVariables.get("outcome"));
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("Verify case results", tasks.get(0).getName());
Map<String, Object> taskInputs = userTaskService.getTaskInputContentByTaskId(tasks.get(0).getId());
assertEquals(HR_CASE_ID, taskInputs.get("CaseId"));
assertEquals("process2case", taskInputs.get("outcome"));
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
ProcessInstanceDesc piLog = runtimeDataService.getProcessInstanceById(processInstanceId);
assertNotNull(piLog);
assertEquals(ProcessInstance.STATE_COMPLETED, piLog.getState().intValue());
processInstanceId = null;
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (processInstanceId != null) {
processService.abortProcessInstance(processInstanceId);
}
}
}
Aggregations