Search in sources :

Example 11 with MockCurrentUserService

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());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Date(java.util.Date) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 12 with MockCurrentUserService

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());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Date(java.util.Date) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 13 with MockCurrentUserService

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());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Date(java.util.Date) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 14 with MockCurrentUserService

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));
}
Also used : MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 15 with MockCurrentUserService

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);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService)

Aggregations

MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)37 CurrentUserService (org.hisp.dhis.user.CurrentUserService)34 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)28 Test (org.junit.Test)28 DhisTest (org.hisp.dhis.DhisTest)19 IntegrationTest (org.hisp.dhis.IntegrationTest)18 Date (java.util.Date)17 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)17 Category (org.junit.experimental.categories.Category)17 HashSet (java.util.HashSet)9 DhisSpringTest (org.hisp.dhis.DhisSpringTest)9 DataMayNotBeApprovedException (org.hisp.dhis.dataapproval.exceptions.DataMayNotBeApprovedException)4 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)3 Expression (org.hisp.dhis.expression.Expression)2 User (org.hisp.dhis.user.User)2 Attribute (org.hisp.dhis.attribute.Attribute)1 AttributeValue (org.hisp.dhis.attribute.AttributeValue)1 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1 DataValue (org.hisp.dhis.datavalue.DataValue)1