usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject incubator-usergrid git commit: added org test; first test passing
Date Mon, 15 Dec 2014 21:40:23 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/UG-rest-test-framework-overhaul 5bd921650 -> d3b6fcc22


added org test; first test passing


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

Branch: refs/heads/UG-rest-test-framework-overhaul
Commit: d3b6fcc2225c89a44846a3d9610f89bff9e06677
Parents: 5bd9216
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Mon Dec 15 14:40:04 2014 -0700
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Mon Dec 15 14:40:04 2014 -0700

----------------------------------------------------------------------
 .../rest/management/OrganizationsIT.java        | 35 ++------------------
 .../rest/test/resource2point0/RestClient.java   |  1 +
 .../endpoints/NamedResource.java                |  6 ++++
 .../endpoints/OrganizationResource.java         |  6 +++-
 .../endpoints/mgmt/OrgResource.java             |  7 ++--
 .../endpoints/mgmt/OrganizationResource.java    | 21 ++++--------
 .../endpoints/mgmt/TokenResource.java           | 14 +++-----
 .../resource2point0/model/Organization.java     |  5 +++
 .../rest/test/resource2point0/model/Token.java  | 10 ++++--
 .../resource2point0/state/ClientContext.java    |  7 ++--
 10 files changed, 44 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b6fcc2/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 f288958..cff42d0 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
@@ -100,40 +100,11 @@ public class OrganizationsIT extends AbstractRestIT {
 
         assertNotNull( tokenBack );
 
+        assertNotNull( clientSetup.getRestClient().getContext().getToken() );
 
+        Organization org = clientSetup.getRestClient().management().orgs().organization(orgName).get();
 
-//        Map payload =
-//                hashMap( "email", email ).map( "username", username ).map( "name", name
).map( "password", password )
-//                                         .map( "organization", orgName ).map( "company",
"Apigee" );
-
-//        Map payload2 = hashMap( "grant_type", "password" ).map( "username", username ).map(
"password", password );
-//
-//        //TODO: make it easier to distinguish between owner/entity/response uuid.
-//        UUID userUuid = UUID.fromString( node.get( "data" ).get( "owner" ).get( "uuid"
).asText() );
-//
-//        node = mapper.readTree( resource().path( "/management/token" ).accept( MediaType.APPLICATION_JSON
)
-//                                          .type( MediaType.APPLICATION_JSON_TYPE ).post(
String.class, payload2 ) );
-//
-//        //assertNotNull( node );
-//
-//        node = mapper.readTree( resource().path( "/management/organizations/" + orgName
+ "/apps/sandbox" )
-//                                          .queryParam( "access_token", node.get( "access_token"
).textValue() )
-//                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE
)
-//                                          .get( String.class ) );
-//
-//        assertNotNull( node );
-//
-//        Set<String> rolePerms = setup.getEmf().getEntityManager(
-//                UUID.fromString( node.get( "entities" ).get( 0 ).get( "uuid" ).asText()
) )
-//                                     .getRolePermissions( "guest" );
-//        assertNotNull( rolePerms );
-//        assertTrue( rolePerms.contains( "get,post,put,delete:/**" ) );
-//        logNode( node );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( setup.getEmf().getManagementAppId()
);
-//        User user = em.get( userUuid, User.class );
-//        assertEquals( name, user.getName() );
-//        assertEquals( "Apigee", user.getProperty( "company" ) );
+        assertTrue(org != null && org.getName().equals(orgName));
     }
 
 //

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b6fcc2/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 c3b17d6..d8339f1 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
@@ -19,6 +19,7 @@ package org.apache.usergrid.rest.test.resource2point0;
 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/d3b6fcc2/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 5f58ba6..711b016 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
