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/02/26 19:06:43 UTC

[1/8] incubator-usergrid git commit: Commented out failures to do tests one at a time.

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-280 [created] 0b5f598fb


Commented out failures to do tests one at a time.


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

Branch: refs/heads/USERGRID-280
Commit: 0f893ffcbf7e6afaab87654cd794a9ba59893227
Parents: 231a449
Author: grey <gr...@apigee.com>
Authored: Thu Jan 8 15:46:41 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Thu Jan 8 15:46:41 2015 -0800

----------------------------------------------------------------------
 .../usergrid/rest/management/AdminUsersIT.java  | 1362 +++++++++---------
 1 file changed, 680 insertions(+), 682 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0f893ffc/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 91ea270..271c013 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
@@ -31,6 +31,7 @@ import javax.mail.MessagingException;
 import javax.mail.internet.MimeMultipart;
 import javax.ws.rs.core.MediaType;
 
+import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
@@ -46,10 +47,13 @@ import org.apache.usergrid.management.MockImapClient;
 import org.apache.usergrid.management.OrganizationInfo;
 import org.apache.usergrid.management.OrganizationOwnerInfo;
 import org.apache.usergrid.management.UserInfo;
-import org.apache.usergrid.rest.AbstractRestIT;
 import org.apache.usergrid.rest.TestContextSetup;
 import org.apache.usergrid.rest.management.organizations.OrganizationsResource;
 import org.apache.usergrid.rest.test.resource.mgmt.Organization;
+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.security.TestAdminUser;
 import org.apache.usergrid.rest.test.security.TestUser;
 import org.apache.usergrid.security.AuthPrincipalInfo;
