use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseDynamicNodesTest method testAddDynamicSubprocessToStageWithNotExistingProcessId.
@Test
public void testAddDynamicSubprocessToStageWithNotExistingProcessId() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getCaseStages()).hasSize(1);
CaseStatus initialStatus = CaseStatus.fromId(caseInstance.getStatus());
String stageId = caseInstance.getCaseStages().iterator().next().getId();
assertThat(stageId).isNotNull();
assertThatThrownBy(() -> caseService.addDynamicSubprocessToStage(caseId, stageId, NOT_EXISTING_SUBPROCESS, Collections.emptyMap())).isInstanceOf(ProcessDefinitionNotFoundException.class);
// case instance status should not have changed
caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
CaseStatus afterStatus = CaseStatus.fromId(caseInstance.getStatus());
assertThat(initialStatus).isEqualTo(afterStatus);
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseDynamicNodesTest method testAddDynamicSubprocessToStageByProcessInstanceId.
@Test
public void testAddDynamicSubprocessToStageByProcessInstanceId() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertThat(caseProcessInstances).isNotNull().hasSize(1);
ProcessInstanceDesc processInstance = caseProcessInstances.iterator().next();
assertThat(processInstance).isNotNull();
assertThat(processInstance.getCorrelationKey()).isEqualTo(FIRST_CASE_ID);
CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getCaseStages()).hasSize(1);
String stageId = caseInstance.getCaseStages().iterator().next().getId();
assertThat(stageId).isNotNull();
Long subprocessId = caseService.addDynamicSubprocessToStage(processInstance.getId(), stageId, SUBPROCESS, Collections.emptyMap());
ProcessInstanceDesc subprocessInstance = runtimeDataService.getProcessInstanceById(subprocessId);
assertThat(subprocessInstance).isNotNull();
assertThat(subprocessInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary userTask = tasks.get(0);
assertThat(userTask.getName()).isEqualTo(SUBPROCESS_TASK);
userTaskService.completeAutoProgress(userTask.getId(), USER, null);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).isEmpty();
subprocessInstance = runtimeDataService.getProcessInstanceById(subprocessId);
assertThat(subprocessInstance).isNotNull();
assertThat(subprocessInstance.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseDynamicNodesTest method testAddMultipleDynamicSubprocessesToStage.
@Test
public void testAddMultipleDynamicSubprocessesToStage() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getCaseStages()).hasSize(1);
String stageId = caseInstance.getCaseStages().iterator().next().getId();
assertThat(stageId).isNotNull();
Long subprocessId1 = caseService.addDynamicSubprocessToStage(caseId, stageId, SUBPROCESS, Collections.emptyMap());
ProcessInstanceDesc subprocessInstance1 = runtimeDataService.getProcessInstanceById(subprocessId1);
assertThat(subprocessInstance1).isNotNull();
assertThat(subprocessInstance1.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Long subprocessId2 = caseService.addDynamicSubprocessToStage(caseId, stageId, SUBPROCESS, Collections.emptyMap());
ProcessInstanceDesc subprocessInstance2 = runtimeDataService.getProcessInstanceById(subprocessId2);
assertThat(subprocessInstance2).isNotNull();
assertThat(subprocessInstance2.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(2);
TaskSummary userTask1 = tasks.get(0);
assertThat(userTask1.getName()).isEqualTo(SUBPROCESS_TASK);
userTaskService.completeAutoProgress(userTask1.getId(), USER, null);
TaskSummary userTask2 = tasks.get(1);
assertThat(userTask2.getName()).isEqualTo(SUBPROCESS_TASK);
userTaskService.completeAutoProgress(userTask2.getId(), USER, null);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).isEmpty();
subprocessInstance1 = runtimeDataService.getProcessInstanceById(subprocessId1);
assertThat(subprocessInstance1).isNotNull();
assertThat(subprocessInstance1.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
subprocessInstance2 = runtimeDataService.getProcessInstanceById(subprocessId2);
assertThat(subprocessInstance2).isNotNull();
assertThat(subprocessInstance2.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartCaseWithDynamicSubCase.
private void testStartCaseWithDynamicSubCase(String idependent, Consumer<String> finishCase) {
Map<String, Object> data = new HashMap<>();
data.put("name", "John Doe");
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(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Map<String, Object> parameters = new HashMap<>();
parameters.put("CaseDefinitionId", "UserTaskCase");
parameters.put("DeploymentId", deploymentUnit.getIdentifier());
parameters.put("UserRole_owner", "john");
parameters.put("Data_s", "#{name}");
parameters.put("Independent", idependent);
TaskSpecification taskSpecification = caseService.newTaskSpec("StartCaseInstance", "Sub Case", parameters);
caseService.addDynamicTask(caseId, taskSpecification);
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(FIRST_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("CaseId"));
assertNull(mainCaseFile.getData("s"));
finishCase.accept(HR_CASE_ID);
mainCaseFile = caseService.getCaseFileInstance(caseId);
assertNotNull(mainCaseFile);
assertEquals(HR_CASE_ID, mainCaseFile.getData("CaseId"));
assertEquals("John Doe", mainCaseFile.getData("s"));
} 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 testStartCaseWithSubCaseAbortProcessInstanceOfSubCase.
@Test
public void testStartCaseWithSubCaseAbortProcessInstanceOfSubCase() {
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"));
processService.abortProcessInstance(tasks.get(0).getProcessInstanceId());
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);
}
}
}
Aggregations