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:19 UTC

[01/19] incubator-usergrid git commit: [USERGRID-320]Adding additional Query logic and result ordering tests

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-323-Win-phone 74ea17e70 -> 2d0d68ce7


[USERGRID-320]Adding additional Query logic and result ordering tests


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: cbe846896509f651f14d1b5422467fc1d31c0a7a
Parents: 231a449
Author: ryan bridges <rb...@apigee.com>
Authored: Fri Jan 9 17:51:14 2015 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Fri Jan 9 17:51:14 2015 -0500

----------------------------------------------------------------------
 .../applications/queries/AndOrQueryTest.java    | 549 +++++++++++--------
 .../rest/applications/queries/OrderByTest.java  | 202 +++++++
 2 files changed, 518 insertions(+), 233 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbe84689/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 59329bc..d67e62a 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
@@ -22,13 +22,13 @@ 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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
-import java.util.LinkedHashMap;
 import java.util.List;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 
 /**
@@ -38,257 +38,340 @@ import static org.junit.Assert.assertTrue;
  * @since 4.0
  */
 public class AndOrQueryTest extends AbstractRestIT {
-  /**
-   * Ensure limit is respected in queries
-   * 1. Insert a number of entities
-   * 2. Set half the entities to have a 'madeup' property of 'true'
-   * and set the other half to 'false'
-   * 3. Query all entities where "madeup = true"
-   * 4. Limit the query to half of the number of entities
-   * 5. Ensure the correct entities are returned
-   *
-   * @throws IOException
-   */
-  @Test //USERGRID-900
-  public void queriesWithAndPastLimit() throws IOException {
-    int numValuesTested = 40;
-    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 a number of entities
-    for (int i = 0; i < numValuesTested; i++) {
-      //2. Set half the entities to have a 'madeup' property of 'true'
-      // and set the other half to 'false'
-      if (i < numValuesTested / 2) {
-        props.put("madeup", false);
-      } else {
-        props.put("madeup", true);
-      }
-
-      props.put("ordinal", i);
-      Entity activity = this.app().collection("activities").post(props);
-      if (i == 0) {
-        created = Long.parseLong(activity.get("created").toString());
-      }
-    }
-
-    this.refreshIndex();
-    //3. Query all entities where "madeup = true"
-    String errorQuery = "select * where created >= " + created + "AND madeup = true";
-    QueryParameters params = new QueryParameters()
-        .setQuery(errorQuery)
-        .setLimit(numValuesTested / 2);//4. Limit the query to half of the number of entities
-    Collection activities = this.app().collection("activities").get(params);
-    //5. Ensure the correct entities are returned
-    assertEquals(numValuesTested / 2, activities.getResponse().getEntityCount());
-    while (activities.hasNext()) {
-      assertTrue(Boolean.parseBoolean(activities.next().get("madeup").toString()));
-    }
-  }
-
-
-  /**
-   * Test negated query
-   * 1. Insert a number of entities
-   * 2. Set half the entities to have a 'verb' property of 'go'
-   * and set the other half to 'stop'
-   * 3. Query all entities where "NOT verb = 'go'"
-   * 4. Limit the query to half of the number of entities
-   * 5. Ensure the returned entities have "verb = 'stop'"
-   *
-   * @throws IOException
-   */
-  @Test //USERGRID-1475
-  public void negatedQuery() throws IOException {
-    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");
-    //1. Insert a number of entities
-    for (int i = 0; i < numValuesTested; i++) {
-      //2. Set half the entities to have a 'verb' property of 'go'
-      // and set the other half to 'stop'
-      if (i % 2 == 0) {
-        props.put("verb", "go");
-      } else {
-        props.put("verb", "stop");
-      }
-
-      props.put("ordinal", i);
-      this.app().collection("activities").post(props);
+    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
+     *
+     * @throws IOException
+     */
+    @Test
+    public void andQueryInclusive() throws IOException {
+        int numOfEntities = 20;
+        String collectionName = "activities";
+        //create our test entities
+        Entity[] entities = 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));
+        Collection activities = this.app().collection("activities").get(params);
+        //results should have madeup = true and ordinal 15-19
+        assertEquals(numOfEntities / 4, activities.getResponse().getEntityCount());
+        int index = 19;
+        while (activities.hasNext()) {
+            Entity activity = activities.next();
+            //ensure the 'madeup' property is set to true
+            assertTrue(Boolean.parseBoolean(activity.get("madeup").toString()));
+            //make sure the correct ordinal properties are returned
+            assertEquals(index--, Long.parseLong(activity.get("ordinal").toString()));
+        }
 
-    this.refreshIndex();
-    //3. Query all entities where "NOT verb = 'go'"
-    String query = "select * where not verb = 'go'";
-    //4. Limit the query to half of the number of entities
-    QueryParameters params = new QueryParameters().setQuery(query).setLimit(numValuesTested / 2);
-    Collection activities = this.app().collection("activities").get(params);
-    //5. Ensure the returned entities have "verb = 'stop'"
-    assertEquals(numValuesTested / 2, activities.getResponse().getEntityCount());
-    while (activities.hasNext()) {
-      assertEquals("stop", activities.next().get("verb").toString());
     }
 
+    /**
+     * Test an exclusive AND query to ensure the correct results are returned
+     *
+     * @throws IOException
+     */
+    @Test
+    public void andQueryExclusive() throws IOException {
+        int numOfEntities = 20;
+        String collectionName = "activities";
+
+        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+
+        //Query where madeup = true (the last half) and NOT the last quarter of entries
+        QueryParameters params = new QueryParameters()
+            .setQuery("select * where madeup = true AND NOT ordinal >= " + (numOfEntities - numOfEntities / 4));
+        Collection activities = this.app().collection("activities").get(params);
+        //results should have madeup = true and ordinal 10-14
+        assertEquals(numOfEntities / 4, activities.getResponse().getEntityCount());
+        int index = 14;
+        while (activities.hasNext()) {
+            Entity activity = activities.next();
+            //ensure the 'madeup' property is set to true
+            assertTrue(Boolean.parseBoolean(activity.get("madeup").toString()));
+            //make sure the correct ordinal properties are returned
+            assertEquals(index--, Long.parseLong(activity.get("ordinal").toString()));
+        }
+    }
 
-  }
-
-  /**
-   * Ensure queries return a subset of entities in the correct order
-   * 1. Insert a number of entities
-   * 2. Query for a subset of the entities
-   * 3. Validate that the correct entities are returned
-   *
-   * @throws Exception
-   */
-  @Test //USERGRID-1615
-  public void queryReturnCount() throws Exception {
-    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");
-    //1. Insert a number of entities
-    for (int i = 0; i < numValuesTested; i++) {
-      props.put("ordinal", i);
-      this.app().collection("activities").post(props);
+    /**
+     * Test an inclusive OR query to ensure the correct results are returned
+     *
+     * @throws IOException
+     */
+    @Test
+    public void orQueryInclusive() throws IOException {
+        int numOfEntities = 20;
+        String collectionName = "activities";
+
+        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+
+        //Query where madeup = false (the first half) or the last quarter of entries
+        QueryParameters params = new QueryParameters()
+            .setQuery("select * where madeup = false OR ordinal >= " + (numOfEntities - numOfEntities / 4))
+            .setLimit((numOfEntities));
+        Collection activities = this.app().collection("activities").get(params);
+        int index = numOfEntities - 1;
+        int count = 0;
+        int returnSize = activities.getResponse().getEntityCount();
+        for (int i = 0; i < returnSize; i++, index--) {
+            count++;
+            Entity activity = activities.getResponse().getEntities().get(i);
+            log.info(String.valueOf(activity.get("ordinal")) + " " + String.valueOf(activity.get("madeup")));
+            if (index < numOfEntities / 2) {
+                assertFalse(Boolean.parseBoolean(String.valueOf(activity.get("madeup"))));
+            } else if (index >= (numOfEntities - numOfEntities / 4)) {
+                assertTrue(Boolean.parseBoolean(String.valueOf(activity.get("madeup"))));
+            }
+            long ordinal = Long.parseLong(String.valueOf(activity.get("ordinal")));
+            assertTrue(ordinal < (numOfEntities / 2) || ordinal >= (numOfEntities - numOfEntities / 4));
+        }
+        //results should have madeup = false or ordinal 15-19
+        assertEquals(3 * numOfEntities / 4, count);
     }
-    this.refreshIndex();
-    //2. Query for a subset of the entities
-    String inCorrectQuery = "select * where ordinal >= 10 order by ordinal asc";
-    QueryParameters params = new QueryParameters().setQuery(inCorrectQuery).setLimit(numValuesTested / 2);
-    Collection activities = this.app().collection("activities").get(params);
-    //3. Validate that the correct entities are returned
-    assertEquals(numValuesTested / 2, activities.getResponse().getEntityCount());
-
-    List<Entity> entities = activities.getResponse().getEntities();
-    for (int i = 0; i < numValuesTested / 2; i++) {
-      assertEquals(numValuesTested / 2 + i, Integer.parseInt(entities.get(i).get("ordinal").toString()));
+
+    /**
+     * Test an exclusive OR query to ensure the correct results are returned
+     *
+     * @throws IOException
+     */
+    @Test
+    public void orQueryExclusive() throws IOException {
+        int numOfEntities = 30;
+        String collectionName = "activities";
+
+        Entity[] entities = 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()
+            .setQuery("select * where (verb = 'go' OR ordinal >= " + (numOfEntities - numOfEntities / 4) + ") AND NOT (verb = 'go' AND ordinal >= " + (numOfEntities - numOfEntities / 4) + ")")
+            .setLimit((numOfEntities));
+        Collection activities = this.app().collection("activities").get(params);
+
+        int index = numOfEntities - 1;
+        int count = 0;
+        int returnSize = activities.getResponse().getEntityCount();
+        for (int i = 0; i < returnSize; i++, index--) {
+            count++;
+            Entity activity = activities.getResponse().getEntities().get(i);
+            long ordinal = Long.parseLong(String.valueOf(activity.get("ordinal")));
+            log.info(ordinal + " " + String.valueOf(activity.get("verb")));
+            if (ordinal < (numOfEntities - numOfEntities / 4)) {
+                assertEquals("go", String.valueOf(activity.get("verb")));
+            } else if (ordinal >= (numOfEntities - numOfEntities / 4)) {
+                assertEquals("stop", String.valueOf(activity.get("verb")));
+            }
+        }
+        //results should be even ordinals in the first 3 quarters and odd ordinals from the last quarter
+        assertEquals(1 + numOfEntities / 2, count);
     }
 
-  }
-
-  /**
-   * Validate sort order with AND/OR query
-   * 1. Insert entities
-   * 2. Use AND/OR query to retrieve entities
-   * 3. Verify the order of results
-   *
-   * @throws Exception
-   */
-  @Test
-  public void queryCheckAsc() throws Exception {
-    int numOfEntities = 20;
-    String collectionName = "imagination";
-
-    Entity props = new Entity();
-    props.put("WhoHelpedYou", "Ruff");
-    //1. Insert entities
-    for (int i = 0; i < numOfEntities; i++) {
-      props.put("ordinal", i);
-      this.app().collection(collectionName).post(props);
+    /**
+     * Ensure limit is respected in queries
+     * 1. Query all entities where "madeup = true"
+     * 2. Limit the query to half of the number of entities
+     * 3. Ensure the correct entities are returned
+     *
+     * @throws IOException
+     */
+    @Test //USERGRID-900
+    public void queriesWithAndPastLimit() throws IOException {
+        int numValuesTested = 40;
+        long created = 0;
+
+        Entity[] entities = generateTestEntities(numValuesTested, "activities");
+        //3. Query all entities where "madeup = true"
+        String errorQuery = "select * where madeup = true";
+        QueryParameters params = new QueryParameters()
+            .setQuery(errorQuery)
+            .setLimit(numValuesTested / 2);//4. Limit the query to half of the number of entities
+        Collection activities = this.app().collection("activities").get(params);
+        //5. Ensure the correct entities are returned
+        assertEquals(numValuesTested / 2, activities.getResponse().getEntityCount());
+        while (activities.hasNext()) {
+            assertTrue(Boolean.parseBoolean(activities.next().get("madeup").toString()));
+        }
     }
 
-    this.refreshIndex();
 
-    //2. Use AND/OR query to retrieve entities
-    String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte 10 "
-        + "or WhoHelpedYou eq 'Ruff' ORDER BY Ordinal asc";
-    QueryParameters params = new QueryParameters().setQuery(inquisitiveQuery).setLimit(numOfEntities / 2);
-    Collection activities = this.app().collection(collectionName).get(params);
+    /**
+     * Test negated query
+     * 1. Query all entities where "NOT verb = 'go'"
+     * 2. Limit the query to half of the number of entities
+     * 3. Ensure the returned entities have "verb = 'stop'"
+     *
+     * @throws IOException
+     */
+    @Test //USERGRID-1475
+    public void negatedQuery() throws IOException {
+        int numValuesTested = 20;
+
+        Entity[] entities = 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
+        QueryParameters params = new QueryParameters().setQuery(query).setLimit(numValuesTested / 2);
+        Collection activities = this.app().collection("activities").get(params);
+        //3. Ensure the returned entities have "verb = 'stop'"
+        assertEquals(numValuesTested / 2, activities.getResponse().getEntityCount());
+        while (activities.hasNext()) {
+            assertEquals("stop", activities.next().get("verb").toString());
+        }
 
-    //3. Verify the order of results
-    assertEquals(numOfEntities / 2, activities.getResponse().getEntityCount());
-    List<Entity> entities = activities.getResponse().getEntities();
-    for (int i = 0; i < numOfEntities / 2; i++) {
-      assertEquals(i, Integer.parseInt(entities.get(i).get("ordinal").toString()));
-    }
-  }
-
-
-  /**
-   * Test a standard query
-   * 1. Insert a number of entities
-   * 2. Issue a query
-   * 3. validate that a full page of (10) entities is returned
-   *
-   * @throws Exception
-   */
-  @Test
-  public void queryReturnCheck() throws Exception {
-    int numOfEntities = 20;
-    String collectionName = "imagination";
-
-    Entity props = new Entity();
-    props.put("WhoHelpedYou", "Ruff");
-    //1. Insert a number of entities
-    for (int i = 0; i < numOfEntities; i++) {
-      props.put("ordinal", i);
-      this.app().collection(collectionName).post(props);
-    }
 
-    this.refreshIndex();
+    }
 
-    //2. Issue a query
-    String inquisitiveQuery = String.format("select * where ordinal >= 0 and ordinal <= %d or WhoHelpedYou = 'Ruff'", numOfEntities);
-    QueryParameters params = new QueryParameters().setQuery(inquisitiveQuery);
-    Collection activities = this.app().collection(collectionName).get(params);
+    /**
+     * Ensure queries return a subset of entities in the correct order
+     * 1. Query for a subset of the entities
+     * 2. Validate that the correct entities are returned
+     *
+     * @throws Exception
+     */
+    @Test //USERGRID-1615
+    public void queryReturnCount() throws Exception {
+        int numValuesTested = 20;
+
+        Entity[] entities = 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);
+        Collection activities = this.app().collection("activities").get(params);
+        //2. Validate that the correct entities are returned
+        assertEquals(numValuesTested / 2, activities.getResponse().getEntityCount());
+
+        List<Entity> entitiesReturned = activities.getResponse().getEntities();
+        for (int i = 0; i < numValuesTested / 2; i++) {
+            assertEquals(numValuesTested / 2 + i, Integer.parseInt(entitiesReturned.get(i).get("ordinal").toString()));
+        }
 
-    //3. validate that a full page of (10) entities is returned
-    assertEquals(10, activities.getResponse().getEntityCount());
-    List<Entity> entities = activities.getResponse().getEntities();
-    for (int i = 0; i < 10; i++) {
-      assertEquals(i, Integer.parseInt(entities.get(i).get("ordinal").toString()));
     }
-  }
-
-  /**
-   * Test a standard query using alphanumeric operators
-   * 1. Insert a number of entities
-   * 2. Issue a query using alphanumeric operators
-   * 3. validate that a full page of (10) entities is returned
-   *
-   * @throws Exception
-   */
-  @Test
-  public void queryReturnCheckWithShortHand() throws Exception {
-    int numOfEntities = 10;
-    String collectionName = "imagination";
-
-    Entity props = new Entity();
-    props.put("WhoHelpedYou", "Ruff");
-    //1. Insert a number of entities
-    for (int i = 0; i < numOfEntities; i++) {
-      props.put("ordinal", i);
-      this.app().collection(collectionName).post(props);
+
+    /**
+     * Validate sort order with AND/OR query
+     * 1. Use AND/OR query to retrieve entities
+     * 2. Verify the order of results
+     *
+     * @throws Exception
+     */
+    @Test
+    public void queryCheckAsc() throws Exception {
+        int numOfEntities = 20;
+        String collectionName = "imagination";
+
+        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+
+        //2. Use AND/OR query to retrieve entities
+        String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte  " + (numOfEntities / 2)
+            + " or WhoHelpedYou eq 'Ruff' ORDER BY Ordinal asc";
+        QueryParameters params = new QueryParameters().setQuery(inquisitiveQuery).setLimit(numOfEntities / 2);
+        Collection activities = this.app().collection(collectionName).get(params);
+
+        //3. Verify the order of results
+        assertEquals(numOfEntities / 2, activities.getResponse().getEntityCount());
+        List<Entity> entitiesReturned = activities.getResponse().getEntities();
+        for (int i = 0; i < numOfEntities / 2; i++) {
+            assertEquals(i, Integer.parseInt(entitiesReturned.get(i).get("ordinal").toString()));
+        }
     }
 
-    this.refreshIndex();
 
-    //2. Issue a query using alphanumeric operators
-    String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte 2000 or WhoHelpedYou eq 'Ruff'";
-    QueryParameters params = new QueryParameters().setQuery(inquisitiveQuery);
-    Collection activities = this.app().collection(collectionName).get(params);
+    /**
+     * Test a standard query
+     * 1. Issue a query
+     * 2. validate that a full page of (10) entities is returned
+     *
+     * @throws Exception
+     */
+    @Test
+    public void queryReturnCheck() throws Exception {
+        int numOfEntities = 20;
+        String collectionName = "imagination";
+
+        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+
+        //2. Issue a query
+        String inquisitiveQuery = String.format("select * where ordinal >= 0 and ordinal <= %d or WhoHelpedYou = 'Ruff'", numOfEntities);
+        QueryParameters params = new QueryParameters().setQuery(inquisitiveQuery);
+        Collection activities = this.app().collection(collectionName).get(params);
+
+        //3. validate that a full page of (10) entities is returned
+        assertEquals(10, activities.getResponse().getEntityCount());
+        List<Entity> entitiesReturned = activities.getResponse().getEntities();
+        for (int i = 0; i < 10; i++) {
+            assertEquals(i, Integer.parseInt(entitiesReturned.get(i).get("ordinal").toString()));
+        }
+    }
 
-    //3. validate that a full page of (10) entities is returned
-    assertEquals(10, activities.getResponse().getEntityCount());
-    List<Entity> entities = activities.getResponse().getEntities();
-    for (int i = 0; i < 10; i++) {
-      assertEquals(i, Integer.parseInt(entities.get(i).get("ordinal").toString()));
+    /**
+     * Test a standard query using alphanumeric operators
+     * 1. Issue a query using alphanumeric operators
+     * 2. validate that a full page of (10) entities is returned
+     *
+     * @throws Exception
+     */
+    @Test
+    public void queryReturnCheckWithShortHand() throws Exception {
+        int numOfEntities = 10;
+        String collectionName = "imagination";
+
+        Entity[] entities = 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'";
+        QueryParameters params = new QueryParameters().setQuery(inquisitiveQuery);
+        Collection activities = this.app().collection(collectionName).get(params);
+
+        //3. validate that a full page of (10) entities is returned
+        assertEquals(10, activities.getResponse().getEntityCount());
+        List<Entity> entitiesReturned = activities.getResponse().getEntities();
+        for (int i = 0; i < 10; i++) {
+            assertEquals(i, Integer.parseInt(entitiesReturned.get(i).get("ordinal").toString()));
+        }
     }
-  }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbe84689/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 6d5f39b..9acee8d 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
@@ -30,6 +30,8 @@ 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,7 +42,207 @@ import static org.junit.Assert.assertEquals;
  */
 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;
+    }
+
+    /**
+     * Test correct sort order for Long properties
+     * @throws IOException
+     */
+    @Test
+    public void testSortLongAsc() throws IOException{
+        int numOfEntities = 20;
+        String collectionName = "activities";
+        //create our test entities
+        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+
+        QueryParameters params = new QueryParameters()
+            .setQuery("select * order by ordinal asc")
+            .setLimit(numOfEntities);
+        Collection activities = this.app().collection("activities").get(params);
+        assertEquals(numOfEntities, activities.getResponse().getEntityCount());
+        //results should be ordered by ordinal
+        int index = 0;
+        while (activities.hasNext()) {
+            Entity activity = activities.next();
+            //make sure the correct ordinal properties are returned
+            assertEquals(index++, Long.parseLong(activity.get("ordinal").toString()));
+        }
+    }
+    /**
+     * Test correct sort order for Long properties
+     * @throws IOException
+     */
+    @Test
+    public void testSortLongDesc() throws IOException{
+        int numOfEntities = 20;
+        String collectionName = "activities";
+        //create our test entities
+        Entity[] entities = 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;
+        //results should be sorted by ordinal
+        while (activities.hasNext()) {
+            Entity activity = activities.next();
+            //make sure the correct ordinal properties are returned
+            assertEquals(index--, Long.parseLong(activity.get("ordinal").toString()));
+        }
+    }
+    /**
+     * Test correct sort order for Boolean properties
+     * @throws IOException
+     */
+    @Test
+    public void testSortBooleanAsc() throws IOException{
+        int numOfEntities = 20;
+        String collectionName = "activities";
+        //create our test entities
+        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+
+        QueryParameters params = new QueryParameters()
+            .setQuery("select * order by madeup asc")
+            .setLimit(numOfEntities);
+        Collection activities = this.app().collection("activities").get(params);
+        assertEquals(numOfEntities, activities.getResponse().getEntityCount());
+        int index = 0;
+        //results should be sorted false, then true
+        while (activities.hasNext()) {
+            Entity activity = activities.next();
+            if(index++ < numOfEntities/2){
+                assertEquals("false", activity.get("madeup").toString());
+            }else{
+                assertEquals("true", activity.get("madeup").toString());
+            }
+        }
+    }
+    /**
+     * Test correct sort order for Boolean properties
+     * @throws IOException
+     */
+    @Test
+    public void testSortBooleanDesc() throws IOException{
+        int numOfEntities = 20;
+        String collectionName = "activities";
+        //create our test entities
+        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+
+        QueryParameters params = new QueryParameters()
+            .setQuery("select * order by madeup desc")
+            .setLimit(numOfEntities);
+        Collection activities = this.app().collection("activities").get(params);
+        assertEquals(numOfEntities, activities.getResponse().getEntityCount());
+        int index = 0;
+        //results should be sorted true, then false
+        while (activities.hasNext()) {
+            Entity activity = activities.next();
+            //make sure the booleans are ordered correctly
+            if(index++ < numOfEntities/2){
+                assertEquals("true", activity.get("madeup").toString());
+            }else{
+                assertEquals("false", activity.get("madeup").toString());
+            }
+        }
+    }
+
+    /**
+     * Test correct sort order for String properties
+     * @throws IOException
+     */
+    @Test
+    public void testSortStringAsc() throws IOException{
+        int numOfEntities = 20;
+        String collectionName = "activities";
+        //create our test entities
+        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+
+        QueryParameters params = new QueryParameters()
+            .setQuery("select * order by verb asc")
+            .setLimit(numOfEntities);
+        Collection activities = this.app().collection("activities").get(params);
+        assertEquals(numOfEntities, activities.getResponse().getEntityCount());
+        int index = 0;
+        //results should be sorted "go", then "stop"
+        while (activities.hasNext()) {
+            Entity activity = activities.next();
+            if(index++ < numOfEntities/2){
+                assertEquals("go", activity.get("verb").toString());
+            }else{
+                assertEquals("stop", activity.get("verb").toString());
+            }
+        }
+    }
+    /**
+     * Test correct sort order for String properties
+     * @throws IOException
+     */
+    @Test
+    public void testSortStringDesc() throws IOException{
+        int numOfEntities = 20;
+        String collectionName = "activities";
+        //create our test entities
+        Entity[] entities = generateTestEntities(numOfEntities, collectionName);
+
+        QueryParameters params = new QueryParameters()
+            .setQuery("select * order by verb desc")
+            .setLimit(numOfEntities);
+        Collection activities = this.app().collection("activities").get(params);
+        assertEquals(numOfEntities, activities.getResponse().getEntityCount());
+        int index = 0;
+        //results should be sorted "stop", then "go"
+        while (activities.hasNext()) {
+            Entity activity = activities.next();
+            if(index++ < numOfEntities/2){
+                assertEquals("stop", activity.get("verb").toString());
+            }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'


[15/19] incubator-usergrid git commit: added apache lic header

Posted by sf...@apache.org.
added apache lic header


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 6ebbe50937a53c94e3555e95a964d52c0976388a
Parents: 561815a
Author: Rod Simpson <ro...@apigee.com>
Authored: Tue Jan 20 14:36:47 2015 -0700
Committer: Rod Simpson <ro...@apigee.com>
Committed: Tue Jan 20 14:36:47 2015 -0700

----------------------------------------------------------------------
 .../rest/applications/queries/QueryTestBase.java    | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6ebbe509/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/QueryTestBase.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/QueryTestBase.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/QueryTestBase.java
index b9287da..5871c84 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/QueryTestBase.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/QueryTestBase.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.usergrid.rest.applications.queries;
 
 import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;


[03/19] incubator-usergrid git commit: [USERGRID-320] Added base class for common methods for query tests

Posted by sf...@apache.org.
[USERGRID-320] Added base class for common methods for query tests


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: b07d52df290ddfae093f30a962b72fa814851f94
Parents: 5c23a7f
Author: ryan bridges <rb...@apigee.com>
Authored: Mon Jan 12 10:54:41 2015 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Mon Jan 12 10:54:41 2015 -0500

----------------------------------------------------------------------
 .../applications/queries/QueryTestBase.java     | 56 ++++++++++++++++++++
 1 file changed, 56 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b07d52df/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/QueryTestBase.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/QueryTestBase.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/QueryTestBase.java
new file mode 100644
index 0000000..b9287da
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/QueryTestBase.java
@@ -0,0 +1,56 @@
+package org.apache.usergrid.rest.applications.queries;
+
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A base class containing common methods used by query tests
+ */
+public class QueryTestBase  extends AbstractRestIT {
+    private static Logger log = LoggerFactory.getLogger(QueryTestBase.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
+     */
+    protected 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;
+    }
+
+
+}


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

Posted by sf...@apache.org.
[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/c078ae14
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c078ae14
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c078ae14

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

----------------------------------------------------------------------
 .../usergrid/rest/applications/queries/BadGrammarQueryTest.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c078ae14/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 12da417..4dd7548 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
@@ -206,7 +206,7 @@ public class BadGrammarQueryTest extends QueryTestBase {
         generateTestEntities(numOfEntities, collectionName);
 
 
-        //Issue an invalid query
+        //Issue a query with the limit appended
         String query = "select * where limit = 5";
         QueryParameters params = new QueryParameters().setQuery(query);
         Collection collection = this.app().collection(collectionName).get(params);


[13/19] incubator-usergrid git commit: Merge remote-tracking branch 'r3b/USERGRID-326' into apache_usergrid/two-dot-o

Posted by sf...@apache.org.
Merge remote-tracking branch 'r3b/USERGRID-326' into apache_usergrid/two-dot-o


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 561815ae8762ef10a284fcbd739fffd240c61174
Parents: e6561c7 2b7d231
Author: Rod Simpson <ro...@apigee.com>
Authored: Tue Jan 20 10:59:43 2015 -0700
Committer: Rod Simpson <ro...@apigee.com>
Committed: Tue Jan 20 10:59:43 2015 -0700

----------------------------------------------------------------------
 .../apache/usergrid/rest/PartialUpdateTest.java | 170 ++++++++-----------
 .../endpoints/CollectionEndpoint.java           |   2 +-
 2 files changed, 76 insertions(+), 96 deletions(-)
----------------------------------------------------------------------



[17/19] incubator-usergrid git commit: roles/role fix

Posted by sf...@apache.org.
roles/role fix


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 6dc62edfc0a625a070497acfa5ab6b21f53c9093
Parents: e4cb321
Author: Rod Simpson <ro...@apigee.com>
Authored: Wed Jan 21 17:58:33 2015 -0700
Committer: Rod Simpson <ro...@apigee.com>
Committed: Wed Jan 21 17:58:33 2015 -0700

----------------------------------------------------------------------
 .../rest/applications/collection/groups/GroupResourceIT.java       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6dc62edf/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
index ed6876b..50e670e 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
@@ -272,7 +272,7 @@ public class GroupResourceIT extends AbstractRestIT {
         this.refreshIndex();
 
         //3. add role to the group
-        Entity response = this.app().collection("role").entity(role).connection().collection("groups").entity(group).post();
+        Entity response = this.app().collection("roles").entity(role).connection().collection("groups").entity(group).post();
         assertEquals(response.get("name"), groupName);
         this.refreshIndex();
 


[16/19] incubator-usergrid git commit: Merge branch 'usergrid-312-appdelete' of github.com:snoopdave/incubator-usergrid into apache_usergrid/two-dot-o

Posted by sf...@apache.org.
Merge branch 'usergrid-312-appdelete' of github.com:snoopdave/incubator-usergrid into apache_usergrid/two-dot-o


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: e4cb321e9e1832af13d97796c1be3f0a91131d8c
Parents: 6ebbe50 4384975
Author: Rod Simpson <ro...@apigee.com>
Authored: Wed Jan 21 16:10:26 2015 -0700
Committer: Rod Simpson <ro...@apigee.com>
Committed: Wed Jan 21 16:10:26 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java |  56 +++++++--
 .../HybridEntityManagerFactory.java             |   9 +-
 .../persistence/EntityManagerFactory.java       |  11 +-
 .../cassandra/EntityManagerFactoryImpl.java     |  11 +-
 .../cassandra/EntityManagerFactoryImplIT.java   |  71 +++++++-----
 .../usergrid/persistence/index/EntityIndex.java |   2 +
 .../index/impl/EsEntityIndexBatchImpl.java      |  14 +--
 .../index/impl/EsEntityIndexImpl.java           | 115 ++++++++-----------
 .../persistence/index/impl/EsIndexCache.java    |  12 +-
 .../rest/applications/ApplicationResource.java  |  32 +++++-
 .../applications/ApplicationDeleteTest.java     |  54 +++++++++
 11 files changed, 257 insertions(+), 130 deletions(-)
----------------------------------------------------------------------



[11/19] incubator-usergrid git commit: Addition of emf.deleteApplicaton() method and a test for it in EntityManagerFacotryImplIT.

Posted by sf...@apache.org.
Addition of emf.deleteApplicaton() method and  a test for it in EntityManagerFacotryImplIT.


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 7335f9411aa20357bc3c4b3c866b12dfdadb23a3
Parents: 0408b4b
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Jan 20 11:59:34 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Jan 20 11:59:34 2015 -0500

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 56 ++++++++++++---
 .../HybridEntityManagerFactory.java             |  9 ++-
 .../persistence/EntityManagerFactory.java       | 11 ++-
 .../cassandra/EntityManagerFactoryImpl.java     | 11 ++-
 .../cassandra/EntityManagerFactoryImplIT.java   | 71 +++++++++++++-------
 5 files changed, 115 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7335f941/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 7016d3c..93eb15e 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -123,8 +123,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
         this.cass = cass;
         this.counterUtils = counterUtils;
-
-
     }
 
 
@@ -136,8 +134,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
             if ( em.getApplication() == null ) {
                 logger.info("Creating system application");
                 Map sysAppProps = new HashMap<String, Object>();
-                sysAppProps.put( PROPERTY_NAME, "systemapp");
-                em.create( CpNamingUtils.SYSTEM_APP_ID, TYPE_APPLICATION, sysAppProps );
+                sysAppProps.put(PROPERTY_NAME, "systemapp");
+                em.create(CpNamingUtils.SYSTEM_APP_ID, TYPE_APPLICATION, sysAppProps);
                 em.getApplication();
                 em.createIndex();
                 em.refreshIndex();
@@ -165,7 +163,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
 
     @Override
-    public String getImpementationDescription() throws Exception {
+    public String getImplementationDescription() throws Exception {
         return IMPLEMENTATION_DESCRIPTION;
     }
 
@@ -187,7 +185,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         EntityManager em = new CpEntityManager();
         em.init( this, applicationId );
 
-        // only need to do this once 
+        // only need to do this once
         if ( !applicationIndexesCreated.contains( applicationId ) ) {
             em.createIndex();
             applicationIndexesCreated.add( applicationId );
@@ -285,6 +283,36 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     }
 
 
+    /**
+     * Delete Application.
+     *
+     * <p>The Application Entity is be moved to a Deleted_Applications collection and the
+     * Application index will be removed.
+     *
+     * <p>TODO: add scheduled task that can completely delete all deleted application data.</p>
+     *
+     * @param applicationId UUID of Application to be deleted.
+     */
+    @Override
+    public void deleteApplication(UUID applicationId) throws Exception {
+
+        // remove old appinfo Entity, which is in the System App's appinfos collection
+        EntityManager em = getEntityManager(CpNamingUtils.SYSTEM_APP_ID);
+        Query q = Query.fromQL(String.format("select * where applicationUuid = '%s'", applicationId.toString()));
+        Results results = em.searchCollection( em.getApplicationRef(), "appinfos", q);
+        Entity appToDelete = results.getEntity();
+        em.delete( appToDelete );
+
+        // create new Entity in deleted_appinfos collection, with same UUID and properties as deleted appinfo
+        em.create( "deleted_appinfo", appToDelete.getProperties() );
+
+        em.refreshIndex();
+
+        // delete the application's index
+        EntityIndex ei = managerCache.getEntityIndex(new ApplicationScopeImpl(
+            new SimpleId(applicationId, TYPE_APPLICATION)));
+        ei.deleteIndex();
+    }
 
 
     @Override
@@ -395,6 +423,11 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
                     managerCache.getEntityCollectionManager( collScope ).load( targetId )
                         .toBlockingObservable().lastOrDefault(null);
 
+            if ( e == null ) {
+                logger.warn("Applicaion {} in index but not found in collections", targetId );
+                continue;
+            } 
+            
             appMap.put(
                 (String)e.getField( PROPERTY_NAME ).getValue(),
                 (UUID)e.getField( "applicationUuid" ).getValue());
@@ -407,6 +440,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     @Override
     public void setup() throws Exception {
         getSetup().init();
+        init();
     }
 
 
@@ -460,7 +494,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
             propsEntity = EntityFactory.newEntity( UUIDUtils.newTimeUUID(), "propertymap");
         }
 
-        // intentionally going only one-level deep into fields and treating all 
+        // intentionally going only one-level deep into fields and treating all
         // values as strings because that is all we need for service properties
         for ( String key : properties.keySet() ) {
             propsEntity.setProperty( key, properties.get(key).toString() );
@@ -711,13 +745,13 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     public Health getEntityStoreHealth() {
 
         // could use any collection scope here, does not matter
-        EntityCollectionManager ecm = getManagerCache().getEntityCollectionManager( 
-            new CollectionScopeImpl( 
+        EntityCollectionManager ecm = getManagerCache().getEntityCollectionManager(
+            new CollectionScopeImpl(
                 new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application"),
                 new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application"),
                 "dummy"
         ));
-                 
+
         return ecm.getHealth();
-    } 
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7335f941/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManagerFactory.java
index af4acdb..a8dd404 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManagerFactory.java
@@ -57,8 +57,8 @@ public class HybridEntityManagerFactory implements EntityManagerFactory, Applica
     }
 
     @Override
-    public String getImpementationDescription() throws Exception {
-        return factory.getImpementationDescription();
+    public String getImplementationDescription() throws Exception {
+        return factory.getImplementationDescription();
     }
 
     @Override
@@ -78,6 +78,11 @@ public class HybridEntityManagerFactory implements EntityManagerFactory, Applica
     }
 
     @Override
+    public void deleteApplication(UUID applicationId) throws Exception {
+        factory.deleteApplication( applicationId );
+    }
+
+    @Override
     public UUID importApplication(String organization, UUID applicationId, String name, 
             Map<String, Object> properties) throws Exception {
         return factory.importApplication(organization, applicationId, name, properties);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7335f941/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
index 3d4827b..b4bfbd2 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
@@ -40,7 +40,7 @@ public interface EntityManagerFactory {
      *
      * @throws Exception the exception
      */
-    public abstract String getImpementationDescription() throws Exception;
+    public abstract String getImplementationDescription() throws Exception;
 
     /**
      * Gets the entity manager.
@@ -73,9 +73,16 @@ public interface EntityManagerFactory {
      *
      * @throws Exception the exception
      */
-    public abstract UUID createApplication( 
+    public abstract UUID createApplication(
             String organizationName, String name, Map<String, Object> properties ) throws Exception;
 
+    /**
+     * Delete Application.
+     *
+     * @param applicationId UUID of Application to be deleted.
+     */
+    public abstract void deleteApplication( UUID applicationId ) throws Exception;
+
     public abstract UUID importApplication( String organization, UUID applicationId, String name,
                                             Map<String, Object> properties ) throws Exception;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7335f941/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
index f073da7..a598a82 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
@@ -119,10 +119,10 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
     /*
      * (non-Javadoc)
      * 
-     * @see org.apache.usergrid.core.Datastore#getImpementationDescription()
+     * @see org.apache.usergrid.core.Datastore#getImplementationDescription()
      */
     @Override
-    public String getImpementationDescription() {
+    public String getImplementationDescription() {
         return IMPLEMENTATION_DESCRIPTION;
     }
 
@@ -218,6 +218,13 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
         return applicationId;
     }
 
+    
+    @Override
+    public void deleteApplication(UUID applicationId) throws Exception {
+        // TODO implement deleteApplication in Usergrid 1 code base (master branch?)
+        throw new UnsupportedOperationException("Not supported."); 
+    }
+
 
     private String buildAppName( String organizationName, String name ) {
         return StringUtils.lowerCase( name.contains( "/" ) ? name : organizationName + "/" + name );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7335f941/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index 4edd121..8841e56 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -17,39 +17,22 @@
 package org.apache.usergrid.persistence.cassandra;
 
 
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.apache.commons.lang3.RandomStringUtils;
-
 import org.apache.usergrid.AbstractCoreIT;
 import org.apache.usergrid.cassandra.CassandraResource;
 import org.apache.usergrid.cassandra.Concurrent;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.persistence.cassandra.util.TraceTag;
 import org.apache.usergrid.persistence.cassandra.util.TraceTagManager;
 import org.apache.usergrid.persistence.cassandra.util.TraceTagReporter;
 import org.apache.usergrid.persistence.index.impl.ElasticSearchResource;
+import org.junit.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 
 @Concurrent()
@@ -107,8 +90,43 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
     }
 
 
-    public void testRebuildIndexes() throws Exception {
+    @Test
+    public void testDeleteApplication() throws Exception {
+
+        String rand = RandomStringUtils.randomAlphabetic(20);
+
+        // create an application with a collection and an entity
 
+        UUID applicationId = setup.createApplication( "test-org-" + rand, "test-app-" + rand );
+
+        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+
+        Map<String, Object> properties1 = new LinkedHashMap<String, Object>();
+        properties1.put( "Name", "12 Angry Men" );
+        properties1.put( "Year", 1957 );
+        Entity film1 = em.create("film", properties1);
+
+        Map<String, Object> properties2 = new LinkedHashMap<String, Object>();
+        properties2.put( "Name", "Reservoir Dogs" );
+        properties2.put( "Year", 1992 );
+        Entity film2 = em.create( "film", properties2 );
+
+        em.refreshIndex();
+
+        // delete the application
+
+        setup.getEmf().deleteApplication( applicationId );
+
+        // attempt to get entities in application's collections in various ways should all fail
+
+        assertNull( setup.getEmf().lookupApplication("test-app-" + rand) );
+
+        Map<String, UUID> appMap = setup.getEmf().getApplications();
+        for ( String appName : appMap.keySet() ) {
+            UUID appId = appMap.get( appName );
+            assertNotEquals( appId, applicationId );
+            assertNotEquals( appName, "test-app-" + rand );
+        }
 
     }
 
@@ -119,7 +137,8 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
         traceTagManager.attach( traceTag );
         logger.info( "EntityDaoTest.testCreateAndGet" );
 
-        UUID applicationId = createApplication( "EntityManagerFactoryImplIT", "testCreateAndGet" + RandomStringUtils.randomAlphabetic(20)  );
+        UUID applicationId = createApplication( "EntityManagerFactoryImplIT", "testCreateAndGet"
+                + RandomStringUtils.randomAlphabetic(20)  );
         logger.info( "Application id " + applicationId );
 
         EntityManager em = emf.getEntityManager( applicationId );


[18/19] incubator-usergrid git commit: push sample

Posted by sf...@apache.org.
push sample


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 122607d13d5b551a1474eb4f748948922aa46f2c
Parents: 74ea17e
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Jan 22 08:47:41 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Jan 22 08:47:41 2015 -0700

----------------------------------------------------------------------
 .../Usergrid.Notifications/App.xaml             |   7 +
 .../Usergrid.Notifications/App.xaml.cs          | 131 ++++++++++++
 .../Assets/Logo.scale-240.png                   | Bin 0 -> 2516 bytes
 .../Assets/SmallLogo.scale-240.png              | Bin 0 -> 753 bytes
 .../Assets/SplashScreen.scale-240.png           | Bin 0 -> 14715 bytes
 .../Assets/Square71x71Logo.scale-240.png        | Bin 0 -> 1122 bytes
 .../Assets/StoreLogo.scale-240.png              | Bin 0 -> 2200 bytes
 .../Assets/WideLogo.scale-240.png               | Bin 0 -> 4530 bytes
 .../Usergrid.Notifications/MainPage.xaml        |  20 ++
 .../Usergrid.Notifications/MainPage.xaml.cs     |  89 ++++++++
 .../Package.StoreAssociation.xml                | 194 +++++++++++++++++
 .../Usergrid.Notifications/Package.appxmanifest |  32 +++
 .../Properties/AssemblyInfo.cs                  |  29 +++
 .../Usergrid.Notifications.csproj               | 139 ++++++++++++
 .../Usergrid.Notifications/Usergrid.cs          | 209 +++++++++++++++++++
 .../Usergrid.Notifications/packages.config      |   4 +
 16 files changed, 854 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/App.xaml
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/App.xaml b/sdks/dotnet/samples/notifications/Usergrid.Notifications/App.xaml
new file mode 100644
index 0000000..8a36359
--- /dev/null
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/App.xaml
@@ -0,0 +1,7 @@
+<Application
+    x:Class="Usergrid.Notifications.App"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:local="using:Usergrid.Notifications">
+
+</Application>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/App.xaml.cs
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/App.xaml.cs b/sdks/dotnet/samples/notifications/Usergrid.Notifications/App.xaml.cs
new file mode 100644
index 0000000..9bf62ac
--- /dev/null
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/App.xaml.cs
@@ -0,0 +1,131 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices.WindowsRuntime;
+using Windows.ApplicationModel;
+using Windows.ApplicationModel.Activation;
+using Windows.Foundation;
+using Windows.Foundation.Collections;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Controls.Primitives;
+using Windows.UI.Xaml.Data;
+using Windows.UI.Xaml.Input;
+using Windows.UI.Xaml.Media;
+using Windows.UI.Xaml.Media.Animation;
+using Windows.UI.Xaml.Navigation;
+
+// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
+
+namespace Usergrid.Notifications
+{
+    /// <summary>
+    /// Provides application-specific behavior to supplement the default Application class.
+    /// </summary>
+    public sealed partial class App : Application
+    {
+        private TransitionCollection transitions;
+
+        /// <summary>
+        /// Initializes the singleton application object.  This is the first line of authored code
+        /// executed, and as such is the logical equivalent of main() or WinMain().
+        /// </summary>
+        public App()
+        {
+            this.InitializeComponent();
+            this.Suspending += this.OnSuspending;
+        }
+
+        /// <summary>
+        /// Invoked when the application is launched normally by the end user.  Other entry points
+        /// will be used when the application is launched to open a specific file, to display
+        /// search results, and so forth.
+        /// </summary>
+        /// <param name="e">Details about the launch request and process.</param>
+        protected override void OnLaunched(LaunchActivatedEventArgs e)
+        {
+#if DEBUG
+            if (System.Diagnostics.Debugger.IsAttached)
+            {
+                this.DebugSettings.EnableFrameRateCounter = true;
+            }
+#endif
+
+            Frame rootFrame = Window.Current.Content as Frame;
+
+            // Do not repeat app initialization when the Window already has content,
+            // just ensure that the window is active
+            if (rootFrame == null)
+            {
+                // Create a Frame to act as the navigation context and navigate to the first page
+                rootFrame = new Frame();
+
+                // TODO: change this value to a cache size that is appropriate for your application
+                rootFrame.CacheSize = 1;
+
+                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
+                {
+                    // TODO: Load state from previously suspended application
+                }
+
+                // Place the frame in the current Window
+                Window.Current.Content = rootFrame;
+            }
+
+            if (rootFrame.Content == null)
+            {
+                // Removes the turnstile navigation for startup.
+                if (rootFrame.ContentTransitions != null)
+                {
+                    this.transitions = new TransitionCollection();
+                    foreach (var c in rootFrame.ContentTransitions)
+                    {
+                        this.transitions.Add(c);
+                    }
+                }
+
+                rootFrame.ContentTransitions = null;
+                rootFrame.Navigated += this.RootFrame_FirstNavigated;
+
+                // When the navigation stack isn't restored navigate to the first page,
+                // configuring the new page by passing required information as a navigation
+                // parameter
+                if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
+                {
+                    throw new Exception("Failed to create initial page");
+                }
+            }
+
+            // Ensure the current window is active
+            Window.Current.Activate();
+        }
+
+        /// <summary>
+        /// Restores the content transitions after the app has launched.
+        /// </summary>
+        /// <param name="sender">The object where the handler is attached.</param>
+        /// <param name="e">Details about the navigation event.</param>
+        private void RootFrame_FirstNavigated(object sender, NavigationEventArgs e)
+        {
+            var rootFrame = sender as Frame;
+            rootFrame.ContentTransitions = this.transitions ?? new TransitionCollection() { new NavigationThemeTransition() };
+            rootFrame.Navigated -= this.RootFrame_FirstNavigated;
+        }
+
+        /// <summary>
+        /// Invoked when application execution is being suspended.  Application state is saved
+        /// without knowing whether the application will be terminated or resumed with the contents
+        /// of memory still intact.
+        /// </summary>
+        /// <param name="sender">The source of the suspend request.</param>
+        /// <param name="e">Details about the suspend request.</param>
+        private void OnSuspending(object sender, SuspendingEventArgs e)
+        {
+            var deferral = e.SuspendingOperation.GetDeferral();
+
+            // TODO: Save application state and stop any background activity
+            deferral.Complete();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/Logo.scale-240.png
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/Logo.scale-240.png b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/Logo.scale-240.png
new file mode 100644
index 0000000..76921ca
Binary files /dev/null and b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/Logo.scale-240.png differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/SmallLogo.scale-240.png
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/SmallLogo.scale-240.png b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/SmallLogo.scale-240.png
new file mode 100644
index 0000000..3166301
Binary files /dev/null and b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/SmallLogo.scale-240.png differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/SplashScreen.scale-240.png
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/SplashScreen.scale-240.png b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/SplashScreen.scale-240.png
new file mode 100644
index 0000000..33f26b3
Binary files /dev/null and b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/SplashScreen.scale-240.png differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/Square71x71Logo.scale-240.png
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/Square71x71Logo.scale-240.png b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/Square71x71Logo.scale-240.png
new file mode 100644
index 0000000..cfa54be
Binary files /dev/null and b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/Square71x71Logo.scale-240.png differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/StoreLogo.scale-240.png
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/StoreLogo.scale-240.png b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/StoreLogo.scale-240.png
new file mode 100644
index 0000000..47e084b
Binary files /dev/null and b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/StoreLogo.scale-240.png differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/WideLogo.scale-240.png
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/WideLogo.scale-240.png b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/WideLogo.scale-240.png
new file mode 100644
index 0000000..6249d29
Binary files /dev/null and b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Assets/WideLogo.scale-240.png differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml
new file mode 100644
index 0000000..3e0affd
--- /dev/null
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml
@@ -0,0 +1,20 @@
+<Page
+    x:Class="Usergrid.Notifications.MainPage"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:local="using:Usergrid.Notifications"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    mc:Ignorable="d"
+    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
+
+    <Grid>
+        <TextBox x:Name="pushText" HorizontalAlignment="Left" Margin="75,46,0,0" TextWrapping="Wrap" Text="Push Text" VerticalAlignment="Top" Width="261" TextChanged="pushText_TextChanged"/>
+        <Button  Content="Send" HorizontalAlignment="Left" Margin="146,121,0,0" VerticalAlignment="Top" Click="Button_Click"/>
+        <TextBox x:Name="NotifierName" HorizontalAlignment="Left" Margin="75,210,0,0" TextWrapping="Wrap" Text="Notifier Name" VerticalAlignment="Top" Width="261"/>
+        <TextBox x:Name="Api_Key" HorizontalAlignment="Left" Margin="75,276,0,0" TextWrapping="Wrap" Text="Sid" VerticalAlignment="Top" Width="261"/>
+        <TextBox x:Name="Sid" HorizontalAlignment="Left" Margin="75,348,0,0" TextWrapping="Wrap" Text="Api Key" VerticalAlignment="Top" Width="261"/>
+        <Button x:Name="AddNotifierButton" Content="Add Notifier" HorizontalAlignment="Left" Margin="146,405,0,0" VerticalAlignment="Top" Click="AddNotifierButton_Click"/>
+
+    </Grid>
+</Page>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
new file mode 100644
index 0000000..882838d
--- /dev/null
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
@@ -0,0 +1,89 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices.WindowsRuntime;
+using Windows.Foundation;
+using Windows.Foundation.Collections;
+using Windows.Networking.PushNotifications;
+using Windows.Storage;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Controls.Primitives;
+using Windows.UI.Xaml.Data;
+using Windows.UI.Xaml.Input;
+using Windows.UI.Xaml.Media;
+using Windows.UI.Xaml.Navigation;
+
+// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
+
+namespace Usergrid.Notifications
+{
+    /// <summary>
+    /// An empty page that can be used on its own or navigated to within a Frame.
+    /// </summary>
+    public sealed partial class MainPage : Page
+    {
+        private Usergrid usergrid;
+        private string serverUrl;
+        private string org;
+        private string app;
+        private string notifier;
+        private string apiKey;
+        private string secret;
+        private Guid deviceId;
+        public MainPage()
+        {
+            this.InitializeComponent();
+            var myIp = "10.0.1.20";
+            serverUrl = "http://" + myIp + ":8080";
+            org = "mobile";
+            app = "sandbox";
+            notifier = "winphone";
+            this.NavigationCacheMode = NavigationCacheMode.Required;
+            this.setup();
+        }
+
+        private async void setup()
+        {
+            usergrid = new Usergrid(serverUrl, org, app);
+            await this.usergrid.Authenticate("superuser", "test", true);
+            await usergrid.Push.RegisterDevice(notifier);
+           
+            
+        }
+
+        /// <summary>
+        /// Invoked when this page is about to be displayed in a Frame.
+        /// </summary>
+        /// <param name="e">Event data that describes how this page was reached.
+        /// This parameter is typically used to configure the page.</param>
+        protected override void OnNavigatedTo(NavigationEventArgs e)
+        {
+            // TODO: Prepare page for display here.
+
+            // TODO: If your application contains multiple pages, ensure that you are
+            // handling the hardware Back button by registering for the
+            // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
+            // If you are using the NavigationHelper provided by some templates,
+            // this event is handled for you.
+        }
+
+        private async void Button_Click(object sender, RoutedEventArgs e)
+        {
+
+            var message = this.pushText.Text;
+            await usergrid.Push.SendNotification(deviceId,message);
+        }
+
+        private void pushText_TextChanged(object sender, TextChangedEventArgs e)
+        {
+
+        }
+
+        private async void AddNotifierButton_Click(object sender, RoutedEventArgs e)
+        {
+            await usergrid.Push.AddNotifier(NotifierName.Text,Sid.Text,Api_Key.Text);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.StoreAssociation.xml
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.StoreAssociation.xml b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.StoreAssociation.xml
new file mode 100644
index 0000000..c6278a4
--- /dev/null
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.StoreAssociation.xml
@@ -0,0 +1,194 @@
+<?xml version="1.0" encoding="utf-8"?>
+<StoreAssociation xmlns="http://schemas.microsoft.com/appx/2010/storeassociation">
+  <Publisher>CN=AC3A1EB7-E4EA-48C0-9556-C37AA8BAE0CF</Publisher>
+  <PublisherDisplayName>feldrocker</PublisherDisplayName>
+  <GeneratePackageHash>http://www.w3.org/2001/04/xmlenc#sha256</GeneratePackageHash>
+  <SupportedLocales>
+    <Language Code="af" InMinimumRequirementSet="true" />
+    <Language Code="af-za" InMinimumRequirementSet="true" />
+    <Language Code="sq" InMinimumRequirementSet="true" />
+    <Language Code="sq-al" InMinimumRequirementSet="true" />
+    <Language Code="ar" InMinimumRequirementSet="true" />
+    <Language Code="ar-ae" InMinimumRequirementSet="true" />
+    <Language Code="ar-bh" InMinimumRequirementSet="true" />
+    <Language Code="ar-dz" InMinimumRequirementSet="true" />
+    <Language Code="ar-eg" InMinimumRequirementSet="true" />
+    <Language Code="ar-iq" InMinimumRequirementSet="true" />
+    <Language Code="ar-jo" InMinimumRequirementSet="true" />
+    <Language Code="ar-kw" InMinimumRequirementSet="true" />
+    <Language Code="ar-lb" InMinimumRequirementSet="true" />
+    <Language Code="ar-ly" InMinimumRequirementSet="true" />
+    <Language Code="ar-ma" InMinimumRequirementSet="true" />
+    <Language Code="ar-om" InMinimumRequirementSet="true" />
+    <Language Code="ar-qa" InMinimumRequirementSet="true" />
+    <Language Code="ar-sa" InMinimumRequirementSet="true" />
+    <Language Code="ar-sy" InMinimumRequirementSet="true" />
+    <Language Code="ar-tn" InMinimumRequirementSet="true" />
+    <Language Code="ar-ye" InMinimumRequirementSet="true" />
+    <Language Code="az-latn" InMinimumRequirementSet="true" />
+    <Language Code="az-latn-az" InMinimumRequirementSet="true" />
+    <Language Code="az" InMinimumRequirementSet="true" />
+    <Language Code="eu" InMinimumRequirementSet="true" />
+    <Language Code="eu-es" InMinimumRequirementSet="true" />
+    <Language Code="be" InMinimumRequirementSet="true" />
+    <Language Code="be-by" InMinimumRequirementSet="true" />
+    <Language Code="pt-br" InMinimumRequirementSet="true" />
+    <Language Code="bg" InMinimumRequirementSet="true" />
+    <Language Code="bg-bg" InMinimumRequirementSet="true" />
+    <Language Code="ca" InMinimumRequirementSet="true" />
+    <Language Code="ca-es" InMinimumRequirementSet="true" />
+    <Language Code="hr" InMinimumRequirementSet="true" />
+    <Language Code="hr-hr" InMinimumRequirementSet="true" />
+    <Language Code="hr-ba" InMinimumRequirementSet="true" />
+    <Language Code="cs" InMinimumRequirementSet="true" />
+    <Language Code="cs-cz" InMinimumRequirementSet="true" />
+    <Language Code="da" InMinimumRequirementSet="true" />
+    <Language Code="da-dk" InMinimumRequirementSet="true" />
+    <Language Code="nl" InMinimumRequirementSet="true" />
+    <Language Code="nl-nl" InMinimumRequirementSet="true" />
+    <Language Code="nl-be" InMinimumRequirementSet="true" />
+    <Language Code="en" InMinimumRequirementSet="true" />
+    <Language Code="en-gb" InMinimumRequirementSet="true" />
+    <Language Code="en-029" InMinimumRequirementSet="true" />
+    <Language Code="en-au" InMinimumRequirementSet="true" />
+    <Language Code="en-bz" InMinimumRequirementSet="true" />
+    <Language Code="en-ie" InMinimumRequirementSet="true" />
+    <Language Code="en-in" InMinimumRequirementSet="true" />
+    <Language Code="en-jm" InMinimumRequirementSet="true" />
+    <Language Code="en-my" InMinimumRequirementSet="true" />
+    <Language Code="en-nz" InMinimumRequirementSet="true" />
+    <Language Code="en-ph" InMinimumRequirementSet="true" />
+    <Language Code="en-sg" InMinimumRequirementSet="true" />
+    <Language Code="en-tt" InMinimumRequirementSet="true" />
+    <Language Code="en-za" InMinimumRequirementSet="true" />
+    <Language Code="en-zw" InMinimumRequirementSet="true" />
+    <Language Code="en-hk" InMinimumRequirementSet="true" />
+    <Language Code="en-us" InMinimumRequirementSet="true" />
+    <Language Code="en-ca" InMinimumRequirementSet="true" />
+    <Language Code="et" InMinimumRequirementSet="true" />
+    <Language Code="et-ee" InMinimumRequirementSet="true" />
+    <Language Code="fil" InMinimumRequirementSet="true" />
+    <Language Code="fil-ph" InMinimumRequirementSet="true" />
+    <Language Code="fi" InMinimumRequirementSet="true" />
+    <Language Code="fi-fi" InMinimumRequirementSet="true" />
+    <Language Code="fr" InMinimumRequirementSet="true" />
+    <Language Code="fr-fr" InMinimumRequirementSet="true" />
+    <Language Code="fr-ca" InMinimumRequirementSet="true" />
+    <Language Code="fr-ch" InMinimumRequirementSet="true" />
+    <Language Code="fr-be" InMinimumRequirementSet="true" />
+    <Language Code="fr-lu" InMinimumRequirementSet="true" />
+    <Language Code="fr-mc" InMinimumRequirementSet="true" />
+    <Language Code="gl" InMinimumRequirementSet="true" />
+    <Language Code="gl-es" InMinimumRequirementSet="true" />
+    <Language Code="de" InMinimumRequirementSet="true" />
+    <Language Code="de-de" InMinimumRequirementSet="true" />
+    <Language Code="de-ch" InMinimumRequirementSet="true" />
+    <Language Code="de-at" InMinimumRequirementSet="true" />
+    <Language Code="de-li" InMinimumRequirementSet="true" />
+    <Language Code="de-lu" InMinimumRequirementSet="true" />
+    <Language Code="el" InMinimumRequirementSet="true" />
+    <Language Code="el-gr" InMinimumRequirementSet="true" />
+    <Language Code="ha-latn" InMinimumRequirementSet="true" />
+    <Language Code="ha-latn-ng" InMinimumRequirementSet="true" />
+    <Language Code="ha" InMinimumRequirementSet="true" />
+    <Language Code="he" InMinimumRequirementSet="true" />
+    <Language Code="he-il" InMinimumRequirementSet="true" />
+    <Language Code="hi" InMinimumRequirementSet="true" />
+    <Language Code="hi-in" InMinimumRequirementSet="true" />
+    <Language Code="hu" InMinimumRequirementSet="true" />
+    <Language Code="hu-hu" InMinimumRequirementSet="true" />
+    <Language Code="id" InMinimumRequirementSet="true" />
+    <Language Code="id-id" InMinimumRequirementSet="true" />
+    <Language Code="it" InMinimumRequirementSet="true" />
+    <Language Code="it-it" InMinimumRequirementSet="true" />
+    <Language Code="it-ch" InMinimumRequirementSet="true" />
+    <Language Code="ja" InMinimumRequirementSet="true" />
+    <Language Code="ja-jp" InMinimumRequirementSet="true" />
+    <Language Code="kk" InMinimumRequirementSet="true" />
+    <Language Code="kk-kz" InMinimumRequirementSet="true" />
+    <Language Code="ko" InMinimumRequirementSet="true" />
+    <Language Code="ko-kr" InMinimumRequirementSet="true" />
+    <Language Code="sr-latn" InMinimumRequirementSet="true" />
+    <Language Code="sr-latn-ba" InMinimumRequirementSet="true" />
+    <Language Code="sr-latn-cs" InMinimumRequirementSet="true" />
+    <Language Code="sr-latn-me" InMinimumRequirementSet="true" />
+    <Language Code="sr-latn-rs" InMinimumRequirementSet="true" />
+    <Language Code="sr" InMinimumRequirementSet="true" />
+    <Language Code="lv" InMinimumRequirementSet="true" />
+    <Language Code="lv-lv" InMinimumRequirementSet="true" />
+    <Language Code="lt" InMinimumRequirementSet="true" />
+    <Language Code="lt-lt" InMinimumRequirementSet="true" />
+    <Language Code="mk" InMinimumRequirementSet="true" />
+    <Language Code="mk-mk" InMinimumRequirementSet="true" />
+    <Language Code="ms" InMinimumRequirementSet="true" />
+    <Language Code="ms-my" InMinimumRequirementSet="true" />
+    <Language Code="ms-bn" InMinimumRequirementSet="true" />
+    <Language Code="nb" InMinimumRequirementSet="true" />
+    <Language Code="nb-no" InMinimumRequirementSet="true" />
+    <Language Code="fa" InMinimumRequirementSet="true" />
+    <Language Code="fa-ir" InMinimumRequirementSet="true" />
+    <Language Code="pl" InMinimumRequirementSet="true" />
+    <Language Code="pl-pl" InMinimumRequirementSet="true" />
+    <Language Code="pt" InMinimumRequirementSet="true" />
+    <Language Code="pt-pt" InMinimumRequirementSet="true" />
+    <Language Code="ro" InMinimumRequirementSet="true" />
+    <Language Code="ro-ro" InMinimumRequirementSet="true" />
+    <Language Code="ru" InMinimumRequirementSet="true" />
+    <Language Code="ru-ru" InMinimumRequirementSet="true" />
+    <Language Code="zh" InMinimumRequirementSet="true" />
+    <Language Code="zh-cn" InMinimumRequirementSet="true" />
+    <Language Code="zh-hans" InMinimumRequirementSet="true" />
+    <Language Code="zh-sg" InMinimumRequirementSet="true" />
+    <Language Code="sk" InMinimumRequirementSet="true" />
+    <Language Code="sk-sk" InMinimumRequirementSet="true" />
+    <Language Code="sl" InMinimumRequirementSet="true" />
+    <Language Code="sl-si" InMinimumRequirementSet="true" />
+    <Language Code="es" InMinimumRequirementSet="true" />
+    <Language Code="es-es" InMinimumRequirementSet="true" />
+    <Language Code="es-mx" InMinimumRequirementSet="true" />
+    <Language Code="es-ar" InMinimumRequirementSet="true" />
+    <Language Code="es-bo" InMinimumRequirementSet="true" />
+    <Language Code="es-cl" InMinimumRequirementSet="true" />
+    <Language Code="es-co" InMinimumRequirementSet="true" />
+    <Language Code="es-cr" InMinimumRequirementSet="true" />
+    <Language Code="es-do" InMinimumRequirementSet="true" />
+    <Language Code="es-ec" InMinimumRequirementSet="true" />
+    <Language Code="es-gt" InMinimumRequirementSet="true" />
+    <Language Code="es-hn" InMinimumRequirementSet="true" />
+    <Language Code="es-ni" InMinimumRequirementSet="true" />
+    <Language Code="es-pa" InMinimumRequirementSet="true" />
+    <Language Code="es-pe" InMinimumRequirementSet="true" />
+    <Language Code="es-pr" InMinimumRequirementSet="true" />
+    <Language Code="es-py" InMinimumRequirementSet="true" />
+    <Language Code="es-sv" InMinimumRequirementSet="true" />
+    <Language Code="es-us" InMinimumRequirementSet="true" />
+    <Language Code="es-uy" InMinimumRequirementSet="true" />
+    <Language Code="es-ve" InMinimumRequirementSet="true" />
+    <Language Code="sv" InMinimumRequirementSet="true" />
+    <Language Code="sv-fi" InMinimumRequirementSet="true" />
+    <Language Code="sv-se" InMinimumRequirementSet="true" />
+    <Language Code="th" InMinimumRequirementSet="true" />
+    <Language Code="th-th" InMinimumRequirementSet="true" />
+    <Language Code="zh-hant" InMinimumRequirementSet="true" />
+    <Language Code="zh-hk" InMinimumRequirementSet="true" />
+    <Language Code="zh-mo" InMinimumRequirementSet="true" />
+    <Language Code="zh-tw" InMinimumRequirementSet="true" />
+    <Language Code="tr" InMinimumRequirementSet="true" />
+    <Language Code="tr-tr" InMinimumRequirementSet="true" />
+    <Language Code="uk" InMinimumRequirementSet="true" />
+    <Language Code="uk-ua" InMinimumRequirementSet="true" />
+    <Language Code="uz-latn" InMinimumRequirementSet="true" />
+    <Language Code="uz-latn-uz" InMinimumRequirementSet="true" />
+    <Language Code="uz" InMinimumRequirementSet="true" />
+    <Language Code="vi" InMinimumRequirementSet="true" />
+    <Language Code="vi-vn" InMinimumRequirementSet="true" />
+  </SupportedLocales>
+  <ProductReservedInfo>
+    <MainPackageIdentityName>15661feldrocker.usergridsample</MainPackageIdentityName>
+    <ReservedNames>
+      <ReservedName>usergrid sample</ReservedName>
+    </ReservedNames>
+  </ProductReservedInfo>
+  <AccountPackageIdentityNames />
+  <PackageInfoList LandingUrl="https://dev.windowsphone.com/AppSubmission/AssociationLanding?windowsProductId=142f4403-3810-4c59-8236-0afe0b8472bf" />
+</StoreAssociation>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.appxmanifest
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.appxmanifest b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.appxmanifest
new file mode 100644
index 0000000..a47ef82
--- /dev/null
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.appxmanifest
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
+  <Identity Name="15661feldrocker.usergridsample" Publisher="CN=AC3A1EB7-E4EA-48C0-9556-C37AA8BAE0CF" Version="1.1.0.0" />
+  <mp:PhoneIdentity PhoneProductId="c05b658a-0b41-4187-a6e4-ca186c2338de" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
+  <Properties>
+    <DisplayName>usergrid sample</DisplayName>
+    <PublisherDisplayName>feldrocker</PublisherDisplayName>
+    <Logo>Assets\StoreLogo.png</Logo>
+  </Properties>
+  <Prerequisites>
+    <OSMinVersion>6.3.1</OSMinVersion>
+    <OSMaxVersionTested>6.3.1</OSMaxVersionTested>
+  </Prerequisites>
+  <Resources>
+    <Resource Language="x-generate" />
+  </Resources>
+  <Applications>
+    <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="Usergrid.Notifications.App">
+      <m3:VisualElements DisplayName="usergrid sample" Square150x150Logo="Assets\Logo.png" Square44x44Logo="Assets\SmallLogo.png" Description="Usergrid.Notifications" ForegroundText="light" BackgroundColor="transparent" ToastCapable="true">
+        <m3:DefaultTile Wide310x150Logo="Assets\WideLogo.png" Square71x71Logo="Assets\Square71x71Logo.png">
+        </m3:DefaultTile>
+        <m3:SplashScreen Image="Assets\SplashScreen.png" />
+        <m3:InitialRotationPreference>
+          <m3:Rotation Preference="portrait" />
+        </m3:InitialRotationPreference>
+      </m3:VisualElements>
+    </Application>
+  </Applications>
+  <Capabilities>
+    <Capability Name="internetClientServer" />
+  </Capabilities>
+</Package>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Properties/AssemblyInfo.cs b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..daf5838
--- /dev/null
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Properties/AssemblyInfo.cs
@@ -0,0 +1,29 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Usergrid.Notifications")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Usergrid.Notifications")]
+[assembly: AssemblyCopyright("Copyright ©  2015")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: ComVisible(false)]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/Usergrid.Notifications.csproj
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Usergrid.Notifications.csproj b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Usergrid.Notifications.csproj
new file mode 100644
index 0000000..c811c83
--- /dev/null
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Usergrid.Notifications.csproj
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{EB364B8E-B7C1-45C2-BF13-1CBF731EA8B6}</ProjectGuid>
+    <OutputType>AppContainerExe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Usergrid.Notifications</RootNamespace>
+    <AssemblyName>Usergrid.Notifications</AssemblyName>
+    <DefaultLanguage>en-US</DefaultLanguage>
+    <TargetPlatformVersion>8.1</TargetPlatformVersion>
+    <MinimumVisualStudioVersion>12</MinimumVisualStudioVersion>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{76F1466A-8B6D-4E39-A767-685A06062A39};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
+    <AppxBundlePlatforms>neutral</AppxBundlePlatforms>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\ARM\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
+    <NoWarn>;2008</NoWarn>
+    <DebugType>full</DebugType>
+    <PlatformTarget>ARM</PlatformTarget>
+    <UseVSHostingProcess>false</UseVSHostingProcess>
+    <ErrorReport>prompt</ErrorReport>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
+    <OutputPath>bin\ARM\Release\</OutputPath>
+    <DefineConstants>TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
+    <Optimize>true</Optimize>
+    <NoWarn>;2008</NoWarn>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>ARM</PlatformTarget>
+    <UseVSHostingProcess>false</UseVSHostingProcess>
+    <ErrorReport>prompt</ErrorReport>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x86\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
+    <NoWarn>;2008</NoWarn>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <UseVSHostingProcess>false</UseVSHostingProcess>
+    <ErrorReport>prompt</ErrorReport>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
+    <OutputPath>bin\x86\Release\</OutputPath>
+    <DefineConstants>TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
+    <Optimize>true</Optimize>
+    <NoWarn>;2008</NoWarn>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <UseVSHostingProcess>false</UseVSHostingProcess>
+    <ErrorReport>prompt</ErrorReport>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="App.xaml.cs">
+      <DependentUpon>App.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="MainPage.xaml.cs">
+      <DependentUpon>MainPage.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Usergrid.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <AppxManifest Include="Package.appxmanifest">
+      <SubType>Designer</SubType>
+    </AppxManifest>
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="Assets\Logo.scale-240.png" />
+    <Content Include="Assets\SmallLogo.scale-240.png" />
+    <Content Include="Assets\SplashScreen.scale-240.png" />
+    <Content Include="Assets\Square71x71Logo.scale-240.png" />
+    <Content Include="Assets\StoreLogo.scale-240.png" />
+    <Content Include="Assets\WideLogo.scale-240.png" />
+    <None Include="Package.StoreAssociation.xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <ApplicationDefinition Include="App.xaml">
+      <Generator>MSBuild:Compile</Generator>
+      <SubType>Designer</SubType>
+    </ApplicationDefinition>
+    <Page Include="MainPage.xaml">
+      <Generator>MSBuild:Compile</Generator>
+      <SubType>Designer</SubType>
+    </Page>
+  </ItemGroup>
+  <ItemGroup>
+    <Reference Include="Newtonsoft.Json">
+      <HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </ItemGroup>
+  <PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '12.0' ">
+    <VisualStudioVersion>12.0</VisualStudioVersion>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(TargetPlatformIdentifier)' == '' ">
+    <TargetPlatformIdentifier>WindowsPhoneApp</TargetPlatformIdentifier>
+  </PropertyGroup>
+  <Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/Usergrid.cs
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Usergrid.cs b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Usergrid.cs
new file mode 100644
index 0000000..cc715f8
--- /dev/null
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Usergrid.cs
@@ -0,0 +1,209 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Net;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Json;
+using System.Text;
+using Newtonsoft.Json.Linq;
+using Newtonsoft.Json;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using Windows.Storage;
+using Windows.Networking.PushNotifications;
+
+namespace Usergrid.Notifications
+{
+    public class Usergrid : UsergridHttpClient
+    {
+        private string url;
+        private string token;
+        private HttpClient client;
+        private PushClient push;
+        private string managementUrl;
+
+        public Usergrid(string url, string org, string app)
+        {
+            string urlWithSlash = url.EndsWith("/",StringComparison.CurrentCulture) ? url : url+"/";
+            this.url = String.Format("{0}{1}/{2}/", urlWithSlash, org, app);
+            this.managementUrl = urlWithSlash + "management/";
+            this.client = new HttpClient();
+            push = new PushClient(this);
+        }
+
+        public async Task Authenticate(string user, string password, bool isManagement)
+        {
+            var url = "token";
+            var jsonObject = new JObject();
+            jsonObject.Add("username", user);
+            jsonObject.Add("password", password);
+            jsonObject.Add("grant_type", "password");
+            HttpResponseMessage response = await SendAsync(HttpMethod.Post,url, jsonObject, isManagement);
+
+            if (response.StatusCode == HttpStatusCode.OK)
+            {
+                JObject jsonResponse = await GetJsonResponse(response);
+                this.token = jsonResponse.GetValue("access_token").Value<String>();
+                client.DefaultRequestHeaders.Add("X-Authorization", token);
+            }
+            else
+            {
+                throw new Exception("Authentication failed");
+            }
+        }
+
+        public async Task<JObject> GetJsonResponse(HttpResponseMessage response)
+        {
+            JObject jsonResponse = null;
+            using (var stream = await response.Content.ReadAsStreamAsync())
+            {
+                using (var reader = new StreamReader(stream, Encoding.UTF8))
+                {
+                    jsonResponse = JObject.Parse(reader.ReadToEnd());
+                }
+            }
+            return jsonResponse;
+        }
+
+        private HttpContent getJsonBody(Object jsonObject)
+        {
+            var content =  new StringContent(JsonConvert.SerializeObject(jsonObject));
+            return content;
+        }
+        public  Task<HttpResponseMessage> SendAsync(HttpMethod method, string url, object obj)
+        {
+            return SendAsync(method, url, obj, false);
+        }
+        public Task<HttpResponseMessage> SendAsync(HttpMethod method, string url, object obj, bool useManagementUrl)
+        {
+            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, (useManagementUrl ? this.managementUrl : this.url) + url);
+            if(obj!=null)
+                message.Content = getJsonBody(obj);
+            message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue( "application/json"));
+            return this.client.SendAsync(message);
+
+        }
+   
+        public PushClient Push
+        {
+            get { return push; }
+        }
+
+
+    }
+
+    public interface UsergridHttpClient
+    {
+        Task<HttpResponseMessage>SendAsync(HttpMethod method,string url, object obj);
+        Task<JObject> GetJsonResponse(HttpResponseMessage response);
+
+    }
+    public class PushClient
+    {
+        private UsergridHttpClient usergrid;
+        
+        public PushClient(UsergridHttpClient usergrid)
+        { 
+            this.usergrid = usergrid; 
+        }
+
+        public async Task<bool> SendNotification(string message)
+        {
+            if (DeviceId == null)
+            {
+                throw new Exception("Please call PushClient.RegisterDevice first.");
+            }
+            var jsonObject = new JObject();
+            var payloads = new JObject();
+            var payload = new JObject();
+            payload.Add("toast", new JValue(message));
+            payloads.Add("winphone", payload);
+            jsonObject.Add("payloads",payloads);
+            jsonObject.Add("debug", true);
+            var response = await usergrid.SendAsync(HttpMethod.Post,String.Format("devices/{0}/notifications",deviceId), jsonObject);
+            var status = response.StatusCode;
+            JObject jsonResponse = await usergrid.GetJsonResponse(response);
+            return (status == HttpStatusCode.OK);
+        }
+
+        public async Task RegisterDevice(string notifier)
+        {
+            this.Notifier = notifier;
+            var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
+            var settings = ApplicationData.Current.LocalSettings;
+            if (!settings.Values.ContainsKey("currentDeviceId"))
+            {
+                Guid uuid = await registerDevice(notifier, channel.Uri);
+                settings.Values.Add("currentDeviceId", uuid);
+                this.DeviceId = uuid;
+            }
+            else
+            {
+                object tempId;
+                settings.Values.TryGetValue("currentDeviceId", out tempId);
+                this.DeviceId = Guid.Parse(tempId.ToString());
+                if (!await DeviceExists(DeviceId))
+                {
+                    Guid uuid = await registerDevice(notifier, channel.Uri);
+                    settings.Values["currentDeviceId"] = uuid;
+                    this.DeviceId = uuid;
+                }
+
+            }
+
+           
+        }
+      
+        public async Task AddNotifier(string name, string sid, string apiKey)
+        {
+            JObject obj = new JObject();
+            obj.Add("name", new JValue(name));
+            obj.Add("sid", new JValue(sid));
+            obj.Add("provider", new JValue("windows"));
+            obj.Add("apiKey", new JValue(apiKey));
+            obj.Add("logging", new JValue(true));
+            HttpResponseMessage response = await usergrid.SendAsync(HttpMethod.Post, "notifiers", obj);
+
+            JObject jsonResponse = await usergrid.GetJsonResponse(response);
+            if (jsonResponse != null)
+            {
+                var body = jsonResponse.GetValue("entities").ToString();
+            }
+        }
+
+        public async Task<bool> DeviceExists(Guid deviceId)
+        {
+            HttpResponseMessage response = await usergrid.SendAsync(HttpMethod.Get, "devices/"+deviceId, null);
+            JObject jsonResponse = await usergrid.GetJsonResponse(response);
+            if (jsonResponse != null)
+            {
+                    var body = jsonResponse.GetValue("entities");
+                    return body!=null &&  body.Value<JArray>().Count > 0;
+            }
+            else { return false; }
+        }
+
+        private async Task<Guid> registerDevice(string notifier, string uri)
+        {
+            JObject obj = new JObject();
+            obj.Add(notifier + ".notifier.id", new JValue(uri));
+            HttpResponseMessage response = await usergrid.SendAsync(HttpMethod.Post, "devices/", obj);
+
+            JObject jsonResponse = await usergrid.GetJsonResponse(response);
+
+            if (response.StatusCode == HttpStatusCode.OK && jsonResponse != null)
+            {
+                var entity = jsonResponse.GetValue("entities").Value<JArray>()[0];
+                var uuid = Guid.Parse(entity.Value<String>("uuid"));
+                return uuid;
+            }
+            else { return Guid.Empty; }
+        }
+
+        public string Notifier { get; set; }
+        private Guid DeviceId { get; set; }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122607d1/sdks/dotnet/samples/notifications/Usergrid.Notifications/packages.config
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/packages.config b/sdks/dotnet/samples/notifications/Usergrid.Notifications/packages.config
new file mode 100644
index 0000000..efaa424
--- /dev/null
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Newtonsoft.Json" version="6.0.8" targetFramework="wpa81" />
+</packages>
\ No newline at end of file


[06/19] incubator-usergrid git commit: [USERGRID-320] Consistent method naming

Posted by sf...@apache.org.
[USERGRID-320] Consistent method naming


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 8fb45d15f3f266a2ba36236efe281363ef3ab21e
Parents: c078ae1
Author: ryan bridges <rb...@apigee.com>
Authored: Mon Jan 12 11:37:21 2015 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Mon Jan 12 11:37:21 2015 -0500

----------------------------------------------------------------------
 .../rest/applications/queries/AndOrQueryTest.java       | 12 ++++++------
 .../rest/applications/queries/BadGrammarQueryTest.java  |  2 +-
 .../usergrid/rest/applications/queries/OrderByTest.java | 12 ++++++------
 3 files changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8fb45d15/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 6cd21da..d5956b5 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
@@ -46,7 +46,7 @@ public class AndOrQueryTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    public void andQueryInclusive() throws IOException {
+    public void queryAndInclusive() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
@@ -74,7 +74,7 @@ public class AndOrQueryTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    public void andQueryExclusive() throws IOException {
+    public void queryAndExclusive() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
 
@@ -102,7 +102,7 @@ public class AndOrQueryTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    public void orQueryInclusive() throws IOException {
+    public void queryOrInclusive() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
 
@@ -138,7 +138,7 @@ public class AndOrQueryTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    public void orQueryExclusive() throws IOException {
+    public void queryOrExclusive() throws IOException {
         int numOfEntities = 30;
         String collectionName = "activities";
 
@@ -177,7 +177,7 @@ public class AndOrQueryTest extends QueryTestBase {
      * @throws IOException
      */
     @Test //USERGRID-900
-    public void queriesWithAndPastLimit() throws IOException {
+    public void queryWithAndPastLimit() throws IOException {
         int numValuesTested = 40;
 
         generateTestEntities(numValuesTested, "activities");
@@ -204,7 +204,7 @@ public class AndOrQueryTest extends QueryTestBase {
      * @throws IOException
      */
     @Test //USERGRID-1475
-    public void negatedQuery() throws IOException {
+    public void queryNegated() throws IOException {
         int numValuesTested = 20;
 
         generateTestEntities(numValuesTested, "activities");

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8fb45d15/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 4dd7548..49120ab 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
@@ -41,7 +41,7 @@ public class BadGrammarQueryTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    public void catchBadQueryGrammar() throws IOException {
+    public void exceptionOnInvalidOperator() throws IOException {
 
         int numOfEntities = 1;
         String collectionName = "things";

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8fb45d15/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 a30168a..1e3b1b7 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
@@ -45,7 +45,7 @@ public class OrderByTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    public void testSortLongAsc() throws IOException {
+    public void orderByLongAsc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
@@ -71,7 +71,7 @@ public class OrderByTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    public void testSortLongDesc() throws IOException {
+    public void orderByLongDesc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
@@ -97,7 +97,7 @@ public class OrderByTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    public void testSortBooleanAsc() throws IOException {
+    public void orderByBooleanAsc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
@@ -126,7 +126,7 @@ public class OrderByTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    public void testSortBooleanDesc() throws IOException {
+    public void orderByBooleanDesc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
@@ -156,7 +156,7 @@ public class OrderByTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    public void testSortStringAsc() throws IOException {
+    public void orderByStringAsc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities
@@ -185,7 +185,7 @@ public class OrderByTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    public void testSortStringDesc() throws IOException {
+    public void orderByStringDesc() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
         //create our test entities


[14/19] incubator-usergrid git commit: Beginnings of a REST test.

Posted by sf...@apache.org.
Beginnings of a REST test.


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 4384975fa91d2c7e5ffad06f9adf4a16855d3839
Parents: 7335f94
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Jan 20 16:30:53 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Jan 20 16:30:53 2015 -0500

----------------------------------------------------------------------
 .../rest/applications/ApplicationResource.java  | 32 +++++++++---
 .../applications/ApplicationDeleteTest.java     | 54 ++++++++++++++++++++
 2 files changed, 80 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4384975f/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
index 6144940..6a3c94c 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
@@ -38,6 +38,13 @@ import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
+import org.apache.usergrid.rest.ApiResponse;
+import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;
+import org.apache.usergrid.services.ServiceAction;
+import org.apache.usergrid.services.ServiceResults;
+import org.apache.usergrid.services.assets.data.AssetUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Scope;
@@ -495,15 +502,28 @@ public class ApplicationResource extends ServiceResource {
 
 
     @DELETE
-    @RequireApplicationAccess
+    @RequireOrganizationAccess
     @Override
-    public JSONWithPadding executeDelete( @Context UriInfo ui,
-                                          @QueryParam("callback") @DefaultValue("callback") String callback )
-            throws Exception {
+    public JSONWithPadding executeDelete(  @Context UriInfo ui,
+        @QueryParam("callback") @DefaultValue("callback") String callback ) throws Exception {
+        
+        if ( applicationId == null ) {
+            throw new IllegalArgumentException("Application ID not specified in request");
+        }
+        
+        ApplicationInfo app = management.getApplicationInfo( applicationId );
+        if ( app == null ) {
+            throw new EntityNotFoundException("Application ID " + applicationId + " not found");
+        }
+        
+        emf.deleteApplication( applicationId );
 
-        logger.debug( "ApplicationResource.executeDelete" );
+        ApiResponse response = createApiResponse();
+        response.setAction( "delete" );
+        response.setApplication( services.getApplication() );
+        response.setParams( ui.getQueryParameters() );
 
-        throw new NotImplementedException( "Application delete is not allowed yet" );
+        return new JSONWithPadding( response, callback );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4384975f/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
new file mode 100644
index 0000000..e74b324
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.usergrid.rest.applications;
+
+
+import org.apache.usergrid.rest.AbstractRestIT;
+import org.apache.usergrid.rest.TestContextSetup;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ApplicationDeleteTest  extends AbstractRestIT {
+    private static final Logger log = LoggerFactory.getLogger(ApplicationDeleteTest.class);
+
+    @Rule
+    public TestContextSetup context = new TestContextSetup( this );
+
+    @Test
+    public void testBasicOperation() throws Exception {
+
+        // create a user
+        
+        // crete an organization 
+        
+        // create an application
+        
+        // create a collection with two entities
+        
+        // test that we can query those entities
+        
+        // delete the application
+        
+        // test that we cannot delete the application a second time
+        
+        // test that we can no longer query for those entities
+    }
+}


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

Posted by sf...@apache.org.
[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);
-  }
 }


[02/19] incubator-usergrid git commit: [USERGRID-320] Fixed casting error in GeoPagingTest due to framework change

Posted by sf...@apache.org.
[USERGRID-320] Fixed casting error in GeoPagingTest due to framework change


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 5c23a7fcded09a0c35e8aaf31b6bbce556d19a2e
Parents: cbe8468
Author: ryan bridges <rb...@apigee.com>
Authored: Mon Jan 12 10:53:42 2015 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Mon Jan 12 10:53:42 2015 -0500

----------------------------------------------------------------------
 .../apache/usergrid/rest/applications/queries/GeoPagingTest.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5c23a7fc/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 044a249..6c48af2 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
@@ -198,7 +198,7 @@ public class GeoPagingTest extends AbstractRestIT {
       // 3. Test that the entities were returned in the order expected
       for (int i = 0; i < 3; i++) {
         // shouldn't start at 10 since you're excluding it above in the query, it should return 9,8,7
-        LinkedHashMap<String, Object> entity = (LinkedHashMap<String, Object>) entities.get(i);
+        Entity entity = (Entity)entities.get(i);
         Entity savedEntity = saved[7 + i];
         assertEquals(savedEntity.get("uuid"), entity.get("uuid"));
       }


[09/19] incubator-usergrid git commit: [USERGRID-326] Additional corrections and comments

Posted by sf...@apache.org.
[USERGRID-326] Additional corrections 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/2b7d2318
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2b7d2318
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2b7d2318

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 2b7d2318c6699838b980e1627e374958172ef862
Parents: 8daa6e5
Author: ryan bridges <rb...@apigee.com>
Authored: Wed Jan 14 18:45:52 2015 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Wed Jan 14 18:45:52 2015 -0500

----------------------------------------------------------------------
 .../apache/usergrid/rest/PartialUpdateTest.java | 27 ++++++++++----------
 .../endpoints/CollectionEndpoint.java           |  2 +-
 2 files changed, 14 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2b7d2318/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
index bdc4e66..e6ada31 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
@@ -77,8 +77,6 @@ public class PartialUpdateTest extends AbstractRestIT {
             try {
                 // PUT the updates to the user and ensure they were saved
                 userNode = this.app().collection("users").entity(userNode).put(updateProps);
-                assertNotNull(userNode);
-
             } catch (UniformInterfaceException uie) {
                 fail("Update failed due to: " + uie.getResponse().getEntity(String.class));
             }
@@ -112,23 +110,24 @@ public class PartialUpdateTest extends AbstractRestIT {
                 Double.parseDouble(((Map<String, Object>) userNode.get("location")).get("longitude").toString()), 0);
         }
 
-        // Update bart's employer without specifying any required fields
+        // Update bart's employer without specifying the full entity
         // (this time with username specified in URL)
         Entity updateProps = new Entity();
         updateProps.put("employer", "ACME Corporation");
 
-        for (int i = 1; i < 10; i++) {
-            try {
-                userNode = this.app().collection("users").entity((String) props.get("username")).put(updateProps);
+        try { //  PUT /users/fred   put /users/uuid
+            userNode = this.app().collection("users").entity(props.getString("username")).put(updateProps);
 
-            } catch (UniformInterfaceException uie) {
-                fail("Update failed due to: " + uie.getResponse().getEntity(String.class));
-            }
-            refreshIndex();
-
-            userNode = this.app().collection("users").entity(userNode).get();
-            assertNotNull(userNode);
-            assertEquals("ACME Corporation", userNode.get("employer").toString());
+        } catch (UniformInterfaceException uie) {
+            fail("Update failed due to: " + uie.getResponse().getEntity(String.class));
         }
+        refreshIndex();
+
+        userNode = this.app().collection("users").entity(userNode).get();
+        assertNotNull(userNode);
+        //Test that the updated property is returned
+        assertEquals(updateProps.get("employer"), userNode.get("employer").toString());
+        //Test that the original properties are still there
+        assertEquals(props.get("username").toString(), userNode.get("username").toString());
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2b7d2318/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 325a5fa..3cb7a32 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
@@ -49,7 +49,7 @@ public class CollectionEndpoint extends NamedResource {
 
 
     public EntityEndpoint entity(final String identifier ){
-        return new EntityEndpoint(identifier, context, this);
+        return uniqueID(identifier);
     }
 
 


[12/19] incubator-usergrid git commit: Merge remote-tracking branch 'r3b/USERGRID-320' into apache_usergrid/two-dot-o

Posted by sf...@apache.org.
Merge remote-tracking branch 'r3b/USERGRID-320' into apache_usergrid/two-dot-o


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: e6561c77864aad2ca016d524e837c346f7bbd3b0
Parents: bcabda2 3ad331b
Author: Rod Simpson <ro...@apigee.com>
Authored: Tue Jan 20 10:58:54 2015 -0700
Committer: Rod Simpson <ro...@apigee.com>
Committed: Tue Jan 20 10:58:54 2015 -0700

----------------------------------------------------------------------
 .../applications/queries/AndOrQueryTest.java    | 528 ++++++++++---------
 .../queries/BadGrammarQueryTest.java            | 213 ++++++--
 .../applications/queries/GeoPagingTest.java     |   2 +-
 .../rest/applications/queries/OrderByTest.java  | 447 +++++++++++-----
 .../applications/queries/QueryTestBase.java     |  56 ++
 5 files changed, 843 insertions(+), 403 deletions(-)
----------------------------------------------------------------------



[08/19] incubator-usergrid git commit: [USERGRID-320] Added/Updated comments

Posted by sf...@apache.org.
[USERGRID-320] Added/Updated 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/3ad331b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/3ad331b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/3ad331b6

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 3ad331b6e84173173911dbe1fe8241398889049b
Parents: 8fb45d1
Author: ryan bridges <rb...@apigee.com>
Authored: Wed Jan 14 18:23:49 2015 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Wed Jan 14 18:23:49 2015 -0500

----------------------------------------------------------------------
 .../applications/queries/AndOrQueryTest.java    | 38 +++++++++++++-------
 .../queries/BadGrammarQueryTest.java            |  6 ++--
 .../rest/applications/queries/OrderByTest.java  | 16 ++++++---
 3 files changed, 41 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ad331b6/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 d5956b5..fbd067e 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
@@ -33,7 +33,6 @@ import static org.junit.Assert.*;
 /**
  * // TODO: Document this
  *
- * @author ApigeeCorporation
  * @since 4.0
  */
 public class AndOrQueryTest extends QueryTestBase {
@@ -49,20 +48,22 @@ public class AndOrQueryTest extends QueryTestBase {
     public void queryAndInclusive() throws IOException {
         int numOfEntities = 20;
         String collectionName = "activities";
-        //create our test entities
+        // create our test entities
         generateTestEntities(numOfEntities, collectionName);
-        //Query where madeup = true (the last half) and the last quarter of entries
+        // 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));
         Collection activities = this.app().collection("activities").get(params);
-        //results should have madeup = true and ordinal 15-19
+        // results should have madeup = true and ordinal 15-19
         assertEquals(numOfEntities / 4, activities.getResponse().getEntityCount());
+        // loop though entities that were returned, and test against the ordinals and values we are
+        // expecting, starting with the last entity and decrementing
         int index = 19;
         while (activities.hasNext()) {
             Entity activity = activities.next();
-            //ensure the 'madeup' property is set to true
+            // ensure the 'madeup' property is set to true
             assertTrue(Boolean.parseBoolean(activity.get("madeup").toString()));
-            //make sure the correct ordinal properties are returned
+            // make sure the correct ordinal properties are returned
             assertEquals(index--, Long.parseLong(activity.get("ordinal").toString()));
         }
 
@@ -86,6 +87,8 @@ public class AndOrQueryTest extends QueryTestBase {
         Collection activities = this.app().collection("activities").get(params);
         //results should have madeup = true and ordinal 10-14
         assertEquals(numOfEntities / 4, activities.getResponse().getEntityCount());
+        // loop though entities that were returned, and test against the ordinals and values we are
+        // expecting, starting with the last expected entity and decrementing
         int index = 14;
         while (activities.hasNext()) {
             Entity activity = activities.next();
@@ -116,19 +119,26 @@ public class AndOrQueryTest extends QueryTestBase {
         int index = numOfEntities - 1;
         int count = 0;
         int returnSize = activities.getResponse().getEntityCount();
+        //loop through the returned results
         for (int i = 0; i < returnSize; i++, index--) {
             count++;
             Entity activity = activities.getResponse().getEntities().get(i);
             log.info(String.valueOf(activity.get("ordinal")) + " " + String.valueOf(activity.get("madeup")));
+            //if the entity is in the first half, the property "madeup" should be false
             if (index < numOfEntities / 2) {
                 assertFalse(Boolean.parseBoolean(String.valueOf(activity.get("madeup"))));
-            } else if (index >= (numOfEntities - numOfEntities / 4)) {
+            }
+            //else if the entity is in the second half, the property "madeup" should be true
+            else if (index >= (numOfEntities - numOfEntities / 4)) {
                 assertTrue(Boolean.parseBoolean(String.valueOf(activity.get("madeup"))));
             }
+            //test to ensure that the ordinal is in the first half (where "madeup = false")
+            //OR that the ordinal is in the last quarter of the entity list (where "ordinal >=  (numOfEntities - numOfEntities / 4))")
             long ordinal = Long.parseLong(String.valueOf(activity.get("ordinal")));
             assertTrue(ordinal < (numOfEntities / 2) || ordinal >= (numOfEntities - numOfEntities / 4));
         }
-        //results should have madeup = false or ordinal 15-19
+        //results should have madeup = false or ordinal 0-9,15-19
+        //A total of 15 entities should be returned
         assertEquals(3 * numOfEntities / 4, count);
     }
 
@@ -158,13 +168,17 @@ public class AndOrQueryTest extends QueryTestBase {
             Entity activity = activities.getResponse().getEntities().get(i);
             long ordinal = Long.parseLong(String.valueOf(activity.get("ordinal")));
             log.info(ordinal + " " + String.valueOf(activity.get("verb")));
+            //if the entity is in the first three quarters, the property "verb" should be "go"
             if (ordinal < (numOfEntities - numOfEntities / 4)) {
                 assertEquals("go", String.valueOf(activity.get("verb")));
-            } else if (ordinal >= (numOfEntities - numOfEntities / 4)) {
+            }
+            //if the entity is in the last quarter, the property "verb" should be "stop"
+            else if (ordinal >= (numOfEntities - numOfEntities / 4)) {
                 assertEquals("stop", String.valueOf(activity.get("verb")));
             }
         }
         //results should be even ordinals in the first 3 quarters and odd ordinals from the last quarter
+        //Should return 1 more than half the number of entities
         assertEquals(1 + numOfEntities / 2, count);
     }
 
@@ -176,7 +190,7 @@ public class AndOrQueryTest extends QueryTestBase {
      *
      * @throws IOException
      */
-    @Test //USERGRID-900
+    @Test
     public void queryWithAndPastLimit() throws IOException {
         int numValuesTested = 40;
 
@@ -203,7 +217,7 @@ public class AndOrQueryTest extends QueryTestBase {
      *
      * @throws IOException
      */
-    @Test //USERGRID-1475
+    @Test
     public void queryNegated() throws IOException {
         int numValuesTested = 20;
 
@@ -229,7 +243,7 @@ public class AndOrQueryTest extends QueryTestBase {
      *
      * @throws Exception
      */
-    @Test //USERGRID-1615
+    @Test
     public void queryReturnCount() throws Exception {
         int numValuesTested = 20;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ad331b6/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 49120ab..fbc88c7 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
@@ -75,7 +75,7 @@ public class BadGrammarQueryTest extends QueryTestBase {
         generateTestEntities(numOfEntities, collectionName);
 
         //Issue an invalid query
-        String query = "select * where name != \"go\"";
+        String query = "select * where NOT name = \"go\"";
         try {
 
             QueryParameters params = new QueryParameters().setQuery(query);
@@ -112,12 +112,12 @@ public class BadGrammarQueryTest extends QueryTestBase {
             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 {
 
@@ -138,12 +138,12 @@ public class BadGrammarQueryTest extends QueryTestBase {
             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 {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ad331b6/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 1e3b1b7..75f4a3f 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
@@ -82,11 +82,13 @@ public class OrderByTest extends QueryTestBase {
             .setLimit(numOfEntities);
         Collection activities = this.app().collection("activities").get(params);
         assertEquals(numOfEntities, activities.getResponse().getEntityCount());
+        //Since the sort order is descending, start at the last entity we created
         int index = numOfEntities - 1;
         //results should be sorted by ordinal
         while (activities.hasNext()) {
             Entity activity = activities.next();
             //make sure the correct ordinal properties are returned
+            //decrement the index to get the next entity in reverse order
             assertEquals(index--, Long.parseLong(activity.get("ordinal").toString()));
         }
     }
@@ -110,6 +112,8 @@ public class OrderByTest extends QueryTestBase {
         assertEquals(numOfEntities, activities.getResponse().getEntityCount());
         int index = 0;
         //results should be sorted false, then true
+        //The first half of entities returned should have "madeup = false"
+        //The second half of entities returned should have "madeup = true"
         while (activities.hasNext()) {
             Entity activity = activities.next();
             if (index++ < numOfEntities / 2) {
@@ -142,6 +146,8 @@ public class OrderByTest extends QueryTestBase {
         while (activities.hasNext()) {
             Entity activity = activities.next();
             //make sure the booleans are ordered correctly
+            //The first half of entities returned should have "madeup = true"
+            //The second half of entities returned should have "madeup = false"
             if (index++ < numOfEntities / 2) {
                 assertEquals("true", activity.get("madeup").toString());
             } else {
@@ -161,7 +167,7 @@ public class OrderByTest extends QueryTestBase {
         String collectionName = "activities";
         //create our test entities
         generateTestEntities(numOfEntities, collectionName);
-
+        //Sort by the "verb" property to test alphabetical sorting of string properties
         QueryParameters params = new QueryParameters()
             .setQuery("select * order by verb asc")
             .setLimit(numOfEntities);
@@ -171,6 +177,8 @@ public class OrderByTest extends QueryTestBase {
         //results should be sorted "go", then "stop"
         while (activities.hasNext()) {
             Entity activity = activities.next();
+            //The first half of entities returned should have "verb = 'go'"
+            //The second half of entities returned should have "verb = 'stop'"
             if (index++ < numOfEntities / 2) {
                 assertEquals("go", activity.get("verb").toString());
             } else {
@@ -191,6 +199,7 @@ public class OrderByTest extends QueryTestBase {
         //create our test entities
         generateTestEntities(numOfEntities, collectionName);
 
+        //Sort by the "verb" property, DESC to test reverse alphabetical sorting of string properties
         QueryParameters params = new QueryParameters()
             .setQuery("select * order by verb desc")
             .setLimit(numOfEntities);
@@ -200,6 +209,8 @@ public class OrderByTest extends QueryTestBase {
         //results should be sorted "stop", then "go"
         while (activities.hasNext()) {
             Entity activity = activities.next();
+            //The first half of entities returned should have "verb = 'stop'"
+            //The second half of entities returned should have "verb = 'go'"
             if (index++ < numOfEntities / 2) {
                 assertEquals("stop", activity.get("verb").toString());
             } else {
@@ -221,7 +232,6 @@ public class OrderByTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    // USERGRID-1400
     public void orderByShouldNotAffectResults() throws IOException {
 
         long created = 0;
@@ -270,7 +280,6 @@ public class OrderByTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    // USERGRID-1520
     public void orderByComesBeforeLimitResult() throws IOException {
 
         Entity actor = new Entity();
@@ -304,7 +313,6 @@ public class OrderByTest extends QueryTestBase {
      * @throws IOException
      */
     @Test
-    // USERGRID-1521
     public void orderByReturnCorrectResults() throws IOException {
 
         int size = 20;


[07/19] incubator-usergrid git commit: [USERGRID-326] Updating PartialUpdateTest to work with the new REST test framework

Posted by sf...@apache.org.
[USERGRID-326] Updating PartialUpdateTest to work with the new REST test framework


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 8daa6e5b8619387b627044225c7befbe00b307ab
Parents: 231a449
Author: ryan bridges <rb...@apigee.com>
Authored: Mon Jan 12 14:23:35 2015 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Mon Jan 12 14:23:35 2015 -0500

----------------------------------------------------------------------
 .../apache/usergrid/rest/PartialUpdateTest.java | 157 ++++++++-----------
 1 file changed, 69 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8daa6e5b/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
index a9e1548..bdc4e66 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
@@ -17,137 +17,118 @@
 package org.apache.usergrid.rest;
 
 
-import com.fasterxml.jackson.databind.JsonNode;
 import com.sun.jersey.api.client.UniformInterfaceException;
-import java.io.IOException;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import javax.ws.rs.core.MediaType;
-
-import org.junit.Rule;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.utils.MapUtils;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.fail;
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
 
 
 /**
- * Partial update test. 
+ * Partial update test.
  */
 public class PartialUpdateTest extends AbstractRestIT {
-    private static final Logger log= LoggerFactory.getLogger(PartialUpdateTest.class );
-    
-    @Rule
-    public TestContextSetup context = new TestContextSetup( this );
+    private static final Logger log = LoggerFactory.getLogger(PartialUpdateTest.class);
 
-    double latitude=37.772837;
-    double longitude=-122.409895;
+    double latitude = 37.772837;
+    double longitude = -122.409895;
 
-    Map<String, Object> geolocation = new LinkedHashMap<String, Object>() {{
-        put("latitude", latitude);
-        put("longitude", longitude);
-    }};
+    Map<String, Double> geolocation = new MapUtils.HashMapBuilder<String, Double>()
+        .map("latitude", latitude)
+        .map("longitude", longitude);
 
-    @Test 
+    @Test
     public void testPartialUpdate() throws IOException {
 
         // create user bart
-        Map<String, Object> userProperties = new LinkedHashMap<String, Object>() {{
-            put( "username", "bart" );
-            put( "employer", "Brawndo" );
-            put( "email", "bart@personal-email.example.com" );
-            put( "location", geolocation);
-        }};
-
-        JsonNode userNode = mapper.readTree( 
-            resource().path( "/test-organization/test-app/users" )
-                .queryParam( "access_token", adminAccessToken )
-                .accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON )
-                .post( String.class, userProperties ));
-
-        assertNotNull( userNode );
-        String uuid = userNode.withArray("entities").get(0).get("uuid").asText();
-        assertNotNull( uuid );
-        refreshIndex( "test-organization", "test-app" );
+        Entity props = new Entity();
+        props.put("username", "bart");
+        props.put("employer", "Brawndo");
+        props.put("email", "bart@personal-email.example.com");
+        props.put("location", geolocation);
+        // POST the entity
+        Entity userNode = this.app().collection("users").post(props);
+        // make sure it was saved properly
+        assertNotNull(userNode);
+        String uuid = userNode.get("uuid").toString();
+        assertNotNull(uuid);
+
+        refreshIndex();
 
         Map<String, Object> updateProperties = new LinkedHashMap<String, Object>();
         // update user bart passing only an update to a property
-        for(int i=1; i<10; i++) {
+        for (int i = 1; i < 10; i++) {
+            // "Move" the user by incrementing their location
+            Entity updateProps = new Entity();
             geolocation.put("latitude", latitude += 0.00001);
             geolocation.put("longitude", longitude += 0.00001);
-            updateProperties.put("employer", "Initech");
-            updateProperties.put("location", geolocation);
+            //update the User's employer property
+            updateProps.put("employer", "Initech");
+            updateProps.put("location", geolocation);
 
             try {
-                JsonNode updatedNode = mapper.readTree(
-                        resource().path("/test-organization/test-app/user/" + uuid)
-                                .queryParam("access_token", adminAccessToken)
-                                .accept(MediaType.APPLICATION_JSON)
-                                .type(MediaType.APPLICATION_JSON)
-                                .put(String.class, updateProperties));
-                assertNotNull(updatedNode);
+                // PUT the updates to the user and ensure they were saved
+                userNode = this.app().collection("users").entity(userNode).put(updateProps);
+                assertNotNull(userNode);
 
             } catch (UniformInterfaceException uie) {
                 fail("Update failed due to: " + uie.getResponse().getEntity(String.class));
             }
 
-            refreshIndex("test-organization", "test-app");
-
-            userNode = mapper.readTree(
-                    resource().path("/test-organization/test-app/users/" + uuid)
-                            .queryParam("access_token", adminAccessToken)
-                            .accept(MediaType.APPLICATION_JSON)
-                            .get(String.class));
+            refreshIndex();
+            // retrieve the user from the backend
+            userNode = this.app().collection("users").entity(userNode).get();
 
             log.info(userNode.toString());
 
+            // verify that the user was returned
             assertNotNull(userNode);
-
-            assertEquals("Initech", userNode.withArray("entities").get(0).get("employer").asText());
-
-            assertNotNull(userNode.withArray("entities").get(0).get("location"));
-            assertNotNull(userNode.withArray("entities").get(0).get("location").get("latitude"));
-            assertNotNull(userNode.withArray("entities").get(0).get("location").get("longitude"));
-
-            assertNotSame( latitude, 
-                userNode.withArray("entities").get(0).get("location").get("latitude").asDouble());
-            assertNotSame( longitude, 
-                userNode.withArray("entities").get(0).get("location").get("longitude").asDouble());
+            // Verify that the user's employer was updated
+            assertEquals("Initech", userNode.get("employer").toString());
+            // verify that the geo data is present
+            assertNotNull(userNode.get("location"));
+            assertNotNull(((Map<String, Object>) userNode.get("location")).get("latitude"));
+            assertNotNull(((Map<String, Object>) userNode.get("location")).get("longitude"));
+
+            // Verify that the location was updated correctly AND that
+            // it is not the same object reference from the original POST
+            log.info(geolocation.get("latitude") + " != " + Double.parseDouble(((Map<String, Object>) userNode.get("location")).get("latitude").toString()));
+            log.info(geolocation.get("longitude") + " != " + Double.parseDouble(((Map<String, Object>) userNode.get("location")).get("longitude").toString()));
+            assertNotSame(geolocation.get("latitude"),
+                Double.parseDouble(((Map<String, Object>) userNode.get("location")).get("latitude").toString()));
+            assertEquals(geolocation.get("latitude").doubleValue(),
+                Double.parseDouble(((Map<String, Object>) userNode.get("location")).get("latitude").toString()), 0);
+            assertNotSame(geolocation.get("longitude"),
+                Double.parseDouble(((Map<String, Object>) userNode.get("location")).get("longitude").toString()));
+            assertEquals(geolocation.get("longitude").doubleValue(),
+                Double.parseDouble(((Map<String, Object>) userNode.get("location")).get("longitude").toString()), 0);
         }
 
-        // Update bart's employer without specifying any required fields 
+        // Update bart's employer without specifying any required fields
         // (this time with username specified in URL)
+        Entity updateProps = new Entity();
+        updateProps.put("employer", "ACME Corporation");
 
-        updateProperties = new LinkedHashMap<String, Object>() {{
-            put( "employer", "ACME Corporation" );
-        }};
-
-        for(int i=1; i<10; i++) {
+        for (int i = 1; i < 10; i++) {
             try {
-                mapper.readTree(
-                        resource().path("/test-organization/test-app/users/bart")
-                                .queryParam("access_token", adminAccessToken)
-                                .accept(MediaType.APPLICATION_JSON)
-                                .type(MediaType.APPLICATION_JSON)
-                                .put(String.class, updateProperties));
+                userNode = this.app().collection("users").entity((String) props.get("username")).put(updateProps);
 
             } catch (UniformInterfaceException uie) {
                 fail("Update failed due to: " + uie.getResponse().getEntity(String.class));
             }
-            refreshIndex("test-organization", "test-app");
+            refreshIndex();
 
-            userNode = mapper.readTree(
-                    resource().path("/test-organization/test-app/users/bart")
-                            .queryParam("access_token", adminAccessToken)
-                            .accept(MediaType.APPLICATION_JSON)
-                            .get(String.class));
+            userNode = this.app().collection("users").entity(userNode).get();
             assertNotNull(userNode);
-            assertEquals("ACME Corporation", userNode.withArray("entities").get(0).get("employer").asText());
+            assertEquals("ACME Corporation", userNode.get("employer").toString());
         }
     }
 }


[19/19] incubator-usergrid git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-323-Win-phone

Posted by sf...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-323-Win-phone


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 2d0d68ce7453a3cc4b6a58432c0186b4b5e1fa1a
Parents: 122607d 6dc62ed
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Jan 22 08:47:56 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Jan 22 08:47:56 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java |  56 +-
 .../HybridEntityManagerFactory.java             |   9 +-
 .../persistence/EntityManagerFactory.java       |  11 +-
 .../cassandra/EntityManagerFactoryImpl.java     |  11 +-
 .../cassandra/EntityManagerFactoryImplIT.java   |  71 ++-
 .../usergrid/persistence/index/EntityIndex.java |   2 +
 .../index/impl/EsEntityIndexBatchImpl.java      |  14 +-
 .../index/impl/EsEntityIndexImpl.java           | 115 ++--
 .../persistence/index/impl/EsIndexCache.java    |  12 +-
 .../rest/applications/ApplicationResource.java  |  32 +-
 .../apache/usergrid/rest/PartialUpdateTest.java | 170 +++---
 .../applications/ApplicationDeleteTest.java     |  54 ++
 .../collection/groups/GroupResourceIT.java      |   2 +-
 .../applications/queries/AndOrQueryTest.java    | 528 ++++++++++---------
 .../queries/BadGrammarQueryTest.java            | 213 ++++++--
 .../applications/queries/GeoPagingTest.java     |   2 +-
 .../rest/applications/queries/OrderByTest.java  | 447 +++++++++++-----
 .../applications/queries/QueryTestBase.java     |  72 +++
 .../endpoints/CollectionEndpoint.java           |   2 +-
 19 files changed, 1193 insertions(+), 630 deletions(-)
----------------------------------------------------------------------



[10/19] incubator-usergrid git commit: Addition of deleteIndex() method, improvements to logging and minor formatting changes.

Posted by sf...@apache.org.
Addition of deleteIndex() method, improvements to logging and minor formatting changes.


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 0408b4b7f4f5cf549ccc0fc0f8029d12ef02dd22
Parents: bcabda2
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Jan 20 11:58:31 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Jan 20 11:58:31 2015 -0500

----------------------------------------------------------------------
 .../usergrid/persistence/index/EntityIndex.java |   2 +
 .../index/impl/EsEntityIndexBatchImpl.java      |  14 +--
 .../index/impl/EsEntityIndexImpl.java           | 115 ++++++++-----------
 .../persistence/index/impl/EsIndexCache.java    |  12 +-
 4 files changed, 62 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0408b4b7/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
index eb9f61e..e221f0e 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
@@ -100,6 +100,8 @@ public interface EntityIndex {
      * Check health of this specific index.
      */
     public Health getIndexHealth();
+    
+    public void deleteIndex();
 
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0408b4b7/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index c9a4769..20669b3 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -123,16 +123,10 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
         final String entityType = entity.getId().getType();
 
         if ( log.isDebugEnabled() ) {
-            log.debug( "Indexing entity {}:{} in scope\n   app {}\n   "
-                + "owner {}\n   name {}\n   type {} \n scope type {}", new Object[] {
-                    entity.getId().getType(), 
-                    entity.getId().getUuid(), 
-                    applicationScope.getApplication(),
-                    indexScope.getOwner(), 
-                    indexScope.getName(), 
-                    entityType, 
-                    context
-            } );
+            log.debug( "Indexing entity {}:{}\n   alias: {}\n" +
+                       "   app: {}\n   scope owner: {}\n   scope name: {}\n   context: {}",
+                entity.getId().getType(), entity.getId().getUuid(), alias.getWriteAlias(),
+                    applicationScope.getApplication(), indexScope.getOwner(), indexScope.getName(), context );
         }
 
         ValidationUtils.verifyEntityWrite( entity );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0408b4b7/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index b743d83..9e9cebf 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -21,29 +21,13 @@ package org.apache.usergrid.persistence.index.impl;
 import com.google.common.collect.ImmutableMap;
 import com.google.inject.Inject;
 import com.google.inject.assistedinject.Assisted;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.util.Health;
 import org.apache.usergrid.persistence.core.util.ValidationUtils;
-import org.apache.usergrid.persistence.index.AliasedEntityIndex;
-import org.apache.usergrid.persistence.index.AliasedEntityIndex.AliasType;
-import org.apache.usergrid.persistence.index.EntityIndexBatch;
-import org.apache.usergrid.persistence.index.IndexFig;
-import org.apache.usergrid.persistence.index.IndexIdentifier;
-import org.apache.usergrid.persistence.index.IndexScope;
-import org.apache.usergrid.persistence.index.SearchTypes;
+import org.apache.usergrid.persistence.index.*;
 import org.apache.usergrid.persistence.index.exceptions.IndexException;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.BOOLEAN_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITYID_ID_FIELDNAME;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITY_VERSION_FIELDNAME;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.NUMBER_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.SPLITTER;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.STRING_PREFIX;
 import org.apache.usergrid.persistence.index.query.CandidateResult;
 import org.apache.usergrid.persistence.index.query.CandidateResults;
 import org.apache.usergrid.persistence.index.query.Query;
@@ -68,13 +52,7 @@ import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
-import org.elasticsearch.index.query.FilteredQueryBuilder;
-import org.elasticsearch.index.query.MatchAllQueryBuilder;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.index.query.TermQueryBuilder;
+import org.elasticsearch.index.query.*;
 import org.elasticsearch.indices.IndexAlreadyExistsException;
 import org.elasticsearch.indices.IndexMissingException;
 import org.elasticsearch.search.SearchHit;
@@ -87,6 +65,14 @@ import org.slf4j.LoggerFactory;
 import rx.Observable;
 import rx.functions.Func1;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.apache.usergrid.persistence.index.impl.IndexingUtils.*;
+
 
 /**
  * Implements index using ElasticSearch Java API.
@@ -197,23 +183,25 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
 
             String[] indexNames = getIndexes(AliasType.Write);
 
-            for(String currentIndex : indexNames){
+            for (String currentIndex : indexNames){
                 isAck = adminClient.indices().prepareAliases().removeAlias(currentIndex,
                         alias.getWriteAlias()).execute().actionGet().isAcknowledged();
 
-                logger.info("Removed Index Name [{}] from Alias=[{}] ACK=[{}]",currentIndex, alias, isAck);
+                logger.info("Removed Index Name [{}] from Alias=[{}] ACK=[{}]", currentIndex, alias, isAck);
             }
 
-            //add read alias
+            // add read alias
             isAck = adminClient.indices().prepareAliases().addAlias(
                     indexName, alias.getReadAlias()).execute().actionGet().isAcknowledged();
-            logger.info("Created new read Alias Name [{}] ACK=[{}]", alias, isAck);
-
-            //add write alias
+            logger.info("Created new read Alias Name [{}] ACK=[{}]", alias.getReadAlias(), isAck);
+            
+            // add write alias
             isAck = adminClient.indices().prepareAliases().addAlias(
                     indexName, alias.getWriteAlias()).execute().actionGet().isAcknowledged();
-            logger.info("Created new write Alias Name [{}] ACK=[{}]", alias, isAck);
+            logger.info("Created new write Alias Name [{}] ACK=[{}]", alias.getWriteAlias(), isAck);
+            
             aliasCache.invalidate(alias);
+            
         } catch (Exception e) {
             logger.warn("Failed to create alias ", e);
         }
@@ -236,7 +224,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         // to receive documents. Occasionally we see errors.
         // See this post: http://s.apache.org/index-missing-exception
 
-        logger.debug( "Testing new index name [{}]", alias);
+        logger.debug( "Testing new index name: read {} write {}", alias.getReadAlias(), alias.getWriteAlias());
 
         final RetryOperation retryOperation = new RetryOperation() {
             @Override
@@ -244,18 +232,19 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
                 final String tempId = UUIDGenerator.newTimeUUID().toString();
 
                 esProvider.getClient().prepareIndex( alias.getWriteAlias(), VERIFY_TYPE, tempId )
-                        .setSource(DEFAULT_PAYLOAD).get();
+                     .setSource(DEFAULT_PAYLOAD).get();
 
                 logger.info( "Successfully created new document with docId {} "
-                        + "in index {} and type {}", tempId, alias, VERIFY_TYPE );
+                     + "in index read {} write {} and type {}", 
+                        tempId, alias.getReadAlias(), alias.getWriteAlias(), VERIFY_TYPE );
 
                 // delete all types, this way if we miss one it will get cleaned up
-                esProvider.getClient().prepareDeleteByQuery( alias.getWriteAlias() )
-                        .setTypes(VERIFY_TYPE) 
+                esProvider.getClient().prepareDeleteByQuery( alias.getWriteAlias())
+                        .setTypes(VERIFY_TYPE)
                         .setQuery(MATCH_ALL_QUERY_BUILDER).get();
 
-                logger.info( "Successfully deleted all documents in index {} and type {}", 
-                        alias, VERIFY_TYPE );
+                logger.info( "Successfully deleted all documents in index {} read {} write {} and type {}",
+                        alias.getReadAlias(), alias.getWriteAlias(), VERIFY_TYPE );
 
                 return true;
             }
@@ -359,16 +348,15 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
 
 
             if ( logger.isDebugEnabled() ) {
-                logger.debug( "Searching index {}\n  scope{} \n type {}\n   query {} ", 
-                        new Object[] { this.alias, context, entityTypes, srb
-                } );
+                logger.debug( "Searching index (read alias): {}\n  scope: {} \n type: {}\n   query: {} ",
+                    this.alias.getReadAlias(), context, entityTypes, srb );
             }
 
             try {
                 searchResponse = srb.execute().actionGet();
             }
             catch ( Throwable t ) {
-                logger.error( "Unable to communicate with elasticsearch", t );
+                logger.error( "Unable to communicate with Elasticsearch", t );
                 failureMonitor.fail( "Unable to execute batch", t );
                 throw t;
             }
@@ -445,17 +433,14 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
             @Override
             public boolean doOp() {
                 try {
-                    String[]  indexes = getIndexes(AliasType.Read);
-                    Observable.from(indexes).map(new Func1<String, String>() {
-                        @Override
-                        public String call(String index) {
-                            esProvider.getClient().admin().indices().prepareRefresh( index ).execute().actionGet();
-                            return index;
-                        }
-                    }).toBlocking().last();
-
-                    logger.debug( "Refreshed index: " + alias);
-
+                    String[] indexes = ArrayUtils.addAll( getIndexes(AliasType.Write), getIndexes(AliasType.Write) );
+                    if ( indexes.length == 0 ) {
+                        logger.debug( "Not refreshing indexes, none found for app {}", 
+                                applicationScope.getApplication().getUuid() );
+                        return true;
+                    }
+                    esProvider.getClient().admin().indices().prepareRefresh( indexes ).execute().actionGet();
+                    logger.debug("Refreshed indexes: {}", StringUtils.join(indexes, ", "));
                     return true;
                 }
                 catch ( IndexMissingException e ) {
@@ -466,8 +451,6 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         };
 
         doInRetry( retryOperation );
-
-        logger.debug( "Refreshed index: " + alias);
     }
 
 
@@ -517,7 +500,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
     @Override
     public void deleteAllVersionsOfEntity( Id entityId ) {
 
-        String idString = IndexingUtils.idString( entityId ).toLowerCase(); 
+        String idString = IndexingUtils.idString(entityId).toLowerCase();
 
         final TermQueryBuilder tqb = QueryBuilders.termQuery( ENTITYID_ID_FIELDNAME, idString );
 
@@ -526,7 +509,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
 
 
         logger.debug( "Deleted entity {}:{} from all index scopes with response status = {}",
-            new Object[] { entityId.getType(), entityId.getUuid(), response.status().toString() });
+            entityId.getType(), entityId.getUuid(), response.status().toString());
 
        checkDeleteByQueryResponse( tqb, response );
 
@@ -539,8 +522,8 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         String idString = IndexingUtils.idString( entityId ).toLowerCase(); 
 
         final FilteredQueryBuilder fqb = QueryBuilders.filteredQuery(
-            QueryBuilders.termQuery( ENTITYID_ID_FIELDNAME, idString ),
-            FilterBuilders.rangeFilter( ENTITY_VERSION_FIELDNAME ).lt( version.timestamp() ) 
+                QueryBuilders.termQuery(ENTITYID_ID_FIELDNAME, idString),
+                FilterBuilders.rangeFilter(ENTITY_VERSION_FIELDNAME).lt(version.timestamp())
         );
 
         final DeleteByQueryResponse response = esProvider.getClient()
@@ -549,7 +532,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         //error message needs to be retooled so that it describes the entity more throughly
         logger.debug( "Deleted entity {}:{} with version {} from all "
                 + "index scopes with response status = {}",
-            new Object[] { entityId.getType(), entityId.getUuid(), version,  response.status().toString() } );
+            entityId.getType(), entityId.getUuid(), version,  response.status().toString()  );
 
         checkDeleteByQueryResponse( fqb, response );
     }
@@ -565,10 +548,10 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
             final ShardOperationFailedException[] failures = indexDeleteByQueryResponse.getFailures();
 
             for ( ShardOperationFailedException failedException : failures ) {
-                throw new IndexException( String.format("Unable to delete by query %s.  "
+                throw new IndexException( String.format("Unable to delete by query %s. "
                         + "Failed with code %d and reason %s on shard %s in index %s",
                     query.toString(), 
-                    failedException.status(), 
+                    failedException.status().getStatus(),
                     failedException.reason(), 
                     failedException.shardId(),
                     failedException.index() ) );
@@ -579,7 +562,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
 
 
     /**
-     * For testing only.
+     * Completely delete an index.
      */
     public void deleteIndex() {
         AdminClient adminClient = esProvider.getClient().admin();
@@ -588,10 +571,10 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
                 .prepareDelete( indexIdentifier.getIndex(null) ).get();
 
         if ( response.isAcknowledged() ) {
-            logger.info( "Deleted index: " + alias);
+            logger.info( "Deleted index: read {} write {}", alias.getReadAlias(), alias.getWriteAlias());
         }
         else {
-            logger.info( "Failed to delete index " + alias);
+            logger.info( "Failed to delete index: read {} write {}", alias.getReadAlias(), alias.getWriteAlias());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0408b4b7/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexCache.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexCache.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexCache.java
index c607222..0c07a34 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexCache.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexCache.java
@@ -45,6 +45,7 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
+
 /**
  * Cache for Es index operations
  */
@@ -58,8 +59,10 @@ public class EsIndexCache {
 
     @Inject
     public EsIndexCache(final EsProvider provider, final IndexFig indexFig) {
+        
         this.refreshExecutors = MoreExecutors
                 .listeningDecorator(Executors.newScheduledThreadPool(indexFig.getIndexCacheMaxWorkers()));
+        
         aliasIndexCache = CacheBuilder.newBuilder().maximumSize(1000)
                 .refreshAfterWrite(5,TimeUnit.MINUTES)
                 .build(new CacheLoader<String, String[]>() {
@@ -78,17 +81,16 @@ public class EsIndexCache {
                     public String[] load(final String aliasName) {
                         final AdminClient adminClient = provider.getClient().admin();
                         //remove write alias, can only have one
-                        ImmutableOpenMap<String, List<AliasMetaData>> aliasMap = adminClient.indices().getAliases(new GetAliasesRequest(aliasName)).actionGet().getAliases();
+                        ImmutableOpenMap<String, List<AliasMetaData>> aliasMap = 
+                           adminClient.indices().getAliases(new GetAliasesRequest(aliasName)).actionGet().getAliases();
                         return aliasMap.keys().toArray(String.class);
                     }
                 }) ;
     }
 
+    
     /**
      * Get indexes for an alias
-     * @param alias
-     * @param aliasType
-     * @return
      */
     public String[] getIndexes(IndexIdentifier.IndexAlias alias, AliasedEntityIndex.AliasType aliasType) {
         String[] indexes;
@@ -101,9 +103,9 @@ public class EsIndexCache {
         return indexes;
     }
 
+    
     /**
      * clean up cache
-     * @param alias
      */
     public void invalidate(IndexIdentifier.IndexAlias alias){
         aliasIndexCache.invalidate(alias.getWriteAlias());