use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalLevelServiceTest method testGetUserReadApprovalLevels_1B.
@Test
public void testGetUserReadApprovalLevels_1B() {
//
// Test 1: Like when a user may capture data within their own district
// but view data in other districts within their province.
//
// Variation B: User *has* approval at lower levels authority.
//
organisationUnitService.addOrganisationUnit(organisationUnitE);
organisationUnitService.addOrganisationUnit(organisationUnitF);
organisationUnitService.addOrganisationUnit(organisationUnitG);
organisationUnitService.addOrganisationUnit(organisationUnitH);
dataApprovalLevelService.addDataApprovalLevel(level1, 1);
dataApprovalLevelService.addDataApprovalLevel(level2, 2);
dataApprovalLevelService.addDataApprovalLevel(level3, 3);
dataApprovalLevelService.addDataApprovalLevel(level4, 4);
dataApprovalLevelService.addDataApprovalLevel(level5, 5);
Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
assignedOrgUnits.add(organisationUnitC);
Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
dataViewOrgUnits.add(organisationUnitB);
CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits, DataApproval.AUTH_APPROVE_LOWER_LEVELS);
setDependency(dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class);
Map<OrganisationUnit, Integer> readApprovalLevels = dataApprovalLevelService.getUserReadApprovalLevels();
assertEquals(2, readApprovalLevels.size());
assertEquals(APPROVAL_LEVEL_UNAPPROVED, (int) readApprovalLevels.get(organisationUnitC));
assertEquals(3, (int) readApprovalLevels.get(organisationUnitB));
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalLevelServiceTest method testGetUserDataApprovalLevelsAcceptMuchLower.
@Test
public void testGetUserDataApprovalLevelsAcceptMuchLower() {
dataApprovalLevelService.addDataApprovalLevel(level4);
Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
assignedOrgUnits.add(organisationUnitB);
Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
dataViewOrgUnits.add(organisationUnitB);
CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits, DataApproval.AUTH_ACCEPT_LOWER_LEVELS);
setDependency(dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class);
List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
assertEquals("04", levelNames(levels));
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceCategoryOptionGroupTest method getMockCurrentUserService.
// -------------------------------------------------------------------------
// Set up/tear down helper methods
// -------------------------------------------------------------------------
private CurrentUserService getMockCurrentUserService(String userName, boolean superUserFlag, OrganisationUnit orgUnit, String... auths) {
CurrentUserService mockCurrentUserService = new MockCurrentUserService(superUserFlag, Sets.newHashSet(orgUnit), Sets.newHashSet(orgUnit), auths);
User user = mockCurrentUserService.getCurrentUser();
user.setFirstName("Test");
user.setSurname(userName);
UserCredentials credentials = user.getUserCredentials();
credentials.setUsername(userName);
for (UserAuthorityGroup role : credentials.getUserAuthorityGroups()) {
// Give the role an arbitrary name
role.setName(CodeGenerator.generateUid());
userService.addUserAuthorityGroup(role);
}
userService.addUserCredentials(credentials);
userService.addUser(user);
return mockCurrentUserService;
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceTest method testMayApproveNoAuthority.
@Test
@Category(IntegrationTest.class)
public void testMayApproveNoAuthority() {
Set<OrganisationUnit> units = newHashSet(organisationUnitB);
CurrentUserService currentUserService = new MockCurrentUserService(units, null, AUTH_APPR_LEVEL);
userService.addUser(currentUserService.getCurrentUser());
setCurrentUserServiceDependencies(currentUserService);
Date date = new Date();
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
dataApprovalStore.addDataApproval(new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA));
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
dataApprovalStore.addDataApproval(new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA));
dataApprovalStore.addDataApproval(new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA));
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
dataApprovalStore.addDataApproval(new DataApproval(level2, workflow1234, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA));
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayApprove());
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalLevelServiceTest method testGetUserReadApprovalLevels_1A.
@Test
public void testGetUserReadApprovalLevels_1A() {
//
// Test 1: Like when a user may capture data within their own district
// but view data in other districts within their province.
//
// Variation A: User does *not* have approval at lower levels authority.
//
organisationUnitService.addOrganisationUnit(organisationUnitE);
organisationUnitService.addOrganisationUnit(organisationUnitF);
organisationUnitService.addOrganisationUnit(organisationUnitG);
organisationUnitService.addOrganisationUnit(organisationUnitH);
dataApprovalLevelService.addDataApprovalLevel(level1, 1);
dataApprovalLevelService.addDataApprovalLevel(level2, 2);
dataApprovalLevelService.addDataApprovalLevel(level3, 3);
dataApprovalLevelService.addDataApprovalLevel(level4, 4);
dataApprovalLevelService.addDataApprovalLevel(level5, 5);
Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
assignedOrgUnits.add(organisationUnitC);
Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
dataViewOrgUnits.add(organisationUnitB);
CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits);
setDependency(dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class);
Map<OrganisationUnit, Integer> readApprovalLevels = dataApprovalLevelService.getUserReadApprovalLevels();
assertEquals(2, readApprovalLevels.size());
assertEquals(4, (int) readApprovalLevels.get(organisationUnitC));
assertEquals(3, (int) readApprovalLevels.get(organisationUnitB));
}
Aggregations