use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceTest method testMayUnapproveLowerLevels.
@Test
@Category(IntegrationTest.class)
public void testMayUnapproveLowerLevels() {
Set<OrganisationUnit> units = newHashSet(organisationUnitB);
CurrentUserService currentUserService = new MockCurrentUserService(units, null, DataApproval.AUTH_APPROVE_LOWER_LEVELS, AUTH_APPR_LEVEL);
userService.addUser(currentUserService.getCurrentUser());
setCurrentUserServiceDependencies(currentUserService);
Date date = new Date();
DataApproval dataApprovalA = new DataApproval(level1, workflow1234, periodA, organisationUnitA, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalB = new DataApproval(level2, workflow1234, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalC = new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalD = new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalE = new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalF = new DataApproval(level4, workflow1234, periodA, organisationUnitF, defaultOptionCombo, NOT_ACCEPTED, date, userA);
dataApprovalStore.addDataApproval(dataApprovalD);
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
dataApprovalStore.addDataApproval(dataApprovalF);
dataApprovalStore.addDataApproval(dataApprovalE);
dataApprovalStore.addDataApproval(dataApprovalC);
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
dataApprovalStore.addDataApproval(dataApprovalB);
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
dataApprovalStore.addDataApproval(dataApprovalA);
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceTest method testGetDataApprovalStateAbove.
@Test
@Category(IntegrationTest.class)
public void testGetDataApprovalStateAbove() {
Set<OrganisationUnit> units = newHashSet(organisationUnitA);
CurrentUserService currentUserService = new MockCurrentUserService(units, null, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS);
userService.addUser(currentUserService.getCurrentUser());
setCurrentUserServiceDependencies(currentUserService);
Date date = new Date();
// Approved for organisation unit C
DataApproval dataApprovalC = new DataApproval(level3, workflow3, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA);
dataApprovalService.approveData(newArrayList(dataApprovalC));
assertEquals(DataApprovalState.APPROVED_HERE, dataApprovalService.getDataApprovalStatus(workflow3, periodA, organisationUnitC, defaultOptionCombo).getState());
assertEquals(DataApprovalState.APPROVED_ABOVE, dataApprovalService.getDataApprovalStatus(workflow3, periodA, organisationUnitD, defaultOptionCombo).getState());
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceTest method testMayUnapproveSameLevel.
@Test
@Category(IntegrationTest.class)
public void testMayUnapproveSameLevel() {
Set<OrganisationUnit> units = newHashSet(organisationUnitB);
CurrentUserService currentUserService = new MockCurrentUserService(units, null, DataApproval.AUTH_APPROVE, AUTH_APPR_LEVEL);
userService.addUser(currentUserService.getCurrentUser());
setCurrentUserServiceDependencies(currentUserService);
Date date = new Date();
DataApproval dataApprovalA = new DataApproval(level1, workflow1234, periodA, organisationUnitA, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalB = new DataApproval(level2, workflow1234, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalC = new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalD = new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalE = new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalF = new DataApproval(level4, workflow1234, periodA, organisationUnitF, defaultOptionCombo, NOT_ACCEPTED, date, userA);
dataApprovalStore.addDataApproval(dataApprovalD);
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
dataApprovalStore.addDataApproval(dataApprovalF);
dataApprovalStore.addDataApproval(dataApprovalE);
dataApprovalStore.addDataApproval(dataApprovalC);
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
dataApprovalStore.addDataApproval(dataApprovalB);
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
dataApprovalStore.addDataApproval(dataApprovalA);
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalAuditStoreTest method TestGetDataApprovalAudits.
@Test
public 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(dataApprovalAuditStore, "currentUserService", mockUserService, CurrentUserService.class);
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 DataValueSetServiceIntegrationTest method setUpTest.
@Override
public void setUpTest() {
deA = createDataElement('A');
deB = createDataElement('B');
deC = createDataElement('C');
deA.setUid("f7n9E0hX8qk");
deB.setUid("Ix2HsbDMLea");
deC.setUid("eY5ehpbEsB7");
idObjectManager.save(deA);
idObjectManager.save(deB);
idObjectManager.save(deC);
ptA = new MonthlyPeriodType();
dsA = createDataSet('A', ptA);
dsA.setUid("pBOMPrpg1QX");
dataSetService.addDataSet(dsA);
peA = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2012, 1, 1), getDate(2012, 1, 31));
peB = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2012, 2, 1), getDate(2012, 2, 29));
peC = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2012, 3, 1), getDate(2012, 3, 31));
periodService.addPeriod(peA);
periodService.addPeriod(peB);
periodService.addPeriod(peC);
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B');
ouC = createOrganisationUnit('C');
ouA.setUid("DiszpKrYNg8");
ouB.setUid("BdfsJfj87js");
ouC.setUid("j7Hg26FpoIa");
idObjectManager.save(ouA);
idObjectManager.save(ouB);
idObjectManager.save(ouC);
user = createUser('A');
user.setOrganisationUnits(Sets.newHashSet(ouA, ouB, ouC));
CurrentUserService currentUserService = new MockCurrentUserService(user);
setDependency(dataValueSetService, "currentUserService", currentUserService);
}
Aggregations