Search in sources :

Example 6 with CurrentUserService

use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.

the class DataApprovalServiceTest method testMayUnapproveNoAuthority.

@Test
@Category(IntegrationTest.class)
public void testMayUnapproveNoAuthority() {
    Set<OrganisationUnit> units = newHashSet(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(units, null, 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());
    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 7 with CurrentUserService

use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.

the class DataApprovalServiceTest method testDeleteDataApproval.

@Test
@Category(IntegrationTest.class)
public void testDeleteDataApproval() {
    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, workflow12, periodA, organisationUnitA, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    DataApproval dataApprovalB = new DataApproval(level2, workflow12, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userB);
    dataApprovalService.approveData(newArrayList(dataApprovalB));
    dataApprovalService.approveData(newArrayList(dataApprovalA));
    assertTrue(dataApprovalService.getDataApprovalStatus(workflow12, periodA, organisationUnitA, defaultOptionCombo).getState().isApproved());
    assertTrue(dataApprovalService.getDataApprovalStatus(workflow12, periodA, organisationUnitB, defaultOptionCombo).getState().isApproved());
    // Only A should be deleted.
    dataApprovalService.unapproveData(newArrayList(dataApprovalA));
    assertFalse(dataApprovalService.getDataApprovalStatus(workflow12, periodA, organisationUnitA, defaultOptionCombo).getState().isApproved());
    assertTrue(dataApprovalService.getDataApprovalStatus(workflow12, periodA, organisationUnitB, defaultOptionCombo).getState().isApproved());
    dataApprovalService.unapproveData(newArrayList(dataApprovalB));
    assertFalse(dataApprovalService.getDataApprovalStatus(workflow12, periodA, organisationUnitA, defaultOptionCombo).getState().isApproved());
    assertFalse(dataApprovalService.getDataApprovalStatus(workflow12, periodA, organisationUnitB, defaultOptionCombo).getState().isApproved());
}
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 8 with CurrentUserService

use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.

the class DataApprovalServiceTest method testWorkflows.

@Test
@Category(IntegrationTest.class)
public void testWorkflows() {
    Set<OrganisationUnit> units = newHashSet(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(units, null, AUTH_APPR_LEVEL, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS);
    userService.addUser(currentUserService.getCurrentUser());
    setCurrentUserServiceDependencies(currentUserService);
    assertEquals("UNAPPROVED_WAITING level=null approve=F unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo));
    assertEquals("UNAPPROVED_ABOVE level=null approve=F unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow12, periodA, organisationUnitC, defaultOptionCombo));
    assertEquals("UNAPPROVED_READY level=null approve=T unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow3, periodA, organisationUnitC, defaultOptionCombo));
    Date date = new Date();
    dataApprovalStore.addDataApproval(new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA));
    dataApprovalStore.addDataApproval(new DataApproval(level4, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA));
    dataApprovalStore.addDataApproval(new DataApproval(level2, workflow12, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA));
    dataApprovalStore.addDataApproval(new DataApproval(level3, workflow3, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA));
    assertEquals("APPROVED_HERE level=level4 approve=T unapprove=T accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo));
    assertEquals("APPROVED_ABOVE level=null approve=F unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow12, periodA, organisationUnitC, defaultOptionCombo));
    assertEquals("APPROVED_HERE level=level3 approve=T unapprove=T accept=F unaccept=F read=T", statusAndPermissions(workflow3, periodA, organisationUnitC, defaultOptionCombo));
}
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 9 with CurrentUserService

use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.

the class DataApprovalServiceTest method testAddDuplicateDataApproval.

// -------------------------------------------------------------------------
// Basic DataApproval
// -------------------------------------------------------------------------
@Test
public void testAddDuplicateDataApproval() {
    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(level2, workflow12, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    // Same
    DataApproval dataApprovalB = new DataApproval(level2, workflow12, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    dataApprovalService.approveData(newArrayList(dataApprovalA));
    // Redundant, so call is ignored.
    dataApprovalService.approveData(newArrayList(dataApprovalB));
}
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) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 10 with CurrentUserService

use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.

the class DataApprovalServiceTest method testGetDataApprovalStateWithMultipleChildren.

@Test
@Category(IntegrationTest.class)
public void testGetDataApprovalStateWithMultipleChildren() {
    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();
    assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getState());
    dataApprovalService.approveData(newArrayList(new DataApproval(level4, workflow1234, periodA, organisationUnitF, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
    assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.APPROVED_HERE, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getState());
    dataApprovalService.approveData(newArrayList(new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
    assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.APPROVED_HERE, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.APPROVED_HERE, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getState());
    dataApprovalService.approveData(newArrayList(new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
    assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.APPROVED_HERE, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.APPROVED_HERE, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.APPROVED_ABOVE, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getState());
    dataApprovalService.approveData(newArrayList(new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
    assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.APPROVED_HERE, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.APPROVED_ABOVE, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.APPROVED_HERE, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.APPROVED_ABOVE, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitF, 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)

Aggregations

MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)34 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 Expression (org.hisp.dhis.expression.Expression)2 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)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 MockBatchHandlerFactory (org.hisp.dhis.mock.batchhandler.MockBatchHandlerFactory)1