usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [08/18] incubator-usergrid git commit: [USERGRID-347] Removed unneeded test. Added Me endpoint along with generic that adds on queryParameters. Added Me Token test.
Date Tue, 24 Mar 2015 22:41:12 GMT
[USERGRID-347] Removed unneeded test.
Added Me endpoint along with generic that adds on queryParameters.
Added Me Token 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/a33ae23c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a33ae23c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a33ae23c

Branch: refs/heads/USERGRID-501
Commit: a33ae23c79c4676fbd1b3c4485c1e9e252d04b74
Parents: b94e21d
Author: GERey <greyes@apigee.com>
Authored: Fri Mar 20 16:56:41 2015 -0700
Committer: GERey <greyes@apigee.com>
Committed: Fri Mar 20 16:56:41 2015 -0700

----------------------------------------------------------------------
 .../usergrid/rest/management/AccessTokenIT.java | 156 +++++++++----------
 .../endpoints/NamedResource.java                |  10 ++
 .../endpoints/mgmt/ManagementResource.java      |   4 +
 .../endpoints/mgmt/MeResource.java              |  32 ++++
 4 files changed, 116 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a33ae23c/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
index af88041..2d7911d 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
@@ -28,12 +28,16 @@ import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
 import org.apache.usergrid.rest.management.organizations.OrganizationsResource;
 import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
 import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.rest.test.resource2point0.model.Organization;
 import org.apache.usergrid.rest.test.resource2point0.model.QueryParameters;
 import org.apache.usergrid.rest.test.resource2point0.model.Token;
 
 import static org.apache.usergrid.utils.MapUtils.hashMap;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+
+import org.jclouds.rest.annotations.Api;
+import org.junit.Ignore;
 import org.junit.Test;
 
 
