usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [3/6] incubator-usergrid git commit: [USERGRID-303]Updates to AndOrQueryTest
Date Wed, 07 Jan 2015 21:54:43 GMT
[USERGRID-303]Updates to AndOrQueryTest


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

Branch: refs/heads/two-dot-o
Commit: dc625ac9d4dc24e5ccdf19a42f3a507d959e7df3
Parents: 323ef95
Author: ryan bridges <rbridges@apigee.com>
Authored: Mon Jan 5 12:01:47 2015 -0500
Committer: ryan bridges <rbridges@apigee.com>
Committed: Wed Jan 7 14:44:29 2015 -0500

----------------------------------------------------------------------
 .../applications/queries/AndOrQueryTest.java    | 233 ++++++++++++-------
 .../applications/queries/GeoPagingTest.java     |   1 -
 2 files changed, 154 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dc625ac9/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 2003faf..ae7083f 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
@@ -18,15 +18,23 @@ package org.apache.usergrid.rest.applications.queries;
 
 
 import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import java.io.IOException;
+
+import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.RandomStringUtils;
+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.apache.usergrid.utils.MapUtils;
 import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
-import org.apache.usergrid.rest.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
 import org.apache.usergrid.rest.TestContextSetup;
 import org.apache.usergrid.rest.test.resource.CustomCollection;
 
