use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.
the class CaseSLAComplianceIntegrationTest method testStartCaseWithSLAEscalation.
@Test
public void testStartCaseWithSLAEscalation() throws Exception {
Map<String, Object> data = new HashMap<>();
data.put("s", "with SLA");
CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_SLA_OWNER_ROLE, USER_JOHN).addUserAssignments(CASE_SLA_ADMIN_ROLE, USER_MARY).data(data).build();
changeUser(USER_JOHN);
String caseId = caseClient.startCase(CONTAINER_ID, SLA_CASE_DEF_ID, caseFile);
CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
List<org.kie.server.api.model.instance.ProcessInstance> instances = caseClient.getActiveProcessInstances(CONTAINER_ID, caseId, 0, 10);
assertThat(caseInstance.getCaseId()).isEqualTo(caseId);
assertThat(caseInstance.getCaseDefinitionId()).isEqualTo(SLA_CASE_DEF_ID);
assertThat(caseInstance.getContainerId()).isEqualTo(CONTAINER_ID);
assertThat(caseInstance.getCaseDescription()).isEqualTo("Case with SLA");
assertThat(caseInstance.getSlaCompliance()).isEqualTo(ProcessInstance.SLA_PENDING);
assertThat(caseInstance.getSlaDueDate()).isCloseTo(new Date(), 30_000L);
List<TaskSummary> johnTasks = taskClient.findTasksAssignedAsPotentialOwner(USER_JOHN, 0, 10);
TaskSummary johnTask = johnTasks.get(0);
assertThat(johnTasks).hasSize(1);
assertThat(johnTask.getName()).isEqualTo("Hello1");
assertThat(johnTask.getProcessType()).isEqualTo(WorkflowProcess.CASE_TYPE);
AbstractStringAssert<?> corKeyAssert = assertThat(johnTask.getCorrelationKey());
if (!instances.isEmpty()) {
corKeyAssert.isEqualTo(instances.get(0).getCorrelationKey());
} else {
corKeyAssert.isNull();
}
changeUser(USER_MARY);
List<TaskSummary> maryTasks = taskClient.findTasksAssignedAsPotentialOwner(USER_MARY, 0, 10);
// No SLA escalation tasks for Mary yet
assertThat(maryTasks).isEmpty();
Long caseProcessInstanceId = johnTask.getProcessInstanceId();
// Wait for SLA to expire
KieServerSynchronization.waitForProcessInstanceSLAViolated(queryClient, caseProcessInstanceId, 8_000L);
caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
assertThat(caseInstance.getCaseId()).isEqualTo(caseId);
assertThat(caseInstance.getSlaCompliance()).isEqualTo(ProcessInstance.SLA_VIOLATED);
assertThat(caseInstance.getSlaDueDate()).isCloseTo(new Date(), 30_000L);
maryTasks = taskClient.findTasksAssignedAsPotentialOwner(USER_MARY, 0, 10);
// SLA Escalation task for Mary should be created
assertThat(maryTasks).hasSize(1);
TaskSummary escalationTask = maryTasks.get(0);
assertThat(escalationTask.getName()).isEqualTo("SLA violation for case " + caseId);
assertThat(escalationTask.getDescription()).isEqualTo("Service Level Agreement has been violated for case " + caseId);
}
use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.
the class CaseServiceIntegrationTest method testCreateCaseWithEmptyCaseFileThenDestroyIt.
@Test
public void testCreateCaseWithEmptyCaseFileThenDestroyIt() {
String caseId = startCarInsuranceClaimCase(USER_YODA, USER_JOHN, USER_YODA);
Assertions.assertThat(caseId).isNotNull();
Assertions.assertThat(caseId).startsWith(CLAIM_CASE_ID_PREFIX);
CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
assertCarInsuranceCaseInstance(caseInstance, caseId, USER_YODA);
List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertEquals(1, tasks.size());
caseClient.destroyCaseInstance(CONTAINER_ID, caseId);
CaseInstance closed = caseClient.getCaseInstance(CONTAINER_ID, caseId);
Assertions.assertThat(closed.getCaseStatus()).isEqualTo(3);
}
use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.
the class CaseServiceIntegrationTest method testCreateCancelAndReopenCaseWithEmptyCaseFile.
@Test
public void testCreateCancelAndReopenCaseWithEmptyCaseFile() {
String caseId = startCarInsuranceClaimCase(USER_YODA, USER_JOHN, USER_YODA);
Assertions.assertThat(caseId).isNotNull();
Assertions.assertThat(caseId).startsWith(CLAIM_CASE_ID_PREFIX);
CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
assertCarInsuranceCaseInstance(caseInstance, caseId, USER_YODA);
caseClient.cancelCaseInstance(CONTAINER_ID, caseId);
CaseInstance closed = caseClient.getCaseInstance(CONTAINER_ID, caseId);
Assertions.assertThat(closed.getCaseStatus()).isEqualTo(3);
Map<String, Object> data = new HashMap<>();
data.put("additionalComment", "reopening the case");
caseClient.reopenCase(caseId, CONTAINER_ID, CLAIM_CASE_DEF_ID, data);
caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
Assertions.assertThat(caseInstance).isNotNull();
Assertions.assertThat(caseInstance.getCaseId()).isEqualTo(caseId);
Object additionalComment = caseClient.getCaseInstanceData(CONTAINER_ID, caseId, "additionalComment");
Assertions.assertThat(additionalComment).isNotNull();
Assertions.assertThat(additionalComment).isEqualTo("reopening the case");
}
use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.
the class CaseServiceIntegrationTest method testCreateCaseWithEmptyCaseFileButWithRoleAssignments.
@Test
public void testCreateCaseWithEmptyCaseFileButWithRoleAssignments() {
CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_INSURED_ROLE, USER_YODA).addUserAssignments(CASE_INS_REP_ROLE, USER_JOHN).build();
String caseId = caseClient.startCase(CONTAINER_ID, CLAIM_CASE_DEF_ID, caseFile);
Assertions.assertThat(caseId).isNotNull();
Assertions.assertThat(caseId).startsWith(CLAIM_CASE_ID_PREFIX);
CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
assertCarInsuranceCaseInstance(caseInstance, caseId, USER_YODA);
List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
Assertions.assertThat(task).isNotNull();
Assertions.assertThat(task.getName()).isEqualTo(ACCIDENT_TASK_NAME);
Assertions.assertThat(task.getActualOwner()).isNull();
Assertions.assertThat(task.getStatus()).isEqualTo("Ready");
}
use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.
the class CaseServiceIntegrationTest method testCreateCaseWithEmptyCaseFile.
@Test
public void testCreateCaseWithEmptyCaseFile() {
String caseId = startCarInsuranceClaimCase(USER_YODA, USER_JOHN, USER_YODA);
Assertions.assertThat(caseId).isNotNull();
Assertions.assertThat(caseId).startsWith(CLAIM_CASE_ID_PREFIX);
CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
assertCarInsuranceCaseInstance(caseInstance, caseId, USER_YODA);
List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
Assertions.assertThat(tasks).hasSize(1);
}
Aggregations