use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class InterpretationServiceTest method beforeTest.
@Before
public void beforeTest() {
userA = createUser('A');
userB = createUser('B');
userService.addUser(userA);
userService.addUser(userB);
setDependency(interpretationService, "currentUserService", new MockCurrentUserService(userA), CurrentUserService.class);
chartA = createChart('A');
chartService.addChart(chartA);
interpretationA = new Interpretation(chartA, null, "Interpration of chart A");
interpretationB = new Interpretation(chartA, null, "Interpration of chart B");
interpretationC = new Interpretation(chartA, null, "Interpration of chart C");
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalAuditStoreTest method TestGetDataApprovalAudits.
@Test
void TestGetDataApprovalAudits() throws Exception {
dataApprovalAuditStore.save(auditA);
dataApprovalAuditStore.save(auditB);
DataApprovalAuditQueryParams params;
List<DataApprovalAudit> audits;
params = new DataApprovalAuditQueryParams();
params.setWorkflows(Sets.newHashSet(workflowA));
audits = dataApprovalAuditStore.getDataApprovalAudits(params);
assertEquals(1, audits.size());
assertEquals(auditA, audits.get(0));
params = new DataApprovalAuditQueryParams();
params.setLevels(Sets.newHashSet(level1));
audits = dataApprovalAuditStore.getDataApprovalAudits(params);
assertEquals(1, audits.size());
assertEquals(auditA, audits.get(0));
params = new DataApprovalAuditQueryParams();
params.setOrganisationUnits(Sets.newHashSet(sourceA));
audits = dataApprovalAuditStore.getDataApprovalAudits(params);
assertEquals(1, audits.size());
assertEquals(auditA, audits.get(0));
params = new DataApprovalAuditQueryParams();
params.setAttributeOptionCombos(Sets.newHashSet(optionComboA));
audits = dataApprovalAuditStore.getDataApprovalAudits(params);
assertEquals(1, audits.size());
assertEquals(auditA, audits.get(0));
params = new DataApprovalAuditQueryParams();
params.setStartDate(dateB);
audits = dataApprovalAuditStore.getDataApprovalAudits(params);
assertEquals(1, audits.size());
assertEquals(auditB, audits.get(0));
params = new DataApprovalAuditQueryParams();
params.setEndDate(dateB);
audits = dataApprovalAuditStore.getDataApprovalAudits(params);
assertEquals(1, audits.size());
assertEquals(auditA, audits.get(0));
CurrentUserService mockUserService = new MockCurrentUserService(Sets.newHashSet(sourceB), null);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, mockUserService, dataApprovalAuditStore);
params = new DataApprovalAuditQueryParams();
audits = dataApprovalAuditStore.getDataApprovalAudits(params);
assertEquals(1, audits.size());
assertEquals(auditB, audits.get(0));
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalStoreUserTest method setUpTest.
// -------------------------------------------------------------------------
// Set up/tear down
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
periodA = createPeriod("201801");
periodService.addPeriod(periodA);
level1 = new DataApprovalLevel("Level1", 1, null);
level2 = new DataApprovalLevel("Level2", 2, null);
level3 = new DataApprovalLevel("Level3", 3, null);
dataApprovalLevelService.addDataApprovalLevel(level1);
dataApprovalLevelService.addDataApprovalLevel(level2);
dataApprovalLevelService.addDataApprovalLevel(level3);
PeriodType periodType = PeriodType.getPeriodTypeByName("Monthly");
workflowA = new DataApprovalWorkflow("workflowA", periodType, newHashSet(level1, level2, level3));
dataApprovalService.addWorkflow(workflowA);
DataSet dataSetA = createDataSet('A');
dataSetA.assignWorkflow(workflowA);
dataSetService.addDataSet(dataSetA);
orgUnitA = createOrganisationUnit('A');
orgUnitB = createOrganisationUnit('B', orgUnitA);
orgUnitC = createOrganisationUnit('C', orgUnitB);
orgUnitD = createOrganisationUnit('D', orgUnitA);
organisationUnitService.addOrganisationUnit(orgUnitA);
organisationUnitService.addOrganisationUnit(orgUnitB);
organisationUnitService.addOrganisationUnit(orgUnitC);
organisationUnitService.addOrganisationUnit(orgUnitD);
orgUnitA.addDataSet(dataSetA);
orgUnitB.addDataSet(dataSetA);
orgUnitC.addDataSet(dataSetA);
orgUnitD.addDataSet(dataSetA);
organisationUnitService.updateOrganisationUnit(orgUnitA);
organisationUnitService.updateOrganisationUnit(orgUnitB);
organisationUnitService.updateOrganisationUnit(orgUnitC);
organisationUnitService.updateOrganisationUnit(orgUnitD);
mockCurrentUserService = new MockCurrentUserService(true, Sets.newHashSet(orgUnitA), Sets.newHashSet(orgUnitA));
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, mockCurrentUserService, dataApprovalStore, dataApprovalLevelService);
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalAuditServiceTest 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);
user.setUsername(userName);
for (UserAuthorityGroup role : user.getUserAuthorityGroups()) {
// Give the role an
role.setName(CodeGenerator.generateUid());
// arbitrary name
userService.addUserAuthorityGroup(role);
}
userService.addUser(user);
return mockCurrentUserService;
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalLevelServiceTest method testGetUserDataApprovalLevelsApproveHere.
// TODO: add tests for getUserDataApprovalLevels where the user can access
// the CategoryOptionGroupSets
@Test
void testGetUserDataApprovalLevelsApproveHere() {
dataApprovalLevelService.addDataApprovalLevel(level4B);
dataApprovalLevelService.addDataApprovalLevel(level4A);
dataApprovalLevelService.addDataApprovalLevel(level4);
dataApprovalLevelService.addDataApprovalLevel(level3B);
dataApprovalLevelService.addDataApprovalLevel(level3A);
dataApprovalLevelService.addDataApprovalLevel(level3);
dataApprovalLevelService.addDataApprovalLevel(level2B);
dataApprovalLevelService.addDataApprovalLevel(level2A);
dataApprovalLevelService.addDataApprovalLevel(level2);
dataApprovalLevelService.addDataApprovalLevel(level1B);
dataApprovalLevelService.addDataApprovalLevel(level1A);
dataApprovalLevelService.addDataApprovalLevel(level1);
Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
assignedOrgUnits.add(organisationUnitB);
Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
dataViewOrgUnits.add(organisationUnitB);
CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits, DataApproval.AUTH_APPROVE);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataApprovalLevelService);
List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels(currentUserService.getCurrentUser());
assertEquals("02 2A 2B 03 3A 3B 04 4A 4B", levelNames(levels));
}
Aggregations