← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2030: Improved testing

 

------------------------------------------------------------
revno: 2030
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Wed 2010-09-01 09:28:01 +0200
message:
  Improved testing
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.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/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2010-09-01 06:14:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2010-09-01 07:28:01 +0000
@@ -113,12 +113,12 @@
         Collection<ValidationRule> validationRules = getAllValidationRules();
 
         Collection<ValidationResult> validationViolations = new HashSet<ValidationResult>();
-        
+
         for ( Source source : sources  )
         {
             for ( Period period : periods )
             {
-                validationViolations.addAll( validate( period, source, validationRules, true ) );
+                validationViolations.addAll( validateInternal( period, source, validationRules, true ) );
             }
         }
         
@@ -143,7 +143,7 @@
         {
             for ( Period period : periods )
             {
-                validationViolations.addAll( validate( period, source, validationRules, true ) );
+                validationViolations.addAll( validateInternal( period, source, validationRules, true ) );
             }
         }
         
@@ -164,7 +164,7 @@
             {                    
                 for ( Period period : relevantPeriods )
                 {
-                    validationViolations.addAll( validate( period, source, relevantRules, false ) );
+                    validationViolations.addAll( validateInternal( period, source, relevantRules, false ) );
                 }
             }
         }
@@ -188,7 +188,7 @@
             {
                 for ( Period period : relevantPeriods )
                 {
-                    validationViolations.addAll( validate( period, source, relevantRules, false ) );
+                    validationViolations.addAll( validateInternal( period, source, relevantRules, false ) );
                 }
             }
         }
@@ -206,7 +206,7 @@
 
         for ( Period period : relevantPeriods )
         {
-            validationViolations.addAll( validate( period, source, relevantRules, false ) );
+            validationViolations.addAll( validateInternal( period, source, relevantRules, false ) );
         }
         
         return validationViolations;
@@ -214,7 +214,7 @@
 
     public Collection<ValidationResult> validate( DataSet dataSet, Period period, Source source )
     {
-        return validate( period, source, getRelevantValidationRules( dataSet.getDataElements() ), false );
+        return validateInternal( period, source, getRelevantValidationRules( dataSet.getDataElements() ), false );
     }
 
     // -------------------------------------------------------------------------
@@ -229,7 +229,7 @@
      * @param validationRules the rules to validate.
      * @returns a collection of rules that did not pass validation.
      */
