use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class EnrollmentSecurityImportValidationTest method testUserNoWriteAccessToProgram.
@Test
void testUserNoWriteAccessToProgram() throws IOException {
clearSecurityContext();
setupMetadata();
programA.setPublicAccess(AccessStringHelper.DATA_READ);
trackedEntityType.setPublicAccess(AccessStringHelper.DATA_READ);
programA.setTrackedEntityType(trackedEntityType);
manager.updateNoAcl(programA);
User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
userService.addUser(user);
injectSecurityContext(user);
TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_no-access-program.json");
params.setUser(user);
params.setImportStrategy(TrackerImportStrategy.CREATE);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertEquals(1, trackerImportReport.getValidationReport().getErrors().size());
assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1091))));
}
use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class EnrollmentSecurityImportValidationTest method testUserNoAccessToTrackedEntity.
@Test
void testUserNoAccessToTrackedEntity() throws IOException {
clearSecurityContext();
setupMetadata();
programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
TrackedEntityType bPJ0FMtcnEh = trackedEntityTypeService.getTrackedEntityType("bPJ0FMtcnEh");
programA.setTrackedEntityType(bPJ0FMtcnEh);
manager.updateNoAcl(programA);
User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
userService.addUser(user);
injectSecurityContext(user);
TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_no-access-tei.json");
params.setUser(user);
params.setImportStrategy(TrackerImportStrategy.CREATE);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertEquals(1, trackerImportReport.getValidationReport().getErrors().size());
assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1104))));
}
use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class EnrollmentSecurityImportValidationTest method testUserHasWriteAccessToProgram.
@Test
void testUserHasWriteAccessToProgram() throws IOException {
clearSecurityContext();
setupMetadata();
programA.setPublicAccess(AccessStringHelper.FULL);
trackedEntityType.setPublicAccess(AccessStringHelper.DATA_READ);
programA.setTrackedEntityType(trackedEntityType);
manager.updateNoAcl(programA);
User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
userService.addUser(user);
injectSecurityContext(user);
TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_no-access-program.json");
params.setUser(user);
params.setImportStrategy(TrackerImportStrategy.CREATE);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
}
use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class EnrollmentSecurityImportValidationTest method testNoWriteAccessToOrg.
@Test
void testNoWriteAccessToOrg() throws IOException {
TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data.json");
User user = userService.getUser(USER_2);
injectSecurityContext(user);
params.setUser(user);
params.setImportStrategy(TrackerImportStrategy.CREATE);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertEquals(4, trackerImportReport.getValidationReport().getErrors().size());
assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1000))));
}
use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class EventSecurityImportValidationTest method initTest.
@Override
protected void initTest() throws IOException {
setUpMetadata("tracker/tracker_basic_metadata.json");
TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/enrollments_te_te-data.json");
User user = userService.getUser("M5zQapPyTZI");
trackerBundleParams.setUser(user);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
trackerBundleParams = renderService.fromJson(new ClassPathResource("tracker/validations/enrollments_te_enrollments-data.json").getInputStream(), TrackerImportParams.class);
trackerBundleParams.setUser(user);
trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
manager.flush();
}
Aggregations