usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject git commit: Further consolidated the tests
Date Wed, 17 Sep 2014 21:52:24 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o-rest-refactor f42ebde4e -> 66b8ecb9e


Further consolidated the tests


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

Branch: refs/heads/two-dot-o-rest-refactor
Commit: 66b8ecb9e4951765e6514a2e851f2ffec9718dc5
Parents: f42ebde
Author: grey <greyes@apigee.com>
Authored: Wed Sep 17 14:52:20 2014 -0700
Committer: grey <greyes@apigee.com>
Committed: Wed Sep 17 14:52:20 2014 -0700

----------------------------------------------------------------------
 .../usergrid/rest/ConcurrentRestITSuite.java    |  12 +-
 .../org/apache/usergrid/rest/RestITSuite.java   |   9 +-
 .../usergrid/rest/management/AccessTokenIT.java |  81 ++++
 .../rest/management/ApplicationsIT.java         | 251 +++++++++++++
 .../rest/management/ManagementResourceIT.java   | 284 --------------
 .../rest/management/OrganizationsIT.java        | 191 ++++++++++
 .../rest/management/RegistrationIT.java         | 369 -------------------
 .../organizations/AdminEmailEncodingIT.java     | 119 ------
 .../applications/ApplicationsIT.java            |  91 -----
 9 files changed, 529 insertions(+), 878 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66b8ecb9/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java b/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java
index 4456054..9a404bf 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java
@@ -36,22 +36,16 @@ import org.apache.usergrid.rest.applications.users.OwnershipResourceIT;
 import org.apache.usergrid.rest.applications.users.PermissionsResourceIT;
 import org.apache.usergrid.rest.applications.users.UserResourceIT;
 import org.apache.usergrid.rest.filters.ContentTypeResourceIT;
