use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseSLAComplianceTest method testStartCaseWithSLAEscalation.
@Test
public void testStartCaseWithSLAEscalation() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
roleAssignments.put("admin", new UserImpl("mary"));
Map<String, Object> data = new HashMap<>();
data.put("s", "Case with SLA");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_SLA_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_SLA_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(HR_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals(ProcessInstance.SLA_PENDING, cInstance.getSlaCompliance().intValue());
List<TaskSummary> escalationTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
assertThat(escalationTasks).hasSize(0);
CountDownListenerFactory.getExisting("slaCompliance").waitTillCompleted();
cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals(ProcessInstance.SLA_VIOLATED, cInstance.getSlaCompliance().intValue());
escalationTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
assertThat(escalationTasks).hasSize(1);
TaskSummary task = escalationTasks.get(0);
assertThat(task.getName()).isEqualTo("SLA violation for case " + caseId);
assertThat(task.getDescription()).isEqualTo("Service Level Agreement has been violated for case " + caseId);
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.CaseFileInstance in project jbpm by kiegroup.
the class CaseSLAComplianceTest method testStartCaseWithSLASubprocess.
@Test
public void testStartCaseWithSLASubprocess() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
roleAssignments.put("admin", new UserImpl("mary"));
Map<String, Object> data = new HashMap<>();
data.put("s", "Case with SLA");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_SLA_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_SLA_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(HR_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals(ProcessInstance.SLA_PENDING, cInstance.getSlaCompliance().intValue());
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(1, caseProcessInstances.size());
CountDownListenerFactory.getExisting("slaCompliance").waitTillCompleted();
cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals(ProcessInstance.SLA_VIOLATED, cInstance.getSlaCompliance().intValue());
caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(2, caseProcessInstances.size());
for (ProcessInstanceDesc pi : caseProcessInstances) {
assertThat(pi.getCorrelationKey()).startsWith(HR_CASE_ID);
}
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.CaseFileInstance in project jbpm by kiegroup.
the class CaseSLAComplianceTest method testStartCaseWithSLAForNewCustomerByRules.
@Test
public void testStartCaseWithSLAForNewCustomerByRules() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
roleAssignments.put("admin", new UserImpl("mary"));
Map<String, Object> data = new HashMap<>();
data.put("s", "Case with SLA");
data.put("CustomerType", "New");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_SLA_EXPR_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_SLA_EXPR_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(HR_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals(ProcessInstance.SLA_NA, cInstance.getSlaCompliance().intValue());
Object calcualtedSlaDueDate = cInstance.getCaseFile().getData("slaDueDate");
assertNotNull(calcualtedSlaDueDate);
assertThat(calcualtedSlaDueDate).isEqualTo("");
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.CaseFileInstance 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);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testCaseWithComments.
@Test
public void testCaseWithComments() {
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_STAGE_AUTO_START_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_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());
Collection<CommentInstance> caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(0, caseComments.size());
String commentId = caseService.addCaseComment(FIRST_CASE_ID, "poul", "just a tiny comment");
assertNotNull(commentId);
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(1, caseComments.size());
CommentInstance comment = caseComments.iterator().next();
assertComment(comment, "poul", "just a tiny comment");
assertEquals(commentId, comment.getId());
caseService.updateCaseComment(FIRST_CASE_ID, comment.getId(), comment.getAuthor(), "Updated " + comment.getComment());
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(1, caseComments.size());
comment = caseComments.iterator().next();
assertComment(comment, "poul", "Updated just a tiny comment");
caseService.addCaseComment(FIRST_CASE_ID, "mary", "another comment");
caseService.addCaseComment(FIRST_CASE_ID, "john", "third comment");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(3, caseComments.size());
Iterator<CommentInstance> it = caseComments.iterator();
assertComment(it.next(), "poul", "Updated just a tiny comment");
assertComment(it.next(), "mary", "another comment");
assertComment(it.next(), "john", "third comment");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, CommentSortBy.Author, new QueryContext());
assertNotNull(caseComments);
assertEquals(3, caseComments.size());
it = caseComments.iterator();
assertComment(it.next(), "john", "third comment");
assertComment(it.next(), "mary", "another comment");
assertComment(it.next(), "poul", "Updated just a tiny comment");
caseService.removeCaseComment(FIRST_CASE_ID, comment.getId());
caseComments = caseService.getCaseComments(FIRST_CASE_ID, CommentSortBy.Author, new QueryContext());
assertEquals(2, caseComments.size());
it = caseComments.iterator();
assertComment(it.next(), "john", "third comment");
assertComment(it.next(), "mary", "another comment");
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations