dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29142
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14671: Check for shared DataApprovalLevel objects in approval level tests.
------------------------------------------------------------
revno: 14671
committer: Jim Grace <jimgrace@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-04-04 12:47:36 -0400
message:
Check for shared DataApprovalLevel objects in approval level tests.
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DataApprovalSelection.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DataApprovalSelection.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DataApprovalSelection.java 2014-03-31 20:44:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DataApprovalSelection.java 2014-04-04 16:47:36 +0000
@@ -322,7 +322,6 @@
lowestApprovalLevel = dataApprovalLevel;
}
-
break;
case UNAPPROVED_READY:
@@ -399,7 +398,9 @@
{
if ( !unapprovedBelow )
{
- log.info( "getState() - not unapproved below." );
+ log.info( "getState() - unapproved ready." );
+
+ dataApprovalLevel = matchingApprovalLevels.get( thisIndex );
return DataApprovalState.UNAPPROVED_READY;
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2014-04-04 12:15:25 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2014-04-04 16:47:36 +0000
@@ -141,7 +141,8 @@
for ( DataApprovalLevel approvalLevel : getAllDataApprovalLevels() )
{
- Boolean canReadThisLevel = ( approvalLevel.getCategoryOptionGroupSet() == null || securityService.canRead( approvalLevel.getCategoryOptionGroupSet() ) );
+ Boolean canReadThisLevel = ( securityService.canRead( approvalLevel ) &&
+ ( approvalLevel.getCategoryOptionGroupSet() == null || securityService.canRead( approvalLevel.getCategoryOptionGroupSet() ) ) );
//
// Test using assignedAtLevel and approvableAtLevel values from the previous (higher) level:
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java 2014-03-31 20:44:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java 2014-04-04 16:47:36 +0000
@@ -187,7 +187,11 @@
permissions.setDataApprovalStatus( status );
- if ( canReadCategoryOptionGroups( categoryOptionGroups, dataElementCategoryOptions ) )
+ DataApprovalLevel dataApprovalLevel = status.getDataApprovalLevel();
+
+ if ( dataApprovalLevel != null && securityService.canRead( dataApprovalLevel )
+ && ( dataApprovalLevel.getCategoryOptionGroupSet() == null || securityService.canRead( dataApprovalLevel.getCategoryOptionGroupSet() ))
+ && canReadOneCategoryOptionGroup( categoryOptionGroups ) )
{
boolean accepted = false;
@@ -256,71 +260,25 @@
// -------------------------------------------------------------------------
/**
- * Return whether the user can read the category option groups (if any)
- * in this data selection. Note that if the user cannot read these groups,
- * they should not have been able to see the data in the first place through
- * the normal webapp, so this test would never fail. So the purpose of this
- * test is to make sure that the web API is not being used to attempt an
- * operation for which the user does not have the security clearance.
- * <p>
- * If category options are specified, then the user must be able to view
- * EVERY category option. The user may view a category option if they
- * have permission to view ANY category option group to which it belongs.
+ * Return true if there are no category option groups, or if there is
+ * one and the user can read it.
*
* @param categoryOptionGroups option groups (if any) for data selection
- * @param dataElementCategoryOptions category options (if any) for data selection
- * @return true if user can read the option groups, else false
+ * @return true if at most 1 option group and user can read, else false
*/
- boolean canReadCategoryOptionGroups( Set<CategoryOptionGroup> categoryOptionGroups, Set<DataElementCategoryOption> dataElementCategoryOptions)
+ boolean canReadOneCategoryOptionGroup( Set<CategoryOptionGroup> categoryOptionGroups )
{
- if ( categoryOptionGroups != null )
- {
- for ( CategoryOptionGroup group : categoryOptionGroups )
- {
- if ( !securityService.canRead( group ) )
- {
- log.info( "User cannot read categoryOptionGroup " + group.getName() + " for approval." );
-
- return false;
- }
- }
- }
-
- if ( dataElementCategoryOptions != null )
- {
- for ( DataElementCategoryOption option : dataElementCategoryOptions )
- {
- if ( !securityService.canRead( option ) )
- {
- boolean canReadGroup = false;
-
- for ( CategoryOptionGroup group : option.getGroups() )
- {
- log.info( "User " + ( securityService.canRead( group ) ? "can" : "cannot" )
- + " read option group" + group.getName()
- + " for option " + option.getName() );
-
- if ( securityService.canRead( group ) )
- {
- canReadGroup = true;
-
- break;
- }
- }
-
- if ( !canReadGroup && option.getGroups().size() != 0 )
- {
- log.info( "User cannot read option " + option.getName() );
-
- return false;
- }
- }
- }
- }
-
- log.info( "User can read categoryOptionGroup and/or dataElementCategoryOptions" );
-
- return true;
+ if ( categoryOptionGroups == null || categoryOptionGroups.size() == 0 )
+ {
+ return true;
+ }
+
+ if ( categoryOptionGroups.size() != 1 )
+ {
+ return false;
+ }
+
+ return ( securityService.canRead( (CategoryOptionGroup) categoryOptionGroups.toArray()[0] ) );
}
/**
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java 2014-04-04 16:05:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java 2014-04-04 16:47:36 +0000
@@ -53,8 +53,7 @@
public class DataApprovalLevelServiceTest
extends DhisSpringTest
{
- private static final String AUTH_APPR_LEVEL = "F_SYSTEM_SETTING";
-
+
@Autowired
private DataApprovalLevelService dataApprovalLevelService;
@@ -127,28 +126,28 @@
categoryService.saveCategoryOptionGroupSet( setD );
level1 = new DataApprovalLevel( "1", 1, null );
- level1A = new DataApprovalLevel( "1 - Set A", 1, setA );
- level1B = new DataApprovalLevel( "1 - Set B", 1, setB );
- level1C = new DataApprovalLevel( "1 - Set C", 1, setC );
- level1D = new DataApprovalLevel( "1 - Set D", 1, setD );
+ level1A = new DataApprovalLevel( "1A", 1, setA );
+ level1B = new DataApprovalLevel( "1B", 1, setB );
+ level1C = new DataApprovalLevel( "1C", 1, setC );
+ level1D = new DataApprovalLevel( "1D", 1, setD );
level2 = new DataApprovalLevel( "2", 2, null );
- level2A = new DataApprovalLevel( "2 - Set A", 2, setA );
- level2B = new DataApprovalLevel( "2 - Set B", 2, setB );
- level2C = new DataApprovalLevel( "2 - Set C", 2, setC );
- level2D = new DataApprovalLevel( "2 - Set D", 2, setD );
+ level2A = new DataApprovalLevel( "2A", 2, setA );
+ level2B = new DataApprovalLevel( "2B", 2, setB );
+ level2C = new DataApprovalLevel( "2C", 2, setC );
+ level2D = new DataApprovalLevel( "2D", 2, setD );
level3 = new DataApprovalLevel( "3", 3, null );
- level3A = new DataApprovalLevel( "3 - Set A", 3, setA );
- level3B = new DataApprovalLevel( "3 - Set B", 3, setB );
- level3C = new DataApprovalLevel( "3 - Set C", 3, setC );
- level3D = new DataApprovalLevel( "3 - Set D", 3, setD );
+ level3A = new DataApprovalLevel( "3A", 3, setA );
+ level3B = new DataApprovalLevel( "3B", 3, setB );
+ level3C = new DataApprovalLevel( "3C", 3, setC );
+ level3D = new DataApprovalLevel( "3D", 3, setD );
level4 = new DataApprovalLevel( "4", 4, null );
- level4A = new DataApprovalLevel( "4 - Set A", 4, setA );
- level4B = new DataApprovalLevel( "4 - Set B", 4, setB );
- level4C = new DataApprovalLevel( "4 - Set C", 4, setC );
- level4D = new DataApprovalLevel( "4 - Set D", 4, setD );
+ level4A = new DataApprovalLevel( "4A", 4, setA );
+ level4B = new DataApprovalLevel( "4B", 4, setB );
+ level4C = new DataApprovalLevel( "4C", 4, setC );
+ level4D = new DataApprovalLevel( "4D", 4, setD );
organisationUnitA = createOrganisationUnit( 'A' );
organisationUnitB = createOrganisationUnit( 'B', organisationUnitA );
@@ -179,7 +178,7 @@
assertEquals( 3, levels.get( 0 ).getOrgUnitLevel() );
assertEquals( "Set B", levels.get( 0 ).getCategoryOptionGroupSet().getName() );
- assertEquals( "3 - Set B", levels.get( 0 ).getName() );
+ assertEquals( "3B", levels.get( 0 ).getName() );
dataApprovalLevelService.addDataApprovalLevel( level2C );
levels = dataApprovalLevelService.getAllDataApprovalLevels();
@@ -187,11 +186,11 @@
assertEquals( 2, levels.get( 0 ).getOrgUnitLevel() );
assertEquals( "Set C", levels.get( 0 ).getCategoryOptionGroupSet().getName() );
- assertEquals( "2 - Set C", levels.get( 0 ).getName() );
+ assertEquals( "2C", levels.get( 0 ).getName() );
assertEquals( 3, levels.get( 1 ).getOrgUnitLevel() );
assertEquals( "Set B", levels.get( 1 ).getCategoryOptionGroupSet().getName() );
- assertEquals( "3 - Set B", levels.get( 1 ).getName() );
+ assertEquals( "3B", levels.get( 1 ).getName() );
dataApprovalLevelService.addDataApprovalLevel( level3 );
levels = dataApprovalLevelService.getAllDataApprovalLevels();
@@ -199,7 +198,7 @@
assertEquals( 2, levels.get( 0 ).getOrgUnitLevel() );
assertEquals( "Set C", levels.get( 0 ).getCategoryOptionGroupSet().getName() );
- assertEquals( "2 - Set C", levels.get( 0 ).getName() );
+ assertEquals( "2C", levels.get( 0 ).getName() );
assertEquals( 3, levels.get( 1 ).getOrgUnitLevel() );
assertNull( levels.get( 1 ).getCategoryOptionGroupSet() );
@@ -207,7 +206,7 @@
assertEquals( 3, levels.get( 2 ).getOrgUnitLevel() );
assertEquals( "Set B", levels.get( 2 ).getCategoryOptionGroupSet().getName() );
- assertEquals( "3 - Set B", levels.get( 2 ).getName() );
+ assertEquals( "3B", levels.get( 2 ).getName() );
dataApprovalLevelService.addDataApprovalLevel( level4A );
levels = dataApprovalLevelService.getAllDataApprovalLevels();
@@ -215,7 +214,7 @@
assertEquals( 2, levels.get( 0 ).getOrgUnitLevel() );
assertEquals( "Set C", levels.get( 0 ).getCategoryOptionGroupSet().getName() );
- assertEquals( "2 - Set C", levels.get( 0 ).getName() );
+ assertEquals( "2C", levels.get( 0 ).getName() );
assertEquals( 3, levels.get( 1 ).getOrgUnitLevel() );
assertNull( levels.get( 1 ).getCategoryOptionGroupSet() );
@@ -223,11 +222,11 @@
assertEquals( 3, levels.get( 2 ).getOrgUnitLevel() );
assertEquals( "Set B", levels.get( 2 ).getCategoryOptionGroupSet().getName() );
- assertEquals( "3 - Set B", levels.get( 2 ).getName() );
+ assertEquals( "3B", levels.get( 2 ).getName() );
assertEquals( 4, levels.get( 3 ).getOrgUnitLevel() );
assertEquals( "Set A", levels.get( 3 ).getCategoryOptionGroupSet().getName() );
- assertEquals( "4 - Set A", levels.get( 3 ).getName() );
+ assertEquals( "4A", levels.get( 3 ).getName() );
}
@Test
@@ -242,31 +241,31 @@
levels = dataApprovalLevelService.getAllDataApprovalLevels();
assertEquals( 4, levels.size() );
- assertEquals( "1 - Set A", levels.get( 0 ).getName() );
- assertEquals( "2 - Set B", levels.get( 1 ).getName() );
- assertEquals( "3 - Set C", levels.get( 2 ).getName() );
- assertEquals( "4 - Set D", levels.get( 3 ).getName() );
+ assertEquals( "1A", levels.get( 0 ).getName() );
+ assertEquals( "2B", levels.get( 1 ).getName() );
+ assertEquals( "3C", levels.get( 2 ).getName() );
+ assertEquals( "4D", levels.get( 3 ).getName() );
dataApprovalLevelService.deleteDataApprovalLevel( 2 );
levels = dataApprovalLevelService.getAllDataApprovalLevels();
assertEquals( 3, levels.size() );
- assertEquals( "1 - Set A", levels.get( 0 ).getName() );
- assertEquals( "3 - Set C", levels.get( 1 ).getName() );
- assertEquals( "4 - Set D", levels.get( 2 ).getName() );
+ assertEquals( "1A", levels.get( 0 ).getName() );
+ assertEquals( "3C", levels.get( 1 ).getName() );
+ assertEquals( "4D", levels.get( 2 ).getName() );
dataApprovalLevelService.deleteDataApprovalLevel( 3 );
levels = dataApprovalLevelService.getAllDataApprovalLevels();
assertEquals( 2, levels.size() );
- assertEquals( "1 - Set A", levels.get( 0 ).getName() );
- assertEquals( "3 - Set C", levels.get( 1 ).getName() );
+ assertEquals( "1A", levels.get( 0 ).getName() );
+ assertEquals( "3C", levels.get( 1 ).getName() );
dataApprovalLevelService.deleteDataApprovalLevel( 1 );
levels = dataApprovalLevelService.getAllDataApprovalLevels();
assertEquals( 1, levels.size() );
- assertEquals( "3 - Set C", levels.get( 0 ).getName() );
+ assertEquals( "3C", levels.get( 0 ).getName() );
dataApprovalLevelService.deleteDataApprovalLevel( 1 );
@@ -369,30 +368,30 @@
levels = dataApprovalLevelService.getAllDataApprovalLevels();
assertEquals( 5, levels.size() );
assertEquals( "1", levels.get( 0 ).getName() );
- assertEquals( "1 - Set A", levels.get( 1 ).getName() );
- assertEquals( "1 - Set B", levels.get( 2 ).getName() );
- assertEquals( "1 - Set C", levels.get( 3 ).getName() );
- assertEquals( "1 - Set D", levels.get( 4 ).getName() );
+ assertEquals( "1A", levels.get( 1 ).getName() );
+ assertEquals( "1B", levels.get( 2 ).getName() );
+ assertEquals( "1C", levels.get( 3 ).getName() );
+ assertEquals( "1D", levels.get( 4 ).getName() );
dataApprovalLevelService.moveDataApprovalLevelDown( 2 );
levels = dataApprovalLevelService.getAllDataApprovalLevels();
assertEquals( 5, levels.size() );
assertEquals( "1", levels.get( 0 ).getName() );
- assertEquals( "1 - Set B", levels.get( 1 ).getName() );
- assertEquals( "1 - Set A", levels.get( 2 ).getName() );
- assertEquals( "1 - Set C", levels.get( 3 ).getName() );
- assertEquals( "1 - Set D", levels.get( 4 ).getName() );
+ assertEquals( "1B", levels.get( 1 ).getName() );
+ assertEquals( "1A", levels.get( 2 ).getName() );
+ assertEquals( "1C", levels.get( 3 ).getName() );
+ assertEquals( "1D", levels.get( 4 ).getName() );
dataApprovalLevelService.moveDataApprovalLevelDown( 3 );
levels = dataApprovalLevelService.getAllDataApprovalLevels();
assertEquals( 5, levels.size() );
assertEquals( "1", levels.get( 0 ).getName() );
- assertEquals( "1 - Set B", levels.get( 1 ).getName() );
- assertEquals( "1 - Set C", levels.get( 2 ).getName() );
- assertEquals( "1 - Set A", levels.get( 3 ).getName() );
- assertEquals( "1 - Set D", levels.get( 4 ).getName() );
+ assertEquals( "1B", levels.get( 1 ).getName() );
+ assertEquals( "1C", levels.get( 2 ).getName() );
+ assertEquals( "1A", levels.get( 3 ).getName() );
+ assertEquals( "1D", levels.get( 4 ).getName() );
}
@Test
@@ -409,44 +408,35 @@
levels = dataApprovalLevelService.getAllDataApprovalLevels();
assertEquals( 5, levels.size() );
assertEquals( "1", levels.get( 0 ).getName() );
- assertEquals( "1 - Set A", levels.get( 1 ).getName() );
- assertEquals( "1 - Set B", levels.get( 2 ).getName() );
- assertEquals( "1 - Set C", levels.get( 3 ).getName() );
- assertEquals( "1 - Set D", levels.get( 4 ).getName() );
+ assertEquals( "1A", levels.get( 1 ).getName() );
+ assertEquals( "1B", levels.get( 2 ).getName() );
+ assertEquals( "1C", levels.get( 3 ).getName() );
+ assertEquals( "1D", levels.get( 4 ).getName() );
dataApprovalLevelService.moveDataApprovalLevelUp( 5 );
levels = dataApprovalLevelService.getAllDataApprovalLevels();
assertEquals( 5, levels.size() );
assertEquals( "1", levels.get( 0 ).getName() );
- assertEquals( "1 - Set A", levels.get( 1 ).getName() );
- assertEquals( "1 - Set B", levels.get( 2 ).getName() );
- assertEquals( "1 - Set D", levels.get( 3 ).getName() );
- assertEquals( "1 - Set C", levels.get( 4 ).getName() );
+ assertEquals( "1A", levels.get( 1 ).getName() );
+ assertEquals( "1B", levels.get( 2 ).getName() );
+ assertEquals( "1D", levels.get( 3 ).getName() );
+ assertEquals( "1C", levels.get( 4 ).getName() );
dataApprovalLevelService.moveDataApprovalLevelUp( 4 );
levels = dataApprovalLevelService.getAllDataApprovalLevels();
assertEquals( 5, levels.size() );
assertEquals( "1", levels.get( 0 ).getName() );
- assertEquals( "1 - Set A", levels.get( 1 ).getName() );
- assertEquals( "1 - Set D", levels.get( 2 ).getName() );
- assertEquals( "1 - Set B", levels.get( 3 ).getName() );
- assertEquals( "1 - Set C", levels.get( 4 ).getName() );
+ assertEquals( "1A", levels.get( 1 ).getName() );
+ assertEquals( "1D", levels.get( 2 ).getName() );
+ assertEquals( "1B", levels.get( 3 ).getName() );
+ assertEquals( "1C", levels.get( 4 ).getName() );
}
@Test
public void testGetUserDataApprovalLevelsNoAuthorities() throws Exception
{
- Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
- units.add( organisationUnitB );
- createUserAndInjectSecurityContext( units, false, AUTH_APPR_LEVEL );
-
- List<DataApprovalLevel> levels;
-
- levels = dataApprovalLevelService.getUserDataApprovalLevels();
- assertEquals( 0, levels.size() );
-
dataApprovalLevelService.addDataApprovalLevel( level4B );
dataApprovalLevelService.addDataApprovalLevel( level4A );
dataApprovalLevelService.addDataApprovalLevel( level4 );
@@ -460,19 +450,17 @@
dataApprovalLevelService.addDataApprovalLevel( level1A );
dataApprovalLevelService.addDataApprovalLevel( level1 );
- levels = dataApprovalLevelService.getUserDataApprovalLevels();
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+ units.add( organisationUnitB );
+ createUserAndInjectSecurityContext( units, false );
+
+ List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
assertEquals( 0, levels.size() );
}
@Test
public void testGetUserDataApprovalLevelsApproveHere() throws Exception
{
- Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
- units.add( organisationUnitB );
- createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, AUTH_APPR_LEVEL );
-
- List<DataApprovalLevel> levels;
-
dataApprovalLevelService.addDataApprovalLevel( level4B );
dataApprovalLevelService.addDataApprovalLevel( level4A );
dataApprovalLevelService.addDataApprovalLevel( level4 );
@@ -486,24 +474,22 @@
dataApprovalLevelService.addDataApprovalLevel( level1A );
dataApprovalLevelService.addDataApprovalLevel( level1 );
- levels = dataApprovalLevelService.getUserDataApprovalLevels();
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+ units.add( organisationUnitB );
+ createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE );
+
+ List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
assertEquals( 4, levels.size() );
assertEquals( "2", levels.get( 0 ).getName() );
- assertEquals( "2 - Set A", levels.get( 1 ).getName() );
- assertEquals( "2 - Set B", levels.get( 2 ).getName() );
+ assertEquals( "2A", levels.get( 1 ).getName() );
+ assertEquals( "2B", levels.get( 2 ).getName() );
assertEquals( "3", levels.get( 3 ).getName() );
}
@Test
public void testGetUserDataApprovalLevelsApproveLower() throws Exception
{
- Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
- units.add( organisationUnitB );
- createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE_LOWER_LEVELS, AUTH_APPR_LEVEL );
-
- List<DataApprovalLevel> levels;
-
dataApprovalLevelService.addDataApprovalLevel( level4B );
dataApprovalLevelService.addDataApprovalLevel( level4A );
dataApprovalLevelService.addDataApprovalLevel( level4 );
@@ -517,28 +503,26 @@
dataApprovalLevelService.addDataApprovalLevel( level1A );
dataApprovalLevelService.addDataApprovalLevel( level1 );
- levels = dataApprovalLevelService.getUserDataApprovalLevels();
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+ units.add( organisationUnitB );
+ createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE_LOWER_LEVELS );
+
+ List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
assertEquals( 8, levels.size() );
- assertEquals( "2 - Set A", levels.get( 0 ).getName() );
- assertEquals( "2 - Set B", levels.get( 1 ).getName() );
+ assertEquals( "2A", levels.get( 0 ).getName() );
+ assertEquals( "2B", levels.get( 1 ).getName() );
assertEquals( "3", levels.get( 2 ).getName() );
- assertEquals( "3 - Set A", levels.get( 3 ).getName() );
- assertEquals( "3 - Set B", levels.get( 4 ).getName() );
+ assertEquals( "3A", levels.get( 3 ).getName() );
+ assertEquals( "3B", levels.get( 4 ).getName() );
assertEquals( "4", levels.get( 5 ).getName() );
- assertEquals( "4 - Set A", levels.get( 6 ).getName() );
- assertEquals( "4 - Set B", levels.get( 7 ).getName() );
+ assertEquals( "4A", levels.get( 6 ).getName() );
+ assertEquals( "4B", levels.get( 7 ).getName() );
}
@Test
public void testGetUserDataApprovalLevelsApproveHereAndLower() throws Exception
{
- Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
- units.add( organisationUnitB );
- createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS, AUTH_APPR_LEVEL );
-
- List<DataApprovalLevel> levels;
-
dataApprovalLevelService.addDataApprovalLevel( level4B );
dataApprovalLevelService.addDataApprovalLevel( level4A );
dataApprovalLevelService.addDataApprovalLevel( level4 );
@@ -552,29 +536,27 @@
dataApprovalLevelService.addDataApprovalLevel( level1A );
dataApprovalLevelService.addDataApprovalLevel( level1 );
- levels = dataApprovalLevelService.getUserDataApprovalLevels();
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+ units.add( organisationUnitB );
+ createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS );
+
+ List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
assertEquals( 9, levels.size() );
assertEquals( "2", levels.get( 0 ).getName() );
- assertEquals( "2 - Set A", levels.get( 1 ).getName() );
- assertEquals( "2 - Set B", levels.get( 2 ).getName() );
+ assertEquals( "2A", levels.get( 1 ).getName() );
+ assertEquals( "2B", levels.get( 2 ).getName() );
assertEquals( "3", levels.get( 3 ).getName() );
- assertEquals( "3 - Set A", levels.get( 4 ).getName() );
- assertEquals( "3 - Set B", levels.get( 5 ).getName() );
+ assertEquals( "3A", levels.get( 4 ).getName() );
+ assertEquals( "3B", levels.get( 5 ).getName() );
assertEquals( "4", levels.get( 6 ).getName() );
- assertEquals( "4 - Set A", levels.get( 7 ).getName() );
- assertEquals( "4 - Set B", levels.get( 8 ).getName() );
+ assertEquals( "4A", levels.get( 7 ).getName() );
+ assertEquals( "4B", levels.get( 8 ).getName() );
}
@Test
public void testGetUserDataApprovalLevelsAcceptLower() throws Exception
{
- Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
- units.add( organisationUnitB );
- createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_ACCEPT_LOWER_LEVELS, AUTH_APPR_LEVEL );
-
- List<DataApprovalLevel> levels;
-
dataApprovalLevelService.addDataApprovalLevel( level4B );
dataApprovalLevelService.addDataApprovalLevel( level4A );
dataApprovalLevelService.addDataApprovalLevel( level4 );
@@ -588,11 +570,15 @@
dataApprovalLevelService.addDataApprovalLevel( level1A );
dataApprovalLevelService.addDataApprovalLevel( level1 );
- levels = dataApprovalLevelService.getUserDataApprovalLevels();
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+ units.add( organisationUnitB );
+ createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_ACCEPT_LOWER_LEVELS );
+
+ List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
assertEquals( 3, levels.size() );
- assertEquals( "2 - Set A", levels.get( 0 ).getName() );
- assertEquals( "2 - Set B", levels.get( 1 ).getName() );
+ assertEquals( "2A", levels.get( 0 ).getName() );
+ assertEquals( "2B", levels.get( 1 ).getName() );
assertEquals( "3", levels.get( 2 ).getName() );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java 2014-04-04 12:42:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java 2014-04-04 16:47:36 +0000
@@ -54,6 +54,7 @@
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.schema.AuthorityType;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserService;
import org.junit.Test;
@@ -66,6 +67,7 @@
extends DhisSpringTest
{
private static final String AUTH_APPR_LEVEL = "F_SYSTEM_SETTING";
+
@Autowired
private DataApprovalService dataApprovalService;
@@ -404,15 +406,15 @@
@Test
public void testAddAndGetDataApproval() throws Exception
{
- Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
- units.add( organisationUnitA );
- createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS, AUTH_APPR_LEVEL );
-
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel1 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel2 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel3 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel4 );
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+ units.add( organisationUnitA );
+ createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS );
+
Date date = new Date();
DataApproval dataApprovalA = new DataApproval( dataSetA, periodA, organisationUnitA, NO_GROUP, NOT_ACCEPTED, date, userA );
DataApproval dataApprovalB = new DataApproval( dataSetA, periodA, organisationUnitB, NO_GROUP, NOT_ACCEPTED, date, userA );
@@ -492,15 +494,15 @@
@Test
public void testAddDuplicateDataApproval() throws Exception
{
- Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
- units.add( organisationUnitA );
- createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS, AUTH_APPR_LEVEL );
-
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel1 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel2 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel3 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel4 );
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+ units.add( organisationUnitA );
+ createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS );
+
Date date = new Date();
DataApproval dataApprovalA = new DataApproval( dataSetA, periodA, organisationUnitA, NO_GROUP, NOT_ACCEPTED, date, userA );
DataApproval dataApprovalB = new DataApproval( dataSetA, periodA, organisationUnitA, NO_GROUP, NOT_ACCEPTED, date, userA );
@@ -521,15 +523,15 @@
@Test
public void testDeleteDataApproval() throws Exception
{
- Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
- units.add( organisationUnitA );
- createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS, AUTH_APPR_LEVEL );
-
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel1 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel2 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel3 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel4 );
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+ units.add( organisationUnitA );
+ createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS );
+
Date date = new Date();
DataApproval dataApprovalA = new DataApproval( dataSetA, periodA, organisationUnitA, NO_GROUP, NOT_ACCEPTED, date, userA );
DataApproval dataApprovalB = new DataApproval( dataSetA, periodA, organisationUnitB, NO_GROUP, NOT_ACCEPTED, date, userB );
@@ -568,15 +570,15 @@
@Test
public void testGetDataApprovalState() throws Exception
{
- Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
- units.add( organisationUnitA );
- createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS, AUTH_APPR_LEVEL );
-
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel1 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel2 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel3 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel4 );
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+ units.add( organisationUnitA );
+ createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS );
+
// Not enabled.
assertEquals( DataApprovalState.UNAPPROVABLE, dataApprovalService.getDataApprovalStatus( dataSetA, periodA, organisationUnitA, NO_GROUPS, NO_OPTIONS ).getDataApprovalState() );
assertEquals( DataApprovalState.UNAPPROVABLE, dataApprovalService.getDataApprovalStatus( dataSetA, periodA, organisationUnitB, NO_GROUPS, NO_OPTIONS ).getDataApprovalState() );
@@ -658,15 +660,15 @@
@Test
public void testGetDataApprovalStateWithMultipleChildren() throws Exception
{
- Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
- units.add( organisationUnitA );
- createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS, AUTH_APPR_LEVEL );
-
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel1 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel2 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel3 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel4 );
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+ units.add( organisationUnitA );
+ createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS );
+
dataSetA.setApproveData( true );
organisationUnitD.addDataSet( dataSetA );
@@ -716,15 +718,15 @@
@Test
public void testGetDataApprovalStateOtherPeriodTypes() throws Exception
{
- Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
- units.add( organisationUnitA );
- createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS, AUTH_APPR_LEVEL );
-
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel1 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel2 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel3 );
dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel4 );
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+ units.add( organisationUnitA );
+ createUserAndInjectSecurityContext( units, false, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS );
+
dataSetA.setApproveData( true );
organisationUnitA.addDataSet( dataSetA );