← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18574: Add unit tests for missing services of ProgramIndicatorService

 

------------------------------------------------------------
revno: 18574
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-03-11 10:38:51 +0700
message:
  Add unit tests for missing services of ProgramIndicatorService
modified:
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.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-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java	2015-02-16 13:13:51 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java	2015-03-11 03:38:51 +0000
@@ -94,7 +94,9 @@
     private ProgramIndicator indicatorInt;
 
     private ProgramIndicator indicatorC;
-
+    
+    private ProgramIndicator indicatorD;
+    
     @Override
     public void setUpTest()
     {
@@ -152,6 +154,13 @@
         indicatorC.setUid( "UID-C" );
         indicatorC.setShortName( "C" );
         indicatorC.setProgram( programB );
+        
+
+        indicatorD = new ProgramIndicator( "IndicatorD", "IndicatorDesD", ProgramIndicator.VALUE_TYPE_INT, "0 + A + 4 + " + ProgramIndicator.KEY_PROGRAM_VARIABLE + "{"
+            + ProgramIndicator.INCIDENT_DATE + "}" );
+        indicatorD.setUid( "UID-D" );
+        indicatorD.setShortName( "D" );
+        indicatorD.setProgram( programB );
     }
 
     @Test
@@ -289,4 +298,30 @@
         assertEquals( DateUtils.getMediumDateString( enrollmentDate ), indicatorMap.get( "IndicatorB" ) );
 
     }
+    
+    @Test
+    public void testGetExpressionDescription()
+    {
+        programIndicatorService.addProgramIndicator( indicatorDate );
+        programIndicatorService.addProgramIndicator( indicatorInt );
+
+        String description = programIndicatorService.getExpressionDescription( indicatorDate.getExpression() );
+        assertEquals( "( Incident date - Enrollment date )  / 7", description);
+        
+        description = programIndicatorService.getExpressionDescription( indicatorInt.getExpression() );
+        assertEquals( "70", description);
+    }
+    
+    @Test
+    public void testExpressionIsValid()
+    {
+        programIndicatorService.addProgramIndicator( indicatorDate );
+        programIndicatorService.addProgramIndicator( indicatorInt );
+        programIndicatorService.addProgramIndicator( indicatorD );
+
+        assertEquals( ProgramIndicator.VALID, programIndicatorService.expressionIsValid( indicatorDate.getExpression() ) );
+        assertEquals( ProgramIndicator.VALID, programIndicatorService.expressionIsValid( indicatorInt.getExpression() ) );
+        assertEquals( ProgramIndicator.EXPRESSION_NOT_WELL_FORMED, programIndicatorService.expressionIsValid( indicatorD.getExpression() ) );
+    }
+    
 }