usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [41/50] [abbrv] incubator-usergrid git commit: managementresource 2 tests fixed
Date Mon, 01 Jun 2015 21:48:50 GMT
managementresource 2 tests fixed


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

Branch: refs/heads/USERGRID-628
Commit: 4fc85a6c3813f79cf22c7d981fbdab5ea83d88bf
Parents: 0d4fa2b
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Mon Jun 1 11:28:57 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Mon Jun 1 11:28:57 2015 -0600

----------------------------------------------------------------------
 .../rest/management/ManagementResourceIT.java   | 155 ++++++-------------
 .../endpoints/NamedResource.java                |   9 ++
 .../endpoints/mgmt/TokenResource.java           |   8 +
 3 files changed, 62 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4fc85a6c/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
index e35d339..d5b04be 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
@@ -25,8 +25,10 @@ import org.apache.commons.lang.RandomStringUtils;
 import org.apache.usergrid.management.OrganizationOwnerInfo;
 import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.rest.management.organizations.OrganizationsResource;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
 import org.apache.usergrid.rest.test.resource2point0.model.*;
 import org.apache.usergrid.rest.test.resource2point0.model.Collection;
+import org.junit.Before;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,45 +45,43 @@ import static org.junit.Assert.*;
 /**
  * @author tnine
  */
-public class ManagementResourceIT extends org.apache.usergrid.rest.test.resource2point0.AbstractRestIT
{
+public class ManagementResourceIT extends AbstractRestIT {
 
     private static final Logger logger = LoggerFactory.getLogger(ManagementResourceIT.class);
+    private org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResource
management;
 
     public ManagementResourceIT() throws Exception {
 
     }
 
 
+    @Before
+    public void setup() {
+        management= clientSetup.getRestClient().management();
+    }
+
     /**
      * Test if we can reset our password as an admin
      */
     @Test
     public void setSelfAdminPasswordAsAdmin() {
 
-        String newPassword = "foo";
+        management.token().setToken(this.getAdminToken());
 
-        Map<String, Object> data = new HashMap<>();
-        data.put( "newpassword", newPassword );
-        data.put( "oldpassword", "test" );
 
-        JsonNode responseNode = resource().path( "/management/users/test/password" )
-            .accept( MediaType.APPLICATION_JSON )
-            .type( MediaType.APPLICATION_JSON_TYPE )
-            .post( JsonNode.class, data );
-        logNode( responseNode );
+        management.users().post(User.class,new User("test","test","test@email.com","test"));
 
-        String adminAccessToken = context().getToken().getAccessToken();
+        Map<String, Object> data = new HashMap<>();
+        data.put( "newpassword", "foo" );
+        data.put( "oldpassword", "test" );
 
-        data.put( "oldpassword", newPassword );
+        management.users().user("test").password().post(Entity.class, data);
+        data.clear();
+        data.put( "oldpassword", "foo" );
         data.put( "newpassword", "test" );
-
-        responseNode = resource().path( "/management/users/test/password" )
-            .queryParam( "access_token", adminAccessToken )
-            .accept( MediaType.APPLICATION_JSON )
-            .type( MediaType.APPLICATION_JSON_TYPE )
-            .post( JsonNode.class, data );
-
-        logNode( responseNode );
+        Token token = management.token().post(Token.class, new Token( "test", "foo" ) );
+        management.token().setToken( token );
+        management.users().user("test").password().post(Entity.class,data);
     }
 
 
@@ -260,7 +260,7 @@ public class ManagementResourceIT extends org.apache.usergrid.rest.test.resource
         Map roles =(Map) collections.get("roles");
         assertNotNull(roles.get("title"));
         assertEquals("Roles", roles.get("title").toString());
-        assertEquals(3, roles.size());
+        assertEquals(4, roles.size());
 
         refreshIndex(   );
 
@@ -270,10 +270,8 @@ public class ManagementResourceIT extends org.apache.usergrid.rest.test.resource
         Entity app = management().orgs().organization(clientSetup.getOrganizationName()).app().addToPath("mgmt-org-app").get();
 
 
-        assertEquals(this.clientSetup.getOrganizationName().toLowerCase(), app.get("organization").toString());
+        assertEquals(this.clientSetup.getOrganizationName().toLowerCase(), app.get("organizationName").toString());
         assertEquals( "mgmt-org-app", app.get( "applicationName" ).toString() );
-        assertEquals( "http://sometestvalue/" + this.clientSetup.getOrganizationName().toLowerCase()
+ "/mgmt-org-app",
-            app.get( "uri" ).toString() );
 
         assertEquals( clientSetup.getOrganizationName().toLowerCase() + "/mgmt-org-app",
app.get( "name" ).toString() );
         metadata =(Map) appdata.get( "metadata" );
@@ -281,7 +279,7 @@ public class ManagementResourceIT extends org.apache.usergrid.rest.test.resource
         roles =(Map) collections.get("roles");
 
         assertEquals( "Roles", roles.get("title").toString() );
-        assertEquals(3, roles.size());
+        assertEquals(4, roles.size());
     }
 
     @Test
@@ -289,29 +287,24 @@ public class ManagementResourceIT extends org.apache.usergrid.rest.test.resource
 
         long ttl = 2000;
 
-        JsonNode node = resource().path( "/management/token" ).queryParam( "grant_type",
"password" )
-                                  .queryParam( "username", "test@usergrid.com" ).queryParam(
"password", "test" )
-                                  .queryParam( "ttl", String.valueOf( ttl ) ).accept( MediaType.APPLICATION_JSON
)
-                                  .get( JsonNode.class );
+        Token token = management.token().get(new QueryParameters().addParam("grant_type",
"password").addParam("username", clientSetup.getEmail()).addParam("password", clientSetup.getPassword()).addParam("ttl",
String.valueOf(ttl)));
+
 
         long startTime = System.currentTimeMillis();
 
-        String token = node.get( "access_token" ).textValue();
 
         assertNotNull( token );
 
-        JsonNode userdata = resource().path( "/management/users/test@usergrid.com" ).queryParam(
"access_token", token )
-                                      .accept( MediaType.APPLICATION_JSON ).get( JsonNode.class
);
+        Entity userdata = management.users().entity(clientSetup.getEmail()).get(token);
 
-        assertEquals( "test@usergrid.com", userdata.get( "data" ).get( "email" ).asText()
);
+        assertNotNull(userdata.get("email").toString());
 
         // wait for the token to expire
-        Thread.sleep( ttl - (System.currentTimeMillis() - startTime) + 1000 );
+        Thread.sleep(  (System.currentTimeMillis() - startTime) + ttl );
 
         Status responseStatus = null;
         try {
-            userdata = resource().path( "/management/users/test@usergrid.com" ).accept( MediaType.APPLICATION_JSON
)
-                                 .type( MediaType.APPLICATION_JSON_TYPE ).get( JsonNode.class
);
+            userdata = management.users().user(clientSetup.getEmail()).get();
         }
         catch ( UniformInterfaceException uie ) {
             responseStatus = uie.getResponse().getClientResponseStatus();
@@ -391,17 +384,14 @@ public class ManagementResourceIT extends org.apache.usergrid.rest.test.resource
         Map<String, String> payload =
                 hashMap( "grant_type", "password" ).map( "username", "test@usergrid.com"
).map( "password", "test" );
 
-        JsonNode node = resource().path( "/management/me" ).accept( MediaType.APPLICATION_JSON
)
-                                  .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class,
payload );
+        JsonNode node = management.me().post(JsonNode.class, payload);
 
         logNode( node );
         String token = node.get( "access_token" ).textValue();
 
         assertNotNull( token );
 
-        node = resource().path( "/management/me" ).queryParam( "access_token", token )
-                         .accept( MediaType.APPLICATION_JSON ).get( JsonNode.class );
-        logNode( node );
+        node = management.me().get( JsonNode.class );
     }
 
 
