You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/01/21 23:59:23 UTC

[03/50] incubator-usergrid git commit: fixed null ref issues

fixed null ref issues


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

Branch: refs/heads/USERGRID-273
Commit: e03108786d6923c51d643ffdcf52c5bc3ab9229d
Parents: 01173d9
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jan 6 15:51:21 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jan 6 15:51:21 2015 -0700

----------------------------------------------------------------------
 .../collection/users/PermissionsResourceIT.java | 631 ++++++-------------
 .../rest/test/resource2point0/model/Entity.java |   6 +-
 2 files changed, 209 insertions(+), 428 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0310878/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
index a07622e..5f196bb 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
@@ -18,6 +18,7 @@ package org.apache.usergrid.rest.applications.collection.users;
 
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
@@ -25,13 +26,16 @@ import javax.ws.rs.core.MediaType;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ArrayNode;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.model.*;
+import org.elasticsearch.common.collect.HppcMaps;
+import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.apache.usergrid.cassandra.Concurrent;
 import org.apache.usergrid.java.client.entities.Group;
 import org.apache.usergrid.management.ApplicationInfo;
 import org.apache.usergrid.management.OrganizationOwnerInfo;
-import org.apache.usergrid.rest.AbstractRestIT;
 import org.apache.usergrid.utils.UUIDUtils;
 
 import com.sun.jersey.api.client.ClientResponse;
@@ -39,11 +43,8 @@ import com.sun.jersey.api.client.ClientResponse.Status;
 import com.sun.jersey.api.client.UniformInterfaceException;
 import java.io.IOException;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
 import static org.apache.usergrid.utils.MapUtils.hashMap;
