You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/01/26 15:24:07 UTC
[08/23] incubator-usergrid git commit: [USERGRID-320] Added/Updated
comments
[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/two-dot-o-import
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;