You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2015/03/03 02:19:52 UTC

incubator-usergrid git commit: Removed test properties change, and some formatting. Added test for properties and additionally added to management feed test.

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-280 749905fe7 -> fa47d2da2


Removed test properties change, and some formatting.
Added test for properties and additionally added to management feed test.


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

Branch: refs/heads/USERGRID-280
Commit: fa47d2da20809bfe71372d95780b33117fd26546
Parents: 749905f
Author: grey <gr...@apigee.com>
Authored: Mon Mar 2 17:19:50 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Mon Mar 2 17:19:50 2015 -0800

----------------------------------------------------------------------
 .../usergrid/rest/management/AdminUsersIT.java  | 87 +++++++++++++-------
 .../rest/test/resource2point0/ClientSetup.java  |  1 -
 .../resources/usergrid-custom-test.properties   |  5 --
 3 files changed, 57 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fa47d2da/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 a66332a..fffb28a 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
@@ -93,16 +93,12 @@ public class AdminUsersIT extends AbstractRestIT {
         passwordPayload.put( "oldpassword", password );
 
         // change the password as admin. The old password isn't required
-        management.users().user( username ).password().post(passwordPayload); //entity( username ).password().post;
+        management.users().user( username ).password().post(passwordPayload);
 
         this.refreshIndex();
 
-
-        //assertNull( getError( node ) );
-
         //Get the token using the new password
         management.token().post( new Token( username, "testPassword" ) );
-        //this.app().token().post(new Token(username, "testPassword"));
 
         //Check that we cannot get the token using the old password
         try {
@@ -164,8 +160,6 @@ public class AdminUsersIT extends AbstractRestIT {
         Map<String, Object> passwordPayload = new HashMap<String, Object>();
         passwordPayload.put( "newpassword", "testPassword" );
 
-
-
         management.users().user( username ).password().post( clientSetup.getSuperuserToken(), passwordPayload );
 
         this.refreshIndex();
@@ -197,7 +191,8 @@ public class AdminUsersIT extends AbstractRestIT {
         ArrayList<Map<String,Object>> feedEntityMap = ( ArrayList ) mgmtUserFeedEntity.get( "entities" );
         assertNotNull( feedEntityMap );
         assertNotNull( feedEntityMap.get( 0 ).get( "title" )  );
-
+        assertTrue("Needs to contain the feed of the specific management user",
+            ((String)(feedEntityMap.get( 0 ).get( "title" ))).contains(clientSetup.getUsername() ));
     }
 
 
@@ -213,6 +208,7 @@ public class AdminUsersIT extends AbstractRestIT {
         Entity originalTestProperties = new Entity( originalTestPropertiesResponse );
         try {
             //Set runtime enviroment to the following settings
+            //TODO: make properties verification its own test.
             Map<String, Object> testPropertiesMap = new HashMap<>();
 
             testPropertiesMap.put( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
@@ -228,14 +224,6 @@ public class AdminUsersIT extends AbstractRestIT {
 
             refreshIndex();
 
-            //Retrieve properties and ensure that they are set correctly.
-            ApiResponse apiResponse = clientSetup.getRestClient().testPropertiesResource().get();
-
-            assertEquals( "sysadmin-1@mockserver.com", apiResponse.getProperties().get( PROPERTIES_SYSADMIN_EMAIL ) );
-            assertEquals( "true", apiResponse.getProperties().get( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION ) );
-            assertEquals( "false", apiResponse.getProperties().get( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS ) );
-            assertEquals( "false", apiResponse.getProperties().get( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS ) );
-
             //Create organization for the admin user to be confirmed
             Organization organization = createOrgPayload( "testUnconfirmedAdminLogin", null );
 
@@ -251,12 +239,13 @@ public class AdminUsersIT extends AbstractRestIT {
             assertFalse( "adminUser should not be confirmed yet", adminUser.getConfirmed() );
 
 
+            //Get token grant for new admin user.
             QueryParameters queryParameters = new QueryParameters();
             queryParameters.addParam( "grant_type", "password" ).addParam( "username", adminUser.getUsername() )
                            .addParam( "password", organization.getPassword() );
 
 
-            //Check that the adminUser cannot log in and fails with a 403
+            //Check that the adminUser cannot log in and fails with a 403 due to not being confirmed.
             try {
                 management().token().get( queryParameters );
                 fail( "Admin user should not be able to log in." );
@@ -365,19 +354,12 @@ public class AdminUsersIT extends AbstractRestIT {
         }
     }
 
-
-    private String getTokenFromMessage( Message msg ) throws IOException, MessagingException {
-        String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString();
-        return StringUtils.substringAfterLast( body, "token=" );
-    }
-
-
     /**
      * Update the current management user and make sure the change persists
      * @throws Exception
      */
-    @Ignore("Fails because we cannot get a single management user without a Admin level token, but"
-        + "we can put without any of those permissions. This test will work once that issue has been resolved.")
+    @Ignore("Fails because we cannot GET a management user with a super user token - only with an Admin level token."
+        + "But, we can PUT with a superuser token. This test will work once that issue has been resolved.")
     @Test
     public void updateManagementUser() throws Exception {
 
@@ -404,7 +386,7 @@ public class AdminUsersIT extends AbstractRestIT {
         assertEquals( "Apigee",userUpdated.getAsString( "company" ) );
     }
 
-    public Entity updateAdminUser(Entity userProperty, Organization organization){
+    private Entity updateAdminUser(Entity userProperty, Organization organization){
         management().users().user( organization.getUsername() ).put( userProperty );
 
         return management().users().user( organization.getUsername() ).get();
@@ -434,7 +416,6 @@ public class AdminUsersIT extends AbstractRestIT {
 
         management().users().user( clientSetup.getUsername() ).resetpw().post(null);
 
-
         //Create mocked inbox
         List<Message> inbox = Mailbox.get( clientSetup.getEmail() );
         assertFalse( inbox.isEmpty() );
@@ -534,7 +515,7 @@ public class AdminUsersIT extends AbstractRestIT {
 
         refreshIndex();
 
-        payload.put("newpassword",passwords[0]);
+        payload.put( "newpassword", passwords[0] );
         payload.put( "oldpassword", passwords[1] );
 
         //Make sure that we can't change the password with itself using a different entry in the history.
@@ -548,7 +529,7 @@ public class AdminUsersIT extends AbstractRestIT {
         }
     }
 
-      //TODO: won't work until resetpw viewables are fixed in the embedded enviroment.
+      //TODO: won't work until resetpw viewables are fixed in the embedded environment.
 //    @Test
 //    public void checkPasswordChangeTime() throws Exception {
 //
@@ -654,6 +635,39 @@ public class AdminUsersIT extends AbstractRestIT {
         }
     }
 
+    @Test
+    public void testProperties(){
+        ApiResponse originalTestPropertiesResponse = clientSetup.getRestClient().testPropertiesResource().get();
+        Entity originalTestProperties = new Entity( originalTestPropertiesResponse );
+        try {
+            //Set runtime enviroment to the following settings
+            Map<String, Object> testPropertiesMap = new HashMap<>();
+
+            testPropertiesMap.put( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
+            testPropertiesMap.put( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
+            //Requires admins to do email confirmation before they can log in.
+            testPropertiesMap.put( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
+            testPropertiesMap.put( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
+
+            Entity testPropertiesPayload = new Entity( testPropertiesMap );
+
+            //Send rest call to the /testProperties endpoint to persist property changes
+            clientSetup.getRestClient().testPropertiesResource().post( testPropertiesPayload );
+
+            refreshIndex();
+
+            //Retrieve properties and ensure that they are set correctly.
+            ApiResponse apiResponse = clientSetup.getRestClient().testPropertiesResource().get();
+
+            assertEquals( "sysadmin-1@mockserver.com", apiResponse.getProperties().get( PROPERTIES_SYSADMIN_EMAIL ) );
+            assertEquals( "true", apiResponse.getProperties().get( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION ) );
+            assertEquals( "false", apiResponse.getProperties().get( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS ) );
+            assertEquals( "false", apiResponse.getProperties().get( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS ) );
+        }finally{
+            clientSetup.getRestClient().testPropertiesResource().post( originalTestProperties);
+        }
+    }
+
     /**
      * Create an organization payload with almost the same value for every field.
      * @param baseName
@@ -666,4 +680,17 @@ public class AdminUsersIT extends AbstractRestIT {
             orgName,orgName+"@usergrid",orgName,orgName, properties);
     }
 
+
+    /**
+     * Extract token from mocked inbox message.
+     * @param msg
+     * @return
+     * @throws IOException
+     * @throws MessagingException
+     */
+    private String getTokenFromMessage( Message msg ) throws IOException, MessagingException {
+        String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString();
+        return StringUtils.substringAfterLast( body, "token=" );
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fa47d2da/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 63c420f..3455744 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
@@ -126,7 +126,6 @@ public class ClientSetup implements TestRule {
         return superuserName;
     }
 
-
     public String getSuperuserPassword() {
         return superuserPassword;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fa47d2da/stack/rest/src/test/resources/usergrid-custom-test.properties
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/usergrid-custom-test.properties b/stack/rest/src/test/resources/usergrid-custom-test.properties
index c299ba5..d726f2b 100644
--- a/stack/rest/src/test/resources/usergrid-custom-test.properties
+++ b/stack/rest/src/test/resources/usergrid-custom-test.properties
@@ -12,11 +12,6 @@
 
 # REST module test properties
 
-# these settings allow tests to run and consistently pass on 16GB MacBook Pro
-# with ug.heapmax=5000m and ug.heapmin=3000m (set in Maven settings.xml)
-tomcat.startup=embedded
-tomcat.threads=200
-
 cassandra.startup=external
 cassandra.timeout=2000
 cassandra.connections=800