You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2014/12/28 21:36:37 UTC

[2/8] incubator-usergrid git commit: added data to response, flushed out groupsrolespermissionsusers test

added data to response, flushed out groupsrolespermissionsusers test


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

Branch: refs/heads/USERGRID-291-User-Tests
Commit: 118aa73e2c42d35e458a3d4cd529077442229349
Parents: 9005e30
Author: Rod Simpson <ro...@apigee.com>
Authored: Sat Dec 20 15:39:35 2014 -0700
Committer: Rod Simpson <ro...@apigee.com>
Committed: Sat Dec 20 15:39:35 2014 -0700

----------------------------------------------------------------------
 .../collection/groups/GroupResourceIT.java      | 128 ++++++++-----------
 .../rest/test/resource2point0/model/Entity.java |   8 +-
 2 files changed, 60 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/118aa73e/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
index f536269..ac1e1d6 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
@@ -64,10 +64,11 @@ public class GroupResourceIT extends AbstractRestIT {
         return entity;
     }
 
-    private Entity createUser(String username, String email) throws IOException{
+    private Entity createUser(String username, String email, String password) throws IOException{
         Entity payload = new Entity();
         payload.put("username", username);
         payload.put("email", email);
+        payload.put("password", password);
         Entity entity = this.app().collection("users").post(payload);
         assertEquals(entity.get("username"), username);
         assertEquals(entity.get("email"), email);
@@ -191,7 +192,8 @@ public class GroupResourceIT extends AbstractRestIT {
         // 2. create a user
         String username = "fred";
         String email = "fred@usergrid.com";
-        Entity user = this.createUser(username, email);
+        String password = "password";
+        Entity user = this.createUser(username, email, password);
 
         // 3. add the user to the group
         Entity response = this.app().collection("users").entity(user).connection().collection("groups").entity(group).post();
@@ -300,6 +302,7 @@ public class GroupResourceIT extends AbstractRestIT {
      *  add user to group
      *  delete default role (to ensure no app-level user operations are allowed)
      *  delete guest role (to ensure no app-level user operations are allowed)
+     *  log the user in with
      *  create a /cats/fluffy
      *  read /cats/fluffy
      *  update /cats/fluffy (should fail)
@@ -316,7 +319,8 @@ public class GroupResourceIT extends AbstractRestIT {
         //2. create a user
         String username = "fred";
         String email = "fred@usergrid.com";
-        Entity user = this.createUser(username, email);
+        String password = "password";
+        Entity user = this.createUser(username, email, password);
 
         //3. create a role
         String roleName = "tester";
@@ -324,95 +328,69 @@ public class GroupResourceIT extends AbstractRestIT {
         Entity role = this.createRole(roleName, roleTitle);
 
         //4. add permissions to role
-
+        Entity payload = new Entity();
+        payload.put("permission","get,post:/cats");
+        Entity permission = this.app().collection("roles").uniqueID(roleName).connection("permissions").post(payload);
+        assertEquals(permission.get("data"), "get,post:/cats");
+        this.refreshIndex();
 
         //5. add role to the group
-        Entity addRoleresponse = this.app().collection("role").entity(role).connection().collection("groups").entity(group).post();
-        assertEquals(addRoleresponse.get("name"), roleName);
+        Entity addRoleResponse = this.app().collection("groups").entity(group).connection().collection("roles").entity(role).post();
+        assertEquals(addRoleResponse.get("name"), roleName);
         this.refreshIndex();
 
         //6. add user to group
         Entity addUserResponse = this.app().collection("users").entity(user).connection().collection("groups").entity(group).post();
         assertEquals(addUserResponse.get("name"), groupName);
         this.refreshIndex();
-    }
-
-    /***
-     *
-     * Verify that we can create a group and then add a role to it
-     */
-    @Test()
-    public void createGroupAndAddARoleValidation() throws IOException {
-
-        /*
-        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 ).get( String.class ));
-        assertNull( node.get( "errors" ) );
-        assertTrue( node.get( "entities" ).findValuesAsText( "name" ).contains( roleName ) );
-
-        */
-    }
-
-    /*
-
-    @Test
-    public void addRemovePermission() throws IOException {
-
-        GroupsCollection groups = context.groups();
-
-
-
-        UUID id = UUIDUtils.newTimeUUID();
 
-        String groupName = "groupname" + id;
-
-        ApiResponse response = client.createGroup( groupName );
-        assertNull( "Error was: " + response.getErrorDescription(), response.getError() );
-
-        refreshIndex("test-organization", "test-app");
-
-        UUID createdId = response.getEntities().get( 0 ).getUuid();
-
-        // add Permission
-        String orgName = context.getOrgName();
-        String appName = context.getAppName();
-        String path = "/"+orgName+"/"+appName+"/groups/";
-
-        String json = "{\"permission\":\"delete:/test\"}";
-        JsonNode node = mapper.readTree( resource().path( path + createdId + "/permissions" )
-                .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, json ));
-
-        // check it
-        assertNull( node.get( "errors" ) );
-        assertEquals( node.get( "data" ).get( 0 ).asText(), "delete:/test" );
+        //7. delete the default role
+        ApiResponse responseDelDefault = this.app().collection("role").uniqueID("Default").delete();
+        this.refreshIndex();
+        //todo: what to do with response from delete call?
 
-        refreshIndex("test-organization", "test-app");
+        //8. delete the guest role
+        ApiResponse responseDelGuest = this.app().collection("role").uniqueID("Guest").delete();
+        this.refreshIndex();
+        //todo: what to do with response from delete call?
 
-        node = mapper.readTree( resource().path( "/test-organization/test-app/groups/" + createdId + "/permissions" )
-                .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-        assertNull( node.get( "errors" ) );
-        assertEquals( node.get( "data" ).get( 0 ).asText(), "delete:/test" );
+        //log user in, should then be using the app user's token not the admin token
+        //todo: need to log user in here - how?
 
 
-        // remove Permission
+        //create a cat - permissions should allow this
+        String catName = "fluffy";
+        payload = new Entity();
+        payload.put("name", catName);
+        Entity fluffy = this.app().collection("cats").post(payload);
+        assertEquals(fluffy.get("name"), catName);
+        this.refreshIndex();
 
-        node = mapper.readTree( resource().path( "/test-organization/test-app/groups/" + createdId + "/permissions" )
-                .queryParam( "access_token", access_token ).queryParam( "permission", "delete%3A%2Ftest" )
-                .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class ));
+        //get the cat - permissions should allow this
+        fluffy = this.app().collection("cats").uniqueID(catName).get();
+        assertEquals(fluffy.get("name"), catName);
 
-        // check it
-        assertNull( node.get( "errors" ) );
-        assertTrue( node.get( "data" ).size() == 0 );
+        //edit the cat - permissions should not allow this
+        fluffy.put("color", "brown");
+        try {
+            this.app().collection("cats").uniqueID(catName).put(fluffy);
+            fail("permissions should not allow this");
+        } catch (UniformInterfaceException e) {
+            //verify the correct error was returned
+            JsonNode node = mapper.readTree( e.getResponse().getEntity( String.class ));
+            assertEquals( "improper credentials or something", node.get( "error" ).textValue() );
+        }
 
-        refreshIndex("test-organization", "test-app");
+        //delete the cat - permissions should not allow this
+        try {
+            this.app().collection("cats").uniqueID(catName).delete();
+            fail("permissions should not allow this");
+        } catch (UniformInterfaceException e) {
+            //verify the correct error was returned
+            JsonNode node = mapper.readTree( e.getResponse().getEntity( String.class ));
+            assertEquals( "improper credentials or something", node.get( "error" ).textValue() );
+        }
 
-        node = mapper.readTree( resource().path( "/test-organization/test-app/groups/" + createdId + "/permissions" )
-                .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-        assertNull( node.get( "errors" ) );
-        assertTrue( node.get( "data" ).size() == 0 );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/118aa73e/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 c4ac5ca..73cdda5 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
@@ -55,11 +55,17 @@ public class Entity implements Serializable, Map<String,Object> {
     public Entity(ApiResponse response){
         this.response = response;
 
-        if(response.getEntities() !=null &&  response.getEntities().size()>=1){
+        if(response.getEntities() != null &&  response.getEntities().size()>=1){
             List<Entity>  entities =  response.getEntities();
             Map<String,Object> entity = entities.get(0);
             this.putAll(entity);
         }
+        else if (response.getData() != null){
+            ArrayList<String> data = (ArrayList <String>) response.getData();
+            Entity entity = new Entity();
+            entity.put("data", data.get(0));
+            this.putAll(entity);
+        }
     }
 
     //For the owner , should have different cases that looks at the different types it could be