← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5914: Fixed minor issue with DataMarTask and added test

 

------------------------------------------------------------
revno: 5914
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-02-11 14:10:26 +0100
message:
  Fixed minor issue with DataMarTask and added test
added:
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/scheduling/
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/scheduling/TaskTest.java
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataMartTask.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-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataMartTask.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataMartTask.java	2012-02-08 21:32:42 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataMartTask.java	2012-02-11 13:10:26 +0000
@@ -145,7 +145,7 @@
     /**
      * Generates periods based on parameters and period types argument.
      */
-    private List<Period> getPeriods( Set<String> periodTypes )
+    public List<Period> getPeriods( Set<String> periodTypes )
     {
         List<Period> periods = new RelativePeriods().getRelativePeriods( periodTypes ).getRelativePeriods( 1 );
         
@@ -154,7 +154,7 @@
             periods.addAll( new RelativePeriods().setLastYear( true ).getRelativePeriods( 1 ) );
         }
         
-        final Date date = new Cal().now().subtract( Calendar.MONTH, 6 ).time();
+        final Date date = new Cal().now().subtract( Calendar.MONTH, 7 ).time();
         
         if ( last6Months )
         {

=== added directory 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/scheduling'
=== added file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/scheduling/TaskTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/scheduling/TaskTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/scheduling/TaskTest.java	2012-02-11 13:10:26 +0000
@@ -0,0 +1,80 @@
+package org.hisp.dhis.system.scheduling;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.QuarterlyPeriodType;
+import org.hisp.dhis.period.SixMonthlyPeriodType;
+import org.hisp.dhis.period.YearlyPeriodType;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class TaskTest
+{
+    @Test
+    public void testGetPeriods()
+    {
+        Set<String> periodTypes = new HashSet<String>();
+        periodTypes.add( MonthlyPeriodType.NAME );
+        periodTypes.add( QuarterlyPeriodType.NAME );
+        periodTypes.add( SixMonthlyPeriodType.NAME );
+        periodTypes.add( YearlyPeriodType.NAME );
+        
+        DataMartTask dataMartTask = new DataMartTask();
+        
+        List<Period> periods = dataMartTask.getPeriods( periodTypes );
+        
+        assertNotNull( periods );
+        assertEquals( 20, periods.size() ); // 2 Y, 2 S, 4 Q, 12 M
+        
+        dataMartTask.setLast6Months( true );
+        dataMartTask.setFrom6To12Months( false );
+        
+        periods = dataMartTask.getPeriods( periodTypes );
+
+        assertNotNull( periods );
+        assertEquals( 10, periods.size() ); // 1 Y, 1 S, 2 Q, 6 M
+        
+        dataMartTask.setLast6Months( false );
+        dataMartTask.setFrom6To12Months( true );
+
+        periods = dataMartTask.getPeriods( periodTypes );
+
+        assertNotNull( periods );
+        assertEquals( 10, periods.size() ); // 1 Y, 1 S, 2 Q, 6 M        
+    }
+}