Search in sources :

Example 6 with CaseInstance

use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.

the class CaseRuntimeDataServiceIntegrationTest method testGetCaseInstanceCarInsuranceClaimCaseWithData.

@Test
public void testGetCaseInstanceCarInsuranceClaimCaseWithData() {
    String caseId = startCarInsuranceClaimCase(USER_YODA, USER_JOHN, USER_YODA);
    CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId, true, true, true, true);
    assertCarInsuranceCaseInstance(caseInstance, caseId, USER_YODA);
    KieServerAssert.assertNullOrEmpty("Milestones should be empty.", caseInstance.getMilestones());
    // Assert case file
    assertNotNull(caseInstance.getCaseFile());
    assertEquals("first case started", caseInstance.getCaseFile().getData().get("s"));
    // Assert role assignments
    assertNotNull(caseInstance.getRoleAssignments());
    assertEquals(4, caseInstance.getRoleAssignments().size());
    CaseRoleAssignment ownerRole = caseInstance.getRoleAssignments().get(0);
    assertEquals("owner", ownerRole.getName());
    assertEquals(1, ownerRole.getUsers().size());
    assertEquals(USER_YODA, ownerRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", ownerRole.getGroups());
    CaseRoleAssignment insuredRole = caseInstance.getRoleAssignments().get(1);
    assertEquals("insured", insuredRole.getName());
    assertEquals(1, insuredRole.getUsers().size());
    assertEquals(USER_YODA, insuredRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", insuredRole.getGroups());
    CaseRoleAssignment assessorRole = caseInstance.getRoleAssignments().get(2);
    assertEquals("assessor", assessorRole.getName());
    assertEquals(USER_YODA, assessorRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", assessorRole.getGroups());
    CaseRoleAssignment insuranceRepresentativeRole = caseInstance.getRoleAssignments().get(3);
    assertEquals("insuranceRepresentative", insuranceRepresentativeRole.getName());
    assertEquals(1, insuranceRepresentativeRole.getUsers().size());
    assertEquals(USER_JOHN, insuranceRepresentativeRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", insuranceRepresentativeRole.getGroups());
    // Assert stages
    assertNotNull(caseInstance.getStages());
    assertEquals(1, caseInstance.getStages().size());
    CaseStage stage = caseInstance.getStages().get(0);
    assertNotNull(stage.getIdentifier());
    assertEquals("Build claim report", stage.getName());
    assertEquals("Active", stage.getStatus());
    List<NodeInstance> activeNodes = stage.getActiveNodes();
    assertEquals(1, activeNodes.size());
    assertEquals("Provide accident information", activeNodes.get(0).getName());
    assertEquals("HumanTaskNode", activeNodes.get(0).getNodeType());
    assertEquals(2, stage.getAdHocFragments().size());
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseRoleAssignment(org.kie.server.api.model.cases.CaseRoleAssignment) CaseStage(org.kie.server.api.model.cases.CaseStage) NodeInstance(org.kie.server.api.model.instance.NodeInstance) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 7 with CaseInstance

use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.

the class CaseRuntimeDataServiceIntegrationTest method testGetCaseInstancesWithData.

@Test
public void testGetCaseInstancesWithData() {
    String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
    List<String> statuses = Collections.singletonList(CaseStatus.OPEN.getName());
    List<CaseInstance> caseInstances = caseClient.getCaseInstances(statuses, 0, 1, "", false, false);
    assertEquals(1, caseInstances.size());
    CaseInstance instance = caseInstances.get(0);
    assertEquals(caseId, instance.getCaseId());
    assertNull(instance.getCaseFile());
    caseInstances = caseClient.getCaseInstances(statuses, 0, 1, "", false, true);
    instance = caseInstances.get(0);
    assertEquals(caseId, instance.getCaseId());
    assertNotNull(instance.getCaseFile());
    assertEquals("first case started", instance.getCaseFile().getData().get("s"));
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 8 with CaseInstance

use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.

the class CaseRuntimeDataServiceIntegrationTest method testCreateCaseWithCaseFileAndTriggerMilestones.

@Test
public void testCreateCaseWithCaseFileAndTriggerMilestones() {
    String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
    assertNotNull(caseId);
    assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
    CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
    assertHrCaseInstance(caseInstance, caseId, USER_YODA);
    List<CaseInstance> caseInstances = caseClient.getCaseInstancesOwnedBy(USER_YODA, null, 0, 10);
    assertEquals(1, caseInstances.size());
    List<CaseMilestone> milestones = caseClient.getMilestones(CONTAINER_ID, caseId, true, 0, 10);
    assertNotNull(milestones);
    assertEquals(0, milestones.size());
    caseClient.triggerAdHocFragment(CONTAINER_ID, caseId, "Milestone1", null);
    milestones = caseClient.getMilestones(CONTAINER_ID, caseId, true, 0, 10);
    assertNotNull(milestones);
    assertEquals(1, milestones.size());
    CaseMilestone milestone = milestones.get(0);
    assertNotNull(milestone);
    assertEquals("Milestone1", milestone.getName());
    assertEquals(true, milestone.isAchieved());
    assertEquals("2", milestone.getIdentifier());
    assertNotNull(milestone.getAchievedAt());
    caseClient.triggerAdHocFragment(CONTAINER_ID, caseId, "Milestone2", null);
    milestones = caseClient.getMilestones(CONTAINER_ID, caseId, true, 0, 10);
    assertNotNull(milestones);
    assertEquals(1, milestones.size());
    milestones = caseClient.getMilestones(CONTAINER_ID, caseId, false, 0, 10);
    assertNotNull(milestones);
    assertEquals(2, milestones.size());
    Map<String, CaseMilestone> mappedMilestones = milestones.stream().collect(Collectors.toMap(CaseMilestone::getName, d -> d));
    assertTrue(mappedMilestones.containsKey("Milestone1"));
    assertTrue(mappedMilestones.containsKey("Milestone2"));
    assertTrue(mappedMilestones.get("Milestone1").isAchieved());
    assertFalse(mappedMilestones.get("Milestone2").isAchieved());
    caseInstances = caseClient.getCaseInstances(0, 10);
    assertEquals(1, caseInstances.size());
    assertHrCaseInstance(caseInstances.get(0), caseId, USER_YODA);
    // now auto complete milestone by inserting data
    caseClient.putCaseInstanceData(CONTAINER_ID, caseId, "dataComplete", true);
    milestones = caseClient.getMilestones(CONTAINER_ID, caseId, true, 0, 10);
    assertNotNull(milestones);
    assertEquals(2, milestones.size());
}
Also used : Arrays(java.util.Arrays) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) BiFunction(java.util.function.BiFunction) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) Reserved(org.kie.api.task.model.Status.Reserved) CaseInstance(org.kie.server.api.model.cases.CaseInstance) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) After(org.junit.After) Assertions(org.assertj.core.api.Assertions) CaseServicesClient(org.kie.server.client.CaseServicesClient) Assert.fail(org.junit.Assert.fail) Ready(org.kie.api.task.model.Status.Ready) TaskSummary(org.kie.server.api.model.instance.TaskSummary) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Collection(java.util.Collection) CaseComment(org.kie.server.api.model.cases.CaseComment) Collectors(java.util.stream.Collectors) CaseRoleAssignment(org.kie.server.api.model.cases.CaseRoleAssignment) List(java.util.List) CaseFileDataItem(org.kie.server.api.model.cases.CaseFileDataItem) CaseAdHocFragment(org.kie.server.api.model.cases.CaseAdHocFragment) CaseDefinition(org.kie.server.api.model.cases.CaseDefinition) Assert.assertFalse(org.junit.Assert.assertFalse) Status(org.kie.api.task.model.Status) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) KieServicesException(org.kie.server.api.exception.KieServicesException) BeforeClass(org.junit.BeforeClass) STATE_ACTIVE(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE) CaseStage(org.kie.server.api.model.cases.CaseStage) HashMap(java.util.HashMap) Function(java.util.function.Function) CaseFile(org.kie.server.api.model.cases.CaseFile) ArrayList(java.util.ArrayList) KieServerAssert(org.kie.server.integrationtests.shared.KieServerAssert) KieServices(org.kie.api.KieServices) Assume(org.junit.Assume) STATE_ABORTED(org.kie.api.runtime.process.ProcessInstance.STATE_ABORTED) CaseMilestone(org.kie.server.api.model.cases.CaseMilestone) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) KieServerDeployer(org.kie.server.integrationtests.shared.KieServerDeployer) TestConfig(org.kie.server.integrationtests.config.TestConfig) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) STATE_COMPLETED(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED) Collectors.toList(java.util.stream.Collectors.toList) Assert.assertNull(org.junit.Assert.assertNull) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) ReleaseId(org.kie.server.api.model.ReleaseId) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseMilestone(org.kie.server.api.model.cases.CaseMilestone) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 9 with CaseInstance

