usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [14/21] incubator-usergrid git commit: Added some more methods for users and organizations. Added comments on resetpw viewables not working in test environment. Cleanup of imports. Added fixes to remaining tests
Date Tue, 03 Mar 2015 21:03:42 GMT
Added some more methods for users and organizations.
Added comments on resetpw viewables not working in test environment.
Cleanup of imports.
Added fixes to remaining tests


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

Branch: refs/heads/USERGRID-422
Commit: 61dcb345f7dbd05c2a3f7d3a81a5a3d10d23f5ba
Parents: 984b6a6
Author: grey <greyes@apigee.com>
Authored: Mon Mar 2 16:12:53 2015 -0800
Committer: grey <greyes@apigee.com>
Committed: Mon Mar 2 16:12:53 2015 -0800

----------------------------------------------------------------------
 .../usergrid/rest/management/AdminUsersIT.java  | 103 ++++++++-----------
 .../endpoints/mgmt/OrgResource.java             |  12 ++-
 .../endpoints/mgmt/UserResource.java            |   4 +
 .../endpoints/mgmt/UsersResource.java           |   7 ++
 4 files changed, 63 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/61dcb345/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java
index 133d64b..166f8ce 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java
@@ -17,21 +17,15 @@
 
 package org.apache.usergrid.rest.management;
 
-
-/**
- * Created by ApigeeCorporation on 9/17/14.
- */
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import javax.mail.Message;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMultipart;
-import javax.ws.rs.core.MediaType;
 
 import org.junit.Before;
 import org.junit.Ignore;
@@ -40,14 +34,11 @@ import org.junit.Test;
 import org.jvnet.mock_javamail.Mailbox;
 
 
-import org.apache.commons.collections4.map.LinkedMap;
 
 import org.apache.usergrid.management.MockImapClient;
 import org.apache.usergrid.persistence.index.utils.StringUtils;
 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.endpoints.mgmt.*;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResource;
 import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
 import org.apache.usergrid.rest.test.resource2point0.model.Entity;
@@ -60,17 +51,14 @@ import com.sun.jersey.api.client.UniformInterfaceException;
 import com.sun.jersey.api.representation.Form;
 
 import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION;
-import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION;
 import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS;
 import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS;
 import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_EMAIL;
 import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_TEST_ACCOUNT_ADMIN_USER_EMAIL;
 import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_TEST_ACCOUNT_ADMIN_USER_PASSWORD;
