Search in sources :

Example 16 with CaseFile

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

the class CaseServiceIntegrationTest method testCreateCaseWithCaseFileWithRestrictions.

@Test
public void testCreateCaseWithCaseFileWithRestrictions() {
    Map<String, Object> caseData = new HashMap<>();
    caseData.put("car", "ford");
    CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_INSURED_ROLE, USER_YODA).addUserAssignments(CASE_INS_REP_ROLE, USER_JOHN).addDataAccessRestrictions("car", CASE_INSURED_ROLE).data(caseData).build();
    String caseId = caseClient.startCase(CONTAINER_ID, CLAIM_CASE_DEF_ID, caseFile);
    Assertions.assertThat(caseId).isNotNull();
    Assertions.assertThat(caseId).startsWith(CLAIM_CASE_ID_PREFIX);
    caseData = caseClient.getCaseInstanceData(CONTAINER_ID, caseId);
    Assertions.assertThat(caseData).isNotNull();
    Assertions.assertThat(caseData).hasSize(1);
    Assertions.assertThat(caseData.get("car")).isEqualTo("ford");
    // remove yoda from insured role to simulate lack of access
    caseClient.removeUserFromRole(CONTAINER_ID, caseId, CASE_INSURED_ROLE, USER_YODA);
    caseData = caseClient.getCaseInstanceData(CONTAINER_ID, caseId);
    Assertions.assertThat(caseData).isNotNull();
    Assertions.assertThat(caseData).hasSize(0);
    // add back yoda to insured role
    caseClient.assignUserToRole(CONTAINER_ID, caseId, CASE_INSURED_ROLE, USER_YODA);
    List<String> restrictions = new ArrayList<>();
    restrictions.add(CaseServicesClient.ACCESS_PUBLIC_GROUP);
    caseClient.putCaseInstanceData(CONTAINER_ID, caseId, "car", "fiat", restrictions);
    Object carCaseData = caseClient.getCaseInstanceData(CONTAINER_ID, caseId, "car");
    Assertions.assertThat(carCaseData).isNotNull();
    Assertions.assertThat(carCaseData).isInstanceOf(String.class);
    Assertions.assertThat(carCaseData).isEqualTo("fiat");
    // remove yoda from insured role to simulate lack of access
    caseClient.removeUserFromRole(CONTAINER_ID, caseId, CASE_INSURED_ROLE, USER_YODA);
    // but it should have access to it as all now eligible to see it
    carCaseData = caseClient.getCaseInstanceData(CONTAINER_ID, caseId, "car");
    Assertions.assertThat(carCaseData).isNotNull();
    Assertions.assertThat(carCaseData).isInstanceOf(String.class);
    Assertions.assertThat(carCaseData).isEqualTo("fiat");
    restrictions = new ArrayList<>();
    restrictions.add(CASE_INSURED_ROLE);
    Map<String, Object> updates = new HashMap<>();
    updates.put("car", "opel");
    caseClient.putCaseInstanceData(CONTAINER_ID, caseId, updates, restrictions);
    caseData = caseClient.getCaseInstanceData(CONTAINER_ID, caseId);
    Assertions.assertThat(caseData).isNotNull();
    Assertions.assertThat(caseData).hasSize(0);
    assertClientException(() -> caseClient.removeCaseInstanceData(CONTAINER_ID, caseId, "car"), 403, "does not have access to data item named car");
    // add back yoda to insured role
    caseClient.assignUserToRole(CONTAINER_ID, caseId, CASE_INSURED_ROLE, USER_YODA);
    caseClient.removeCaseInstanceData(CONTAINER_ID, caseId, "car");
    caseData = caseClient.getCaseInstanceData(CONTAINER_ID, caseId);
    Assertions.assertThat(caseData).isNotNull();
    Assertions.assertThat(caseData).hasSize(0);
}
Also used : HashMap(java.util.HashMap) CaseFile(org.kie.server.api.model.cases.CaseFile) ArrayList(java.util.ArrayList) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 17 with CaseFile

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

the class CaseServiceIntegrationTest method testAddAndRemoveMultipleDataFromCaseFile.