use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.

the class CaseRuntimeDataServiceIntegrationTest method testCreateDifferentTypesCases.

@Test
public void testCreateDifferentTypesCases() {
    String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
    String caseClaimId = startCarInsuranceClaimCase(USER_JOHN, USER_YODA, USER_YODA);
    assertNotNull(caseId);
    assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
    assertNotNull(caseClaimId);
    assertTrue(caseClaimId.startsWith(CLAIM_CASE_ID_PREFIX));
    List<CaseInstance> caseInstances = caseClient.getCaseInstancesByContainer(CONTAINER_ID, Arrays.asList(CaseStatus.OPEN.getName()), 0, 10);
    assertEquals(2, caseInstances.size());
    List<String> caseDefs = caseInstances.stream().map(c -> c.getCaseDefinitionId()).collect(toList());
    assertTrue(caseDefs.contains(CASE_HR_DEF_ID));
    assertTrue(caseDefs.contains(CLAIM_CASE_DEF_ID));
    caseInstances = caseClient.getCaseInstancesByDefinition(CONTAINER_ID, CLAIM_CASE_DEF_ID, Arrays.asList(CaseStatus.OPEN.getName()), 0, 10);
    assertEquals(1, caseInstances.size());
    List<CaseStage> stages = caseClient.getStages(CONTAINER_ID, caseClaimId, true, 0, 10);
    assertEquals(1, stages.size());
    CaseStage caseStage = stages.get(0);
    assertEquals("Build claim report", caseStage.getName());
    assertEquals(2, caseStage.getAdHocFragments().size());
    List<CaseRoleAssignment> roles = caseClient.getRoleAssignments(CONTAINER_ID, caseClaimId);
    assertEquals(4, roles.size());
    Map<String, CaseRoleAssignment> mappedRoles = roles.stream().collect(toMap(CaseRoleAssignment::getName, r -> r));
    assertTrue(mappedRoles.containsKey(CASE_OWNER_ROLE));
    assertTrue(mappedRoles.containsKey(CASE_INSURED_ROLE));
    assertTrue(mappedRoles.containsKey(CASE_INS_REP_ROLE));
    assertTrue(mappedRoles.containsKey(CASE_ASSESSOR_ROLE));
    CaseRoleAssignment ownerRole = mappedRoles.get(CASE_OWNER_ROLE);
    assertTrue(ownerRole.getUsers().contains(USER_YODA));
    KieServerAssert.assertNullOrEmpty("Groups should be empty", ownerRole.getGroups());
    CaseRoleAssignment insuredRole = mappedRoles.get(CASE_INSURED_ROLE);
    assertTrue(insuredRole.getUsers().contains(USER_JOHN));
    KieServerAssert.assertNullOrEmpty("Groups should be empty", insuredRole.getGroups());
    CaseRoleAssignment insRepRole = mappedRoles.get(CASE_INS_REP_ROLE);
    assertTrue(insRepRole.getUsers().contains(USER_YODA));
    KieServerAssert.assertNullOrEmpty("Groups should be empty", insRepRole.getGroups());
    CaseRoleAssignment assessorRole = mappedRoles.get(CASE_ASSESSOR_ROLE);
    assertTrue(assessorRole.getUsers().contains(USER_YODA));
    KieServerAssert.assertNullOrEmpty("Groups should be empty", assessorRole.getGroups());
    caseClient.assignUserToRole(CONTAINER_ID, caseClaimId, CASE_ASSESSOR_ROLE, USER_MARY);
    caseClient.assignGroupToRole(CONTAINER_ID, caseClaimId, CASE_ASSESSOR_ROLE, "managers");
    roles = caseClient.getRoleAssignments(CONTAINER_ID, caseClaimId);
    assertEquals(4, roles.size());
    mappedRoles = roles.stream().collect(toMap(CaseRoleAssignment::getName, r -> r));
    assessorRole = mappedRoles.get(CASE_ASSESSOR_ROLE);
    assertTrue(assessorRole.getUsers().contains(USER_MARY));
    assertTrue(assessorRole.getGroups().contains("managers"));
    caseClient.removeUserFromRole(CONTAINER_ID, caseClaimId, CASE_ASSESSOR_ROLE, USER_MARY);
    caseClient.removeUserFromRole(CONTAINER_ID, caseClaimId, CASE_ASSESSOR_ROLE, USER_YODA);
    caseClient.removeGroupFromRole(CONTAINER_ID, caseClaimId, CASE_ASSESSOR_ROLE, "managers");
    roles = caseClient.getRoleAssignments(CONTAINER_ID, caseClaimId);
    assertEquals(4, roles.size());
    mappedRoles = roles.stream().collect(toMap(CaseRoleAssignment::getName, r -> r));
    assessorRole = mappedRoles.get(CASE_ASSESSOR_ROLE);
    KieServerAssert.assertNullOrEmpty("Users should be empty", assessorRole.getUsers());
    KieServerAssert.assertNullOrEmpty("Groups should be empty", assessorRole.getGroups());
}
Also used : Arrays(java.util.Arrays) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) BiFunction(java.util.function.BiFunction) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) Reserved(org.kie.api.task.model.Status.Reserved) CaseInstance(org.kie.server.api.model.cases.CaseInstance) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) After(org.junit.After) Assertions(org.assertj.core.api.Assertions) CaseServicesClient(org.kie.server.client.CaseServicesClient) Assert.fail(org.junit.Assert.fail) Ready(org.kie.api.task.model.Status.Ready) TaskSummary(org.kie.server.api.model.instance.TaskSummary) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Collection(java.util.Collection) CaseComment(org.kie.server.api.model.cases.CaseComment) Collectors(java.util.stream.Collectors) CaseRoleAssignment(org.kie.server.api.model.cases.CaseRoleAssignment) List(java.util.List) CaseFileDataItem(org.kie.server.api.model.cases.CaseFileDataItem) CaseAdHocFragment(org.kie.server.api.model.cases.CaseAdHocFragment) CaseDefinition(org.kie.server.api.model.cases.CaseDefinition) Assert.assertFalse(org.junit.Assert.assertFalse) Status(org.kie.api.task.model.Status) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) KieServicesException(org.kie.server.api.exception.KieServicesException) BeforeClass(org.junit.BeforeClass) STATE_ACTIVE(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE) CaseStage(org.kie.server.api.model.cases.CaseStage) HashMap(java.util.HashMap) Function(java.util.function.Function) CaseFile(org.kie.server.api.model.cases.CaseFile) ArrayList(java.util.ArrayList) KieServerAssert(org.kie.server.integrationtests.shared.KieServerAssert) KieServices(org.kie.api.KieServices) Assume(org.junit.Assume) STATE_ABORTED(org.kie.api.runtime.process.ProcessInstance.STATE_ABORTED) CaseMilestone(org.kie.server.api.model.cases.CaseMilestone) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) KieServerDeployer(org.kie.server.integrationtests.shared.KieServerDeployer) TestConfig(org.kie.server.integrationtests.config.TestConfig) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) STATE_COMPLETED(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED) Collectors.toList(java.util.stream.Collectors.toList) Assert.assertNull(org.junit.Assert.assertNull) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) ReleaseId(org.kie.server.api.model.ReleaseId) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseRoleAssignment(org.kie.server.api.model.cases.CaseRoleAssignment) CaseStage(org.kie.server.api.model.cases.CaseStage) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 10 with CaseInstance

use of org.kie.server.api.model.cases.CaseInstance in project droolsjbpm-integration by kiegroup.

the class CaseRuntimeDataServiceIntegrationTest method testGetCaseOwnedWithData.

@Test
public void testGetCaseOwnedWithData() {
    String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
    List<String> statuses = Collections.singletonList(CaseStatus.OPEN.getName());
    List<CaseInstance> caseInstances = caseClient.getCaseInstancesOwnedBy(USER_YODA, statuses, 0, 1, "", false, false);
    assertEquals(1, caseInstances.size());
    CaseInstance instance = caseInstances.get(0);
    assertEquals(caseId, instance.getCaseId());
    assertNull(instance.getCaseFile());
    caseInstances = caseClient.getCaseInstancesOwnedBy(USER_YODA, statuses, 0, 1, "", false, true);
    instance = caseInstances.get(0);
    assertEquals(caseId, instance.getCaseId());
    assertNotNull(instance.getCaseFile());
    assertEquals("first case started", instance.getCaseFile().getData().get("s"));
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

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