Search in sources :

Example 11 with CaseInstance

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);
}
Also used : HashMap(java.util.HashMap) Date(java.util.Date) CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseFile(org.kie.server.api.model.cases.CaseFile) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 12 with CaseInstance

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);
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) TaskSummary(org.kie.server.api.model.instance.TaskSummary) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 13 with CaseInstance

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");
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) HashMap(java.util.HashMap) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 14 with CaseInstance

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");
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseFile(org.kie.server.api.model.cases.CaseFile) TaskSummary(org.kie.server.api.model.instance.TaskSummary) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 15 with CaseInstance

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);
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) TaskSummary(org.kie.server.api.model.instance.TaskSummary) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Aggregations

CaseInstance (org.kie.server.api.model.cases.CaseInstance)30 Test (org.junit.Test)17 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)17 CaseStatus (org.jbpm.casemgmt.api.model.CaseStatus)9 CaseInstanceList (org.kie.server.api.model.cases.CaseInstanceList)9 HashMap (java.util.HashMap)8 TaskSummary (org.kie.server.api.model.instance.TaskSummary)7 CaseFile (org.kie.server.api.model.cases.CaseFile)5 ArrayList (java.util.ArrayList)4 CaseRoleAssignment (org.kie.server.api.model.cases.CaseRoleAssignment)4 CaseStage (org.kie.server.api.model.cases.CaseStage)3 NodeInstance (org.kie.server.api.model.instance.NodeInstance)3 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 BiFunction (java.util.function.BiFunction)2 Function (java.util.function.Function)2