Repository: usergrid
Updated Branches:
  refs/heads/release-2.1.1 29d7660ee -> 74de4bca3


Adding in beginning test.


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

Branch: refs/heads/release-2.1.1
Commit: 56e03718a911a6a1215fa75522b54ad694c4b566
Parents: b9e8088
Author: George Reyes <g...@apache.org>
Authored: Thu Mar 3 08:20:30 2016 -0800
Committer: George Reyes <g...@apache.org>
Committed: Thu Mar 24 09:05:30 2016 -0700

----------------------------------------------------------------------
 .../persistence/cassandra/ApplicationCF.java    |  7 +-
 .../rest/applications/ServiceResource.java      | 32 +++++++++
 .../collection/CollectionsResourceIT.java       | 69 +++++++++++++++-----
 3 files changed, 91 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/56e03718/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/ApplicationCF.java
----------------------------------------------------------------------
diff --git 
a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/ApplicationCF.java
 
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/ApplicationCF.java
index 5dbe4b5..ad72717 100644
--- 
a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/ApplicationCF.java
+++ 
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/ApplicationCF.java
@@ -44,7 +44,12 @@ public enum ApplicationCF implements CFEnum {
     APPLICATION_AGGREGATE_COUNTERS( "Application_Aggregate_Counters", 
"LongType", COUNTERTYPE.getClassName() ),
 
     /** Entity counters */
-    ENTITY_COUNTERS( "Entity_Counters", "BytesType", 
COUNTERTYPE.getClassName() ),;
+    ENTITY_COUNTERS( "Entity_Counters", "BytesType", 
COUNTERTYPE.getClassName() );
+
+    /**
+     * Collection Schema
+     */
+    COL_SCHEMA( "")
 
     private final String cf;
     private final String comparator;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/56e03718/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
----------------------------------------------------------------------
diff --git 
a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
 
b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
index 4c92fef..2843417 100644
--- 
a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
+++ 
b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
@@ -353,6 +353,38 @@ public class ServiceResource extends 
AbstractContextResource {
     }
 
 
+    /**
+     * THE BEGINNINGS OF AN ENDPOINT THAT WILL ALLOW TO DEFINE WHAT TO
+     * STORE IN ELASTICSEARCH.
+     * @param ui
+     * @param callback
+     * @return
+     * @throws Exception
+     */
+    @POST
+    @Path("_indexes")
+    @Produces({MediaType.APPLICATION_JSON,"application/javascript"})
+    @RequireApplicationAccess
+    @JSONP
+    public ApiResponse executePostOnIndexes( @Context UriInfo ui,
+                                   @QueryParam("callback") 
@DefaultValue("callback") String callback )
+        throws Exception {
+
+        if(logger.isTraceEnabled()){
+            logger.trace( "ServiceResource.executePostOnIndexes" );
+        }
+
+        ApiResponse response = createApiResponse();
+
+        response.setAction( "post" );
+        response.setApplication( services.getApplication() );
+        response.setParams( ui.getQueryParameters() );
+
+        executeServiceRequest( ui, response, ServiceAction.POST, null );
+
+        return response;
+    }
+
     @SuppressWarnings({ "unchecked" })
     public ServicePayload getPayload( Object json ) {
         ServicePayload payload = null;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/56e03718/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git 
a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
 
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
index 9752035..ca5360d 100644
--- 
a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
+++ 
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
@@ -38,6 +38,8 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
+import java.util.ArrayList;
+
 
 import static org.junit.Assert.*;
 
@@ -112,33 +114,68 @@ public class CollectionsResourceIT extends AbstractRestIT 
{
     }
 
 
+    /**
+     * Create test collection
+     * Give collection an indexing schema
+     * Give collection a new entity and ensure it only indexes wht is in the 
schema
+     * Reindex and make sure old entity with full text indexing is reindexed 
with the schema.
+     *
+     * @throws Exception
+     */
     @Test
     public void postToReservedField() throws Exception {
+
+        //Create test collection with test entity that is full text indexed.
+        Entity testEntity = new Entity();
+        testEntity.put( "one", "12/31/9999" );
+        //this field shouldn't persist after reindexing.
+        testEntity.put( "two","2015-04-20T17:41:38.035Z" );
+
+        //TODO: add arrays to the indexing test
+        //testEntity.put("array","array stuff here");
+
+        Entity returnedEntity = this.app().collection( "testCollection" 
).post( testEntity );
+
+        //Creating schema.
+        //this could be changed to a hashmap.
+        ArrayList<String> indexingArray = new ArrayList<>(  );
+        indexingArray.add( "one" );
+
+        //TODO: add indexing array to the backend/test once you finish the 
regular selective indexing.
+        //indexingArray.add( "field.three.index.array" );
+
+        //field "fields" is required.
         Entity payload = new Entity();
-        payload.put( "term_date", "12/31/9999" );
-        payload.put( "effective_date","2015-04-20T17:41:38.035Z" );
-        payload.put("junk","TEST");
+        payload.put( "fields", indexingArray);
 
-        this.app().collection( "testCollection" ).post( payload );
+        //Post index to the collection metadata
+        this.app().collection( "testCollection" ).collection( "_indexes" 
).post( payload );
         refreshIndex();
-        Thread.sleep( 1000 );
 
-        Collection collection = this.app().collection( "testCollection" 
).get();
+        //Below is what needs to be implemented along with the index call above
 
-        assertNotEquals(0, collection.getNumOfEntities() );
+        //Get the collection schema and verify that it contains the same 
schema as posted above.
+        Collection collection = this.app().collection( "testCollection" 
).collection( "_index" ).get();
 
-        payload = new Entity();
-        payload.put( "term_date","1991-17-10" );
-        payload.put( "effective_date","HELLO WORLD!" );
-        payload.put("junk","TEST");
+        Entity testCollectionSchema = 
(Entity)collection.getResponse().getEntity();
+        //the below will have to be replaced by the values that I deem correct.
+        assertEquals( "lastUpdated", testCollectionSchema.get( "lastUpdated" 
));
+        assertEquals( "lastUpdatedBy",testCollectionSchema.get( 
"lastUpdatedBy" ) );
+        assertEquals( "lastReindex",testCollectionSchema.get( "lastReindex" ) 
);
 
-        this.app().collection( "testCollection" ).post( payload );
-        refreshIndex();
-        Thread.sleep( 1000 );
 
-        collection = this.app().collection( "testCollection" ).get();
+        ArrayList<String> schema = ( ArrayList<String> ) 
testCollectionSchema.get( "fields" );
+        assertEquals( "one",schema.get( 0 ) );
+
+        //Reindex and verify that the entity only has field one index.
+        this.app().collection( "testCollection" ).collection( "_reindex" 
).post();
+
+        refreshIndex();
 
-        assertEquals( 2, collection.getNumOfEntities() );
+        Entity reindexedEntity = this.app().collection( "testCollection" 
).entity( returnedEntity.getUuid() ).get();
+        assertEquals( "12/31/9999",reindexedEntity.get( "one" ) );
+        assertNull( reindexedEntity.get( "two" ) );
+        //not sure if this should have some kind of sleep here because this 
reindex will be heavily throttled.
 
     }
 

Reply via email to