You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/01/22 16:48:22 UTC

[04/19] incubator-usergrid git commit: [USERGRID-320] Additional tests and comments

[USERGRID-320] Additional tests and comments


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 4efd58bd7bb2df8fcaed3d3c4891fc3230b5a111
Parents: b07d52d
Author: ryan bridges <rb...@apigee.com>
Authored: Mon Jan 12 11:31:16 2015 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Mon Jan 12 11:31:16 2015 -0500

----------------------------------------------------------------------
 .../applications/queries/AndOrQueryTest.java    |  65 +---
 .../queries/BadGrammarQueryTest.java            | 213 +++++++++--
 .../rest/applications/queries/OrderByTest.java  | 367 +++++++++----------
 3 files changed, 361 insertions(+), 284 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4efd58bd/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/AndOrQueryTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/AndOrQueryTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/AndOrQueryTest.java
index d67e62a..6cd21da 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/AndOrQueryTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/AndOrQueryTest.java
@@ -17,7 +17,6 @@
 package org.apache.usergrid.rest.applications.queries;
 
 
-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.usergrid.rest.test.resource2point0.model.QueryParameters;
@@ -37,50 +36,9 @@ import static org.junit.Assert.*;
  * @author ApigeeCorporation
  * @since 4.0
  */
-public class AndOrQueryTest extends AbstractRestIT {
+public class AndOrQueryTest extends QueryTestBase {
     private static Logger log = LoggerFactory.getLogger(AndOrQueryTest.class);
 
-    /**
-     * Create a number of entities in the specified collection
-     * with properties to make them independently searchable
-     *
-     * @param numberOfEntities
-     * @param collectionName
-     * @return an array of the Entity objects created
-     */
-    private Entity[] generateTestEntities(int numberOfEntities, String collectionName) {
-        Entity[] entities = new Entity[numberOfEntities];
-        Entity props = new Entity();
-        //Insert the desired number of entities
-        for (int i = 0; i < numberOfEntities; i++) {
-            Entity actor = new Entity();
-            actor.put("displayName", String.format("Test User %d", i));
-            actor.put("username", String.format("user%d", i));
-            props.put("actor", actor);
-            //give each entity a unique, numeric ordinal value
-            props.put("ordinal", i);
-            //Set half the entities to have a 'madeup' property of 'true'
-            // and set the other half to 'false'
-            if (i < numberOfEntities / 2) {
-                props.put("madeup", false);
-            } else {
-                props.put("madeup", true);
-            }
-            //Set even-numbered users to have a verb of 'go' and the rest to 'stop'
-            if (i % 2 == 0) {
-                props.put("verb", "go");
-            } else {
-                props.put("verb", "stop");
-            }
-            //create the entity in the desired collection and add it to the return array
-            entities[i] = this.app().collection(collectionName).post(props);
-            log.info(entities[i].entrySet().toString());
-        }
-        //refresh the index so that they are immediately searchable
-        this.refreshIndex();
-
-        return entities;
-    }
 
     /**
      * Test an inclusive AND query to ensure the correct results are returned
@@ -92,7 +50,7 @@ public class AndOrQueryTest extends AbstractRestIT {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
         //Query where madeup = true (the last half) and the last quarter of entries
         QueryParameters params = new QueryParameters()
             .setQuery("select * where madeup = true AND ordinal >= " + (numOfEntities - numOfEntities / 4));
@@ -120,7 +78,7 @@ public class AndOrQueryTest extends AbstractRestIT {
         int numOfEntities = 20;
         String collectionName = "activities";
 
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         //Query where madeup = true (the last half) and NOT the last quarter of entries
         QueryParameters params = new QueryParameters()
@@ -148,7 +106,7 @@ public class AndOrQueryTest extends AbstractRestIT {
         int numOfEntities = 20;
         String collectionName = "activities";
 
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         //Query where madeup = false (the first half) or the last quarter of entries
         QueryParameters params = new QueryParameters()
@@ -184,7 +142,7 @@ public class AndOrQueryTest extends AbstractRestIT {
         int numOfEntities = 30;
         String collectionName = "activities";
 
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         //Query where the verb = 'go' (half) OR the last quarter by ordinal, but NOT where verb = 'go' AND the ordinal is in the last quarter
         QueryParameters params = new QueryParameters()
@@ -221,9 +179,8 @@ public class AndOrQueryTest extends AbstractRestIT {
     @Test //USERGRID-900
     public void queriesWithAndPastLimit() throws IOException {
         int numValuesTested = 40;
-        long created = 0;
 
-        Entity[] entities = generateTestEntities(numValuesTested, "activities");
+        generateTestEntities(numValuesTested, "activities");
         //3. Query all entities where "madeup = true"
         String errorQuery = "select * where madeup = true";
         QueryParameters params = new QueryParameters()
@@ -250,7 +207,7 @@ public class AndOrQueryTest extends AbstractRestIT {
     public void negatedQuery() throws IOException {
         int numValuesTested = 20;
 
-        Entity[] entities = generateTestEntities(numValuesTested, "activities");
+        generateTestEntities(numValuesTested, "activities");
         //1. Query all entities where "NOT verb = 'go'"
         String query = "select * where not verb = 'go'";
         //2. Limit the query to half of the number of entities
@@ -276,7 +233,7 @@ public class AndOrQueryTest extends AbstractRestIT {
     public void queryReturnCount() throws Exception {
         int numValuesTested = 20;
 
-        Entity[] entities = generateTestEntities(numValuesTested, "activities");
+        generateTestEntities(numValuesTested, "activities");
         //1. Query for a subset of the entities
         String inCorrectQuery = "select * where ordinal >= " + (numValuesTested / 2) + " order by ordinal asc";
         QueryParameters params = new QueryParameters().setQuery(inCorrectQuery).setLimit(numValuesTested / 2);
@@ -303,7 +260,7 @@ public class AndOrQueryTest extends AbstractRestIT {
         int numOfEntities = 20;
         String collectionName = "imagination";
 
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         //2. Use AND/OR query to retrieve entities
         String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte  " + (numOfEntities / 2)
@@ -332,7 +289,7 @@ public class AndOrQueryTest extends AbstractRestIT {
         int numOfEntities = 20;
         String collectionName = "imagination";
 
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         //2. Issue a query
         String inquisitiveQuery = String.format("select * where ordinal >= 0 and ordinal <= %d or WhoHelpedYou = 'Ruff'", numOfEntities);
@@ -359,7 +316,7 @@ public class AndOrQueryTest extends AbstractRestIT {
         int numOfEntities = 10;
         String collectionName = "imagination";
 
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         //2. Issue a query using alphanumeric operators
         String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte 2000 or WhoHelpedYou eq 'Ruff'";

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4efd58bd/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/BadGrammarQueryTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/BadGrammarQueryTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/BadGrammarQueryTest.java
index 00b90dc..12da417 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/BadGrammarQueryTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/BadGrammarQueryTest.java
@@ -18,7 +18,7 @@ package org.apache.usergrid.rest.applications.queries;
 
 
 import com.sun.jersey.api.client.UniformInterfaceException;
-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.usergrid.rest.test.resource2point0.model.QueryParameters;
 import org.junit.Test;
@@ -30,36 +30,187 @@ import static org.junit.Assert.fail;
 
 
 /**
- * Test for an exception with incorrect query grammar
- * 1. Insert an entity
- * 2. Issue an invalid query
- * 3. Check for an exception
+ * Test for exceptions resulting from invalid query syntax
  */
-public class BadGrammarQueryTest extends AbstractRestIT {
-
-  @Test
-  public void catchBadQueryGrammar() throws IOException {
-
-    //1. Insert an entity
-    Entity actor = new Entity();
-    actor.put("displayName", "Erin");
-    Entity props = new Entity();
-    props.put("actor", actor);
-    props.put("content", "bragh");
-
-    this.app().collection("things").post(props);
-    refreshIndex();
-
-    //2. Issue an invalid query
-    String query = "select * where name != 'go'";
-    try {
-
-      QueryParameters params = new QueryParameters().setQuery(query);
-      this.app().collection("things").get(params);
-      fail("This should throw an exception");
-    } catch (UniformInterfaceException uie) {
-      //3. Check for an exception
-      assertEquals(400, uie.getResponse().getStatus());
+public class BadGrammarQueryTest extends QueryTestBase {
+
+    /**
+     * We should get an exception if the clause contains
+     * an invalid operator.
+     * (eg. "name != 'go'" instead of "NOT name = 'go'")
+     * @throws IOException
+     */
+    @Test
+    public void catchBadQueryGrammar() throws IOException {
+
+        int numOfEntities = 1;
+        String collectionName = "things";
+        //create our test entities
+        generateTestEntities(numOfEntities, collectionName);
+
+        //Issue an invalid query
+        String query = "select * where name != 'go'";
+        try {
+
+            QueryParameters params = new QueryParameters().setQuery(query);
+            this.app().collection(collectionName).get(params);
+            fail("This should throw an exception");
+        } catch (UniformInterfaceException uie) {
+            //Check for an exception
+            assertEquals(400, uie.getResponse().getStatus());
+        }
+    }
+
+    /**
+     * We should get an exception if the clause contains
+     * a string that is surrounded by double-quotes
+     * @throws IOException
+     */
+    @Test
+    public void exceptionOnDoubleQuotes() throws IOException {
+
+        int numOfEntities = 1;
+        String collectionName = "things";
+        //create our test entities
+        generateTestEntities(numOfEntities, collectionName);
+
+        //Issue an invalid query
+        String query = "select * where name != \"go\"";
+        try {
+
+            QueryParameters params = new QueryParameters().setQuery(query);
+            this.app().collection(collectionName).get(params);
+            fail("This should throw an exception");
+        } catch (UniformInterfaceException uie) {
+            //Check for an exception
+            assertEquals(400, uie.getResponse().getStatus());
+        }
     }
-  }
+
+    /**
+     * We should get an exception if the clause contains
+     * a string that is not properly quoted
+     * @throws IOException
+     */
+    @Test
+    public void exceptionOnMissingQuotes() throws IOException {
+
+        int numOfEntities = 1;
+        String collectionName = "things";
+        //create our test entities
+        generateTestEntities(numOfEntities, collectionName);
+
+        //Issue an invalid query
+        String query = "select * where name != go";
+        try {
+
+            QueryParameters params = new QueryParameters().setQuery(query);
+            this.app().collection(collectionName).get(params);
+            fail("This should throw an exception");
+        } catch (UniformInterfaceException uie) {
+            //Check for an exception
+            assertEquals(400, uie.getResponse().getStatus());
+        }
+    }
+    /**
+     * We should get an exception if the property name
+     * is missing from the clause
+     * @throws IOException
+     */
+
+    @Test
+    public void exceptionOnMissingProperty() throws IOException {
+
+        int numOfEntities = 1;
+        String collectionName = "things";
+        //create our test entities
+        generateTestEntities(numOfEntities, collectionName);
+
+        //Issue an invalid query
+        String query = "select * where != 'go'";
+        try {
+
+            QueryParameters params = new QueryParameters().setQuery(query);
+            this.app().collection(collectionName).get(params);
+            fail("This should throw an exception");
+        } catch (UniformInterfaceException uie) {
+            //Check for an exception
+            assertEquals(400, uie.getResponse().getStatus());
+        }
+    }
+    /**
+     * We should get an exception if the property value
+     * is missing from the clause
+     * @throws IOException
+     */
+
+    @Test
+    public void exceptionOnMissingPropertyValue() throws IOException {
+
+        int numOfEntities = 1;
+        String collectionName = "things";
+        //create our test entities
+        generateTestEntities(numOfEntities, collectionName);
+
+        //Issue an invalid query
+        String query = "select * where name != ";
+        try {
+
+            QueryParameters params = new QueryParameters().setQuery(query);
+            this.app().collection(collectionName).get(params);
+            fail("This should throw an exception");
+        } catch (UniformInterfaceException uie) {
+            //Check for an exception
+            assertEquals(400, uie.getResponse().getStatus());
+        }
+    }
+
+    /**
+     * We should get an exception if the operator is missing
+     * from the clause
+     * @throws IOException
+     */
+    @Test
+    public void exceptionOnMissingOperator() throws IOException {
+
+        int numOfEntities = 1;
+        String collectionName = "things";
+        //create our test entities
+        generateTestEntities(numOfEntities, collectionName);
+
+        //Issue an invalid query
+        String query = "select * where name 'go' ";
+        try {
+
+            QueryParameters params = new QueryParameters().setQuery(query);
+            this.app().collection(collectionName).get(params);
+            fail("This should throw an exception");
+        } catch (UniformInterfaceException uie) {
+            //Check for an exception
+            assertEquals(400, uie.getResponse().getStatus());
+        }
+    }
+
+    /**
+     * Limit should be sent separately from the query,
+     * else the query will return only entities with
+     * a property named 'limit'
+     * @throws IOException
+     */
+    @Test
+    public void limitInQuery() throws IOException {
+
+        int numOfEntities =1;
+        String collectionName = "things";
+        //create our test entities
+        generateTestEntities(numOfEntities, collectionName);
+
+
+        //Issue an invalid query
+        String query = "select * where limit = 5";
+        QueryParameters params = new QueryParameters().setQuery(query);
+        Collection collection = this.app().collection(collectionName).get(params);
+        assertEquals(0, collection.getNumOfEntities());
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4efd58bd/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/OrderByTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/OrderByTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/OrderByTest.java
index 9acee8d..a30168a 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/OrderByTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/OrderByTest.java
@@ -18,7 +18,6 @@ package org.apache.usergrid.rest.applications.queries;
 
 
 import org.apache.commons.lang.ArrayUtils;
-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.usergrid.rest.test.resource2point0.model.QueryParameters;
@@ -27,11 +26,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
-import java.util.LinkedHashMap;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
 
 
 /**
@@ -40,60 +36,20 @@ import static org.junit.Assert.assertTrue;
  * @author ApigeeCorporation
  * @since 4.0
  */
-public class OrderByTest extends AbstractRestIT {
-  private static Logger log = LoggerFactory.getLogger(OrderByTest.class);
-    /**
-     * Create a number of entities in the specified collection
-     * with properties to make them independently searchable
-     *
-     * @param numberOfEntities
-     * @param collectionName
-     * @return an array of the Entity objects created
-     */
-    private Entity[] generateTestEntities(int numberOfEntities, String collectionName) {
-        Entity[] entities = new Entity[numberOfEntities];
-        Entity props = new Entity();
-        //Insert the desired number of entities
-        for (int i = 0; i < numberOfEntities; i++) {
-            Entity actor = new Entity();
-            actor.put("displayName", String.format("Test User %d", i));
-            actor.put("username", String.format("user%d", i));
-            props.put("actor", actor);
-            //give each entity a unique, numeric ordinal value
-            props.put("ordinal", i);
-            //Set half the entities to have a 'madeup' property of 'true'
-            // and set the other half to 'false'
-            if (i < numberOfEntities / 2) {
-                props.put("madeup", false);
-            } else {
-                props.put("madeup", true);
-            }
-            //Set even-numbered users to have a verb of 'go' and the rest to 'stop'
-            if (i % 2 == 0) {
-                props.put("verb", "go");
-            } else {
-                props.put("verb", "stop");
-            }
-            //create the entity in the desired collection and add it to the return array
-            entities[i] = this.app().collection(collectionName).post(props);
-            log.info(entities[i].entrySet().toString());
-        }
-        //refresh the index so that they are immediately searchable
-        this.refreshIndex();
-
-        return entities;
-    }
+public class OrderByTest extends QueryTestBase {
+    private static Logger log = LoggerFactory.getLogger(OrderByTest.class);
 
     /**
      * Test correct sort order for Long properties
+     *
      * @throws IOException
      */
     @Test
-    public void testSortLongAsc() throws IOException{
+    public void testSortLongAsc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         QueryParameters params = new QueryParameters()
             .setQuery("select * order by ordinal asc")
@@ -108,23 +64,25 @@ public class OrderByTest extends AbstractRestIT {
             assertEquals(index++, Long.parseLong(activity.get("ordinal").toString()));
         }
     }
+
     /**
      * Test correct sort order for Long properties
+     *
      * @throws IOException
      */
     @Test
-    public void testSortLongDesc() throws IOException{
+    public void testSortLongDesc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         QueryParameters params = new QueryParameters()
             .setQuery("select * order by ordinal desc")
             .setLimit(numOfEntities);
         Collection activities = this.app().collection("activities").get(params);
         assertEquals(numOfEntities, activities.getResponse().getEntityCount());
-        int index = numOfEntities-1;
+        int index = numOfEntities - 1;
         //results should be sorted by ordinal
         while (activities.hasNext()) {
             Entity activity = activities.next();
@@ -132,16 +90,18 @@ public class OrderByTest extends AbstractRestIT {
             assertEquals(index--, Long.parseLong(activity.get("ordinal").toString()));
         }
     }
+
     /**
      * Test correct sort order for Boolean properties
+     *
      * @throws IOException
      */
     @Test
-    public void testSortBooleanAsc() throws IOException{
+    public void testSortBooleanAsc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         QueryParameters params = new QueryParameters()
             .setQuery("select * order by madeup asc")
@@ -152,23 +112,25 @@ public class OrderByTest extends AbstractRestIT {
         //results should be sorted false, then true
         while (activities.hasNext()) {
             Entity activity = activities.next();
-            if(index++ < numOfEntities/2){
+            if (index++ < numOfEntities / 2) {
                 assertEquals("false", activity.get("madeup").toString());
-            }else{
+            } else {
                 assertEquals("true", activity.get("madeup").toString());
             }
         }
     }
+
     /**
      * Test correct sort order for Boolean properties
+     *
      * @throws IOException
      */
     @Test
-    public void testSortBooleanDesc() throws IOException{
+    public void testSortBooleanDesc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         QueryParameters params = new QueryParameters()
             .setQuery("select * order by madeup desc")
@@ -180,9 +142,9 @@ public class OrderByTest extends AbstractRestIT {
         while (activities.hasNext()) {
             Entity activity = activities.next();
             //make sure the booleans are ordered correctly
-            if(index++ < numOfEntities/2){
+            if (index++ < numOfEntities / 2) {
                 assertEquals("true", activity.get("madeup").toString());
-            }else{
+            } else {
                 assertEquals("false", activity.get("madeup").toString());
             }
         }
@@ -190,14 +152,15 @@ public class OrderByTest extends AbstractRestIT {
 
     /**
      * Test correct sort order for String properties
+     *
      * @throws IOException
      */
     @Test
-    public void testSortStringAsc() throws IOException{
+    public void testSortStringAsc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         QueryParameters params = new QueryParameters()
             .setQuery("select * order by verb asc")
@@ -208,23 +171,25 @@ public class OrderByTest extends AbstractRestIT {
         //results should be sorted "go", then "stop"
         while (activities.hasNext()) {
             Entity activity = activities.next();
-            if(index++ < numOfEntities/2){
+            if (index++ < numOfEntities / 2) {
                 assertEquals("go", activity.get("verb").toString());
-            }else{
+            } else {
                 assertEquals("stop", activity.get("verb").toString());
             }
         }
     }
+
     /**
      * Test correct sort order for String properties
+     *
      * @throws IOException
      */
     @Test
-    public void testSortStringDesc() throws IOException{
+    public void testSortStringDesc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
-        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+        generateTestEntities(numOfEntities, collectionName);
 
         QueryParameters params = new QueryParameters()
             .setQuery("select * order by verb desc")
@@ -235,149 +200,153 @@ public class OrderByTest extends AbstractRestIT {
         //results should be sorted "stop", then "go"
         while (activities.hasNext()) {
             Entity activity = activities.next();
-            if(index++ < numOfEntities/2){
+            if (index++ < numOfEntities / 2) {
                 assertEquals("stop", activity.get("verb").toString());
-            }else{
+            } else {
                 assertEquals("go", activity.get("verb").toString());
             }
         }
 
     }
-  /**
-   * Inserts a number of entities. Query a subset of entities
-   * with unspecified 'order by' and then ordered by 'created'
-   * to ensure the result is unchanged.
-   * 1. Insert entities
-   * 2. Query without 'order by'
-   * 3. Query with 'order by'
-   * 4. Ensure the same entities are returned
-   * @throws IOException
-   */
-  @Test
-  // USERGRID-1400
-  public void orderByShouldNotAffectResults() throws IOException {
-
-    long created = 0;
-    Entity actor = new Entity();
-    actor.put("displayName", "Erin");
-    Entity props = new Entity();
-    props.put("actor", actor);
-    props.put("verb", "go");
-    props.put("content", "bragh");
-    //1. Insert entities
-    for (int i = 0; i < 20; i++) {
-      props.put("ordinal", i);
-      Entity activity = this.app().collection("activity").post(props);
-      log.info("Created", activity.get("created").toString());
-      if (i == 5) {
-        created = Long.parseLong(activity.get("created").toString());
-      }
-    }
 
-    refreshIndex();
-    //2. Query without 'order by'
-    String query = "select * where created > " + created;
-    QueryParameters params = new QueryParameters().setQuery(query);
-    Collection activitiesWithoutOrderBy = this.app().collection("activities").get(params);
-    assertEquals(10, activitiesWithoutOrderBy.getResponse().getEntityCount());
-    //3. Query with 'order by'
-    query = query + " order by created desc";
-    params.setQuery(query);
-    Collection activitiesWithOrderBy = this.app().collection("activities").get(params);
-    assertEquals(10, activitiesWithOrderBy.getResponse().getEntityCount());
-    //4. Ensure the same entities are returned
-    while(activitiesWithoutOrderBy.hasNext() && activitiesWithOrderBy.hasNext()) {
-      Entity activityWithoutOrderBy = activitiesWithoutOrderBy.next();
-      Entity activityWithOrderBy = activitiesWithOrderBy.next();
-      assertEquals(activityWithoutOrderBy.get("uuid").toString(), activityWithOrderBy.get("uuid").toString());
-    }
-  }
-
-
-  /**
-   * Ensure successful query when 'limit' and 'order by' are specified
-   * 1. Insert entities
-   * 2. Query a subset of the entities, specifying order and limit
-   * 3. Ensure the correct number of results are returned
-   * @throws IOException
-   */
-  @Test
-  // USERGRID-1520
-  public void orderByComesBeforeLimitResult() throws IOException {
-
-    Entity actor = new Entity();
-    actor.put("displayName", "Erin");
-    Entity props = new Entity();
-    props.put("actor", actor);
-    props.put("verb", "go");
-    props.put("content", "bragh");
-    //1. Insert entities
-    for (int i = 0; i < 20; i++) {
-      props.put("ordinal", i);
-      this.app().collection("activity").post(props);
+    /**
+     * Inserts a number of entities. Query a subset of entities
+     * with unspecified 'order by' and then ordered by 'created'
+     * to ensure the result is unchanged.
+     * 1. Insert entities
+     * 2. Query without 'order by'
+     * 3. Query with 'order by'
+     * 4. Ensure the same entities are returned
+     *
+     * @throws IOException
+     */
+    @Test
+    // USERGRID-1400
+    public void orderByShouldNotAffectResults() throws IOException {
+
+        long created = 0;
+        Entity actor = new Entity();
+        actor.put("displayName", "Erin");
+        Entity props = new Entity();
+        props.put("actor", actor);
+        props.put("verb", "go");
+        props.put("content", "bragh");
+        //1. Insert entities
+        for (int i = 0; i < 20; i++) {
+            props.put("ordinal", i);
+            Entity activity = this.app().collection("activity").post(props);
+            log.info("Created", activity.get("created").toString());
+            if (i == 5) {
+                created = Long.parseLong(activity.get("created").toString());
+            }
+        }
+
+        refreshIndex();
+        //2. Query without 'order by'
+        String query = "select * where created > " + created;
+        QueryParameters params = new QueryParameters().setQuery(query);
+        Collection activitiesWithoutOrderBy = this.app().collection("activities").get(params);
+        assertEquals(10, activitiesWithoutOrderBy.getResponse().getEntityCount());
+        //3. Query with 'order by'
+        query = query + " order by created desc";
+        params.setQuery(query);
+        Collection activitiesWithOrderBy = this.app().collection("activities").get(params);
+        assertEquals(10, activitiesWithOrderBy.getResponse().getEntityCount());
+        //4. Ensure the same entities are returned
+        while (activitiesWithoutOrderBy.hasNext() && activitiesWithOrderBy.hasNext()) {
+            Entity activityWithoutOrderBy = activitiesWithoutOrderBy.next();
+            Entity activityWithOrderBy = activitiesWithOrderBy.next();
+            assertEquals(activityWithoutOrderBy.get("uuid").toString(), activityWithOrderBy.get("uuid").toString());
+        }
     }
 
-    refreshIndex();
-    //2. Query a subset of the entities, specifying order and limit
-    String query = "select * where created > " + 1 + " order by created desc";
-    QueryParameters params = new QueryParameters().setQuery(query).setLimit(5);
-    Collection activities = this.app().collection("activities").get(params);
-    //3. Ensure the correct number of results are returned
-    assertEquals(5, activities.getResponse().getEntityCount());
-
-  }
-
-  /**
-   * Ensure that results are returned in the correct descending order, when specified
-   * 1. Insert a number of entities and add them to an array
-   * 2. Query for the entities in descending order
-   * 3. Validate that the order is correct
-   * @throws IOException
-   */
-  @Test
-  // USERGRID-1521
-  public void orderByReturnCorrectResults() throws IOException {
-
-    int size = 20;
-    Entity[] activities = new Entity[size];
-
-    Entity actor = new Entity();
-    actor.put("displayName", "Erin");
-    Entity props = new Entity();
-    props.put("actor", actor);
-    props.put("verb", "go");
-    props.put("content", "bragh");
-    //1. Insert a number of entities and add them to an array
-    for (int i = 0; i < size; i++) {
-      props.put("ordinal", i);
-      Entity e = this.app().collection("activity").post(props);
-      activities[i] = e;
-      log.info(String.valueOf(e.get("uuid").toString()));
-      log.info(String.valueOf(Long.parseLong(activities[0].get("created").toString())));
+
+    /**
+     * Ensure successful query when 'limit' and 'order by' are specified
+     * 1. Insert entities
+     * 2. Query a subset of the entities, specifying order and limit
+     * 3. Ensure the correct number of results are returned
+     *
+     * @throws IOException
+     */
+    @Test
+    // USERGRID-1520
+    public void orderByComesBeforeLimitResult() throws IOException {
+
+        Entity actor = new Entity();
+        actor.put("displayName", "Erin");
+        Entity props = new Entity();
+        props.put("actor", actor);
+        props.put("verb", "go");
+        props.put("content", "bragh");
+        //1. Insert entities
+        for (int i = 0; i < 20; i++) {
+            props.put("ordinal", i);
+            this.app().collection("activity").post(props);
+        }
+
+        refreshIndex();
+        //2. Query a subset of the entities, specifying order and limit
+        String query = "select * where created > " + 1 + " order by created desc";
+        QueryParameters params = new QueryParameters().setQuery(query).setLimit(5);
+        Collection activities = this.app().collection("activities").get(params);
+        //3. Ensure the correct number of results are returned
+        assertEquals(5, activities.getResponse().getEntityCount());
+
     }
 
-    refreshIndex();
-
-
-     ArrayUtils.reverse(activities);
-    long lastCreated = Long.parseLong(activities[0].get("created").toString());
-    //2. Query for the entities in descending order
-    String errorQuery = String.format("select * where created <= %d order by created desc", lastCreated);
-    int index = size - 1;
-
-    QueryParameters params = new QueryParameters().setQuery(errorQuery);
-    Collection activitiesResponse = this.app().collection("activities").get(params);
-    //3. Validate that the order is correct
-    do {
-      int returnSize = activitiesResponse.getResponse().getEntityCount();
-      //loop through the current page of results
-      for (int i = 0; i < returnSize; i++, index--) {
-        assertEquals(activitiesResponse.getResponse().getEntities().get(i).get("uuid").toString(),
-            (activities[i]).get("uuid").toString());
-      }
-      //grab the next page of results
-      activitiesResponse = this.app().getNextPage(activitiesResponse, params, true);
+    /**
+     * Ensure that results are returned in the correct descending order, when specified
+     * 1. Insert a number of entities and add them to an array
+     * 2. Query for the entities in descending order
+     * 3. Validate that the order is correct
+     *
+     * @throws IOException
+     */
+    @Test
+    // USERGRID-1521
+    public void orderByReturnCorrectResults() throws IOException {
+
+        int size = 20;
+        Entity[] activities = new Entity[size];
+
+        Entity actor = new Entity();
+        actor.put("displayName", "Erin");
+        Entity props = new Entity();
+        props.put("actor", actor);
+        props.put("verb", "go");
+        props.put("content", "bragh");
+        //1. Insert a number of entities and add them to an array
+        for (int i = 0; i < size; i++) {
+            props.put("ordinal", i);
+            Entity e = this.app().collection("activity").post(props);
+            activities[i] = e;
+            log.info(String.valueOf(e.get("uuid").toString()));
+            log.info(String.valueOf(Long.parseLong(activities[0].get("created").toString())));
+        }
+
+        refreshIndex();
+
+
+        ArrayUtils.reverse(activities);
+        long lastCreated = Long.parseLong(activities[0].get("created").toString());
+        //2. Query for the entities in descending order
+        String errorQuery = String.format("select * where created <= %d order by created desc", lastCreated);
+        int index = size - 1;
+
+        QueryParameters params = new QueryParameters().setQuery(errorQuery);
+        Collection activitiesResponse = this.app().collection("activities").get(params);
+        //3. Validate that the order is correct
+        do {
+            int returnSize = activitiesResponse.getResponse().getEntityCount();
+            //loop through the current page of results
+            for (int i = 0; i < returnSize; i++, index--) {
+                assertEquals(activitiesResponse.getResponse().getEntities().get(i).get("uuid").toString(),
+                    (activities[i]).get("uuid").toString());
+            }
+            //grab the next page of results
+            activitiesResponse = this.app().getNextPage(activitiesResponse, params, true);
+        }
+        while (activitiesResponse.getCursor() != null);
     }
-    while (activitiesResponse.getCursor() != null);
-  }
 }