usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [06/16] incubator-usergrid git commit: Fixed PagingEntities and PagingResourceTest. Fixed bug where proper resource wasn't being used in the delete call. Added a queryParameter get call to the Entity method for testing purposes. Added a way to get the re
Date Wed, 07 Jan 2015 19:18:27 GMT
Fixed PagingEntities and PagingResourceTest.
Fixed bug where proper resource wasn't being used in the delete call.
Added a queryParameter get call to the Entity method for testing purposes.
Added a way to get the response from Collection


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

Branch: refs/heads/USERGRID-313
Commit: 56e3c3238de71e7f9bb0eb8603aab7db94e0e752
Parents: fa27c04
Author: grey <greyes@apigee.com>
Authored: Mon Dec 22 16:17:28 2014 -0800
Committer: grey <greyes@apigee.com>
Committed: Mon Dec 22 16:17:28 2014 -0800

----------------------------------------------------------------------
 .../collection/paging/PagingEntitiesTest.java   | 195 ++++++----
 .../collection/paging/PagingResourceIT.java     | 373 +++++++++----------
 .../endpoints/CollectionEndpoint.java           |   2 +-
 .../endpoints/EntityEndpoint.java               |  11 +
 .../test/resource2point0/model/Collection.java  |   9 +-
 5 files changed, 308 insertions(+), 282 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/56e3c323/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingEntitiesTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingEntitiesTest.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingEntitiesTest.java
index 9889afb..9dd1b7d 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingEntitiesTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingEntitiesTest.java
@@ -17,116 +17,169 @@
 package org.apache.usergrid.rest.applications.collection.paging;
 
 
+import java.io.IOException;
 import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 
-import com.fasterxml.jackson.databind.JsonNode;
-import java.io.IOException;
-import org.junit.Rule;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import org.apache.usergrid.persistence.index.utils.UUIDUtils;
-import org.apache.usergrid.rest.TestContextSetup;
-import org.apache.usergrid.rest.test.resource.CustomCollection;
 import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
 import org.apache.usergrid.rest.test.resource2point0.model.Collection;
 import org.apache.usergrid.rest.test.resource2point0.model.Entity;
-
-import org.apache.commons.lang.ArrayUtils;
+import org.apache.usergrid.rest.test.resource2point0.model.QueryParameters;
 
 import static org.junit.Assert.assertEquals;