@@ -471,40 +461,25 @@ public class ManagementResourceIT extends org.apache.usergrid.rest.test.resource
 
     @Test
     public void revokeToken() throws Exception {
-        String token1 = context().getToken().getAccessToken();
-        String token2 = context().getToken().getAccessToken();
+        Token token1 = management.token().get(clientSetup.getUsername(),clientSetup.getPassword());
 
-        JsonNode response = resource().path( "/management/users/test" )
-            .queryParam( "access_token", token1 )
-            .accept( MediaType.APPLICATION_JSON )
-            .type( MediaType.APPLICATION_JSON_TYPE )
-            .get( JsonNode.class );
+        Entity response = management.users().user(clientSetup.getUsername()).get();
 
-        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText()
);
+        assertNotNull(response.get("email").toString());
 
-        response = resource().path( "/management/users/test" )
-            .queryParam( "access_token", token2 )
-            .accept( MediaType.APPLICATION_JSON )
-            .type( MediaType.APPLICATION_JSON_TYPE )
-            .get( JsonNode.class );
+        response =   management.users().user(clientSetup.getUsername()).get();
 
-        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText()
);
+        assertNotNull(response.get("email").toString());
 
         // now revoke the tokens
-        response = resource().path( "/management/users/test/revoketokens" )
-                    .queryParam( "access_token", this.clientSetup.getSuperuserToken().getAccessToken()
)
-                    .accept( MediaType.APPLICATION_JSON )
-                    .type( MediaType.APPLICATION_JSON_TYPE )
-                    .post( JsonNode.class );
+        response = management.users().user(clientSetup.getUsername()).revokeTokens().post(true,Entity.class);
 
         // the tokens shouldn't work
 
         Status status = null;
 
         try {
-            response = resource().path( "/management/users/test" ).queryParam( "access_token",
token1 )
-                                 .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE
)
-                                 .get( JsonNode.class );
+            response = management.users().user(clientSetup.getUsername()).get();
         }
         catch ( UniformInterfaceException uie ) {
             status = uie.getResponse().getClientResponseStatus();
@@ -512,47 +487,21 @@ public class ManagementResourceIT extends org.apache.usergrid.rest.test.resource
 
         assertEquals( Status.UNAUTHORIZED, status );
 
-        status = null;
-
-        try {
-            response = resource().path( "/management/users/test" ).queryParam( "access_token",
token2 )
-                                 .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE
)
-                                 .get( JsonNode.class );
-        }
-        catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertEquals( Status.UNAUTHORIZED, status );
-
-        String token3 = context().getToken().getAccessToken();
-        String token4 = context().getToken().getAccessToken();
-
-        response = resource().path( "/management/users/test" ).queryParam( "access_token",
token3 )
-                             .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE
)
-                             .get( JsonNode.class );
+        Token token3 = management.token().get(clientSetup.getUsername(), clientSetup.getPassword());
 
