usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject incubator-usergrid git commit: Renamed the RevisedApiResponse to be just Response and the ApiResponseCollection to be the ResponseEntityIterator to highlight the relationship between the two classes and give them less ambiguous names. Refactor in files t
Date Thu, 04 Dec 2014 19:33:20 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-256-ApiResponseImplementation 354c39750 -> c7d8f8460


Renamed the RevisedApiResponse to be just Response and the ApiResponseCollection to be the ResponseEntityIterator to highlight the relationship between the two classes and give them less ambiguous names.
Refactor in files to change to the new names.
Fixed a test in CollectionsResourceIT that shows how to get a Entity back and interact with it.


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

Branch: refs/heads/USERGRID-256-ApiResponseImplementation
Commit: c7d8f8460bf678d912e1e5faa5446fff247da65a
Parents: 354c397
Author: grey <greyes@apigee.com>
Authored: Thu Dec 4 11:33:17 2014 -0800
Committer: grey <greyes@apigee.com>
Committed: Thu Dec 4 11:33:17 2014 -0800

----------------------------------------------------------------------
 .../collection/CollectionsResourceIT.java       |  61 +-
 .../collection/users/UserResourceIT.java        |   6 +-
 .../usergrid/rest/test/resource/Response.java   | 652 +++++++++++++++++++
 .../rest/test/resource/RevisedApiResponse.java  | 652 -------------------
 .../rest/test/resource/ValueResource.java       |  15 +-
 .../resource/app/ApiResponseCollection.java     | 111 ----
 .../rest/test/resource/app/Collection.java      |  13 +-
 .../resource/app/ResponseEntityIterator.java    | 110 ++++
 8 files changed, 810 insertions(+), 810 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c7d8f846/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 f50ef73..fbe3539 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
@@ -32,8 +32,8 @@ import org.slf4j.LoggerFactory;
 import org.apache.usergrid.cassandra.Concurrent;
 import org.apache.usergrid.rest.AbstractRestIT;
 import org.apache.usergrid.rest.TestContextSetup;
-import org.apache.usergrid.rest.test.resource.app.ApiResponseCollection;
-import org.apache.usergrid.rest.test.resource.app.User;
+import org.apache.usergrid.rest.test.resource.Response;
+import org.apache.usergrid.rest.test.resource.app.ResponseEntityIterator;
 import org.apache.usergrid.utils.UUIDUtils;
 import org.apache.usergrid.rest.test.resource.app.model.Entity;
 
@@ -45,6 +45,7 @@ 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;
+import static org.junit.Assert.fail;
 
 
 /**
@@ -82,7 +83,7 @@ public class CollectionsResourceIT extends AbstractRestIT {
     public void postToEmptyCollection() throws IOException {
         Map<String, String> payload = new HashMap<String, String>();
 
-        ApiResponseCollection node = context.collection( "cities" ).postResponse( payload );
+        ResponseEntityIterator node = context.collection( "cities" ).postResponse( payload );
 
         assertFalse( node.hasNext() );
 
@@ -90,22 +91,18 @@ public class CollectionsResourceIT extends AbstractRestIT {
 
     @Test
     public void postToEmptyCollectionApiResponse() throws IOException {
-        //Map<String, String> payload = new HashMap<String, String>();
-        Map<String, String> payload = hashMap( "name", "Austin" ).map( "state", "TX" );
-
-
-        ApiResponseCollection node = context.collection( "cities" ).postResponse( payload );
-//TODO: code = node.getHTTPResponseCode();
-//        assertFalse( node.hasNext() );
+        Map<String, String> payload = new HashMap<String, String>();
 
-        Entity entity = node.getResponse().getEntities().get( 0 );
+        ResponseEntityIterator node = context.collection( "cities" ).postResponse( payload );
+        assertFalse( node.hasNext() );
 
-        ApiResponseCollection collection = context.collection( "cities" ).getResponse();
+        ResponseEntityIterator collection = context.collection( "cities" ).getResponse();
 
         assertEquals( ( Object ) 0, collection.getResponse().getCount() );
     }
 
 
+
     /**
      * emails with "me" in them are causing errors. Test we can post to a colleciton after creating a user with this
      * email
@@ -155,50 +152,48 @@ public class CollectionsResourceIT extends AbstractRestIT {
     }
 
 
+    /**
+     * Checks that we can post a string with spaces and get it back in the response.
+     * @throws IOException
+     */
     @Test
     public void stringWithSpaces() throws IOException {
 
 
         String collectionName = "calendarlists";
         Map<String, String> payload = hashMap( "summaryOverview", "My Summary" ).map( "caltype", "personal" );
+        Entity entity = null;
 
-//        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/calendarlists" )
-//                .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-//                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
-//this need to be decoupled so that it only requires client side models ( in this case we need an entity class.
-        ApiResponseCollection arc = context.collection( collectionName ).postResponse( payload );
+        ResponseEntityIterator arc = context.collection( collectionName ).postResponse( payload );
+        //pattern to check if entity that was posted , was returned in the response
+        if(arc.hasNext()){
+            entity = arc.next();
+        }
+        else
+            fail( "No entities found from post" );
 
-//TODO:broken, plz fix
-//        org.apache.usergrid.persistence.Entity entity = arc.next().toTypedEntity();
-        UUID id = null;//arc.next().getUuid();// entity.getUuid();
+        UUID id = entity.getUuid();
 
         //post a second entity
-
-
         payload = hashMap( "summaryOverview", "Your Summary" ).map( "caltype", "personal" );
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/calendarlists" ).queryParam( "access_token", access_token )
-                .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                .post( String.class, payload ));
-
+        context.collection( "calendarlists" ).postResponse( payload );
 