@@ -53,4 +53,10 @@ public class NamedResource implements UrlResource {
     public WebResource getResource() {
         return parent.getResource().path( getPath() );
     }
+
+    public WebResource getResourceWithToken() {
+        WebResource resource = parent.getResource().path( getPath() );
+        return resource.queryParam("access_token",this.context.getToken().getAccessToken());
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b6fcc2/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
index 087ce56..d862892 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
@@ -22,6 +22,7 @@ import java.util.Map;
 import javax.ws.rs.core.MediaType;
 
 import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.Organization;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 import org.apache.usergrid.utils.MapUtils;
 
@@ -41,7 +42,7 @@ public class OrganizationResource extends NamedResource {
         super( name, context, parent );
     }
 
-    public ApplicationResource getApp(final String app){
+    public ApplicationResource app(final String app){
         return new ApplicationResource( app, context ,this );
     }
 
@@ -51,4 +52,7 @@ public class OrganizationResource extends NamedResource {
                      .post( ApiResponse.class, organization );
     }
 
+    public Organization get(){
+        throw new UnsupportedOperationException("service doesn't exist");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b6fcc2/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
index d67ddad..4c7dc46 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
@@ -40,7 +40,7 @@ public class OrgResource  extends NamedResource {
 
 
     public OrganizationResource organization (final String orgname){
-        return new OrganizationResource( orgname,context,parent );
+        return new OrganizationResource( orgname,context,this );
     }
 
     public Organization post(Organization organization){
@@ -61,10 +61,7 @@ public class OrgResource  extends NamedResource {
     }
 
     public Organization get(){
-        ApiResponse response = getResource().queryParam( "access_token", context.getToken()
).type( MediaType.APPLICATION_JSON_TYPE )
-                                            .accept( MediaType.APPLICATION_JSON ).get(ApiResponse.class);
-
-       return new Organization(response);
+        throw new UnsupportedOperationException("service doesn't exist");
     }
 
     public void delete(){

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b6fcc2/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 513b126..353d964 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
@@ -25,6 +25,7 @@ import org.apache.usergrid.rest.test.resource2point0.endpoints.ApplicationResour
 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.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.Organization;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 
 
@@ -35,21 +36,13 @@ import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
  */
 public class OrganizationResource extends NamedResource {
 
-//TODO: need to find a way to integrate having the orgs/<org_name> into the same endpoint.
-    //maybe I could append the orgs to the end of the parent
     public OrganizationResource( final String name, final ClientContext context, final UrlResource
parent ) {
         super( name, context, parent );
     }
-
-    //TODO: change this so that it reflects the management endpoint
-//    public ApplicationResource getApp(final String app){
-//        return new ApplicationResource( app, context ,this );
-//    }
-
-//    public ApiResponse post(Map<String,String> organization){
-//
-//        return getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON
)
-//                     .post( ApiResponse.class, organization );
-//    }
-
+    public Organization get() {
+        Map<String,Object> response = getResourceWithToken().type(MediaType.APPLICATION_JSON_TYPE)
+                .accept(MediaType.APPLICATION_JSON).get(Organization.class);
+        Organization org =  new Organization().mapOrgResponse(response);
+        return org;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b6fcc2/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 68c2b57..f5b6581 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
@@ -38,21 +38,15 @@ public class TokenResource extends NamedResource {
 
     /**
      * Obtains an access token of type "application user"
-     * @param grant
-     * @param username
-     * @param password
+     * @param token
      * @return
      */
     public Token post(Token token){
-
-        return getResource().type( MediaType.APPLICATION_JSON_TYPE )
+        token = getResource().type( MediaType.APPLICATION_JSON_TYPE )
                                     .accept( MediaType.APPLICATION_JSON ).post(Token.class,token);
-//        ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE )
-//                            .accept( MediaType.APPLICATION_JSON ).post(ApiResponse.class,token);
+        this.context.setToken(token);
+        return token;
 
-//        Token returnedToken = new Token( response );
-//        returnedToken.setUser(new User(response));
-        //return returnedToken;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b6fcc2/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 cfdd7a6..a094ac2 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
@@ -93,4 +93,9 @@ public class Organization extends Entity {
     public void setOwner(User user){
         this.user = user;
     }
+
+    public Organization mapOrgResponse(Map<String,Object> map){
+        putAll((Map<String, Object>) map.get("organization"));
+        return this;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b6fcc2/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Token.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Token.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Token.java
index 3f7c5de..12be69f 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Token.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Token.java
@@ -52,8 +52,12 @@ public class Token extends Entity{
         return (Long) this.get("passwordChanged");
     }
 
-//    public User setUser(User user){
-//        this.user =
-//    }
+    public void setUser(User user) {
+        this.user = user;
+    }
+
+    public User getUser() {
+        return user;
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b6fcc2/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 baec806..4a25044 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
@@ -18,6 +18,7 @@ package org.apache.usergrid.rest.test.resource2point0.state;
 
 
 import org.apache.usergrid.rest.test.resource2point0.model.Organization;
+import org.apache.usergrid.rest.test.resource2point0.model.Token;
 import org.apache.usergrid.rest.test.resource2point0.model.User;
 
 
@@ -26,18 +27,18 @@ import org.apache.usergrid.rest.test.resource2point0.model.User;
  * This includes token,orgName and uuid, appName and uuid, and user information
  */
 public class ClientContext {
-    private String token;
+    private Token token;
 //    private Organization organization;
 //    private User user;
 
 
 
-    public String getToken() {
+    public Token getToken() {
         return token;
     }
 
 
-    public void setToken( final String token ) {
+    public void setToken( final Token token ) {
         this.token = token;
     }
 


Mime
View raw message