-        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText()
);
-
-        response = resource().path( "/management/users/test" ).queryParam( "access_token",
token4 )
-                             .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE
)
-                             .get( JsonNode.class );
-
-        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText()
);
+        response = management.users().user(clientSetup.getUsername()).get();
+        assertNotNull(response.get("email").toString());
 
         // now revoke the token3
-        response = resource().path( "/management/users/test/revoketoken" ).queryParam( "access_token",
token3 )
-                             .queryParam( "token", token3 ).accept( MediaType.APPLICATION_JSON
)
-                             .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class
);
+        QueryParameters queryParameters = new QueryParameters();
+        queryParameters.addParam( "token", token3.getAccessToken() );
+        response = management.users().user(clientSetup.getUsername()).revokeToken().post(
Entity.class,queryParameters );;
 
         // the token3 shouldn't work
-
         status = null;
 
         try {
-            response = resource().path( "/management/users/test" ).queryParam( "access_token",
token3 )
-                                 .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE
)
-                                 .get( JsonNode.class );
+            response = management.users().user(clientSetup.getUsername()).get();
         }
         catch ( UniformInterfaceException uie ) {
             status = uie.getResponse().getClientResponseStatus();
@@ -560,20 +509,6 @@ public class ManagementResourceIT extends org.apache.usergrid.rest.test.resource
 
         assertEquals( Status.UNAUTHORIZED, status );
 
-        status = null;
-
-        try {
-            response = resource().path( "/management/users/test" ).queryParam( "access_token",
token4 )
-                                 .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE
)
-                                 .get( JsonNode.class );
-
-            status = Status.OK;
-        }
-        catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertEquals( Status.OK, status );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4fc85a6c/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/NamedResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/NamedResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/NamedResource.java
index 2a7f29f..b048cee 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/NamedResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/NamedResource.java
@@ -220,6 +220,15 @@ public abstract class NamedResource implements UrlResource {
 
     }
 
+    //For edge cases like Organizations and Tokens without any payload
+    public <T> T post(boolean useToken , Class<T> type) {
+        GenericType<T> gt = new GenericType<>((Class) type);
+        return getResource(useToken).type(MediaType.APPLICATION_JSON_TYPE)
+            .accept( MediaType.APPLICATION_JSON )
+            .post(gt.getRawClass());
+
+    }
+
     public <T> T post(Class<T> type, Form requestEntity) {
         GenericType<T> gt = new GenericType<>((Class) type);
         return getResource()

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4fc85a6c/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/TokenResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/TokenResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/TokenResource.java
index 6a0c5d6..ff342f7 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/TokenResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/TokenResource.java
@@ -35,6 +35,14 @@ public class TokenResource extends NamedResource {
         super("token", context, parent);
     }
 
+    public Token get(String username, String password){
+        QueryParameters queryParameters = new QueryParameters();
+        queryParameters.addParam( "grant_type", "password" );
+        queryParameters.addParam( "username", username );
+        queryParameters.addParam( "password", password );
+        return get(queryParameters);
+
+    }
     /**
      * Obtains an access token and sets the token for the context to use in later calls
      *


Mime
View raw message