-        refreshIndex("test-organization", "test-app");
+        context.refreshIndex();
 
         //query for the first entity
 
         String query = "summaryOverview = 'My Summary'";
 
-
-        JsonNode queryResponse = mapper.readTree( resource().path( "/test-organization/test-app/calendarlists" )
-                .queryParam( "access_token", access_token ).queryParam( "ql", query )
-                .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+        //TODO: fix it so that queries and the other 'with' keywords can reutrn instances of iterable entities.Not just response.
+        Response queryResponse = context.collection( "calendarlists" ).withQuery( query ).getInternalResponse();
 
 
-        UUID returnedId = getEntityId( queryResponse, 0 );
+        UUID returnedId = queryResponse.getEntities().get( 0 ).getUuid();
 
         assertEquals( id, returnedId );
 
-        assertEquals( 1, queryResponse.get( "entities" ).size() );
+        assertEquals( 1, queryResponse.getEntities().size() );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c7d8f846/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
index f5ec434..ccde71f 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
@@ -43,7 +43,7 @@ import org.apache.usergrid.cassandra.Concurrent;
 import org.apache.usergrid.management.ApplicationInfo;
 import org.apache.usergrid.management.OrganizationInfo;
 import org.apache.usergrid.rest.AbstractRestIT;
-import org.apache.usergrid.rest.test.resource.RevisedApiResponse;
+import org.apache.usergrid.rest.test.resource.Response;
 import org.apache.usergrid.rest.TestContextSetup;
 import org.apache.usergrid.rest.applications.utils.UserRepo;
 import org.apache.usergrid.utils.UUIDUtils;
@@ -96,14 +96,14 @@ public class UserResourceIT extends AbstractRestIT {
                         MediaType.APPLICATION_JSON )
                                                    .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
         //JsonNode node = context.collection( "users" ).query( ql,null,null ).;
-        RevisedApiResponse node = null;
+        Response node = null;
 
         try {
             node = resource().path( "/"+context.getOrgName()+"/"+context.getAppName()+"/users" ).queryParam( "ql", ql )
                                                 .queryParam( "access_token",
                                                         context.getActiveUser().getToken() ).accept(
                             MediaType.APPLICATION_JSON )
-                                                .type( MediaType.APPLICATION_JSON_TYPE ).get( RevisedApiResponse.class );
+                                                .type( MediaType.APPLICATION_JSON_TYPE ).get( Response.class );
         }catch(Exception e){
             e.printStackTrace();
             fail();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c7d8f846/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/Response.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/Response.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/Response.java
new file mode 100644
index 0000000..99474c1
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/Response.java
@@ -0,0 +1,652 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.rest.test.resource;
+
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter;
+import com.fasterxml.jackson.annotation.JsonAnySetter;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.UUID;
+
+import javax.xml.bind.annotation.XmlAnyElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.apache.usergrid.persistence.AggregateCounterSet;
+import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.rest.ServerEnvironmentProperties;
+import org.apache.usergrid.security.oauth.ClientCredentialsInfo;
+import org.apache.usergrid.services.ServiceRequest;
+import org.apache.usergrid.services.ServiceResults;
+import org.apache.usergrid.utils.InflectionUtils;
+
+import org.apache.commons.lang.ClassUtils;
+import org.apache.commons.lang.StringUtils;
+
+import static org.apache.usergrid.utils.InflectionUtils.pluralize;
+import org.apache.usergrid.rest.test.resource.app.model.Entity;
+
+//TODO: code = node.getHTTPResponseCode(); We need a way to see the httpResponseCode
+//TODO: Move this into the testing framework
+@JsonPropertyOrder( {
+        "action", "application", "params", "path", "query", "uri", "status", "error", "applications", "entity",
+        "entities", "list", "data", "next", "timestamp", "duration"
+} )
+@XmlRootElement
+public class Response {
+
+    private ServiceRequest esp;
+//TODO: investigate that errors are all properly set/ http responsecode, error description, The error Code thrown form the stack.
+    private String error;
+    private String errorDescription;
+    private String errorUri;
+    private String exception; //illegal_argument
+    private String callback;
+
+    private String path;
+    private String uri;
+    private String status;
+    private long timestamp;
+    private String organization;
+    private String applicationName;
+    private UUID application;
+    private List<Entity> entities;
+    private UUID next;
+    private String cursor;
+    private Integer count;
+    private String action;
+    private List<Object> list;
+    private Object data;
+    private Map<String, UUID> applications;
+    private Map<String, Object> metadata;
+    private Map<String, List<String>> params;
+    private List<AggregateCounterSet> counters;
+    private ClientCredentialsInfo credentials;
+
+    protected Map<String, Object> properties = new TreeMap<String, Object>( String.CASE_INSENSITIVE_ORDER );
+
+    @Autowired
+    protected ServerEnvironmentProperties serverEnvironmentProperties;
+
+
+    public Response() {
+        timestamp = System.currentTimeMillis();
+    }
+
+
+    public Response( ServerEnvironmentProperties properties ) {
+        this.serverEnvironmentProperties = properties;
+        timestamp = System.currentTimeMillis();
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public String getCallback() {
+        return callback;
+    }
+
+
+    public void setCallback( String callback ) {
+        this.callback = callback;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public String getError() {
+        return error;
+    }
+
+
+    @JsonProperty("error")
+    public void setError( String code ) {
+        error = code;
+    }
+
+
+    public static String exceptionToErrorCode( Throwable e ) {
+        if ( e == null ) {
+            return "service_error";
+        }
+        String s = ClassUtils.getShortClassName( e.getClass() );
+        s = StringUtils.removeEnd( s, "Exception" );
+        s = InflectionUtils.underscore( s ).toLowerCase();
+        return s;
+    }
+
+
+    public Response withError( String code ) {
+        return withError( code, null, null );
+    }
+
+
+    public void setError( Throwable e ) {
+        setError( null, null, e );
+    }
+
+
+    public Response withError( Throwable e ) {
+        return withError( null, null, e );
+    }
+
+
+    public void setError( String description, Throwable e ) {
+        setError( null, description, e );
+    }
+
+
+    public Response withError( String description, Throwable e ) {
+        return withError( null, description, e );
+    }
+
+
+
+    public void setError( String code, String description, Throwable e ) {
+        if ( code == null ) {
+            code = exceptionToErrorCode( e );
+        }
+        error = code;
+        errorDescription = description;
+        if ( e != null ) {
+            if ( description == null ) {
+                errorDescription = e.getMessage();
+            }
+            exception = e.getClass().getName();
+        }
+    }
+
+
+    public Response withError( String code, String description, Throwable e ) {
+        setError( code, description, e );
+        return this;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    @JsonProperty( "error_description" )
+    public String getErrorDescription() {
+        return errorDescription;
+    }
+
+
+    @JsonProperty( "error_description" )
+    public void setErrorDescription( String errorDescription ) {
+        this.errorDescription = errorDescription;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    @JsonProperty( "error_uri" )
+    public String getErrorUri() {
+        return errorUri;
+    }
+
+
+    @JsonProperty( "error_uri" )
+    public void setErrorUri( String errorUri ) {
+        this.errorUri = errorUri;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public String getException() {
+        return exception;
+    }
+
+
+    public void setException( String exception ) {
+        this.exception = exception;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public String getPath() {
+        return path;
+    }
+
+
+    public void setPath( String path ) {
+        if ( path == null ) {
+            this.path = null;
+            uri = null;
+        }
+        this.path = path;
+        //uri = createPath( path );
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public String getUri() {
+        return uri;
+    }
+
+    public void setUri(String uri) {
+        //not entirely sure this works
+//        if( uri == null){
+//            uri = createPath( getPath() );
+//        }
+        this.uri = uri;
+    }
+
+
+    public void setServiceRequest( ServiceRequest p ) {
+        esp = p;
+        if ( p != null ) {
+            path = p.getPath();
+            uri = createPath( path );
+        }
+    }
+
+
+    public Response withServiceRequest( ServiceRequest p ) {
+        setServiceRequest( p );
+        return this;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public String getStatus() {
+        return status;
+    }
+
+
+    public void setSuccess() {
+        status = "ok";
+    }
+
+
+    public Response withSuccess() {
+        status = "ok";
+        return this;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public long getDuration() {
+        return System.currentTimeMillis() - timestamp;
+    }
+
+
+    public void setTimestamp( long timestamp ) {
+        this.timestamp = timestamp;
+    }
+
+
+    public Response withTimestamp( long timestamp ) {
+        this.timestamp = timestamp;
+        return this;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public long getTimestamp() {
+        return timestamp;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public String getAction() {
+        return action;
+    }
+
+
+    public void setAction( String action ) {
+        this.action = action;
+    }
+
+
+    public Response withAction( String action ) {
+        this.action = action;
+        return this;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public UUID getApplication() {
+        return application;
+    }
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public String applicationName() {
+        return applicationName;
+    }
+
+
+    /** @return the orgId */
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public String getOrganization() {
+        return organization;
+    }
+
+
+
+    public void setApplication( Application app) {
+        this.application = app.getUuid();
+    }
+
+    /** Set the application and organization information */
+//    public void setApplication( Application app ) {
+//        this.organization = app.getOrganizationName();
+//        this.applicationName = app.getApplicationName();
+//        this.application = app.getUuid();
+//
+//        if ( esp != null ) {
+//            uri = createPath( esp.toString() );
+//        }
+//    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    @XmlAnyElement
+    public List<Entity> getEntities() {
+        return entities;
+    }
+
+
+    public void setEntities( List<Entity> entities ) {
+        if ( entities != null ) {
+            this.entities = entities;
+        }
+        else {
+            this.entities = new ArrayList<Entity>();
+        }
+    }
+
+
+    public Response withEntities( List<Entity> entities ) {
+        setEntities( entities );
+        return this;
+    }
+
+
+    public void setResults( ServiceResults results ) {
+        if ( results != null ) {
+            setPath( results.getPath() );
+            //entities = results.getEntities();
+            next = results.getNextResult();
+            cursor = results.getCursor();
+            counters = results.getCounters();
+        }
+        else {
+            entities = new ArrayList<Entity>();
+        }
+    }
+
+
+    public Response withResults( ServiceResults results ) {
+        setResults( results );
+        return this;
+    }
+
+
+    public Response withResultsCount( ServiceResults results ) {
+        setResults( results );
+        if ( results != null ) {
+            count = results.size();
+        }
+        return this;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public UUID getNext() {
+        return next;
+    }
+
+
+    public void setNext( UUID next ) {
+        this.next = next;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public String getCursor() {
+        return cursor;
+    }
+
+
+    public void setCursor( String cursor ) {
+        this.cursor = cursor;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public Integer getCount() {
+        return count;
+    }
+
+
+    public void setCount( Integer count ) {
+        this.count = count;
+    }
+
+
+    public Response withEntity( Entity entity ) {
+        entities = new ArrayList<Entity>();
+        entities.add( entity );
+        return this;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public List<Object> getList() {
+        return list;
+    }
+
+
+    public void setList( List<Object> list ) {
+        if ( list != null ) {
+            this.list = list;
+        }
+        else {
+            this.list = new ArrayList<Object>();
+        }
+    }
+
+
+    public Response withList( List<Object> list ) {
+        setList( list );
+        return this;
+    }
+
+
+    public Response withListCount( List<Object> list ) {
+        setList( list );
+        if ( !list.isEmpty() ) {
+            this.count = list.size();
+        }
+        return this;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public Object getData() {
+        return data;
+    }
+
+
+    public void setData( Object data ) {
+        if ( data != null ) {
+            this.data = data;
+        }
+        else {
+            this.data = new LinkedHashMap<String, Object>();
+        }
+    }
+
+
+    public Response withData( Object data ) {
+        setData( data );
+        return this;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public List<AggregateCounterSet> getCounters() {
+        return counters;
+    }
+
+
+    public void setCounters( List<AggregateCounterSet> counters ) {
+        this.counters = counters;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public Map<String, UUID> getApplications() {
+        return applications;
+    }
+
+
+    public void setApplications( Map<String, UUID> applications ) {
+        this.applications = applications;
+    }
+
+
+    public Response withApplications( Map<String, UUID> applications ) {
+        this.applications = applications;
+        return this;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public ClientCredentialsInfo getCredentials() {
+        return credentials;
+    }
+
+
+    public void setCredentials( ClientCredentialsInfo credentials ) {
+        this.credentials = credentials;
+    }
+
+
+    public Response withCredentials( ClientCredentialsInfo credentials ) {
+        this.credentials = credentials;
+        return this;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public Map<String, List<String>> getParams() {
+        return params;
+    }
+
+
+    public void setParams( Map<String, List<String>> params ) {
+        Map<String, List<String>> q = new LinkedHashMap<String, List<String>>();
+        for ( String k : params.keySet() ) {
+            List<String> v = params.get( k );
+            if ( v != null ) {
+                q.put( k, new ArrayList<String>( v ) );
+            }
+        }
+        this.params = q;
+    }
+
+
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public Map<String, Object> getMetadata() {
+        return metadata;
+    }
+
+
+    public void setMetadata( Map<String, Object> metadata ) {
+        this.metadata = metadata;
+    }
+
+
+    public String getEntityPath( String url_base, org.apache.usergrid.persistence.Entity entity ) {
+        String entity_uri = null;
+        if ( !Application.ENTITY_TYPE.equals( entity.getType() ) ) {
+            entity_uri = createPath( pluralize( entity.getType() ), entity.getUuid().toString() );
+        }
+        else {
+            entity_uri = createPath();
+        }
+        return entity_uri;
+    }
+
+//TODO: figure out what this does.
+//    public void prepareEntities() {
+//        if ( uri != null ) {
+//            String url_base = serverEnvironmentProperties.getApiBase();
+//            if ( entities != null ) {
+//                for ( Entity entity : entities ) {
+//                    String entity_uri = getEntityPath( url_base, entity );
+//                    entity.setMetadata( "uri", entity_uri );
+//                    entity.setMetadata( "path", path + "/" + entity.getUuid() );
+//                }
+//            }
+//        }
+//    }
+
+
+    @JsonAnyGetter
+    public Map<String, Object> getProperties() {
+        return properties;
+    }
+
+
+    @JsonAnySetter
+    public void setProperty( String key, Object value ) {
+        properties.put( key, value );
+    }
+
+
+    /**
+     * Create a path
+     *
+     * @return `
+     */
+    private String createPath( String... suffixes ) {
+
+        StringBuilder builder = new StringBuilder();
+
+        builder.append( serverEnvironmentProperties.getApiBase() );
+        if ( !serverEnvironmentProperties.getApiBase().endsWith( "/" ) ) {
+            builder.append( "/" );
+        }
+        builder.append( organization );
+        builder.append( "/" );
+        builder.append( applicationName );
+
+        if ( suffixes.length == 0 ) {
+            return builder.toString();
+        }
+
+
+        for ( String current : suffixes ) {
+            if ( current == null ) {
+                continue;
+            }
+
+            if ( !current.startsWith( "/" ) ) {
+                builder.append( "/" );
+            }
+            builder.append( current );
+        }
+
+        return builder.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c7d8f846/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/RevisedApiResponse.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/RevisedApiResponse.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/RevisedApiResponse.java
deleted file mode 100644
index 96dacee..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/RevisedApiResponse.java
+++ /dev/null
@@ -1,652 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.rest.test.resource;
-
-
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonAnySetter;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.UUID;
-
-import javax.xml.bind.annotation.XmlAnyElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.apache.usergrid.persistence.AggregateCounterSet;
-import org.apache.usergrid.persistence.entities.Application;
-import org.apache.usergrid.rest.ServerEnvironmentProperties;
-import org.apache.usergrid.security.oauth.ClientCredentialsInfo;
-import org.apache.usergrid.services.ServiceRequest;
-import org.apache.usergrid.services.ServiceResults;
-import org.apache.usergrid.utils.InflectionUtils;
-
-import org.apache.commons.lang.ClassUtils;
-import org.apache.commons.lang.StringUtils;
-
-import static org.apache.usergrid.utils.InflectionUtils.pluralize;
-import org.apache.usergrid.rest.test.resource.app.model.Entity;
-
-
-//TODO: Move this into the testing framework
-@JsonPropertyOrder( {
-        "action", "application", "params", "path", "query", "uri", "status", "error", "applications", "entity",
-        "entities", "list", "data", "next", "timestamp", "duration"
-} )
-@XmlRootElement
-public class RevisedApiResponse  {
-
-    private ServiceRequest esp;
-//TODO: investigate that errors are all properly set/ http responsecode, error description, The error Code thrown form the stack.
-    private String error;
-    private String errorDescription;
-    private String errorUri;
-    private String exception; //illegal_argument
-    private String callback;
-
-    private String path;
-    private String uri;
-    private String status;
-    private long timestamp;
-    private String organization;
-    private String applicationName;
-    private UUID application;
-    private List<Entity> entities;
-    private UUID next;
-    private String cursor;
-    private Integer count;
-    private String action;
-    private List<Object> list;
-    private Object data;
-    private Map<String, UUID> applications;
-    private Map<String, Object> metadata;
-    private Map<String, List<String>> params;
-    private List<AggregateCounterSet> counters;
-    private ClientCredentialsInfo credentials;
-
-    protected Map<String, Object> properties = new TreeMap<String, Object>( String.CASE_INSENSITIVE_ORDER );
-
-    @Autowired
-    protected ServerEnvironmentProperties serverEnvironmentProperties;
-
-
-    public RevisedApiResponse() {
-        timestamp = System.currentTimeMillis();
-    }
-
-
-    public RevisedApiResponse( ServerEnvironmentProperties properties ) {
-        this.serverEnvironmentProperties = properties;
-        timestamp = System.currentTimeMillis();
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public String getCallback() {
-        return callback;
-    }
-
-
-    public void setCallback( String callback ) {
-        this.callback = callback;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public String getError() {
-        return error;
-    }
-
-
-    @JsonProperty("error")
-    public void setError( String code ) {
-        error = code;
-    }
-
-
-    public static String exceptionToErrorCode( Throwable e ) {
-        if ( e == null ) {
-            return "service_error";
-        }
-        String s = ClassUtils.getShortClassName( e.getClass() );
-        s = StringUtils.removeEnd( s, "Exception" );
-        s = InflectionUtils.underscore( s ).toLowerCase();
-        return s;
-    }
-
-
-    public RevisedApiResponse withError( String code ) {
-        return withError( code, null, null );
-    }
-
-
-    public void setError( Throwable e ) {
-        setError( null, null, e );
-    }
-
-
-    public RevisedApiResponse withError( Throwable e ) {
-        return withError( null, null, e );
-    }
-
-
-    public void setError( String description, Throwable e ) {
-        setError( null, description, e );
-    }
-
-
-    public RevisedApiResponse withError( String description, Throwable e ) {
-        return withError( null, description, e );
-    }
-
-
-
-    public void setError( String code, String description, Throwable e ) {
-        if ( code == null ) {
-            code = exceptionToErrorCode( e );
-        }
-        error = code;
-        errorDescription = description;
-        if ( e != null ) {
-            if ( description == null ) {
-                errorDescription = e.getMessage();
-            }
-            exception = e.getClass().getName();
-        }
-    }
-
-
-    public RevisedApiResponse withError( String code, String description, Throwable e ) {
-        setError( code, description, e );
-        return this;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    @JsonProperty( "error_description" )
-    public String getErrorDescription() {
-        return errorDescription;
-    }
-
-
-    @JsonProperty( "error_description" )
-    public void setErrorDescription( String errorDescription ) {
-        this.errorDescription = errorDescription;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    @JsonProperty( "error_uri" )
-    public String getErrorUri() {
-        return errorUri;
-    }
-
-
-    @JsonProperty( "error_uri" )
-    public void setErrorUri( String errorUri ) {
-        this.errorUri = errorUri;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public String getException() {
-        return exception;
-    }
-
-
-    public void setException( String exception ) {
-        this.exception = exception;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public String getPath() {
-        return path;
-    }
-
-
-    public void setPath( String path ) {
-        if ( path == null ) {
-            this.path = null;
-            uri = null;
-        }
-        this.path = path;
-        //uri = createPath( path );
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public String getUri() {
-        return uri;
-    }
-
-    public void setUri(String uri) {
-        //not entirely sure this works
-//        if( uri == null){
-//            uri = createPath( getPath() );
-//        }
-        this.uri = uri;
-    }
-
-
-    public void setServiceRequest( ServiceRequest p ) {
-        esp = p;
-        if ( p != null ) {
-            path = p.getPath();
-            uri = createPath( path );
-        }
-    }
-
-
-    public RevisedApiResponse withServiceRequest( ServiceRequest p ) {
-        setServiceRequest( p );
-        return this;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public String getStatus() {
-        return status;
-    }
-
-
-    public void setSuccess() {
-        status = "ok";
-    }
-
-
-    public RevisedApiResponse withSuccess() {
-        status = "ok";
-        return this;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public long getDuration() {
-        return System.currentTimeMillis() - timestamp;
-    }
-
-
-    public void setTimestamp( long timestamp ) {
-        this.timestamp = timestamp;
-    }
-
-
-    public RevisedApiResponse withTimestamp( long timestamp ) {
-        this.timestamp = timestamp;
-        return this;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public long getTimestamp() {
-        return timestamp;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public String getAction() {
-        return action;
-    }
-
-
-    public void setAction( String action ) {
-        this.action = action;
-    }
-
-
-    public RevisedApiResponse withAction( String action ) {
-        this.action = action;
-        return this;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public UUID getApplication() {
-        return application;
-    }
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public String applicationName() {
-        return applicationName;
-    }
-
-
-    /** @return the orgId */
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public String getOrganization() {
-        return organization;
-    }
-
-
-
-    public void setApplication( Application app) {
-        this.application = app.getUuid();
-    }
-
-    /** Set the application and organization information */
-//    public void setApplication( Application app ) {
-//        this.organization = app.getOrganizationName();
-//        this.applicationName = app.getApplicationName();
-//        this.application = app.getUuid();
-//
-//        if ( esp != null ) {
-//            uri = createPath( esp.toString() );
-//        }
-//    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    @XmlAnyElement
-    public List<Entity> getEntities() {
-        return entities;
-    }
-
-
-    public void setEntities( List<Entity> entities ) {
-        if ( entities != null ) {
-            this.entities = entities;
-        }
-        else {
-            this.entities = new ArrayList<Entity>();
-        }
-    }
-
-
-    public RevisedApiResponse withEntities( List<Entity> entities ) {
-        setEntities( entities );
-        return this;
-    }
-
-
-    public void setResults( ServiceResults results ) {
-        if ( results != null ) {
-            setPath( results.getPath() );
-            //entities = results.getEntities();
-            next = results.getNextResult();
-            cursor = results.getCursor();
-            counters = results.getCounters();
-        }
-        else {
-            entities = new ArrayList<Entity>();
-        }
-    }
-
-
-    public RevisedApiResponse withResults( ServiceResults results ) {
-        setResults( results );
-        return this;
-    }
-
-
-    public RevisedApiResponse withResultsCount( ServiceResults results ) {
-        setResults( results );
-        if ( results != null ) {
-            count = results.size();
-        }
-        return this;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public UUID getNext() {
-        return next;
-    }
-
-
-    public void setNext( UUID next ) {
-        this.next = next;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public String getCursor() {
-        return cursor;
-    }
-
-
-    public void setCursor( String cursor ) {
-        this.cursor = cursor;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public Integer getCount() {
-        return count;
-    }
-
-
-    public void setCount( Integer count ) {
-        this.count = count;
-    }
-
-
-    public RevisedApiResponse withEntity( Entity entity ) {
-        entities = new ArrayList<Entity>();
-        entities.add( entity );
-        return this;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public List<Object> getList() {
-        return list;
-    }
-
-
-    public void setList( List<Object> list ) {
-        if ( list != null ) {
-            this.list = list;
-        }
-        else {
-            this.list = new ArrayList<Object>();
-        }
-    }
-
-
-    public RevisedApiResponse withList( List<Object> list ) {
-        setList( list );
-        return this;
-    }
-
-
-    public RevisedApiResponse withListCount( List<Object> list ) {
-        setList( list );
-        if ( !list.isEmpty() ) {
-            this.count = list.size();
-        }
-        return this;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public Object getData() {
-        return data;
-    }
-
-
-    public void setData( Object data ) {
-        if ( data != null ) {
-            this.data = data;
-        }
-        else {
-            this.data = new LinkedHashMap<String, Object>();
-        }
-    }
-
-
-    public RevisedApiResponse withData( Object data ) {
-        setData( data );
-        return this;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public List<AggregateCounterSet> getCounters() {
-        return counters;
-    }
-
-
-    public void setCounters( List<AggregateCounterSet> counters ) {
-        this.counters = counters;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public Map<String, UUID> getApplications() {
-        return applications;
-    }
-
-
-    public void setApplications( Map<String, UUID> applications ) {
-        this.applications = applications;
-    }
-
-
-    public RevisedApiResponse withApplications( Map<String, UUID> applications ) {
-        this.applications = applications;
-        return this;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public ClientCredentialsInfo getCredentials() {
-        return credentials;
-    }
-
-
-    public void setCredentials( ClientCredentialsInfo credentials ) {
-        this.credentials = credentials;
-    }
-
-
-    public RevisedApiResponse withCredentials( ClientCredentialsInfo credentials ) {
-        this.credentials = credentials;
-        return this;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public Map<String, List<String>> getParams() {
-        return params;
-    }
-
-
-    public void setParams( Map<String, List<String>> params ) {
-        Map<String, List<String>> q = new LinkedHashMap<String, List<String>>();
-        for ( String k : params.keySet() ) {
-            List<String> v = params.get( k );
-            if ( v != null ) {
-                q.put( k, new ArrayList<String>( v ) );
-            }
-        }
-        this.params = q;
-    }
-
-
-    @JsonSerialize( include = Inclusion.NON_NULL )
-    public Map<String, Object> getMetadata() {
-        return metadata;
-    }
-
-
-    public void setMetadata( Map<String, Object> metadata ) {
-        this.metadata = metadata;
-    }
-
-
-    public String getEntityPath( String url_base, org.apache.usergrid.persistence.Entity entity ) {
-        String entity_uri = null;
-        if ( !Application.ENTITY_TYPE.equals( entity.getType() ) ) {
-            entity_uri = createPath( pluralize( entity.getType() ), entity.getUuid().toString() );
-        }
-        else {
-            entity_uri = createPath();
-        }
-        return entity_uri;
-    }
-
-//TODO: figure out what this does.
-//    public void prepareEntities() {
-//        if ( uri != null ) {
-//            String url_base = serverEnvironmentProperties.getApiBase();
-//            if ( entities != null ) {
-//                for ( Entity entity : entities ) {
-//                    String entity_uri = getEntityPath( url_base, entity );
-//                    entity.setMetadata( "uri", entity_uri );
-//                    entity.setMetadata( "path", path + "/" + entity.getUuid() );
-//                }
-//            }
-//        }
-//    }
-
-
-    @JsonAnyGetter
-    public Map<String, Object> getProperties() {
-        return properties;
-    }
-
-
-    @JsonAnySetter
-    public void setProperty( String key, Object value ) {
-        properties.put( key, value );
-    }
-
-
-    /**
-     * Create a path
-     *
-     * @return `
-     */
-    private String createPath( String... suffixes ) {
-
-        StringBuilder builder = new StringBuilder();
-
-        builder.append( serverEnvironmentProperties.getApiBase() );
-        if ( !serverEnvironmentProperties.getApiBase().endsWith( "/" ) ) {
-            builder.append( "/" );
-        }
-        builder.append( organization );
-        builder.append( "/" );
-        builder.append( applicationName );
-
-        if ( suffixes.length == 0 ) {
-            return builder.toString();
-        }
-
-
-        for ( String current : suffixes ) {
-            if ( current == null ) {
-                continue;
-            }
-
-            if ( !current.startsWith( "/" ) ) {
-                builder.append( "/" );
-            }
-            builder.append( current );
-        }
-
-        return builder.toString();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c7d8f846/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 d5f0053..74fcbc5 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
@@ -102,10 +102,10 @@ public abstract class ValueResource extends NamedResource {
     }
 
     //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 {
+    protected Response postInternalResponse( Map<String, ?> entity ) throws IOException {
 
         return mapper.readValue( jsonMedia( withParams( withToken( resource() ) ) ).post( String.class, entity ),
-                RevisedApiResponse.class );
+                Response.class );
     }
 
 
@@ -138,9 +138,14 @@ public abstract class ValueResource extends NamedResource {
 
         }
     }
+    //TODO: I think this class needs to return a ApiResponseCollection
 
-    public RevisedApiResponse getInternalResponse() {
+    public Response getInternalResponse() {
         try {
+//TODO: I believe this code needs to be added here so that we can use the with Keywords and still get the appropriate  apiResponsecollection Back
+//            CollectionResource collectionResource = new CollectionResource( this.getName(),this.getParent() );
+//            ApiResponseCollection collectionRevisedApiResponse = new ApiResponseCollection(collectionResource,this.getInternalResponse() );
+//            return collectionRevisedApiResponse;
             return getInternalApiResponse();
         }
         catch ( IOException e ) {
@@ -236,7 +241,7 @@ public abstract class ValueResource extends NamedResource {
         return mapper.readTree( json );
     }
 //TODO: find better name / design paradigm for the methods that call upon this class
-    protected RevisedApiResponse getInternalApiResponse() throws IOException {
+    protected Response getInternalApiResponse() throws IOException {
         WebResource resource = withParams( withToken( resource() ) );
 
 
@@ -256,7 +261,7 @@ public abstract class ValueResource extends NamedResource {
             resource = resource.queryParam( "limit", limit.toString() );
         }
 
-        return  jsonMedia( resource ).get( RevisedApiResponse.class );
+        return  jsonMedia( resource ).get( Response.class );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c7d8f846/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
deleted file mode 100644
index 32a1da0..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/ApiResponseCollection.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.rest.test.resource.app;
-
-
-import java.util.Iterator;
-
-import org.apache.usergrid.rest.test.resource.RevisedApiResponse;
-import org.apache.usergrid.rest.test.resource.CollectionResource;
-import org.apache.usergrid.rest.test.resource.app.model.Entity;
-
-
-/**
- * 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
- *
- * Keep generics? Maybe just use entities for now
- * 1.) Primary key
- * 2.) Default data-> default data is different from type to type. (Groups would need path and title, Activities require actors...etc)
- * 3.) Things that you can do with them-> Groups create connections or something else. Adding users to a group. ( this can be boiled down to creating a connection )
- *
- * Two connecting builder patterns
- * 1. POST /collection/entity/verb (e.g. likes or following)/collection/entity  //connect any two entities
- *  - POST /users/fred/following/users/barney
- * 2. POST /collection/entity/collection/entity //for built in collections e.g. add user to group, add role to group, etc
- *  - POST users/fred/groups/funlovincriminals
- *
- * Two similar builder patterns for getting connected entities
- * 1. GET /users/fred/following
- * 2. GET /users/fred/groups
- *
- */
-public class ApiResponseCollection implements Iterable, Iterator {
-
-    private final CollectionResource sourceEndpoint;
-    private RevisedApiResponse response;
-
-
-    public Iterator entities;
-
-
-    public ApiResponseCollection(final CollectionResource sourceCollection, final RevisedApiResponse response){
-        this.response = response;
-        this.sourceEndpoint = sourceCollection;
-        this.entities = response.getEntities().iterator();
-    }
-
-    public RevisedApiResponse getResponse(){
-        return response;
-    }
-
-    @Override
-    public Iterator iterator() {
-        return this;
-    }
-
-
-    @Override
-    public boolean hasNext() {
-        if(!entities.hasNext()){
-            advance();
-        }
-
-        return entities.hasNext();
-    }
-
-
-    @Override
-    public Entity next() {
-        return (Entity)entities.next();
-    }
-
-
-    /**
-     * Go back to the endpoint and try to load the next page
-     */
-    private void advance(){
-
-      //call the original resource for the next page.
-
-        final String cursor = response.getCursor();
-
-        //no next page
-        if(cursor == null){
-            return;
-        }
-
-        response = sourceEndpoint.withCursor( cursor ).getInternalResponse();
-        this.entities = response.getEntities().iterator();
-    }
-
-
-    @Override
-    public void remove() {
-        throw new UnsupportedOperationException( "Remove is unsupported" );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c7d8f846/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 7d3e526..2363515 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
@@ -20,7 +20,7 @@ package org.apache.usergrid.rest.test.resource.app;
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.usergrid.rest.test.resource.RevisedApiResponse;
+import org.apache.usergrid.rest.test.resource.Response;
 import org.apache.usergrid.rest.test.resource.CollectionResource;
 import org.apache.usergrid.rest.test.resource.NamedResource;
 import org.apache.usergrid.rest.test.resource.SetResource;
@@ -81,11 +81,11 @@ public class Collection extends SetResource {
         return getEntity( response, 0 );
     }
 
-    public  ApiResponseCollection postResponse(Map entityData) throws IOException{
+    public ResponseEntityIterator postResponse(Map entityData) throws IOException{
 
         CollectionResource collectionResource = new CollectionResource( this.getName(),this.getParent() );
-        RevisedApiResponse response = this.postInternalResponse( entityData );
-        ApiResponseCollection collectionRevisedApiResponse = new ApiResponseCollection(collectionResource,response );
+        Response response = this.postInternalResponse( entityData );
+        ResponseEntityIterator collectionRevisedApiResponse = new ResponseEntityIterator(collectionResource,response );
 
         return collectionRevisedApiResponse;
     }
@@ -96,9 +96,10 @@ public class Collection extends SetResource {
      * @return
      * @throws IOException
      */
-    public ApiResponseCollection getResponse() throws IOException  {
+    public ResponseEntityIterator getResponse() throws IOException  {
         CollectionResource collectionResource = new CollectionResource( this.getName(),this.getParent() );
-        ApiResponseCollection collectionRevisedApiResponse = new ApiResponseCollection(collectionResource,this.getInternalResponse() );
+        ResponseEntityIterator
+                collectionRevisedApiResponse = new ResponseEntityIterator(collectionResource,this.getInternalResponse() );
         return collectionRevisedApiResponse;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c7d8f846/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/ResponseEntityIterator.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/ResponseEntityIterator.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/ResponseEntityIterator.java
new file mode 100644
index 0000000..b550c55
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/ResponseEntityIterator.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.rest.test.resource.app;
+
+
+import java.util.Iterator;
+
+import org.apache.usergrid.rest.test.resource.Response;
+import org.apache.usergrid.rest.test.resource.CollectionResource;
+import org.apache.usergrid.rest.test.resource.app.model.Entity;
+
+
+/**
+ * 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.
+ * Keep generics? Maybe just use entities for now
+ * 1.) Primary key
+ * 2.) Default data-> default data is different from type to type. (Groups would need path and title, Activities require actors...etc)
+ * 3.) Things that you can do with them-> Groups create connections or something else. Adding users to a group. ( this can be boiled down to creating a connection )
+ *
+ * Two connecting builder patterns
+ * 1. POST /collection/entity/verb (e.g. likes or following)/collection/entity  //connect any two entities
+ *  - POST /users/fred/following/users/barney
+ * 2. POST /collection/entity/collection/entity //for built in collections e.g. add user to group, add role to group, etc
+ *  - POST users/fred/groups/funlovincriminals
+ *
+ * Two similar builder patterns for getting connected entities
+ * 1. GET /users/fred/following
+ * 2. GET /users/fred/groups
+ *
+ */
+public class ResponseEntityIterator implements Iterable, Iterator {
+
+    private final CollectionResource sourceEndpoint;
+    private Response response;
+
+
+    public Iterator entities;
+
+
+    public ResponseEntityIterator( final CollectionResource sourceCollection, final Response response ){
+        this.response = response;
+        this.sourceEndpoint = sourceCollection;
+        this.entities = response.getEntities().iterator();
+    }
+
+    public Response getResponse(){
+        return response;
+    }
+
+    @Override
+    public Iterator iterator() {
+        return this;
+    }
+
+
+    @Override
+    public boolean hasNext() {
+        if(!entities.hasNext()){
+            advance();
+        }
+
+        return entities.hasNext();
+    }
+
+
+    @Override
+    public Entity next() {
+        return (Entity)entities.next();
+    }
+
+
+    /**
+     * Go back to the endpoint and try to load the next page
+     */
+    private void advance(){
+
+      //call the original resource for the next page.
+
+        final String cursor = response.getCursor();
+
+        //no next page
+        if(cursor == null){
+            return;
+        }
+
+        response = sourceEndpoint.withCursor( cursor ).getInternalResponse();
+        this.entities = response.getEntities().iterator();
+    }
+
+
+    @Override
+    public void remove() {
+        throw new UnsupportedOperationException( "Remove is unsupported" );
+    }
+}


Mime
View raw message