← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18354: adds tests for QueryService.getQueryFromUrl(...)

 

------------------------------------------------------------
revno: 18354
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-02-20 16:25:12 +0700
message:
  adds tests for QueryService.getQueryFromUrl(...)
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-19 05:29:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java	2015-02-20 09:25:12 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.collect.Lists;
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObjectManager;
@@ -112,6 +113,16 @@
     }
 
     @Test
+    public void getAllQueryUrl()
+    {
+        createDataElements();
+        Query query = queryService.getQueryFromUrl( DataElement.class, Lists.<String>newArrayList(), Lists.<Order>newArrayList() );
+        Result result = queryService.query( query );
+
+        assertEquals( 6, result.size() );
+    }
+
+    @Test
     public void getMinMaxQuery()
     {
         createDataElements();
@@ -141,6 +152,17 @@
     }
 
     @Test
+    public void getEqQueryUrl()
+    {
+        createDataElements();
+        Query query = queryService.getQueryFromUrl( DataElement.class, Lists.newArrayList( "id:eq:deabcdefghA" ), Lists.<Order>newArrayList() );
+        Result result = queryService.query( query );
+
+        assertEquals( 1, result.size() );
+        assertEquals( "deabcdefghA", result.getItems().get( 0 ).getUid() );
+    }
+
+    @Test
     public void getNeQuery()
     {
         createDataElements();
@@ -159,6 +181,23 @@
     }
 
     @Test
+    public void getNeQueryUrl()
+    {
+        createDataElements();
+        Query query = queryService.getQueryFromUrl( DataElement.class, Lists.newArrayList( "id:ne:deabcdefghA" ), Lists.<Order>newArrayList() );
+        Result result = queryService.query( query );
+
+        assertEquals( 5, result.size() );
+
+        assertFalse( collectionContainsUid( result.getItems(), "deabcdefghA" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghB" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghC" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghD" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghE" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghF" ) );
+    }
+
+    @Test
     public void getLikeQuery()
     {
         createDataElements();
@@ -171,6 +210,17 @@
     }
 
     @Test
+    public void getLikeQueryUrl()
+    {
+        createDataElements();
+        Query query = queryService.getQueryFromUrl( DataElement.class, Lists.newArrayList( "name:like:F" ), Lists.<Order>newArrayList() );
+        Result result = queryService.query( query );
+
+        assertEquals( 1, result.size() );
+        assertEquals( "deabcdefghF", result.getItems().get( 0 ).getUid() );
+    }
+
+    @Test
     public void getGtQuery()
     {
         createDataElements();
@@ -186,6 +236,20 @@
     }
 
     @Test
+    public void getGtQueryUrl()
+    {
+        createDataElements();
+        Query query = queryService.getQueryFromUrl( DataElement.class, Lists.newArrayList( "created:gt:2003" ), Lists.<Order>newArrayList() );
+        Result result = queryService.query( query );
+
+        assertEquals( 3, result.size() );
+
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghD" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghE" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghF" ) );
+    }
+
+    @Test
     public void getLtQuery()
     {
         createDataElements();
@@ -200,6 +264,19 @@
     }
 
     @Test
+    public void getLtQueryUrl()
+    {
+        createDataElements();
+        Query query = queryService.getQueryFromUrl( DataElement.class, Lists.newArrayList( "created:lt:2003" ), Lists.<Order>newArrayList() );
+        Result result = queryService.query( query );
+
+        assertEquals( 2, result.size() );
+
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghA" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghB" ) );
+    }
+
+    @Test
     public void getGeQuery()
     {
         createDataElements();
@@ -216,6 +293,21 @@
     }
 
     @Test
+    public void getGeQueryUrl()
+    {
+        createDataElements();
+        Query query = queryService.getQueryFromUrl( DataElement.class, Lists.newArrayList( "created:ge:2003" ), Lists.<Order>newArrayList() );
+        Result result = queryService.query( query );
+
+        assertEquals( 4, result.size() );
+
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghC" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghD" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghE" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghF" ) );
+    }
+
+    @Test
     public void getLeQuery()
     {
         createDataElements();
@@ -231,6 +323,20 @@
     }
 
     @Test
+    public void getLeQueryUrl()
+    {
+        createDataElements();
+        Query query = queryService.getQueryFromUrl( DataElement.class, Lists.newArrayList( "created:le:2003" ), Lists.<Order>newArrayList() );
+        Result result = queryService.query( query );
+
+        assertEquals( 3, result.size() );
+
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghA" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghB" ) );
+        assertTrue( collectionContainsUid( result.getItems(), "deabcdefghC" ) );
+    }
+
+    @Test
     public void getBetweenQuery()
     {
         createDataElements();