← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19953: add tests for get de by value type(s)

 

------------------------------------------------------------
revno: 19953
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-03 11:42:52 +0700
message:
  add tests for get de by value type(s)
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.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-api/src/main/java/org/hisp/dhis/common/ValueType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java	2015-09-03 04:17:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java	2015-09-03 04:42:52 +0000
@@ -61,6 +61,16 @@
     OPTION_SET( String.class ),
     USERNAME( String.class );
 
+    public static List<ValueType> INTEGER_TYPES = Lists.newArrayList(
+        INTEGER, INTEGER_POSITIVE, INTEGER_NEGATIVE, INTEGER_ZERO_OR_POSITIVE
+    );
+
+    public static List<ValueType> NUMERIC_TYPES = Lists.newArrayList(
+        INTEGER, INTEGER_POSITIVE, INTEGER_NEGATIVE, INTEGER_ZERO_OR_POSITIVE, NUMBER, UNIT_INTERVAL, PERCENTAGE
+    );
+
+    public static List<ValueType> TEXT_TYPES = Lists.newArrayList( TEXT, LONG_TEXT );
+
     public static List<String> INTEGER_TYPE_STRINGS = Lists.newArrayList(
         INTEGER.toString(), INTEGER_POSITIVE.toString(), INTEGER_NEGATIVE.toString(), INTEGER_ZERO_OR_POSITIVE.toString()
     );
@@ -70,9 +80,7 @@
         NUMBER.toString(), UNIT_INTERVAL.toString(), PERCENTAGE.toString()
     );
 
-    public static List<String> TEXT_TYPE_STRINGS = Lists.newArrayList(
-        TEXT.toString(), LONG_TEXT.toString()
-    );
+    public static List<String> TEXT_TYPE_STRINGS = Lists.newArrayList( TEXT.toString(), LONG_TEXT.toString() );
 
     private final Class<?> javaClass;
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java	2015-09-03 04:31:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java	2015-09-03 04:42:52 +0000
@@ -29,6 +29,7 @@
  */
 
 import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.common.ValueType;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -280,10 +281,8 @@
     @Test
     public void testGetDataElementsByAggregationOperator()
     {
-        assertEquals( 0, dataElementService.getDataElementsByAggregationOperator(
-            DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM ).size() );
-        assertEquals( 0, dataElementService.getDataElementsByAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM )
-            .size() );
+        assertEquals( 0, dataElementService.getDataElementsByAggregationOperator( DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM ).size() );
+        assertEquals( 0, dataElementService.getDataElementsByAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM ).size() );
 
         DataElement dataElementA = createDataElement( 'A' );
         dataElementA.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM );
@@ -303,6 +302,50 @@
         assertEquals( 3, dataElementService.getDataElementsByAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM ).size() );
     }
 
