use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseUsingCaseFileOwnerAsLoggedInUser.
@Test
public void testStartEmptyCaseUsingCaseFileOwnerAsLoggedInUser() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("mary"));
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data, roleAssignments);
identityProvider.setName("mary");
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("mary", cInstance.getOwner());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
String initiator = (String) processService.getProcessInstanceVariable(((CaseInstanceImpl) cInstance).getProcessInstanceId(), "initiator");
assertEquals("mary", initiator);
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
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 CaseServiceImplTest method testInclusiveGatewayWithDynamicActivity.
@Test
public void testInclusiveGatewayWithDynamicActivity() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("actorRole", new UserImpl("john"));
roleAssignments.put("groupRole", new GroupImpl("managers"));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), "InclusiveGatewayCase", data, roleAssignments);
((CaseAssignment) caseFile).assignUser("generalRole", "john");
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), "InclusiveGatewayCase", 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());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertThat(tasks).hasSize(2);
caseService.addDynamicTask(caseId, caseService.newHumanTaskSpec("First task", "another test", "actorRole", null, new HashMap<>()));
List<TaskSummary> allTasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertThat(allTasks).hasSize(3);
// now complete only tasks from case definition and leave dynamic task alone
for (TaskSummary task : tasks) {
userTaskService.completeAutoProgress(task.getId(), "john", null);
}
// dynamic task should still be there
allTasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertThat(allTasks).hasSize(1);
cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
} 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 CaseServiceImplTest method testTriggerAdHocTasksFromCurrentAndNextStage.
@Test
public void testTriggerAdHocTasksFromCurrentAndNextStage() {
identityProvider.setName("john");
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
Map<String, Object> data = new HashMap<>();
data.put("customData", "none");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), TWO_STAGES_CONDITIONS_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CONDITIONS_CASE_P_ID, caseFile);
assertNotNull(caseId);
try {
Collection<CaseStageInstance> stages = caseRuntimeDataService.getCaseInstanceStages(caseId, false, null);
assertThat(stages).isNotNull().hasSize(2);
Iterator<CaseStageInstance> iterator = stages.iterator();
CaseStageInstance stage1 = iterator.next();
assertThat(stage1.getName()).isEqualTo("Stage One");
assertThat(stage1.getStatus()).isEqualTo(StageStatus.Active);
CaseStageInstance stage2 = iterator.next();
assertThat(stage2.getName()).isEqualTo("Stage Two");
assertThat(stage2.getStatus()).isEqualTo(StageStatus.Available);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertThat(tasks).isNotNull().isEmpty();
caseService.triggerAdHocFragment(caseId, "Task 1", null);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertThat(tasks).isNotNull().hasSize(1);
assertTask(tasks.get(0), "john", "Task 1", Status.Reserved);
caseService.triggerAdHocFragment(caseId, "Task 2", null);
// the task from the next stage should not be triggered
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertThat(tasks).isNotNull().hasSize(1);
assertTask(tasks.get(0), "john", "Task 1", Status.Reserved);
Map<String, Object> params = Collections.singletonMap("myData", "nextStage");
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
stages = caseRuntimeDataService.getCaseInstanceStages(caseId, false, null);
assertThat(stages).isNotNull().hasSize(2);
iterator = stages.iterator();
stage1 = iterator.next();
assertThat(stage1.getName()).isEqualTo("Stage One");
assertThat(stage1.getStatus()).isEqualTo(StageStatus.Completed);
stage2 = iterator.next();
assertThat(stage2.getName()).isEqualTo("Stage Two");
assertThat(stage2.getStatus()).isEqualTo(StageStatus.Active);
caseService.triggerAdHocFragment(caseId, "Task 2", null);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertThat(tasks).isNotNull().hasSize(1);
assertTask(tasks.get(0), "john", "Task 2", Status.Reserved);
caseService.triggerAdHocFragment(caseId, "Task 1", null);
// the task from the previous stage should not be triggered
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertThat(tasks).isNotNull().hasSize(1);
assertTask(tasks.get(0), "john", "Task 2", Status.Reserved);
params = Collections.singletonMap("myData", "none");
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
CaseInstance caseInstance = caseService.getCaseInstance(caseId);
assertThat(caseInstance.getStatus()).isIn(CaseStatus.CLOSED.getId(), CaseStatus.CANCELLED.getId());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
caseService.cancelCase(caseId);
fail("Unexpected exception " + e.getMessage());
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartThenReopenEmptyCaseUpdateDescription.
@Test
public void testStartThenReopenEmptyCaseUpdateDescription() {
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());
assertEquals("#{name}", cInstance.getCaseDescription());
long firstCaseProcessInstanceId = ((CaseInstanceImpl) cInstance).getProcessInstanceId();
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals("my first case", cInstance.getCaseDescription());
long secondCaseProcessInstanceId = ((CaseInstanceImpl) cInstance).getProcessInstanceId();
assertTrue(secondCaseProcessInstanceId > firstCaseProcessInstanceId);
caseService.destroyCase(caseId);
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 CaseServiceImplTest method testStartThenReopenActiveCase.
@Test
public void testStartThenReopenActiveCase() {
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
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());
assertEquals("my first case", cInstance.getCaseDescription());
try {
caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
fail("Not allowed to reopen active case");
} catch (CaseActiveException e) {
// expected
}
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations