usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [1/2] incubator-usergrid git commit: Used jackson to deserialize organization and response into the dynamic entity properties. Made collection abstract class for other collections that will use it ( User collections, Roles collections)
Date Fri, 12 Dec 2014 16:42:47 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/UG-rest-test-framework-overhaul ce26189f3 -> b030d89c8


Used jackson to deserialize organization and response into the dynamic entity properties.
Made collection abstract class for other collections that will use it ( User collections,
Roles collections)


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

Branch: refs/heads/UG-rest-test-framework-overhaul
Commit: 2573255a8a3b1d852cb278ce21cc6958354031b2
Parents: 8437af5
Author: grey <greyes@apigee.com>
Authored: Fri Dec 12 08:42:30 2014 -0800
Committer: grey <greyes@apigee.com>
Committed: Fri Dec 12 08:42:30 2014 -0800

----------------------------------------------------------------------
 .../rest/test/resource2point0/ClientSetup.java  |  16 +--
 .../rest/test/resource2point0/DumbClient.java   |  15 ++-
 .../endpoints/ApplicationResource.java          |   6 +-
 .../resource2point0/endpoints/Collection.java   |   4 +-
 .../resource2point0/endpoints/RestResource.java |  23 ++---
 .../resource2point0/endpoints/RootResource.java |   3 +-
 .../endpoints/mgmt/OrgResource.java             |   8 +-
 .../test/resource2point0/model/ApiResponse.java |   2 +-
 .../rest/test/resource2point0/model/Entity.java |  16 +++
 .../resource2point0/model/Organization.java     | 103 +++++++++++++++++--
 .../resource2point0/state/ClientContext.java    |  38 +++----
 11 files changed, 168 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2573255a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
index 31a30c9..fc74eb6 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
@@ -79,21 +79,13 @@ public class ClientSetup implements TestRule {
 
         String username = name + UUIDUtils.newTimeUUID();
 //TODO: also create a new application
+        Organization organization = new Organization( username,username,username+"@usergrid.com",username,username
 );
 
-        //Default creates a new org and owner.
-        //restClient.getContext().setOrganization( new Organization(  ) );
-        ApiResponse response = restClient.management().orgs().post( mapOrganization(username,username,username+"@usergrid.com",username,username
) );
-        //TODO: inquire about what kind of context the getContext should hold, and if we
need to set it everytime we do
-        //a change with the client.
-        //restClient.getContext().setOrganization( new Organization(  ) );
+        //ApiResponse response = restClient.management().orgs().post( mapOrganization(username,username,username+"@usergrid.com",username,username
) );
+        organization = restClient.management().orgs().post( organization );
+        System.out.println();
 
