You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@usergrid.apache.org by r3b <gi...@git.apache.org> on 2015/04/20 22:49:38 UTC

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

GitHub user r3b opened a pull request:

    https://github.com/apache/incubator-usergrid/pull/232

    Refactoring of test harness and tests

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/apache/incubator-usergrid USERGRID-336

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-usergrid/pull/232.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #232
    
----
commit 3e3567103a53432e4bb277c11279114dbc078a8e
Author: ryan bridges <ry...@apache.org>
Date:   2015-04-02T06:29:05Z

    [USERGRID-336] Updating ContentTypeResourceIT

commit 778f49b8f51937615ec1af2e0825e02f682347ac
Author: ryan bridges <ry...@apache.org>
Date:   2015-04-02T06:29:50Z

    [USERGRID-340] Updating RegistrationIT

commit c77835a6650eaa645d8cc627efa3c883078011d0
Author: ryan bridges <ry...@apache.org>
Date:   2015-04-10T15:08:28Z

    [USERGRID-515] catch exception in ApplicationResource.executePut if application restore fails

commit 9b1bd03e81e620324bb66724fc57b46ac34f5c7f
Author: ryan bridges <ry...@apache.org>
Date:   2015-04-20T16:12:46Z

    [USERGRID-342, USERGRID-336, USERGRID-340] Updating and refactoring IT tests

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28733735
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/NamedResource.java ---
    @@ -17,32 +17,35 @@
     package org.apache.usergrid.rest.test.resource2point0.endpoints;
     
     
    +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.QueryParameters;
     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;
     
    -import java.util.HashMap;
    +import javax.ws.rs.core.MediaType;
     import java.util.Iterator;
    +import java.util.List;
     import java.util.Map;
     import java.util.Set;
    -import java.util.UUID;
     
     
     /**
      * Base class that is extended by named endpoints.
      * The NamedResource stores the parent of the class, the context in which the class operates and then Name of this resource
      */
    -public abstract class NamedResource implements UrlResource {
    +public abstract class NamedResource<T extends NamedResource<T>> implements UrlResource {
     
    -    protected final String name;
    -    protected final ClientContext context;
    +    protected String name;
    +    protected ClientContext context;
         /* Stores the path of the parent that called it.
         i.e If we had a ApplicationResource ( an instance of a namedResource ) this would contain the OrganizationResource.
          */
    -    protected final UrlResource parent;
    +    protected UrlResource parent;
     
    +    protected abstract T getThis();
    --- End diff --
    
    I guess the comment on clarity should probably go here explaining the purpose of the method.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28729383
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/filters/ContentTypeResourceIT.java ---
    @@ -105,106 +75,84 @@ public void correctHeaders() throws Exception {
          */
         @Test
         public void textPlainContentType() throws Exception {
    -        Map<String, String> data = hashMap( "name", "Solitaire2" );
    -
    -        String json = JsonUtils.mapToFormattedJsonString( data );
    -
    -        DefaultHttpClient client = new DefaultHttpClient();
    -
    -        HttpHost host = new HttpHost( super.getBaseURI().getHost(), super.getBaseURI().getPort() );
    +        refreshIndex();
    +        String json = JsonUtils.mapToFormattedJsonString(hashMap("name", "Solitaire2"));
    +        WebResource.Builder builder = app().collection("games").getResource(true, getAdminToken())
    +            .accept(MediaType.APPLICATION_JSON)
    +            .type(MediaType.APPLICATION_JSON);
    --- End diff --
    
    Should this be application_json_type ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28732352
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java ---
    @@ -17,212 +17,238 @@
     package org.apache.usergrid.rest.management;
     
     
    -import java.io.IOException;
    -import java.util.List;
    -import java.util.Map;
    -import java.util.Properties;
    -import java.util.UUID;
    -
    -import javax.mail.Folder;
    -import javax.mail.Message;
    -import javax.mail.MessagingException;
    -import javax.mail.Session;
    -import javax.mail.Store;
    -import javax.mail.internet.MimeMultipart;
    -import javax.ws.rs.core.MediaType;
    -import javax.ws.rs.core.MultivaluedMap;
    -
    -import com.eaio.uuid.UUIDGen;
    -import com.fasterxml.jackson.databind.JsonNode;
    -
    -import org.junit.Rule;
    +import com.sun.jersey.api.client.UniformInterfaceException;
    +import com.sun.jersey.api.representation.Form;
    +import org.apache.commons.lang.StringUtils;
    +import org.apache.usergrid.management.AccountCreationProps;
    +import org.apache.usergrid.persistence.model.util.UUIDGenerator;
    +import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
    +import org.apache.usergrid.rest.test.resource2point0.model.*;
    +import org.apache.usergrid.rest.test.resource2point0.model.Collection;
     import org.junit.Test;
     import org.jvnet.mock_javamail.Mailbox;
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
    -import org.apache.usergrid.management.UserInfo;
    -import org.apache.usergrid.persistence.model.util.UUIDGenerator;
    -import org.apache.usergrid.rest.AbstractRestIT;
    -import org.apache.usergrid.rest.ITSetup;
    -import org.apache.usergrid.rest.TestContextSetup;
    -import org.apache.usergrid.rest.test.security.TestAppUser;
    -import org.apache.usergrid.rest.test.security.TestUser;
     
    -import org.apache.commons.lang.StringUtils;
    +import javax.mail.*;
    +import javax.mail.internet.MimeMultipart;
    +import javax.ws.rs.core.MediaType;
    +import java.io.IOException;
    +import java.util.*;
     
    -import com.sun.jersey.api.client.ClientResponse;
    -import com.sun.jersey.api.client.UniformInterfaceException;
    -import com.sun.jersey.core.util.MultivaluedMapImpl;
    -
    -import static org.junit.Assert.assertEquals;
    -import static org.junit.Assert.assertFalse;
    -import static org.junit.Assert.assertNotNull;
    -import static org.junit.Assert.assertNotSame;
    -import static org.junit.Assert.assertTrue;
    -import static org.junit.Assert.fail;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_ADMIN_RESETPW_URL;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_EMAIL;
    -import static org.apache.usergrid.utils.MapUtils.hashMap;
    +import static org.apache.usergrid.management.AccountCreationProps.*;
    +import static org.junit.Assert.*;
     
     
     public class RegistrationIT extends AbstractRestIT {
     
    -    private static final Logger logger = LoggerFactory.getLogger( RegistrationIT.class );
    -
    -    private static final ITSetup setup = ITSetup.getInstance();
    -
    -    @Rule
    -    public TestContextSetup context = new TestContextSetup( this );
    -
    -
    -    @Test
    -    public void postCreateOrgAndAdmin() throws Exception {
    +    private static final Logger logger = LoggerFactory.getLogger(RegistrationIT.class);
     
    -        Map<String, String> originalProperties = getRemoteTestProperties();
    +    public Map<String, Object> getRemoteTestProperties() {
    +        return clientSetup.getRestClient().testPropertiesResource().get().getProperties();
    +    }
     
    -        try {
    -            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
    -            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
    -            setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" );
    -            setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
    +    /**
    +     * Sets a management service property locally and remotely.
    +     */
    +    public void setTestProperty(String key, Object value) {
    +        // set the value remotely (in the Usergrid instance running in Tomcat classloader)
    +        Entity props = new Entity();
    +        props.put(key, value);
    +        clientSetup.getRestClient().testPropertiesResource().post(props);
     
    -//            JsonNode node = postCreateOrgAndAdmin( "test-org-1", "test-user-1", "Test User",
    -//                    "test-user-1@mockserver.com", "testpassword" );
    +    }
     
    +    public void setTestProperties(Map<String, Object> props) {
    +        Entity properties = new Entity();
    +        // set the values locally (in the Usergrid instance here in the JUnit classloader
    +        for (String key : props.keySet()) {
    +            properties.put(key, props.get(key));
     
    -            final String username = "registrationUser"+UUIDGenerator.newTimeUUID();
    -            final String email = username+"@usergrid.com" ;
    -            final String password = "password";
    +        }
     
    -            final TestUser user1 = new TestAppUser(username , password, email);
    +        // set the values remotely (in the Usergrid instance running in Tomcat classloader)
    +        clientSetup.getRestClient().testPropertiesResource().post(properties);
    +    }
     
    -            context.withOrg( "org" + UUIDGenerator.newTimeUUID() ).withApp( "app" + UUIDGenerator.newTimeUUID() ).withUser( user1 ).createNewOrgAndUser();
    -            context.createAppForOrg();
    +    public String getTokenFromMessage(Message msg) throws IOException, MessagingException {
    +        String body = ((MimeMultipart) msg.getContent()).getBodyPart(0).getContent().toString();
    +        // TODO better token extraction
    +        // this is going to get the wrong string if the first part is not
    +        // text/plain and the url isn't the last character in the email
    +        return StringUtils.substringAfterLast(body, "token=");
    +    }
     
    -            final UUID owner_uuid = context.getActiveUser().getUuid();
    +    public User postAddAdminToOrg(String organizationName, String email, String password, Token token) throws IOException {
    +
    +        ApiResponse apiResponse = this
    +            .management()
    +            .orgs()
    +            .organization(organizationName)
    +            .users()
    +            .getResource(true, token)
    +            .type(MediaType.APPLICATION_JSON_TYPE)
    +            .accept(MediaType.APPLICATION_ATOM_XML_TYPE)
    +            .post(ApiResponse.class, new User().chainPut("email", email).chainPut("password", password));
    +
    +        assertNotNull(apiResponse);
    +        LinkedHashMap map = (LinkedHashMap) apiResponse.getData();
    +        return new User((LinkedHashMap) map.get("user"));
    +    }
     
    -//            refreshIndex("test-organization", "test-app");
    -//
    -//            UUID owner_uuid =
    -//                    UUID.fromString( node.findPath( "data" ).findPath( "owner" ).findPath( "uuid" ).textValue() );
    +    private Message[] getMessages(String host, String user, String password) throws MessagingException, IOException {
     
    -            List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get( "test-user-1@mockserver.com" );
    +        Session session = Session.getDefaultInstance(new Properties());
    +        Store store = session.getStore("imap");
    +        store.connect(host, user, password);
     
    -            assertFalse( inbox.isEmpty() );
    +        Folder folder = store.getFolder("inbox");
    +        folder.open(Folder.READ_ONLY);
    +        Message[] msgs = folder.getMessages();
     
    -            Message account_confirmation_message = inbox.get( 0 );
    -            assertEquals( "User Account Confirmation: " + email,
    -                    account_confirmation_message.getSubject() );
    +        for (Message m : msgs) {
    +            logger.info("Subject: " + m.getSubject());
    +            logger.info(
    +                "Body content 0 " + ((MimeMultipart) m.getContent()).getBodyPart(0).getContent());
    +            logger.info(
    +                "Body content 1 " + ((MimeMultipart) m.getContent()).getBodyPart(1).getContent());
    +        }
    +        return msgs;
    +    }
     
    -            String token = getTokenFromMessage( account_confirmation_message );
    -            logger.info( token );
    +    @Test
    +    public void postCreateOrgAndAdmin() throws Exception {
     
    -            setup.getMgmtSvc().disableAdminUser( owner_uuid );
    +        Map<String, Object> originalProperties = getRemoteTestProperties();
     
    -            refreshIndex(context.getOrgName(), context.getAppName());
    +        try {
    +            setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
    +            setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
    +            setTestProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false");
    +            setTestProperty(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@usergrid");
     
    +            final String username = "registrationUser" + UUIDGenerator.newTimeUUID();
    +            final String email = username + "@usergrid.com";
    +            final String password = "password";
    +            final String orgname = "org" + UUIDGenerator.newTimeUUID();
    +            final String appname = "app" + UUIDGenerator.newTimeUUID();
    +
    +            Organization organization = this
    +                .management()
    +                .orgs()
    +                .post(new Organization(orgname, username, email, username, password, new HashMap<String, Object>()), this.getAdminToken());
    +            Token orgToken = this.management().token().post(new Token(username, password));
    +            this.management().orgs().organization(organization.getName()).app().post(new Application(appname), orgToken);
    +
    +
    +            List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get(email);
    +            Message[] messages = inbox.toArray(new Message[inbox.size()]);
    +            assertNotEquals(messages.length, 0);
    +
    +            Message account_confirmation_message = messages[0];
    +            assertEquals("User Account Confirmation: " + email,
    +                account_confirmation_message.getSubject());
    +
    +            String token = getTokenFromMessage(account_confirmation_message);
    +            logger.info(token);
    +
    +            setTestProperty(AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_ALLOWED, "false");
    +
    +            refreshIndex();
    +            Collection appCollection = clientSetup
    +                .getRestClient()
    +                .org(orgname)
    +                .app(appname)
    +                .withToken(orgToken).get();
    +            Entity application = appCollection.next();
    +            assertNotNull(application);
    +            Entity appUser = clientSetup
    +                .getRestClient()
    +                .org(orgname)
    +                .app(appname)
    +                .users()
    +                .withToken(orgToken)
    +                .post(new User("testuser", "Test User", "test@usergrid.org", "password"));
                 try {
    -                resource().path( "/management/token" ).queryParam( "grant_type", "password" )
    -                        .queryParam( "username", username ).queryParam( "password", password )
    -                        .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
    -                        .get( String.class );
    -                fail( "request for disabled user should fail" );
    +                this.management().orgs().organization(organization.getName()).users().user(username)
    +                    .getResource(true, getAdminToken())
    +                    .get(String.class);
    +                fail("request for disabled admin should fail");
    +            } catch (UniformInterfaceException uie) {
    +                assertEquals(401, uie.getResponse().getStatus());
                 }
    -            catch ( UniformInterfaceException uie ) {
    -                ClientResponse.Status status = uie.getResponse().getClientResponseStatus();
    -                JsonNode body = mapper.readTree( uie.getResponse().getEntity( String.class ));
    -                assertEquals( "user disabled", body.findPath( "error_description" ).textValue() );
    +            setTestProperty(AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_ALLOWED, "true");
    +            Token objToken = management()
    +                .token()
    +                .post(new Token(username, password));
    +            try {
    +                clientSetup
    +                    .getRestClient()
    +                    .org(orgname)
    +                    .app(appname)
    +                    .users()
    +                    .user("testuser")
    +                    .revoketokens()
    +                    .withToken(objToken)
    +                    .put();
    +            } catch (UniformInterfaceException uie0) {
    +                fail("Failed to revoke user tokens");
                 }
    -
    -            setup.getMgmtSvc().deactivateUser( setup.getEmf().getManagementAppId(), owner_uuid );
                 try {
    -                resource().path( "/management/token" ).queryParam( "grant_type", "password" )
    -                        .queryParam( "username", username ).queryParam( "password", password)
    -                        .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
    -                        .get( String.class );
    -                fail( "request for deactivated user should fail" );
    +                clientSetup
    +                    .getRestClient()
    +                    .org(orgname)
    +                    .app(appname)
    +                    .users()
    +                    .user("testuser")
    +                    .withToken(objToken)
    +                    .put(appUser.chainPut("activated", "false").chainPut("deactivated", System.currentTimeMillis()));
    +                refreshIndex();
    +            } catch (UniformInterfaceException uie0) {
    +                fail("Failed to deactivate the user");
                 }
    -            catch ( UniformInterfaceException uie ) {
    -                ClientResponse.Status status = uie.getResponse().getClientResponseStatus();
    -                JsonNode body = mapper.readTree( uie.getResponse().getEntity( String.class ));
    -                assertEquals( "user not activated", body.findPath( "error_description" ).textValue() );
    --- End diff --
    
    We still want to read the error_description to make sure we are getting the correct text back. It'll make the refactor of the rest tier errors easier to verify.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28731316
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java ---
    @@ -17,212 +17,238 @@
     package org.apache.usergrid.rest.management;
     
     
    -import java.io.IOException;
    -import java.util.List;
    -import java.util.Map;
    -import java.util.Properties;
    -import java.util.UUID;
    -
    -import javax.mail.Folder;
    -import javax.mail.Message;
    -import javax.mail.MessagingException;
    -import javax.mail.Session;
    -import javax.mail.Store;
    -import javax.mail.internet.MimeMultipart;
    -import javax.ws.rs.core.MediaType;
    -import javax.ws.rs.core.MultivaluedMap;
    -
    -import com.eaio.uuid.UUIDGen;
    -import com.fasterxml.jackson.databind.JsonNode;
    -
    -import org.junit.Rule;
    +import com.sun.jersey.api.client.UniformInterfaceException;
    +import com.sun.jersey.api.representation.Form;
    +import org.apache.commons.lang.StringUtils;
    +import org.apache.usergrid.management.AccountCreationProps;
    +import org.apache.usergrid.persistence.model.util.UUIDGenerator;
    +import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
    +import org.apache.usergrid.rest.test.resource2point0.model.*;
    +import org.apache.usergrid.rest.test.resource2point0.model.Collection;
     import org.junit.Test;
     import org.jvnet.mock_javamail.Mailbox;
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
    -import org.apache.usergrid.management.UserInfo;
    -import org.apache.usergrid.persistence.model.util.UUIDGenerator;
    -import org.apache.usergrid.rest.AbstractRestIT;
    -import org.apache.usergrid.rest.ITSetup;
    -import org.apache.usergrid.rest.TestContextSetup;
    -import org.apache.usergrid.rest.test.security.TestAppUser;
    -import org.apache.usergrid.rest.test.security.TestUser;
     
    -import org.apache.commons.lang.StringUtils;
    +import javax.mail.*;
    +import javax.mail.internet.MimeMultipart;
    +import javax.ws.rs.core.MediaType;
    +import java.io.IOException;
    +import java.util.*;
     
    -import com.sun.jersey.api.client.ClientResponse;
    -import com.sun.jersey.api.client.UniformInterfaceException;
    -import com.sun.jersey.core.util.MultivaluedMapImpl;
    -
    -import static org.junit.Assert.assertEquals;
    -import static org.junit.Assert.assertFalse;
    -import static org.junit.Assert.assertNotNull;
    -import static org.junit.Assert.assertNotSame;
    -import static org.junit.Assert.assertTrue;
    -import static org.junit.Assert.fail;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_ADMIN_RESETPW_URL;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_EMAIL;
    -import static org.apache.usergrid.utils.MapUtils.hashMap;
    +import static org.apache.usergrid.management.AccountCreationProps.*;
    +import static org.junit.Assert.*;
     
     
     public class RegistrationIT extends AbstractRestIT {
     
    -    private static final Logger logger = LoggerFactory.getLogger( RegistrationIT.class );
    -
    -    private static final ITSetup setup = ITSetup.getInstance();
    -
    -    @Rule
    -    public TestContextSetup context = new TestContextSetup( this );
    -
    -
    -    @Test
    -    public void postCreateOrgAndAdmin() throws Exception {
    +    private static final Logger logger = LoggerFactory.getLogger(RegistrationIT.class);
     
    -        Map<String, String> originalProperties = getRemoteTestProperties();
    +    public Map<String, Object> getRemoteTestProperties() {
    +        return clientSetup.getRestClient().testPropertiesResource().get().getProperties();
    +    }
     
    -        try {
    -            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
    -            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
    -            setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" );
    -            setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
    +    /**
    +     * Sets a management service property locally and remotely.
    +     */
    +    public void setTestProperty(String key, Object value) {
    +        // set the value remotely (in the Usergrid instance running in Tomcat classloader)
    +        Entity props = new Entity();
    +        props.put(key, value);
    +        clientSetup.getRestClient().testPropertiesResource().post(props);
     
    -//            JsonNode node = postCreateOrgAndAdmin( "test-org-1", "test-user-1", "Test User",
    -//                    "test-user-1@mockserver.com", "testpassword" );
    +    }
     
    +    public void setTestProperties(Map<String, Object> props) {
    +        Entity properties = new Entity();
    +        // set the values locally (in the Usergrid instance here in the JUnit classloader
    +        for (String key : props.keySet()) {
    +            properties.put(key, props.get(key));
     
    -            final String username = "registrationUser"+UUIDGenerator.newTimeUUID();
    -            final String email = username+"@usergrid.com" ;
    -            final String password = "password";
    +        }
     
    -            final TestUser user1 = new TestAppUser(username , password, email);
    +        // set the values remotely (in the Usergrid instance running in Tomcat classloader)
    +        clientSetup.getRestClient().testPropertiesResource().post(properties);
    +    }
     
    -            context.withOrg( "org" + UUIDGenerator.newTimeUUID() ).withApp( "app" + UUIDGenerator.newTimeUUID() ).withUser( user1 ).createNewOrgAndUser();
    -            context.createAppForOrg();
    +    public String getTokenFromMessage(Message msg) throws IOException, MessagingException {
    +        String body = ((MimeMultipart) msg.getContent()).getBodyPart(0).getContent().toString();
    +        // TODO better token extraction
    +        // this is going to get the wrong string if the first part is not
    +        // text/plain and the url isn't the last character in the email
    +        return StringUtils.substringAfterLast(body, "token=");
    +    }
     
    -            final UUID owner_uuid = context.getActiveUser().getUuid();
    +    public User postAddAdminToOrg(String organizationName, String email, String password, Token token) throws IOException {
    +
    +        ApiResponse apiResponse = this
    +            .management()
    +            .orgs()
    +            .organization(organizationName)
    +            .users()
    +            .getResource(true, token)
    +            .type(MediaType.APPLICATION_JSON_TYPE)
    +            .accept(MediaType.APPLICATION_ATOM_XML_TYPE)
    --- End diff --
    
    What changed about this class such that we would need a different type or rather a different accept? Maybe a comment at the top of the class or for the tests that use this class?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28732673
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java ---
    @@ -17,212 +17,238 @@
     package org.apache.usergrid.rest.management;
     
     
    -import java.io.IOException;
    -import java.util.List;
    -import java.util.Map;
    -import java.util.Properties;
    -import java.util.UUID;
    -
    -import javax.mail.Folder;
    -import javax.mail.Message;
    -import javax.mail.MessagingException;
    -import javax.mail.Session;
    -import javax.mail.Store;
    -import javax.mail.internet.MimeMultipart;
    -import javax.ws.rs.core.MediaType;
    -import javax.ws.rs.core.MultivaluedMap;
    -
    -import com.eaio.uuid.UUIDGen;
    -import com.fasterxml.jackson.databind.JsonNode;
    -
    -import org.junit.Rule;
    +import com.sun.jersey.api.client.UniformInterfaceException;
    +import com.sun.jersey.api.representation.Form;
    +import org.apache.commons.lang.StringUtils;
    +import org.apache.usergrid.management.AccountCreationProps;
    +import org.apache.usergrid.persistence.model.util.UUIDGenerator;
    +import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
    +import org.apache.usergrid.rest.test.resource2point0.model.*;
    +import org.apache.usergrid.rest.test.resource2point0.model.Collection;
     import org.junit.Test;
     import org.jvnet.mock_javamail.Mailbox;
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
    -import org.apache.usergrid.management.UserInfo;
    -import org.apache.usergrid.persistence.model.util.UUIDGenerator;
    -import org.apache.usergrid.rest.AbstractRestIT;
    -import org.apache.usergrid.rest.ITSetup;
    -import org.apache.usergrid.rest.TestContextSetup;
    -import org.apache.usergrid.rest.test.security.TestAppUser;
    -import org.apache.usergrid.rest.test.security.TestUser;
     
    -import org.apache.commons.lang.StringUtils;
    +import javax.mail.*;
    +import javax.mail.internet.MimeMultipart;
    +import javax.ws.rs.core.MediaType;
    +import java.io.IOException;
    +import java.util.*;
     
    -import com.sun.jersey.api.client.ClientResponse;
    -import com.sun.jersey.api.client.UniformInterfaceException;
    -import com.sun.jersey.core.util.MultivaluedMapImpl;
    -
    -import static org.junit.Assert.assertEquals;
    -import static org.junit.Assert.assertFalse;
    -import static org.junit.Assert.assertNotNull;
    -import static org.junit.Assert.assertNotSame;
    -import static org.junit.Assert.assertTrue;
    -import static org.junit.Assert.fail;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_ADMIN_RESETPW_URL;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS;
    -import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_EMAIL;
    -import static org.apache.usergrid.utils.MapUtils.hashMap;
    +import static org.apache.usergrid.management.AccountCreationProps.*;
    +import static org.junit.Assert.*;
     
     
     public class RegistrationIT extends AbstractRestIT {
     
    -    private static final Logger logger = LoggerFactory.getLogger( RegistrationIT.class );
    -
    -    private static final ITSetup setup = ITSetup.getInstance();
    -
    -    @Rule
    -    public TestContextSetup context = new TestContextSetup( this );
    -
    -
    -    @Test
    -    public void postCreateOrgAndAdmin() throws Exception {
    +    private static final Logger logger = LoggerFactory.getLogger(RegistrationIT.class);
     
    -        Map<String, String> originalProperties = getRemoteTestProperties();
    +    public Map<String, Object> getRemoteTestProperties() {
    +        return clientSetup.getRestClient().testPropertiesResource().get().getProperties();
    +    }
     
    -        try {
    -            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
    -            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
    -            setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" );
    -            setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
    +    /**
    +     * Sets a management service property locally and remotely.
    +     */
    +    public void setTestProperty(String key, Object value) {
    +        // set the value remotely (in the Usergrid instance running in Tomcat classloader)
    +        Entity props = new Entity();
    +        props.put(key, value);
    +        clientSetup.getRestClient().testPropertiesResource().post(props);
     
    -//            JsonNode node = postCreateOrgAndAdmin( "test-org-1", "test-user-1", "Test User",
    -//                    "test-user-1@mockserver.com", "testpassword" );
    +    }
     
    +    public void setTestProperties(Map<String, Object> props) {
    +        Entity properties = new Entity();
    +        // set the values locally (in the Usergrid instance here in the JUnit classloader
    +        for (String key : props.keySet()) {
    +            properties.put(key, props.get(key));
     
    -            final String username = "registrationUser"+UUIDGenerator.newTimeUUID();
    -            final String email = username+"@usergrid.com" ;
    -            final String password = "password";
    +        }
     
    -            final TestUser user1 = new TestAppUser(username , password, email);
    +        // set the values remotely (in the Usergrid instance running in Tomcat classloader)
    +        clientSetup.getRestClient().testPropertiesResource().post(properties);
    +    }
     
    -            context.withOrg( "org" + UUIDGenerator.newTimeUUID() ).withApp( "app" + UUIDGenerator.newTimeUUID() ).withUser( user1 ).createNewOrgAndUser();
    -            context.createAppForOrg();
    +    public String getTokenFromMessage(Message msg) throws IOException, MessagingException {
    +        String body = ((MimeMultipart) msg.getContent()).getBodyPart(0).getContent().toString();
    +        // TODO better token extraction
    +        // this is going to get the wrong string if the first part is not
    +        // text/plain and the url isn't the last character in the email
    +        return StringUtils.substringAfterLast(body, "token=");
    +    }
     
    -            final UUID owner_uuid = context.getActiveUser().getUuid();
    +    public User postAddAdminToOrg(String organizationName, String email, String password, Token token) throws IOException {
    +
    +        ApiResponse apiResponse = this
    +            .management()
    +            .orgs()
    +            .organization(organizationName)
    +            .users()
    +            .getResource(true, token)
    +            .type(MediaType.APPLICATION_JSON_TYPE)
    +            .accept(MediaType.APPLICATION_ATOM_XML_TYPE)
    +            .post(ApiResponse.class, new User().chainPut("email", email).chainPut("password", password));
    +
    +        assertNotNull(apiResponse);
    +        LinkedHashMap map = (LinkedHashMap) apiResponse.getData();
    +        return new User((LinkedHashMap) map.get("user"));
    +    }
     
    -//            refreshIndex("test-organization", "test-app");
    -//
    -//            UUID owner_uuid =
    -//                    UUID.fromString( node.findPath( "data" ).findPath( "owner" ).findPath( "uuid" ).textValue() );
    +    private Message[] getMessages(String host, String user, String password) throws MessagingException, IOException {
     
    -            List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get( "test-user-1@mockserver.com" );
    +        Session session = Session.getDefaultInstance(new Properties());
    +        Store store = session.getStore("imap");
    +        store.connect(host, user, password);
     
    -            assertFalse( inbox.isEmpty() );
    +        Folder folder = store.getFolder("inbox");
    +        folder.open(Folder.READ_ONLY);
    +        Message[] msgs = folder.getMessages();
     
    -            Message account_confirmation_message = inbox.get( 0 );
    -            assertEquals( "User Account Confirmation: " + email,
    -                    account_confirmation_message.getSubject() );
    +        for (Message m : msgs) {
    +            logger.info("Subject: " + m.getSubject());
    +            logger.info(
    +                "Body content 0 " + ((MimeMultipart) m.getContent()).getBodyPart(0).getContent());
    +            logger.info(
    +                "Body content 1 " + ((MimeMultipart) m.getContent()).getBodyPart(1).getContent());
    +        }
    +        return msgs;
    +    }
     
    -            String token = getTokenFromMessage( account_confirmation_message );
    -            logger.info( token );
    +    @Test
    +    public void postCreateOrgAndAdmin() throws Exception {
     
    -            setup.getMgmtSvc().disableAdminUser( owner_uuid );
    +        Map<String, Object> originalProperties = getRemoteTestProperties();
     
    -            refreshIndex(context.getOrgName(), context.getAppName());
    +        try {
    +            setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
    +            setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
    +            setTestProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false");
    +            setTestProperty(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@usergrid");
     
    +            final String username = "registrationUser" + UUIDGenerator.newTimeUUID();
    +            final String email = username + "@usergrid.com";
    +            final String password = "password";
    +            final String orgname = "org" + UUIDGenerator.newTimeUUID();
    +            final String appname = "app" + UUIDGenerator.newTimeUUID();
    +
    +            Organization organization = this
    +                .management()
    +                .orgs()
    +                .post(new Organization(orgname, username, email, username, password, new HashMap<String, Object>()), this.getAdminToken());
    +            Token orgToken = this.management().token().post(new Token(username, password));
    +            this.management().orgs().organization(organization.getName()).app().post(new Application(appname), orgToken);
    +
    +
    +            List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get(email);
    +            Message[] messages = inbox.toArray(new Message[inbox.size()]);
    +            assertNotEquals(messages.length, 0);
    +
    +            Message account_confirmation_message = messages[0];
    +            assertEquals("User Account Confirmation: " + email,
    +                account_confirmation_message.getSubject());
    +
    +            String token = getTokenFromMessage(account_confirmation_message);
    +            logger.info(token);
    +
    +            setTestProperty(AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_ALLOWED, "false");
    +
    +            refreshIndex();
    +            Collection appCollection = clientSetup
    +                .getRestClient()
    +                .org(orgname)
    +                .app(appname)
    +                .withToken(orgToken).get();
    +            Entity application = appCollection.next();
    +            assertNotNull(application);
    +            Entity appUser = clientSetup
    +                .getRestClient()
    +                .org(orgname)
    +                .app(appname)
    +                .users()
    +                .withToken(orgToken)
    +                .post(new User("testuser", "Test User", "test@usergrid.org", "password"));
                 try {
    -                resource().path( "/management/token" ).queryParam( "grant_type", "password" )
    -                        .queryParam( "username", username ).queryParam( "password", password )
    -                        .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
    -                        .get( String.class );
    -                fail( "request for disabled user should fail" );
    +                this.management().orgs().organization(organization.getName()).users().user(username)
    +                    .getResource(true, getAdminToken())
    +                    .get(String.class);
    +                fail("request for disabled admin should fail");
    +            } catch (UniformInterfaceException uie) {
    +                assertEquals(401, uie.getResponse().getStatus());
                 }
    -            catch ( UniformInterfaceException uie ) {
    -                ClientResponse.Status status = uie.getResponse().getClientResponseStatus();
    -                JsonNode body = mapper.readTree( uie.getResponse().getEntity( String.class ));
    -                assertEquals( "user disabled", body.findPath( "error_description" ).textValue() );
    +            setTestProperty(AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_ALLOWED, "true");
    +            Token objToken = management()
    +                .token()
    +                .post(new Token(username, password));
    +            try {
    +                clientSetup
    +                    .getRestClient()
    +                    .org(orgname)
    +                    .app(appname)
    +                    .users()
    +                    .user("testuser")
    +                    .revoketokens()
    +                    .withToken(objToken)
    +                    .put();
    +            } catch (UniformInterfaceException uie0) {
    +                fail("Failed to revoke user tokens");
                 }
    -
    -            setup.getMgmtSvc().deactivateUser( setup.getEmf().getManagementAppId(), owner_uuid );
                 try {
    -                resource().path( "/management/token" ).queryParam( "grant_type", "password" )
    -                        .queryParam( "username", username ).queryParam( "password", password)
    -                        .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
    -                        .get( String.class );
    -                fail( "request for deactivated user should fail" );
    +                clientSetup
    +                    .getRestClient()
    +                    .org(orgname)
    +                    .app(appname)
    +                    .users()
    +                    .user("testuser")
    +                    .withToken(objToken)
    +                    .put(appUser.chainPut("activated", "false").chainPut("deactivated", System.currentTimeMillis()));
    +                refreshIndex();
    +            } catch (UniformInterfaceException uie0) {
    +                fail("Failed to deactivate the user");
                 }
    -            catch ( UniformInterfaceException uie ) {
    -                ClientResponse.Status status = uie.getResponse().getClientResponseStatus();
    -                JsonNode body = mapper.readTree( uie.getResponse().getEntity( String.class ));
    -                assertEquals( "user not activated", body.findPath( "error_description" ).textValue() );
    +            try {
    +                objToken = clientSetup
    +                    .getRestClient()
    +                    .org(orgname)
    +                    .app(appname)
    +                    .token()
    +                    .post(new Token("testuser", "password"));
    +                assertNull(objToken.getAccessToken());
    +                fail("token request for deactivated user should fail");
    +            } catch (UniformInterfaceException uie) {
    +                assertTrue(uie.getResponse().getEntity(String.class).contains("user not activated"));
                 }
     
    -            // assertEquals(ActivationState.ACTIVATED,
    -            // svcSetup.getMgmtSvc().handleConfirmationTokenForAdminUser(
    -            // owner_uuid, token));
    -
    -            // need to enable JSP usage in the test version of Jetty to make this test run
    -            //      String response = resource()
    -            //        .path("/management/users/" + owner_uuid + "/confirm").get(String.class);
    -            //      logger.info(response);
    -            //      Message account_activation_message = inbox.get(1);
    -            //      assertEquals("User Account Activated", account_activation_message.getSubject());
    -
    -        }
    -        finally {
    -            setTestProperties( originalProperties );
    +        } finally {
    +            setTestProperties(originalProperties);
             }
         }
     
     
    -    public String getTokenFromMessage( Message msg ) throws IOException, MessagingException {
    -        String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString();
    -        String token = StringUtils.substringAfterLast( body, "token=" );
    -        // TODO better token extraction
    -        // this is going to get the wrong string if the first part is not
    -        // text/plain and the url isn't the last character in the email
    -        return token;
    -    }
    -
    -
    -
    -    @SuppressWarnings({ "unchecked", "rawtypes" })
    -    public JsonNode postAddAdminToOrg( String organizationName, String email, String password, String token ) throws IOException {
    -        JsonNode node = null;
    -
    -        MultivaluedMap formData = new MultivaluedMapImpl();
    -        formData.add( "email", email );
    -        formData.add( "password", password );
    -
    -        node = mapper.readTree( resource().path( "/management/organizations/" + organizationName + "/users" )
    -                .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON )
    -                .type( MediaType.APPLICATION_FORM_URLENCODED ).post( String.class, formData ));
    -
    -        assertNotNull( node );
    -        logNode( node );
    -        return node;
    -    }
    -
    -
         @Test
         public void putAddToOrganizationFail() throws Exception {
     
    -        Map<String, String> originalProperties = getRemoteTestProperties();
    +        Map<String, Object> originalProperties = getRemoteTestProperties();
     
             try {
    -            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
    -            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
    -            setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" );
    -            setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
    -
    -            String t = adminToken();
    -            MultivaluedMap formData = new MultivaluedMapImpl();
    -            formData.add( "foo", "bar" );
    +            setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
    +            setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
    +            setTestProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false");
    +            setTestProperty(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com");
    +
    +            String t = this.getAdminToken().getAccessToken();
    +            Form form = new Form();
    +            form.add("foo", "bar");
                 try {
    -                resource().path( "/management/organizations/test-organization/users/test-admin-null@mockserver.com" )
    -                        .queryParam( "access_token", t ).accept( MediaType.APPLICATION_JSON )
    -                        .type( MediaType.APPLICATION_FORM_URLENCODED ).put( String.class, formData );
    -            }
    -            catch ( UniformInterfaceException e ) {
    -                assertEquals( "Should receive a 400 Not Found", 400, e.getResponse().getStatus() );
    +                this.org().getResource(false).path("/users/test-admin-null@mockserver.com")
    --- End diff --
    
    Was the test not valid against the management endpoint?  Just noticed the difference between the deleted test and the new test logic.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28729020
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/filters/ContentTypeResourceIT.java ---
    @@ -105,106 +75,84 @@ public void correctHeaders() throws Exception {
          */
         @Test
         public void textPlainContentType() throws Exception {
    -        Map<String, String> data = hashMap( "name", "Solitaire2" );
    -
    -        String json = JsonUtils.mapToFormattedJsonString( data );
    -
    -        DefaultHttpClient client = new DefaultHttpClient();
    -
    -        HttpHost host = new HttpHost( super.getBaseURI().getHost(), super.getBaseURI().getPort() );
    +        refreshIndex();
    +        String json = JsonUtils.mapToFormattedJsonString(hashMap("name", "Solitaire2"));
    +        WebResource.Builder builder = app().collection("games").getResource(true, getAdminToken())
    +            .accept(MediaType.APPLICATION_JSON)
    +            .type(MediaType.APPLICATION_JSON);
     
    -        HttpPost post = new HttpPost( String.format( "/%s/%s/games", context.getOrgUuid(), context.getAppUuid() ) );
    -        post.setEntity( new StringEntity( json ) );
    -        post.setHeader( HttpHeaders.AUTHORIZATION, "Bearer " + context.getActiveUser().getToken() );
    -        post.setHeader( HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON );
    -        post.setHeader( HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN );
    +        ClientResponse clientResponse = builder.post(ClientResponse.class, json);
     
    -        HttpResponse rsp = client.execute( host, post );
    +        assertEquals(200, clientResponse.getStatus());
     
    -        printResponse( rsp );
    +        MultivaluedMap<String, String> headers = clientResponse.getHeaders();
     
    -        assertEquals( 200, rsp.getStatusLine().getStatusCode() );
    +        List<String> contentType = headers.get("Content-Type");
    +        assertEquals(1, contentType.size());
    +        assertEquals(MediaType.APPLICATION_JSON, contentType.get(0));
     
    -        Header[] headers = rsp.getHeaders( HttpHeaders.CONTENT_TYPE );
    -
    -        assertEquals( 1, headers.length );
    -
    -        assertEquals( MediaType.APPLICATION_JSON, headers[0].getValue() );
         }
     
     
    -    /** Tests that application/x-www-url-form-encoded works correctly */
    +    /**
    +     * Tests that application/x-www-url-form-encoded works correctly
    +     */
         @Test
         public void formEncodedContentType() throws Exception {
     
    -        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
     
    -        pairs.add( new BasicNameValuePair( "organization", "formContentOrg" ) );
    -        pairs.add( new BasicNameValuePair( "username", "formContentOrg" ) );
    -        pairs.add( new BasicNameValuePair( "name", "Test User" ) );
    -        pairs.add( new BasicNameValuePair( "email", UUIDUtils.newTimeUUID() + "@usergrid.org" ) );
    -        pairs.add( new BasicNameValuePair( "password", "foobar" ) );
    +        Form payload = new Form();
    +        payload.add("access_token", getAdminToken().toString());
    +        payload.add("organization", "formContentOrg");
    +        payload.add("username", "formContentOrg");
    +        payload.add("name", "Test User");
    +        payload.add("email", UUIDUtils.newTimeUUID() + "@usergrid.org");
    +        payload.add("password", "foobar");
     
    -        UrlEncodedFormEntity entity = new UrlEncodedFormEntity( pairs, "UTF-8" );
     
    -        DefaultHttpClient client = new DefaultHttpClient();
    +        ClientResponse clientResponse = app().users().getResource(false)
    +            .accept(MediaType.APPLICATION_JSON)
    +            .type(MediaType.APPLICATION_FORM_URLENCODED)
    +            .post(ClientResponse.class, payload);
     
    -        HttpHost host = new HttpHost( super.getBaseURI().getHost(), super.getBaseURI().getPort() );
    +        assertEquals(200, clientResponse.getStatus());
     
    -        HttpPost post = new HttpPost( "/management/orgs" );
    -        post.setEntity( entity );
    -        // post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + context.getActiveUser().getToken());
    +        MultivaluedMap<String, String> headers = clientResponse.getHeaders();
     
    -        post.setHeader( HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED );
    -
    -        HttpResponse rsp = client.execute( host, post );
    -
    -        printResponse( rsp );
    -
    -        // should be an error, no content type was set
    -        assertEquals( 200, rsp.getStatusLine().getStatusCode() );
    -
    -        Header[] headers = rsp.getHeaders( HttpHeaders.CONTENT_TYPE );
    -
    -        assertEquals( 1, headers.length );
    -
    -        assertEquals( MediaType.APPLICATION_JSON, headers[0].getValue() );
    +        List<String> contentType = headers.get("Content-Type");
    +        assertEquals(1, contentType.size());
    +        assertEquals(MediaType.APPLICATION_JSON, contentType.get(0));
         }
     
     
    -    /** Tests that application/x-www-url-form-encoded works correctly */
    +    /**
    +     * Tests that application/x-www-url-form-encoded works correctly
    +     */
         @Test
         @Ignore("This will only pass in tomcat, and shouldn't pass in grizzly")
    --- End diff --
    
    We aren't using grizzly anymore ( at least I'm pretty sure we don't ). So this test should pass.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28728793
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/filters/ContentTypeResourceIT.java ---
    @@ -17,85 +17,55 @@
     package org.apache.usergrid.rest.filters;
     
     
    -import java.io.IOException;
    -import java.util.ArrayList;
    -import java.util.List;
    -import java.util.Map;
    -
    -import javax.ws.rs.core.HttpHeaders;
    -import javax.ws.rs.core.MediaType;
    -
    -import org.junit.Ignore;
    -import org.junit.Rule;
    -import org.junit.Test;
    -
    -import org.apache.usergrid.rest.AbstractRestIT;
    -import org.apache.usergrid.rest.TestContextSetup;
    +import com.sun.jersey.api.client.ClientResponse;
    +import com.sun.jersey.api.client.WebResource;
    +import com.sun.jersey.api.representation.Form;
    +import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
    +import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
    +import org.apache.usergrid.rest.test.resource2point0.model.Entity;
     import org.apache.usergrid.utils.JsonUtils;
     import org.apache.usergrid.utils.UUIDUtils;
    +import org.junit.Ignore;
    +import org.junit.Test;
     
    -import org.apache.http.Header;
    -import org.apache.http.HttpEntity;
    -import org.apache.http.HttpHost;
    -import org.apache.http.HttpResponse;
    -import org.apache.http.NameValuePair;
    -import org.apache.http.ParseException;
    -import org.apache.http.client.entity.UrlEncodedFormEntity;
    -import org.apache.http.client.methods.HttpGet;
    -import org.apache.http.client.methods.HttpPost;
    -import org.apache.http.entity.StringEntity;
    -import org.apache.http.impl.client.DefaultHttpClient;
    -import org.apache.http.message.BasicNameValuePair;
    -import org.apache.http.params.BasicHttpParams;
    -import org.apache.http.util.EntityUtils;
    +import javax.ws.rs.core.MediaType;
    +import javax.ws.rs.core.MultivaluedMap;
    +import java.util.List;
     
    -import static org.junit.Assert.assertEquals;
     import static org.apache.usergrid.utils.MapUtils.hashMap;
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertNotNull;
    +import static org.junit.Assert.assertNull;
     
     
    -/** @author tnine */
    +/**
    + * @author tnine
    + */
     
     // @Ignore("Client login is causing tests to fail due to socket closure by grizzly.  Need to re-enable once we're not
     // using grizzly to test")
     public class ContentTypeResourceIT extends AbstractRestIT {
     
    -    @Rule
    -    public TestContextSetup context = new TestContextSetup( this );
    -
    -
         /**
          * Creates a simple entity of type game. Does not set the content type. The type should be set to json to match the
          * body
          */
         @Test
         public void correctHeaders() throws Exception {
    -
    -
    -        Map<String, String> data = hashMap( "name", "Solitaire1" );
    -
    -        String json = JsonUtils.mapToFormattedJsonString( data );
    -
    -        DefaultHttpClient client = new DefaultHttpClient();
    -
    -        HttpHost host = new HttpHost( super.getBaseURI().getHost(), super.getBaseURI().getPort() );
    -
    -        HttpPost post = new HttpPost( String.format( "/%s/%s/games", context.getOrgUuid(), context.getAppUuid() ) );
    -        post.setEntity( new StringEntity( json ) );
    -        post.setHeader( HttpHeaders.AUTHORIZATION, "Bearer " + context.getActiveUser().getToken() );
    -        post.setHeader( HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON );
    -        post.setHeader( HttpHeaders.CONTENT_TYPE, "*/*" );
    -
    -        HttpResponse rsp = client.execute( host, post );
    -
    -        printResponse( rsp );
    -
    -        assertEquals( 200, rsp.getStatusLine().getStatusCode() );
    -
    -        Header[] headers = rsp.getHeaders( HttpHeaders.CONTENT_TYPE );
    -
    -        assertEquals( 1, headers.length );
    -
    -        assertEquals( MediaType.APPLICATION_JSON, headers[0].getValue() );
    +        refreshIndex();
    --- End diff --
    
    Is there a specific reason we want to start by refreshing the index?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28733686
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/EntityEndpoint.java ---
    @@ -30,7 +30,12 @@
     
     import javax.ws.rs.core.MediaType;
     
    -public class EntityEndpoint extends NamedResource {
    +public class EntityEndpoint extends NamedResource<EntityEndpoint> {
    +
    +    @Override
    +    protected EntityEndpoint getThis() {
    +        return null;
    --- End diff --
    
    I'm not entirely clear why we want to return null here. Could you add a comment , just seems strange when looking at the others returning themselves.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-usergrid/pull/232


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28729413
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/filters/ContentTypeResourceIT.java ---
    @@ -105,106 +75,84 @@ public void correctHeaders() throws Exception {
          */
         @Test
         public void textPlainContentType() throws Exception {
    -        Map<String, String> data = hashMap( "name", "Solitaire2" );
    -
    -        String json = JsonUtils.mapToFormattedJsonString( data );
    -
    -        DefaultHttpClient client = new DefaultHttpClient();
    -
    -        HttpHost host = new HttpHost( super.getBaseURI().getHost(), super.getBaseURI().getPort() );
    +        refreshIndex();
    +        String json = JsonUtils.mapToFormattedJsonString(hashMap("name", "Solitaire2"));
    +        WebResource.Builder builder = app().collection("games").getResource(true, getAdminToken())
    +            .accept(MediaType.APPLICATION_JSON)
    +            .type(MediaType.APPLICATION_JSON);
     
    -        HttpPost post = new HttpPost( String.format( "/%s/%s/games", context.getOrgUuid(), context.getAppUuid() ) );
    -        post.setEntity( new StringEntity( json ) );
    -        post.setHeader( HttpHeaders.AUTHORIZATION, "Bearer " + context.getActiveUser().getToken() );
    -        post.setHeader( HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON );
    -        post.setHeader( HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN );
    +        ClientResponse clientResponse = builder.post(ClientResponse.class, json);
    --- End diff --
    
    Is there a reason this couldn't use the POST command you specified in the named resource?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28733615
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java ---
    @@ -219,58 +224,58 @@ public ApiResponse delete(final QueryParameters parameters, final boolean useTok
          * POST /users {"color","red"}
          * </pre>
          */
    -    public Entity post(Entity payload){
    -
    -        String acceptHeader = MediaType.APPLICATION_JSON;
    -        if (this.acceptHeaders.size() > 0) {
    -            acceptHeader = StringUtils.join(this.acceptHeaders, ',');
    -        }
    -
    -        // use string type so we can log actual response from server
    -        String responseString = getResource(true)
    -            .type( MediaType.APPLICATION_JSON_TYPE )
    -            .accept(acceptHeader)
    -            .post(String.class, payload);
    -
    -        logger.debug("Response from post: " + responseString);
    -
    -        ObjectMapper mapper = new ObjectMapper();
    -        ApiResponse response;
    -        try {
    -            response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
    -        } catch (IOException e) {
    -            throw new RuntimeException("Error parsing response", e);
    -        }
    -
    -        return new Entity(response);
    -    }
    -
    -    public Entity post() {
    -
    -        String acceptHeader = MediaType.APPLICATION_JSON;
    -
    -        if (this.acceptHeaders.size() > 0) {
    -            acceptHeader = StringUtils.join(this.acceptHeaders, ',');
    -        }
    -
    -        // use string type so we can log actual response from server
    -        String responseString = getResource(true)
    -            .type( MediaType.APPLICATION_JSON_TYPE )
    -            .accept(acceptHeader)
    -            .post(String.class);
    -
    -        logger.debug("Response from post: " + responseString);
    -
    -        ObjectMapper mapper = new ObjectMapper();
    -        ApiResponse response;
    -        try {
    -            response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
    -        } catch (IOException e) {
    -            throw new RuntimeException("Error parsing response", e);
    -        }
    -
    -        return new Entity(response);
    -    }
    +//    public Entity post(Entity payload){
    --- End diff --
    
    You could delete this. No point in having it hanging around :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28728802
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/filters/ContentTypeResourceIT.java ---
    @@ -105,106 +75,84 @@ public void correctHeaders() throws Exception {
          */
         @Test
         public void textPlainContentType() throws Exception {
    -        Map<String, String> data = hashMap( "name", "Solitaire2" );
    -
    -        String json = JsonUtils.mapToFormattedJsonString( data );
    -
    -        DefaultHttpClient client = new DefaultHttpClient();
    -
    -        HttpHost host = new HttpHost( super.getBaseURI().getHost(), super.getBaseURI().getPort() );
    +        refreshIndex();
    --- End diff --
    
    ^ same as above



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Refactoring of test harness and t...

Posted by GERey <gi...@git.apache.org>.
Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28733144
  
    --- Diff: stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java ---
    @@ -250,48 +274,56 @@ public void postAddToOrganization() throws Exception {
         @Test
         public void addNewAdminUserWithNoPwdToOrganization() throws Exception {
     
    -        Map<String, String> originalProperties = getRemoteTestProperties();
    +        Map<String, Object> originalProperties = getRemoteTestProperties();
     
             try {
                 Mailbox.clearAll();
    -            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
    -            setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
    -            setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" );
    -            setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
    +            setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
    +            setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
    +            setTestProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false");
    +            setTestProperty(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com");
     
                 // this should send resetpwd  link in email to newly added org admin user(that did not exist
                 ///in usergrid) and "User Invited To Organization" email
    -            String adminToken = adminToken();
    -            JsonNode node = postAddAdminToOrg( "test-organization", "test-admin-nopwd@mockserver.com", "", adminToken );
    -            String uuid = node.get( "data" ).get( "user" ).get( "uuid" ).textValue();
    -            UUID userId = UUID.fromString( uuid );
    +            Entity node = postAddAdminToOrg("test-organization", "test-admin-nopwd@mockserver.com", "", getAdminToken());
    --- End diff --
    
    Probably don't want to use the default organization because we might have the test-organization disabled in the properties file. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---