@@ -80,19 +84,13 @@ import static org.junit.Assert.fail;
  */
 public class AdminUsersIT extends AbstractRestIT {
 
-    //Used for all MUUserResourceITTests
-    private Logger LOG = LoggerFactory.getLogger( AdminUsersIT.class );
-
-    @Rule
-    public TestContextSetup context = new TestContextSetup( this );
-
-    public AdminUsersIT() throws Exception {
+    ManagementResource management;
 
+    @Before
+    public void setup() {
+        management= clientSetup.getRestClient().management();
     }
 
-
-
-
     /**
      * Test if we can reset our password as an admin
      */
@@ -125,677 +123,677 @@ public class AdminUsersIT extends AbstractRestIT {
         assertNull( getError( node ) );
     }
 
-
-    @Test
-    public void passwordMismatchErrorAdmin() {
-        String origPassword = "foo";
-        String newPassword = "bar";
-
-        Map<String, String> data = new HashMap<String, String>();
-        data.put( "newpassword", origPassword );
-
-        // now change the password, with an incorrect old password
-
-        data.put( "oldpassword", origPassword );
-        data.put( "newpassword", newPassword );
-
-        ClientResponse.Status responseStatus = null;
-
-        try {
-            resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
-                      .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data );
-        }
-        catch ( UniformInterfaceException uie ) {
-            responseStatus = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertNotNull( responseStatus );
-
-        assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus );
-    }
-
-
-    @Test
-    public void setAdminPasswordAsSysAdmin() throws IOException {
-
-        String superToken = superAdminToken();
-
-        String newPassword = "foo";
-
-        Map<String, String> data = new HashMap<String, String>();
-        data.put( "newpassword", newPassword );
-
-        // change the password as admin. The old password isn't required
-        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken )
-                                                   .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                                                   .post( String.class, data ));
-
-        assertNull( getError( node ) );
-
-        refreshIndex("test-organization", "test-app");
-
-        // log in with the new password
-        String token = mgmtToken( "test", newPassword );
-
-        assertNotNull( token );
-
-        data.put( "newpassword", "test" );
-
-        // now change the password back
-        node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken )
-                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                                          .post( String.class, data ));
-
-        assertNull( getError( node ) );
-    }
-
-    @Test
-    public void mgmtUserFeed() throws Exception {
-        JsonNode userdata = mapper.readTree( resource().path( "/management/users/test@usergrid.com/feed" )
-                                                       .queryParam( "access_token", adminAccessToken )
-                                                       .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-        assertTrue( StringUtils.contains( this.getEntity( userdata, 0 ).get( "title" ).asText(),
-                "<a href=\"mailto:test@usergrid.com\">" ) );
-    }
-
-    //everything below is MUUserResourceIT
-
-    @Test
-    public void testCaseSensitivityAdminUser() throws Exception {
-
-        LOG.info( "Starting testCaseSensitivityAdminUser()" );
-
-        UserInfo mixcaseUser = setup.getMgmtSvc()
-                                    .createAdminUser( "AKarasulu", "Alex Karasulu", "AKarasulu@Apache.org", "test", true, false );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        AuthPrincipalInfo adminPrincipal = new AuthPrincipalInfo(
-                AuthPrincipalType.ADMIN_USER, mixcaseUser.getUuid(), UUIDUtils.newTimeUUID() );
-        OrganizationInfo organizationInfo =
-                setup.getMgmtSvc().createOrganization( "MixedCaseOrg", mixcaseUser, true );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        String tokenStr = mgmtToken( "akarasulu@apache.org", "test" );
-
-        // Should succeed even when we use all lowercase
-        JsonNode node = mapper.readTree( resource().path( "/management/users/akarasulu@apache.org" )
-                                                   .queryParam( "access_token", tokenStr )
-                                                   .accept( MediaType.APPLICATION_JSON )
-                                                   .type( MediaType.APPLICATION_JSON_TYPE )
-                                                   .get( String.class ));
-        logNode( node );
-    }
-
-
-    @Test
-    public void testUnconfirmedAdminLogin() throws Exception {
-
-        // Setup properties to require confirmation of users
-        // -------------------------------------------
-
-        Map<String, String> originalProperties = getRemoteTestProperties();
-
-        try {
-            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
-            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
-            setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
-            setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
-            setTestProperty( PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION, "true" );
-
-            assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() );
-            assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() );
-
-            // Setup org/app/user variables and create them
-            // -------------------------------------------
-            String orgName = this.getClass().getName();
-            String appName = "testUnconfirmedAdminLogin";
-            String userName = "TestUser";
-            String email = "test-user-46@mockserver.com";
-            String passwd = "testpassword";
-            OrganizationOwnerInfo orgOwner;
-
-            orgOwner = setup.getMgmtSvc().createOwnerAndOrganization(
-                    orgName, userName, appName, email, passwd, false, false );
-            assertNotNull( orgOwner );
-            String returnedUsername = orgOwner.getOwner().getUsername();
-            assertEquals( userName, returnedUsername );
-
-            UserInfo adminUserInfo = setup.getMgmtSvc().getAdminUserByUsername( userName );
-            assertNotNull( adminUserInfo );
-            assertFalse( "adminUser should not be activated yet", adminUserInfo.isActivated() );
-            assertFalse( "adminUser should not be confirmed yet", adminUserInfo.isConfirmed() );
-
-            // Attempt to authenticate but this should fail
-            // -------------------------------------------
-            JsonNode node;
-            try {
-                node = mapper.readTree( resource().path( "/management/token" )
-                                                  .queryParam( "grant_type", "password" )
-                                                  .queryParam( "username", userName )
-                                                  .queryParam( "password", passwd )
-                                                  .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-
-                fail( "Unconfirmed users should not be authorized to authenticate." );
-            }
-            catch ( UniformInterfaceException e ) {
-                node = mapper.readTree( e.getResponse().getEntity( String.class ));
-                assertEquals( "invalid_grant", node.get( "error" ).textValue() );
-                assertEquals( "User must be confirmed to authenticate",
-                        node.get( "error_description" ).textValue() );
-                LOG.info( "Unconfirmed user was not authorized to authenticate!" );
-            }
-
-            // Confirm the getting account confirmation email for unconfirmed user
-            // -------------------------------------------
-            List<Message> inbox = Mailbox.get( email );
-            assertFalse( inbox.isEmpty() );
-
-            MockImapClient client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" );
-            client.processMail();
-
-            Message confirmation = inbox.get( 0 );
-            assertEquals( "User Account Confirmation: " + email, confirmation.getSubject() );
-
-            // Extract the token to confirm the user
-            // -------------------------------------------
-            String token = getTokenFromMessage( confirmation );
-            LOG.info( token );
-
-            ActivationState state = setup.getMgmtSvc().handleConfirmationTokenForAdminUser(
-                    orgOwner.getOwner().getUuid(), token );
-            assertEquals( ActivationState.ACTIVATED, state );
-
-            Message activation = inbox.get( 1 );
-            assertEquals( "User Account Activated", activation.getSubject() );
-
-            client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" );
-            client.processMail();
-
-            refreshIndex(orgName, appName);
-
-            // Attempt to authenticate again but this time should pass
-            // -------------------------------------------
-
-            node = mapper.readTree( resource().path( "/management/token" )
-                                              .queryParam( "grant_type", "password" )
-                                              .queryParam( "username", userName )
-                                              .queryParam( "password", passwd )
-                                              .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-
-            assertNotNull( node );
-            LOG.info( "Authentication succeeded after confirmation: {}.", node.toString() );
-        }
-        finally {
-            setTestProperties( originalProperties );
-        }
-    }
-
-
-    @Test
-    public void testSystemAdminNeedsNoConfirmation() throws Exception {
-
-        Map<String, String> originalProperties = getRemoteTestProperties();
-
-        try {
-            // require comfirmation of new admin users
-            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
-            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
-            setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
-
-            assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() );
-            assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() );
-
-            String sysadminUsername = ( String ) setup.getMgmtSvc().getProperties()
-                                                      .get( AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_EMAIL );
-
-            String sysadminPassword = ( String ) setup.getMgmtSvc().getProperties()
-                                                      .get( AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_PASSWORD );
-
-            // sysadmin login should suceed despite confirmation setting
-            JsonNode node;
-            try {
-                node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" )
-                                                  .queryParam( "username", sysadminUsername ).queryParam( "password", sysadminPassword )
-                                                  .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-            }
-            catch ( UniformInterfaceException e ) {
-                fail( "Sysadmin should need no confirmation" );
-            }
-        }
-        finally {
-            setTestProperties( originalProperties );
-        }
-    }
-
-
-    @Test
-    public void testTestUserNeedsNoConfirmation() throws Exception {
-
-        Map<String, String> originalProperties = getRemoteTestProperties();
-
-        try {
-            // require comfirmation of new admin users
-            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
-            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
-            setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
-
-            assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() );
-            assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() );
-
-            String testUserUsername = ( String ) setup.getMgmtSvc().getProperties()
-                                                      .get( AccountCreationProps
-                                                              .PROPERTIES_TEST_ACCOUNT_ADMIN_USER_EMAIL );
-
-            String testUserPassword = ( String ) setup.getMgmtSvc().getProperties()
-                                                      .get( AccountCreationProps
-                                                              .PROPERTIES_TEST_ACCOUNT_ADMIN_USER_PASSWORD );
-
-            // test user login should suceed despite confirmation setting
-            JsonNode node;
-            try {
-                node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" )
-                                                  .queryParam( "username", testUserUsername ).queryParam( "password", testUserPassword )
-                                                  .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-            }
-            catch ( UniformInterfaceException e ) {
-                fail( "Test User should need no confirmation" );
-            }
-        }
-        finally {
-            setTestProperties( originalProperties );
-        }
-    }
-
-
-    private String getTokenFromMessage( Message msg ) throws IOException, MessagingException {
-        String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString();
-        return StringUtils.substringAfterLast( body, "token=" );
-    }
-
-
-    @Test
-    public void updateManagementUser() throws Exception {
-        Map<String, String> payload =
-                hashMap( "email", "uort-user-1@apigee.com" ).map( "username", "uort-user-1" ).map( "name", "Test User" )
-                                                            .map( "password", "password" ).map( "organization", "uort-org" ).map( "company", "Apigee" );
-
-        JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON )
-                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
-        logNode( node );
-        String userId = node.get( "data" ).get( "owner" ).get( "uuid" ).asText();
-
-        assertEquals( "Apigee", node.get( "data" ).get( "owner" ).get( "properties" ).get( "company" ).asText() );
-
-        String token = mgmtToken( "uort-user-1@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( "company", "Usergrid" );
-        LOG.info( "sending PUT for company update" );
-        node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token )
-                                          .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, payload ));
-        assertNotNull( node );
-        node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token )
-                                          .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-        assertEquals( "Usergrid", node.get( "data" ).get( "properties" ).get( "company" ).asText() );
-
-
-        logNode( node );
-    }
-
-
-    @Test
-    public void getUser() throws Exception {
-
-        // set an organization property
-        HashMap<String, Object> payload = new HashMap<String, Object>();
-        Map<String, Object> properties = new HashMap<String, Object>();
-        properties.put( "securityLevel", 5 );
-        payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties );
-
-
-        /**
-         * Get the original org admin before we overwrite the property as a super user
-         */
-        final TestUser orgAdmin = context.getActiveUser();
-        final String orgName = context.getOrgName();
-        final String superAdminToken = superAdminToken();
-
-        TestAdminUser superAdmin = new TestAdminUser( "super", "super", "superuser@usergrid.com" );
-        superAdmin.setToken( superAdminToken );
-
-        Organization org = context.withUser( superAdmin ).management().orgs().organization( orgName );
-
-        org.put( payload );
-
-
-        //now get the org
-        JsonNode node = context.withUser( orgAdmin ).management().users().user( orgAdmin.getUser() ).get();
-
-        logNode( node );
-
-        JsonNode applications = node.findValue( "applications" );
-        assertNotNull( applications );
-        JsonNode users = node.findValue( "users" );
-        assertNotNull( users );
-
-        JsonNode securityLevel = node.findValue( "securityLevel" );
-        assertNotNull( securityLevel );
-        assertEquals( 5L, securityLevel.asLong() );
-    }
-
-
-    @Test
-    public void getUserShallow() throws Exception {
-
-
-        // set an organization property
-        HashMap<String, Object> payload = new HashMap<String, Object>();
-        Map<String, Object> properties = new HashMap<String, Object>();
-        properties.put( "securityLevel", 5 );
-        payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties );
-
-
-        /**
-         * Get the original org admin before we overwrite the property as a super user
-         */
-        final TestUser orgAdmin = context.getActiveUser();
-        final String orgName = context.getOrgName();
-        final String superAdminToken  = superAdminToken();
-
-        TestAdminUser superAdmin = new TestAdminUser( "super", "super", "superuser@usergrid.com" );
-        superAdmin.setToken( superAdminToken );
-
-        Organization org = context.withUser( superAdmin ).management().orgs().organization( orgName );
-
-        org.put( payload );
-
-
-        //now get the org
-        JsonNode node = context.withUser( orgAdmin ).management().users().user( orgAdmin.getUser() ).withParam(
-                "shallow", "true" ).get();
-
-        logNode( node );
-
-        JsonNode applications = node.findValue( "applications" );
-        assertNull( applications );
-        JsonNode users = node.findValue( "users" );
-        assertNull( users );
-
-        JsonNode securityLevel = node.findValue( "securityLevel" );
-        assertNotNull( securityLevel );
-        assertEquals( 5L, securityLevel.asLong() );
-    }
-
-
-    @Test
-    public void reactivateMultipleSend() throws Exception {
-
-        JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON )
-                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, buildOrgUserPayload( "reactivate" ) ));
-
-        logNode( node );
-        String email = node.get( "data" ).get( "owner" ).get( "email" ).asText();
-        String uuid = node.get( "data" ).get( "owner" ).get( "uuid" ).asText();
-        assertNotNull( email );
-        assertEquals( "MUUserResourceIT-reactivate@apigee.com", email );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        // reactivate should send activation email
-
-        node = mapper.readTree( resource().path( String.format( "/management/users/%s/reactivate", uuid ) )
-                                          .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON )
-                                          .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get( email );
-
-        assertFalse( inbox.isEmpty() );
-        logNode( node );
-    }
-
-
-    private Map<String, String> buildOrgUserPayload( String caller ) {
-        String className = this.getClass().getSimpleName();
-        Map<String, String> payload = hashMap( "email", String.format( "%s-%s@apigee.com", className, caller ) )
-                .map( "username", String.format( "%s-%s-user", className, caller ) )
-                .map( "name", String.format( "%s %s", className, caller ) ).map( "password", "password" )
-                .map( "organization", String.format( "%s-%s-org", className, caller ) );
-        return payload;
-    }
-
-
-    @Test
-    public void checkPasswordReset() throws Exception {
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        TestUser user = context.getActiveUser();
-
-        String email = user.getEmail();
-        UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email );
-        String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 );
-
-        assertTrue( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        Form formData = new Form();
-        formData.add( "token", resetToken );
-        formData.add( "password1", "sesame" );
-        formData.add( "password2", "sesame" );
-
-        String html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" )
-                                .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData );
-
-        assertTrue( html.contains( "password set" ) );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        assertFalse( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) );
-
-        html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" )
-                         .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData );
-
-        assertTrue( html.contains( "invalid token" ) );
-    }
-
-
-    @Test
-    @Ignore( "causes problems in build" )
-    public void passwordResetIncorrectUserName() throws Exception {
-
-        String email = "test2@usergrid.com";
-        setup.getMgmtSvc().createAdminUser( "test2", "test2", "test2@usergrid.com", "sesa2me", false, false );
-        UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email );
-        String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 );
-
-        assertTrue( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) );
-
-        Form formData = new Form();
-        formData.add( "token", resetToken );
-        formData.add( "password1", "sesa2me" );
-        formData.add( "password2", "sesa2me" );
-
-        String html = resource().path( "/management/users/" + "noodle" + userInfo.getUsername() + "/resetpw" )
-                                .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData );
-
-        assertTrue( html.contains( "Incorrect username entered" ) );
-
-        html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" )
-                         .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData );
-
-        assertTrue( html.contains( "password set" ) );
-    }
-
-
-    @Test
-    public void checkPasswordHistoryConflict() throws Exception {
-
-        String[] passwords = new String[] { "password1", "password2", "password3", "password4" };
-
-        UserInfo user =
-                setup.getMgmtSvc().createAdminUser( "edanuff", "Ed Anuff", "ed@anuff.com", passwords[0], true, false );
-        assertNotNull( user );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        OrganizationInfo organization = setup.getMgmtSvc().createOrganization( "ed-organization", user, true );
-        assertNotNull( organization );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        // set history to 1
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put( OrganizationInfo.PASSWORD_HISTORY_SIZE_KEY, 1 );
-        organization.setProperties( props );
-        setup.getMgmtSvc().updateOrganization( organization );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( "ed@anuff.com" );
-
-        Map<String, String> payload = hashMap( "oldpassword", passwords[0] ).map( "newpassword", passwords[0] ); // fail
-
-        try {
-            JsonNode node = mapper.readTree( resource().path( "/management/users/edanuff/password" )
-                                                       .accept( MediaType.APPLICATION_JSON )
-                                                       .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
-            fail( "should fail with conflict" );
-        }
-        catch ( UniformInterfaceException e ) {
-            assertEquals( 409, e.getResponse().getStatus() );
-        }
-
-        payload.put( "newpassword", passwords[1] ); // ok
-        JsonNode node = mapper.readTree( resource().path( "/management/users/edanuff/password" )
-                                                   .accept( MediaType.APPLICATION_JSON )
-                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
-        payload.put( "oldpassword", passwords[1] );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        payload.put( "newpassword", passwords[0] ); // fail
-        try {
-            node = mapper.readTree( resource().path( "/management/users/edanuff/password" )
-                                              .accept( MediaType.APPLICATION_JSON )
-                                              .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
-            fail( "should fail with conflict" );
-        }
-        catch ( UniformInterfaceException e ) {
-            assertEquals( 409, e.getResponse().getStatus() );
-        }
-    }
-
-
-    @Test
-    public void checkPasswordChangeTime() throws Exception {
-
-        final TestUser user = context.getActiveUser();
-        String email = user.getEmail();
-        UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email );
-        String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        Form formData = new Form();
-        formData.add( "token", resetToken );
-        formData.add( "password1", "sesame" );
-        formData.add( "password2", "sesame" );
-
-        String html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" )
-                                .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData );
-        assertTrue( html.contains( "password set" ) );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        JsonNode node = mapper.readTree( resource().path( "/management/token" )
-                                                   .queryParam( "grant_type", "password" )
-                                                   .queryParam( "username", email ).queryParam( "password", "sesame" )
-                                                   .accept( MediaType.APPLICATION_JSON )
-                                                   .get( String.class ));
-
-        Long changeTime = node.get( "passwordChanged" ).longValue();
-        assertTrue( System.currentTimeMillis() - changeTime < 2000 );
-
-        Map<String, String> payload = hashMap( "oldpassword", "sesame" ).map( "newpassword", "test" );
-        node = mapper.readTree( resource().path( "/management/users/" + userInfo.getUsername() + "/password" )
-                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                                          .post( String.class, payload ));
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        node = mapper.readTree( resource().path( "/management/token" )
-                                          .queryParam( "grant_type", "password" )
-                                          .queryParam( "username", email )
-                                          .queryParam( "password", "test" )
-                                          .accept( MediaType.APPLICATION_JSON )
-                                          .get( String.class ));
-
-        Long changeTime2 = node.get( "passwordChanged" ).longValue();
-        assertTrue( changeTime < changeTime2 );
-        assertTrue( System.currentTimeMillis() - changeTime2 < 2000 );
-
-        node = mapper.readTree( resource().path( "/management/me" ).queryParam( "grant_type", "password" )
-                                          .queryParam( "username", email ).queryParam( "password", "test" ).accept( MediaType.APPLICATION_JSON )
-                                          .get( String.class ));
-
-        Long changeTime3 = node.get( "passwordChanged" ).longValue();
-        assertEquals( changeTime2, changeTime3 );
-    }
-
-
-    /** 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 ) {
-        }
+//
+//    @Test
+//    public void passwordMismatchErrorAdmin() {
+//        String origPassword = "foo";
+//        String newPassword = "bar";
+//
+//        Map<String, String> data = new HashMap<String, String>();
+//        data.put( "newpassword", origPassword );
+//
+//        // now change the password, with an incorrect old password
+//
+//        data.put( "oldpassword", origPassword );
+//        data.put( "newpassword", newPassword );
+//
+//        ClientResponse.Status responseStatus = null;
+//
+//        try {
+//            resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
+//                      .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data );
+//        }
+//        catch ( UniformInterfaceException uie ) {
+//            responseStatus = uie.getResponse().getClientResponseStatus();
+//        }
+//
+//        assertNotNull( responseStatus );
+//
+//        assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus );
+//    }
+//
+//
+//    @Test
+//    public void setAdminPasswordAsSysAdmin() throws IOException {
+//
+//        String superToken = superAdminToken();
+//
+//        String newPassword = "foo";
+//
+//        Map<String, String> data = new HashMap<String, String>();
+//        data.put( "newpassword", newPassword );
+//
+//        // change the password as admin. The old password isn't required
+//        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken )
+//                                                   .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+//                                                   .post( String.class, data ));
+//
+//        assertNull( getError( node ) );
+//
+//        refreshIndex("test-organization", "test-app");
+//
+//        // log in with the new password
+//        String token = mgmtToken( "test", newPassword );
+//
+//        assertNotNull( token );
+//
+//        data.put( "newpassword", "test" );
+//
+//        // now change the password back
+//        node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken )
+//                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+//                                          .post( String.class, data ));
+//
+//        assertNull( getError( node ) );
+//    }
+//
+//    @Test
+//    public void mgmtUserFeed() throws Exception {
+//        JsonNode userdata = mapper.readTree( resource().path( "/management/users/test@usergrid.com/feed" )
+//                                                       .queryParam( "access_token", adminAccessToken )
+//                                                       .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+//        assertTrue( StringUtils.contains( this.getEntity( userdata, 0 ).get( "title" ).asText(),
+//                "<a href=\"mailto:test@usergrid.com\">" ) );
+//    }
+//
+//    //everything below is MUUserResourceIT
+//
+//    @Test
+//    public void testCaseSensitivityAdminUser() throws Exception {
+//
+//        LOG.info( "Starting testCaseSensitivityAdminUser()" );
+//
+//        UserInfo mixcaseUser = setup.getMgmtSvc()
+//                                    .createAdminUser( "AKarasulu", "Alex Karasulu", "AKarasulu@Apache.org", "test", true, false );
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        AuthPrincipalInfo adminPrincipal = new AuthPrincipalInfo(
+//                AuthPrincipalType.ADMIN_USER, mixcaseUser.getUuid(), UUIDUtils.newTimeUUID() );
+//        OrganizationInfo organizationInfo =
+//                setup.getMgmtSvc().createOrganization( "MixedCaseOrg", mixcaseUser, true );
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        String tokenStr = mgmtToken( "akarasulu@apache.org", "test" );
+//
+//        // Should succeed even when we use all lowercase
+//        JsonNode node = mapper.readTree( resource().path( "/management/users/akarasulu@apache.org" )
+//                                                   .queryParam( "access_token", tokenStr )
+//                                                   .accept( MediaType.APPLICATION_JSON )
+//                                                   .type( MediaType.APPLICATION_JSON_TYPE )
+//                                                   .get( String.class ));
+//        logNode( node );
+//    }
+//
+//
+//    @Test
+//    public void testUnconfirmedAdminLogin() throws Exception {
+//
+//        // Setup properties to require confirmation of users
+//        // -------------------------------------------
+//
+//        Map<String, String> originalProperties = getRemoteTestProperties();
+//
+//        try {
+//            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
+//            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
+//            setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
+//            setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
+//            setTestProperty( PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION, "true" );
+//
+//            assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() );
+//            assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() );
+//
+//            // Setup org/app/user variables and create them
+//            // -------------------------------------------
+//            String orgName = this.getClass().getName();
+//            String appName = "testUnconfirmedAdminLogin";
+//            String userName = "TestUser";
+//            String email = "test-user-46@mockserver.com";
+//            String passwd = "testpassword";
+//            OrganizationOwnerInfo orgOwner;
+//
+//            orgOwner = setup.getMgmtSvc().createOwnerAndOrganization(
+//                    orgName, userName, appName, email, passwd, false, false );
+//            assertNotNull( orgOwner );
+//            String returnedUsername = orgOwner.getOwner().getUsername();
+//            assertEquals( userName, returnedUsername );
+//
+//            UserInfo adminUserInfo = setup.getMgmtSvc().getAdminUserByUsername( userName );
+//            assertNotNull( adminUserInfo );
+//            assertFalse( "adminUser should not be activated yet", adminUserInfo.isActivated() );
+//            assertFalse( "adminUser should not be confirmed yet", adminUserInfo.isConfirmed() );
+//
+//            // Attempt to authenticate but this should fail
+//            // -------------------------------------------
+//            JsonNode node;
+//            try {
+//                node = mapper.readTree( resource().path( "/management/token" )
+//                                                  .queryParam( "grant_type", "password" )
+//                                                  .queryParam( "username", userName )
+//                                                  .queryParam( "password", passwd )
+//                                                  .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+//
+//                fail( "Unconfirmed users should not be authorized to authenticate." );
+//            }
+//            catch ( UniformInterfaceException e ) {
+//                node = mapper.readTree( e.getResponse().getEntity( String.class ));
+//                assertEquals( "invalid_grant", node.get( "error" ).textValue() );
+//                assertEquals( "User must be confirmed to authenticate",
+//                        node.get( "error_description" ).textValue() );
+//                LOG.info( "Unconfirmed user was not authorized to authenticate!" );
+//            }
+//
+//            // Confirm the getting account confirmation email for unconfirmed user
+//            // -------------------------------------------
+//            List<Message> inbox = Mailbox.get( email );
+//            assertFalse( inbox.isEmpty() );
+//
+//            MockImapClient client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" );
+//            client.processMail();
+//
+//            Message confirmation = inbox.get( 0 );
+//            assertEquals( "User Account Confirmation: " + email, confirmation.getSubject() );
+//
+//            // Extract the token to confirm the user
+//            // -------------------------------------------
+//            String token = getTokenFromMessage( confirmation );
+//            LOG.info( token );
+//
+//            ActivationState state = setup.getMgmtSvc().handleConfirmationTokenForAdminUser(
+//                    orgOwner.getOwner().getUuid(), token );
+//            assertEquals( ActivationState.ACTIVATED, state );
+//
+//            Message activation = inbox.get( 1 );
+//            assertEquals( "User Account Activated", activation.getSubject() );
+//
+//            client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" );
+//            client.processMail();
+//
+//            refreshIndex(orgName, appName);
+//
+//            // Attempt to authenticate again but this time should pass
+//            // -------------------------------------------
+//
+//            node = mapper.readTree( resource().path( "/management/token" )
+//                                              .queryParam( "grant_type", "password" )
+//                                              .queryParam( "username", userName )
+//                                              .queryParam( "password", passwd )
+//                                              .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+//
+//            assertNotNull( node );
+//            LOG.info( "Authentication succeeded after confirmation: {}.", node.toString() );
+//        }
+//        finally {
+//            setTestProperties( originalProperties );
+//        }
+//    }
+//
+//
+//    @Test
+//    public void testSystemAdminNeedsNoConfirmation() throws Exception {
+//
+//        Map<String, String> originalProperties = getRemoteTestProperties();
+//
+//        try {
+//            // require comfirmation of new admin users
+//            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
+//            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
+//            setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
+//
+//            assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() );
+//            assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() );
+//
+//            String sysadminUsername = ( String ) setup.getMgmtSvc().getProperties()
+//                                                      .get( AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_EMAIL );
+//
+//            String sysadminPassword = ( String ) setup.getMgmtSvc().getProperties()
+//                                                      .get( AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_PASSWORD );
+//
+//            // sysadmin login should suceed despite confirmation setting
+//            JsonNode node;
+//            try {
+//                node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" )
+//                                                  .queryParam( "username", sysadminUsername ).queryParam( "password", sysadminPassword )
+//                                                  .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+//            }
+//            catch ( UniformInterfaceException e ) {
+//                fail( "Sysadmin should need no confirmation" );
+//            }
+//        }
+//        finally {
+//            setTestProperties( originalProperties );
+//        }
+//    }
+//
+//
+//    @Test
+//    public void testTestUserNeedsNoConfirmation() throws Exception {
+//
+//        Map<String, String> originalProperties = getRemoteTestProperties();
+//
+//        try {
+//            // require comfirmation of new admin users
+//            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
+//            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
+//            setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
+//
+//            assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() );
+//            assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() );
+//
+//            String testUserUsername = ( String ) setup.getMgmtSvc().getProperties()
+//                                                      .get( AccountCreationProps
+//                                                              .PROPERTIES_TEST_ACCOUNT_ADMIN_USER_EMAIL );
+//
+//            String testUserPassword = ( String ) setup.getMgmtSvc().getProperties()
+//                                                      .get( AccountCreationProps
+//                                                              .PROPERTIES_TEST_ACCOUNT_ADMIN_USER_PASSWORD );
+//
+//            // test user login should suceed despite confirmation setting
+//            JsonNode node;
+//            try {
+//                node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" )
+//                                                  .queryParam( "username", testUserUsername ).queryParam( "password", testUserPassword )
+//                                                  .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+//            }
+//            catch ( UniformInterfaceException e ) {
+//                fail( "Test User should need no confirmation" );
+//            }
+//        }
+//        finally {
+//            setTestProperties( originalProperties );
+//        }
+//    }
+//
+//
+//    private String getTokenFromMessage( Message msg ) throws IOException, MessagingException {
+//        String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString();
+//        return StringUtils.substringAfterLast( body, "token=" );
+//    }
+//
+//
+//    @Test
+//    public void updateManagementUser() throws Exception {
+//        Map<String, String> payload =
+//                hashMap( "email", "uort-user-1@apigee.com" ).map( "username", "uort-user-1" ).map( "name", "Test User" )
+//                                                            .map( "password", "password" ).map( "organization", "uort-org" ).map( "company", "Apigee" );
+//
+//        JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON )
+//                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
+//        logNode( node );
+//        String userId = node.get( "data" ).get( "owner" ).get( "uuid" ).asText();
+//
+//        assertEquals( "Apigee", node.get( "data" ).get( "owner" ).get( "properties" ).get( "company" ).asText() );
+//
+//        String token = mgmtToken( "uort-user-1@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( "company", "Usergrid" );
+//        LOG.info( "sending PUT for company update" );
+//        node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token )
+//                                          .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, payload ));
+//        assertNotNull( node );
+//        node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token )
+//                                          .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+//        assertEquals( "Usergrid", node.get( "data" ).get( "properties" ).get( "company" ).asText() );
+//
+//
+//        logNode( node );
+//    }
+//
+//
+//    @Test
+//    public void getUser() throws Exception {
+//
+//        // set an organization property
+//        HashMap<String, Object> payload = new HashMap<String, Object>();
+//        Map<String, Object> properties = new HashMap<String, Object>();
+//        properties.put( "securityLevel", 5 );
+//        payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties );
+//
+//
+//        /**
+//         * Get the original org admin before we overwrite the property as a super user
+//         */
+//        final TestUser orgAdmin = context.getActiveUser();
+//        final String orgName = context.getOrgName();
+//        final String superAdminToken = superAdminToken();
+//
+//        TestAdminUser superAdmin = new TestAdminUser( "super", "super", "superuser@usergrid.com" );
+//        superAdmin.setToken( superAdminToken );
+//
+//        Organization org = context.withUser( superAdmin ).management().orgs().organization( orgName );
+//
+//        org.put( payload );
+//
+//
+//        //now get the org
+//        JsonNode node = context.withUser( orgAdmin ).management().users().user( orgAdmin.getUser() ).get();
+//
+//        logNode( node );
+//
+//        JsonNode applications = node.findValue( "applications" );
+//        assertNotNull( applications );
+//        JsonNode users = node.findValue( "users" );
+//        assertNotNull( users );
+//
+//        JsonNode securityLevel = node.findValue( "securityLevel" );
+//        assertNotNull( securityLevel );
+//        assertEquals( 5L, securityLevel.asLong() );
+//    }
+//
+//
+//    @Test
+//    public void getUserShallow() throws Exception {
+//
+//
+//        // set an organization property
+//        HashMap<String, Object> payload = new HashMap<String, Object>();
+//        Map<String, Object> properties = new HashMap<String, Object>();
+//        properties.put( "securityLevel", 5 );
+//        payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties );
+//
+//
+//        /**
+//         * Get the original org admin before we overwrite the property as a super user
+//         */
+//        final TestUser orgAdmin = context.getActiveUser();
+//        final String orgName = context.getOrgName();
+//        final String superAdminToken  = superAdminToken();
+//
+//        TestAdminUser superAdmin = new TestAdminUser( "super", "super", "superuser@usergrid.com" );
+//        superAdmin.setToken( superAdminToken );
+//
+//        Organization org = context.withUser( superAdmin ).management().orgs().organization( orgName );
+//
+//        org.put( payload );
+//
+//
+//        //now get the org
+//        JsonNode node = context.withUser( orgAdmin ).management().users().user( orgAdmin.getUser() ).withParam(
+//                "shallow", "true" ).get();
+//
+//        logNode( node );
+//
+//        JsonNode applications = node.findValue( "applications" );
+//        assertNull( applications );
+//        JsonNode users = node.findValue( "users" );
+//        assertNull( users );
+//
+//        JsonNode securityLevel = node.findValue( "securityLevel" );
+//        assertNotNull( securityLevel );
+//        assertEquals( 5L, securityLevel.asLong() );
+//    }
+//
+//
+//    @Test
+//    public void reactivateMultipleSend() throws Exception {
+//
+//        JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON )
+//                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, buildOrgUserPayload( "reactivate" ) ));
+//
+//        logNode( node );
+//        String email = node.get( "data" ).get( "owner" ).get( "email" ).asText();
+//        String uuid = node.get( "data" ).get( "owner" ).get( "uuid" ).asText();
+//        assertNotNull( email );
+//        assertEquals( "MUUserResourceIT-reactivate@apigee.com", email );
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        // reactivate should send activation email
+//
+//        node = mapper.readTree( resource().path( String.format( "/management/users/%s/reactivate", uuid ) )
+//                                          .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON )
+//                                          .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get( email );
+//
+//        assertFalse( inbox.isEmpty() );
+//        logNode( node );
+//    }
+//
+//
+//    private Map<String, String> buildOrgUserPayload( String caller ) {
+//        String className = this.getClass().getSimpleName();
+//        Map<String, String> payload = hashMap( "email", String.format( "%s-%s@apigee.com", className, caller ) )
+//                .map( "username", String.format( "%s-%s-user", className, caller ) )
+//                .map( "name", String.format( "%s %s", className, caller ) ).map( "password", "password" )
+//                .map( "organization", String.format( "%s-%s-org", className, caller ) );
+//        return payload;
+//    }
+//
+//
+//    @Test
+//    public void checkPasswordReset() throws Exception {
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        TestUser user = context.getActiveUser();
+//
+//        String email = user.getEmail();
+//        UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email );
+//        String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 );
+//
+//        assertTrue( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) );
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        Form formData = new Form();
+//        formData.add( "token", resetToken );
+//        formData.add( "password1", "sesame" );
+//        formData.add( "password2", "sesame" );
+//
+//        String html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" )
+//                                .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData );
+//
+//        assertTrue( html.contains( "password set" ) );
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        assertFalse( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) );
+//
+//        html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" )
+//                         .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData );
+//
+//        assertTrue( html.contains( "invalid token" ) );
+//    }
+//
+//
+//    @Test
+//    @Ignore( "causes problems in build" )
+//    public void passwordResetIncorrectUserName() throws Exception {
+//
+//        String email = "test2@usergrid.com";
+//        setup.getMgmtSvc().createAdminUser( "test2", "test2", "test2@usergrid.com", "sesa2me", false, false );
+//        UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email );
+//        String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 );
+//
+//        assertTrue( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) );
+//
+//        Form formData = new Form();
+//        formData.add( "token", resetToken );
+//        formData.add( "password1", "sesa2me" );
+//        formData.add( "password2", "sesa2me" );
+//
+//        String html = resource().path( "/management/users/" + "noodle" + userInfo.getUsername() + "/resetpw" )
+//                                .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData );
+//
+//        assertTrue( html.contains( "Incorrect username entered" ) );
+//
+//        html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" )
+//                         .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData );
+//
+//        assertTrue( html.contains( "password set" ) );
+//    }
+//
+//
+//    @Test
+//    public void checkPasswordHistoryConflict() throws Exception {
+//
+//        String[] passwords = new String[] { "password1", "password2", "password3", "password4" };
+//
+//        UserInfo user =
+//                setup.getMgmtSvc().createAdminUser( "edanuff", "Ed Anuff", "ed@anuff.com", passwords[0], true, false );
+//        assertNotNull( user );
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        OrganizationInfo organization = setup.getMgmtSvc().createOrganization( "ed-organization", user, true );
+//        assertNotNull( organization );
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        // set history to 1
+//        Map<String, Object> props = new HashMap<String, Object>();
+//        props.put( OrganizationInfo.PASSWORD_HISTORY_SIZE_KEY, 1 );
+//        organization.setProperties( props );
+//        setup.getMgmtSvc().updateOrganization( organization );
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( "ed@anuff.com" );
+//
+//        Map<String, String> payload = hashMap( "oldpassword", passwords[0] ).map( "newpassword", passwords[0] ); // fail
+//
+//        try {
+//            JsonNode node = mapper.readTree( resource().path( "/management/users/edanuff/password" )
+//                                                       .accept( MediaType.APPLICATION_JSON )
+//                                                       .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
+//            fail( "should fail with conflict" );
+//        }
+//        catch ( UniformInterfaceException e ) {
+//            assertEquals( 409, e.getResponse().getStatus() );
+//        }
+//
+//        payload.put( "newpassword", passwords[1] ); // ok
+//        JsonNode node = mapper.readTree( resource().path( "/management/users/edanuff/password" )
+//                                                   .accept( MediaType.APPLICATION_JSON )
+//                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
+//        payload.put( "oldpassword", passwords[1] );
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        payload.put( "newpassword", passwords[0] ); // fail
+//        try {
+//            node = mapper.readTree( resource().path( "/management/users/edanuff/password" )
+//                                              .accept( MediaType.APPLICATION_JSON )
+//                                              .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
+//            fail( "should fail with conflict" );
+//        }
+//        catch ( UniformInterfaceException e ) {
+//            assertEquals( 409, e.getResponse().getStatus() );
+//        }
+//    }
+//
+//
+//    @Test
+//    public void checkPasswordChangeTime() throws Exception {
+//
+//        final TestUser user = context.getActiveUser();
+//        String email = user.getEmail();
+//        UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email );
+//        String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 );
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        Form formData = new Form();
+//        formData.add( "token", resetToken );
+//        formData.add( "password1", "sesame" );
+//        formData.add( "password2", "sesame" );
+//
+//        String html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" )
+//                                .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData );
+//        assertTrue( html.contains( "password set" ) );
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        JsonNode node = mapper.readTree( resource().path( "/management/token" )
+//                                                   .queryParam( "grant_type", "password" )
+//                                                   .queryParam( "username", email ).queryParam( "password", "sesame" )
+//                                                   .accept( MediaType.APPLICATION_JSON )
+//                                                   .get( String.class ));
+//
+//        Long changeTime = node.get( "passwordChanged" ).longValue();
+//        assertTrue( System.currentTimeMillis() - changeTime < 2000 );
+//
+//        Map<String, String> payload = hashMap( "oldpassword", "sesame" ).map( "newpassword", "test" );
+//        node = mapper.readTree( resource().path( "/management/users/" + userInfo.getUsername() + "/password" )
+//                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+//                                          .post( String.class, payload ));
+//
+//        refreshIndex(context.getOrgName(), context.getAppName());
+//
+//        node = mapper.readTree( resource().path( "/management/token" )
+//                                          .queryParam( "grant_type", "password" )
+//                                          .queryParam( "username", email )
+//                                          .queryParam( "password", "test" )
+//                                          .accept( MediaType.APPLICATION_JSON )
+//                                          .get( String.class ));
+//
+//        Long changeTime2 = node.get( "passwordChanged" ).longValue();
+//        assertTrue( changeTime < changeTime2 );
+//        assertTrue( System.currentTimeMillis() - changeTime2 < 2000 );
+//
+//        node = mapper.readTree( resource().path( "/management/me" ).queryParam( "grant_type", "password" )
+//                                          .queryParam( "username", email ).queryParam( "password", "test" ).accept( MediaType.APPLICATION_JSON )
+//                                          .get( String.class ));
+//
+//        Long changeTime3 = node.get( "passwordChanged" ).longValue();
+//        assertEquals( changeTime2, changeTime3 );
+//    }
+//
+//
+//    /** 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 ) {
+//        }
     }
 
 }