-import static org.apache.usergrid.utils.MapUtils.hashMap;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 
 /**
- * // TODO: Document this
- *
- * @author ApigeeCorporation
- * @since 4.0
+ * Holds tests that handles creation of tons of entities and then paging through them
+ * using a cursor.
  */
 public class PagingEntitiesTest extends AbstractRestIT {
 
 
-    @Test //USERGRID-266
-    public void pageThroughConnectedEntities() throws IOException {
-
-
+    /**
+     * Tests that we can create 100 entities and then get them back in the order that they
were created 10 at a time and
+     * retrieving the next 10 with a cursor.
+     */
+    @Test
+    public void pagingEntities() throws IOException {
         long created = 0;
         int maxSize = 100;
-        Map<String, Object> entityPayload = new HashMap<String,Object>(  );
-        String collectionName = "merp"+ UUIDUtils.newTimeUUID();
-
-        for( created = 0; created < maxSize; created++) {
+        Map<String, Object> entityPayload = new HashMap<String, Object>();
+        String collectionName = "merp" + UUIDUtils.newTimeUUID();
 
-            entityPayload.put( "name","value"+created );
-            Entity entity = new Entity(entityPayload );
-            this.app().collection( collectionName).post( entity );
+        for ( created = 0; created < maxSize; created++ ) {
 
+            entityPayload.put( "name", "value" + created );
+            Entity entity = new Entity( entityPayload );
+            this.app().collection( collectionName ).post( entity );
         }
 
         this.refreshIndex();
 
-        Collection sandboxCollection = this.app().collection( collectionName).get();
+        Collection sandboxCollection = this.app().collection( collectionName ).get();
         assertNotNull( sandboxCollection );
 
         created = 0;
-        for(int i = 0; i< 10; i++) {
+        for ( int i = 0; i < 10; i++ ) {
             while ( sandboxCollection.hasNext() ) {
                 Entity returnedEntity = sandboxCollection.next();
                 assertEquals( "value" + created++, returnedEntity.get( "name" ) );
             }
             sandboxCollection = this.app().collection( collectionName ).getNextPage( sandboxCollection,
true );
         }
+    }
 
 
+    @Ignore( "This test only checks activities and if we can retrieve them using a limit"
+            + "Doesn't check to make sure we can page through entities that are connected
using connections." )
+    @Test //USERGRID-266
+    public void pageThroughConnectedEntities() throws IOException {
 
+        //        CustomCollection activities = context.collection( "activities" );
+        //
+        //        long created = 0;
+        //        int maxSize = 100;
+        //        long[] verifyCreated = new long[maxSize];
+        //        Map actor = hashMap( "displayName", "Erin" );
+        //        Map props = new HashMap();
+        //
+        //
+        //        props.put( "actor", actor );
+        //        props.put( "verb", "go" );
+        //
+        //        for ( int i = 0; i < maxSize; i++ ) {
+        //
+        //            props.put( "ordinal", i );
+        //            JsonNode activity = activities.create( props );
+        //            verifyCreated[i] = activity.findValue( "created" ).longValue();
+        //            if ( i == 0 ) {
+        //                created = activity.findValue( "created" ).longValue();
+        //            }
+        //        }
+        //        ArrayUtils.reverse( verifyCreated );
+        //
+        //        refreshIndex( context.getOrgName(), context.getAppName() );
+        //
+        //        String query = "select * where created >= " + created;
+        //
+        //
+        //        JsonNode node = activities.query( query, "limit", "2" ); //activities.query(query,"");
+        //        int index = 0;
+        //        while ( node.get( "entities" ).get( "created" ) != null ) {
+        //            assertEquals( 2, node.get( "entities" ).size() );
+        //
+        //            if ( node.get( "cursor" ) != null ) {
+        //                node = activities.query( query, "cursor", node.get( "cursor" ).toString()
);
+        //            }
+        //
+        //            else {
+        //                break;
+        //            }
+        //        }
     }
 
-//
-//    @Test //USERGRID-1253
-//    public void pagingQueryReturnCorrectResults() throws Exception {
-//
-//        CustomCollection activities = context.customCollection( "activities" );
-//
-//        long created = 0;
-//        int maxSize = 23;
-//        long[] verifyCreated = new long[maxSize];
-//        Map actor = hashMap( "displayName", "Erin" );
-//        Map props = new HashMap();
-//
-//        props.put( "actor", actor );
-//        props.put( "content", "bragh" );
-//
-//        for ( int i = 0; i < maxSize; i++ ) {
-//
-//            if ( i > 17 && i < 23 ) {
-//                props.put( "verb", "stop" );
-//            }
-//            else {
-//                props.put( "verb", "go" );
-//            }
-//            props.put( "ordinal", i );
-//            JsonNode activity = activities.create( props );
-//            verifyCreated[i] = activity.findValue( "created" ).longValue();
-//            if ( i == 18 ) {
-//                created = activity.findValue( "created" ).longValue();
-//            }
-//        }
-//
-//        refreshIndex(context.getOrgName(), context.getAppName());
-//
-//        String query = "select * where created >= " + created + " or verb = 'stop'";
-//
-//        JsonNode node = activities.withQuery( query ).get();
-//
-//        for ( int index = 0; index < 5; index++ ) {
-//            assertEquals( verifyCreated[maxSize - 1 - index],
-//                    node.get( "entities" ).get( index ).get( "created" ).longValue() );
-//        }
-//
-//        int totalEntitiesContained = activities.countEntities( query );
-//
-//        assertEquals( 5, totalEntitiesContained );
-//    }
+
+    /**
+     * Checks to make sure the query gives us the correct result set.
+     * @throws Exception
+     */
+    @Test //USERGRID-1253
+    public void pagingQueryReturnCorrectResults() throws Exception {
+
+        long created = 0;
+        int maxSize = 20;
+        Map<String, Object> entityPayload = new HashMap<String, Object>();
+        List<Entity> entityPayloadVerifier = new LinkedList<>(  );
+        long createdTimestamp = 0;
+        String collectionName = "merp" + createdTimestamp;
+
+        for ( created = 0; created < maxSize; created++ ) {
+
+            if ( created >= 15 && created < 20 ) {
+
+                entityPayload.put( "verb", "stop" );
+            }
+            else {
+                entityPayload.put( "verb", "go" );
+            }
+
+            entityPayload.put( "name", "value" + created );
+            Entity entity = new Entity( entityPayload );
+            entityPayloadVerifier.add( entity );
+            if(created == 15)
+                createdTimestamp = System.currentTimeMillis();
+            this.app().collection( collectionName ).post( entity );
+        }
+
+        this.refreshIndex();
+
+        String query = "select * where created >= " + createdTimestamp + " or verb = 'stop'";
+
+        QueryParameters queryParameters = new QueryParameters();
+        queryParameters.setQuery( query );
+        Collection queryCollection = this.app().collection( collectionName ).get( queryParameters
);
+
+        assertNotNull( queryCollection );
+        assertNull( queryCollection.getCursor() );
+        assertEquals( 5, queryCollection.getResponse().getEntities().size() );
+
+        for(int i = 15;i<maxSize;i++){
+            Entity correctEntity = entityPayloadVerifier.get( i );
+            Entity returnedEntity = queryCollection.next();
+            assertEquals( correctEntity.get( "name" ), returnedEntity.get( "name" ) );
+            assertEquals( correctEntity.get( "verb" ), returnedEntity.get( "verb" ) );
+
+        }
+    }
 }
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/56e3c323/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingResourceIT.java
index 50f5f58..4052c2f 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingResourceIT.java
@@ -17,285 +17,246 @@
 package org.apache.usergrid.rest.applications.collection.paging;
 
 
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.util.HashMap;
 import java.util.Map;
-import java.util.UUID;
-import javax.ws.rs.core.MediaType;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.usergrid.cassandra.Concurrent;
-import org.apache.usergrid.java.client.entities.Entity;
-import org.apache.usergrid.java.client.response.ApiResponse;
-import org.apache.usergrid.rest.AbstractRestIT;
-import org.apache.usergrid.rest.TestContextSetup;
-import org.apache.usergrid.rest.test.resource.CustomCollection;
-import org.apache.usergrid.rest.test.resource.EntityResource;
-import static org.apache.usergrid.utils.MapUtils.hashMap;
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.Collection;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.rest.test.resource2point0.model.QueryParameters;
+
 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;
-import org.junit.Rule;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
-/** Simple tests to test querying at the REST tier */
+/**
+ * Checks about different aspects of using a cursor combined with a query.
+ */
 @Concurrent()
 public class PagingResourceIT extends AbstractRestIT {
 
     private static final Logger logger = LoggerFactory.getLogger( PagingResourceIT.class
);
 
-    @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 );
-    }
-
-
+    /**
+     * Creates 40 objects and then retrieves all 40 by paging through sets of 10 with a cursor.
+     * @throws Exception
+     */
     @Test
     public void collectionPaging() throws Exception {
 
-        CustomCollection things = context.application().customCollection( "test1things" );
-
-        int size = 40;
-
-        List<Map<String, String>> created = new ArrayList<Map<String, String>>(
size );
-
-        for ( int i = 0; i < size; i++ ) {
-            Map<String, String> entity = hashMap( "name", String.valueOf( i ) );
-            things.create( entity );
-
-            created.add( entity );
-        }
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        // now page them all
-        ApiResponse response = null;
-        Iterator<Map<String, String>> entityItr = created.iterator();
-
-        do {
-
-            response = parse( things.get() );
-
-            for ( Entity e : response.getEntities() ) {
-                assertTrue( entityItr.hasNext() );
-                assertEquals( entityItr.next().get( "name" ), e.getProperties().get( "name"
).asText() );
-                logger.debug("Got item value {}", e.getProperties().get( "name" ).asText());
-            }
-
-            logger.debug("response cursor: " + response.getCursor() );
-            
-            things = things.withCursor( response.getCursor() );
-        }
-        while ( response != null && response.getCursor() != null );
-
-        assertFalse("Should have paged them all", entityItr.hasNext() );
-    }
-
-
-    @Test
-    @Ignore("ignored because currently startPaging is only be supported for queues and not
for  "
-            + "generic collections as this test assumes. "
-            + "see also: https://issues.apache.org/jira/browse/USERGRID-211 ")
-    public void startPaging() throws Exception {
-
-        CustomCollection things = context.application().customCollection( "test2things" );
+        String collectionName = "testCollectionPaging" + UUIDUtils.newTimeUUID();
 
         int size = 40;
 
-        List<Map<String, String>> created = new ArrayList<Map<String, String>>(
size );
-
+        //Creates 40 entities by posting to collection
         for ( int i = 0; i < size; i++ ) {
-            Map<String, String> entity = hashMap( "name", String.valueOf( i ) );
-            things.create( entity );
+            Map<String, Object> entityPayload = new HashMap<String, Object>();
+            entityPayload.put( "name", String.valueOf( i ) );
+            Entity entity = new Entity( entityPayload );
 
-            created.add( entity );
+            this.app().collection( collectionName ).post( entity );
         }
 
-        refreshIndex(context.getOrgName(), context.getAppName());
+        this.refreshIndex();
 
-        // now page them all
-        ApiResponse response = null;
+        Collection testCollections = this.app().collection( collectionName ).get();
 
-        UUID start = null;
+        //checks to make sure we can page through all entities in order.
         int index = 0;
-
-        do {
-
-            response = parse( things.get() );
-
-            for ( Entity e : response.getEntities() ) {
-                logger.debug("Getting item {} value {}", index, e.getProperties().get( "name"
).asText());
-                assertEquals( created.get( index ).get( "name" ), e.getProperties().get(
"name" ).asText() );
-                index++;
+        for ( int i = 0; i < 4; i++ ) {
+            while ( testCollections.hasNext() ) {
+                Entity returnedEntity = testCollections.next();
+                assertEquals( String.valueOf( index++ ), returnedEntity.get( "name" ) );
             }
-
-            // decrement since we'll get this one again
-            index--;
-
-            start = response.getEntities().get( response.getEntities().size() - 1 ).getUuid();
-
-            things = things.withStart( start );
+            testCollections = this.app().collection( collectionName ).getNextPage( testCollections,
true );
         }
-        while ( response != null && response.getEntities().size() > 1 );
-
-        // we paged them all
-        assertEquals( created.size() - 1, index );
+        //make sure the cursor is null after we have no more entities to page through.
+        assertNull( testCollections.getCursor() );
     }
 
-
+    //
+    //    @Test
+    //    @Ignore("ignored because currently startPaging is only be supported for queues
and not for  "
+    //            + "generic collections as this test assumes. "
+    //            + "see also: https://issues.apache.org/jira/browse/USERGRID-211 ")
+    //    public void startPaging() throws Exception {
+    //
+    //        CustomCollection things = context.application().customCollection( "test2things"
);
+    //
+    //        int size = 40;
+    //
+    //        List<Map<String, String>> created = new ArrayList<Map<String,
String>>( size );
+    //
+    //        for ( int i = 0; i < size; i++ ) {
+    //            Map<String, String> entity = hashMap( "name", String.valueOf( i )
);
+    //            things.create( entity );
+    //
+    //            created.add( entity );
+    //        }
+    //
+    //        refreshIndex(context.getOrgName(), context.getAppName());
+    //
+    //        // now page them all
+    //        ApiResponse response = null;
+    //
+    //        UUID start = null;
+    //        int index = 0;
+    //
+    //        do {
+    //
+    //            response = parse( things.get() );
+    //
+    //            for ( Entity e : response.getEntities() ) {
+    //                logger.debug("Getting item {} value {}", index, e.getProperties().get(
"name" ).asText());
+    //                assertEquals( created.get( index ).get( "name" ), e.getProperties().get(
"name" ).asText() );
+    //                index++;
+    //            }
+    //
+    //            // decrement since we'll get this one again
+    //            index--;
+    //
+    //            start = response.getEntities().get( response.getEntities().size() - 1 ).getUuid();
+    //
+    //            things = things.withStart( start );
+    //        }
+    //        while ( response != null && response.getEntities().size() > 1 );
+    //
+    //        // we paged them all
+    //        assertEquals( created.size() - 1, index );
+    //    }
+
+
+    /**
+     * Creates 40 objects and then creates a query to delete sets of 10 entities per call.
Checks at the end
+     * to make sure there are no entities remaining.
+     * @throws Exception
+     */
     @Test
     public void collectionBatchDeleting() throws Exception {
 
-        CustomCollection things = context.application().customCollection( "test3things" );
 
-        int size = 40;
-
-        List<Map<String, String>> created = new ArrayList<Map<String, String>>(
size );
+        String collectionName = "testCollectionBatchDeleting" + UUIDUtils.newTimeUUID();
 
+        //Creates 40 entities by posting to collection
+        int size = 40;
         for ( int i = 0; i < size; i++ ) {
-            Map<String, String> entity = hashMap( "name", String.valueOf( i ) );
-            things.create( entity );
+            Map<String, Object> entityPayload = new HashMap<String, Object>();
+            entityPayload.put( "name", String.valueOf( i ) );
+            Entity entity = new Entity( entityPayload );
 
-            created.add( entity );
+            this.app().collection( collectionName ).post( entity );
         }
 
-        refreshIndex(context.getOrgName(), context.getAppName());
+        this.refreshIndex();
 
-        ApiResponse response;
+        //sets the number of entities we want to delete per call.
         int deletePageSize = 10;
+        QueryParameters queryParameters = new QueryParameters();
+        queryParameters.setLimit( deletePageSize );
 
-        things = things.withLimit( deletePageSize );
-
+        //deletes the entities using the above set value. Then verifies that those entities
were deleted.
         for ( int i = 0; i < size / deletePageSize; i++ ) {
-            response = parse( things.delete() );
 
-            refreshIndex(context.getOrgName(), context.getAppName());
+            ApiResponse response = this.app().collection( collectionName ).delete( queryParameters
);
+
+            this.refreshIndex();
 
             assertEquals( "Only 10 entities should have been deleted", 10, response.getEntityCount()
);
         }
 
-        response = parse( things.get() );
-
-        assertEquals( "All entities should have been removed", 0, response.getEntityCount()
);
-
-        //now do 1 more delete, we should get any results
+        //verifies that we can't get anymore entities from the collection
+        Collection getCollection = this.app().collection( collectionName ).get();
 
-        response = parse( things.delete() );
+        assertEquals( "All entities should have been removed", 0, getCollection.getResponse().getEntityCount()
);
 
+        //now do 1 more delete, we shouldn't get any results
+        ApiResponse response = this.app().collection( collectionName ).delete( queryParameters
);
         assertEquals( "No more entities deleted", 0, response.getEntityCount() );
     }
 
 
