You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2014/12/02 21:38:23 UTC
[2/2] incubator-usergrid git commit: Fixed the CollectionsResourceIT
tests to use the RevisedApiResponse. Added todo to RevisedApiResponse Added a
new postInternalResponse method to Value Resource in order to keep older
tests working. Added getResponse m
Fixed the CollectionsResourceIT tests to use the RevisedApiResponse.
Added todo to RevisedApiResponse
Added a new postInternalResponse method to Value Resource in order to keep older tests working.
Added getResponse method so that we could easily query the api response from the ApiResponseCollection.
Added postREsponse collection to the Collection so that we could response specific operations.
Added in test method to groups in order to start seeing how these changes will affect new 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/d11974d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/d11974d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/d11974d4
Branch: refs/heads/USERGRID-256-ApiResponseImplementation
Commit: d11974d4a1370f08082a9d5c6da075c5ba144f2d
Parents: 29f666c
Author: grey <gr...@apigee.com>
Authored: Tue Dec 2 12:17:45 2014 -0800
Committer: grey <gr...@apigee.com>
Committed: Tue Dec 2 12:17:45 2014 -0800
----------------------------------------------------------------------
.../usergrid/rest/RevisedApiResponse.java | 2 +-
.../collection/CollectionsResourceIT.java | 23 +++++++-------------
.../rest/test/resource/ValueResource.java | 8 ++++++-
.../resource/app/ApiResponseCollection.java | 8 +++++--
.../rest/test/resource/app/Collection.java | 12 +++++++++-
.../test/resource/app/GroupsCollection.java | 10 +++++----
6 files changed, 39 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d11974d4/stack/rest/src/main/java/org/apache/usergrid/rest/RevisedApiResponse.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/RevisedApiResponse.java b/stack/rest/src/main/java/org/apache/usergrid/rest/RevisedApiResponse.java
index 648541c..ddf14c8 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/RevisedApiResponse.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/RevisedApiResponse.java
@@ -47,7 +47,7 @@ import org.apache.commons.lang.StringUtils;
import static org.apache.usergrid.utils.InflectionUtils.pluralize;
-
+//TODO: Move this into the testing framework
@JsonPropertyOrder( {
"action", "application", "params", "path", "query", "uri", "status", "error", "applications", "entity",
"entities", "list", "data", "next", "timestamp", "duration"
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d11974d4/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 d60caf0..540a8e1 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
@@ -42,6 +42,7 @@ import com.sun.jersey.api.client.UniformInterfaceException;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.apache.usergrid.utils.MapUtils.hashMap;
@@ -81,32 +82,24 @@ public class CollectionsResourceIT extends AbstractRestIT {
@Test
public void postToEmptyCollection() throws IOException {
Map<String, String> payload = new HashMap<String, String>();
- //for whatever reason this does a getEntity before returning the post, i think this is a bug needs to be fixed.
- //after api response stuff is handled. We should only be getting the raw response.
- JsonNode node = context.collection( "cities" ).post( payload );
- assertNull( getEntity( node, 0 ) );
- //why doens't this work?
- //assertNull( node.get( "count" ) );
+ ApiResponseCollection node = context.collection( "cities" ).postResponse( payload );
+
+ assertFalse( node.hasNext() );
+
}
@Test
public void postToEmptyCollectionApiResponse() throws IOException {
Map<String, String> payload = new HashMap<String, String>();
-//this get response always returns a jsonnode of the entity, seems wrong. Should return response.
- // JsonNode node = context.collection( "cities" ).post( payload );
-// JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/cities" ).queryParam( "access_token", context.getActiveUser().get )
-// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-// .post( String.class, payload ));
- // assertNull( node );
- JsonNode node = context.collection( "cities" ).post( payload );
+ ApiResponseCollection node = context.collection( "cities" ).postResponse( payload );
- assertNull(node);
+ assertFalse( node.hasNext() );
ApiResponseCollection<Collection> collection = context.collection( "cities" ).getCollectionResponse();
- assertNotNull( collection );
+ assertEquals( ( Object ) 0, collection.getResponse().getCount() );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d11974d4/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
index 7842b27..09a412b 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
@@ -100,7 +100,13 @@ public abstract class ValueResource extends NamedResource {
//TODO: fix error reporting
protected JsonNode postInternal( Map<String, ?> entity ) throws IOException {
- return mapper.readTree( jsonMedia( withParams( withToken( resource() ) ) ).post( String.class, entity ));
+ return mapper.readTree( jsonMedia( withParams( withToken( resource() ) ) ).post( String.class, entity ) );
+ }
+
+ //TODO: eventually we need to merge this and make it the offical postInternal. this was not done to keep tests compiling.
+ protected RevisedApiResponse postInternalResponse( Map<String, ?> entity ) throws IOException {
+
+ return jsonMedia( withParams( withToken( resource() ) ) ).post( RevisedApiResponse.class, entity );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d11974d4/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/ApiResponseCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/ApiResponseCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/ApiResponseCollection.java
index ddb2a8a..74b2238 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/ApiResponseCollection.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/ApiResponseCollection.java
@@ -10,8 +10,8 @@ import org.apache.usergrid.rest.test.resource.CollectionResource;
/**
- * A stateful iterable collection respose. This is a "collection" of entities from our response that are easier
- * to work with
+ * A stateful iterable collection response. This is a "collection" of entities from our response that are easier
+ * to work with. The Generic means that we can type cast the iterator
*/
public class ApiResponseCollection<T> implements Iterable<T>, Iterator<T> {
@@ -28,6 +28,10 @@ public class ApiResponseCollection<T> implements Iterable<T>, Iterator<T> {
this.entities = response.getEntities().iterator();
}
+ public RevisedApiResponse<T> getResponse(){
+ return response;
+ }
+
@Override
public Iterator<T> iterator() {
return this;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d11974d4/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
index 2990cfe..4925d19 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
@@ -70,7 +70,8 @@ public class Collection extends SetResource {
}
/**
- * POST an entity with only a Map
+ * POST an entity with only a Map. Talk to rod about this. I think the ApiResponse should only handle responses back
+ * that were called but maybe
* @param entityData
* @return JsonNode
* @throws IOException
@@ -82,6 +83,15 @@ public class Collection extends SetResource {
return getEntity( response, 0 );
}
+ public ApiResponseCollection<Collection> postResponse(Map entityData) throws IOException{
+
+ CollectionResource collectionResource = new CollectionResource( this.getName(),this.getParent() );
+ RevisedApiResponse response = this.postInternalResponse( entityData );
+ ApiResponseCollection<Collection> collectionRevisedApiResponse = new ApiResponseCollection<>(collectionResource,response );
+
+ return collectionRevisedApiResponse;
+ }
+
/**
* Creates a ApiResponseCollection which takes in an api response returns it as a collection of the type handed in
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d11974d4/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java
index b3cd548..9601c3f 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java
@@ -58,10 +58,12 @@ public class GroupsCollection extends CollectionResource {
}
//example of what a call could look like
-// public ApiResponseCollection<Group> get() throws IOException {
-// //create new ApiResponseCollection from ApiResponse then return to user for further processing.
-// return this.getResponse();
-// }
+ public ApiResponseCollection<Group> getResource() throws IOException {
+ //create new ApiResponseCollection from ApiResponse then return to user for further processing.
+ CollectionResource collectionResource = new CollectionResource( this.getName(),this.getParent() );
+ ApiResponseCollection<Group> collectionRevisedApiResponse = new ApiResponseCollection<>(collectionResource,this.getResponse() );
+ return collectionRevisedApiResponse;
+ }