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 2014/12/22 17:54:17 UTC

[11/50] incubator-usergrid git commit: adding token calls

adding token calls


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

Branch: refs/heads/two-dot-o
Commit: c3b522246c1677b94373f45619f7c769a2276a37
Parents: 52d1458
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Dec 15 19:40:54 2014 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Dec 15 19:40:54 2014 -0700

----------------------------------------------------------------------
 .../rest/management/OrganizationsIT.java        |  4 +-
 .../rest/test/resource2point0/ClientSetup.java  | 28 +++++++++--
 .../rest/test/resource2point0/RestClient.java   |  5 ++
 .../endpoints/TokenResource.java                | 53 ++++++++++++++++++++
 .../endpoints/mgmt/ApplicationResource.java     | 49 ++++++++++++++++++
 .../endpoints/mgmt/OrganizationResource.java    |  7 ++-
 .../test/resource2point0/model/Application.java |  4 +-
 .../rest/test/resource2point0/model/Token.java  |  6 +++
 8 files changed, 145 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3b52224/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 c9f9f11..9f96193 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
@@ -26,6 +26,7 @@ import java.util.UUID;
 
 import javax.ws.rs.core.MediaType;
 
+import org.apache.usergrid.rest.test.resource2point0.ClientSetup;
 import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
@@ -63,9 +64,6 @@ import static org.junit.Assert.assertTrue;
 public class OrganizationsIT extends AbstractRestIT {
     private static final Logger LOG = LoggerFactory.getLogger( OrganizationsIT.class );
 
-    @Rule
-    public TestContextSetup context = new TestContextSetup( this );
-
 
     /**
      * Tests that a Organization and Owner can be created and that they persist properties and default permissions.

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3b52224/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 7546385..b115ed8 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
@@ -24,6 +24,10 @@ package org.apache.usergrid.rest.test.resource2point0;
 import java.io.IOException;
 import java.util.Map;
 
+import org.apache.usergrid.rest.test.resource2point0.endpoints.ApplicationResource;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.OrganizationResource;
+import org.apache.usergrid.rest.test.resource2point0.model.Application;
+import org.apache.usergrid.rest.test.resource2point0.model.Token;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -41,8 +45,13 @@ import org.apache.usergrid.utils.MapUtils;
 public class ClientSetup implements TestRule {
 
     RestClient restClient;
+    protected String username, orgName, appName;
+    protected Organization organization;
+    protected Application application;
+
 
     public ClientSetup (String serverUrl) {
+
         restClient = new RestClient( serverUrl );
     }
 
@@ -77,15 +86,26 @@ public class ClientSetup implements TestRule {
         String methodName = description.getMethodName();
         String name = testClass + "." + methodName;
 
-        String username = name + UUIDUtils.newTimeUUID();
-//TODO: also create a new application
-        Organization organization = new Organization( username,username,username+"@usergrid.com",username,username,null  );
+        username = "user_"+name + UUIDUtils.newTimeUUID();
+        orgName = "org_"+name+UUIDUtils.newTimeUUID();
+        orgName = "app_"+name+UUIDUtils.newTimeUUID();
+
+        organization = restClient.management().orgs().post(new Organization( orgName,username,username+"@usergrid.com",username,username, null  ));
+
+        Token token = restClient.management().token().post(new Token(username,username));
+
+        application = restClient.management().orgs().organization(organization.getName()).app().post(new Application(appName));
 
-        Organization orgOwner = restClient.management().orgs().post( organization );
         //ApiResponse response = restClient.management().orgs().post( mapOrganization(username,username,username+"@usergrid.com",username,username ) );
         System.out.println();
 
+    }
+    protected OrganizationResource getOrganizationResource(){
+        return restClient.org(orgName);
+    }
 
+    protected ApplicationResource getApplicationResource(){
+        return getOrganizationResource().app(appName);
     }
 
     public RestClient getRestClient(){

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3b52224/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 d8339f1..7369d13 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
@@ -16,6 +16,7 @@
  */
 package org.apache.usergrid.rest.test.resource2point0;
 
+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;
@@ -86,6 +87,10 @@ public class RestClient implements UrlResource {
         return new OrganizationResource( orgName, context, this );
     }
 
+    public TokenResource token(){
+        return new TokenResource(context,this);
+    }
+
 
     //todo:fix this method for the client.
 //    public void loginAdminUser( final String username, final String password ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3b52224/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/TokenResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/TokenResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/TokenResource.java
new file mode 100644
index 0000000..41c9f2a
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/TokenResource.java
@@ -0,0 +1,53 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  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.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+
+package org.apache.usergrid.rest.test.resource2point0.endpoints;
+
+
+
+import org.apache.usergrid.rest.test.resource2point0.model.Token;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+
+import javax.ws.rs.core.MediaType;
+
+/**
+ * Classy class class.
+ */
+public class TokenResource extends NamedResource {
+    public TokenResource(final ClientContext context, final UrlResource parent) {
+        super("token", context, parent);
+    }
+
+
+    /**
+     * Obtains an access token of type "application user"
+     *
+     * @param token
+     * @return
+     */
+    public Token post(Token token) {
+        token = getResource().type(MediaType.APPLICATION_JSON_TYPE)
+                .accept(MediaType.APPLICATION_JSON).post(Token.class, token);
+        this.context.setToken(token);
+        return token;
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3b52224/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
new file mode 100644
index 0000000..12df661
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
@@ -0,0 +1,49 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  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.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+
+package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt;
+
+import org.apache.usergrid.batch.service.App;
+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.Application;
+import org.apache.usergrid.rest.test.resource2point0.model.Organization;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+
+import javax.ws.rs.core.MediaType;
+import java.util.Map;
+
+/**
+ * Classy class class.
+ */
+public class ApplicationResource extends NamedResource {
+    public ApplicationResource( ClientContext context, UrlResource parent) {
+        super("applications", context, parent);
+    }
+
+    public Application post(Application application) {
+        ApiResponse response = getResource(true).type(MediaType.APPLICATION_JSON_TYPE)
+                .accept(MediaType.APPLICATION_JSON).post(ApiResponse.class,application);
+        Application app =  new Application(response);
+        return app;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3b52224/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 01cafcf..96ec55c 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
@@ -21,10 +21,10 @@ import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
 
-import org.apache.usergrid.rest.test.resource2point0.endpoints.ApplicationResource;
 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.Application;
 import org.apache.usergrid.rest.test.resource2point0.model.Organization;
 import org.apache.usergrid.rest.test.resource2point0.model.User;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
@@ -46,4 +46,9 @@ public class OrganizationResource extends NamedResource {
         Organization org =  new Organization().mapOrgResponse(response);
         return org;
     }
+
+    public ApplicationResource app(){
+        return new ApplicationResource(  context ,this );
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3b52224/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Application.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Application.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Application.java
index ed29134..16e4718 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Application.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Application.java
@@ -26,9 +26,7 @@ import java.util.List;
  * Classy class class.
  */
 public class Application extends Entity {
-    public Application(){
-
-    }
+    public Application(){  }
 
     public Application(String name){
         this.put("name",name);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3b52224/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 12be69f..14c3ea2 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
@@ -28,6 +28,12 @@ public class Token extends Entity{
 
     }
 
+    public Token( String username, String password){
+        this.put("grant_type","token");
+        this.put("username", username);
+        this.put("password", password);
+    }
+
     /**
      * Constructor for admin/application user ( difference is in the path )
      * @param grantType