-import org.apache.usergrid.rest.management.ManagementResourceIT;
-import org.apache.usergrid.rest.management.RegistrationIT;
-import org.apache.usergrid.rest.management.organizations.AdminEmailEncodingIT;
-import org.apache.usergrid.rest.management.users.organizations.UsersOrganizationsResourceIT;
 
 
 @RunWith(ConcurrentSuite.class)
 @Suite.SuiteClasses(
         {
-                ActivityResourceIT.class, AdminEmailEncodingIT.class, ApplicationRequestCounterIT.class,
+                ActivityResourceIT.class, ApplicationRequestCounterIT.class,
                 ApplicationResourceIT.class, AssetResourceIT.class, BasicIT.class, CollectionsResourceIT.class,
                 ContentTypeResourceIT.class, DevicesResourceIT.class, EventsResourceIT.class, GroupResourceIT.class,
-                MUUserResourceIT.class, ManagementResourceIT.class, OrganizationResourceIT.class,
-                OrganizationsResourceIT.class, OwnershipResourceIT.class, PagingResourceIT.class,
-                PermissionsResourceIT.class, RegistrationIT.class, UserResourceIT.class,
-                UsersOrganizationsResourceIT.class
+                OwnershipResourceIT.class, PagingResourceIT.class,
+                PermissionsResourceIT.class, UserResourceIT.class
         })
 @Concurrent()
 public class ConcurrentRestITSuite {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66b8ecb9/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java b/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java
index dbf8834..7630bb1 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java
@@ -34,17 +34,14 @@ import org.apache.usergrid.rest.applications.users.OwnershipResourceIT;
 import org.apache.usergrid.rest.applications.users.PermissionsResourceIT;
 import org.apache.usergrid.rest.applications.users.UserResourceIT;
 import org.apache.usergrid.rest.filters.ContentTypeResourceIT;
-import org.apache.usergrid.rest.management.organizations.AdminEmailEncodingIT;
-import org.apache.usergrid.rest.management.users.organizations.UsersOrganizationsResourceIT;
 
 @RunWith(Suite.class)
 @Suite.SuiteClasses(
         {
-            ActivityResourceIT.class, AdminEmailEncodingIT.class, ApplicationRequestCounterIT.class,
+            ActivityResourceIT.class, ApplicationRequestCounterIT.class,
             AssetResourceIT.class, BasicIT.class, CollectionsResourceIT.class, ContentTypeResourceIT.class,
-            DevicesResourceIT.class, EventsResourceIT.class, GroupResourceIT.class, OrganizationResourceIT.class,
-            OrganizationsResourceIT.class, OwnershipResourceIT.class, PagingResourceIT.class,
-            PermissionsResourceIT.class, UserResourceIT.class, UsersOrganizationsResourceIT.class
+            DevicesResourceIT.class, EventsResourceIT.class, GroupResourceIT.class, OwnershipResourceIT.class, PagingResourceIT.class,
+            PermissionsResourceIT.class, UserResourceIT.class
         })
 @Concurrent()
 public class RestITSuite {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66b8ecb9/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
index 75743cb..d769870 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
@@ -7,10 +7,13 @@ import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
 
+import org.junit.Rule;
 import org.junit.Test;
 
 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.security.TestAdminUser;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.sun.jersey.api.client.ClientResponse;
@@ -328,6 +331,84 @@ public class AccessTokenIT extends AbstractRestIT {
         assertEquals( ClientResponse.Status.OK, status );
     }
 
+    //Done for AdminEmailEncoding Tests
+    @Rule
+    public TestContextSetup context = new TestContextSetup( this );
+
+
+    @Test
+    public void getTokenPlus() throws Exception {
+        String org = "AdminEmailEncodingTestgetTokenPlus";
+        String app = "Plus";
+
+        doTest( "+", org, app );
+    }
+
+
+    @Test
+    public void getTokenUnderscore() throws Exception {
+        String org = "AdminEmailEncodingTestgetTokenUnderscore";
+        String app = "Underscore";
+
+        doTest( "_", org, app );
+    }
+
+
+    @Test
+    public void getTokenDash() throws Exception {
+        String org = "AdminEmailEncodingTestgetTokenDash";
+        String app = "Dash";
+
+        doTest( "-", org, app );
+    }
+
+
+    private void doTest( String symbol, String org, String app ) throws IOException {
+
+        org = org.toLowerCase();
+        app = app.toLowerCase();
+
+        String email = String.format( "admin%sname@adminemailencodingtest.org", symbol );
+        String user = email;
+        String password = "password";
+
+        TestAdminUser adminUser = new TestAdminUser( user, password, email );
+
+        context.withApp( app ).withOrg( org ).withUser( adminUser );
+
+        // create the org and app
+        context.createNewOrgAndUser();
+
+        // no need for refresh here as Service module does an index refresh when org/app created
+
+        // now log in via a GET
+
+        String getToken = context.management().tokenGet( email, password );
+
+        assertNotNull( getToken );
+
+        String postToken = context.management().tokenPost( email, password );
+
+        assertNotNull( postToken );
+
+        // not log in with our admin
+        context.withUser( adminUser ).loginUser();
+
+        //now get the "me" and ensure it's correct
+
+        JsonNode data = context.management().me().get();
+
+        assertNotNull( data.get( "access_token" ).asText() );
+
+        data = context.management().users().user( email ).get();
+
+        JsonNode admin = data.get( "data" ).get( "organizations" ).get( org ).get( "users" ).get( email );
+
+        assertNotNull( admin );
+
+        assertEquals( email, admin.get( "email" ).asText() );
+        assertEquals( user, admin.get( "username" ).asText() );
+    }
 
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66b8ecb9/stack/rest/src/test/java/org/apache/usergrid/rest/management/ApplicationsIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ApplicationsIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ApplicationsIT.java
new file mode 100644
index 0000000..05e56a3
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ApplicationsIT.java
@@ -0,0 +1,251 @@
+/*
+ * 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.management;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.util.UUID;
+
+import javax.ws.rs.core.MediaType;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.usergrid.management.OrganizationInfo;
+import org.apache.usergrid.rest.AbstractRestIT;
+import org.apache.usergrid.rest.TestContextSetup;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Ignore;
+
+
+/**
+ *
+ *
+ */
+public class ApplicationsIT extends AbstractRestIT {
+
+    @Rule
+    public TestContextSetup context = new TestContextSetup( this );
+
+
+    @Test
+    @Ignore("ignored because this test fails because it does not account for the default app "
+            + "created by the TestContext and the sandbox app. "
+            + "see also: https://issues.apache.org/jira/browse/USERGRID-210 ")
+    public void test10AppLimit() throws IOException {
+
+        int size = 11;
+
+        Set<String> appNames = new HashSet<String>( size );
+
+        for ( int i = 0; i < size; i++ ) {
+            final String name = i + "";
+
+            appNames.add( name );
+
+            context.withApp( name ).createAppForOrg();
+            refreshIndex(context.getOrgName(), name);
+        }
+
+
+        //now go through and ensure each entry is present
+
+        final JsonNode apps = context.management().orgs().organization( context.getOrgName() ).apps().get();
+
+        final JsonNode data = apps.get( "data" );
+
+        final String orgName = context.getOrgName();
+
+
+        final Set<String> copy = new HashSet<String> (appNames);
+
+        for(String appName: copy){
+
+            final String mapEntryName = String.format( "%s/%s", orgName.toLowerCase(),  appName.toLowerCase());
+
+            JsonNode orgApp = data.get( mapEntryName);
+
+            if(orgApp != null){
+                appNames.remove( appName );
+            }
+
+        }
+
+        assertEquals("All elements removed", 0, appNames.size());
+
+    }
+    /**
+     * Test that we can support over 10 items in feed.
+     */
+    @Test
+    public void mgmtFollowsUserFeed() throws Exception {
+        List<String> users1 = new ArrayList<String>();
+        int i;
+        //try with 10 users
+        for ( i = 0; i < 10; i++ ) {
+            users1.add( "follower" + Integer.toString( i ) );
+        }
+
+        refreshIndex("test-organization", "test-app");
+
+        checkFeed( "leader1", users1 );
+        //try with 11
+        List<String> users2 = new ArrayList<String>();
+        for ( i = 20; i < 31; i++ ) {
+            users2.add( "follower" + Integer.toString( i ) );
+        }
+        checkFeed( "leader2", users2 );
+    }
+
+
+    private void checkFeed( String leader, List<String> followers ) throws IOException {
+        JsonNode userFeed;
+
+        //create user
+        createUser( leader );
+        refreshIndex("test-organization", "test-app");
+
+        String preFollowContent = leader + ": pre-something to look for " + UUID.randomUUID().toString();
+
+        addActivity( leader, leader + " " + leader + "son", preFollowContent );
+        refreshIndex("test-organization", "test-app");
+
+        String lastUser = followers.get( followers.size() - 1 );
+        int i = 0;
+        for ( String user : followers ) {
+            createUser( user );
+            refreshIndex("test-organization", "test-app");
+            follow( user, leader );
+            refreshIndex("test-organization", "test-app");
+        }
+        userFeed = getUserFeed( lastUser );
+        assertTrue( userFeed.size() == 1 );
+
+        //retrieve feed
+        userFeed = getUserFeed( lastUser );
+        assertTrue( userFeed.size() == 1 );
+        String postFollowContent = leader + ": something to look for " + UUID.randomUUID().toString();
+        addActivity( leader, leader + " " + leader + "son", postFollowContent );
+
+        refreshIndex("test-organization", "test-app");
+
+        //check feed
+        userFeed = getUserFeed( lastUser );
+        assertNotNull( userFeed );
+        assertTrue( userFeed.size() > 1 );
+        String serialized = userFeed.toString();
+        assertTrue( serialized.indexOf( postFollowContent ) > 0 );
+        assertTrue( serialized.indexOf( preFollowContent ) > 0 );
+    }
+
+
+    private void createUser( String username ) {
+        Map<String, Object> payload = new LinkedHashMap<String, Object>();
+        payload.put( "username", username );
+        resource().path( "/test-organization/test-app/users" ).queryParam( "access_token", access_token )
+                  .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                  .post( String.class, payload );
+    }
+
+
+    private JsonNode getUserFeed( String username ) throws IOException {
+        JsonNode userFeed = mapper.readTree( resource().path( "/test-organization/test-app/users/" + username + "/feed" )
+                                                       .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
+                                                       .get( String.class ));
+        return userFeed.get( "entities" );
+    }
+
+
+    private void follow( String user, String followUser ) {
+        //post follow
+        resource().path( "/test-organization/test-app/users/" + user + "/following/users/" + followUser )
+                  .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
+                  .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, new HashMap<String, String>() );
+    }
+
+
+    private void addActivity( String user, String name, String content ) {
+        Map<String, Object> activityPayload = new HashMap<String, Object>();
+        activityPayload.put( "content", content );
+        activityPayload.put( "verb", "post" );
+        Map<String, String> actorMap = new HashMap<String, String>();
+        actorMap.put( "displayName", name );
+        actorMap.put( "username", user );
+        activityPayload.put( "actor", actorMap );
+        resource().path( "/test-organization/test-app/users/" + user + "/activities" )
+                  .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
+                  .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, activityPayload );
+    }
+
+
+    @Test
+    public void mgmtCreateAndGetApplication() throws Exception {
+
+        OrganizationInfo orgInfo = setup.getMgmtSvc().getOrganizationByName( "test-organization" );
+        Map<String, String> data = new HashMap<String, String>();
+        data.put( "name", "mgmt-org-app" );
+
+        // POST /applications
+        JsonNode appdata = mapper.readTree( resource().path( "/management/orgs/" + orgInfo.getUuid() + "/applications" )
+                                                      .queryParam( "access_token", adminToken() ).accept( MediaType.APPLICATION_JSON )
+                                                      .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
+        logNode( appdata );
+        appdata = getEntity( appdata, 0 );
+
+        refreshIndex("test-organization", "test-app");
+
+        assertEquals( "test-organization/mgmt-org-app", appdata.get( "name" ).asText() );
+        assertNotNull(appdata.get( "metadata" ));
+        assertNotNull(appdata.get( "metadata" ).get( "collections" ));
+        assertNotNull(appdata.get( "metadata" ).get( "collections" ).get( "roles" ));
+        assertNotNull(appdata.get( "metadata" ).get( "collections" ).get( "roles" ).get( "title" ));
+        assertEquals( "Roles", appdata.get( "metadata" ).get( "collections" ).get( "roles" ).get( "title" ).asText() );
+        assertEquals( 3, appdata.get( "metadata" ).get( "collections" ).get( "roles" ).get( "count" ).asInt() );
+
+        refreshIndex("test-organization", "test-app");
+
+        // GET /applications/mgmt-org-app
+        appdata = mapper.readTree( resource().path( "/management/orgs/" + orgInfo.getUuid() + "/applications/mgmt-org-app" )
+                                             .queryParam( "access_token", adminToken() ).accept( MediaType.APPLICATION_JSON )
+                                             .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+        logNode( appdata );
+
+        assertEquals( "test-organization", appdata.get( "organization" ).asText() );
+        assertEquals( "mgmt-org-app", appdata.get( "applicationName" ).asText() );
+        assertEquals( "http://sometestvalue/test-organization/mgmt-org-app", appdata.get( "uri" ).textValue() );
+        appdata = getEntity( appdata, 0 );
+
+        assertEquals( "test-organization/mgmt-org-app", appdata.get( "name" ).asText() );
+        assertEquals( "Roles", appdata.get( "metadata" ).get( "collections" ).get( "roles" ).get( "title" ).asText() );
+        assertEquals( 3, appdata.get( "metadata" ).get( "collections" ).get( "roles" ).get( "count" ).asInt() );
+    }
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66b8ecb9/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
deleted file mode 100644
index 58691a1..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * 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.management;
-
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.core.MediaType;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import org.junit.Test;
-
-import org.apache.commons.lang.StringUtils;
-
-import org.apache.usergrid.cassandra.Concurrent;
-import org.apache.usergrid.management.OrganizationInfo;
-import org.apache.usergrid.management.OrganizationOwnerInfo;
-import org.apache.usergrid.rest.AbstractRestIT;
-import org.apache.usergrid.rest.management.organizations.OrganizationsResource;
-
-import com.sun.jersey.api.client.ClientResponse.Status;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.representation.Form;
-import java.io.IOException;
-
-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;
-import static org.junit.Assert.assertTrue;
-
-
-/**
- * @author tnine
- */
-@Concurrent()
-public class ManagementResourceIT extends AbstractRestIT {
-
-    public ManagementResourceIT() throws Exception {
-
-    }
-
-
-
-
-    /**
-     * Test that admins can't view organizations they're not authorized to view.
-     */
-    @Test
-    public void crossOrgsNotViewable() throws Exception {
-
-        OrganizationOwnerInfo orgInfo = setup.getMgmtSvc().createOwnerAndOrganization( "crossOrgsNotViewable",
-                "crossOrgsNotViewable", "TestName", "crossOrgsNotViewable@usergrid.org", "password" );
-
-        refreshIndex("test-organization", "test-app");
-
-        // check that the test admin cannot access the new org info
-
-        Status status = null;
-
-        try {
-            resource().path( String.format( "/management/orgs/%s", orgInfo.getOrganization().getName() ) )
-                      .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON )
-                      .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class );
-        }
-        catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertNotNull( status );
-        assertEquals( Status.UNAUTHORIZED, status );
-
-        status = null;
-
-        try {
-            resource().path( String.format( "/management/orgs/%s", orgInfo.getOrganization().getUuid() ) )
-                      .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON )
-                      .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class );
-        }
-        catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertNotNull( status );
-        assertEquals( Status.UNAUTHORIZED, status );
-
-        // this admin should have access to test org
-        status = null;
-        try {
-            resource().path( "/management/orgs/test-organization" ).queryParam( "access_token", adminAccessToken )
-                      .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                      .get( String.class );
-        }
-        catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertNull( status );
-
-        OrganizationInfo org = setup.getMgmtSvc().getOrganizationByName( "test-organization" );
-
-        status = null;
-        try {
-            resource().path( String.format( "/management/orgs/%s", org.getUuid() ) )
-                      .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON )
-                      .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class );
-        }
-        catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertNull( status );
-    }
-
-
-
-
-
-    /**
-     * Test that we can support over 10 items in feed.
-     */
-    @Test
-    public void mgmtFollowsUserFeed() throws Exception {
-        List<String> users1 = new ArrayList<String>();
-        int i;
-        //try with 10 users
-        for ( i = 0; i < 10; i++ ) {
-            users1.add( "follower" + Integer.toString( i ) );
-        }
-
-        refreshIndex("test-organization", "test-app");
-
-        checkFeed( "leader1", users1 );
-        //try with 11
-        List<String> users2 = new ArrayList<String>();
-        for ( i = 20; i < 31; i++ ) {
-            users2.add( "follower" + Integer.toString( i ) );
-        }
-        checkFeed( "leader2", users2 );
-    }
-
-
-    private void checkFeed( String leader, List<String> followers ) throws IOException {
-        JsonNode userFeed;
-
-        //create user
-        createUser( leader );
-        refreshIndex("test-organization", "test-app");
-
-        String preFollowContent = leader + ": pre-something to look for " + UUID.randomUUID().toString();
-
-        addActivity( leader, leader + " " + leader + "son", preFollowContent );
-        refreshIndex("test-organization", "test-app");
-        
-        String lastUser = followers.get( followers.size() - 1 );
-        int i = 0;
-        for ( String user : followers ) {
-            createUser( user );
-            refreshIndex("test-organization", "test-app");
-            follow( user, leader );
-            refreshIndex("test-organization", "test-app");
-        }
-        userFeed = getUserFeed( lastUser );
-        assertTrue( userFeed.size() == 1 );
-
-        //retrieve feed
-        userFeed = getUserFeed( lastUser );
-        assertTrue( userFeed.size() == 1 );
-        String postFollowContent = leader + ": something to look for " + UUID.randomUUID().toString();
-        addActivity( leader, leader + " " + leader + "son", postFollowContent );
-
-        refreshIndex("test-organization", "test-app");
-
-        //check feed
-        userFeed = getUserFeed( lastUser );
-        assertNotNull( userFeed );
-        assertTrue( userFeed.size() > 1 );
-        String serialized = userFeed.toString();
-        assertTrue( serialized.indexOf( postFollowContent ) > 0 );
-        assertTrue( serialized.indexOf( preFollowContent ) > 0 );
-    }
-
-
-    private void createUser( String username ) {
-        Map<String, Object> payload = new LinkedHashMap<String, Object>();
-        payload.put( "username", username );
-        resource().path( "/test-organization/test-app/users" ).queryParam( "access_token", access_token )
-                  .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                  .post( String.class, payload );
-    }
-
-
-    private JsonNode getUserFeed( String username ) throws IOException {
-        JsonNode userFeed = mapper.readTree( resource().path( "/test-organization/test-app/users/" + username + "/feed" )
-                                      .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-                                      .get( String.class ));
-        return userFeed.get( "entities" );
-    }
-
-
-    private void follow( String user, String followUser ) {
-        //post follow
-        resource().path( "/test-organization/test-app/users/" + user + "/following/users/" + followUser )
-                  .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-                  .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, new HashMap<String, String>() );
-    }
-
-
-    private void addActivity( String user, String name, String content ) {
-        Map<String, Object> activityPayload = new HashMap<String, Object>();
-        activityPayload.put( "content", content );
-        activityPayload.put( "verb", "post" );
-        Map<String, String> actorMap = new HashMap<String, String>();
-        actorMap.put( "displayName", name );
-        actorMap.put( "username", user );
-        activityPayload.put( "actor", actorMap );
-        resource().path( "/test-organization/test-app/users/" + user + "/activities" )
-                  .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-                  .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, activityPayload );
-    }
-
-
-    @Test
-    public void mgmtCreateAndGetApplication() throws Exception {
-
-        OrganizationInfo orgInfo = setup.getMgmtSvc().getOrganizationByName( "test-organization" );
-        Map<String, String> data = new HashMap<String, String>();
-        data.put( "name", "mgmt-org-app" );
-
-        // POST /applications
-        JsonNode appdata = mapper.readTree( resource().path( "/management/orgs/" + orgInfo.getUuid() + "/applications" )
-                                     .queryParam( "access_token", adminToken() ).accept( MediaType.APPLICATION_JSON )
-                                     .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
-        logNode( appdata );
-        appdata = getEntity( appdata, 0 );
-
-        refreshIndex("test-organization", "test-app");
-
-        assertEquals( "test-organization/mgmt-org-app", appdata.get( "name" ).asText() );
-        assertNotNull(appdata.get( "metadata" ));
-        assertNotNull(appdata.get( "metadata" ).get( "collections" ));
-        assertNotNull(appdata.get( "metadata" ).get( "collections" ).get( "roles" ));
-        assertNotNull(appdata.get( "metadata" ).get( "collections" ).get( "roles" ).get( "title" ));
-        assertEquals( "Roles", appdata.get( "metadata" ).get( "collections" ).get( "roles" ).get( "title" ).asText() );
-        assertEquals( 3, appdata.get( "metadata" ).get( "collections" ).get( "roles" ).get( "count" ).asInt() );
-
-        refreshIndex("test-organization", "test-app");
-
-        // GET /applications/mgmt-org-app
-        appdata = mapper.readTree( resource().path( "/management/orgs/" + orgInfo.getUuid() + "/applications/mgmt-org-app" )
-                            .queryParam( "access_token", adminToken() ).accept( MediaType.APPLICATION_JSON )
-                            .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-        logNode( appdata );
-
-        assertEquals( "test-organization", appdata.get( "organization" ).asText() );
-        assertEquals( "mgmt-org-app", appdata.get( "applicationName" ).asText() );
-        assertEquals( "http://sometestvalue/test-organization/mgmt-org-app", appdata.get( "uri" ).textValue() );
-        appdata = getEntity( appdata, 0 );
-
-        assertEquals( "test-organization/mgmt-org-app", appdata.get( "name" ).asText() );
-        assertEquals( "Roles", appdata.get( "metadata" ).get( "collections" ).get( "roles" ).get( "title" ).asText() );
-        assertEquals( 3, appdata.get( "metadata" ).get( "collections" ).get( "roles" ).get( "count" ).asInt() );
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66b8ecb9/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
index 2a72bc5..35517c5 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
@@ -3,9 +3,14 @@ package org.apache.usergrid.rest.management;
 
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.UUID;
 
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMultipart;
 import javax.ws.rs.core.MediaType;
 
 import org.junit.Rule;
@@ -13,8 +18,11 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.apache.commons.lang.StringUtils;
+
 import org.apache.usergrid.management.ApplicationInfo;
 import org.apache.usergrid.management.OrganizationInfo;
+import org.apache.usergrid.management.OrganizationOwnerInfo;
 import org.apache.usergrid.management.UserInfo;
 import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.entities.User;
@@ -36,7 +44,9 @@ import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYS
 import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_EMAIL;
 import static org.apache.usergrid.utils.MapUtils.hashMap;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 
@@ -359,4 +369,185 @@ public class OrganizationsIT extends AbstractRestIT {
                     .asInt() );
     }
 
+
+    /**
+     * Test that admins can't view organizations they're not authorized to view.
+     */
+    @Test
+    public void crossOrgsNotViewable() throws Exception {
+
+        OrganizationOwnerInfo orgInfo = setup.getMgmtSvc().createOwnerAndOrganization( "crossOrgsNotViewable",
+                "crossOrgsNotViewable", "TestName", "crossOrgsNotViewable@usergrid.org", "password" );
+
+        refreshIndex("test-organization", "test-app");
+
+        // check that the test admin cannot access the new org info
+
+        ClientResponse.Status status = null;
+
+        try {
+            resource().path( String.format( "/management/orgs/%s", orgInfo.getOrganization().getName() ) )
+                      .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON )
+                      .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class );
+        }
+        catch ( UniformInterfaceException uie ) {
+            status = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertNotNull( status );
+        assertEquals( ClientResponse.Status.UNAUTHORIZED, status );
+
+        status = null;
+
+        try {
+            resource().path( String.format( "/management/orgs/%s", orgInfo.getOrganization().getUuid() ) )
+                      .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON )
+                      .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class );
+        }
+        catch ( UniformInterfaceException uie ) {
+            status = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertNotNull( status );
+        assertEquals( ClientResponse.Status.UNAUTHORIZED, status );
+
+        // this admin should have access to test org
+        status = null;
+        try {
+            resource().path( "/management/orgs/test-organization" ).queryParam( "access_token", adminAccessToken )
+                      .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                      .get( String.class );
+        }
+        catch ( UniformInterfaceException uie ) {
+            status = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertNull( status );
+
+        OrganizationInfo org = setup.getMgmtSvc().getOrganizationByName( "test-organization" );
+
+        status = null;
+        try {
+            resource().path( String.format( "/management/orgs/%s", org.getUuid() ) )
+                      .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON )
+                      .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class );
+        }
+        catch ( UniformInterfaceException uie ) {
+            status = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertNull( status );
+    }
+
+    @Test
+    public void postCreateOrgAndAdmin() throws Exception {
+
+        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, "false" );
+            setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
+
+            JsonNode node = postCreateOrgAndAdmin( "test-org-1", "test-user-1", "Test User",
+                    "test-user-1@mockserver.com", "testpassword" );
+
+            if (true ) return;
+
+            refreshIndex("test-organization", "test-app");
+
+            UUID owner_uuid =
+                    UUID.fromString( node.findPath( "data" ).findPath( "owner" ).findPath( "uuid" ).textValue() );
+
+            List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get( "test-user-1@mockserver.com" );
+
+            assertFalse( inbox.isEmpty() );
+
+            Message account_confirmation_message = inbox.get( 0 );
+            assertEquals( "User Account Confirmation: test-user-1@mockserver.com",
+                    account_confirmation_message.getSubject() );
+
+            String token = getTokenFromMessage( account_confirmation_message );
+            LOG.info( token );
+
+            setup.getMgmtSvc().disableAdminUser( owner_uuid );
+
+            refreshIndex("test-organization", "test-app");
+
+            try {
+                resource().path( "/management/token" ).queryParam( "grant_type", "password" )
+                          .queryParam( "username", "test-user-1" ).queryParam( "password", "testpassword" )
+                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                          .get( String.class );
+                org.junit.Assert.fail( "request for disabled user should fail" );
+            }
+            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() );
+            }
+
+            setup.getMgmtSvc().deactivateUser( setup.getEmf().getManagementAppId(), owner_uuid );
+            try {
+                resource().path( "/management/token" ).queryParam( "grant_type", "password" )
+                          .queryParam( "username", "test-user-1" ).queryParam( "password", "testpassword" )
+                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                          .get( String.class );
+                org.junit.Assert.fail( "request for deactivated user should fail" );
+            }
+            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() );
+            }
+
+            // 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 );
+        }
+    }
+
+
+    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;
+    }
+
+
+    public JsonNode postCreateOrgAndAdmin( String organizationName, String username, String name,
+                                           String email, String password ) throws IOException {
+
+        JsonNode node = null;
+        Map<String, String> payload = hashMap( "email", email )
+                .map( "username", username )
+                .map( "name", name ).map( "password", password )
+                .map( "organization", organizationName );
+
+        node = mapper.readTree( resource().path( "/management/organizations" )
+                                          .accept( MediaType.APPLICATION_JSON )
+                                          .type( MediaType.APPLICATION_JSON_TYPE )
+                                          .post( String.class, payload ));
+
+        assertNotNull( node );
+        logNode( node );
+        return node;
+    }
+
+    //
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66b8ecb9/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java
deleted file mode 100644
index 580be03..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
- * 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.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.fasterxml.jackson.databind.JsonNode;
-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.rest.AbstractRestIT;
-
-import org.apache.commons.lang.StringUtils;
-
-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;
-
-
-public class RegistrationIT extends AbstractRestIT {
-
-    private static final Logger logger = LoggerFactory.getLogger( RegistrationIT.class );
-
-
-    @Test
-    public void postCreateOrgAndAdmin() throws Exception {
-
-        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, "false" );
-            setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
-
-            JsonNode node = postCreateOrgAndAdmin( "test-org-1", "test-user-1", "Test User", 
-                    "test-user-1@mockserver.com", "testpassword" );
-
-            if (true ) return;
-            
-            refreshIndex("test-organization", "test-app");
-
-            UUID owner_uuid =
-                    UUID.fromString( node.findPath( "data" ).findPath( "owner" ).findPath( "uuid" ).textValue() );
-
-            List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get( "test-user-1@mockserver.com" );
-
-            assertFalse( inbox.isEmpty() );
-
-            Message account_confirmation_message = inbox.get( 0 );
-            assertEquals( "User Account Confirmation: test-user-1@mockserver.com",
-                    account_confirmation_message.getSubject() );
-
-            String token = getTokenFromMessage( account_confirmation_message );
-            logger.info( token );
-
-            setup.getMgmtSvc().disableAdminUser( owner_uuid );
-
-            refreshIndex("test-organization", "test-app");
-
-            try {
-                resource().path( "/management/token" ).queryParam( "grant_type", "password" )
-                        .queryParam( "username", "test-user-1" ).queryParam( "password", "testpassword" )
-                        .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                        .get( String.class );
-                fail( "request for disabled user should fail" );
-            }
-            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() );
-            }
-
-            setup.getMgmtSvc().deactivateUser( setup.getEmf().getManagementAppId(), owner_uuid );
-            try {
-                resource().path( "/management/token" ).queryParam( "grant_type", "password" )
-                        .queryParam( "username", "test-user-1" ).queryParam( "password", "testpassword" )
-                        .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                        .get( String.class );
-                fail( "request for deactivated user should fail" );
-            }
-            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() );
-            }
-
-            // 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 );
-        }
-    }
-
-
-    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;
-    }
-
-
-    public JsonNode postCreateOrgAndAdmin( String organizationName, String username, String name, 
-            String email, String password ) throws IOException {
-
-        JsonNode node = null;
-        Map<String, String> payload = hashMap( "email", email )
-                .map( "username", username )
-                .map( "name", name ).map( "password", password )
-                .map( "organization", organizationName );
-
-        node = mapper.readTree( resource().path( "/management/organizations" )
-                .accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE )
-                .post( String.class, payload ));
-
-        assertNotNull( node );
-        logNode( node );
-        return node;
-    }
-
-
-    @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();
-
-        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" );
-            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() );
-            }
-        }
-        finally {
-            setTestProperties( originalProperties );
-        }
-    }
-
-
-    @Test
-    public void postAddToOrganization() throws Exception {
-
-        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, "false" );
-            setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
-
-            String t = adminToken();
-            postAddAdminToOrg( "test-organization", "test-admin@mockserver.com", "password", t );
-        }
-        finally {
-            setTestProperties( originalProperties );
-        }
-    }
-
-
-    @Test
-    public void addNewAdminUserWithNoPwdToOrganization() throws Exception {
-
-        Map<String, String> 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" );
-
-            // 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 );
-
-            refreshIndex("test-organization", "test-app");
-
-            String subject = "Password Reset";
-            String reset_url = String.format( setup.getProps().getProperty( PROPERTIES_ADMIN_RESETPW_URL ), uuid );
-            String invited = "User Invited To Organization";
-
-            Message[] msgs = getMessages( "mockserver.com", "test-admin-nopwd", "password" );
-
-            // 1 Invite and 1 resetpwd
-            assertTrue( msgs.length == 2 );
-
-            //email subject
-            assertEquals( subject, msgs[0].getSubject() );
-            assertEquals( invited, msgs[1].getSubject() );
-
-            // reseturl
-            String mailContent = ( String ) ( ( MimeMultipart ) msgs[0].getContent() ).getBodyPart( 1 ).getContent();
-            logger.info( mailContent );
-            assertTrue( StringUtils.contains( mailContent, reset_url ) );
-
-            //token
-            String token = getTokenFromMessage( msgs[0] );
-            assertTrue( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userId, token ) );
-        }
-        finally {
-            setTestProperties( originalProperties );
-        }
-    }
-
-
-    @Test
-    public void addExistingAdminUserToOrganization() throws Exception {
-
-        Map<String, String> 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" );
-
-            // svcSetup an admin user
-            String adminUserName = "AdminUserFromOtherOrg";
-            String adminUserEmail = "AdminUserFromOtherOrg@otherorg.com";
-
-            UserInfo adminUser = setup.getMgmtSvc().createAdminUser( 
-                    adminUserEmail, adminUserEmail, adminUserEmail, "password1", true, false );
-
-            refreshIndex("test-organization", "test-app");
-
-            assertNotNull( adminUser );
-            Message[] msgs = getMessages( "otherorg.com", adminUserName, "password1" );
-            assertEquals( 1, msgs.length );
-
-            // add existing admin user to org
-
-            // this should NOT send resetpwd link in email to newly added org admin user(that
-            // already exists in usergrid) only "User Invited To Organization" email
-            String adminToken = adminToken();
-            JsonNode node = postAddAdminToOrg( "test-organization", 
-                    adminUserEmail, "password1", adminToken );
-            String uuid = node.get( "data" ).get( "user" ).get( "uuid" ).textValue();
-            UUID userId = UUID.fromString( uuid );
-
-            assertEquals( adminUser.getUuid(), userId );
-
-            msgs = getMessages( "otherorg.com", adminUserName, "password1" );
-
-            // only 1 invited msg
-            assertEquals( 2, msgs.length );
-
-            // check email subject
-            String resetpwd = "Password Reset";
-            assertNotSame( resetpwd, msgs[1].getSubject() );
-
-            String invited = "User Invited To Organization";
-            assertEquals( invited, msgs[1].getSubject() );
-        }
-        finally {
-            setTestProperties( originalProperties );
-        }
-    }
-
-
-    private Message[] getMessages( String host, String user, String password ) throws MessagingException, IOException {
-
-        Session session = Session.getDefaultInstance( new Properties() );
-        Store store = session.getStore( "imap" );
-        store.connect( host, user, password );
-
-        Folder folder = store.getFolder( "inbox" );
-        folder.open( Folder.READ_ONLY );
-        Message[] msgs = folder.getMessages();
-
-        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;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66b8ecb9/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/AdminEmailEncodingIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/AdminEmailEncodingIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/AdminEmailEncodingIT.java
deleted file mode 100644
index 145ccd3..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/AdminEmailEncodingIT.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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.management.organizations;
-
-
-import com.fasterxml.jackson.databind.JsonNode;
-import java.io.IOException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.apache.usergrid.cassandra.Concurrent;
-import org.apache.usergrid.rest.AbstractRestIT;
-import org.apache.usergrid.rest.TestContextSetup;
-import org.apache.usergrid.rest.test.security.TestAdminUser;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-
-/**
- * Tests for admin emails with + signs create accounts correctly, and can get tokens in both the POST and GET forms of
- * the api
- *
- * @author tnine
- */
-@Concurrent()
-public class AdminEmailEncodingIT extends AbstractRestIT {
-
-    @Rule
-    public TestContextSetup context = new TestContextSetup( this );
-
-
-    @Test
-    public void getTokenPlus() throws Exception {
-        String org = "AdminEmailEncodingTestgetTokenPlus";
-        String app = "Plus";
-
-        doTest( "+", org, app );
-    }
-
-
-    @Test
-    public void getTokenUnderscore() throws Exception {
-        String org = "AdminEmailEncodingTestgetTokenUnderscore";
-        String app = "Underscore";
-
-        doTest( "_", org, app );
-    }
-
-
-    @Test
-    public void getTokenDash() throws Exception {
-        String org = "AdminEmailEncodingTestgetTokenDash";
-        String app = "Dash";
-
-        doTest( "-", org, app );
-    }
-
-
-    private void doTest( String symbol, String org, String app ) throws IOException {
-
-        org = org.toLowerCase();
-        app = app.toLowerCase();
-
-        String email = String.format( "admin%sname@adminemailencodingtest.org", symbol );
-        String user = email;
-        String password = "password";
-
-        TestAdminUser adminUser = new TestAdminUser( user, password, email );
-
-        context.withApp( app ).withOrg( org ).withUser( adminUser );
-
-        // create the org and app
-        context.createNewOrgAndUser();
-
-        // no need for refresh here as Service module does an index refresh when org/app created
-
-        // now log in via a GET
-
-        String getToken = context.management().tokenGet( email, password );
-
-        assertNotNull( getToken );
-
-        String postToken = context.management().tokenPost( email, password );
-
-        assertNotNull( postToken );
-
-        // not log in with our admin
-        context.withUser( adminUser ).loginUser();
-
-        //now get the "me" and ensure it's correct
-
-        JsonNode data = context.management().me().get();
-
-        assertNotNull( data.get( "access_token" ).asText() );
-
-        data = context.management().users().user( email ).get();
-
-        JsonNode admin = data.get( "data" ).get( "organizations" ).get( org ).get( "users" ).get( email );
-
-        assertNotNull( admin );
-
-        assertEquals( email, admin.get( "email" ).asText() );
-        assertEquals( user, admin.get( "username" ).asText() );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66b8ecb9/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsIT.java
deleted file mode 100644
index b55e3f7..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsIT.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.management.organizations.applications;
-
-
-import java.util.HashSet;
-import java.util.Set;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import java.io.IOException;
-import org.junit.Rule;
-import org.junit.Test;
-
-import org.apache.usergrid.rest.AbstractRestIT;
-import org.apache.usergrid.rest.TestContextSetup;
-
-import static org.junit.Assert.assertEquals;
-import org.junit.Ignore;
-
-
-/**
- *
- *
- */
-public class ApplicationsIT extends AbstractRestIT {
-
-    @Rule
-    public TestContextSetup context = new TestContextSetup( this );
-
-
-    @Test
-    @Ignore("ignored because this test fails because it does not account for the default app "
-            + "created by the TestContext and the sandbox app. "
-            + "see also: https://issues.apache.org/jira/browse/USERGRID-210 ")
-    public void test10AppLimit() throws IOException {
-
-        int size = 11;
-
-        Set<String> appNames = new HashSet<String>( size );
-
-        for ( int i = 0; i < size; i++ ) {
-            final String name = i + "";
-
-            appNames.add( name );
-
-            context.withApp( name ).createAppForOrg();
-            refreshIndex(context.getOrgName(), name);
-        }
-
-
-        //now go through and ensure each entry is present
-
-        final JsonNode apps = context.management().orgs().organization( context.getOrgName() ).apps().get();
-
-        final JsonNode data = apps.get( "data" );
-
-        final String orgName = context.getOrgName();
-
-
-        final Set<String> copy = new HashSet<String> (appNames);
-
-        for(String appName: copy){
-
-            final String mapEntryName = String.format( "%s/%s", orgName.toLowerCase(),  appName.toLowerCase());
-
-            JsonNode orgApp = data.get( mapEntryName);
-
-            if(orgApp != null){
-                appNames.remove( appName );
-            }
-
-        }
-
-        assertEquals("All elements removed", 0, appNames.size());
-
-    }
-}


Mime
View raw message