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,
"[email protected]" );
+ /**
+ * 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",
-// "[email protected]", "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 [email protected] or file a JIRA ticket
with INFRA.
---