@Test
public void testAddAndRemoveMultipleDataFromCaseFile() {
    Map<String, Object> caseData = new HashMap<>();
    caseData.put("car", "ford");
    caseData.put("location", "prague");
    CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_INSURED_ROLE, USER_YODA).addUserAssignments(CASE_INS_REP_ROLE, USER_JOHN).data(caseData).build();
    String caseId = caseClient.startCase(CONTAINER_ID, CLAIM_CASE_DEF_ID, caseFile);
    Assertions.assertThat(caseId).isNotNull();
    Assertions.assertThat(caseId).startsWith(CLAIM_CASE_ID_PREFIX);
    caseData = caseClient.getCaseInstanceData(CONTAINER_ID, caseId);
    Assertions.assertThat(caseData).containsOnly(entry("car", "ford"), entry("location", "prague"));
    caseData = caseClient.getCaseInstanceData(CONTAINER_ID, caseId, Arrays.asList("car", "nonexisting"));
    Assertions.assertThat(caseData).containsOnly(entry("car", "ford"));
    caseData = new HashMap<>();
    caseData.put("car", "fiat");
    caseData.put("location", "brno");
    caseData.put("conditions", "sunny");
    caseClient.putCaseInstanceData(CONTAINER_ID, caseId, caseData);
    caseData = caseClient.getCaseInstanceData(CONTAINER_ID, caseId);
    Assertions.assertThat(caseData).containsOnly(entry("car", "fiat"), entry("location", "brno"), entry("conditions", "sunny"));
    caseClient.removeCaseInstanceData(CONTAINER_ID, caseId, "location", "conditions", "nonexisting");
    caseData = caseClient.getCaseInstanceData(CONTAINER_ID, caseId);
    Assertions.assertThat(caseData).containsOnly(entry("car", "fiat"));
}
Also used : HashMap(java.util.HashMap) CaseFile(org.kie.server.api.model.cases.CaseFile) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 18 with CaseFile

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

the class CaseServiceIntegrationTest method testDestroyCaseInstance.

@Test
public void testDestroyCaseInstance() {
    Map<String, Object> caseData = new HashMap<>();
    caseData.put("car", "ford");
    CaseFile caseFile = CaseFile.builder().data(caseData).addUserAssignments(CASE_INSURED_ROLE, USER_YODA).addUserAssignments(CASE_INS_REP_ROLE, USER_JOHN).addUserAssignments(CASE_ASSESSOR_ROLE, USER_YODA).build();
    String caseId = caseClient.startCase(CONTAINER_ID, CLAIM_CASE_DEF_ID, caseFile);
    Assertions.assertThat(caseId).isNotNull();
    CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
    assertCarInsuranceCaseInstance(caseInstance, caseId, USER_YODA);
    caseClient.destroyCaseInstance(CONTAINER_ID, caseId);
    CaseInstance closed = caseClient.getCaseInstance(CONTAINER_ID, caseId);
    Assertions.assertThat(closed.getCaseStatus()).isEqualTo(3);
    // Should throw exception because destroyed case cannot be reopen.
    assertClientException(() -> caseClient.reopenCase(caseId, CONTAINER_ID, CLAIM_CASE_DEF_ID), 404, caseId);
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) HashMap(java.util.HashMap) CaseFile(org.kie.server.api.model.cases.CaseFile) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 19 with CaseFile

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

the class CaseServiceRestOnlyIntegrationTest method startUserTaskCase.

private String startUserTaskCase(String owner, String contact) {
    Map<String, Object> data = new HashMap<>();
    data.put("s", "first case started");
    CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_OWNER_ROLE, owner).addUserAssignments(CASE_CONTACT_ROLE, contact).data(data).build();
    String caseId = caseClient.startCase(CONTAINER_ID, CASE_HR_DEF_ID, caseFile);
    assertNotNull(caseId);
    return caseId;
}
Also used : HashMap(java.util.HashMap) CaseFile(org.kie.server.api.model.cases.CaseFile) JaxbString(org.kie.server.api.model.type.JaxbString)

Example 20 with CaseFile

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

the class PrometheusIntegrationTest method startUserTaskCase.

private String startUserTaskCase(String owner, String contact) {
    Map<String, Object> data = new HashMap<>();
    data.put("s", "first case started");
    CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_OWNER_ROLE, owner).addUserAssignments(CASE_CONTACT_ROLE, contact).data(data).build();
    String caseId = caseClient.startCase(CONTAINER_ID_CASE, CASE_DEF_ID, caseFile);
    assertNotNull(caseId);
    return caseId;
}
Also used : HashMap(java.util.HashMap) CaseFile(org.kie.server.api.model.cases.CaseFile)

Aggregations

CaseFile (org.kie.server.api.model.cases.CaseFile)23 HashMap (java.util.HashMap)17 Test (org.junit.Test)13 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)9 CaseInstance (org.kie.server.api.model.cases.CaseInstance)3 TaskSummary (org.kie.server.api.model.instance.TaskSummary)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 WebTarget (javax.ws.rs.client.WebTarget)1 CaseDefinitionNotFoundException (org.jbpm.casemgmt.api.CaseDefinitionNotFoundException)1 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)1 CaseRuntimeDataService (org.jbpm.casemgmt.api.CaseRuntimeDataService)1 CaseService (org.jbpm.casemgmt.api.CaseService)1 TaskSpecification (org.jbpm.casemgmt.api.dynamic.TaskSpecification)1