← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18314: minor, add tests for Query with order

 

------------------------------------------------------------
revno: 18314
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-02-18 20:22:39 +0700
message:
  minor, add tests for Query with order
modified:
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.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/test/java/org/hisp/dhis/query/QueryServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java	2015-02-18 13:15:40 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java	2015-02-18 13:22:39 +0000
@@ -32,6 +32,7 @@
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
 import org.jfree.data.time.Year;
 import org.junit.Test;
@@ -40,9 +41,7 @@
 import java.util.Collection;
 import java.util.Iterator;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -317,4 +316,64 @@
         assertTrue( collectionContainsUid( result.getItems(), "deabcdefghE" ) );
         assertTrue( collectionContainsUid( result.getItems(), "deabcdefghF" ) );
     }
+
+    @Test
+    public void sortNameDesc()
+    {
+        createDataElements();
+        Schema schema = schemaService.getDynamicSchema( DataElement.class );
+
+        Query query = Query.from( schema );
+        query.addOrder( new Order( schema.getProperty( "name" ), false ) );
+        Result result = queryService.query( query );
+
+        assertEquals( 6, result.size() );
+
+        assertEquals( "deabcdefghF", result.getItems().get( 0 ).getUid() );
+        assertEquals( "deabcdefghE", result.getItems().get( 1 ).getUid() );
+        assertEquals( "deabcdefghD", result.getItems().get( 2 ).getUid() );
+        assertEquals( "deabcdefghC", result.getItems().get( 3 ).getUid() );
+        assertEquals( "deabcdefghB", result.getItems().get( 4 ).getUid() );
+        assertEquals( "deabcdefghA", result.getItems().get( 5 ).getUid() );
+    }
+
+    @Test
+    public void sortCreatedDesc()
+    {
+        createDataElements();
+        Schema schema = schemaService.getDynamicSchema( DataElement.class );
+
+        Query query = Query.from( schema );
+        query.addOrder( new Order( schema.getProperty( "created" ), false ) );
+        Result result = queryService.query( query );
+
+        assertEquals( 6, result.size() );
+
+        assertEquals( "deabcdefghF", result.getItems().get( 0 ).getUid() );
+        assertEquals( "deabcdefghE", result.getItems().get( 1 ).getUid() );
+        assertEquals( "deabcdefghD", result.getItems().get( 2 ).getUid() );
+        assertEquals( "deabcdefghC", result.getItems().get( 3 ).getUid() );
+        assertEquals( "deabcdefghB", result.getItems().get( 4 ).getUid() );
+        assertEquals( "deabcdefghA", result.getItems().get( 5 ).getUid() );
+    }
+
+    @Test
+    public void sortCreatedAsc()
+    {
+        createDataElements();
+        Schema schema = schemaService.getDynamicSchema( DataElement.class );
+
+        Query query = Query.from( schema );
+        query.addOrder( new Order( schema.getProperty( "created" ), true ) );
+        Result result = queryService.query( query );
+
+        assertEquals( 6, result.size() );
+
+        assertEquals( "deabcdefghA", result.getItems().get( 0 ).getUid() );
+        assertEquals( "deabcdefghB", result.getItems().get( 1 ).getUid() );
+        assertEquals( "deabcdefghC", result.getItems().get( 2 ).getUid() );
+        assertEquals( "deabcdefghD", result.getItems().get( 3 ).getUid() );
+        assertEquals( "deabcdefghE", result.getItems().get( 4 ).getUid() );
+        assertEquals( "deabcdefghF", result.getItems().get( 5 ).getUid() );
+    }
 }