use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceTest method testMayApproveSameAndLowerLevels.
@Test
@Category(IntegrationTest.class)
public void testMayApproveSameAndLowerLevels() {
Set<OrganisationUnit> units = newHashSet(organisationUnitB);
CurrentUserService currentUserService = new MockCurrentUserService(units, null, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS, AUTH_APPR_LEVEL);
userService.addUser(currentUserService.getCurrentUser());
setCurrentUserServiceDependencies(currentUserService);
Date date = new Date();
// Level 4 (organisationUnitD and organisationUnitF ready)
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 3 (organisationUnitC) and Level 4 (organisationUnitF) ready
dataApprovalService.approveData(newArrayList(new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 2 (organisationUnitB) ready
dataApprovalService.approveData(newArrayList(new DataApproval(level4, workflow1234, periodA, organisationUnitF, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
dataApprovalService.approveData(newArrayList(new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
dataApprovalService.approveData(newArrayList(new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 1 (organisationUnitA) ready
dataApprovalService.approveData(newArrayList(new DataApproval(level2, workflow1234, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 1 (organisationUnitA) try to approve
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level1, workflow1234, periodA, organisationUnitA, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit A.");
} catch (DataMayNotBeApprovedException ex) {
// Expected
}
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceTest method testMayApproveLowerLevels.
@Test
@Category(IntegrationTest.class)
public void testMayApproveLowerLevels() {
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();
// Level 4 (organisationUnitD and organisationUnitF ready)
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 3 (organisationUnitC) and Level 4 (organisationUnitF) ready
dataApprovalService.approveData(newArrayList(new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 2 (organisationUnitB) ready
dataApprovalService.approveData(newArrayList(new DataApproval(level4, workflow1234, periodA, organisationUnitF, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
dataApprovalService.approveData(newArrayList(new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
dataApprovalService.approveData(newArrayList(new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 1 (organisationUnitA) ready
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level2, workflow1234, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit B.");
} catch (DataMayNotBeApprovedException ex) {
// Expected error, so add the data through dataApprovalStore:
}
dataApprovalStore.addDataApproval(new DataApproval(level2, workflow1234, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA));
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 1 (organisationUnitA) try to approve
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level1, workflow1234, periodA, organisationUnitA, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit A.");
} catch (DataMayNotBeApprovedException ex) {
// Expected
}
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class PredictorServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
organisationUnitService.addOrganisationUnitLevel(orgUnitLevel1);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementC = createDataElement('C');
dataElementD = createDataElement('D');
dataElementX = createDataElement('X', ValueType.NUMBER, AggregationType.NONE);
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
dataElementService.addDataElement(dataElementX);
dataElements = new HashSet<>();
dataElements.add(dataElementA);
dataElements.add(dataElementB);
dataElements.add(dataElementC);
dataElements.add(dataElementD);
sourceA = createOrganisationUnit('A');
sourceB = createOrganisationUnit('B');
sourceC = createOrganisationUnit('C', sourceB);
sourceD = createOrganisationUnit('D', sourceB);
sourceE = createOrganisationUnit('E', sourceD);
sourceF = createOrganisationUnit('F', sourceD);
sourceG = createOrganisationUnit('G');
organisationUnitService.addOrganisationUnit(sourceA);
organisationUnitService.addOrganisationUnit(sourceB);
organisationUnitService.addOrganisationUnit(sourceC);
organisationUnitService.addOrganisationUnit(sourceD);
organisationUnitService.addOrganisationUnit(sourceE);
organisationUnitService.addOrganisationUnit(sourceF);
organisationUnitService.addOrganisationUnit(sourceG);
periodTypeMonthly = PeriodType.getPeriodTypeByName("Monthly");
dataSetMonthly = createDataSet('M', periodTypeMonthly);
dataSetMonthly.addDataSetElement(dataElementA);
dataSetMonthly.addDataSetElement(dataElementB);
dataSetMonthly.addDataSetElement(dataElementC);
dataSetMonthly.addDataSetElement(dataElementD);
dataSetMonthly.addDataSetElement(dataElementX);
dataSetMonthly.addOrganisationUnit(sourceA);
dataSetMonthly.addOrganisationUnit(sourceB);
dataSetMonthly.addOrganisationUnit(sourceC);
dataSetMonthly.addOrganisationUnit(sourceD);
dataSetMonthly.addOrganisationUnit(sourceE);
dataSetMonthly.addOrganisationUnit(sourceG);
dataSetService.addDataSet(dataSetMonthly);
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
defaultCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
altCategoryOption = new DataElementCategoryOption("AltCategoryOption");
categoryService.addDataElementCategoryOption(altCategoryOption);
altDataElementCategory = createDataElementCategory('A', altCategoryOption);
categoryService.addDataElementCategory(altDataElementCategory);
altDataElementCategoryCombo = createCategoryCombo('Y', altDataElementCategory);
categoryService.addDataElementCategoryCombo(altDataElementCategoryCombo);
altCombo = createCategoryOptionCombo('Z', altDataElementCategoryCombo, altCategoryOption);
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
optionCombos.add(altCombo);
categoryService.addDataElementCategoryOptionCombo(altCombo);
expressionA = new Expression("AVG(#{" + dataElementA.getUid() + "})+1.5*STDDEV(#{" + dataElementA.getUid() + "})", "descriptionA");
expressionB = new Expression("AVG(#{" + dataElementB.getUid() + "." + defaultCombo.getUid() + "})", "descriptionB");
expressionC = new Expression("1234", "descriptionC");
expressionD = new Expression(SYMBOL_DAYS, "descriptionD");
expressionService.addExpression(expressionA);
expressionService.addExpression(expressionB);
expressionService.addExpression(expressionC);
expressionService.addExpression(expressionD);
Set<OrganisationUnit> units = newHashSet(sourceA, sourceB, sourceG);
CurrentUserService mockCurrentUserService = new MockCurrentUserService(true, units, units);
setDependency(predictorService, "currentUserService", mockCurrentUserService, CurrentUserService.class);
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataSetServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
userService = _userService;
periodType = new MonthlyPeriodType();
period = createPeriod(periodType, getDate(2000, 3, 1), getDate(2000, 3, 31));
periodService.addPeriod(period);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
unitA = createOrganisationUnit('A');
unitB = createOrganisationUnit('B');
unitC = createOrganisationUnit('C');
unitD = createOrganisationUnit('D');
unitE = createOrganisationUnit('E');
unitF = createOrganisationUnit('F');
organisationUnitService.addOrganisationUnit(unitA);
organisationUnitService.addOrganisationUnit(unitB);
organisationUnitService.addOrganisationUnit(unitC);
organisationUnitService.addOrganisationUnit(unitD);
organisationUnitService.addOrganisationUnit(unitE);
organisationUnitService.addOrganisationUnit(unitF);
attributeOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
mockCurrentUserService = new MockCurrentUserService(true, newHashSet(unitA), newHashSet(unitA), UserAuthorityGroup.AUTHORITY_ALL);
setDependency(approvalService, "currentUserService", mockCurrentUserService, CurrentUserService.class);
setDependency(approvalStore, "currentUserService", mockCurrentUserService, CurrentUserService.class);
setDependency(levelService, "currentUserService", mockCurrentUserService, CurrentUserService.class);
User user = mockCurrentUserService.getCurrentUser();
user.setFirstName("John");
user.setSurname("Doe");
userService.addUser(mockCurrentUserService.getCurrentUser());
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataValueSetServiceExportTest method setUpTest.
@Override
public void setUpTest() {
deA = createDataElement('A');
deB = createDataElement('B');
deC = createDataElement('C');
idObjectManager.save(deA);
idObjectManager.save(deB);
idObjectManager.save(deC);
ccA = createCategoryCombo('A');
categoryService.addDataElementCategoryCombo(ccA);
cocA = createCategoryOptionCombo('A');
cocB = createCategoryOptionCombo('B');
cocA.setCategoryCombo(ccA);
cocB.setCategoryCombo(ccA);
categoryService.addDataElementCategoryOptionCombo(cocA);
categoryService.addDataElementCategoryOptionCombo(cocB);
atA = createAttribute('A');
atA.setDataElementAttribute(true);
atA.setOrganisationUnitAttribute(true);
atA.setCategoryOptionComboAttribute(true);
idObjectManager.save(atA);
dsA = createDataSet('A');
dsA.addDataSetElement(deA);
dsA.addDataSetElement(deB);
dsB = createDataSet('B');
dsB.addDataSetElement(deA);
dataSetService.addDataSet(dsA);
dataSetService.addDataSet(dsB);
peA = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2016, 3, 1), getDate(2016, 3, 31));
peB = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2016, 4, 1), getDate(2016, 4, 30));
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B', ouA);
organisationUnitService.addOrganisationUnit(ouA);
organisationUnitService.addOrganisationUnit(ouB);
avA = new AttributeValue("AttributeValueA", atA);
avB = new AttributeValue("AttributeValueB", atA);
avC = new AttributeValue("AttributeValueC", atA);
avD = new AttributeValue("AttributeValueD", atA);
attributeService.addAttributeValue(deA, avA);
attributeService.addAttributeValue(ouA, avB);
attributeService.addAttributeValue(cocA, avC);
attributeService.addAttributeValue(cocB, avD);
// Data values
dataValueService.addDataValue(new DataValue(deA, peA, ouA, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peA, ouA, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deA, peA, ouB, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peA, ouB, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouA, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouA, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouB, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouB, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouA, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouA, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouB, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouB, cocB, cocB, "1"));
// Flush session to make data values visible to JDBC query
dbmsManager.flushSession();
// Service mocks
user = createUser('A');
user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
CurrentUserService currentUserService = new MockCurrentUserService(user);
setDependency(dataValueSetService, "currentUserService", currentUserService);
setDependency(organisationUnitService, "currentUserService", currentUserService);
}
Aggregations