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 2016/06/14 17:15:06 UTC
[27/44] usergrid git commit: Tests to illustrate case-insensitive
handling of Entity field names.
Tests to illustrate case-insensitive handling of Entity field names.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/e9228e11
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/e9228e11
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/e9228e11
Branch: refs/heads/usergrid-1268-akka-211
Commit: e9228e111f338aabf34b334e2661e1966116f23a
Parents: 5452d68
Author: Dave Johnson <sn...@apache.org>
Authored: Thu Jun 2 15:33:28 2016 -0400
Committer: Dave Johnson <sn...@apache.org>
Committed: Thu Jun 2 15:33:28 2016 -0400
----------------------------------------------------------------------
.../queries/SelectMappingsQueryTest.java | 79 +++++++++++++-------
1 file changed, 54 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/e9228e11/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/SelectMappingsQueryTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/SelectMappingsQueryTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/SelectMappingsQueryTest.java
index eb6aeee..4a291b6 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/SelectMappingsQueryTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/SelectMappingsQueryTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.usergrid.rest.applications.queries;
+import org.apache.commons.lang.RandomStringUtils;
import org.apache.usergrid.rest.test.resource.model.Collection;
import org.apache.usergrid.rest.test.resource.model.Entity;
import org.apache.usergrid.rest.test.resource.model.QueryParameters;
@@ -34,6 +35,9 @@ public class SelectMappingsQueryTest extends QueryTestBase {
private static final Logger logger = LoggerFactory.getLogger(OrderByTest.class);
+ /**
+ * Select field mappings may include nested entity fields.
+ */
@Test
public void testNestedSelectFieldNames() throws Exception {
@@ -64,42 +68,67 @@ public class SelectMappingsQueryTest extends QueryTestBase {
/**
- * Shows that field names are case-insensitive.
- * If you define two fields with same name but different cases, behavior is undefined.
+ * When entity posted with two duplicate names with different cases, last one wins.
*/
@Test
- public void testFieldNameCaseSensitivity() throws Exception {
+ public void testMixedCaseDupField() throws Exception {
- int numberOfEntities = 10;
String collectionName = "things";
- Entity[] entities = new Entity[numberOfEntities];
- Entity props = new Entity();
+ String value = RandomStringUtils.randomAlphabetic( 20 );
+ String otherValue = RandomStringUtils.randomAlphabetic( 20 );
- for (int i = 0; i < numberOfEntities; i++) {
- props.put("testProp", "a");
- props.put("testprop", "b");
- entities[i] = app().collection(collectionName).post(props);
- }
+ // create entity with testProp=value
+ Entity entity = new Entity()
+ .withProp( "testProp", value )
+ .withProp( "TESTPROP", otherValue);
+ app().collection( collectionName ).post( entity );
refreshIndex();
- {
- QueryParameters params = new QueryParameters()
- .setQuery( "select * where testProp = 'b'" );
- Collection things = this.app().collection( "things" ).get( params );
+ // testProp and TESTPROP should now have otherValue
- // if field names were case sensitive, this would fail
- assertEquals( numberOfEntities, things.getNumOfEntities() );
- }
+ QueryParameters params = new QueryParameters()
+ .setQuery( "select * where testProp='" + otherValue + "'" );
+ Collection things = this.app().collection( "things" ).get( params );
+ assertEquals( 1, things.getNumOfEntities() );
+
+ params = new QueryParameters()
+ .setQuery( "select * where TESTPROP='" + otherValue + "'" );
+ things = app().collection( "things" ).get( params );
+ assertEquals( 1, things.getNumOfEntities() );
+ }
- {
- QueryParameters params = new QueryParameters()
- .setQuery( "select * where testprop='b'" );
- Collection things = this.app().collection( "things" ).get( params );
- assertEquals( numberOfEntities, things.getNumOfEntities() );
- }
+ /**
+ * Field named testProp can be over-written by field named TESTPROP.
+ */
+ @Test
+ public void testFieldOverride() throws Exception {
- }
+ String collectionName = "things";
+ // create entity with testProp=value
+ String value = RandomStringUtils.randomAlphabetic( 20 );
+ Entity entity = new Entity().withProp( "testProp", value );
+ app().collection( collectionName ).post( entity );
+ refreshIndex();
+
+ // override with TESTPROP=newValue
+ String newValue = RandomStringUtils.randomAlphabetic( 20 );
+ entity = new Entity().withProp( "TESTPROP", newValue );
+ app().collection( collectionName ).post( entity );
+ refreshIndex();
+
+ // testProp and TESTPROP should now have newValue
+
+ QueryParameters params = new QueryParameters()
+ .setQuery( "select * where testProp='" + newValue + "'" );
+ Collection things = this.app().collection( "things" ).get( params );
+ assertEquals( 1, things.getNumOfEntities() );
+
+ params = new QueryParameters()
+ .setQuery( "select * where TESTPROP='" + newValue + "'" );
+ things = app().collection( "things" ).get( params );
+ assertEquals( 1, things.getNumOfEntities() );
+ }
}