[5/8] incubator-usergrid git commit: did some cleanup on commented out code. Commented back in a couple more of the tests that need updating.

Posted by gr...@apache.org.
did some cleanup on commented out code. Commented back in a couple more of the tests that need updating.


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

Branch: refs/heads/USERGRID-280
Commit: 0e17c53d7d8e7a8ee30b953a6b183d0f71c03de9
Parents: cbbb8bf
Author: grey <gr...@apigee.com>
Authored: Tue Jan 13 10:01:55 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Tue Jan 13 10:01:55 2015 -0800

----------------------------------------------------------------------
 .../usergrid/rest/management/AdminUsersIT.java  | 85 ++++++++++----------
 .../endpoints/mgmt/UsersResource.java           |  1 -
 2 files changed, 43 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0e17c53d/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 e576a6d..d9a250d 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
@@ -137,8 +137,6 @@ public class AdminUsersIT extends AbstractRestIT {
     @Test
     public void passwordMismatchErrorAdmin() {
 
-
-
         String username = clientSetup.getUsername();
         String password = clientSetup.getPassword();
 
@@ -149,10 +147,6 @@ public class AdminUsersIT extends AbstractRestIT {
 
         // change the password as admin. The old password isn't required
         management.users().user( username ).password().post( passwordPayload );
-//        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
-//                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, passwordPayload ));
-
-
 
         this.refreshIndex();
 
@@ -171,45 +165,52 @@ public class AdminUsersIT extends AbstractRestIT {
         }
 
     }
-//
-//
-//    /**
-//     * Checks that as a superuser (i.e with a superuser token ) we can change the password of a admin.
-//     * @throws IOException
-//     */
-//    @Test
-//    public void setAdminPasswordAsSysAdmin() throws IOException {
-//
-//        String superToken = superAdminToken();
-//
-//        String newPassword = "foo";
-//
-//        Map<String, String> data = new HashMap<String, String>();
-//        data.put( "newpassword", newPassword );
-//
-//        // change the password as admin. The old password isn't required
+
+
+    /**
+     * Checks that as a superuser (i.e with a superuser token ) we can change the password of a admin.
+     * @throws IOException
+     */
+    @Test
+    public void setAdminPasswordAsSysAdmin() throws IOException {
+
+        String username = clientSetup.getUsername();
+        String password = clientSetup.getPassword();
+
+        String superToken = superAdminToken();
+
+        String newPassword = "foo";
+
+        Map<String, Object> passwordPayload = new HashMap<String, Object>();
+        data.put( "newpassword", newPassword );
+
+
+        // change the password as admin. The old password isn't required
+        management.users().user( username ).password().post( passwordPayload );
+
+
 //        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken )
 //                                                   .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
 //                                                   .post( String.class, data ));
-//
-//        assertNull( getError( node ) );
-//
-//        refreshIndex("test-organization", "test-app");
-//
-//        // log in with the new password
-//        String token = mgmtToken( "test", newPassword );
-//
-//        assertNotNull( token );
-//
-//        data.put( "newpassword", "test" );
-//
-//        // now change the password back
-//        node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken )
-//                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-//                                          .post( String.class, data ));
-//
-//        assertNull( getError( node ) );
-//    }
+
+        assertNull( getError( node ) );
+
+        refreshIndex();
+
+        // log in with the new password
+        String token = mgmtToken( "test", newPassword );
+
+        assertNotNull( token );
+
+        data.put( "newpassword", "test" );
+
+        // now change the password back
+        node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken )
+                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                                          .post( String.class, data ));
+
+        assertNull( getError( node ) );
+    }
 //
 //    @Test
 //    public void mgmtUserFeed() throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0e17c53d/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 7a9e5dd..b71247c 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
