use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.
the class CaseDynamicNodesTest method testAddDynamicSubprocessToNotActiveStage.
@Test
public void testAddDynamicSubprocessToNotActiveStage() {
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.addDynamicSubprocessToStage(caseId, stageId, SUBPROCESS, Collections.emptyMap())).isInstanceOf(StageNotFoundException.class);
}
use of org.jbpm.casemgmt.api.model.CaseDefinition 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.CaseDefinition in project jbpm by kiegroup.
the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitionsByDeploymentId.
@Test
public void testGetCaseDefinitionsByDeploymentId() {
Collection<CaseDefinition> cases = caseRuntimeDataService.getCasesByDeployment(deploymentUnit.getIdentifier(), new QueryContext());
assertNotNull(cases);
assertEquals(5, cases.size());
Map<String, CaseDefinition> mappedCases = mapCases(cases);
assertTrue(mappedCases.containsKey("EmptyCase"));
assertTrue(mappedCases.containsKey("UserTaskCase"));
assertTrue(mappedCases.containsKey("UserTaskCaseBoundary"));
assertTrue(mappedCases.containsKey("UserTaskWithStageCase"));
cases = caseRuntimeDataService.getCasesByDeployment("not-existing", new QueryContext());
assertNotNull(cases);
assertEquals(0, cases.size());
}
use of org.jbpm.casemgmt.api.model.CaseDefinition 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.CaseDefinition in project jbpm by kiegroup.
the class CaseServiceImplTest method testTriggerTaskAndMilestoneInCase.
@Test
public void testTriggerTaskAndMilestoneInCase() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
Map<String, Object> data = new HashMap<>();
data.put("s", "description");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID);
assertNotNull(caseDef);
assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
assertEquals(3, caseDef.getAdHocFragments().size());
Map<String, AdHocFragment> mappedFragments = mapAdHocFragments(caseDef.getAdHocFragments());
assertTrue(mappedFragments.containsKey("Hello2"));
assertTrue(mappedFragments.containsKey("Milestone1"));
assertTrue(mappedFragments.containsKey("Milestone2"));
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(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertNotNull(task);
assertEquals("Hello1", task.getName());
assertEquals("john", task.getActualOwnerId());
assertEquals(Status.Reserved, task.getStatus());
// now let's trigger one (human task) fragment
Map<String, Object> taskData = new HashMap<>();
taskData.put("test", "value");
taskData.put("fromVar", "#{s}");
caseService.triggerAdHocFragment(HR_CASE_ID, "Hello2", taskData);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(2, tasks.size());
task = tasks.get(0);
assertNotNull(task);
assertEquals("Hello2", task.getName());
assertEquals("john", task.getActualOwnerId());
assertEquals(Status.Reserved, task.getStatus());
Map<String, Object> taskInputs = userTaskService.getTaskInputContentByTaskId(task.getId());
assertNotNull(taskInputs);
assertTrue(taskInputs.containsKey("test"));
assertTrue(taskInputs.containsKey("fromVar"));
assertEquals("value", taskInputs.get("test"));
assertEquals("description", taskInputs.get("fromVar"));
task = tasks.get(1);
assertNotNull(task);
assertEquals("Hello1", task.getName());
assertEquals("john", task.getActualOwnerId());
assertEquals(Status.Reserved, task.getStatus());
Collection<CaseMilestoneInstance> milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
assertNotNull(milestones);
assertEquals(0, milestones.size());
milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, false, new QueryContext());
assertNotNull(milestones);
assertEquals(2, milestones.size());
List<String> expectedMilestones = Arrays.asList("Milestone1", "Milestone2");
for (CaseMilestoneInstance mi : milestones) {
assertTrue("Expected mile stopne not found", expectedMilestones.contains(mi.getName()));
assertEquals("Wrong milestone status", MilestoneStatus.Available, mi.getStatus());
assertFalse("Should not be achieved", mi.isAchieved());
assertNull("Achieved date should be null", mi.getAchievedAt());
}
// trigger milestone node
caseService.triggerAdHocFragment(HR_CASE_ID, "Milestone1", null);
milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
assertNotNull(milestones);
assertEquals(1, milestones.size());
CaseMilestoneInstance msInstance = milestones.iterator().next();
assertNotNull(msInstance);
assertEquals("Milestone1", msInstance.getName());
assertEquals(true, msInstance.isAchieved());
assertNotNull(msInstance.getAchievedAt());
// trigger another milestone node that has condition so it should not be achieved
caseService.triggerAdHocFragment(HR_CASE_ID, "Milestone2", null);
milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
assertNotNull(milestones);
assertEquals(1, milestones.size());
milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, false, new QueryContext());
assertNotNull(milestones);
assertEquals(2, milestones.size());
// add dataComplete to case file to achieve milestone
caseService.addDataToCaseFile(HR_CASE_ID, "dataComplete", true);
milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
assertNotNull(milestones);
assertEquals(2, milestones.size());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations