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);
}
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"));
}
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);
}
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;
}
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;
}
Aggregations