You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/09/19 17:05:48 UTC

[3/5] git commit: Test to show that cursor is not required for result sets that do not require it.

Test to show that cursor is not required for result sets that do not require it.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/dfc0d96b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/dfc0d96b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/dfc0d96b

Branch: refs/heads/two-dot-o
Commit: dfc0d96b67f301e8784f11c148287d81c6415704
Parents: 6ae1a66
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Sep 18 10:27:53 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Sep 18 10:27:53 2014 -0400

----------------------------------------------------------------------
 .../collection/PagingResourceIT.java            | 52 ++++++++++++++++++--
 1 file changed, 48 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dfc0d96b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/PagingResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/PagingResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/PagingResourceIT.java
index c7a7a84..7008f3e 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/PagingResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/PagingResourceIT.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import javax.ws.rs.core.MediaType;
 import org.apache.usergrid.cassandra.Concurrent;
 import org.apache.usergrid.java.client.entities.Entity;
 import org.apache.usergrid.java.client.response.ApiResponse;
@@ -34,6 +35,7 @@ import org.apache.usergrid.rest.test.resource.EntityResource;
 import static org.apache.usergrid.utils.MapUtils.hashMap;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import org.junit.Ignore;
@@ -52,6 +54,13 @@ public class PagingResourceIT extends AbstractRestIT {
     @Rule
     public TestContextSetup context = new TestContextSetup( this );
 
+    private static ObjectMapper mapper = new ObjectMapper();
+
+    private static final ApiResponse parse( JsonNode response ) throws Exception {
+        String jsonResponseString = mapper.writeValueAsString( response );
+        return mapper.readValue( jsonResponseString, ApiResponse.class );
+    }
+
 
     @Test
     public void collectionPaging() throws Exception {
@@ -229,11 +238,46 @@ public class PagingResourceIT extends AbstractRestIT {
     }
 
 
-    private static ObjectMapper mapper = new ObjectMapper();
+    @Test
+    public void testCursor() throws Exception {
+
+        // test that we do get cursor when we need one
+        // create 50 widgets
+        int widgetsSize = 50;
+        CustomCollection widgets = context.application().collection("widgets");
+        for (int i = 0; i < widgetsSize; i++) {
+            Map<String, String> entity = hashMap("name", String.valueOf(i));
+            widgets.create(entity);
+        }
+        refreshIndex(context.getOrgName(), context.getAppName());
+
+        // fetch all widgets 
+        JsonNode widgetsNode = mapper.readTree(
+            resource().path("/" + context.getOrgName() + "/" + context.getAppName() + "/widgets")
+                .queryParam("access_token", context.getActiveUser().getToken())
+                .accept(MediaType.APPLICATION_JSON)
+                .get(String.class));
+        assertEquals(10, widgetsNode.get("count").asInt()); // get back default page size of 10
+        assertNotNull(widgetsNode.get("cursor")); // with a cursor
+
+        // test that we DO NOT get cursor when we should not get cursor
+        // create 5 trinkets
+        int trinketsSize = 5;
+        CustomCollection trinkets = context.application().collection("trinkets");
+        for (int i = 0; i < trinketsSize; i++) {
+            Map<String, String> entity = hashMap("name", String.valueOf(i));
+            trinkets.create(entity);
+        }
+        refreshIndex(context.getOrgName(), context.getAppName());
 
+        // fetch all trinkets 
+        JsonNode trinketsNode = mapper.readTree(
+            resource().path("/" + context.getOrgName() + "/" + context.getAppName() + "/trinkets")
+                .queryParam("access_token", context.getActiveUser().getToken())
+                .accept(MediaType.APPLICATION_JSON)
+                .get(String.class));
+        assertEquals(trinketsSize, trinketsNode.get("count").asInt()); // get back all 
+        assertNull(trinketsNode.get("cursor")); // and no cursor
 
-    private static final ApiResponse parse( JsonNode response ) throws Exception {
-        String jsonResponseString = mapper.writeValueAsString( response );
-        return mapper.readValue( jsonResponseString, ApiResponse.class );
     }
 }