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

[08/17] incubator-usergrid git commit: Cleanup of imports and spaces. Fixed OrganizationsIT and added comments. Added users to the end of ManagementResource to emulate AdminUser calls. Added put to organizationResource so we can update organizations. Add

Cleanup of imports and spaces.
Fixed OrganizationsIT and added comments.
Added users to the end of ManagementResource to emulate AdminUser calls.
Added put to organizationResource so we can update organizations.
Added Additional case to entities that puts any data from a entity into the entity itself.
Added ability to get Organization properties without needing to go through dynamic properties.
Removed cruft from ClientContext.


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

Branch: refs/heads/two-dot-o
Commit: 860de10b31f1135ca0622a70713ad01cdee6075b
Parents: f6c1a0e
Author: grey <gr...@apigee.com>
Authored: Tue Jan 6 15:02:37 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Tue Jan 6 15:02:37 2015 -0800

----------------------------------------------------------------------
 .../collection/groups/GroupResourceIT.java      |   1 -
 .../rest/management/OrganizationsIT.java        | 137 ++++++++-----------
 .../rest/test/resource2point0/RestClient.java   |   1 -
 .../endpoints/mgmt/ManagementResource.java      |   4 +
 .../endpoints/mgmt/OrganizationResource.java    |   8 ++
 .../rest/test/resource2point0/model/Entity.java |  23 +++-
 .../resource2point0/model/Organization.java     |   3 +
 .../resource2point0/state/ClientContext.java    |  21 ---
 8 files changed, 91 insertions(+), 107 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/860de10b/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 e7acf4b..8f3fbcc 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