@@ -54,7 +54,6 @@ public class UsersResource extends NamedResource {
         return new UserResource( identifier, context, this );
     }
 
-
     public Entity post(Entity userPayload){
         WebResource resource = getResource(true);
 //TODO: need to parse the specific response gotten for admin entities. It is different from regular entities.


[3/8] incubator-usergrid git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-280

Posted by gr...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-280

# By grey (16) and others
# Via grey (8) and others
* 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid: (24 commits)
  added apache header to editor config
  Ignore known failing test
  Added fix for entity class and array list casting.
  Simplified the setup of some of the tests
  Cleanup the imports and add an actual loop in the connection loopback test.
  Added todo for final commit for fix.
  Revert "Made the styles path relative so they will no longer go to the root and get 401 errors."
  Added in a bunch of comments to clarify what was going on in PermissionsResourceIT
  Added missing comment to tests in OwnershipResourceIT Added revamped comments and cleaned the tests in ConnectionResourceTest
  Finished adding comments for OwnershipResourceIT
  Added a comment clearing what the token post method accomplishes. Adding clarifying comments to meVerify, contextualPathOwnership, and contextualConnectionOwnership test.
  Fixes and comments while looking over the tests
  Cleared up and added some comments to the tests in organizationIt Added comment to one of the methods in AbstractRestIt.
  Added comments to configuration options. removed 'root' declaration
  Adding editorconfig settings file to help with consistent formatting
  Cleanup of imports and spaces. Fixed OrganizationsIT and added comments. Added users to the end of ManagementResource to emulate AdminUser calls. Added put to organizationResource so we can update organizations. Added Additional case to entities that puts any data from a entity into the entity itself. Added ability to get Organization properties without needing to go through dynamic properties. Removed cruft from ClientContext.
  fixed null ref issues
  finished test
  fix resourse test
  fixing ownershipResourceIT
  ...

Conflicts:
	stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java


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

Branch: refs/heads/USERGRID-280
Commit: 21cdfe1a96bad971eba9e8e102e23ef8c4f0d8a7
Parents: 17c439b bcabda2
Author: grey <gr...@apigee.com>
Authored: Mon Jan 12 12:22:58 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Mon Jan 12 12:22:58 2015 -0800

----------------------------------------------------------------------
 stack/.editorconfig                             |  16 +
 .../collection/groups/GroupResourceIT.java      |   6 +-
 .../users/ConnectionResourceTest.java           | 282 ++++----
 .../collection/users/OwnershipResourceIT.java   | 424 ++++++-----
 .../collection/users/PermissionsResourceIT.java | 723 +++++++------------
 .../rest/management/OrganizationsIT.java        | 353 ++++-----
 .../test/resource2point0/AbstractRestIT.java    |  11 +-
 .../rest/test/resource2point0/ClientSetup.java  |   1 +
 .../rest/test/resource2point0/RestClient.java   |   1 -
 .../endpoints/TokenResource.java                |   2 +-
 .../endpoints/mgmt/ManagementResource.java      |   4 +
 .../endpoints/mgmt/OrganizationResource.java    |  13 +
 .../endpoints/mgmt/UsersResource.java           |  61 ++
 .../rest/test/resource2point0/model/Entity.java |  33 +-
 .../resource2point0/model/Organization.java     |   3 +
 .../resource2point0/state/ClientContext.java    |  21 -
 16 files changed, 954 insertions(+), 1000 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/21cdfe1a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
----------------------------------------------------------------------
diff --cc stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
index 1ec767f,f564eab..91dbb16
--- 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
@@@ -41,7 -41,8 +41,8 @@@ import javax.ws.rs.core.MediaType
  public class ClientSetup implements TestRule {
  
      RestClient restClient;
 -    //TODO: store the password as a string here as well
 -    protected String username, orgName, appName;
++
 +    protected String username, password,orgName, appName;
      protected Organization organization;
      protected Application application;
  


[7/8] incubator-usergrid git commit: Fixed another test that uses the superuser token, and added a different endpoint to facilitate using the superuser token or the default endpoint.

Posted by gr...@apache.org.
Fixed another test that uses the superuser token, and added a different endpoint to facilitate using the superuser token or the default endpoint.


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

Branch: refs/heads/USERGRID-280
Commit: ff7b1a4a4e244310152ba698334a6e568b351e9d
Parents: 760a09c
Author: grey <gr...@apigee.com>
Authored: Tue Feb 3 15:56:08 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Tue Feb 3 15:56:08 2015 -0800

----------------------------------------------------------------------
 .../usergrid/rest/management/AdminUsersIT.java  | 34 ++++++++------------
 .../rest/test/resource2point0/ClientSetup.java  | 14 ++++++--
 .../endpoints/mgmt/PasswordResource.java        | 17 ++++++++--
 3 files changed, 38 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ff7b1a4a/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 d9a250d..c5ca4d5 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
@@ -177,39 +177,31 @@ public class AdminUsersIT extends AbstractRestIT {
         String username = clientSetup.getUsername();
         String password = clientSetup.getPassword();
 
-        String superToken = superAdminToken();
-
-        String newPassword = "foo";
 
         Map<String, Object> passwordPayload = new HashMap<String, Object>();
-        data.put( "newpassword", newPassword );
+        passwordPayload.put( "newpassword", "testPassword" );
 
 
         // change the password as admin. The old password isn't required
-        management.users().user( username ).password().post( passwordPayload );
+        //management.users().user( username ).password().
 
+        management.users().user( username ).password().post( clientSetup.getSuperuserToken(), passwordPayload );
+
+        this.refreshIndex();
 
 //        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken )
 //                                                   .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
 //                                                   .post( String.class, data ));
 
-        assertNull( getError( node ) );
-
-        refreshIndex();
-
-        // log in with the new password
-        String token = mgmtToken( "test", newPassword );
-
-        assertNotNull( token );
-
-        data.put( "newpassword", "test" );
+        assertNotNull( management.token().post( new Token( username, "testPassword" ) ) );
 
-        // now change the password back
-        node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken )
-                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                                          .post( String.class, data ));
-
-        assertNull( getError( node ) );
+        //Check that we cannot get the token using the old password
+        try {
+            management.token().post( new Token( username, password ) );
+            fail( "We shouldn't be able to get a token using the old password" );
+        }catch(UniformInterfaceException uie) {
+            errorParse( 400,"invalid_grant",uie );
+        }
     }
 //
 //    @Test

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ff7b1a4a/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 45c9976..819cd85 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
@@ -42,7 +42,12 @@ public class ClientSetup implements TestRule {
 
     RestClient restClient;
 
-    protected String username, password,orgName, appName, superuserToken;
+    protected String username;
+    protected String password;
+    protected String orgName;
+    protected String appName;
+    protected Token superuserToken;
+
     protected Organization organization;
     protected Application application;
 
@@ -84,8 +89,7 @@ public class ClientSetup implements TestRule {
         String name = testClass + "." + methodName;
 
         restClient.superuserSetup();
-        Token superuserResponse = restClient.management().token().post( new Token("superuser","superpassword") );
-        superuserToken=superuserResponse.getAccessToken();
+        superuserToken = restClient.management().token().post( new Token( "superuser", "superpassword" ) );
 
         username = "user_"+name + UUIDUtils.newTimeUUID();
         password = username;
@@ -110,6 +114,10 @@ public class ClientSetup implements TestRule {
 
     public String getAppName() {return appName;}
 
+    public Token getSuperuserToken() {
+        return superuserToken;
+    }
+
     public void refreshIndex() {
         this.restClient.refreshIndex(getOrganizationName(),getAppName());
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ff7b1a4a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java
index 779e057..c901022 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java
@@ -25,6 +25,7 @@ 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.Token;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 
 import com.sun.jersey.api.client.WebResource;
@@ -41,10 +42,20 @@ public class PasswordResource extends NamedResource {
         super( "password", context, parent );
     }
 
-    public Entity post(Map<String, Object> payload){
-        WebResource resource = getResource(true);
+    public Entity post(Token token, Map<String,Object> payload){
+        WebResource resource;
+
+        if(token != null) {
+            resource = getResource( true, token );
+        }
+        else
+            resource = getResource( true );
 
         return resource.type( MediaType.APPLICATION_JSON_TYPE )
-                                       .accept( MediaType.APPLICATION_JSON ).post( Entity.class, payload );
+                       .accept( MediaType.APPLICATION_JSON ).post( Entity.class, payload );
+    }
+
+    public Entity post(Map<String, Object> payload){
+        return post( null, payload );
     }
 }


[8/8] incubator-usergrid git commit: Added test for user feeds and started testCaseSensitivity test.

Posted by gr...@apache.org.
Added test for user feeds and started testCaseSensitivity 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/0b5f598f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0b5f598f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0b5f598f

Branch: refs/heads/USERGRID-280
Commit: 0b5f598fb8f934735aba7a9d52372a47e714911a
Parents: ff7b1a4
Author: grey <gr...@apigee.com>
Authored: Thu Feb 5 07:55:40 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Thu Feb 5 07:55:40 2015 -0800

----------------------------------------------------------------------
 .../usergrid/rest/management/AdminUsersIT.java  | 79 +++++++++++++-------
 .../endpoints/mgmt/FeedResource.java            | 48 ++++++++++++
 .../endpoints/mgmt/OrganizationResource.java    |  4 +-
 .../endpoints/mgmt/UserResource.java            | 16 ++++
 .../endpoints/mgmt/UsersResource.java           |  2 +-
 5 files changed, 117 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b5f598f/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 c5ca4d5..005c4ad 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
@@ -22,7 +22,9 @@ 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;
 
@@ -177,22 +179,16 @@ public class AdminUsersIT extends AbstractRestIT {
         String username = clientSetup.getUsername();
         String password = clientSetup.getPassword();
 
-
+        // change the password as admin. The old password isn't required
         Map<String, Object> passwordPayload = new HashMap<String, Object>();
         passwordPayload.put( "newpassword", "testPassword" );
 
 
-        // change the password as admin. The old password isn't required
-        //management.users().user( username ).password().
 
         management.users().user( username ).password().post( clientSetup.getSuperuserToken(), passwordPayload );
 
         this.refreshIndex();
 
-//        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken )
-//                                                   .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-//                                                   .post( String.class, data ));
-
         assertNotNull( management.token().post( new Token( username, "testPassword" ) ) );
 
         //Check that we cannot get the token using the old password
@@ -203,23 +199,50 @@ public class AdminUsersIT extends AbstractRestIT {
             errorParse( 400,"invalid_grant",uie );
         }
     }
-//
-//    @Test
-//    public void mgmtUserFeed() throws Exception {
-//        JsonNode userdata = mapper.readTree( resource().path( "/management/users/test@usergrid.com/feed" )
-//                                                       .queryParam( "access_token", adminAccessToken )
-//                                                       .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-//        assertTrue( StringUtils.contains( this.getEntity( userdata, 0 ).get( "title" ).asText(),
-//                "<a href=\"mailto:test@usergrid.com\">" ) );
-//    }
-//
-//    //everything below is MUUserResourceIT
-//
-//    @Test
-//    public void testCaseSensitivityAdminUser() throws Exception {
-//
-//        LOG.info( "Starting testCaseSensitivityAdminUser()" );
-//
+
+
+    /**
+     * Get the management user feed and check that it has the correct title.
+     * @throws Exception
+     */
+    @Test
+    public void mgmtUserFeed() throws Exception {
+
+        Entity mgmtUserFeedEntity = management.users().user( clientSetup.getUsername() ).feed().get();
+        String correctValue= "<a href=mailto:"+clientSetup.getUsername();  //user_org.apache.usergrid.rest.management.AdminUsersIT.mgmtUserFeed4c3e53e0-acc7-11e4-b527-0b8af3c5813f@usergrid.com">user_org.apache.usergrid.rest.management.AdminUsersIT.mgmtUserFeed4c3e53e0-acc7-11e4-b527-0b8af3c5813f (user_org.apache.usergrid.rest.management.AdminUsersIT.mgmtUserFeed4c3e53e0-acc7-11e4-b527-0b8af3c5813f@usergrid.com)</a> created a new organization account named org_org.apache.usergrid.rest.management.AdminUsersIT.mgmtUserFeed4c3ec910-acc7-11e4-94c8-33f0d48a5559
+
+        assertNotNull( mgmtUserFeedEntity );
+
+        ArrayList<Map<String,Object>> feedEntityMap = ( ArrayList ) mgmtUserFeedEntity.get( "entities" );
+        assertNotNull( feedEntityMap );
+        assertNotNull( feedEntityMap.get( 0 ).get( "title" )  );
+
+    }
+
+    //everything below is MUUserResourceIT
+
+    @Test
+    public void testCaseSensitivityAdminUser() throws Exception {
+
+        //Create adminUser values
+        Entity adminUserPayload = new Entity();
+        String username = "testCaseSensitivityAdminUser"+ org.apache.usergrid.persistence.index.utils
+            .UUIDUtils
+            .newTimeUUID();
+        adminUserPayload.put( "username", username );
+        adminUserPayload.put( "name", username );
+        adminUserPayload.put( "email", username+"@usergrid.com" );
+        adminUserPayload.put( "password", username );
+
+        //create adminUser
+        //Entity adminUserResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() ).users().post( adminUserPayload );
+        management.users().post( adminUserPayload );
+
+        refreshIndex();
+
+        Entity adminUserResponse = management.users().user( username.toLowerCase() ).get();
+        assertNotNull( adminUserResponse );
+
 //        UserInfo mixcaseUser = setup.getMgmtSvc()
 //                                    .createAdminUser( "AKarasulu", "Alex Karasulu", "AKarasulu@Apache.org", "test", true, false );
 //
@@ -233,15 +256,15 @@ public class AdminUsersIT extends AbstractRestIT {
 //        refreshIndex(context.getOrgName(), context.getAppName());
 //
 //        String tokenStr = mgmtToken( "akarasulu@apache.org", "test" );
-//
-//        // Should succeed even when we use all lowercase
+
+        // Should succeed even when we use all lowercase
 //        JsonNode node = mapper.readTree( resource().path( "/management/users/akarasulu@apache.org" )
 //                                                   .queryParam( "access_token", tokenStr )
 //                                                   .accept( MediaType.APPLICATION_JSON )
 //                                                   .type( MediaType.APPLICATION_JSON_TYPE )
 //                                                   .get( String.class ));
-//        logNode( node );
-//    }
+
+    }
 //
 //
 //    @Test

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b5f598f/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/FeedResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/FeedResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/FeedResource.java
new file mode 100644
index 0000000..5b95aa5
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/FeedResource.java
@@ -0,0 +1,48 @@
+/*
+ *
+ *  * 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 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.state.ClientContext;
+
+
+/**
+ * Contains the REST methods to interacting with the ManagementEndpoints
+ * and the user feeds
+ */
+public class FeedResource extends NamedResource {
+    public FeedResource(final ClientContext context, final UrlResource parent) {
+        super ( "feed",context, parent);
+    }
+
+    public Entity get() {
+        return getResource( true ).type( MediaType.APPLICATION_JSON_TYPE )
+            .accept( MediaType.APPLICATION_JSON ).get( Entity.class);
+
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b5f598f/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 a436358..dbc4ad5 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
@@ -25,8 +25,6 @@ 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.model.Token;
-import org.apache.usergrid.rest.test.resource2point0.model.User;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 
 
@@ -74,7 +72,7 @@ public class OrganizationResource extends NamedResource {
                         organization );
 
     }
-    
+
     public ApplicationResource app(){
         return new ApplicationResource(  context ,this );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b5f598f/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 c5a823e..1adcd83 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
@@ -16,10 +16,16 @@
  */
 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.state.ClientContext;
 
+import com.sun.jersey.api.client.WebResource;
+
 
 /**
  * Relations to the following endpoint
@@ -36,4 +42,14 @@ public class UserResource extends NamedResource {
         return new PasswordResource( context, this );
     }
 
+    public FeedResource feed() {
+        return new FeedResource( context, this );
+    }
+
+    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);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b5f598f/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 b71247c..a273c58 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
@@ -56,7 +56,7 @@ public class UsersResource extends NamedResource {
 
     public Entity post(Entity userPayload){
         WebResource resource = getResource(true);
-//TODO: need to parse the specific response gotten for admin entities. It is different from regular entities.
+
         ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE )
                 .accept( MediaType.APPLICATION_JSON ).post( ApiResponse.class, userPayload);
         return new Entity(response);


[6/8] incubator-usergrid git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-280

Posted by gr...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-280

# By Shawn Feldman (13) and others
# Via Rod Simpson (4) and others
* 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid: (29 commits)
  Use example URL instead
  fix authentication workflow
  fixed double slash bug in data explorer in admin portal
  remove lexer
  Revert "remove lexer"
  remove lexer
  compile issue...
  add valid notification types
  add illegal argument type
  add default case to factory
  remove sln file
  moving files to own dir
  push sample
  roles/role fix
  Working windows phone toasts
  added apache lic header
  Beginnings of a REST test.
  Addition of emf.deleteApplicaton() method and  a test for it in EntityManagerFacotryImplIT.
  Addition of deleteIndex() method, improvements to logging and minor formatting changes.
  add initial windows adapter
  ...


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

Branch: refs/heads/USERGRID-280
Commit: 760a09c7235e529387e3fed96ff5b43cadd25b55
Parents: 0e17c53 198f479
Author: grey <gr...@apigee.com>
Authored: Tue Feb 3 14:33:00 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Tue Feb 3 14:33:00 2015 -0800

----------------------------------------------------------------------
 .gitignore                                      |   4 +-
 portal/js/global/ug-service.js                  |  72 +--
 portal/js/push/push-config-controller.js        |  18 +-
 portal/js/push/push-config.html                 |  50 ++
 .../Usergrid.Notifications/App.xaml             |  27 +
 .../Usergrid.Notifications/App.xaml.cs          | 150 ++++++
 .../Assets/Logo.scale-240.png                   | Bin 0 -> 2516 bytes
 .../Assets/SmallLogo.scale-240.png              | Bin 0 -> 753 bytes
 .../Assets/SplashScreen.scale-240.png           | Bin 0 -> 14715 bytes
 .../Assets/Square71x71Logo.scale-240.png        | Bin 0 -> 1122 bytes
 .../Assets/StoreLogo.scale-240.png              | Bin 0 -> 2200 bytes
 .../Assets/WideLogo.scale-240.png               | Bin 0 -> 4530 bytes
 .../Client/EntityResponse.cs                    |  80 +++
 .../Client/IUsergridClient.cs                   | 123 +++++
 .../Usergrid.Notifications/Client/PushClient.cs | 155 ++++++
 .../Usergrid.Notifications/Client/Usergrid.cs   | 122 +++++
 .../Usergrid.Notifications/MainPage.xaml        |  38 ++
 .../Usergrid.Notifications/MainPage.xaml.cs     | 124 +++++
 .../Package.StoreAssociation.xml                | 194 +++++++
 .../Usergrid.Notifications/Package.appxmanifest |  53 ++
 .../Properties/AssemblyInfo.cs                  |  29 +
 .../Usergrid.Notifications.csproj               | 142 +++++
 .../Usergrid.Notifications/packages.config      |  25 +
 .../notifications/packages/repositories.config  |   4 +
 .../corepersistence/CpEntityManagerFactory.java |  56 +-
 .../HybridEntityManagerFactory.java             |   9 +-
 .../persistence/EntityManagerFactory.java       |  11 +-
 .../cassandra/EntityManagerFactoryImpl.java     |  11 +-
 .../usergrid/persistence/entities/Notifier.java |  31 +-
 .../cassandra/EntityManagerFactoryImplIT.java   |  71 ++-
 .../usergrid/persistence/index/EntityIndex.java |   2 +
 .../index/impl/EsEntityIndexBatchImpl.java      |  14 +-
 .../index/impl/EsEntityIndexImpl.java           | 115 ++--
 .../persistence/index/impl/EsIndexCache.java    |  12 +-
 .../persistence/queue/impl/QueueScopeImpl.java  |   4 -
 .../rest/applications/ApplicationResource.java  |  32 +-
 .../apache/usergrid/rest/PartialUpdateTest.java | 170 +++---
 .../applications/ApplicationDeleteTest.java     |  54 ++
 .../collection/groups/GroupResourceIT.java      |   2 +-
 .../applications/queries/AndOrQueryTest.java    | 528 ++++++++++---------
 .../queries/BadGrammarQueryTest.java            | 213 ++++++--
 .../applications/queries/GeoPagingTest.java     |   2 +-
 .../rest/applications/queries/OrderByTest.java  | 447 +++++++++++-----
 .../applications/queries/QueryTestBase.java     |  72 +++
 .../endpoints/CollectionEndpoint.java           |   2 +-
 stack/services/pom.xml                          |   7 +-
 .../notifications/ProviderAdapterFactory.java   |   5 +
 .../impl/ApplicationQueueManagerImpl.java       |   8 +-
 .../wns/TranslatedNotification.java             |  50 ++
 .../services/notifications/wns/WNSAdapter.java  | 163 ++++++
 50 files changed, 2806 insertions(+), 695 deletions(-)
----------------------------------------------------------------------



[4/8] incubator-usergrid git commit: Added admin user tests and also added in User and Password Resources to extend the rest test framework. Added additional string to keep track of the superuserToken. Added httpBasicAuthFilter so we can login and setup

Posted by gr...@apache.org.
Added admin user tests and also added in User and Password Resources to extend the rest test framework.
Added additional string to keep track of the superuserToken.
Added httpBasicAuthFilter so we can login and setup superadmin user.
Added superuser properties to the rest test properties.


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

Branch: refs/heads/USERGRID-280
Commit: cbbb8bf8f824b1ab86bdf76eb5c164e9545aa109
Parents: 21cdfe1
Author: grey <gr...@apigee.com>
Authored: Mon Jan 12 16:58:35 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Mon Jan 12 16:58:35 2015 -0800

----------------------------------------------------------------------
 .../usergrid/rest/management/AdminUsersIT.java  | 145 +++++++++----------
 .../rest/test/resource2point0/ClientSetup.java  |   6 +-
 .../rest/test/resource2point0/RestClient.java   |  11 ++
 .../endpoints/mgmt/PasswordResource.java        |  50 +++++++
 .../endpoints/mgmt/UserResource.java            |  39 +++++
 .../endpoints/mgmt/UsersResource.java           |   5 +
 .../resources/usergrid-custom-test.properties   |  10 +-
 7 files changed, 189 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/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 1db0aa3..e576a6d 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
@@ -54,6 +54,7 @@ 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.Entity;
 import org.apache.usergrid.rest.test.resource2point0.model.Token;
 import org.apache.usergrid.rest.test.resource2point0.model.User;
 import org.apache.usergrid.rest.test.security.TestAdminUser;
@@ -97,81 +98,79 @@ public class AdminUsersIT extends AbstractRestIT {
     /**
      * Test if we can reset an admin's password by using that same admins credentials.
      */
-//    @Test
-//    public void setSelfAdminPasswordAsAdmin() throws IOException {
-//
-//        String username = clientSetup.getUsername();
-//        String password = clientSetup.getPassword();
-//
-//
-//        Map<String, String> passwordPayload = new HashMap<String, String>();
-//        passwordPayload.put( "newpassword", "testPassword" );
-//        passwordPayload.put( "oldpassword", password );
-//
-//        // change the password as admin. The old password isn't required
-//        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
-//                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, passwordPayload ));
-//
-//
-//
-//        this.refreshIndex();
-//
-//
-//        assertNull( getError( node ) );
-//
-//        //Get the token using the new password
-//        Token tokenPayload = this.app().token().post(new Token(username, "testPassword"));
-//
-//        //Check that we cannot get the token using the old password
-//        try {
-//            this.app().token().post( new Token( username, password ) );
-//            fail( "We shouldn't be able to get a token using the old password" );
-//        }catch(UniformInterfaceException uie) {
-//            errorParse( 500,"BadPeople",uie );
-//        }
-//    }
-//
-//
-//    /**
-//     * Check that we cannot change the password by using an older password
-//     */
-//    @Test
-//    public void passwordMismatchErrorAdmin() {
-//
-//
-//
-//        String username = clientSetup.getUsername();
-//        String password = clientSetup.getPassword();
-//
-//
-//        Map<String, String> passwordPayload = new HashMap<String, String>();
-//        passwordPayload.put( "newpassword", "testPassword" );
-//        passwordPayload.put( "oldpassword", password );
-//
-//        // change the password as admin. The old password isn't required
+    @Test
+    public void setSelfAdminPasswordAsAdmin() throws IOException {
+
+        String username = clientSetup.getUsername();
+        String password = clientSetup.getPassword();
+
+
+        Map<String, Object> passwordPayload = new HashMap<String, Object>();
+        passwordPayload.put( "newpassword", "testPassword" );
+        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;
+
+        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 {
+            management.token().post( new Token( username, password ) );
+            fail( "We shouldn't be able to get a token using the old password" );
+        }catch(UniformInterfaceException uie) {
+            errorParse( 400,"invalid_grant",uie );
+        }
+    }
+
+
+    /**
+     * Check that we cannot change the password by using an older password
+     */
+    @Test
+    public void passwordMismatchErrorAdmin() {
+
+
+
+        String username = clientSetup.getUsername();
+        String password = clientSetup.getPassword();
+
+
+        Map<String, Object> passwordPayload = new HashMap<String, Object>();
+        passwordPayload.put( "newpassword", "testPassword" );
+        passwordPayload.put( "oldpassword", password );
+
+        // change the password as admin. The old password isn't required
+        management.users().user( username ).password().post( passwordPayload );
 //        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
 //                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, passwordPayload ));
-//
-//
-//
-//        this.refreshIndex();
-//
-//
-//        //Get the token using the new password
-//        Token tokenPayload = this.app().token().post(new Token(username, "testPassword"));
-//
-//
-//        // Check that we can't change the password using the old password.
-//        try {
-//            resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
-//                      .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, passwordPayload );
-//            fail("We shouldn't be able to change the password with the same payload");
-//        }
-//        catch ( UniformInterfaceException uie ) {
-//            errorParse( ClientResponse.Status.BAD_REQUEST.getStatusCode(),ClientResponse.Status.BAD_REQUEST.getReasonPhrase(),uie );
-//        }
-//
-//    }
+
+
+
+        this.refreshIndex();
+
+
+        //Get the token using the new password
+        management.token().post( new Token( username, "testPassword" ) );
+
+
+        // Check that we can't change the password using the old password.
+        try {
+            management.users().user( username ).password().post( passwordPayload );
+            fail("We shouldn't be able to change the password with the same payload");
+        }
+        catch ( UniformInterfaceException uie ) {
+            errorParse( ClientResponse.Status.BAD_REQUEST.getStatusCode(),"auth_invalid_username_or_password",uie );
+        }
+
+    }
 //
 //
 //    /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/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 91dbb16..45c9976 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
@@ -42,7 +42,7 @@ public class ClientSetup implements TestRule {
 
     RestClient restClient;
 
-    protected String username, password,orgName, appName;
+    protected String username, password,orgName, appName, superuserToken;
     protected Organization organization;
     protected Application application;
 
@@ -83,7 +83,9 @@ public class ClientSetup implements TestRule {
         String methodName = description.getMethodName();
         String name = testClass + "." + methodName;
 
-        Token test = restClient.management().token().post( new Token("superuser","superpassword") );
+        restClient.superuserSetup();
+        Token superuserResponse = restClient.management().token().post( new Token("superuser","superpassword") );
+        superuserToken=superuserResponse.getAccessToken();
 
         username = "user_"+name + UUIDUtils.newTimeUUID();
         password = username;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/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 ebd1e35..9349ae6 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
@@ -22,10 +22,12 @@ import org.apache.usergrid.rest.test.resource2point0.endpoints.OrganizationResou
 import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 
+import com.fasterxml.jackson.databind.JsonNode;
 import com.sun.jersey.api.client.Client;
 import com.sun.jersey.api.client.WebResource;
 import com.sun.jersey.api.client.config.ClientConfig;
 import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
 
 import javax.ws.rs.core.MediaType;
 
@@ -99,6 +101,15 @@ public class RestClient implements UrlResource {
                 .accept( MediaType.APPLICATION_JSON ).post();
     }
 
+    public void superuserSetup() {
+        //TODO: change this when we upgrade to new version of jersey
+        HTTPBasicAuthFilter httpBasicAuthFilter = new HTTPBasicAuthFilter( "superuser","superpassword" );
+        client.addFilter( httpBasicAuthFilter );
+
+        this.getResource().path( "system/superuser/setup" )
+            .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON ).get( JsonNode.class );
+    }
+
     //todo:fix this method for the client.
 //    public void loginAdminUser( final String username, final String password ) {
 //        //Post isn't implemented yet, but using the method below we should be able to get a superuser password as well.

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java
new file mode 100644
index 0000000..779e057
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.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 java.util.Map;
+
+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.state.ClientContext;
+
+import com.sun.jersey.api.client.WebResource;
+
+
+/**
+ * Relations to the following endpoint
+ * /management/users/"username"/password
+ * Allows admin users to change their passwords
+ */
+public class PasswordResource extends NamedResource {
+
+    public PasswordResource( final ClientContext context, final UrlResource parent ) {
+        super( "password", context, parent );
+    }
+
+    public Entity post(Map<String, Object> payload){
+        WebResource resource = getResource(true);
+
+        return resource.type( MediaType.APPLICATION_JSON_TYPE )
+                                       .accept( MediaType.APPLICATION_JSON ).post( Entity.class, payload );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/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
new file mode 100644
index 0000000..c5a823e
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+
+
+/**
+ * Relations to the following endpoint
+ * /management/users/"username"
+ * Store endpoints relating to specific users
+ */
+public class UserResource extends NamedResource {
+
+    public UserResource( final String name, final ClientContext context, final UrlResource parent ) {
+        super( name, context, parent );
+    }
+
+    public PasswordResource password() {
+        return new PasswordResource( context, this );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/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 df3f3c1..7a9e5dd 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
@@ -50,6 +50,11 @@ public class UsersResource extends NamedResource {
         return new EntityEndpoint(identifier, context, this);
     }
 
+    public UserResource user(String identifier) {
+        return new UserResource( identifier, context, this );
+    }
+
+
     public Entity post(Entity userPayload){
         WebResource resource = getResource(true);
 //TODO: need to parse the specific response gotten for admin entities. It is different from regular entities.

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/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 d9688c4..58cb831 100644
--- a/stack/rest/src/test/resources/usergrid-custom-test.properties
+++ b/stack/rest/src/test/resources/usergrid-custom-test.properties
@@ -12,8 +12,8 @@
 
 # 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) 
+# 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
 
@@ -38,3 +38,9 @@ usergrid.counter.batch.size=1
 swagger.basepath=http://sometestvalue
 
 usergrid.notifications.listener.run=false
+
+usergrid.sysadmin.login.name=superuser
+usergrid.sysadmin.login.email=superuser@usergrid.com
+usergrid.sysadmin.login.password=superpassword
+usergrid.sysadmin.login.allowed=true
+


[2/8] incubator-usergrid git commit: Adding some test outlines for admin users tests. Also added in a password and a non working call in the before that shows we can't get the super user.

Posted by gr...@apache.org.
Adding some test outlines for admin users tests. Also added in a password and a non working call in the before that shows we can't get the super user.


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

Branch: refs/heads/USERGRID-280
Commit: 17c439b21bec1efc77ef0635a7ac135dad78990d
Parents: 0f893ff
Author: grey <gr...@apigee.com>
Authored: Fri Jan 9 13:35:47 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Fri Jan 9 13:35:47 2015 -0800

----------------------------------------------------------------------
 .../usergrid/rest/management/AdminUsersIT.java  | 113 +++++++++++--------
 .../rest/test/resource2point0/ClientSetup.java  |   7 +-
 2 files changed, 75 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/17c439b2/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 271c013..1db0aa3 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
@@ -54,6 +54,8 @@ 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.Token;
+import org.apache.usergrid.rest.test.resource2point0.model.User;
 import org.apache.usergrid.rest.test.security.TestAdminUser;
 import org.apache.usergrid.rest.test.security.TestUser;
 import org.apache.usergrid.security.AuthPrincipalInfo;
@@ -61,6 +63,7 @@ import org.apache.usergrid.security.AuthPrincipalType;
 import org.apache.usergrid.utils.UUIDUtils;
 
 import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.deploy.util.SessionState;
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.client.UniformInterfaceException;
 import com.sun.jersey.api.representation.Form;
@@ -92,67 +95,89 @@ public class AdminUsersIT extends AbstractRestIT {
     }
 
     /**
-     * Test if we can reset our password as an admin
+     * Test if we can reset an admin's password by using that same admins credentials.
      */
-    @Test
-    public void setSelfAdminPasswordAsAdmin() throws IOException {
-
-        String newPassword = "foo";
-
-        Map<String, String> data = new HashMap<String, String>();
-        data.put( "newpassword", newPassword );
-        data.put( "oldpassword", "test" );
-
-        // change the password as admin. The old password isn't required
-        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
-                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
-
-        assertNull( getError( node ) );
-
-        refreshIndex("test-organization", "test-app");
-
-        adminAccessToken = mgmtToken( "test", newPassword );
-
-        data.put( "oldpassword", newPassword );
-        data.put( "newpassword", "test" );
-
-        node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", adminAccessToken )
-                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                                          .post( String.class, data ));
-
-        assertNull( getError( node ) );
-    }
-
+//    @Test
+//    public void setSelfAdminPasswordAsAdmin() throws IOException {
+//
+//        String username = clientSetup.getUsername();
+//        String password = clientSetup.getPassword();
+//
+//
+//        Map<String, String> passwordPayload = new HashMap<String, String>();
+//        passwordPayload.put( "newpassword", "testPassword" );
+//        passwordPayload.put( "oldpassword", password );
+//
+//        // change the password as admin. The old password isn't required
+//        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
+//                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, passwordPayload ));
 //
+//
+//
+//        this.refreshIndex();
+//
+//
+//        assertNull( getError( node ) );
+//
+//        //Get the token using the new password
+//        Token tokenPayload = this.app().token().post(new Token(username, "testPassword"));
+//
+//        //Check that we cannot get the token using the old password
+//        try {
+//            this.app().token().post( new Token( username, password ) );
+//            fail( "We shouldn't be able to get a token using the old password" );
+//        }catch(UniformInterfaceException uie) {
+//            errorParse( 500,"BadPeople",uie );
+//        }
+//    }
+//
+//
+//    /**
+//     * Check that we cannot change the password by using an older password
+//     */
 //    @Test
 //    public void passwordMismatchErrorAdmin() {
-//        String origPassword = "foo";
-//        String newPassword = "bar";
 //
-//        Map<String, String> data = new HashMap<String, String>();
-//        data.put( "newpassword", origPassword );
 //
-//        // now change the password, with an incorrect old password
 //
-//        data.put( "oldpassword", origPassword );
-//        data.put( "newpassword", newPassword );
+//        String username = clientSetup.getUsername();
+//        String password = clientSetup.getPassword();
 //
-//        ClientResponse.Status responseStatus = null;
 //
+//        Map<String, String> passwordPayload = new HashMap<String, String>();
+//        passwordPayload.put( "newpassword", "testPassword" );
+//        passwordPayload.put( "oldpassword", password );
+//
+//        // change the password as admin. The old password isn't required
+//        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
+//                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, passwordPayload ));
+//
+//
+//
+//        this.refreshIndex();
+//
+//
+//        //Get the token using the new password
+//        Token tokenPayload = this.app().token().post(new Token(username, "testPassword"));
+//
+//
+//        // Check that we can't change the password using the old password.
 //        try {
 //            resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
-//                      .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data );
+//                      .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, passwordPayload );
+//            fail("We shouldn't be able to change the password with the same payload");
 //        }
 //        catch ( UniformInterfaceException uie ) {
-//            responseStatus = uie.getResponse().getClientResponseStatus();
+//            errorParse( ClientResponse.Status.BAD_REQUEST.getStatusCode(),ClientResponse.Status.BAD_REQUEST.getReasonPhrase(),uie );
 //        }
 //
-//        assertNotNull( responseStatus );
-//
-//        assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus );
 //    }
 //
 //
+//    /**
+//     * Checks that as a superuser (i.e with a superuser token ) we can change the password of a admin.
+//     * @throws IOException
+//     */
 //    @Test
 //    public void setAdminPasswordAsSysAdmin() throws IOException {
 //
@@ -794,6 +819,6 @@ public class AdminUsersIT extends AbstractRestIT {
 //        }
 //        catch ( Exception ex ) {
 //        }
-    }
+//    }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/17c439b2/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 b644030..1ec767f 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
@@ -41,7 +41,7 @@ import javax.ws.rs.core.MediaType;
 public class ClientSetup implements TestRule {
 
     RestClient restClient;
-    protected String username, orgName, appName;
+    protected String username, password,orgName, appName;
     protected Organization organization;
     protected Application application;
 
@@ -82,7 +82,10 @@ public class ClientSetup implements TestRule {
         String methodName = description.getMethodName();
         String name = testClass + "." + methodName;
 
+        Token test = restClient.management().token().post( new Token("superuser","superpassword") );
+
         username = "user_"+name + UUIDUtils.newTimeUUID();
+        password = username;
         orgName = "org_"+name+UUIDUtils.newTimeUUID();
         appName = "app_"+name+UUIDUtils.newTimeUUID();
 
@@ -96,6 +99,8 @@ public class ClientSetup implements TestRule {
 
     public String getUsername(){return username;}
 
+    public String getPassword(){return password;}
+
     public Organization getOrganization(){return organization;}
 
     public String getOrganizationName(){return orgName;}