+    /**
+     * Checks to make sure we can get an entity despite having a empty query, and limit parameter
+     * @throws Exception
+     */
     @Test
     public void emptyQlandLimitIgnored() throws Exception {
 
-        CustomCollection things = context.application().customCollection( "test4things" );
+        String collectionName = "testEmptyQAndLimitIgnored" + UUIDUtils.newTimeUUID();
 
-        Map<String, String> data = hashMap( "name", "thing1" );
-        JsonNode response = things.create( data );
 
-        refreshIndex(context.getOrgName(), context.getAppName());
+        Map<String, Object> entityPayload = new HashMap<String, Object>();
+        entityPayload.put( "name", "thing1" );
+        Entity entity = new Entity( entityPayload );
 
-        JsonNode entity = getEntity( response, 0 );
+        this.app().collection( collectionName ).post( entity );
 
-        String uuid = entity.get( "uuid" ).asText();
+        this.refreshIndex();
 
-        EntityResource entityRequest = things.entity( "thing1" ).withParam( "ql", "" ).withParam(
"limit", "" );
+        //passes in empty parameters
+        QueryParameters parameters = new QueryParameters();
+        parameters.setKeyValue( "ql", "" );
+        parameters.setKeyValue( "limit", "" );
 
-        JsonNode returnedEntity = getEntity( entityRequest.get(), 0 );
+        //make get using empty parameters
+        Entity testEntity = this.app().collection( collectionName ).uniqueID( ( String )
entity.get( "name" ) )
+                                .get( parameters, true );
 
-        assertEquals( entity, returnedEntity );
-
-        entityRequest = things.entity( uuid ).withParam( "ql", "" ).withParam( "limit", ""
);
-
-        returnedEntity = getEntity( entityRequest.get(), 0 );
-
-        assertEquals( entity, returnedEntity );
-
-        // now do a delete
-        returnedEntity = getEntity( entityRequest.delete(), 0 );
-
-        assertEquals( entity, returnedEntity );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        // verify it's gone
-        returnedEntity = getEntity( things.entity( uuid ).get(), 0 );
-
-        assertNull( returnedEntity );
+        assertEquals( entity.get( "name" ), testEntity.get( "name" ) );
     }
 
 
