use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataValueSetServiceTest method setUpTest.
@Override
public void setUpTest() {
mockDataValueBatchHandler = new MockBatchHandler<>();
mockDataValueAuditBatchHandler = new MockBatchHandler<>();
mockBatchHandlerFactory = new MockBatchHandlerFactory();
mockBatchHandlerFactory.registerBatchHandler(DataValueBatchHandler.class, mockDataValueBatchHandler);
mockBatchHandlerFactory.registerBatchHandler(DataValueAuditBatchHandler.class, mockDataValueAuditBatchHandler);
setDependency(dataValueSetService, "batchHandlerFactory", mockBatchHandlerFactory);
attribute = new Attribute("CUSTOM_ID", ValueType.TEXT);
attribute.setUid(ATTRIBUTE_UID);
attribute.setUnique(true);
attribute.setOrganisationUnitAttribute(true);
attribute.setDataElementAttribute(true);
idObjectManager.save(attribute);
categoryOptionA = createCategoryOption('A');
categoryOptionB = createCategoryOption('B');
categoryA = createDataElementCategory('A', categoryOptionA, categoryOptionB);
categoryComboA = createCategoryCombo('A', categoryA);
categoryComboDef = categoryService.getDefaultDataElementCategoryCombo();
ocDef = categoryService.getDefaultDataElementCategoryOptionCombo();
ocDef.setCode("OC_DEF_CODE");
categoryService.updateDataElementCategoryOptionCombo(ocDef);
osA = new OptionSet("OptionSetA", ValueType.INTEGER);
osA.getOptions().add(new Option("Blue", "1"));
osA.getOptions().add(new Option("Green", "2"));
osA.getOptions().add(new Option("Yellow", "3"));
ocA = createCategoryOptionCombo(categoryComboA, categoryOptionA);
ocB = createCategoryOptionCombo(categoryComboA, categoryOptionB);
deA = createDataElement('A', categoryComboDef);
deB = createDataElement('B', categoryComboDef);
deC = createDataElement('C', categoryComboDef);
deD = createDataElement('D', categoryComboDef);
deE = createDataElement('E');
deE.setOptionSet(osA);
deF = createDataElement('F', categoryComboDef);
deF.setValueType(ValueType.BOOLEAN);
deG = createDataElement('G', categoryComboDef);
deG.setValueType(ValueType.TRUE_ONLY);
dsA = createDataSet('A', new MonthlyPeriodType());
dsA.setCategoryCombo(categoryComboDef);
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B');
ouC = createOrganisationUnit('C');
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));
ocA.setUid("kjuiHgy67hg");
ocB.setUid("Gad33qy67g5");
deA.setUid("f7n9E0hX8qk");
deB.setUid("Ix2HsbDMLea");
deC.setUid("eY5ehpbEsB7");
deE.setUid("jH26dja2f28");
deF.setUid("jH26dja2f30");
deG.setUid("jH26dja2f31");
dsA.setUid("pBOMPrpg1QX");
ouA.setUid("DiszpKrYNg8");
ouB.setUid("BdfsJfj87js");
ouC.setUid("j7Hg26FpoIa");
ocA.setCode("OC_A");
ocB.setCode("OC_B");
deA.setCode("DE_A");
deB.setCode("DE_B");
deC.setCode("DE_C");
deD.setCode("DE_D");
dsA.setCode("DS_A");
ouA.setCode("OU_A");
ouB.setCode("OU_B");
ouC.setCode("OU_C");
categoryService.addDataElementCategoryOption(categoryOptionA);
categoryService.addDataElementCategoryOption(categoryOptionB);
categoryService.addDataElementCategory(categoryA);
categoryService.addDataElementCategoryCombo(categoryComboA);
categoryService.addDataElementCategoryOptionCombo(ocA);
categoryService.addDataElementCategoryOptionCombo(ocB);
attributeService.addAttributeValue(deA, createAttributeValue(attribute, "DE1"));
dataElementService.addDataElement(deA);
attributeService.addAttributeValue(deB, createAttributeValue(attribute, "DE2"));
dataElementService.addDataElement(deB);
attributeService.addAttributeValue(deC, createAttributeValue(attribute, "DE3"));
dataElementService.addDataElement(deC);
attributeService.addAttributeValue(deD, createAttributeValue(attribute, "DE4"));
dataElementService.addDataElement(deD);
dataElementService.addDataElement(deF);
dataElementService.addDataElement(deG);
idObjectManager.save(osA);
dsA.addDataSetElement(deA);
dsA.addDataSetElement(deB);
dsA.addDataSetElement(deC);
dsA.addDataSetElement(deD);
attributeService.addAttributeValue(ouA, createAttributeValue(attribute, "OU1"));
organisationUnitService.addOrganisationUnit(ouA);
attributeService.addAttributeValue(ouB, createAttributeValue(attribute, "OU2"));
organisationUnitService.addOrganisationUnit(ouB);
attributeService.addAttributeValue(ouC, createAttributeValue(attribute, "OU3"));
organisationUnitService.addOrganisationUnit(ouC);
dsA.addOrganisationUnit(ouA);
dsA.addOrganisationUnit(ouC);
dataSetService.addDataSet(dsA);
periodService.addPeriod(peA);
periodService.addPeriod(peB);
periodService.addPeriod(peC);
user = createUser('A');
user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
CurrentUserService currentUserService = new MockCurrentUserService(user);
setDependency(dataValueSetService, "currentUserService", currentUserService);
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class ValidationServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
CurrentUserService currentUserService = new MockCurrentUserService(allSources, null);
setDependency(validationService, "currentUserService", currentUserService, CurrentUserService.class);
periodTypeWeekly = new WeeklyPeriodType();
periodTypeMonthly = new MonthlyPeriodType();
periodTypeYearly = new YearlyPeriodType();
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementC = createDataElement('C');
dataElementD = createDataElement('D');
dataElementE = createDataElement('E');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
dataElementService.addDataElement(dataElementE);
optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
String suffix = SEPARATOR + optionCombo.getUid();
optionCombos = new HashSet<>();
optionCombos.add(optionCombo);
expressionA = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA");
expressionB = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB");
expressionC = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC");
expressionD = new Expression("#{" + dataElementB.getUid() + suffix + "}", "expressionD");
expressionE = new Expression("AVG(#{" + dataElementB.getUid() + suffix + "} * 1.5)", "expressionE");
expressionF = new Expression("#{" + dataElementB.getUid() + suffix + "} / #{" + dataElementE.getUid() + suffix + "}", "expressionF");
expressionG = new Expression("AVG(#{" + dataElementB.getUid() + suffix + "} * 1.5 / #{" + dataElementE.getUid() + suffix + "})", "expressionG");
expressionH = new Expression("AVG(#{" + dataElementB.getUid() + suffix + "}) + 1.5*STDDEV(#{" + dataElementB.getUid() + suffix + "})", "expressionH");
expressionI = new Expression("#{" + dataElementA.getUid() + suffix + "}", "expressionI");
expressionJ = new Expression("#{" + dataElementB.getUid() + suffix + "}", "expressionJ");
expressionK = new Expression("#{" + dataElementC.getUid() + "}", "expressionK", NEVER_SKIP);
expressionL = new Expression("#{" + dataElementD.getUid() + "}", "expressionL", NEVER_SKIP);
expressionP = new Expression(SYMBOL_DAYS, "expressionP", NEVER_SKIP);
expressionQ = new Expression("#{" + dataElementE.getUid() + "}", "expressionQ", NEVER_SKIP);
expressionService.addExpression(expressionA);
expressionService.addExpression(expressionB);
expressionService.addExpression(expressionC);
expressionService.addExpression(expressionD);
expressionService.addExpression(expressionE);
expressionService.addExpression(expressionF);
expressionService.addExpression(expressionG);
expressionService.addExpression(expressionH);
expressionService.addExpression(expressionI);
expressionService.addExpression(expressionJ);
expressionService.addExpression(expressionK);
expressionService.addExpression(expressionL);
expressionService.addExpression(expressionP);
expressionService.addExpression(expressionQ);
periodA = createPeriod(periodTypeMonthly, getDate(2000, 3, 1), getDate(2000, 3, 31));
periodB = createPeriod(periodTypeMonthly, getDate(2000, 4, 1), getDate(2000, 4, 30));
periodY = createPeriod(periodTypeYearly, getDate(2000, 1, 1), getDate(2000, 12, 31));
dayInPeriodA = periodService.getDayInPeriod(periodA, new Date());
dayInPeriodB = periodService.getDayInPeriod(periodB, new Date());
dayInPeriodY = periodService.getDayInPeriod(periodY, new Date());
dataSetWeekly = createDataSet('W', periodTypeWeekly);
dataSetMonthly = createDataSet('M', periodTypeMonthly);
dataSetYearly = createDataSet('Y', periodTypeYearly);
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');
sourcesA.add(sourceA);
sourcesA.add(sourceB);
allSources.add(sourceA);
allSources.add(sourceB);
allSources.add(sourceC);
allSources.add(sourceD);
allSources.add(sourceE);
allSources.add(sourceF);
allSources.add(sourceG);
dataSetMonthly.addOrganisationUnit(sourceA);
dataSetMonthly.addOrganisationUnit(sourceB);
dataSetMonthly.addOrganisationUnit(sourceC);
dataSetMonthly.addOrganisationUnit(sourceD);
dataSetMonthly.addOrganisationUnit(sourceE);
dataSetMonthly.addOrganisationUnit(sourceF);
dataSetWeekly.addOrganisationUnit(sourceB);
dataSetWeekly.addOrganisationUnit(sourceC);
dataSetWeekly.addOrganisationUnit(sourceD);
dataSetWeekly.addOrganisationUnit(sourceE);
dataSetWeekly.addOrganisationUnit(sourceF);
dataSetWeekly.addOrganisationUnit(sourceG);
dataSetYearly.addOrganisationUnit(sourceB);
dataSetYearly.addOrganisationUnit(sourceC);
dataSetYearly.addOrganisationUnit(sourceD);
dataSetYearly.addOrganisationUnit(sourceE);
dataSetYearly.addOrganisationUnit(sourceF);
organisationUnitService.addOrganisationUnit(sourceA);
organisationUnitService.addOrganisationUnit(sourceB);
organisationUnitService.addOrganisationUnit(sourceC);
organisationUnitService.addOrganisationUnit(sourceD);
organisationUnitService.addOrganisationUnit(sourceE);
organisationUnitService.addOrganisationUnit(sourceF);
organisationUnitService.addOrganisationUnit(sourceG);
dataSetMonthly.addDataSetElement(dataElementA);
dataSetMonthly.addDataSetElement(dataElementB);
dataSetMonthly.addDataSetElement(dataElementC);
dataSetMonthly.addDataSetElement(dataElementD);
dataSetWeekly.addDataSetElement(dataElementE);
dataSetYearly.addDataSetElement(dataElementE);
dataSetService.addDataSet(dataSetWeekly);
dataSetService.addDataSet(dataSetMonthly);
dataSetService.addDataSet(dataSetYearly);
dataElementService.updateDataElement(dataElementA);
dataElementService.updateDataElement(dataElementB);
dataElementService.updateDataElement(dataElementC);
dataElementService.updateDataElement(dataElementD);
dataElementService.updateDataElement(dataElementE);
// deA + deB = deC - deD
validationRuleA = createValidationRule("A", equal_to, expressionA, expressionB, periodTypeMonthly);
// deC - deD > deB * 2
validationRuleB = createValidationRule("B", greater_than, expressionB, expressionC, periodTypeMonthly);
// deC - deD <= deA + deB
validationRuleC = createValidationRule("C", less_than_or_equal_to, expressionB, expressionA, periodTypeMonthly);
// deA + deB < deB * 2
validationRuleD = createValidationRule("D", less_than, expressionA, expressionC, periodTypeMonthly);
// deA [Compulsory pair] deB
validationRuleE = createValidationRule("E", compulsory_pair, expressionI, expressionJ, periodTypeMonthly);
// deA [Exclusive pair] deB
validationRuleF = createValidationRule("F", exclusive_pair, expressionI, expressionJ, periodTypeMonthly);
// deC = deD
validationRuleG = createValidationRule("G", equal_to, expressionK, expressionL, periodTypeMonthly);
// deA = [days]
validationRuleP = createValidationRule("P", equal_to, expressionI, expressionP, periodTypeMonthly);
// deE = [days]
validationRuleQ = createValidationRule("Q", equal_to, expressionQ, expressionP, periodTypeYearly);
// deA + deB = deB * 2
validationRuleX = createValidationRule("X", equal_to, expressionA, expressionC, periodTypeMonthly);
group = createValidationRuleGroup('A');
defaultCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceTest method testMayApproveSameLevel.
@Test
@Category(IntegrationTest.class)
public void testMayApproveSameLevel() {
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();
// Level 4 (organisationUnitD and organisationUnitF ready)
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 3 (organisationUnitC) and Level 4 (organisationUnitF) ready
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit C.");
} catch (DataMayNotBeApprovedException ex) {
// Expected error, so add the data through dataApprovalStore:
}
dataApprovalStore.addDataApproval(new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA));
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 2 (organisationUnitB) ready
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level4, workflow1234, periodA, organisationUnitF, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit F.");
} catch (DataMayNotBeApprovedException ex) {
// Expected error, so add the data through dataApprovalStore:
}
dataApprovalStore.addDataApproval(new DataApproval(level4, workflow1234, periodA, organisationUnitF, defaultOptionCombo, NOT_ACCEPTED, date, userA));
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit E.");
} catch (DataMayNotBeApprovedException ex) {
// Expected error, so add the data through dataApprovalStore:
}
dataApprovalStore.addDataApproval(new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA));
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit C.");
} catch (DataMayNotBeApprovedException ex) {
// Expected error, so add the data through dataApprovalStore:
}
dataApprovalStore.addDataApproval(new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA));
assertEquals("UNAPPROVED_READY level=null approve=T unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo));
assertEquals("APPROVED_HERE level=level3 approve=T unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level4 approve=F unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo));
assertEquals("APPROVED_HERE level=level3 approve=T unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level4 approve=F unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo));
// Level 1 (organisationUnitA) ready
dataApprovalService.approveData(newArrayList(new DataApproval(level2, workflow1234, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
assertEquals("APPROVED_HERE level=level2 approve=F unapprove=T accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level3 approve=T unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level4 approve=F unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level3 approve=T unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level4 approve=F unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo));
// 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 testAddAllAndGetDataApprovalStatus.
@Test
@Category(IntegrationTest.class)
public void testAddAllAndGetDataApprovalStatus() {
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();
DataApproval dataApprovalA = new DataApproval(level1, workflow12A, periodA, organisationUnitA, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalB = new DataApproval(level2, workflow12A, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalC = new DataApproval(level2, workflow12A, periodB, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalD = new DataApproval(level2, workflow12B, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
// Must be approved before A.
dataApprovalService.approveData(newArrayList(dataApprovalB, dataApprovalC, dataApprovalD));
dataApprovalService.approveData(newArrayList(dataApprovalA));
DataApprovalStatus status = dataApprovalService.getDataApprovalStatus(workflow12A, periodA, organisationUnitA, defaultOptionCombo);
assertEquals(DataApprovalState.APPROVED_HERE, status.getState());
assertNotNull(status);
assertEquals(organisationUnitA.getUid(), status.getOrganisationUnitUid());
assertEquals(date, status.getCreated());
assertEquals(userA.getId(), status.getCreator().getId());
DataApprovalLevel level = status.getApprovedLevel();
assertNotNull(level);
assertEquals(level1.getName(), level.getName());
status = dataApprovalService.getDataApprovalStatus(workflow12A, periodA, organisationUnitB, defaultOptionCombo);
assertEquals(DataApprovalState.APPROVED_ABOVE, status.getState());
assertNotNull(status);
assertEquals(organisationUnitB.getUid(), status.getOrganisationUnitUid());
assertEquals(date, status.getCreated());
assertEquals(userA.getId(), status.getCreator().getId());
level = status.getApprovedLevel();
assertNotNull(level);
assertEquals(level2.getName(), level.getName());
status = dataApprovalService.getDataApprovalStatus(workflow12A, periodB, organisationUnitB, defaultOptionCombo);
assertEquals(DataApprovalState.APPROVED_HERE, status.getState());
assertNotNull(status);
assertEquals(organisationUnitB.getUid(), status.getOrganisationUnitUid());
assertEquals(date, status.getCreated());
assertEquals(userA.getId(), status.getCreator().getId());
level = status.getApprovedLevel();
assertNotNull(level);
assertEquals(level2.getName(), level.getName());
status = dataApprovalService.getDataApprovalStatus(workflow12B, periodA, organisationUnitB, defaultOptionCombo);
assertEquals(DataApprovalState.APPROVED_HERE, status.getState());
assertNotNull(status);
assertEquals(organisationUnitB.getUid(), status.getOrganisationUnitUid());
assertEquals(date, status.getCreated());
assertEquals(userA.getId(), status.getCreator().getId());
level = status.getApprovedLevel();
assertNotNull(level);
assertEquals(level2.getName(), level.getName());
status = dataApprovalService.getDataApprovalStatus(workflow12B, periodB, organisationUnitB, defaultOptionCombo);
assertEquals(DataApprovalState.UNAPPROVED_READY, status.getState());
level = status.getApprovedLevel();
assertNull(level);
}
use of org.hisp.dhis.mock.MockCurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceTest method testGetDataApprovalStateOtherPeriodTypes.
@Test
@Category(IntegrationTest.class)
public void testGetDataApprovalStateOtherPeriodTypes() {
Set<OrganisationUnit> units = newHashSet(organisationUnitA);
CurrentUserService currentUserService = new MockCurrentUserService(units, null, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS);
setCurrentUserServiceDependencies(currentUserService);
assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodB, organisationUnitA, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodY, organisationUnitA, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodY, organisationUnitD, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodD, organisationUnitD, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodW, organisationUnitD, defaultOptionCombo).getState());
}
Aggregations