@@ -347,7 +347,6 @@ public class GroupResourceIT extends AbstractRestIT {
 
         //8. log user in, should then be using the app user's token not the admin token
         this.getAppUserToken(username, password);
-
         //9. create a cat - permissions should allow this
         String catName = "fluffy";
         payload = new Entity();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/860de10b/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
index aae2735..0a7a82b 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
@@ -163,6 +163,7 @@ public class OrganizationsIT extends AbstractRestIT {
     @Test
     public void testCreateDuplicateOrgEmail() throws Exception {
 
+        //Setup the org/owner combo
         String username = "testCreateDuplicateOrgEmail" + UUIDUtils.newTimeUUID();
         String name = username;
         String password = "password";
@@ -171,14 +172,17 @@ public class OrganizationsIT extends AbstractRestIT {
 
         Organization orgPayload = new Organization( orgName, username, email, name, password, null );
 
+        //create the org/owner
         Organization orgCreatedResponse = clientSetup.getRestClient().management().orgs().post( orgPayload );
 
         this.refreshIndex();
 
         assertNotNull( orgCreatedResponse );
 
+        //recreate a new payload using a duplicate email
         orgPayload = new Organization( orgName+"test", username+"test", email, name+"test", password+"test", null );
 
+        //verify that we cannot create an organization that shares a email with another preexisting organization.
         try {
             clientSetup.getRestClient().management().orgs().post( orgPayload );
             fail( "Should not have created organization" );
@@ -187,6 +191,7 @@ public class OrganizationsIT extends AbstractRestIT {
             errorParse( 400,duplicateUniquePropertyExistsErrorMessage,ex);
         }
 
+        //try to get the token from the organization that failed to be created to verify it was not made.
         Token tokenPayload = new Token( "password", username + "test", password );
         Token tokenError = null;
         try {
@@ -200,6 +205,7 @@ public class OrganizationsIT extends AbstractRestIT {
 
         assertNull( tokenError );
 
+        //get token from organization that was created to verify it exists.
         tokenPayload = new Token( "password", username, password );
         Token tokenReturned = clientSetup.getRestClient().management().token().post( tokenPayload );
 
@@ -244,6 +250,7 @@ public class OrganizationsIT extends AbstractRestIT {
     @Test
     public void testOrgPOSTForm() throws IOException {
 
+        //create the form to hold the organization
         UUID timeUuid = UUIDUtils.newTimeUUID();
         Form form = new Form();
         form.add( "organization", "testOrgPOSTForm" + timeUuid );
@@ -285,105 +292,75 @@ public class OrganizationsIT extends AbstractRestIT {
      */
     @Test
     public void testCreateOrgUserAndReturnCorrectUsername() throws Exception {
-
-
         String username = "testCreateOrgUserAndReturnCorrectUsername"+UUIDUtils.newTimeUUID();
 
         RestClient restClient = clientSetup.getRestClient();
 
+        //Create adminUser values
         Entity adminUserPayload = new Entity();
         adminUserPayload.put( "username", username );
         adminUserPayload.put( "name", username );
         adminUserPayload.put( "email", username+"@usergrid.com" );
         adminUserPayload.put( "password", username );
 
+        //create adminUser
         Entity adminUserResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() )
                                            .users().post( adminUserPayload );
 
+        //verify that the response contains the correct data
         assertNotNull( adminUserResponse );
         assertEquals( username, adminUserResponse.get( "username" ) );
 
-        adminUserResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() )
-                                                .users().entity( username ).get();
+        //fetch the stored response
+        adminUserResponse = restClient.management().users().entity( username ).get(this.getAdminToken(username,username));
 
+        //verify that values match stored response
         assertNotNull( adminUserResponse );
         assertEquals( username , adminUserResponse.get( "username" ) );
         assertEquals( username, adminUserResponse.get( "name" ) );
-        assertEquals( username, adminUserResponse.get( "email" ));
-
-//        Map<String, String> payload = hashMap( "username", "test-user-2" ).map( "name", "Test User 2" )
-//                                                                          .map( "email", "test-user-2@mockserver.com" )
-//                                                                          .map( "password", "password" );
-//
-//        JsonNode node = mapper.readTree(
-//                resource().path( "/management/organizations/" + context.getOrgName() + "/users" )
-//                          .queryParam( "access_token", mgmtToken ).accept( MediaType.APPLICATION_JSON )
-//                          .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) );
-//
-//        clientSetup.getRestClient().management().orgs()
-//
-//        logNode( node );
-//        assertNotNull( node );
-//
-//        String username = node.get( "data" ).get( "user" ).get( "username" ).asText();
-//        String name = node.get( "data" ).get( "user" ).get( "name" ).asText();
-//        String email = node.get( "data" ).get( "user" ).get( "email" ).asText();
-//
-//        assertNotNull( username );
-//        assertNotNull( name );
-//        assertNotNull( email );
-//
-//        assertEquals( "test-user-2", username );
-//        assertEquals( "Test User 2", name );
-//        assertEquals( "test-user-2@mockserver.com", email );
+        assertEquals( username+"@usergrid.com", adminUserResponse.get( "email" ));
+
+    }
+
+
+    /**
+     * Inserts a value into the default organization then update that value and see if the value persists.
+     * @throws Exception
+     */
+    @Test
+    public void testOrganizationUpdate() throws Exception {
+
+        RestClient restClient = clientSetup.getRestClient();
+
+        //Setup what will be interested into the organization
+        Map<String, Object> properties = new HashMap<String, Object>();
+        properties.put( "securityLevel", 5 );
+
+        Organization orgPayload = clientSetup.getOrganization();
+        orgPayload.put( "properties", properties );
+
+        //update the organization.
+        restClient.management().orgs().organization( clientSetup.getOrganizationName() ).put(orgPayload);
+
+        this.refreshIndex();
+
+        //retrieve the organization
+        Organization orgResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() ).get();
+
+        assertEquals( 5, orgResponse.getProperties().get( "securityLevel" ));
+
+        //update the value added to the organization
+        properties.put( "securityLevel", 6 );
+        orgPayload.put( "properties", properties );
+
+        //update the organization.
+        restClient.management().orgs().organization( clientSetup.getOrganizationName() ).put(orgPayload);
+
+        this.refreshIndex();
+
+        orgResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() ).get();
+
+        assertEquals( 6, orgResponse.getProperties().get( "securityLevel" ));
+
     }
-//
-//
-//    @Test
-//    public void testOrganizationUpdate() throws Exception {
-//        String accessToken = context.getActiveUser().getToken();
-//        Map<String, Object> properties = new HashMap<String, Object>();
-//        properties.put( "securityLevel", 5 );
-//        Map payload = new HashMap();
-//        payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties );
-//
-//
-//        //update the organizations
-//        mapper.readTree( resource().path( "/management/organizations/" + context.getOrgName() )
-//                                   .queryParam( "access_token", accessToken ).accept( MediaType.APPLICATION_JSON )
-//                                   .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, payload ) );
-//
-//
-//        refreshIndex( context.getOrgName(), context.getAppName() );
-//
-//        //get the organization
-//        JsonNode node = mapper.readTree( resource().path( "/management/organizations/" + context.getOrgName() )
-//                                                   .queryParam( "access_token", accessToken )
-//                                                   .accept( MediaType.APPLICATION_JSON )
-//                                                   .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) );
-//
-//        assertEquals( 5L, node.get( "organization" ).get( "properties" ).get( "securityLevel" )
-//                              .asLong() );//orgInfo.getProperties().get( "securityLevel" ) );
-//
-//        payload = new HashMap();
-//        properties.put( "securityLevel", 6 );
-//        payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties );
-//
-//        node = mapper.readTree( resource().path( "/management/organizations/" + context.getOrgName() )
-//                                          .queryParam( "access_token", accessToken )
-//                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-//                                          .put( String.class, payload ) );
-//        logNode( node );
-//
-//        refreshIndex( context.getOrgName(), context.getAppName() );
-//
-//        node = mapper.readTree( resource().path( "/management/organizations/" + context.getOrgName() )
-//                                          .queryParam( "access_token", accessToken )
-//                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-//                                          .get( String.class ) );
-//        logNode( node );
-//        Assert.assertEquals( 6,
-//                node.get( "organization" ).get( OrganizationsResource.ORGANIZATION_PROPERTIES ).get( "securityLevel" )
-//                    .asInt() );
-//    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/860de10b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
index 52e4262..ebd1e35 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
@@ -20,7 +20,6 @@ import org.apache.usergrid.rest.test.resource2point0.endpoints.TokenResource;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResource;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.OrganizationResource;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
-import org.apache.usergrid.rest.test.resource2point0.model.Organization;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 
 import com.sun.jersey.api.client.Client;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/860de10b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResource.java
index 78631bb..0443695 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResource.java
@@ -37,4 +37,8 @@ public class ManagementResource extends NamedResource {
     public OrgResource orgs() {
         return new OrgResource( context, this );
     }
+
+    public UsersResource users() {
+        return new UsersResource( context, this );
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/860de10b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
index 95797f5..85451bd 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
@@ -67,6 +67,14 @@ public class OrganizationResource extends NamedResource {
         return org;
     }
 
+    //Doesn't return anything useful.
+    public void put( Organization organization ){
+        Map<String,Object> response = getResource(true).type(MediaType.APPLICATION_JSON_TYPE)
+                                                       .accept(MediaType.APPLICATION_JSON).put( Organization.class,
+                        organization );
+
+    }
+
     public ApplicationResource app(){
         return new ApplicationResource(  context ,this );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/860de10b/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 3a4b2b0..346a4b0 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
@@ -61,10 +61,21 @@ public class Entity implements Serializable, Map<String,Object> {
             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);
+            LinkedHashMap dataResponse = ( LinkedHashMap ) response.getData();
+
+            //covers case for admin users
+            if(dataResponse.get( "user" )!=null){
+                //Entity entity = new Entity();
+                //entity.put( "data", dataResponse.get( "user" ) );
+                this.putAll( ( Map<? extends String, ?> ) dataResponse.get( "user" ) );
+            }
+            else {
+                //Doesn't always type correct below.
+                //ArrayList<String> data = ( ArrayList<String> ) response.getData();
+                //Entity entity = new Entity();
+               // entity.put( "data", data.get( 0 ) );
+                this.putAll( dataResponse );
+            }
         }
     }
 
@@ -180,4 +191,8 @@ public class Entity implements Serializable, Map<String,Object> {
         put(key,value);
         return this;
     }
+
+    public ApiResponse getResponse(){
+        return response;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/860de10b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Organization.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Organization.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Organization.java
index 4e28844..5487bda 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Organization.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Organization.java
@@ -94,6 +94,9 @@ public class Organization extends Entity {
         this.user = new User( response, nameOverride);
     }
 
+    public Map<String,Object> getProperties(){
+        return (Map) this.get( "properties" );
+    }
 
     /**
      * Created specifically so that we could set the organization owner to the Organization model from a get Organization

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/860de10b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/state/ClientContext.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/state/ClientContext.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/state/ClientContext.java
index 6ebbeca..3a0e280 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/state/ClientContext.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/state/ClientContext.java
@@ -26,10 +26,6 @@ import org.apache.usergrid.rest.test.resource2point0.model.Token;
  */
 public class ClientContext {
     private Token token;
-//    private Organization organization;
-//    private User user;
-
-
 
     public Token getToken() {
         return token;
@@ -40,21 +36,4 @@ public class ClientContext {
         this.token = token;
     }
 
-//    public Organization getOrganization() {
-//        return organization;
-//    }
-//
-//
-//    public void setOrganization( final Organization organization ) {
-//        this.organization = organization;
-//    }
-//
-//    public User getUser() {
-//        return user;
-//    }
-//
-//
-//    public void setUser( final User user ) {
-//        this.user = user;
-//    }
 }