@@ -51,17 +55,10 @@ public class AccessTokenIT extends AbstractRestIT {
 
         long ttl = 2000;
 
-        QueryParameters queryParameters = new QueryParameters();
-        queryParameters.addParam( "grant_type", "password" );
-        queryParameters.addParam( "username", clientSetup.getUsername() );
-        queryParameters.addParam( "password", clientSetup.getPassword());
-        queryParameters.addParam( "ttl", String.valueOf(ttl) );
-
-        Token adminToken = management().token().
-            get( queryParameters );
+        tokenSetup( ttl );
 
         long startTime = System.currentTimeMillis();
-        Entity user = management().users().user( clientSetup.getUsername() ).get();
+        Entity user = new Entity(management().users().user( clientSetup.getUsername() ).get(ApiResponse.class));
 
 
         assertEquals(clientSetup.getUsername(), user.get( "username" ));
@@ -71,7 +68,7 @@ public class AccessTokenIT extends AbstractRestIT {
 
         ClientResponse.Status responseStatus = null;
         try {
-            management().users().user( clientSetup.getUsername() ).get();
+            management().users().user( clientSetup.getUsername() ).get( ApiResponse.class);
         } catch (UniformInterfaceException uie) {
             responseStatus = uie.getResponse().getClientResponseStatus();
         }
@@ -79,82 +76,69 @@ public class AccessTokenIT extends AbstractRestIT {
         assertEquals(ClientResponse.Status.UNAUTHORIZED, responseStatus);
     }
 
-//    @Test
-//    public void token() throws Exception {
-//        JsonNode node = mapper.readTree(resource()
-//                .path("/management/token")
-//                .queryParam("grant_type", "password")
-//                .queryParam("username", "test@usergrid.com")
-//                .queryParam("password", "test")
-//                .accept(MediaType.APPLICATION_JSON)
-//                .get(String.class));
-//
-//        logNode(node);
-//        String token = node.get("access_token").textValue();
-//        assertNotNull(token);
-//
-//        // set an organization property
-//        HashMap<String, Object> payload = new HashMap<String, Object>();
-//        Map<String, Object> properties = new HashMap<String, Object>();
-//        properties.put("securityLevel", 5);
-//        payload.put(OrganizationsResource.ORGANIZATION_PROPERTIES, properties);
-//        node = mapper.readTree(resource()
-//                .path("/management/organizations/test-organization")
-//                .queryParam("access_token", superAdminToken())
-//                .accept(MediaType.APPLICATION_JSON)
-//                .type(MediaType.APPLICATION_JSON_TYPE)
-//                .put(String.class, payload));
-//
-//        refreshIndex("test-organization", "test-app");
-//
-//        // ensure the organization property is included
-//        node = mapper.readTree(resource().path("/management/token").queryParam("access_token",
token)
-//                .accept(MediaType.APPLICATION_JSON).get(String.class));
-//        logNode(node);
-//
-//        JsonNode securityLevel = node.findValue("securityLevel");
-//        assertNotNull(securityLevel);
-//        assertEquals(5L, securityLevel.asLong());
-//    }
-//
-//    @Test
-//    public void meToken() throws Exception {
-//        JsonNode node = mapper.readTree(resource()
-//                .path("/management/me")
-//                .queryParam("grant_type", "password")
-//                .queryParam("username", "test@usergrid.com")
-//                .queryParam("password", "test")
-//                .accept(MediaType.APPLICATION_JSON)
-//                .get(String.class));
-//
-//        logNode(node);
-//        String token = node.get("access_token").textValue();
-//        assertNotNull(token);
-//
-//        node = mapper.readTree(resource()
-//                .path("/management/me")
-//                .queryParam("access_token", token)
-//                .accept(MediaType.APPLICATION_JSON)
-//                .get(String.class));
-//        logNode(node);
-//
-//        assertNotNull(node.get("passwordChanged"));
-//        assertNotNull(node.get("access_token"));
-//        assertNotNull(node.get("expires_in"));
-//        JsonNode userNode = node.get("user");
-//        assertNotNull(userNode);
-//        assertNotNull(userNode.get("uuid"));
-//        assertNotNull(userNode.get("username"));
-//        assertNotNull(userNode.get("email"));
-//        assertNotNull(userNode.get("name"));
-//        assertNotNull(userNode.get("properties"));
-//        JsonNode orgsNode = userNode.get("organizations");
-//        assertNotNull(orgsNode);
-//        JsonNode orgNode = orgsNode.get("test-organization");
-//        assertNotNull(orgNode);
-//        assertNotNull(orgNode.get("name"));
-//        assertNotNull(orgNode.get("properties"));
-//    }
+
+    private Token tokenSetup( final long ttl ) {
+        QueryParameters queryParameters = getQueryParameters( ttl );
+
+        Token adminToken = management().token().
+            get(Token.class, queryParameters );
+        management().token().setToken( adminToken );
+
+        return adminToken;
+    }
+
+    private Token tokenMeSetup( final long ttl ) {
+        QueryParameters queryParameters = getQueryParameters( ttl );
+
+        Token adminToken = management().me().
+            get(Token.class, queryParameters );
+        management().token().setToken( adminToken );
+
+        return adminToken;
+    }
+
+
+    private QueryParameters getQueryParameters( final long ttl ) {
+        QueryParameters queryParameters = new QueryParameters();
+        queryParameters.addParam( "grant_type", "password" );
+        queryParameters.addParam( "username", clientSetup.getUsername() );
+        queryParameters.addParam( "password", clientSetup.getPassword());
+        if(ttl != 0)
+            queryParameters.addParam( "ttl", String.valueOf(ttl) );
+        return queryParameters;
+    }
+    
+    @Test
+    public void meToken() throws Exception {
+        tokenMeSetup( 0 );
+
+        ApiResponse response = management().me().get(ApiResponse.class);
+
+        assertNotNull( response );
+        assertNotNull(response.getAccessToken());
+
+        Map<String,Object> responseProperties = response.getProperties();
+
+
+        assertNotNull( responseProperties.get( "passwordChanged" ) );
+        assertNotNull(responseProperties.get("expires_in"));
+        Map<String,Object> userProperties = ( Map<String, Object> ) responseProperties.get("user");
+        assertNotNull( userProperties );
+        //user verification
+        assertNotNull(userProperties.get("uuid"));
+        assertNotNull(userProperties.get("username"));
+        assertNotNull(userProperties.get("email"));
+        assertNotNull(userProperties.get("name"));
+        assertNotNull(userProperties.get("properties"));
+
+        Map<String,Object> org = ( Map<String, Object> ) userProperties.get("organizations");
+        Map<String,Object> orgProperties = ( Map<String, Object> )
+            org.get( clientSetup.getOrganizationName().toLowerCase() );
+
+        assertNotNull(orgProperties);
+        assertNotNull(orgProperties.get("name"));
+        assertNotNull(orgProperties.get("properties"));
+    }
 //
 //    @Test
 //    public void meTokenPost() throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a33ae23c/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 fc610bd..a5ffc9f 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
@@ -185,4 +185,14 @@ public abstract class NamedResource implements UrlResource {
 
     }
 
+    public <T> T get(Class<T> type,QueryParameters queryParameters) {
+        WebResource resource = getResource();
+        resource = addParametersToResource(resource, queryParameters);
+        GenericType<T> gt = new GenericType<>((Class) type);
+        return resource.type(MediaType.APPLICATION_JSON_TYPE)
+                                  .accept( MediaType.APPLICATION_JSON )
+                                  .get( gt.getRawClass() );
+
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a33ae23c/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 3bad451..45d9b7f 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
@@ -33,6 +33,10 @@ public class ManagementResource extends NamedResource {
         return new TokenResource( context, this );
     }
 
+    public MeResource me(){
+        return new MeResource( context, this );
+    }
+
     public AuthorizeResource authorize(){
         return new AuthorizeResource( context, this );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a33ae23c/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/MeResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/MeResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/MeResource.java
new file mode 100644
index 0000000..1c7bf1b
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/MeResource.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt;
+
+
+import org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+
+
+/**
+ * Calls the management/me endpoints
+ */
+public class MeResource extends NamedResource {
+    public MeResource( final ClientContext context, final UrlResource parent ) {
+        super( "me", context, parent );
+    }
+}


Mime
View raw message