-import static org.apache.usergrid.utils.MapUtils.hashMap;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -444,7 +432,7 @@ public class AdminUsersIT extends AbstractRestIT {
     public void checkFormPasswordReset() throws Exception {
 
 
-        String errors = management().users().user( clientSetup.getUsername() ).resetpw().post(null);
+        management().users().user( clientSetup.getUsername() ).resetpw().post(null);
 
 
         //Create mocked inbox
@@ -476,7 +464,7 @@ public class AdminUsersIT extends AbstractRestIT {
         assertTrue( html.contains( "invalid token" ) );
     }
 //
-//
+//     TODO: will work once resetpw viewables work
 //    @Test
 //    @Ignore( "causes problems in build" )
 //    public void passwordResetIncorrectUserName() throws Exception {
@@ -551,8 +539,8 @@ public class AdminUsersIT extends AbstractRestIT {
             assertEquals( 409, e.getResponse().getStatus() );
         }
     }
-//
-//
+
+      //TODO: won't work until resetpw viewables are fixed in the embedded enviroment.
 //    @Test
 //    public void checkPasswordChangeTime() throws Exception {
 //
@@ -610,54 +598,45 @@ public class AdminUsersIT extends AbstractRestIT {
 //    }
 //
 //
-//    /** USERGRID-1960 */
-//    @Test
-//    @Ignore( "Depends on other tests" )
-//    public void listOrgUsersByName() {
-//        JsonNode response = context.management().orgs().organization( context.getOrgName()
).users().get();
-//
-//        //get the response and verify our user is there
-//        JsonNode adminNode = response.get( "data" ).get( 0 );
-//        assertEquals( context.getActiveUser().getEmail(), adminNode.get( "email" ).asText()
);
-//        assertEquals( context.getActiveUser().getUser(), adminNode.get( "username" ).asText()
);
-//    }
-//
-//    @Test
-//    public void createOrgFromUserConnectionFail() throws Exception {
-//
-//
-//        Map<String, String> payload = hashMap( "email", "orgfromuserconn@apigee.com"
).map( "password", "password" )
-//                                                                                      .map(
"organization", "orgfromuserconn" );
-//
-//        JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept(
MediaType.APPLICATION_JSON )
-//                                                   .type( MediaType.APPLICATION_JSON_TYPE
).post( String.class, payload ));
-//
-//        String userId = node.get( "data" ).get( "owner" ).get( "uuid" ).asText();
-//
-//        assertNotNull( node );
-//
-//        String token = mgmtToken( "orgfromuserconn@apigee.com", "password" );
-//
-//        node = mapper.readTree( resource().path( String.format( "/management/users/%s/",
userId ) ).queryParam( "access_token", token )
-//                                          .type( MediaType.APPLICATION_JSON_TYPE ).get(
String.class ));
-//
-//        logNode( node );
-//
-//        payload = hashMap( "organization", "Orgfromuserconn" );
-//
-//        // try to create the same org again off the connection
-//        try {
-//            node = mapper.readTree( resource().path( String.format( "/management/users/%s/organizations",
userId ) )
-//                                              .queryParam( "access_token", token ).accept(
MediaType.APPLICATION_JSON )
-//                                              .type( MediaType.APPLICATION_JSON_TYPE ).post(
String.class, payload ));
-//            fail( "Should have thrown unique exception on org name" );
-//        }
-//        catch ( Exception ex ) {
-//        }
-//    }
+    /** USERGRID-1960 */
+    @Test
+    public void listOrgUsersByName() {
+
+        Entity adminUserPayload = new Entity();
+        String username = "listOrgUsersByName"+UUIDUtils.newTimeUUID();
+        adminUserPayload.put( "username", username );
+        adminUserPayload.put( "name", username );
+        adminUserPayload.put( "email", username+"@usergrid.com" );
+        adminUserPayload.put( "password", username );
+
+        management().orgs().organization( clientSetup.getOrganizationName() ).users().post(
adminUserPayload );
+
+        refreshIndex();
+
+        Entity adminUsers = management().orgs().organization( clientSetup.getOrganizationName()
).users().get();
+
+        assertEquals("There need to be 2 admin users",2,( ( ArrayList ) adminUsers.getResponse().getData()
).size());
+
+    }
+
+    //TODO: figure out what is the expected behavior from this test. While it fails it is
not sure what it should return
+    @Test
+    public void createOrgFromUserConnectionFail() throws Exception {
+
+        Token token = management().token().post( new Token( clientSetup.getUsername(),clientSetup.getPassword()
) );
+        // try to create the same org again off the connection
+        try {
+            management().users().user( clientSetup.getUsername() ).organizations().post(
clientSetup.getOrganization(),token );
+
+            fail( "Should have thrown unique exception on org name" );
+        }
+        catch ( UniformInterfaceException uie ) {
+            assertEquals(500,uie.getResponse().getStatus());
+        }
+    }
 
     /**
-     * Create an organization payload with almost the same value for everyfield.
+     * Create an organization payload with almost the same value for every field.
      * @param baseName
      * @param properties
      * @return

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/61dcb345/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 839f2cd..93e7d6b 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
@@ -24,6 +24,7 @@ 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.model.QueryParameters;
+import org.apache.usergrid.rest.test.resource2point0.model.Token;
 import org.apache.usergrid.rest.test.resource2point0.model.User;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 
@@ -39,7 +40,7 @@ import com.sun.jersey.api.representation.Form;
 public class OrgResource  extends NamedResource {
 
     public OrgResource( final ClientContext context, final UrlResource parent ) {
-        super( "orgs", context, parent );
+        super( "organizations", context, parent );
     }
 
 
@@ -89,6 +90,15 @@ public class OrgResource  extends NamedResource {
 
         return org;
     }
+    public Organization post(Organization organization, Token token){
+        ApiResponse response = getResource(true,token).type( MediaType.APPLICATION_JSON_TYPE
).accept( MediaType.APPLICATION_JSON )
+                                            .post( ApiResponse.class,organization );
+
+        Organization org = new Organization(response);
+        org.setOwner( response );
+
+        return org;
+    }
 
     public Organization put(Organization organization){
         ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept(
MediaType.APPLICATION_JSON )

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/61dcb345/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java
index 0531646..9af23ce 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java
@@ -58,6 +58,10 @@ public class UserResource extends NamedResource {
         return new ResetResource(context,this);
     }
 
+    public OrgResource organizations() {
+        return new OrgResource( context, this );
+    }
+
     public Entity get() {
         WebResource resource = getResource( true );
         ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE )

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/61dcb345/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
index a273c58..e62d5aa 100644
--- 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
@@ -62,4 +62,11 @@ public class UsersResource extends NamedResource {
         return new Entity(response);
     }
 
+    public Entity get() {
+        WebResource resource = getResource(true);
+
+        ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE )
+                                       .accept( MediaType.APPLICATION_JSON ).get( ApiResponse.class);
+        return new Entity(response);
+    }
 }


Mime
View raw message