← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 320: Made the Period constructor protected and updated a few tests.

 

------------------------------------------------------------
revno: 320
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Sat 2009-05-23 17:20:46 +0200
message:
  Made the Period constructor protected and updated a few tests.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java
  dhis-2/dhis-services/dhis-service-aggregationengine-default/src/test/java/org/hisp/dhis/aggregation/AggregationStoreTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueStoreTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java	2009-05-23 15:20:46 +0000
@@ -67,7 +67,7 @@
     {
     }
 
-    public Period( PeriodType periodType, Date startDate, Date endDate )
+    protected Period( PeriodType periodType, Date startDate, Date endDate )
     {
         this.periodType = periodType;
         this.startDate = startDate;

=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/test/java/org/hisp/dhis/aggregation/AggregationStoreTest.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/test/java/org/hisp/dhis/aggregation/AggregationStoreTest.java	2009-03-09 08:28:19 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/test/java/org/hisp/dhis/aggregation/AggregationStoreTest.java	2009-05-23 15:20:46 +0000
@@ -28,26 +28,23 @@
  */
 
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
 
-import org.hisp.dhis.DhisSpringTest;
-import org.hisp.dhis.jdbc.StatementManager;
+import org.hisp.dhis.DhisConvenienceTest;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionComboService;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.jdbc.StatementManager;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
-import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.source.Source;
 import org.hisp.dhis.source.SourceStore;
-import org.hisp.dhis.system.util.UUIdUtils;
 import org.hisp.dhis.transaction.TransactionManager;
 
 /**
@@ -55,7 +52,7 @@
  * @version $Id: AggregationStoreTest.java 5942 2008-10-16 15:44:57Z larshelg $
  */
 public class AggregationStoreTest
-    extends DhisSpringTest
+    extends DhisConvenienceTest
 {
     private TransactionManager transactionManager;
 
@@ -71,8 +68,6 @@
 
     private DataValueService dataValueService;    
     
-    private Calendar calendar;
-    
     private DataElementCategoryOptionCombo optionCombo;
     
     private StatementManager statementManager;
@@ -94,8 +89,6 @@
 
         dataValueService = (DataValueService) getBean( DataValueService.ID );
 
-        calendar = Calendar.getInstance();
-
         optionCombo = new DataElementCategoryOptionCombo();
         
         categoryOptionComboService.addDataElementCategoryOptionCombo( optionCombo );
@@ -106,14 +99,6 @@
     // -------------------------------------------------------------------------
     // Support methods
     // -------------------------------------------------------------------------
-
-    private Date getDay( int day )
-    {
-        calendar.clear();
-        calendar.set( Calendar.DAY_OF_YEAR, day );
-
-        return calendar.getTime();
-    }
     
     private Collection<Integer> getPeriodIds( Collection<Period> periods )
     {
@@ -127,22 +112,6 @@
         return periodIds;
     }
 
-    private DataElement createDataElement( char uniqueCharacter )
-    {
-        DataElement dataElement = new DataElement();
-
-        dataElement.setUuid( UUIdUtils.getUUId() );
-        dataElement.setName( "DataElement" + uniqueCharacter );
-        dataElement.setAlternativeName( "AlternativeName" + uniqueCharacter );
-        dataElement.setShortName( "DE" + uniqueCharacter );
-        dataElement.setCode( "Code" + uniqueCharacter );
-        dataElement.setDescription( "DataElementDescription" + uniqueCharacter );
-        dataElement.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );
-        dataElement.setType( DataElement.TYPE_INT );
-
-        return dataElement;
-    }
-
     // -------------------------------------------------------------------------
     // AggregationStore test
     // -------------------------------------------------------------------------
@@ -152,16 +121,14 @@
     {
         DataElement dataElementA = createDataElement( 'A' );
         
-        PeriodType periodType = periodService.getAllPeriodTypes().iterator().next();
-        
-        Period periodA = new Period( periodType, getDay( 5 ), getDay( 6 ) );
-        Period periodB = new Period( periodType, getDay( 6 ), getDay( 7 ) );
-        Period periodC = new Period( periodType, getDay( 7 ), getDay( 8 ) );
-        Period periodD = new Period( periodType, getDay( 8 ), getDay( 9 ) );
-        Period periodE = new Period( periodType, getDay( 9 ), getDay( 10 ) );
-        Period periodF = new Period( periodType, getDay( 5 ), getDay( 7 ) );
-        Period periodG = new Period( periodType, getDay( 8 ), getDay( 10 ) );
-        Period periodH = new Period( periodType, getDay( 5 ), getDay( 10 ) );
+        Period periodA = createPeriod( getDay( 5 ), getDay( 6 ) );
+        Period periodB = createPeriod( getDay( 6 ), getDay( 7 ) );
+        Period periodC = createPeriod( getDay( 7 ), getDay( 8 ) );
+        Period periodD = createPeriod( getDay( 8 ), getDay( 9 ) );
+        Period periodE = createPeriod( getDay( 9 ), getDay( 10 ) );
+        Period periodF = createPeriod( getDay( 5 ), getDay( 7 ) );
+        Period periodG = createPeriod( getDay( 8 ), getDay( 10 ) );
+        Period periodH = createPeriod( getDay( 5 ), getDay( 10 ) );
 
         Source sourceA = new OrganisationUnit( "nameA", null, "shortNameA", "codeA", null, null, false, null );
         Source sourceB = new OrganisationUnit( "nameB", null, "shortNameB", "codeB", null, null, false, null );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueServiceTest.java	2009-03-19 12:56:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueServiceTest.java	2009-05-23 15:20:46 +0000
@@ -119,11 +119,10 @@
         dataElementStore.addDataElement( dataElementC );
         dataElementStore.addDataElement( dataElementD );
 
-        PeriodType periodType = periodService.getAllPeriodTypes().iterator().next();
-        periodA = new Period( periodType, getDay( 5 ), getDay( 6 ) );
-        periodB = new Period( periodType, getDay( 6 ), getDay( 7 ) );
-        periodC = new Period( periodType, getDay( 7 ), getDay( 8 ) );
-        periodD = new Period( periodType, getDay( 8 ), getDay( 9 ) );
+        periodA = createPeriod( getDay( 5 ), getDay( 6 ) );
+        periodB = createPeriod( getDay( 6 ), getDay( 7 ) );
+        periodC = createPeriod( getDay( 7 ), getDay( 8 ) );
+        periodD = createPeriod( getDay( 8 ), getDay( 9 ) );
         
         sourceA = new DummySource( "SourceA" );
         sourceB = new DummySource( "SourceB" );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueStoreTest.java	2009-03-19 12:56:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueStoreTest.java	2009-05-23 15:20:46 +0000
@@ -123,11 +123,10 @@
         dataElementStore.addDataElement( dataElementC );
         dataElementStore.addDataElement( dataElementD );
 
-        PeriodType periodType = periodStore.getAllPeriodTypes().iterator().next();
-        periodA = new Period( periodType, getDay( 5 ), getDay( 6 ) );
-        periodB = new Period( periodType, getDay( 6 ), getDay( 7 ) );
-        periodC = new Period( periodType, getDay( 7 ), getDay( 8 ) );
-        periodD = new Period( periodType, getDay( 8 ), getDay( 9 ) );
+        periodA = createPeriod( getDay( 5 ), getDay( 6 ) );
+        periodB = createPeriod( getDay( 6 ), getDay( 7 ) );
+        periodC = createPeriod( getDay( 7 ), getDay( 8 ) );
+        periodD = createPeriod( getDay( 8 ), getDay( 9 ) );
 
         periodStore.addPeriod( periodA );
         periodStore.addPeriod( periodB );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java	2009-05-23 15:20:46 +0000
@@ -28,7 +28,6 @@
  */
 
 import java.util.Collection;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -43,7 +42,6 @@
 import org.hisp.dhis.dataelement.Operand;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.source.DummySource;
 import org.hisp.dhis.source.Source;
 import org.hisp.dhis.source.SourceStore;
@@ -124,7 +122,7 @@
         
         categoryOptionComboId = categoryOptionCombo.getId();
         
-        period = new Period( PeriodType.getAvailablePeriodTypes().iterator().next(), new Date(), new Date() );
+        period = createPeriod( getDate( 2000, 1, 1 ), getDate( 2000, 2, 1 ) );
         
         source = new DummySource( "SourceA" );
         

=== 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	2009-04-23 17:07:39 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2009-05-23 15:20:46 +0000
@@ -71,6 +71,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.MonthlyPeriodType;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
@@ -507,7 +508,7 @@
     }
     
     /**
-     * @param uniqueCharacter A unique character to identify the object.
+     * @param type The PeriodType.
      * @param startDate The start date.
      * @param endDate The end date.
      */
@@ -523,6 +524,21 @@
     }
     
     /**
+     * @param startDate The start date.
+     * @param endDate The end date.
+     */
+    protected static Period createPeriod( Date startDate, Date endDate )
+    {
+        Period period = new Period();
+        
+        period.setPeriodType( new MonthlyPeriodType() );
+        period.setStartDate( startDate );
+        period.setEndDate( endDate );
+        
+        return period;
+    }
+    
+    /**
      * @param dataElement The data element.
      * @param period The period.
      * @param source The source.



--
Trunk
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.