-    }
-
-    public Map<String,String> mapOrganization(String orgName, String username, String
email, String name, String password){
 
-        return MapUtils.hashMap( "organization", orgName ).map( "username", username )
-                       .map( "email", email ).map( "name", name )
-                       .map( "password", password);
     }
 
     public RestClient getRestClient(){

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2573255a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/DumbClient.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/DumbClient.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/DumbClient.java
index 210307a..c9f2ccb 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/DumbClient.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/DumbClient.java
@@ -24,6 +24,7 @@ import org.junit.Rule;
 import org.junit.Test;
 
 import org.apache.usergrid.persistence.index.utils.UUIDUtils;
+import org.apache.usergrid.rest.test.resource2point0.model.User;
 import org.apache.usergrid.utils.MapUtils;
 
 import static org.junit.Assert.assertEquals;
@@ -49,9 +50,19 @@ public class DumbClient extends AbstractRestIT {
     public void stuff(){
 
         String name = "stuff"+ UUIDUtils.newTimeUUID();
+        User user = new User( "derp","derp", "derp"  );
+        //so user could have an instance of save, then the save does a deep copy of all properties
and saves over the previous versions.
+        //Save is part of the entities.
 
-        Organization org = clientSetup.getRestClient().management().orgs().post(  )
-        clientSetup.getRestClient().management().orgs().delete(org.getName);
+
+//        clientSetup.getRestClient().org(  ).getApp( "" ).users().post( user );
+//        clientSetup.getRestClient().org(  ).getApp( "" ).users().get(user.getUuid());
+//        clientSetup.getRestClient().org(  ).getApp( "" ).users().put(user);
+
+
+
+        //Organization org = clientSetup.getRestClient().management().orgs().post(  )
+      //  clientSetup.getRestClient().management().orgs().delete(org.getName);
        // OrganizationResource response =  clientSetup.getRestClient().management().orgs().organization(
"" );
         //assertNotNull( response );
         //EntityResponse itr  =  client.org( "test" ).getApp( "test" ).users().getEntityResponse();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2573255a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationResource.java
index 91c9043..2357655 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationResource.java
@@ -38,7 +38,7 @@ public class ApplicationResource extends NamedResource {
      * The pattern should look like: orgs.apps.users , orgs.apps.groups and so on...
      * @return
      */
-    public Collection users(){
-        return new Collection("users", context , this);
-    }
+//    public Collection users(){
+//        return new Collection("users", context , this);
+//    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2573255a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/Collection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/Collection.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/Collection.java
index a51a07c..4495d77 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/Collection.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/Collection.java
@@ -31,7 +31,7 @@ import com.google.common.base.Optional;
  * Holds POST,PUT,GET,DELETE methods for Collections. Models the rest endpoints for the different
ways
  * to get an entity out of UG.
  */
-public class Collection extends NamedResource {
+public abstract class Collection extends NamedResource {
 
 
     public Collection( final String name, final ClientContext context,  final UrlResource
parent ) {
@@ -44,7 +44,7 @@ public class Collection extends NamedResource {
      * @return
      */
     public ApiResponse get(final Optional<String> cursor){
-        return getResource().get( ApiResponse.class );
+      return getResource().get( ApiResponse.class );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2573255a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/RestResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/RestResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/RestResource.java
index 211f45d..4686ab8 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/RestResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/RestResource.java
@@ -2,44 +2,41 @@ package org.apache.usergrid.rest.test.resource2point0.endpoints;
 
 
 import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 
 import com.sun.jersey.api.client.WebResource;
 
 
 /**
- * Created by ApigeeCorporation on 12/11/14.
+ * Class that would hold all the rest calls that are duplicated ( such as posts, or puts
where all we have to do
+ * is send a map through jersey.
  */
 public class RestResource extends NamedResource {
 
-    public RestResource (){
-
+    //TODO: wouldn't need a name, so maybe it isn't a NamedResource but just a URL Resource.
+    public RestResource( final ClientContext context, final UrlResource parent ) {
+        super("name",context, parent );
     }
 
     public ApiResponse post(){
-        return
+        return null;
     }
 
     public ApiResponse put(){
+        return null;
 
     }
 
     public ApiResponse get(){
+        return null;
 
     }
 
     public ApiResponse delete(){
+        return null;
 
     }
 
 
-    @Override
-    public String getPath() {
-        return super.getPath();
-    }
-
 
-    @Override
-    public WebResource getResource() {
-        return super.getResource();
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2573255a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/RootResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/RootResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/RootResource.java
index b7a51d1..5f1e7ec 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/RootResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/RootResource.java
@@ -43,7 +43,8 @@ public class RootResource implements UrlResource {
      * @param serverUrl The serverurl that has stood up the UG instance i.e localhost:8080
      * @param context Contains the token that will be used for the following resources.
      */
-    public RootResource( final String serverUrl, final ClientContext context ) {this.serverUrl
= serverUrl;
+    public RootResource( final String serverUrl, final ClientContext context ) {
+        this.serverUrl = serverUrl;
         this.context = context;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2573255a/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 cec2acf..1d19719 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
@@ -25,7 +25,9 @@ import javax.ws.rs.core.MediaType;
 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;
+import org.apache.usergrid.utils.MapUtils;
 
 
 /**
@@ -50,10 +52,12 @@ public class OrgResource  extends NamedResource {
 
     //TODO: why take in a map? Just use base resource and call post from there,
     //TODO: Why ApiResponse when we could just type what we expect back.
-    public ApiResponse post(Map<String,String> organization){
+    public Organization post(Organization organization){
 
         return getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON
)
-                            .post( ApiResponse.class, organization );
+                            .post( Organization.class,organization );
     }
 
+
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2573255a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/ApiResponse.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/ApiResponse.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/ApiResponse.java
index b41ad4f..de61349 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/ApiResponse.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/ApiResponse.java
@@ -35,7 +35,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
 /**
  * Contains the needed types
  */
-public class ApiResponse {
+public class ApiResponse<Entity> {
 
     private String accessToken;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2573255a/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 6874faa..5ed47d3 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
@@ -35,6 +35,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 import org.apache.usergrid.persistence.EntityFactory;
 import org.apache.usergrid.persistence.Schema;
 import org.apache.usergrid.persistence.annotations.EntityProperty;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.Collection;
 
 import com.fasterxml.jackson.annotation.JsonAnyGetter;
 import com.fasterxml.jackson.annotation.JsonAnySetter;
@@ -69,6 +70,19 @@ public class Entity implements Serializable {
     protected Map<String, Set<Object>> dynamic_sets = new TreeMap<String,
Set<Object>>( String.CASE_INSENSITIVE_ORDER );
 
 
+    private Collection targetResource;
+
+
+
+    /**
+     * Performs deep copy on entity passed in and save over what we currently have
+     */
+    public void save(){
+        Entity response = targetResource.put(this);
+        this.dynamic_properties.putAll(response.getDynamicProperties());
+    }
+
+
     @EntityProperty( required = true, mutable = false, basic = true, indexed = false )
     @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
     public UUID getUuid() {
@@ -263,6 +277,8 @@ public class Entity implements Serializable {
         return "Entity(" + getProperties() + ")";
     }
 
+    public Collection getTargetResource(){return targetResource;}
+    public void setTargetResource(Collection targetResource){this.targetResource = targetResource;}
 
     @JsonAnySetter
     public void setDynamicProperty( String key, Object value ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2573255a/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 135f693..2853db1 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
@@ -19,30 +19,111 @@ package org.apache.usergrid.rest.test.resource2point0.model;
 
 
 import java.util.HashMap;
+import java.util.Map;
 import java.util.UUID;
 
+import org.apache.usergrid.utils.MapUtils;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
 
 /**
  * Holds the parsed out information of the Organization returned from the ApiResponse.
  * so when you get the organization object, we could then model it out to do the client calls
  */
-public class Organization extends HashMap<String,Object> {
+public class Organization extends Entity {
 
-    private String orgName;
-    //Keep the raw api response in here, dole out
-    private ApiResponse apiResponse;
 
-    //Organizations are always initialized by name, and the uuid will be set on creations
-    public Organization( final String orgName) {
-        this.orgName = orgName;
+    private String organization;
+    private String username;
+    private String email;
+    private String name;
+    private String password;
+    private String passwordHistorySize;
+
+
+    public Organization() {
+
+    }
+
+    public Organization( String orgName, String username, String email, String ownerName,
String password ){
+
+        this.dynamic_properties.put( "orgName",orgName );
+    }
+
+    @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
+    public String getOrganization( ) {
+        return ( String ) this.dynamic_properties.get( "orgName" );
+    }
+    public void setOrganization( final String orgName ) {
+        this.organization = orgName;
+    }
+
+    @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
+    public String getUsername() {
+        return ( String ) this.dynamic_properties.get( "orgName" );
+    }
+
+
+    public void setUsername( final String username ) {
+        this.username = username;
+    }
+
+    @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
+    public String getEmail() {
+        return ( String ) this.dynamic_properties.get( "orgName" );
+    }
+
+
+    public void setEmail( final String email ) {
+        this.email = email;
+    }
+
+    @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
+    public String getName() {
+        return ( String ) this.dynamic_properties.get( "orgName" );
     }
 
-    public UUID getUuid() {
-        return (UUID)this.get( "uuid" );
+    public void setName( final String name ) {
+        this.name = name;
     }
 
-    public String getOrgName() {
-        return orgName;
+
+    @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
+    public String getPassword() {
+        return ( String ) this.dynamic_properties.get( "orgName" );
     }
 
+
+
+
+//    public String getOrganizationName(){
+//        return (String) dynamic_properties.get( "orgName" );
+//    }
+
+
+    public void setPasswordHistorySize( final String passwordHistorySize ) {
+        this.passwordHistorySize = passwordHistorySize;
+    }
+
+    //private String orgName;
+    //Keep the raw api response in here, dole out
+   // private ApiResponse apiResponse;
+
+    //Organizations are always initialized by name, and the uuid will be set on creations
+//    public Organization( final String orgName) {
+//        this.orgName = orgName;
+//    }
+
+    //Add setter and getter methods for throwing in relevant objects.
+//
+//    public UUID getUuid() {
+//        return (UUID)this.get( "uuid" );
+//    }
+//
+//    public String getOrgName() {
+//        return (String) this.get( "name" );
+//        //return orgName;
+//    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2573255a/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 dcf7212..baec806 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
@@ -27,8 +27,8 @@ import org.apache.usergrid.rest.test.resource2point0.model.User;
  */
 public class ClientContext {
     private String token;
-    private Organization organization;
-    private User user;
+//    private Organization organization;
+//    private User user;
 
 
 
@@ -41,21 +41,21 @@ 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;
-    }
+//    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;
+//    }
 }


Mime
View raw message