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 2015/01/12 19:13:25 UTC

[05/17] incubator-usergrid git commit: Fixing organizationIT by adding back in the users flow.

Fixing organizationIT by adding back in the users flow.


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

Branch: refs/heads/two-dot-o
Commit: 5a59dea0716dd24666ee75e2b330b25483ae06a5
Parents: fa27c04
Author: grey <gr...@apigee.com>
Authored: Tue Dec 23 12:04:28 2014 -0800
Committer: grey <gr...@apigee.com>
Committed: Tue Dec 23 12:04:28 2014 -0800

----------------------------------------------------------------------
 .../rest/management/OrganizationsIT.java        | 54 ++++++++++++++------
 .../endpoints/mgmt/OrganizationResource.java    |  5 ++
 .../endpoints/mgmt/UsersResource.java           | 50 ++++++++++++++++++
 3 files changed, 93 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5a59dea0/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 7ae579a..6ccaab1 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
@@ -29,6 +29,8 @@ import org.slf4j.LoggerFactory;
 import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
 
+import org.apache.usergrid.rest.test.resource2point0.RestClient;
+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;
@@ -85,9 +87,9 @@ public class OrganizationsIT extends AbstractRestIT {
 
         assertNotNull( clientSetup.getRestClient().getContext().getToken() );
 
+        //Assert that the get returns the correct org and owner.
         Organization returnedOrg = clientSetup.getRestClient().management().orgs().organization( orgName ).get();
 
-        //TODO: clean this up
         assertTrue( returnedOrg != null && returnedOrg.getName().equals( orgName ) );
 
         User returnedUser = returnedOrg.getOwner();
@@ -114,25 +116,22 @@ public class OrganizationsIT extends AbstractRestIT {
         Organization orgPayload = new Organization( orgName, username, email, name, password, null );
 
         Organization orgCreatedResponse = clientSetup.getRestClient().management().orgs().post( orgPayload );
-
+        this.refreshIndex();
 
         assertNotNull( orgCreatedResponse );
 
-        //TODO: Check to see if we still need to refresh the index.
 
         Organization orgTestDuplicatePayload =
                 new Organization( orgName, username + "test", email + "test", name + "test", password, null );
-        Organization orgTestDuplicateResponse = null;
         try {
-            orgTestDuplicateResponse = clientSetup.getRestClient().management().orgs().post( orgTestDuplicatePayload );
+            Organization orgTestDuplicateResponse = clientSetup.getRestClient()
+                                                               .management().orgs().post( orgTestDuplicatePayload );
             fail("Should not have been able to create duplicate organization");
         }
         catch ( UniformInterfaceException ex ) {
             errorParse( 400,duplicateUniquePropertyExistsErrorMessage, ex );
         }
 
-        //refreshIndex( "create-duplicate-orgname-org" + timeuuid, "dummy" );
-
         // Post to get token of what should be a non existent user.
 
         Token tokenPayload = new Token( "password", username + "test", password );
@@ -174,6 +173,8 @@ public class OrganizationsIT extends AbstractRestIT {
 
         Organization orgCreatedResponse = clientSetup.getRestClient().management().orgs().post( orgPayload );
 
+        this.refreshIndex();
+
         assertNotNull( orgCreatedResponse );
 
         orgPayload = new Organization( orgName+"test", username+"test", email, name+"test", password+"test", null );
@@ -186,8 +187,6 @@ public class OrganizationsIT extends AbstractRestIT {
             errorParse( 400,duplicateUniquePropertyExistsErrorMessage,ex);
         }
 
-        //refreshIndex( "test-organization", "test-app" );
-
         Token tokenPayload = new Token( "password", username + "test", password );
         Token tokenError = null;
         try {
@@ -208,7 +207,10 @@ public class OrganizationsIT extends AbstractRestIT {
     }
 
 
-    //TODO:
+    /**
+     * Creates a organization by setting the information as part of the queryParameters
+     * @throws IOException
+     */
     @Test
     public void testOrgPOSTParams() throws IOException {
 
@@ -218,8 +220,6 @@ public class OrganizationsIT extends AbstractRestIT {
         String orgName = username;
         String email = username + "@usergrid.com";
 
-        UUID timeUuid = UUIDUtils.newTimeUUID();
-
         QueryParameters queryParameters = new QueryParameters();
         queryParameters.setKeyValue( "organization",orgName );
         queryParameters.setKeyValue( "username",username );
@@ -230,10 +230,17 @@ public class OrganizationsIT extends AbstractRestIT {
 
         Organization organization = clientSetup.getRestClient().management().orgs().post( queryParameters );
 
+        this.refreshIndex();
+
         assertNotNull( organization );
         assertEquals( orgName,organization.getName() );
     }
 
+
+    /**
+     * Creates a organization by posting a form with the organization data.
+     * @throws IOException
+     */
     @Test
     public void testOrgPOSTForm() throws IOException {
 
@@ -248,6 +255,8 @@ public class OrganizationsIT extends AbstractRestIT {
 
         Organization organization = clientSetup.getRestClient().management().orgs().post( form );
 
+        this.refreshIndex();
+
         assertNotNull( organization );
         assertEquals( "testOrgPOSTForm" + timeUuid ,organization.getName() );
     }
@@ -271,20 +280,33 @@ public class OrganizationsIT extends AbstractRestIT {
     }
 
 
+    /**
+     * Creates a regular organization user and then does a get to check the correct username is returned.
+     * @throws Exception
+     */
     @Test
     public void testCreateOrgUserAndReturnCorrectUsername() throws Exception {
-/*
+
+
         String username = "testCreateOrgUserAndReturnCorrectUsername"+UUIDUtils.newTimeUUID();
 
         RestClient restClient = clientSetup.getRestClient();
 
-        User adminUserPayload = new User(username,username,username+"@usergrid.com",username  );
+        Entity adminUserPayload = new Entity();
+        adminUserPayload.put( "username", username );
+        adminUserPayload.put( "name", username );
+        adminUserPayload.put( "email", username+"@usergrid.com" );
+        adminUserPayload.put( "password", username );
 
-        User adminUserResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() )
+        Entity adminUserResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() )
                                            .users().post( adminUserPayload );
 
         assertNotNull( adminUserResponse );
-*/
+        assertEquals( username, adminUserResponse.get( "username" ) );
+
+        Entity adminUserGetResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() )
+                                                .users()//needs an additional endpoint here
+
 //        Map<String, String> payload = hashMap( "username", "test-user-2" ).map( "name", "Test User 2" )
 //                                                                          .map( "email", "test-user-2@mockserver.com" )
 //                                                                          .map( "password", "password" );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5a59dea0/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 51d48cd..b60fbb2 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
@@ -39,6 +39,11 @@ public class OrganizationResource extends NamedResource {
     public OrganizationResource( final String name, final ClientContext context, final UrlResource parent ) {
         super( name, context, parent );
     }
+
+    public UsersResource users(){
+        return new UsersResource( context,this );
+    }
+
     public Organization get() {
         ApiResponse rep = getResource(true).type(MediaType.APPLICATION_JSON_TYPE)
                                            .accept( MediaType.APPLICATION_JSON ).get( ApiResponse.class );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5a59dea0/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java
new file mode 100644
index 0000000..7c79977
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java
@@ -0,0 +1,50 @@
+/*
+ * 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 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.Entity;
+import org.apache.usergrid.rest.test.resource2point0.model.User;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+
+import com.sun.jersey.api.client.WebResource;
+
+
+/**
+ * Handles calls to the users management endpoint
+ * Example: /management/orgs/org_name/users
+ */
+public class UsersResource extends NamedResource {
+    public UsersResource( final ClientContext context, final UrlResource parent ) {
+        super( "users", context, parent );
+    }
+
+    public Entity post(Entity userPayload){
+        WebResource resource = getResource(true);
+
+        ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE )
+                .accept( MediaType.APPLICATION_JSON ).post( ApiResponse.class, userPayload);
+        return new Entity(response);
+    }
+
+}