+    @Test
+    public void testGetDataElementsByValueType()
+    {
+        DataElement dataElementA = createDataElement( 'A', ValueType.NUMBER );
+        DataElement dataElementB = createDataElement( 'B', ValueType.NUMBER );
+        DataElement dataElementC = createDataElement( 'C', ValueType.BOOLEAN );
+        DataElement dataElementD = createDataElement( 'D', ValueType.TEXT );
+
+        dataElementService.addDataElement( dataElementA );
+        dataElementService.addDataElement( dataElementB );
+        dataElementService.addDataElement( dataElementC );
+        dataElementService.addDataElement( dataElementD );
+
+        assertEquals( 2, dataElementService.getDataElementsByValueType( ValueType.NUMBER ).size() );
+        assertEquals( 1, dataElementService.getDataElementsByValueType( ValueType.BOOLEAN ).size() );
+        assertEquals( 1, dataElementService.getDataElementsByValueType( ValueType.TEXT ).size() );
+        assertEquals( 0, dataElementService.getDataElementsByValueType( ValueType.LONG_TEXT ).size() );
+        assertEquals( 0, dataElementService.getDataElementsByValueType( ValueType.INTEGER ).size() );
+        assertEquals( 0, dataElementService.getDataElementsByValueType( ValueType.INTEGER_POSITIVE ).size() );
+        assertEquals( 0, dataElementService.getDataElementsByValueType( ValueType.INTEGER_NEGATIVE ).size() );
+    }
+
+    @Test
+    public void testGetDataElementsByValueTypes()
+    {
+        DataElement dataElementA = createDataElement( 'A', ValueType.INTEGER );
+        DataElement dataElementB = createDataElement( 'B', ValueType.INTEGER_POSITIVE );
+        DataElement dataElementC = createDataElement( 'C', ValueType.INTEGER_ZERO_OR_POSITIVE );
+        DataElement dataElementD = createDataElement( 'D', ValueType.NUMBER );
+        DataElement dataElementE = createDataElement( 'E', ValueType.TEXT );
+        DataElement dataElementF = createDataElement( 'F', ValueType.LONG_TEXT );
+
+        dataElementService.addDataElement( dataElementA );
+        dataElementService.addDataElement( dataElementB );
+        dataElementService.addDataElement( dataElementC );
+        dataElementService.addDataElement( dataElementD );
+        dataElementService.addDataElement( dataElementE );
+        dataElementService.addDataElement( dataElementF );
+
+        assertEquals( 3, dataElementService.getDataElementsByValueTypes( ValueType.INTEGER_TYPES ).size() );
+        assertEquals( 4, dataElementService.getDataElementsByValueTypes( ValueType.NUMERIC_TYPES ).size() );
+        assertEquals( 2, dataElementService.getDataElementsByValueTypes( ValueType.TEXT_TYPES ).size() );
+    }
+
     // -------------------------------------------------------------------------
     // DataElementGroup
     // -------------------------------------------------------------------------

=== 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	2015-09-03 03:11:47 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2015-09-03 04:42:52 +0000
@@ -362,6 +362,27 @@
 
     /**
      * @param uniqueCharacter A unique character to identify the object.
+     */
+    public static DataElement createDataElement( char uniqueCharacter, ValueType valueType )
+    {
+        DataElement dataElement = new DataElement();
+        dataElement.setAutoFields();
+
+        dataElement.setUid( BASE_DE_UID + uniqueCharacter );
+        dataElement.setName( "DataElement" + uniqueCharacter );
+        dataElement.setShortName( "DataElementShort" + uniqueCharacter );
+        dataElement.setCode( "DataElementCode" + uniqueCharacter );
+        dataElement.setDescription( "DataElementDescription" + uniqueCharacter );
+        dataElement.setType( DataElement.VALUE_TYPE_INT ); // remove
+        dataElement.setValueType( valueType );
+        dataElement.setDomainType( DataElementDomain.AGGREGATE );
+        dataElement.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );
+
+        return dataElement;
+    }
+
+    /**
+     * @param uniqueCharacter A unique character to identify the object.
      * @param categoryCombo   The category combo.
      */
     public static DataElement createDataElement( char uniqueCharacter, DataElementCategoryCombo categoryCombo )
@@ -391,6 +412,21 @@
 
     /**
      * @param uniqueCharacter     A unique character to identify the object.
+     * @param valueType           The value type.
+     * @param aggregationOperator The aggregation operator.
+     */
+    public static DataElement createDataElement( char uniqueCharacter, ValueType valueType, String aggregationOperator )
+    {
+        DataElement dataElement = createDataElement( uniqueCharacter );
+        dataElement.setValueType( valueType );
+        dataElement.setDomainType( DataElementDomain.AGGREGATE );
+        dataElement.setAggregationOperator( aggregationOperator );
+
+        return dataElement;
+    }
+
+    /**
+     * @param uniqueCharacter     A unique character to identify the object.
      * @param type                The value type.
      * @param aggregationOperator The aggregation operator.
      * @param categoryCombo       The category combo.