-    private Collection<ValidationResult> validate( final Period period, final Source source,
+    private Collection<ValidationResult> validateInternal( final Period period, final Source source,
         final Collection<ValidationRule> validationRules, boolean aggregate )
     {
         final Collection<ValidationResult> validationResults = new HashSet<ValidationResult>();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java	2010-09-01 06:14:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java	2010-09-01 07:28:01 +0000
@@ -38,7 +38,10 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.amplecode.quick.BatchHandler;
+import org.amplecode.quick.BatchHandlerFactory;
 import org.hisp.dhis.DhisTest;
+import org.hisp.dhis.aggregation.AggregatedDataValue;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -49,6 +52,7 @@
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.expression.Expression;
 import org.hisp.dhis.expression.ExpressionService;
+import org.hisp.dhis.jdbc.batchhandler.AggregatedDataValueBatchHandler;
 import org.hisp.dhis.mock.MockSource;
 import org.hisp.dhis.period.MonthlyPeriodType;
 import org.hisp.dhis.period.Period;
@@ -58,6 +62,7 @@
 import org.hisp.dhis.source.SourceStore;
 import org.hisp.dhis.system.util.MathUtils;
 import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
 
 /**
  * @author Lars Helge Overland
@@ -66,10 +71,9 @@
 public class ValidationRuleServiceTest
     extends DhisTest
 {
-    private ValidationRuleService validationRuleService;
-
-    private ExpressionService expressionService;
-
+    @Autowired
+    private BatchHandlerFactory batchHandlerFactory;
+    
     private DataElement dataElementA;
 
     private DataElement dataElementB;
@@ -222,14 +226,10 @@
         dataElementService.updateDataElement( dataElementC );
         dataElementService.updateDataElement( dataElementD );
         
-        validationRuleA = createValidationRule( 'A', ValidationRule.OPERATOR_EQUAL, expressionA, expressionB,
-            periodType );
-        validationRuleB = createValidationRule( 'B', ValidationRule.OPERATOR_GREATER, expressionB, expressionC,
-            periodType );
-        validationRuleC = createValidationRule( 'C', ValidationRule.OPERATOR_LESSER_EQUAL, expressionB, expressionA,
-            periodType );
-        validationRuleD = createValidationRule( 'D', ValidationRule.OPERATOR_LESSER, expressionA, expressionC,
-            periodType );
+        validationRuleA = createValidationRule( 'A', ValidationRule.OPERATOR_EQUAL, expressionA, expressionB, periodType );
+        validationRuleB = createValidationRule( 'B', ValidationRule.OPERATOR_GREATER, expressionB, expressionC, periodType );
+        validationRuleC = createValidationRule( 'C', ValidationRule.OPERATOR_LESSER_EQUAL, expressionB, expressionA, periodType );
+        validationRuleD = createValidationRule( 'D', ValidationRule.OPERATOR_LESSER, expressionA, expressionC, periodType );
 
         group = createValidationRuleGroup( 'A' );
     }
@@ -244,8 +244,63 @@
     // Business logic tests
     // ----------------------------------------------------------------------
 
+    @Test
     public void testValidateAggregatedDateDateSources()
-    {   
+    {
+        periodService.addPeriod( periodA );
+        periodService.addPeriod( periodB );
+        
+        BatchHandler<AggregatedDataValue> batchHandler = batchHandlerFactory.createBatchHandler( AggregatedDataValueBatchHandler.class ).init();
+        
+        batchHandler.addObject( new AggregatedDataValue( dataElementA.getId(), categoryOptionCombo.getId(), periodA.getId(), 0, sourceA.getId(), 0, 1.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementB.getId(), categoryOptionCombo.getId(), periodA.getId(), 0, sourceA.getId(), 0, 2.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementC.getId(), categoryOptionCombo.getId(), periodA.getId(), 0, sourceA.getId(), 0, 3.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementD.getId(), categoryOptionCombo.getId(), periodA.getId(), 0, sourceA.getId(), 0, 4.0 ) );
+
+        batchHandler.addObject( new AggregatedDataValue( dataElementA.getId(), categoryOptionCombo.getId(), periodB.getId(), 0, sourceA.getId(), 0, 1.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementB.getId(), categoryOptionCombo.getId(), periodB.getId(), 0, sourceA.getId(), 0, 2.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementC.getId(), categoryOptionCombo.getId(), periodB.getId(), 0, sourceA.getId(), 0, 3.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementD.getId(), categoryOptionCombo.getId(), periodB.getId(), 0, sourceA.getId(), 0, 4.0 ) );
+
+        batchHandler.addObject( new AggregatedDataValue( dataElementA.getId(), categoryOptionCombo.getId(), periodA.getId(), 0, sourceB.getId(), 0, 1.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementB.getId(), categoryOptionCombo.getId(), periodA.getId(), 0, sourceB.getId(), 0, 2.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementC.getId(), categoryOptionCombo.getId(), periodA.getId(), 0, sourceB.getId(), 0, 3.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementD.getId(), categoryOptionCombo.getId(), periodA.getId(), 0, sourceB.getId(), 0, 4.0 ) );
+
+        batchHandler.addObject( new AggregatedDataValue( dataElementA.getId(), categoryOptionCombo.getId(), periodB.getId(), 0, sourceB.getId(), 0, 1.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementB.getId(), categoryOptionCombo.getId(), periodB.getId(), 0, sourceB.getId(), 0, 2.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementC.getId(), categoryOptionCombo.getId(), periodB.getId(), 0, sourceB.getId(), 0, 3.0 ) );
+        batchHandler.addObject( new AggregatedDataValue( dataElementD.getId(), categoryOptionCombo.getId(), periodB.getId(), 0, sourceB.getId(), 0, 4.0 ) );
+        
+        batchHandler.flush();
+
+        validationRuleService.saveValidationRule( validationRuleA );
+        validationRuleService.saveValidationRule( validationRuleB );
+        validationRuleService.saveValidationRule( validationRuleC );
+        validationRuleService.saveValidationRule( validationRuleD );
+
+        Collection<ValidationResult> results = validationRuleService.validateAggregate( getDate( 2000, 2, 1 ), getDate( 2000, 6, 1 ), sourcesA );
+        
+        Collection<ValidationResult> reference = new HashSet<ValidationResult>();
+
+        reference.add( new ValidationResult( periodA, sourceA, validationRuleA, 3.0, -1.0 ) );
+        reference.add( new ValidationResult( periodB, sourceA, validationRuleA, 3.0, -1.0 ) );
+        reference.add( new ValidationResult( periodA, sourceB, validationRuleA, 3.0, -1.0 ) );
+        reference.add( new ValidationResult( periodB, sourceB, validationRuleA, 3.0, -1.0 ) );
+
+        reference.add( new ValidationResult( periodA, sourceA, validationRuleB, -1.0, 4.0 ) );
+        reference.add( new ValidationResult( periodB, sourceA, validationRuleB, -1.0, 4.0 ) );
+        reference.add( new ValidationResult( periodA, sourceB, validationRuleB, -1.0, 4.0 ) );
+        reference.add( new ValidationResult( periodB, sourceB, validationRuleB, -1.0, 4.0 ) );
+
+        for ( ValidationResult result : results )
+        {
+            assertFalse( MathUtils.expressionIsTrue( result.getLeftsideValue(), result.getValidationRule()
+                .getOperator(), result.getRightsideValue() ) );
+        }
+
+        assertEquals( results.size(), 8 );
+        assertEquals( reference, results );
     }
     
     @Test

=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2010-07-10 12:15:44 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2010-09-01 07:28:01 +0000
@@ -36,6 +36,7 @@
 import java.util.List;
 import java.util.Set;
 
+import org.hisp.dhis.aggregation.AggregatedDataValueService;
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.datadictionary.DataDictionary;
 import org.hisp.dhis.datadictionary.DataDictionaryService;
@@ -128,6 +129,8 @@
     protected OrganisationUnitService organisationUnitService;
 
     protected OrganisationUnitGroupService organisationUnitGroupService;
+    
+    protected AggregatedDataValueService aggregatedDataValueService;
 
     protected PeriodService periodService;