@@ -42,26 +50,21 @@ import static org.apache.usergrid.utils.MapUtils.hashMap;
  */
 public class AndOrQueryTest extends AbstractRestIT {
 
-    @Rule
-    public TestContextSetup context = new TestContextSetup( this );
-
-
     @Test //USERGRID-900
     public void queriesWithAndPastLimit() throws IOException {
 
-        CustomCollection activities = context.customCollection( "activities" );
 
         long created = 0;
-        Map actor = hashMap( "displayName", "Erin" );
-        Map props = new HashMap();
-
+      Entity actor = new Entity();
+      actor.put("displayName", "Erin");
+      Entity props = new Entity();
         props.put( "actor", actor );
         props.put( "verb", "go" );
         props.put( "content", "bragh" );
 
 
-        for ( int i = 0; i < 2000; i++ ) {
-            if ( i < 1000 ) {
+        for ( int i = 0; i < 20; i++ ) {
+            if ( i < 10 ) {
                 props.put( "madeup", false );
             }
             else {
@@ -69,136 +72,208 @@ public class AndOrQueryTest extends AbstractRestIT {
             }
 
             props.put( "ordinal", i );
-            JsonNode activity = activities.create( props );
+            Entity activity = this.app().collection("activities").post(props);
             if ( i == 0 ) {
-                created = activity.findValue( "created" ).longValue();
+                created = Long.parseLong(activity.get("created").toString());
             }
         }
 
-        this.refreshIndex( context.getAppUuid() );
+        this.refreshIndex();
 
         String errorQuery = "select * where created >= " + created + "AND madeup = true";
-        JsonNode incorrectNode = activities.withQuery( errorQuery ).get();
+      QueryParameters params= new QueryParameters();
+      params.setQuery(errorQuery);
+       Collection activities=this.app().collection("activities").get(params);
 
-        assertEquals( 10, incorrectNode.get( "entities" ).size() );
+        assertEquals( 10, activities.response.getEntityCount() );
     }
 
 
     @Test //USERGRID-1475
     public void displayFullQueriesInLimit() throws IOException {
 
-        CustomCollection activities = context.customCollection( "activities" );
+      int numValuesTested = 20;
+      Entity actor = new Entity();
+      actor.put("displayName", "Erin");
+      Entity props = new Entity();
+      props.put( "actor", actor );
+      props.put( "verb", "go" );
+      props.put( "content", "bragh" );
 
-        Map actor = hashMap( "displayName", "Erin" );
-        Map props = new HashMap();
-        props.put( "actor", actor );
-        props.put( "content", "bragh" );
 
-        for ( int i = 0; i < 20; i++ ) {
+      for ( int i = 0; i < numValuesTested; i++ ) {
+        if ( i < numValuesTested/2 ) {
+          props.put( "verb", "go" );
+        }
+        else {
+          props.put( "verb", "stop" );
+        }
 
-            if ( i < 10 ) {
-                props.put( "verb", "go" );
-            }
-            else {
-                props.put( "verb", "stop" );
-            }
+        props.put( "ordinal", i );
+        this.app().collection("activities").post(props);
+      }
 
-            props.put( "ordinal", i );
-            JsonNode activity = activities.create( props );
-        }
 
-        this.refreshIndex( context.getAppUuid() );
+        this.refreshIndex();
 
         String query = "select * where not verb = 'go'";
-        JsonNode incorrectNode = activities.query( query, "limit", Integer.toString( 10 )
);
+      QueryParameters params= new QueryParameters();
+      params.setQuery(query);
+      Collection activities=this.app().collection("activities").get(params);
 
-        assertEquals( 10, incorrectNode.get( "entities" ).size() );
+      assertEquals( numValuesTested/2, activities.response.getEntityCount() );
+      List entities = activities.response.getEntities();
 
-        for ( int i = 0; i < 10; i++ ) {
-            assertEquals( 19 - i, incorrectNode.get( "entities" ).get( i ).get( "ordinal"
).intValue() );
-            assertEquals( "stop", incorrectNode.get( "entities" ).get( i ).get( "verb" ).textValue()
);
+        for ( int i = 0; i < numValuesTested/2; i++ ) {
+            assertEquals(numValuesTested - i, Integer.parseInt(((LinkedHashMap<String,
Object>) entities.get(i)).get("ordinal").toString()));
+            assertEquals( "stop", ((LinkedHashMap<String, Object>) entities.get(i)).get("verb").toString()
);
         }
     }
-
+  
 
     @Test //USERGRID-1615
     public void queryReturnCount() throws Exception {
 
-        CustomCollection activities = context.customCollection( "activities" );
-
-        Map actor = hashMap( "displayName", "Erin" );
-        Map props = new HashMap();
 
         int numValuesTested = 20;
 
+      Entity actor = new Entity();
+      actor.put("displayName", "Erin");
+      Entity props = new Entity();
+      props.put( "actor", actor );
+      props.put( "verb", "go" );
+      props.put( "content", "bragh" );
+      Entity[] correctValues = new Entity[numValuesTested];
+      for(int i=0; i< numValuesTested; i++){
+        props.put("ordinal", i);
+        correctValues[i] = this.app().collection("activities").post(props);
+      }
+      this.refreshIndex();
+
+      String inCorrectQuery = "select * where ordinal >= 10 order by ordinal asc";
+      QueryParameters params = new QueryParameters();
+      params.setQuery(inCorrectQuery);
+      Collection activities=this.app().collection("activities").get(params);
+
+      assertEquals( 10, activities.response.getEntityCount() );
+
+//      verificationOfQueryResults( "activities", (Entity[])ArrayUtils.subarray(correctValues,
10, 19), false, inCorrectQuery );
+      List entities = activities.response.getEntities();
+
+      for ( int i = 0; i < 10; i++ ) {
+        assertEquals(10+i, Integer.parseInt(((LinkedHashMap<String, Object>) entities.get(i)).get("ordinal").toString()));
+//        assertEquals( "stop", ((LinkedHashMap<String, Object>) entities.get(i)).get("verb").toString()
);
+      }
 
-        props.put( "actor", actor );
-        props.put( "verb", "go" );
-        props.put( "content", "bragh" );
-
-        JsonNode[] correctValues = activities.createEntitiesWithOrdinal( props, numValuesTested
);
-
-        this.refreshIndex( context.getAppUuid() );
-
-        String inCorrectQuery = "select * where verb = 'go' and ordinal >= 10 ";
-
-        activities.verificationOfQueryResults( correctValues, true, inCorrectQuery );
     }
 
 
     @Test //Check to make sure that asc works
     public void queryCheckAsc() throws Exception {
+      int numOfEntities = 10;
+        String collectionName = "imagination" + RandomStringUtils.randomAlphabetic( 5 );
 
-        CustomCollection madeupStuff = context.customCollection(
-                "imagination" + RandomStringUtils.randomAlphabetic( 5 ) );
-        Map character = hashMap( "WhoHelpedYou", "Ruff" );
+      Entity[] correctValues = new Entity[numOfEntities];
+      Entity props = new Entity();
+      props.put( "WhoHelpedYou", "Ruff" );
+      for(int i=0; i< numOfEntities; i++){
+        props.put("ordinal", i);
+        correctValues[i] = this.app().collection(collectionName).post(props);
+      }
 
-        JsonNode[] correctValues;
-        correctValues = madeupStuff.createEntitiesWithOrdinal( character, 10 );
-
-        this.refreshIndex( context.getAppUuid() );
+        this.refreshIndex(  );
 
         String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte 10 "
                 + "or WhoHelpedYou eq 'Ruff' ORDER BY Ordinal asc";
 
-        int totalEntitiesContained = madeupStuff.verificationOfQueryResults( correctValues,
false, inquisitiveQuery );
+        int totalEntitiesContained = verificationOfQueryResults( collectionName, correctValues,
false, inquisitiveQuery );
 
-        assertEquals( 10, totalEntitiesContained );
+        assertEquals( numOfEntities, totalEntitiesContained );
     }
 
 
-    @Ignore("Test to make sure all 1000 exist with a regular query")
+//    @Ignore("Test to make sure all 1000 exist with a regular query")
+    @Test
     public void queryReturnCheck() throws Exception {
-        CustomCollection madeupStuff = context.customCollection( "imagination" );
-        Map character = hashMap( "WhoHelpedYou", "Ruff" );
+        int numOfEntities = 20;
 
-        int numOfEntities = 1000;
+      String collectionName = "imagination" + RandomStringUtils.randomAlphabetic( 5 );
 
-        JsonNode[] correctValues = madeupStuff.createEntitiesWithOrdinal( character, numOfEntities
);
+      Entity[] correctValues = new Entity[numOfEntities];
+      Entity props = new Entity();
+      props.put( "WhoHelpedYou", "Ruff" );
+      for(int i=0; i< numOfEntities; i++){
+        props.put("ordinal", i);
+        correctValues[i] = this.app().collection(collectionName).post(props);
+      }
 
-        this.refreshIndex( context.getAppUuid() );
+      this.refreshIndex(  );
 
-        String inquisitiveQuery = "select * where Ordinal >= 0 and Ordinal <= 2000
or WhoHelpedYou = 'Ruff'";
+        String inquisitiveQuery = "select * where ordinal >= 0 and ordinal <= 2000
or WhoHelpedYou = 'Ruff'";
 
-        int totalEntitiesContained = madeupStuff.verificationOfQueryResults( correctValues,
true, inquisitiveQuery );
+        int totalEntitiesContained = verificationOfQueryResults( collectionName, correctValues,
true, inquisitiveQuery );
 
         assertEquals( numOfEntities, totalEntitiesContained );
     }
 
 
-    @Ignore
-    public void queryReturnCheckWithShortHand() throws IOException {
-        CustomCollection madeupStuff = context.customCollection( "imagination" );
-        Map character = hashMap( "WhoHelpedYou", "Ruff" );
+    @Test
+    public void queryReturnCheckWithShortHand() throws Exception {
+      int numOfEntities = 20;
 
-        madeupStuff.createEntitiesWithOrdinal( character, 1000 );
+      String collectionName = "imagination" + RandomStringUtils.randomAlphabetic( 5 );
 
-        this.refreshIndex( context.getAppUuid() );
+      Entity[] correctValues = new Entity[numOfEntities];
+      Entity props = new Entity();
+      props.put( "WhoHelpedYou", "Ruff" );
+      for(int i=0; i< numOfEntities; i++){
+        props.put("ordinal", i);
+        correctValues[i] = this.app().collection(collectionName).post(props);
+      }
 
-        String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte 2000 or WhoHelpedYou
eq 'Ruff'";
+      this.refreshIndex(  );
 
-        int totalEntitiesContained = madeupStuff.countEntities( inquisitiveQuery );
+      String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte 2000 or WhoHelpedYou
eq 'Ruff'";
+
+      int totalEntitiesContained = verificationOfQueryResults( collectionName, correctValues,
true, inquisitiveQuery );
+
+      assertEquals( numOfEntities, totalEntitiesContained );
 
-        assertEquals( 1000, totalEntitiesContained );
     }
+
+  public int verificationOfQueryResults( String collectionName, Entity[] correctValues, boolean
reverse, String checkedQuery )
+      throws Exception {
+
+    int totalEntitiesContained = 0;
+    QueryParameters params = new QueryParameters();
+    params.setQuery(checkedQuery);
+    Collection checkedNodes = this.app().collection(collectionName).get(params);
+
+    while ( correctValues.length != totalEntitiesContained )//correctNode.get("entities")
!= null)
+    {
+      totalEntitiesContained += checkedNodes.response.getEntityCount();
+      if ( !reverse ) {
+        for ( int index = 0; index < checkedNodes.response.getEntityCount(); index++ )
{
+          assertEquals( correctValues[index].get("uuid"),
+              ((LinkedHashMap)checkedNodes.response.getEntities().get( index )).get("uuid")
);
+        }
+      }
+      else {
+        for ( int index = 0; index < checkedNodes.response.getEntityCount(); index++ )
{
+          assertEquals( correctValues[correctValues.length - 1 - index].get("uuid"),
+              ((LinkedHashMap)checkedNodes.response.getEntities().get( index )).get("uuid")
);
+        }
+      }
+
+      if ( checkedNodes.getCursor() != null ) {
+        checkedNodes = this.app().getNextPage(checkedNodes,true);
+      }
+
+      else {
+        break;
+      }
+    }
+    return totalEntitiesContained;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dc625ac9/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
index babbb56..4a3ff80 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
@@ -250,7 +250,6 @@ public class GeoPagingTest extends AbstractRestIT {
 
   /**
    * Creates two users, then a matrix of coordinates, then checks to see if any of the coordinates
are near our users
-   * <p/>
    * 1. Create 2 users
    * 2. Create a list of geo points
    * 3. Test each to ensure it is not within 10000 meters of our users


Mime
View raw message