use of org.jbpm.casemgmt.api.model.CaseStage in project jbpm by kiegroup.
the class CaseDynamicNodesTest method testAddDynamicTaskToNotActiveStage.
@Test
public void testAddDynamicTaskToNotActiveStage() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
CaseDefinition caseDefinition = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID);
assertThat(caseDefinition).isNotNull();
assertThat(caseDefinition.getCaseStages()).hasSize(2);
Iterator<CaseStage> caseStageIterator = caseDefinition.getCaseStages().iterator();
caseStageIterator.next();
String stageId = caseStageIterator.next().getId();
assertThatThrownBy(() -> caseService.addDynamicTaskToStage(caseId, stageId, createUserTask())).isInstanceOf(StageNotFoundException.class);
}
use of org.jbpm.casemgmt.api.model.CaseStage in project jbpm by kiegroup.
the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitionById.
@Test
public void testGetCaseDefinitionById() {
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), "UserTaskWithStageCase");
// UserTaskWithStageCase asserts
assertNotNull(caseDef);
assertEquals("UserTaskWithStageCase", caseDef.getId());
assertEquals("UserTaskWithStageCase", caseDef.getName());
assertEquals("1.0", caseDef.getVersion());
assertEquals(CaseDefinition.DEFAULT_PREFIX, caseDef.getIdentifierPrefix());
assertNotNull(caseDef.getCaseMilestones());
assertEquals(0, caseDef.getCaseMilestones().size());
assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
assertNotNull(caseDef.getCaseStages());
assertEquals(1, caseDef.getCaseStages().size());
Map<String, CaseStage> mappedStages = mapStages(caseDef.getCaseStages());
assertTrue(mappedStages.containsKey("Collect input"));
CaseStage caseStage = mappedStages.get("Collect input");
assertNotNull(caseStage);
assertEquals("Collect input", caseStage.getName());
assertEquals(2, caseStage.getAdHocFragments().size());
Map<String, AdHocFragment> mappedFragments = mapAdHocFragments(caseStage.getAdHocFragments());
assertTrue(mappedFragments.containsKey("Missing data"));
assertEquals("HumanTaskNode", mappedFragments.get("Missing data").getType());
assertTrue(mappedFragments.containsKey("Verification of data"));
assertEquals("SubProcessNode", mappedFragments.get("Verification of data").getType());
assertNotNull(caseDef.getCaseRoles());
assertEquals(3, caseDef.getCaseRoles().size());
Map<String, CaseRole> mappedRoles = mapRoles(caseDef.getCaseRoles());
assertTrue(mappedRoles.containsKey("owner"));
assertTrue(mappedRoles.containsKey("contact"));
assertTrue(mappedRoles.containsKey("participant"));
assertEquals(1, mappedRoles.get("owner").getCardinality().intValue());
assertEquals(2, mappedRoles.get("contact").getCardinality().intValue());
assertEquals(-1, mappedRoles.get("participant").getCardinality().intValue());
}
use of org.jbpm.casemgmt.api.model.CaseStage in project jbpm by kiegroup.
the class CaseServiceImplTest method testAddSubprocessToCaseWithStage.
@Test
public void testAddSubprocessToCaseWithStage() {
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());
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID);
assertNotNull(caseDef);
assertEquals(1, caseDef.getCaseStages().size());
assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
CaseStage stage = caseDef.getCaseStages().iterator().next();
// add dynamic user task to empty case instance - first by case id
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicSubprocessToStage(FIRST_CASE_ID, stage.getId(), SUBPROCESS_P_ID, parameters);
// second task add by process instance id
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(2, caseProcessInstances.size());
ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
assertNotNull(casePI);
assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
caseService.addDynamicSubprocessToStage(casePI.getId(), stage.getId(), SUBPROCESS_P_ID, parameters);
// let's verify that there are three process instances related to this case
caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(3, caseProcessInstances.size());
} 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.CaseStage in project jbpm by kiegroup.
the class CaseServiceImplTest method testAddUserTaskToCaseWithStage.
@Test
public void testAddUserTaskToCaseWithStage() {
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());
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID);
assertNotNull(caseDef);
assertEquals(1, caseDef.getCaseStages().size());
assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
CaseStage stage = caseDef.getCaseStages().iterator().next();
// add dynamic user task to empty case instance - first by case id
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicTaskToStage(FIRST_CASE_ID, stage.getId(), caseService.newHumanTaskSpec("First task", "test", "john", null, parameters));
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertTask(task, "john", "First task", Status.Reserved);
assertEquals("test", task.getDescription());
// second task add by process instance id
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(1, caseProcessInstances.size());
ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
assertNotNull(casePI);
assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
caseService.addDynamicTaskToStage(casePI.getId(), stage.getId(), caseService.newHumanTaskSpec("Second task", "another test", "mary", null, parameters));
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertTask(task, "mary", "Second task", Status.Reserved);
assertEquals("another test", task.getDescription());
} 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.CaseStage in project jbpm by kiegroup.
the class StageCompletionConditionTest method testAutoCompleteNoAutoStartTaskAdHocInStage.
@Test
public void testAutoCompleteNoAutoStartTaskAdHocInStage() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_NO_AUTOSTART);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
assertCaseInstanceActive(caseId);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).isEmpty();
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_NO_AUTOSTART);
Collection<CaseStage> stages = caseDef.getCaseStages();
assertThat(stages).hasSize(1);
String stageId = stages.iterator().next().getId();
caseService.triggerAdHocFragment(caseId, stageId, INSIDE_TASK, null);
assertCaseInstanceActive(caseId);
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);
assertCaseInstanceNotActive(caseId);
}
Aggregations