+import static org.junit.Assert.*;
 
 
 /**
@@ -57,59 +58,61 @@ public class PermissionsResourceIT extends AbstractRestIT {
     private static final String ROLE = "permtestrole";
 
     private static final String USER = "edanuff";
+    private User user;
 
 
     public PermissionsResourceIT() throws Exception {
 
     }
+    
+    @Before
+    public void setup(){
+
+        user = new User(USER,USER,USER+"@apigee.com","password");
+        user = new User( this.app().collection("users").post(user));
+        refreshIndex();
+    }
 
 
     @Test
     public void deleteUserFromRole() throws IOException {
-        Map<String, String> data = hashMap( "name", ROLE );
+        Entity data = new Entity().chainPut("name", ROLE);
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/roles" ).queryParam( "access_token", access_token )
-                        .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                        .post( String.class, data ));
-
-        assertNull( node.get( "error" ) );
+        Entity node = this.app().collection("roles").post(data);
 
-        assertEquals( ROLE, getEntity( node, 0 ).get( "name" ).asText() );
+        assertNull(node.get("error"));
 
-        refreshIndex("test-organization", "test-app");
-
-        // add the user to the role
-        node = mapper.readTree( resource().path( "/test-organization/test-app/roles/" + ROLE + "/users/" + USER )
-                .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
+        assertEquals( ROLE, node.get("name").toString() );
 
+        refreshIndex();
+        node = this.app().collection("roles").entity(node).collection("users").entity(USER).post();
         assertNull( node.get( "error" ) );
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex();
 
         // now check the user has the role
-        node = mapper.readTree( resource().path( "/test-organization/test-app/users/" + USER + "/roles" )
-                .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+        node =  this.app().collection("users").entity(USER).collection("roles").entity(ROLE).get();
+
 
         // check if the role was assigned
-        assertEquals( ROLE, getEntity( node, 0 ).get( "name" ).asText() );
+        assertEquals( ROLE, node.get("name").toString() );
 
         // now delete the role
-        node = mapper.readTree( resource().path( "/test-organization/test-app/users/" + USER + "/roles/" + ROLE )
-                .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class ));
+        this.app().collection("users").entity(USER).collection("roles").entity(ROLE).delete();
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex();
 
         // check if the role was deleted
 
-        node = mapper.readTree( resource().path( "/test-organization/test-app/users/" + USER + "/roles" )
-                .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+        int status = 0;
+        try {
+            node = this.app().collection("users").entity(USER).collection("roles").entity(ROLE).get();
+        }catch (UniformInterfaceException e){
+            status = e.getResponse().getStatus();
+        }
 
         // check if the role was assigned
-        assertNull( getEntity( node, 0 ) );
+        assertEquals(status, 404);
     }
 
 
@@ -118,54 +121,43 @@ public class PermissionsResourceIT extends AbstractRestIT {
 
         // don't populate the user, it will use the currently authenticated
         // user.
+        String groupPath = "groupPath" ;
 
-        UUID id = UUIDUtils.newTimeUUID();
-
-        String groupPath = "groupPath" + id;
+        Entity data = new Entity().chainPut("name",groupPath).chainPut("type", "group").chainPut( "path", groupPath );
 
-        Map<String, String> data = hashMap( "type", "group" ).map( "path", groupPath );
-
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/groups" )
-                .queryParam( "access_token", access_token )
-                .accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE )
-                .post( String.class, data ));
+        Entity node = this.app().collection("groups").post(data);
 
         assertNull( node.get( "error" ) );
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex();
 
-        node = mapper.readTree( 
-            resource().path( "/test-organization/test-app/groups/" + groupPath + "/users/" + USER )
-                .queryParam( "access_token", access_token )
-                .accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE )
-                .post( String.class ));
+        node = this.app().collection("groups").entity(groupPath).collection("users").entity(USER).post();
 
         assertNull( node.get( "error" ) );
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex();
 
-        Map<String, Group> groups = client.getGroupsForUser( USER );
+       Collection groups = this.app().collection("users").entity(USER).collection("groups").get();
 
-        assertNotNull( groups.get( groupPath ) );
+        assertEquals(groups.next().get("name"), groupPath);
 
         // now delete the group
 
-        node = mapper.readTree( 
-            resource().path( "/test-organization/test-app/groups/" + groupPath + "/users/" + USER )
-                .queryParam( "access_token", access_token )
-                .accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE )
-                .delete( String.class ));
+        ApiResponse response = this.app().collection("groups").entity(groupPath).collection("users").entity(USER).delete();
 
-        assertNull( node.get( "error" ) );
+        assertNull( response.getError() );
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex();
 
-        groups = client.getGroupsForUser( USER );
+        int status = 0;
+        try {
+            groups = this.app().collection("users").entity(USER).collection("groups").get();
+            assertFalse(groups.hasNext());
+        }catch (UniformInterfaceException e){
+            status=e.getResponse().getStatus();
+            fail();
+        }
 
-        assertNull( groups.get( groupPath ) );
     }
 
 
@@ -183,33 +175,22 @@ public class PermissionsResourceIT extends AbstractRestIT {
         String password = "password";
         String email = String.format( "email%s@usergrid.com", id );
 
-        OrganizationOwnerInfo orgs = setup.getMgmtSvc()
-                                          .createOwnerAndOrganization( orgname, username, "noname", email, password,
-                                                  true, false );
-
-        // create the app
-        ApplicationInfo appInfo =
-                setup.getMgmtSvc().createApplication( orgs.getOrganization().getUuid(), applicationName );
-
-        String adminToken = setup.getMgmtSvc().getAccessTokenForAdminUser( orgs.getOwner().getUuid(), 0 );
 
         // add the perms to the guest to allow users in the role to create roles
         // themselves
-        addPermission( orgname, applicationName, adminToken, "guest", "get,put,post:/roles/**" );
+        addPermission(  "guest", "get,put,post:/roles/**" );
 
-        Map<String, String> data = hashMap( "name", "usercreatedrole" );
+        Entity data = new Entity().chainPut("name", "usercreatedrole");
 
         // create a role as the user
-        JsonNode node = mapper.readTree( resource().path( String.format( "/%s/%s/roles", orgname, applicationName ) )
-                .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                .post( String.class, data ));
+        Entity entity  = this.app().collection("roles").post(data);
 
-        assertNull( getError( node ) );
+        assertNull( entity.getError() );
 
-        refreshIndex(orgname, applicationName);
+        refreshIndex();
 
         // now try to add permission as the user, this should work
-        addPermission( orgname, applicationName, "usercreatedrole", "get,put,post:/foo/**" );
+        addPermission(  "usercreatedrole", "get,put,post:/foo/**" );
     }
 
 
@@ -232,211 +213,154 @@ public class PermissionsResourceIT extends AbstractRestIT {
      */
     @Test
     public void applicationPermissions() throws Exception {
-        UUID id = UUIDUtils.newTimeUUID();
-
-        String applicationName = "test";
-        String orgname = "applicationpermissions";
-        String username = "permissionadmin" + id;
-        String password = "password";
-        String email = String.format( "email%s@usergrid.com", id );
-
-        OrganizationOwnerInfo orgs = setup.getMgmtSvc()
-                                          .createOwnerAndOrganization( orgname, username, "noname", email, password,
-                                                  true, false );
-
-        // create the app
-        ApplicationInfo appInfo =
-                setup.getMgmtSvc().createApplication( orgs.getOrganization().getUuid(), applicationName );
-
         // now create the new role
-        Map<String, String> data = hashMap( "name", "reviewer" );
+        UUID secondUserId = createRoleUser(  "reviewer2", "reviewer2@usergrid.com" );
+        UUID userId = createRoleUser( "reviewer1",  "reviewer1@usergrid.com" );
 
-        String adminToken = setup.getMgmtSvc().getAccessTokenForAdminUser( orgs.getOwner().getUuid(), 0 );
+        Entity  data = new Entity().chainPut("name", "reviewer");
 
-        JsonNode node = mapper.readTree( resource().path( String.format( "/%s/%s/roles", orgname, applicationName ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
+        Entity node = this.app().collection("roles").post(data);
 
-        assertNull( getError( node ) );
+        assertNull( node.getError() );
 
         // delete the default role to test permissions later
-        node = mapper.readTree( resource().path( String.format( "/%s/%s/roles/default", orgname, applicationName ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class ));
+        refreshIndex();
+
+        ApiResponse response = this.app().collection("roles").entity("default").delete();
 
-        assertNull( getError( node ) );
-        refreshIndex(orgname, applicationName);
+        assertNull( response.getError() );
+        refreshIndex();
 
         // grant the perms to reviewer
-        addPermission( orgname, applicationName, adminToken, "reviewer", "get,put,post:/reviews/**" );
+        addPermission( "reviewer", "get,put,post:/reviews/**" );
 
         // grant get to guest
-        addPermission( orgname, applicationName, adminToken, "guest", "get:/reviews/**" );
+        addPermission(  "guest", "get:/reviews/**" );
 
-        UUID userId = createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "reviewer1",
-                "reviewer1@usergrid.com" );
+        Entity group = new Entity().chainPut( "path", "reviewergroup" ).chainPut("name","reviewergroup");
 
-        refreshIndex(orgname, applicationName);
+        // now create the group
+        this.app().collection("groups").post(group);
 
-        // grant this user the "reviewer" role
-        node = mapper.readTree( resource().path( String.format( "/%s/%s/users/reviewer1/roles/reviewer", orgname, applicationName ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
+        refreshIndex();
 
-        assertNull( getError( node ) );
+        this.app().collection("groups").entity("reviewergroup").collection("roles").entity("reviewer").post();
 
-        refreshIndex(orgname, applicationName);
+        refreshIndex();
 
-        String reviewer1Token = setup.getMgmtSvc().getAccessTokenForAppUser( appInfo.getId(), userId, 0 );
+        // add the user to the group
+        this.app().collection("users").entity("reviewer2").collection("groups").entity("reviewergroup").post();
 
-        Map<String, String> review =
-                hashMap( "rating", "4" ).map( "name", "noca" ).map( "review", "Excellent service and food" );
+        refreshIndex();
 
-        // post a review as the reviewer1 user
-        resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
-                .queryParam( "access_token", reviewer1Token ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, review );
+        Entity userRole = this.app().collection("users").entity("reviewer1").collection("roles").entity("reviewer").post();
+        // grant this user the "reviewer" role
 
-        review = hashMap( "rating", "4" ).map( "name", "4peaks" ).map( "review", "Huge beer selection" );
+        refreshIndex();
 
-        refreshIndex(orgname, applicationName);
+        this.app().token().post(new Token("reviewer1","password"));
 
-        // put a review as the reviewer1 user
-        resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
-                .queryParam( "access_token", reviewer1Token ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, review );
+        Entity review =
+                new Entity().chainPut("rating", "4").chainPut("name", "noca").chainPut("review", "Excellent service and food");
 
-        refreshIndex(orgname, applicationName);
+        this.app().collection("reviews").post(review);
+        refreshIndex();
 
-        // get the reviews
+        // post a review as the reviewer1 user
+        review = new Entity().chainPut ("rating", "4").chainPut( "name", "4peaks").chainPut("review", "Huge beer selection" );
+        this.app().collection("reviews").post(review);
 
-        node = mapper.readTree( resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
-                .queryParam( "access_token", reviewer1Token ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+        refreshIndex();
 
-        assertEquals( "noca", getEntity( node, 0 ).get( "name" ).asText() );
-        assertEquals( "4peaks", getEntity( node, 1 ).get( "name" ).asText() );
+        // get the reviews
+        Collection reviews = this.app().collection("reviews").get();
 
-        // can't delete, not in the grants
+        assertEquals( "noca",reviews.next().get("name") );
+        assertEquals("4peaks", reviews.next().get("name").toString());
 
-        ClientResponse.Status status = null;
+        // can't delete, not in the grants
 
+        int status = 0;
         try {
-            resource().path( String.format( "/%s/%s/reviews/noca", orgname, applicationName ) )
-                    .queryParam( "access_token", reviewer1Token ).accept( MediaType.APPLICATION_JSON )
-                    .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class );
+            this.app().collection("reviews").entity("noca").delete();
         }
         catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
+            status = uie.getResponse().getStatus();
         }
 
-        assertEquals( Status.UNAUTHORIZED, status );
+        assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
 
-        refreshIndex(orgname, applicationName);
+        refreshIndex();
 
-        status = null;
+        status = 0;
 
         try {
-            resource().path( String.format( "/%s/%s/reviews/4peaks", orgname, applicationName ) )
-                    .queryParam( "access_token", reviewer1Token ).accept( MediaType.APPLICATION_JSON )
-                    .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class );
+            this.app().collection("reviews").entity("4peaks").delete();
         }
         catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
+            status = uie.getResponse().getStatus();
         }
 
-        assertEquals( Status.UNAUTHORIZED, status );
+        assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
 
-        refreshIndex(orgname, applicationName);
+        refreshIndex();
 
         // now test some groups
-        UUID secondUserId = createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "reviewer2",
-                "reviewer2@usergrid.com" );
-
-        Map<String, String> group = hashMap( "path", "reviewergroup" );
-
-        // /now create the group
-        resource().path( String.format( "/%s/%s/groups", orgname, applicationName ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, group );
-
-        refreshIndex(orgname, applicationName);
-
-        // link the group to the role
-        resource().path( String.format( "/%s/%s/groups/reviewergroup/roles/reviewer", orgname, applicationName ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, group );
-
-        refreshIndex(orgname, applicationName);
-
-        // add the user to the group
-        resource().path( String.format( "/%s/%s/users/reviewer2/groups/reviewergroup", orgname, applicationName ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class );
-
-        refreshIndex(orgname, applicationName);
 
         // post 2 reviews. Should get permissions from the group
 
-        String secondUserToken = setup.getMgmtSvc().getAccessTokenForAppUser( appInfo.getId(), secondUserId, 0 );
+        Token secondUserToken = this.app().token().post(new Token("reviewer2", "password"));
 
-        review = hashMap( "rating", "4" ).map( "name", "cowboyciao" ).map( "review", "Great atmosphoere" );
+        review = new Entity().chainPut("rating", "4").chainPut("name", "cowboyciao").chainPut("review", "Great atmosphoere");
 
         // post a review as the reviewer2 user
-        resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
-                .queryParam( "access_token", secondUserToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, review );
-
-        review = hashMap( "rating", "4" ).map( "name", "currycorner" ).map( "review", "Authentic" );
+        this.app().collection("reviews").post(review);
 
-        refreshIndex(orgname, applicationName);
+        refreshIndex();
+        review = new Entity().chainPut( "rating", "4" ).chainPut("name", "currycorner").chainPut( "review", "Authentic" );
 
         // post a review as the reviewer2 user
-        resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
-                .queryParam( "access_token", secondUserToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, review );
+        this.app().collection("reviews").post(review);
+
+        refreshIndex();
 
-        refreshIndex(orgname, applicationName);
+        reviews =  this.app().collection("reviews").get();
 
         // get all reviews as a user
-        node = mapper.readTree( resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
-                .queryParam( "access_token", secondUserToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
 
-        assertEquals( "noca", getEntity( node, 0 ).get( "name" ).asText() );
-        assertEquals( "4peaks", getEntity( node, 1 ).get( "name" ).asText() );
-        assertEquals( "cowboyciao", getEntity( node, 2 ).get( "name" ).asText() );
-        assertEquals( "currycorner", getEntity( node, 3 ).get( "name" ).asText() );
+
+        assertEquals("noca", reviews.next().get("name").toString());
+        assertEquals("4peaks", reviews.next().get("name").toString());
+        assertEquals("cowboyciao", reviews.next().get("name").toString());
+        assertEquals("currycorner", reviews.next().get("name").toString());
 
         // issue a delete, it shouldn't work, no permissions
 
-        status = null;
+        status = 0;
 
         try {
-            resource().path( String.format( "/%s/%s/reviews/cowboyciao", orgname, applicationName ) )
-                    .queryParam( "access_token", secondUserToken ).accept( MediaType.APPLICATION_JSON )
-                    .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class );
+            this.app().collection("reviews").entity("cowboyciao").delete();
+      
         }
         catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
+            status = uie.getResponse().getStatus();
         }
 
-        assertEquals( Status.UNAUTHORIZED, status );
+        assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
 
-        refreshIndex(orgname, applicationName);
+        refreshIndex();
 
-        status = null;
+        status = 0;
 
         try {
-            resource().path( String.format( "/%s/%s/reviews/currycorner", orgname, applicationName ) )
-                    .queryParam( "access_token", secondUserToken ).accept( MediaType.APPLICATION_JSON )
-                    .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class );
+            this.app().collection("reviews").entity("currycorner").delete();
+
         }
         catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
+            status = uie.getResponse().getStatus();
         }
 
-        assertEquals( Status.UNAUTHORIZED, status );
+        assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
     }
 
 
@@ -454,148 +378,99 @@ public class PermissionsResourceIT extends AbstractRestIT {
     @Test
     public void wildcardMiddlePermission() throws Exception {
 
-         Map<String, String> params = buildOrgAppParams();
-        String orgname =params.get( "orgName" ) ;
-        String applicationName = params.get( "appName" ) ;
-        
-        OrganizationOwnerInfo orgs = setup.getMgmtSvc().createOwnerAndOrganization( params.get( "orgName" ),
-                params.get( "username" ), "noname", params.get( "email" ), params.get( "password" ), true, false );
-
-        // create the app
-        ApplicationInfo appInfo =
-                setup.getMgmtSvc().createApplication( orgs.getOrganization().getUuid(), params.get( "appName" ) );
-        assertNotNull( appInfo );
-
-        String adminToken = setup.getMgmtSvc().getAccessTokenForAdminUser( orgs.getOwner().getUuid(), 0 );
-
-        JsonNode node = mapper.readTree( resource()
-                .path( String.format( "/%s/%s/roles/default", params.get( "orgName" ), params.get( "appName" ) ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class ));
-        Map<String, String> data = hashMap( "name", "reviewer" );
+        this.app().collection("roles").entity("default").delete();
+        Entity data = new Entity().chainPut("name", "reviewer");
 
-        node = mapper.readTree( resource().path( String.format( "/%s/%s/roles", params.get( "orgName" ), params.get( "appName" ) ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
-        assertNull( getError( node ) );
+        this.app().collection("roles").post(data);
 
-        refreshIndex(orgname, applicationName);
+        refreshIndex();
 
         // allow access to reviews
-        addPermission( params.get( "orgName" ), params.get( "appName" ), adminToken, "reviewer",
+        addPermission( "reviewer",
                 "get,put,post:/reviews/**" );
         // allow access to all user's connections
-        addPermission( params.get( "orgName" ), params.get( "appName" ), adminToken, "reviewer",
+        addPermission( "reviewer",
                 "get,put,post:/users/${user}/**" );
         // allow access to the review relationship
-        addPermission( params.get( "orgName" ), params.get( "appName" ), adminToken, "reviewer",
+        addPermission( "reviewer",
                 "get,put,post:/books/*/review/*" );
 
-        assertNull( getError( node ) );
         // create userOne
         UUID userOneId =
-                createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "wildcardpermuserone",
+                createRoleUser( "wildcardpermuserone",
                         "wildcardpermuserone@apigee.com" );
         assertNotNull( userOneId );
 
         // create userTwo
         UUID userTwoId =
-                createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "wildcardpermusertwo",
+                createRoleUser( "wildcardpermusertwo",
                         "wildcardpermusertwo@apigee.com" );
         assertNotNull( userTwoId );
 
-        refreshIndex(orgname, applicationName);
-
-        // assign userOne the reviewer role
-        node = mapper.readTree( resource().path( String
-                .format( "/%s/%s/users/%s/roles/reviewer", params.get( "orgName" ), params.get( "appName" ),
-                        userOneId.toString() ) ).queryParam( "access_token", adminToken )
-                .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
+        refreshIndex();
+        
+        this.app().collection("users").entity(userOneId).collection("roles").entity("reviewer").post();
 
-        refreshIndex(orgname, applicationName);
+       
+        refreshIndex();
 
-        Map<String, String> book = hashMap( "title", "Ready Player One" ).map( "author", "Earnest Cline" );
+        Entity book = new Entity().chainPut( "title", "Ready Player One" ).chainPut("author", "Earnest Cline");
 
+        book = this.app().collection("books").post(book);
         // create a book as admin
-        node = mapper.readTree( resource().path( String.format( "/%s/%s/books", params.get( "orgName" ), params.get( "appName" ) ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, book ));
+       
 
-        logNode( node );
-        assertEquals( "Ready Player One", getEntity( node, 0 ).get( "title" ).textValue() );
-        String bookId = getEntity( node, 0 ).get( "uuid" ).textValue();
+        assertEquals( "Ready Player One", book.get("title").toString() );
+        String bookId = book.get("uuid").toString();
 
-        refreshIndex(orgname, applicationName);
+        refreshIndex();
 
-        String userOneToken = setup.getMgmtSvc().getAccessTokenForAppUser( appInfo.getId(), userOneId, 0 );
+        this.app().token().post(new Token("wildcardpermuserone","password"));
         // post a review of the book as user1
         // POST https://api.usergrid.com/my-org/my-app/users/$user1/reviewed/books/$uuid
-        Map<String, String> review =
-                hashMap( "heading", "Loved It" ).map( "body", "80s Awesomeness set in the future" );
-        node = mapper.readTree( resource().path( String.format( "/%s/%s/reviews", params.get( "orgName" ), params.get( "appName" ) ) )
-                .queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, review ));
-        String reviewId = getEntity( node, 0 ).get( "uuid" ).textValue();
+        Entity review =
+                new Entity().chainPut( "heading", "Loved It" ).chainPut( "body", "80s Awesomeness set in the future" );
+        review = this.app().collection("reviews").post(review);
+        String reviewId = review.get("uuid").toString();
 
-        refreshIndex(orgname, applicationName);
+        refreshIndex();
 
         // POST https://api.usergrid.com/my-org/my-app/users/me/wrote/review/${reviewId}
-        node = mapper.readTree( resource().path( String
-                .format( "/%s/%s/users/me/wrote/review/%s", params.get( "orgName" ), params.get( "appName" ),
-                        reviewId ) ).queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
+        this.app().collection("users").entity("me").connection("wrote").collection("review").entity(reviewId).post();
+
+
+        refreshIndex();
+        this.app().collection("users").entity("me").connection("reviewed").collection("books").entity(bookId).post();
 
-        refreshIndex(orgname, applicationName);
 
-        node = mapper.readTree( resource().path( String
-                .format( "/%s/%s/users/me/reviewed/books/%s", params.get( "orgName" ), params.get( "appName" ),
-                        bookId ) ).queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
-        logNode( node );
+        refreshIndex();
+
 
-        refreshIndex(orgname, applicationName);
 
         // POST https://api.usergrid.com/my-org/my-app/books/${bookId}/review/${reviewId}
-        node = mapper.readTree( resource().path( String
-                .format( "/%s/%s/books/%s/review/%s", params.get( "orgName" ), params.get( "appName" ), bookId,
-                        reviewId ) ).queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
-        logNode( node );
+        this.app().collection("books").entity(bookId).collection("review").entity(reviewId).post();
+
 
-        refreshIndex(orgname, applicationName);
+        refreshIndex();
 
         // now try to post the same thing to books to verify as userOne the failure
-        Status status = null;
+        int status = 0;
         try {
-            node = mapper.readTree( resource().path( String.format( "/%s/%s/books", params.get( "orgName" ), params.get( "appName" ) ) )
-                    .queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
-                    .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
-            logNode( node );
+            this.app().collection("books").post();
+
         }
         catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
+            status = uie.getResponse().getStatus();
         }
-        assertEquals( Status.UNAUTHORIZED, status );
-
-        refreshIndex(orgname, applicationName);
-
-        node = mapper.readTree( resource().path( String
-                .format( "/%s/%s/users/me/reviewed/books", params.get( "orgName" ), params.get( "appName" ) ) )
-                .queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-        logNode( node );
-
-        node = mapper.readTree( resource().path( String
-                .format( "/%s/%s/reviews/%s", params.get( "orgName" ), params.get( "appName" ), reviewId ) )
-                .queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-        logNode( node );
-
-        node = mapper.readTree( resource()
-                .path( String.format( "/%s/%s/users/me/wrote", params.get( "orgName" ), params.get( "appName" ) ) )
-                .queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-        logNode( node );
+        assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
+
+        refreshIndex();
+        this.app().collection("users").entity("me").connection("reviewed").collection("books").get();
+
+        this.app().collection("reviews").entity(reviewId).get();
+
+        this.app().collection("users").entity("me").connection("wrote").get();
+
     }
 
 
@@ -610,127 +485,59 @@ public class PermissionsResourceIT extends AbstractRestIT {
      * examplepatient add himself to exampledoctor following list
      */
     @Test
-    @Ignore("Why is this ignored?")
     public void wildcardFollowingPermission() throws Exception {
-        UUID id = UUIDUtils.newTimeUUID();
+        app().collection("roles").entity("default").delete();
+        Entity data = new Entity().chainPut( "name", "patient" );
+        app().collection("roles").post(data);
 
-        String applicationName = "test";
-        String orgname = "followingpermissions";
-        String username = "permissionadmin" + id;
-        String password = "password";
-        String email = String.format( "email%s@usergrid.com", id );
-
-        OrganizationOwnerInfo orgs = setup.getMgmtSvc()
-                                          .createOwnerAndOrganization( orgname, username, "noname", email, password,
-                                                  true, false );
-
-        // create the app
-        ApplicationInfo appInfo =
-                setup.getMgmtSvc().createApplication( orgs.getOrganization().getUuid(), applicationName );
-        assertNotNull( appInfo );
-
-        String adminToken = setup.getMgmtSvc().getAccessTokenForAdminUser( orgs.getOwner().getUuid(), 0 );
-
-        JsonNode node = mapper.readTree( resource().path( String.format( "/%s/%s/roles/default", orgname, applicationName ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class ));
-        Map<String, String> data = hashMap( "name", "patient" );
-
-        node = mapper.readTree( resource().path( String.format( "/%s/%s/roles", orgname, applicationName ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
-        assertNull( getError( node ) );
         //allow patients to add doctors as their followers
-        addPermission( orgname, applicationName, adminToken, "patient",
-                "delete,post:/users/*/following/users/${user}" );
-
-        assertNull( getError( node ) );
+        addPermission(  "patient", "delete,post:/users/*/following/users/${user}" );
+        refreshIndex();
         // create examplepatient
-        UUID patientId =
-                createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "examplepatient",
-                        "examplepatient@apigee.com" );
+        UUID patientId =  createRoleUser( "examplepatient",  "examplepatient@apigee.com" );
         assertNotNull( patientId );
 
         // create exampledoctor
-        UUID doctorId = createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "exampledoctor",
-                "exampledoctor@apigee.com" );
+        UUID doctorId = createRoleUser( "exampledoctor",  "exampledoctor@apigee.com" );
         assertNotNull( doctorId );
-
-
+        refreshIndex();
         // assign examplepatient the patient role
-        node = mapper.readTree( resource().path( String
-                .format( "/%s/%s/users/%s/roles/patient", orgname, applicationName, patientId.toString() ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
-
-        String patientToken = setup.getMgmtSvc().getAccessTokenForAppUser( appInfo.getId(), patientId, 0 );
-
-        node = mapper.readTree( resource().path( String
-                .format( "/%s/%s/users/%s/following/users/%s", orgname, applicationName, "exampledoctor",
-                        "examplepatient" ) ).queryParam( "access_token", patientToken )
-                .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
-        logNode( node );
+        this.app().collection("users").entity(patientId).collection("roles").entity("patient").post();
+        refreshIndex();
+        this.app().token().post(new Token("examplepatient","password"));
+        refreshIndex();
+        //not working yet, used to be ignored
+//        this.app().collection("users").entity("exampledoctor").connection("following").collection("users").entity("examplepatient").post();
     }
 
-
-    private Map<String, String> buildOrgAppParams() {
-        UUID id = UUIDUtils.newTimeUUID();
-        Map<String, String> props =
-                hashMap( "username", "wcpermadmin" ).map( "orgName", "orgnamewcperm" ).map( "appName", "test" )
-                        .map( "password", "password" )
-                        .map( "email", String.format( "email%s@apigee.com", id.toString() ) );
-
-        return props;
-    }
-
-
     /**
      * Create the user, check there are no errors
      *
      * @return the userid
      */
-    private UUID createRoleUser( UUID orgId, UUID appId, String adminToken, String username, String email )
+    private UUID createRoleUser(String username, String email)
             throws Exception {
 
-        Map<String, String> props = hashMap( "email", email ).map( "username", username ).map( "name", username )
-                .map( "password", "password" );
-
-        JsonNode node = mapper.readTree( resource().path( String.format( "/%s/%s/users", orgId, appId ) )
-                .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, props ));
-
-        assertNull( getError( node ) );
+        User props = new User(username, username, email, "password");
 
-        UUID userId = UUID.fromString( getEntity( node, 0 ).get( "uuid" ).asText() );
+        Entity entity = this.app().collection("users").post(props);
 
-        // manually activate user
-        setup.getMgmtSvc().activateAppUser( appId, userId );
-
-        return userId;
+        return entity.getUuid();
     }
 
 
     /** Test adding the permission to the role */
-    private void addPermission( String orgname, String appname, String adminToken, String rolename, String grant ) throws IOException {
-        Map<String, String> props = hashMap( "permission", grant );
-
-        String rolePath = String.format( "/%s/%s/roles/%s/permissions", orgname, appname, rolename );
-
-        JsonNode node = mapper.readTree( resource().path( rolePath ).queryParam( "access_token", adminToken )
-                .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                .put( String.class, props ));
+    private void addPermission(  String rolename, String grant ) throws IOException {
+        Entity props = new Entity().chainPut("permission", grant);
 
-        assertNull( getError( node ) );
+        this.app().collection("roles").entity(rolename).collection("permissions").post(props);
 
-        node = mapper.readTree( resource().path( rolePath ).queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+        Collection node = this.app().collection("roles").entity(rolename).collection("permissions").get();
 
-        ArrayNode data = ( ArrayNode ) node.get( "data" );
+        List<Object> data =(List) node.getResponse().getData();
 
-        Iterator<JsonNode> iterator = data.elements();
-
-        while ( iterator.hasNext() ) {
-            if ( grant.equals( iterator.next().asText() ) ) {
+        for(Object o : data){
+            if(grant.equals(o.toString())){
                 return;
             }
         }
@@ -739,30 +546,4 @@ public class PermissionsResourceIT extends AbstractRestIT {
     }
 
 
-    /** Test adding the permission to the role */
-    private void addPermission( String orgname, String appname, String rolename, String grant ) throws IOException {
-        Map<String, String> props = hashMap( "permission", grant );
-
-        String rolePath = String.format( "/%s/%s/roles/%s/permissions", orgname, appname, rolename );
-
-        JsonNode node = mapper.readTree( resource().path( rolePath ).accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                        .put( String.class, props ));
-
-        assertNull( getError( node ) );
-
-        node = mapper.readTree( resource().path( rolePath ).accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                .get( String.class ));
-
-        ArrayNode data = ( ArrayNode ) node.get( "data" );
-
-        Iterator<JsonNode> iterator = data.elements();
-
-        while ( iterator.hasNext() ) {
-            if ( grant.equals( iterator.next().asText() ) ) {
-                return;
-            }
-        }
-
-        fail( String.format( "didn't find grant %s in the results", grant ) );
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0310878/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
index b70f90c..5b74215 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
@@ -124,15 +124,15 @@ public class Entity implements Serializable, Map<String,Object> {
     }
 
     public String getError () {
-        return (String) this.get("error").toString();
+        return (String) this.get("error");
     }
 
     public String getErrorCode () {
-        return (String) this.get("errorCode").toString();
+        return (String)this.get("errorCode");
     }
 
     public String getErrorDescription () {
-        return (String) this.get("errorDescription").toString();
+        return (String) this.get("errorDescription");
     }
 
     @Override