http://git-wip-us.apache.org/repos/asf/usergrid/blob/11aa1386/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java index 115be99..74f7038 100644 --- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java +++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java @@ -20,7 +20,6 @@ package org.apache.usergrid.persistence.collection; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.UUID; @@ -100,7 +99,7 @@ public class EntityCollectionManagerIT { EntityCollectionManager manager = factory.createCollectionManager( context ); - Observable<Entity> observable = manager.write( newEntity ); + Observable<Entity> observable = manager.write( newEntity, null ); Entity returned = observable.toBlocking().lastOrDefault( null ); @@ -122,7 +121,7 @@ public class EntityCollectionManagerIT { Entity newEntity = new Entity( new SimpleId( "test" ) ); newEntity.setField( new IntegerField( "count", 5, true ) ); - Observable<Entity> observable = manager.write( newEntity ); + Observable<Entity> observable = manager.write( newEntity, null ); Entity returned = observable.toBlocking().lastOrDefault( null ); } @@ -131,7 +130,7 @@ public class EntityCollectionManagerIT { Entity newEntity = new Entity( new SimpleId( "test" ) ); newEntity.setField( new IntegerField( "count", 5, true ) ); - manager.write( newEntity ).toBlocking().last(); + manager.write( newEntity, null ).toBlocking().last(); fail( "Write should have thrown an exception" ); } catch ( Exception ex ) { @@ -152,7 +151,7 @@ public class EntityCollectionManagerIT { EntityCollectionManager manager = factory.createCollectionManager( context ); - Observable<Entity> observable = manager.write( newEntity ); + Observable<Entity> observable = manager.write( newEntity, null ); Entity createReturned = observable.toBlocking().lastOrDefault( null ); @@ -178,7 +177,7 @@ public class EntityCollectionManagerIT { EntityCollectionManager manager = factory.createCollectionManager( context ); - Observable<Entity> observable = manager.write( newEntity ); + Observable<Entity> observable = manager.write( newEntity, null ); Entity createReturned = observable.toBlocking().lastOrDefault( null ); @@ -211,7 +210,7 @@ public class EntityCollectionManagerIT { EntityCollectionManager manager = factory.createCollectionManager( context ); - Observable<Entity> observable = manager.write( newEntity ); + Observable<Entity> observable = manager.write( newEntity, null ); Entity createReturned = observable.toBlocking().lastOrDefault( null ); @@ -232,7 +231,7 @@ public class EntityCollectionManagerIT { createReturned.setField( new IntegerField( "counter", 2 ) ); //wait for the write to complete - manager.write( createReturned ).toBlocking().lastOrDefault( null ); + manager.write( createReturned, null ).toBlocking().lastOrDefault( null ); loadObservable = manager.load( createReturned.getId() ); @@ -257,7 +256,7 @@ public class EntityCollectionManagerIT { EntityCollectionManager manager = factory.createCollectionManager( collectionScope1 ); - Observable<Entity> observable = manager.write( newEntity ); + Observable<Entity> observable = manager.write( newEntity, null ); Entity createReturned = observable.toBlocking().lastOrDefault( null ); @@ -298,7 +297,7 @@ public class EntityCollectionManagerIT { EntityCollectionManager manager = factory.createCollectionManager( collectionScope1 ); - Observable<Entity> observable = manager.write( newEntity ); + Observable<Entity> observable = manager.write( newEntity, null ); Entity createReturned = observable.toBlocking().lastOrDefault( null ); @@ -327,7 +326,7 @@ public class EntityCollectionManagerIT { EntityCollectionManager manager = factory.createCollectionManager( collectionScope1 ); - Observable<Entity> observable = manager.write( firstInstance ); + Observable<Entity> observable = manager.write( firstInstance, null ); Entity createReturned = observable.toBlocking().lastOrDefault( null ); @@ -350,7 +349,7 @@ public class EntityCollectionManagerIT { Field secondField = new StringField( firstField.getName(), "unique2", true ); secondInstance.setField( secondField ); - Observable<Entity> observableSecond = manager.write( secondInstance ); + Observable<Entity> observableSecond = manager.write( secondInstance, null ); Entity createReturnedSecond = observableSecond.toBlocking().lastOrDefault( null ); @@ -392,7 +391,7 @@ public class EntityCollectionManagerIT { ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) ); EntityCollectionManager manager = factory.createCollectionManager( context ); - Entity returned = manager.write( origEntity ).toBlocking().lastOrDefault( null ); + Entity returned = manager.write( origEntity, null ).toBlocking().lastOrDefault( null ); // note its version UUID oldVersion = returned.getVersion(); @@ -403,7 +402,7 @@ public class EntityCollectionManagerIT { // partial update entity but we don't have version number Entity updateEntity = new Entity( origEntity.getId() ); updateEntity.setField( new StringField( "addedField", "other value" ) ); - manager.write( updateEntity ).toBlocking().lastOrDefault( null ); + manager.write( updateEntity, null ).toBlocking().lastOrDefault( null ); // get entity now, it must have a new version returned = manager.load( origEntity.getId() ).toBlocking().lastOrDefault( null ); @@ -430,7 +429,7 @@ public class EntityCollectionManagerIT { for ( int i = 0; i < multigetSize; i++ ) { final Entity entity = new Entity( new SimpleId( "test" ) ); - final Entity written = manager.write( entity ).toBlocking().last(); + final Entity written = manager.write( entity, null ).toBlocking().last(); writtenEntities.add( written ); entityIds.add( written.getId() ); @@ -474,11 +473,11 @@ public class EntityCollectionManagerIT { for ( int i = 0; i < multigetSize; i++ ) { final Entity entity = new Entity( new SimpleId( "test" ) ); - final Entity written = manager.write( entity ).toBlocking().last(); + final Entity written = manager.write( entity, null ).toBlocking().last(); written.setField( new BooleanField( "updated", true ) ); - final Entity updated = manager.write( written ).toBlocking().last(); + final Entity updated = manager.write( written, null ).toBlocking().last(); writtenEntities.add( updated ); entityIds.add( updated.getId() ); @@ -539,14 +538,14 @@ public class EntityCollectionManagerIT { final Entity newEntity = new Entity( new SimpleId( "test" ) ); - Entity created1 = manager.write( newEntity ).toBlocking().lastOrDefault( null ); + Entity created1 = manager.write( newEntity, null ).toBlocking().lastOrDefault( null ); assertNotNull( "Id was assigned", created1.getId() ); assertNotNull( "Version was assigned", created1.getVersion() ); Entity secondEntity = new Entity( new SimpleId( "test" ) ); - Entity created2 = manager.write( secondEntity ).toBlocking().lastOrDefault( null ); + Entity created2 = manager.write( secondEntity, null ).toBlocking().lastOrDefault( null ); assertNotNull( "Id was assigned", created2.getId() ); assertNotNull( "Version was assigned", created2.getVersion() ); @@ -580,7 +579,7 @@ public class EntityCollectionManagerIT { final Entity newEntity = new Entity( new SimpleId( "test" ) ); - final Entity v1Created = manager.write( newEntity ).toBlocking().lastOrDefault( null ); + final Entity v1Created = manager.write( newEntity, null ).toBlocking().lastOrDefault( null ); assertNotNull( "Id was assigned", v1Created.getId() ); assertNotNull( "Version was assigned", v1Created.getVersion() ); @@ -596,7 +595,7 @@ public class EntityCollectionManagerIT { assertEquals( MvccLogEntry.State.COMPLETE, version1Log.getState() ); assertEquals( Stage.COMMITTED, version1Log.getStage() ); - final Entity v2Created = manager.write( v1Created ).toBlocking().last(); + final Entity v2Created = manager.write( v1Created, null ).toBlocking().last(); final UUID v2Version = v2Created.getVersion(); @@ -625,7 +624,7 @@ public class EntityCollectionManagerIT { final Entity newEntity = new Entity( new SimpleId( "test" ) ); - final Entity v1Created = manager.write( newEntity ).toBlocking().lastOrDefault( null ); + final Entity v1Created = manager.write( newEntity, null ).toBlocking().lastOrDefault( null ); assertNotNull( "Id was assigned", v1Created.getId() ); assertNotNull( "Version was assigned", v1Created.getVersion() ); @@ -642,7 +641,7 @@ public class EntityCollectionManagerIT { assertEquals( MvccLogEntry.State.COMPLETE, version1Log.getState() ); assertEquals( Stage.COMMITTED, version1Log.getStage() ); - final Entity v2Created = manager.write( v1Created ).toBlocking().last(); + final Entity v2Created = manager.write( v1Created, null ).toBlocking().last(); final UUID v2Version = v2Created.getVersion(); @@ -694,7 +693,7 @@ public class EntityCollectionManagerIT { final EntityCollectionManager manager = factory.createCollectionManager( context ); - final Entity saved = manager.write( entity ).toBlocking().last(); + final Entity saved = manager.write( entity, null ).toBlocking().last(); assertEquals( entity, saved ); @@ -728,7 +727,7 @@ public class EntityCollectionManagerIT { EntityCollectionManager manager = factory.createCollectionManager( context ); - Observable<Entity> observable = manager.write( newEntity ); + Observable<Entity> observable = manager.write( newEntity, null ); Entity createReturned = observable.toBlocking().lastOrDefault( null ); @@ -779,7 +778,7 @@ public class EntityCollectionManagerIT { Entity entity1 = new Entity( new SimpleId( "item" ) ); entity1.setField( new StringField( "unique_id", "1", true ) ); - manager.write( entity1 ).toBlocking().last(); + manager.write( entity1, null ).toBlocking().last(); final Observable<Id> idObs = manager.getIdField( "item", new StringField( "unique_id", "1" ) ); Id id = idObs.toBlocking().lastOrDefault( null ); @@ -790,7 +789,7 @@ public class EntityCollectionManagerIT { Entity entity2 = new Entity( new SimpleId( "deleted_item" ) ); entity2.setField( new StringField( "unique_id", "1", true ) ); manager = factory.createCollectionManager( context ); - manager.write( entity2 ).toBlocking().last(); + manager.write( entity2, null ).toBlocking().last(); final Observable<Id> id2Obs = manager.getIdField( "deleted_item", new StringField( "unique_id", "1" ) ); Id id2 = id2Obs.toBlocking().lastOrDefault( null ); @@ -808,7 +807,7 @@ public class EntityCollectionManagerIT { EntityCollectionManager manager = factory.createCollectionManager( context ); - Entity createReturned = manager.write( entity ).toBlocking().lastOrDefault( null ); + Entity createReturned = manager.write( entity, null ).toBlocking().lastOrDefault( null ); assertNotNull( "Id was assigned", createReturned.getId() ); @@ -824,7 +823,7 @@ public class EntityCollectionManagerIT { final Entity newEntity = new Entity( entityId ); newEntity.setField( new IntegerField( "counter", i ) ); - final Entity returnedEntity = manager.write( newEntity ).toBlocking().last(); + final Entity returnedEntity = manager.write( newEntity, null ).toBlocking().last(); versions.add( returnedEntity.getVersion() ); }
http://git-wip-us.apache.org/repos/asf/usergrid/blob/11aa1386/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerStressTest.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerStressTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerStressTest.java index c919c8f..7904a42 100644 --- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerStressTest.java +++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerStressTest.java @@ -81,7 +81,7 @@ public class EntityCollectionManagerStressTest { newEntity.setField(new StringField("name", String.valueOf(i))); newEntity.setField(new LocationField("location", new Location(120,40))); - Entity returned = manager.write(newEntity).toBlocking().last(); + Entity returned = manager.write(newEntity, null ).toBlocking().last(); assertNotNull("Returned has a id", returned.getId()); assertNotNull("Returned has a version", returned.getVersion()); http://git-wip-us.apache.org/repos/asf/usergrid/blob/11aa1386/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyIT.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyIT.java index 9d0cd20..15be420 100644 --- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyIT.java +++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyIT.java @@ -74,7 +74,7 @@ public class WriteUniqueVerifyIT { entity.setField(new StringField("name", "Aston Martin Vanquish", true)); entity.setField(new StringField("identifier", "v12", true)); entity.setField(new IntegerField("top_speed_mph", 200)); - entityManager.write( entity ).toBlocking().last(); + entityManager.write( entity, null ).toBlocking().last(); Entity entityFetched = entityManager.load( entity.getId() ).toBlocking().last(); entityFetched.setField( new StringField("foo", "bar")); @@ -91,7 +91,7 @@ public class WriteUniqueVerifyIT { entity2.setField(new IntegerField("top_speed_mph", 120)); try { - entityManager.write( entity2 ).toBlocking().last(); + entityManager.write( entity2, null ).toBlocking().last(); fail("Write should have thrown an exception"); } catch ( Exception ex ) { @@ -103,7 +103,7 @@ public class WriteUniqueVerifyIT { // ensure we can update original entity without error entity.setField( new IntegerField("top_speed_mph", 190) ); - entityManager.write( entity ); + entityManager.write( entity, null ); } @Test @@ -118,11 +118,11 @@ public class WriteUniqueVerifyIT { entity.setField(new StringField("name", "Porsche 911 GT3", true)); entity.setField(new StringField("identifier", "911gt3", true)); entity.setField(new IntegerField("top_speed_mph", 194)); - entityManager.write( entity ).toBlocking().last(); + entityManager.write( entity, null ).toBlocking().last(); Entity entityFetched = entityManager.load( entity.getId() ).toBlocking().last(); entityFetched.setField( new StringField("foo", "baz")); - entityManager.write( entityFetched ).toBlocking().last(); + entityManager.write( entityFetched, null ).toBlocking().last(); } @Test @@ -137,9 +137,9 @@ public class WriteUniqueVerifyIT { entity.setField(new StringField("name", "Alfa Romeo 8C Competizione", true)); entity.setField(new StringField("identifier", "ar8c", true)); entity.setField(new IntegerField("top_speed_mph", 182)); - entityManager.write( entity ).toBlocking().last(); + entityManager.write( entity, null ).toBlocking().last(); entity.setField( new StringField("foo", "bar")); - entityManager.write( entity ).toBlocking().last(); + entityManager.write( entity, null ).toBlocking().last(); } } http://git-wip-us.apache.org/repos/asf/usergrid/blob/11aa1386/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/uniquevalues/UniqueValuesServiceTest.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/uniquevalues/UniqueValuesServiceTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/uniquevalues/UniqueValuesServiceTest.java index 0847649..c6efe80 100644 --- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/uniquevalues/UniqueValuesServiceTest.java +++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/uniquevalues/UniqueValuesServiceTest.java @@ -120,7 +120,7 @@ public class UniqueValuesServiceTest { newEntity.setField( new StringField( "username", username, true ) ); newEntity.setField( new StringField( "email", username + "@example.org", true ) ); - Observable<Entity> observable = manager.write( newEntity ); + Observable<Entity> observable = manager.write( newEntity, null ); Entity returned = observable.toBlocking().lastOrDefault( null ); usersCreated.put( username, newEntity ); http://git-wip-us.apache.org/repos/asf/usergrid/blob/11aa1386/stack/rest/src/main/java/org/apache/usergrid/rest/AbstractContextResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/AbstractContextResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/AbstractContextResource.java index 77d2d1e..84ebe49 100644 --- a/stack/rest/src/main/java/org/apache/usergrid/rest/AbstractContextResource.java +++ b/stack/rest/src/main/java/org/apache/usergrid/rest/AbstractContextResource.java @@ -242,6 +242,7 @@ public abstract class AbstractContextResource { protected EntityManagerFactory getEmf(){ return emf; } + /** * Next three new methods necessary to work around inexplicable problems with EntityHolder. * This problem happens consistently when you deploy "two-dot-o" to Tomcat: http://git-wip-us.apache.org/repos/asf/usergrid/blob/11aa1386/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java index d0e675b..9373b4d 100644 --- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java +++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java @@ -86,7 +86,7 @@ public class CollectionResource extends ServiceResource { * POST settings for a collection. * * Expects a JSON object which may include: - * - fields: (array) field names to be indexed, '*' for all and 'none' for no indexing + * - fields: (array or string) either an array of field names to be indexed, or 'all' or 'none' * - region: (string) name of the authoritative region for this collection */ @POST @@ -108,7 +108,7 @@ public class CollectionResource extends ServiceResource { Object json; if ( StringUtils.isEmpty( body ) ) { - json = null; + throw new NullArgumentException( "No body posted" ); } else { json = readJsonToObject( body ); } @@ -121,25 +121,16 @@ public class CollectionResource extends ServiceResource { ServicePayload payload = getPayload( json ); - if(payload.getProperty( "fields" )==null){ - throw new NullArgumentException( "fields" ); - } - - if(! (payload.getProperty( "fields" ) instanceof ArrayList)){ - throw new NullArgumentException( "fields must be of json array type" ); - } - - - executeServicePostRequestForSettings( ui,response, ServiceAction.POST,payload ); + executeServicePostRequestForSettings( ui,response, ServiceAction.POST, payload ); return response; } - private void addItemToServiceContext( final @Context UriInfo ui, - final @PathParam( "itemName" ) PathSegment itemName ) throws Exception { - //The below is duplicated because it could change in the future and is probably not all needed but - //not determined yet. + private void addItemToServiceContext( UriInfo ui, PathSegment itemName ) throws Exception { + + // The below is duplicated because it could change in the future + // and is probably not all needed but not determined yet. if ( itemName.getPath().startsWith( "{" ) ) { Query query = Query.fromJsonString( itemName.getPath() ); if ( query != null ) { @@ -190,7 +181,7 @@ public class CollectionResource extends ServiceResource { @GET - @Path( "{itemName}/_index") + @Path( "{itemName}/_settings") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) @RequireApplicationAccess @JSONP @@ -200,7 +191,7 @@ public class CollectionResource extends ServiceResource { @QueryParam("callback") @DefaultValue("callback") String callback ) throws Exception { if(logger.isTraceEnabled()){ - logger.trace( "CollectionResource.executeGetOnIndex" ); + logger.trace( "CollectionResource.executeGetOnSettings" ); } addItemToServiceContext( ui, itemName ); http://git-wip-us.apache.org/repos/asf/usergrid/blob/11aa1386/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 9396758..500ce98 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 @@ -148,7 +148,7 @@ public class CollectionsResourceIT extends AbstractRestIT { refreshIndex(); - Collection collection = this.app().collection( "testCollections" ).collection( "_index" ).get(); + Collection collection = this.app().collection( "testCollections" ).collection( "_settings" ).get(); LinkedHashMap testCollectionSchema = (LinkedHashMap)collection.getResponse().getData(); assertEquals( "app credentials",testCollectionSchema.get( "lastUpdateBy" ) ); @@ -235,101 +235,34 @@ public class CollectionsResourceIT extends AbstractRestIT { } - @Test - public void verifyThatFieldsIsRequiredForCollectionSchema() throws Exception { - ArrayList<String> indexingArray = new ArrayList<>( ); - - //field "fields" is required. - Entity payload = new Entity(); - payload.put( "fieldWeirdnessNotFields", indexingArray); - - //Post index to the collection metadata - try { - this.app().collection( "testCollections" ).collection( "_settings" ).post( payload ); - fail(); - }catch(BadRequestException bre){ - //this is expected. - } - - //ensure that it has to be an arraylist passed in. - Map indexingMap = new HashMap<>( ); - indexingMap.put( "exludeStuff","randomtext" ); - - payload = new Entity(); - payload.put( "fields", indexingMap); - - try { - this.app().collection( "testCollections" ).collection( "_settings" ).post( payload ); - fail(); - }catch(BadRequestException bre){ - //this is expected. - } - - payload = new Entity(); - payload.put( "fields", indexingArray); - - try { - this.app().collection( "testCollections" ).collection( "_settings" ).post( payload ); - }catch(BadRequestException bre){ - fail( "This shouldn't fail" ); - } - - } - @Test public void postCollectionSchemaWithWildcardIndexAll() throws Exception { - //Creating schema. - //this could be changed to a hashmap. - ArrayList<String> indexingArray = new ArrayList<>( ); - indexingArray.add( "*" ); - indexingArray.add( "one" ); - indexingArray.add( "two" ); - - //field "fields" is required. + // setup collection with index all Entity payload = new Entity(); - payload.put( "fields", indexingArray); - - //Post index to the collection metadata - Entity thing = this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); + payload.put( "fields", "all"); + app().collection( "testCollection" ).collection( "_settings" ).post( payload ); refreshIndex(); - - Collection collection = this.app().collection( "testCollection" ).collection( "_index" ).get(); - - LinkedHashMap testCollectionSchema = (LinkedHashMap)collection.getResponse().getData(); - ArrayList<String> schema = ( ArrayList<String> ) testCollectionSchema.get( "fields" ); - assertTrue( schema.contains( "*" ) ); - assertFalse( schema.contains( "one" ) ); - assertFalse( schema.contains( "two" ) ); - - -//The above verifies the test case. - - - //Create test collection with a test entity that is partially indexed. + // post entity with two fields Entity testEntity = new Entity(); testEntity.put( "one", "helper" ); testEntity.put( "two","query" ); - - //Post entity. - this.app().collection( "testCollection" ).post( testEntity ); + app().collection( "testCollection" ).post( testEntity ); refreshIndex(); - //Do a query to see if you can find the indexed query. + // verify it can be queried on both fields + String query = "two ='query'"; QueryParameters queryParameters = new QueryParameters().setQuery(query); - - //having a name breaks it. Need to get rid of the stack trace and also - Collection tempEntity = this.app().collection( "testCollection" ).get(queryParameters,true); + Collection tempEntity = app().collection( "testCollection" ).get(queryParameters,true); Entity reindexedEntity = tempEntity.getResponse().getEntity(); assertEquals( "helper",reindexedEntity.get( "one" ) ); - //Verify if you can query on an entity that was not indexed and that no entities are returned. query = "one = 'helper'"; queryParameters = new QueryParameters().setQuery(query); - tempEntity = this.app().collection( "testCollection" ).get(queryParameters,true); + tempEntity = app().collection( "testCollection" ).get(queryParameters,true); assertEquals(1,tempEntity.getResponse().getEntities().size()); } @@ -339,8 +272,6 @@ public class CollectionsResourceIT extends AbstractRestIT { * 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 postToCollectionSchemaUpdateExistingCollection() throws Exception { @@ -420,7 +351,7 @@ public class CollectionsResourceIT extends AbstractRestIT { Entity thing = this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); refreshIndex(); - Collection collection = this.app().collection( "testCollection" ).collection( "_index" ).get(); + Collection collection = this.app().collection( "testCollection" ).collection( "_settings" ).get(); LinkedHashMap testCollectionSchema = (LinkedHashMap)collection.getResponse().getData(); assertEquals( ( thing ).get( "lastUpdated" ), testCollectionSchema.get( "lastUpdated" )); @@ -447,7 +378,7 @@ public class CollectionsResourceIT extends AbstractRestIT { //Post index to the collection metadata this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); - collection = this.app().collection( "testCollection" ).collection( "_index" ).get(); + collection = this.app().collection( "testCollection" ).collection( "_settings" ).get(); @@ -497,7 +428,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); refreshIndex(); //Create test collection with a test entity that is partially indexed. @@ -539,7 +470,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); refreshIndex(); Map<String,Object> arrayFieldsForTesting = new HashMap<>(); @@ -589,7 +520,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); refreshIndex(); Map<String,Object> arrayFieldsForTesting = new HashMap<>(); @@ -632,7 +563,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); refreshIndex(); Map<String,Object> arrayFieldsForTestingSelectiveIndexing = new HashMap<>(); @@ -687,7 +618,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); refreshIndex(); Map<String,Object> arrayFieldsForTestingSelectiveIndexing = new HashMap<>(); @@ -738,7 +669,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); refreshIndex(); //Create test collection with a test entity that is partially indexed. @@ -895,7 +826,8 @@ public class CollectionsResourceIT extends AbstractRestIT { LinkedHashMap collectionHashMap = ( LinkedHashMap ) usersDefaultCollection.getEntity().get( "metadata" ); - assertNotSame( null,((LinkedHashMap)(collectionHashMap.get( "collections" ))).get( collectionName.toLowerCase() )); + assertNotSame( null, + ((LinkedHashMap)(collectionHashMap.get( "collections" ))).get( collectionName.toLowerCase() )); this.refreshIndex(); this.app().collection( collectionName ).entity( testEntity.getEntity().getUuid() ).delete(); @@ -907,7 +839,8 @@ public class CollectionsResourceIT extends AbstractRestIT { collectionHashMap = ( LinkedHashMap ) usersDefaultCollection.getEntity().get( "metadata" ); - assertNotSame( null,((LinkedHashMap)(collectionHashMap.get( "collections" ))).get( collectionName.toLowerCase() )); + assertNotSame( null, + ((LinkedHashMap)(collectionHashMap.get( "collections" ))).get( collectionName.toLowerCase() )); Collection createdCollectionResponse = this.app().collection( collectionName ).get(); @@ -951,13 +884,8 @@ public class CollectionsResourceIT extends AbstractRestIT { @Test public void postCollectionSchemaWithWildcardIndexNone() throws Exception { - // creating schema with no index wildcard and other fields that should be ignored - ArrayList<String> indexingArray = new ArrayList<>( ); - indexingArray.add( "none" ); - indexingArray.add( "one" ); - indexingArray.add( "two" ); Entity payload = new Entity(); - payload.put( "fields", indexingArray); + payload.put( "fields", "none"); String randomizer = RandomStringUtils.randomAlphanumeric(10); String collectionName = "col_" + randomizer; @@ -965,12 +893,10 @@ public class CollectionsResourceIT extends AbstractRestIT { refreshIndex(); // was the no-index wildcard saved and others ignored? - Collection collection = app().collection( collectionName ).collection( "_index" ).get(); + Collection collection = app().collection( collectionName ).collection( "_settings" ).get(); LinkedHashMap testCollectionSchema = (LinkedHashMap)collection.getResponse().getData(); - ArrayList<String> schema = ( ArrayList<String> ) testCollectionSchema.get( "fields" ); - assertTrue( schema.contains( "none" ) ); - assertFalse( schema.contains( "one" ) ); - assertFalse( schema.contains( "two" ) ); + String schema = (String)testCollectionSchema.get( "fields" ); + assertEquals( "none", schema ); // post an entity with a name and a color String entityName = "name_" + randomizer; @@ -993,7 +919,6 @@ public class CollectionsResourceIT extends AbstractRestIT { assertFalse( getByQuery.hasNext() ); } - /** * Test that indexed entities can be connected to un-indexed Entities and connections still work. */ @@ -1096,4 +1021,57 @@ public class CollectionsResourceIT extends AbstractRestIT { assertEquals( 0, connectionsByQuery.getNumOfEntities() ); } + @Test + public void testCollectionRegion() { + + // create collection with settings for index all + + String randomizer = RandomStringUtils.randomAlphanumeric(10); + String collectionName = "col_" + randomizer; + + app().collection( collectionName ).collection( "_settings" ) + .post( new Entity().chainPut( "fields", "all" ) ); + refreshIndex(); + + // get collection settings, should see no region + + Collection collection = app().collection( collectionName ).collection( "_settings" ).get(); + Map<String, Object> settings = (Map<String, Object>)collection.getResponse().getData(); + assertNull( settings.get( "region" )); + + // set collection region with bad region, expect error + + try { + app().collection( collectionName ).collection( "_settings" ) + .post( new Entity().chainPut( "region", "us-moon-1" ) ); + fail( "post should have failed"); + + } catch ( BadRequestException expected ) {} + + // set collection region with good region + + app().collection( collectionName ).collection( "_settings" ) + .post( new Entity().chainPut( "region", "us-east-1" ) ); + + // get collection settings see that we have a region + + collection = app().collection( collectionName ).collection( "_settings" ).get(); + settings = (Map<String, Object>)collection.getResponse().getData(); + assertNotNull( settings.get( "region" )); + assertEquals( "us-east-1", settings.get( "region" )); + + // unset the collection region + + app().collection( collectionName ).collection( "_settings" ) + .post( new Entity().chainPut( "region", "" ) ); + refreshIndex(); + + // get collection settings, should see no region + + collection = app().collection( collectionName ).collection( "_settings" ).get(); + settings = (Map<String, Object>)collection.getResponse().getData(); + assertNull( settings.get( "region" )); + + + } } http://git-wip-us.apache.org/repos/asf/usergrid/blob/11aa1386/stack/services/src/main/resources/usergrid-services-context.xml ---------------------------------------------------------------------- diff --git a/stack/services/src/main/resources/usergrid-services-context.xml b/stack/services/src/main/resources/usergrid-services-context.xml index c064f60..e9b514a 100644 --- a/stack/services/src/main/resources/usergrid-services-context.xml +++ b/stack/services/src/main/resources/usergrid-services-context.xml @@ -126,7 +126,7 @@ <!--<constructor-arg orgAppName="emf" ref="entityManagerFactory" />--> <!--<constructor-arg orgAppName="metricsService" ref="metricsFactory" />--> <!--<constructor-arg orgAppName="smf" ref="serviceManagerFactory" />--> - <!--<constructor-arg orgAppName="props" ref="properties" />--> + <!--<constructor-arg orgAppName="props" ref="newSettings" />--> <!--</bean>-->