+    /**
+     * Checks to make sure we get a cursor when we should ( by creating 50 entities ) and
then checks to make sure
+     * we do not get a cursor when we create a collection of only 5 entities.
+     * @throws Exception
+     */
     @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().customCollection( "widgets" );
-        for (int i = 0; i < widgetsSize; i++) {
-            Map<String, String> entity = hashMap("name", String.valueOf(i));
-            widgets.create(entity);
+        // create enough widgets to make sure we need a cursor
+        int widgetsSize = 11;
+        Map<String, Object> entityPayload = new HashMap<String, Object>();
+        String collectionName = "testCursor" + UUIDUtils.newTimeUUID();
+
+        for ( int i = 0; i < widgetsSize; i++ ) {
+
+            entityPayload.put( "name", "value" + i );
+            Entity entity = new Entity( entityPayload );
+            this.app().collection( collectionName ).post( 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
+
+        this.refreshIndex();
+
+        //checks to make sure we have a cursor
+        Collection testCollection = this.app().collection( collectionName ).get();
+        assertNotNull( testCollection.getCursor() );
+        assertEquals( 10, testCollection.getResponse().getEntityCount() );
+
+        //Create new collection of only 5 entities
+        String trinketCollectionName = "trinkets" + UUIDUtils.newTimeUUID();
         int trinketsSize = 5;
-        CustomCollection trinkets = context.application().customCollection( "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
-    }
+        for ( int i = 0; i < trinketsSize; i++ ) {
 
+            entityPayload.put( "name", "value" + i );
+            Entity entity = new Entity( entityPayload );
+            this.app().collection( trinketCollectionName ).post( entity );
+        }
 
-//    @Test
-//    public void testPagingWithUpdates() throws IOException {
-//
-//        // create 500 widgets
-//        int widgetsSize = 500;
-//        List<String> widgetIds = new ArrayList<String>();
-//        CustomCollection widgets = context.application().collection("widgets");
-//        for (int i = 0; i < widgetsSize; i++) {
-//            Map<String, String> entity = hashMap("name", String.valueOf(i));
-//            JsonNode widgetNode = widgets.create(entity);
-//            logger.info("widgetNode: " + widgetNode.toString());
-//        }
-//
-//        refreshIndex(context.getOrgName(), context.getAppName());
-//    }
+        this.refreshIndex();
 
+        //checks to make sure we don't get a cursor for just 5 entities.
+        testCollection = this.app().collection( trinketCollectionName ).get();
+        assertNull( testCollection.getCursor() );
+        assertEquals( 5, testCollection.getResponse().getEntityCount() );
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/56e3c323/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
index e573a70..6f7c0e6 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
@@ -150,7 +150,7 @@ public class CollectionEndpoint extends NamedResource {
 
     public ApiResponse delete(final QueryParameters parameters, final boolean useToken){
         WebResource resource  = getResource(useToken);
-        addParametersToResource(getResource(), parameters);
+        resource = addParametersToResource(resource, parameters);
         return resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
                 .delete(ApiResponse.class);
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/56e3c323/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/EntityEndpoint.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/EntityEndpoint.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/EntityEndpoint.java
index 4ed8fa2..799e57f 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/EntityEndpoint.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/EntityEndpoint.java
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.sun.jersey.api.client.WebResource;
 import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
 import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.rest.test.resource2point0.model.QueryParameters;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 
 import javax.ws.rs.core.MediaType;
@@ -63,6 +64,16 @@ public class EntityEndpoint extends NamedResource {
         return new Entity(response);
     }
 
+    //For testing purposes only
+    public Entity get(QueryParameters parameters, final boolean useToken){
+        WebResource resource  = getResource(useToken);
+        resource = addParametersToResource(resource, parameters);
+        ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+                                       .get(ApiResponse.class);
+
+        return new Entity(response);
+    }
+
 
     /**
      * DELETE a single entity

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/56e3c323/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Collection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Collection.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Collection.java
index 826d3fe..6b12097 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Collection.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Collection.java
@@ -33,9 +33,9 @@ public class Collection implements Iterable<Entity>, Iterator<Entity>
{
 
     private String cursor;
 
-    public Iterator entities;
+    private Iterator entities;
 
-    public ApiResponse response;
+    private ApiResponse response;
 
 
     /**
@@ -58,6 +58,9 @@ public class Collection implements Iterable<Entity>, Iterator<Entity>
{
         entities = response.getEntities().iterator();
     }
 
+    public ApiResponse getResponse(){
+        return response;
+    }
 
     @Override
     public Iterator iterator() {
@@ -84,7 +87,5 @@ public class Collection implements Iterable<Entity>, Iterator<Entity>
{
     public void remove() {
         throw new UnsupportedOperationException( "Remove is unsupported" );
     }
-
-
 }
 


Mime
View raw message