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

[17/23] incubator-usergrid git commit: Changes to allow us to fix the old tests that are broken because tests now share the same C* keyspace, and some fixes to the old ApplicationResourceIT.

Changes to allow us to fix the old tests that are broken because tests now share the same C* keyspace, and some fixes to the old ApplicationResourceIT.


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

Branch: refs/heads/USERGRID-409
Commit: 72fcdda38d55356152e594aeae8e212a5a46b091
Parents: d1880e6
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Feb 25 13:41:49 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Feb 25 13:41:49 2015 -0500

----------------------------------------------------------------------
 .../apache/usergrid/rest/AbstractRestIT.java    | 116 ++++++++-----
 .../applications/ApplicationResourceIT.java     | 174 ++++++++-----------
 2 files changed, 138 insertions(+), 152 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/72fcdda3/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
index 082e436..5f4a534 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
@@ -27,13 +27,14 @@ import com.sun.jersey.test.framework.AppDescriptor;
 import com.sun.jersey.test.framework.JerseyTest;
 import com.sun.jersey.test.framework.WebAppDescriptor;
 import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.usergrid.java.client.Client;
-import org.apache.usergrid.management.ManagementService;
-import org.apache.usergrid.setup.ConcurrentProcessSingleton;
+import org.apache.usergrid.management.ApplicationInfo;
+import org.apache.usergrid.management.OrganizationInfo;
+import org.apache.usergrid.management.OrganizationOwnerInfo;
 
 import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.Rule;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -124,21 +125,43 @@ public abstract class AbstractRestIT extends JerseyTest {
     }
 
 
-    /** Hook to get the token for our base user */
+    public ApplicationInfo appInfo = null;
+    public OrganizationInfo orgInfo = null;
+    public String orgAppPath = null;
+    public String username = null;
+    public String userEmail = null;
+
+    /** Quick fix to get old style test working again. We need them! */
     @Before
-    public void acquireToken() throws Exception {
+    public void setupOrgApp() throws Exception {
+
+        setup.getMgmtSvc().setup();
+
+        String rand = RandomStringUtils.randomAlphanumeric(5);
+
+        orgInfo = setup.getMgmtSvc().getOrganizationByName("test-organization");
+        if ( orgInfo == null  ) {
+            OrganizationOwnerInfo orgOwnerInfo = setup.getMgmtSvc().createOwnerAndOrganization(
+                "test-organization" + rand, "test", "test", "test@usergrid.org", rand, false, false);
+            orgInfo = orgOwnerInfo.getOrganization();
+        }
+
+        appInfo = setup.getMgmtSvc().createApplication(orgInfo.getUuid(), "app-" + rand);
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
+
+        orgAppPath = appInfo.getName() + "/";
+        adminToken();
+
+        setupUsers();
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
+
+        loginClient();
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
+
+        LOG.info( "acquiring token" );
+        access_token = userToken( userEmail, "sesame" );
+        LOG.info( "with token: {}", access_token );
 
-//        setupUsers();
-//
-//        refreshIndex("test-organization", "test-app");
-//
-//        LOG.info( "acquiring token" );
-//        access_token = userToken( "ed@anuff.com", "sesame" );
-//        LOG.info( "with token: {}", access_token );
-//
-//        loginClient();
-//
-//        refreshIndex("test-organization", "test-app");
     }
 
 
@@ -159,39 +182,35 @@ public abstract class AbstractRestIT extends JerseyTest {
     }
 
 
-    protected void setupUsers() {
+    protected void setupUsers() throws Exception {
 
         LOG.info("Entering setupUsers");
 
-        if ( usersSetup ) {
-            LOG.info("Leaving setupUsers: already setup");
-            return;
-        }
+//        if ( usersSetup ) {
+//            LOG.info("Leaving setupUsers: already setup");
+//            return;
+//        }
+
+        String rand = RandomStringUtils.randomAlphanumeric(5);
+        username = "user-" + rand;
+        userEmail = username + "@example.com";
 
-        //
-        createUser( "edanuff", "ed@anuff.com", "sesame", "Ed Anuff" ); // client.setApiUrl(apiUrl);
+        createUser( username, userEmail, "sesame", "User named " + rand);
 
-        usersSetup = true;
-        LOG.info("Leaving setupUsers success");
+        //usersSetup = true;
+        LOG.info("Leaving setupUsers, setup user: " + userEmail );
     }
 
 
     public void loginClient() throws Exception {
-        // now create a client that logs in ed
 
-        // TODO T.N. This is a filthy hack and I should be ashamed of it (which
-        // I am). There's a bug in the grizzly server when it's restarted per
-        // test, and until we can upgrade versions this is the workaround. Backs
-        // off with each attempt to allow the server to catch up
+        String appNameOnly = appInfo.getName().split("/")[1];
 
-
-        setUserPassword( "ed@anuff.com", "sesame" );
-
-        client = new Client( "test-organization", "test-app" ).withApiUrl(
+        client = new Client( "test-organization", appNameOnly ).withApiUrl(
                 UriBuilder.fromUri( "http://localhost/" ).port(tomcatRuntime.getPort() ).build().toString() );
 
         org.apache.usergrid.java.client.response.ApiResponse response =
-                client.authorizeAppUser( "ed@anuff.com", "sesame" );
+            client.authorizeAppUser( userEmail, "sesame" );
 
         assertTrue( response != null && response.getError() == null );
     }
@@ -226,10 +245,8 @@ public abstract class AbstractRestIT extends JerseyTest {
     protected String userToken( String name, String password ) throws Exception {
 
         try {
-            setUserPassword( "ed@anuff.com", "sesame" );
-
-            JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/token" )
-                    .queryParam( "grant_type", "password" )
+            JsonNode node = mapper.readTree( resource().path( orgAppPath + "token" )
+                    .queryParam("grant_type", "password")
                     .queryParam( "username", name )
                     .queryParam( "password", password ).accept( MediaType.APPLICATION_JSON )
                     .get( String.class ));
@@ -248,7 +265,7 @@ public abstract class AbstractRestIT extends JerseyTest {
     public void createUser( String username, String email, String password, String name ) {
 
         try {
-            JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/token" )
+            JsonNode node = mapper.readTree( resource().path( orgAppPath + "token" )
                 .queryParam( "grant_type", "password" )
                 .queryParam( "username", username )
                 .queryParam( "password", password )
@@ -271,7 +288,7 @@ public abstract class AbstractRestIT extends JerseyTest {
             .map( "password", password )
             .map( "pin", "1234" );
 
-        resource().path( "/test-organization/test-app/users" )
+        resource().path( orgAppPath + "users" )
             .queryParam( "access_token", adminAccessToken )
             .accept( MediaType.APPLICATION_JSON )
             .type( MediaType.APPLICATION_JSON )
@@ -286,12 +303,12 @@ public abstract class AbstractRestIT extends JerseyTest {
         adminToken();
 
         // change the password as admin. The old password isn't required
-        JsonNode node = mapper.readTree( resource().path(
-                String.format( "/test-organization/test-app/users/%s/password", username ) )
-                .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
-
-        assertNull( getError( node ) );
+        JsonNode node = mapper.readTree(
+            resource().path( String.format( orgAppPath + "users/%s/password", username ) )
+                .queryParam("access_token", adminAccessToken)
+                .accept(MediaType.APPLICATION_JSON)
+                .type(MediaType.APPLICATION_JSON_TYPE)
+                .post(String.class, data));
     }
 
 
@@ -385,7 +402,7 @@ public abstract class AbstractRestIT extends JerseyTest {
 
     /** convenience to return a ready WebResource.Builder in a single call */
     protected WebResource.Builder appPath( String path ) {
-        return resource().path( "/test-organization/test-app/" + path )
+        return resource().path( orgAppPath + "" + path )
                 .queryParam( "access_token", access_token )
                 .accept( MediaType.APPLICATION_JSON )
                 .type( MediaType.APPLICATION_JSON_TYPE );
@@ -464,6 +481,9 @@ public abstract class AbstractRestIT extends JerseyTest {
 
         LOG.debug("Refreshing index for app {}/{}", orgName, appName );
 
+        // be nice if somebody accidentally passed in orgName/appName
+        appName = appName.contains("/") ? appInfo.getName().split("/")[1] : appName;
+
         try {
 
             resource().path( "/refreshindex" )

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/72fcdda3/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
index ea4ab39..dc84197 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
@@ -54,17 +54,16 @@ import org.slf4j.LoggerFactory;
 public class ApplicationResourceIT extends AbstractRestIT {
     private static final Logger logger = LoggerFactory.getLogger( ApplicationResourceIT.class );
 
+
     @Test
     public void applicationWithOrgCredentials() throws Exception {
 
-        OrganizationInfo orgInfo = setup.getMgmtSvc().getOrganizationByName( "test-organization" );
-
         String clientId = setup.getMgmtSvc().getClientIdForOrganization( orgInfo.getUuid() );
         String clientSecret = setup.getMgmtSvc().getClientSecretForOrganization( orgInfo.getUuid() );
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/users" )
+        JsonNode node = mapper.readTree( resource().path( orgAppPath + "users" )
                 .queryParam( "client_id", clientId )
                 .queryParam( "client_secret", clientSecret ).accept( MediaType.APPLICATION_JSON )
                 .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
@@ -75,18 +74,16 @@ public class ApplicationResourceIT extends AbstractRestIT {
     @Test
     public void applicationWithAppCredentials() throws Exception {
 
-        ApplicationInfo appInfo = setup.getMgmtSvc().getApplicationInfo( "test-organization/test-app" );
-
         String clientId = setup.getMgmtSvc().getClientIdForApplication( appInfo.getId() );
         String clientSecret = setup.getMgmtSvc().getClientSecretForApplication( appInfo.getId() );
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/users" )
+        JsonNode node = mapper.readTree( resource().path( orgAppPath + "users" )
                 .queryParam( "client_id", clientId )
                 .queryParam( "client_secret", clientSecret )
                 .accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+                .type( MediaType.APPLICATION_JSON_TYPE).get(String.class));
 
         assertNotNull( node.get( "entities" ) );
     }
@@ -98,14 +95,14 @@ public class ApplicationResourceIT extends AbstractRestIT {
     @Test
     public void jsonForNoAccepts() throws Exception {
 
-        ApplicationInfo app = setup.getMgmtSvc().getApplicationInfo("test-organization/test-app");
+        ApplicationInfo app = appInfo;
         String clientId = setup.getMgmtSvc().getClientIdForApplication( app.getId() );
         String clientSecret = setup.getMgmtSvc().getClientSecretForApplication( app.getId() );
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
 
         JsonNode node = mapper.readTree( resource()
-                .path( "/test-organization/test-app" )
+                .path( orgAppPath )
                 .queryParam( "client_id", clientId )
                 .queryParam( "client_secret", clientSecret )
                 .get( String.class ));
@@ -120,14 +117,13 @@ public class ApplicationResourceIT extends AbstractRestIT {
     @Test
     public void jsonForAcceptsTextHtml() throws Exception {
 
-        ApplicationInfo app = setup.getMgmtSvc().getApplicationInfo("test-organization/test-app");
-        String clientId = setup.getMgmtSvc().getClientIdForApplication( app.getId() );
-        String clientSecret = setup.getMgmtSvc().getClientSecretForApplication( app.getId() );
+        String clientId = setup.getMgmtSvc().getClientIdForApplication(appInfo.getId());
+        String clientSecret = setup.getMgmtSvc().getClientSecretForApplication( appInfo.getId() );
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
 
         JsonNode node = mapper.readTree( resource()
-                .path( "/test-organization/test-app" )
+                .path( orgAppPath )
                 .queryParam( "client_id", clientId )
                 .queryParam( "client_secret", clientSecret )
                 .accept( MediaType.TEXT_HTML )
@@ -139,8 +135,6 @@ public class ApplicationResourceIT extends AbstractRestIT {
     @Test
     public void applicationWithJsonCreds() throws Exception {
 
-        ApplicationInfo appInfo = setup.getMgmtSvc().getApplicationInfo( "test-organization/test-app" );
-
         String clientId = setup.getMgmtSvc().getClientIdForApplication( appInfo.getId() );
         String clientSecret = setup.getMgmtSvc().getClientSecretForApplication( appInfo.getId() );
 
@@ -148,19 +142,19 @@ public class ApplicationResourceIT extends AbstractRestIT {
                 .map( "username", "applicationWithJsonCreds" ).map( "name", "applicationWithJsonCreds" )
                 .map( "password", "applicationWithJsonCreds" ).map( "pin", "1234" );
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/users" )
-                .queryParam( "client_id", clientId )
+        JsonNode node = mapper.readTree( resource().path( orgAppPath + "users" )
+                .queryParam("client_id", clientId)
                 .queryParam( "client_secret", clientSecret ).accept( MediaType.APPLICATION_JSON )
                 .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
 
         assertNotNull( getEntity( node, 0 ) );
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
 
         payload = hashMap( "username", "applicationWithJsonCreds" ).map( "password", "applicationWithJsonCreds" )
                 .map( "grant_type", "password" );
 
-        node = mapper.readTree( resource().path( "/test-organization/test-app/token" ).accept( MediaType.APPLICATION_JSON )
+        node = mapper.readTree( resource().path( orgAppPath + "token" ).accept( MediaType.APPLICATION_JSON )
                 .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
 
         JsonNode token = node.get( "access_token" );
@@ -175,13 +169,10 @@ public class ApplicationResourceIT extends AbstractRestIT {
             + "rootApplicationWithOrgCredentials:139 expected:<3> but was:<4>")
     public void rootApplicationWithOrgCredentials() throws Exception {
 
-        OrganizationInfo orgInfo = setup.getMgmtSvc().getOrganizationByName( "test-organization" );
-        ApplicationInfo appInfo = setup.getMgmtSvc().getApplicationInfo( "test-organization/test-app" );
-
         String clientId = setup.getMgmtSvc().getClientIdForOrganization( orgInfo.getUuid() );
         String clientSecret = setup.getMgmtSvc().getClientSecretForOrganization( orgInfo.getUuid() );
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
 
         JsonNode node = mapper.readTree( resource().path( "/" + appInfo.getId() )
                 .queryParam( "client_id", clientId )
@@ -189,10 +180,10 @@ public class ApplicationResourceIT extends AbstractRestIT {
                 .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
 
         // ensure the URI uses the properties file as a base
-        assertEquals( node.get( "uri" ).textValue(), "http://sometestvalue/test-organization/test-app" );
+        assertEquals( node.get( "uri" ).textValue(), "http://sometestvalue/" + orgAppPath);
 
         node = getEntity( node, 0 );
-        assertEquals( "test-organization/test-app", node.get( "name" ).asText() );
+        assertEquals( orgAppPath, node.get( "name" ).asText() );
         assertEquals( "Roles", node.get( "metadata" ).get( "collections" ).get( "roles" ).get( "title" ).asText() );
 
         // TODO - when run together with many tests this sees 4 instead of expected 3
@@ -204,12 +195,15 @@ public class ApplicationResourceIT extends AbstractRestIT {
     public void test_GET_credentials_ok() throws IOException {
         String mgmtToken = adminToken();
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
+
+        JsonNode node = mapper.readTree( resource()
+            .path(orgAppPath + "credentials")
+            .queryParam("access_token", mgmtToken)
+            .accept(MediaType.APPLICATION_JSON)
+            .type(MediaType.APPLICATION_JSON_TYPE)
+            .get(String.class));
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/credentials" )
-                .queryParam( "access_token", mgmtToken )
-                        .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                        .get( String.class ));
         assertEquals( "ok", node.get( "status" ).textValue() );
         logNode( node );
     }
@@ -219,9 +213,9 @@ public class ApplicationResourceIT extends AbstractRestIT {
     public void testResetAppCredentials() throws IOException {
         String mgmtToken = adminToken();
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/credentials" )
+        JsonNode node = mapper.readTree( resource().path( orgAppPath + "credentials" )
                 .queryParam( "access_token", mgmtToken )
                         .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
                         .post( String.class ));
@@ -231,39 +225,18 @@ public class ApplicationResourceIT extends AbstractRestIT {
 
 
     @Test
-    public void noAppDelete() throws IOException {
-        String mgmtToken = adminToken();
-
-        Status status = null;
-        JsonNode node = null;
-
-        refreshIndex("test-organization", "test-app");
-
-        try {
-            node = mapper.readTree( resource().path( "/test-organization/test-app" )
-                    .queryParam( "access_token", mgmtToken )
-                    .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                    .delete( String.class ));
-        }
-        catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertEquals( Status.NOT_IMPLEMENTED, status );
-    }
-
-
-    @Test
     public void ttlOverMax() throws Exception {
 
         Map<String, String> payload =
-                hashMap( "grant_type", "password" ).map( "username", "test@usergrid.com" ).map( "password", "test" )
-                        .map( "ttl", Long.MAX_VALUE + "" );
+            hashMap( "grant_type", "password" )
+            .map("username", "test@usergrid.com")
+            .map("password", "test")
+            .map("ttl", Long.MAX_VALUE + "");
 
         Status responseStatus = null;
 
         try {
-            resource().path( "/test-organization/test-app/token" ).accept( MediaType.APPLICATION_JSON )
+            resource().path( orgAppPath + "token" ).accept( MediaType.APPLICATION_JSON )
                     .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload );
         }
         catch ( UniformInterfaceException uie ) {
@@ -279,9 +252,9 @@ public class ApplicationResourceIT extends AbstractRestIT {
 
         long ttl = 2000;
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/token" )
+        JsonNode node = mapper.readTree( resource().path( orgAppPath + "token" )
                 .queryParam( "grant_type", "password" )
-                .queryParam( "username", "ed@anuff.com" )
+                .queryParam( "username", userEmail )
                 .queryParam( "password", "sesame" )
                 .queryParam( "ttl", String.valueOf( ttl ) ).accept( MediaType.APPLICATION_JSON ).get( String.class ));
 
@@ -294,18 +267,18 @@ public class ApplicationResourceIT extends AbstractRestIT {
         long expires_in = node.get( "expires_in" ).longValue();
         assertEquals( ttl, expires_in * 1000 );
 
-        JsonNode userdata = mapper.readTree( resource().path( "/test-organization/test-app/users/ed@anuff.com" )
+        JsonNode userdata = mapper.readTree( resource().path( orgAppPath + "users/" + userEmail )
                 .queryParam( "access_token", token )
                         .accept( MediaType.APPLICATION_JSON ).get( String.class ));
 
-        assertEquals( "ed@anuff.com", getEntity( userdata, 0 ).get( "email" ).asText() );
+        assertEquals( userEmail, getEntity( userdata, 0 ).get( "email" ).asText() );
 
         // wait for the token to expire
-        Thread.sleep( ttl - ( System.currentTimeMillis() - startTime ) + 1000 );
+        Thread.sleep(ttl - (System.currentTimeMillis() - startTime) + 1000);
 
         Status responseStatus = null;
         try {
-            userdata = mapper.readTree( resource().path( "/test-organization/test-app/users/ed@anuff.com" )
+            userdata = mapper.readTree( resource().path( orgAppPath + "users/" + userEmail)
                     .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
         }
         catch ( UniformInterfaceException uie ) {
@@ -320,12 +293,14 @@ public class ApplicationResourceIT extends AbstractRestIT {
     public void ttlNan() throws Exception {
 
         Map<String, String> payload =
-                hashMap( "grant_type", "password" ).map( "username", "ed@anuff.com" ).map( "password", "sesame" )
-                        .map( "ttl", "derp" );
+            hashMap( "grant_type", "password" )
+            .map( "username", userEmail)
+                .map( "password", "sesame")
+                .map( "ttl", "derp");
 
         Status responseStatus = null;
         try {
-            resource().path( "/test-organization/test-app/token" ).accept( MediaType.APPLICATION_JSON )
+            resource().path( orgAppPath + "token" ).accept( MediaType.APPLICATION_JSON )
                     .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload );
         }
         catch ( UniformInterfaceException uie ) {
@@ -339,12 +314,12 @@ public class ApplicationResourceIT extends AbstractRestIT {
     @Test
     public void updateAccessTokenTtl() throws Exception {
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/token" )
+        JsonNode node = mapper.readTree( resource().path( orgAppPath + "token" )
                 .queryParam( "grant_type", "password" )
-                .queryParam( "username", "ed@anuff.com" )
-                .queryParam( "password", "sesame" )
-                .accept( MediaType.APPLICATION_JSON )
-                .get( String.class ));
+                .queryParam( "username", userEmail)
+            .queryParam( "password", "sesame")
+            .accept( MediaType.APPLICATION_JSON)
+            .get( String.class));
 
         String token = node.get( "access_token" ).textValue();
         logNode( node );
@@ -355,17 +330,17 @@ public class ApplicationResourceIT extends AbstractRestIT {
 
         Map<String, String> payload = hashMap( "accesstokenttl", "31536000000" );
 
-        node = mapper.readTree( resource().path( "/test-organization/test-app" )
+        node = mapper.readTree( resource().path( orgAppPath )
                 .queryParam( "access_token", adminAccessToken )
                 .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, payload ));
         logNode( node );
 
-        node = mapper.readTree( resource().path( "/test-organization/test-app/token" )
+        node = mapper.readTree( resource().path( orgAppPath + "token" )
                 .queryParam( "grant_type", "password" )
-                .queryParam( "username", "ed@anuff.com" )
-                .queryParam( "password", "sesame" )
-                .accept( MediaType.APPLICATION_JSON )
-                .get( String.class ));
+                .queryParam( "username", userEmail)
+            .queryParam( "password", "sesame")
+            .accept( MediaType.APPLICATION_JSON)
+            .get( String.class));
 
         assertEquals( 31536000, node.get( "expires_in" ).longValue() );
         logNode( node );
@@ -374,10 +349,9 @@ public class ApplicationResourceIT extends AbstractRestIT {
 
     @Test
     public void authorizationCodeWithWrongCredentials() throws Exception {
-        ApplicationInfo appInfo = setup.getMgmtSvc().getApplicationInfo( "test-organization/test-app" );
         String clientId = setup.getMgmtSvc().getClientIdForApplication( appInfo.getId() );
 
-        refreshIndex("test-organization", "test-app");
+        refreshIndex( orgInfo.getName(), appInfo.getName() );
 
         Form payload = new Form();
         payload.add( "username", "wrong_user" );
@@ -387,7 +361,7 @@ public class ApplicationResourceIT extends AbstractRestIT {
         payload.add( "scope", "none" );
         payload.add( "redirect_uri", "http://www.my_test.com" );
 
-        String result = resource().path( "/test-organization/test-app/authorize" )
+        String result = resource().path( orgAppPath + "authorize" )
                 .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).accept( MediaType.TEXT_HTML )
                 .post( String.class, payload );
 
@@ -399,7 +373,7 @@ public class ApplicationResourceIT extends AbstractRestIT {
     @Test
     public void authorizeWithInvalidClientIdRaisesError() throws Exception {
         String result =
-                resource().path( "/test-organization/test-app/authorize" )
+                resource().path( orgAppPath + "authorize" )
                         .queryParam( "response_type", "token" )
                         .queryParam( "client_id", "invalid_client_id" )
                         .queryParam( "redirect_uri", "http://www.my_test.com" ).get( String.class );
@@ -410,11 +384,10 @@ public class ApplicationResourceIT extends AbstractRestIT {
 
     @Test
     public void authorizationCodeWithValidCredentials() throws Exception {
-        ApplicationInfo appInfo = setup.getMgmtSvc().getApplicationInfo( "test-organization/test-app" );
         String clientId = setup.getMgmtSvc().getClientIdForApplication( appInfo.getId() );
 
         Form payload = new Form();
-        payload.add( "username", "ed@anuff.com" );
+        payload.add( "username", userEmail );
         payload.add( "password", "sesame" );
         payload.add( "response_type", "code" );
         payload.add( "client_id", clientId );
@@ -425,7 +398,7 @@ public class ApplicationResourceIT extends AbstractRestIT {
 
         Status status = null;
         try {
-            String result = resource().path( "/test-organization/test-app/authorize" )
+            String result = resource().path( orgAppPath + "authorize" )
                     .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE )
                     .accept( MediaType.TEXT_HTML )
                     .post( String.class, payload );
@@ -440,7 +413,6 @@ public class ApplicationResourceIT extends AbstractRestIT {
 
     @Test
     public void clientCredentialsFlowWithHeaderAuthorization() throws Exception {
-        ApplicationInfo appInfo = setup.getMgmtSvc().getApplicationInfo( "test-organization/test-app" );
         String clientId = setup.getMgmtSvc().getClientIdForApplication( appInfo.getId() );
         String clientSecret = setup.getMgmtSvc().getClientSecretForApplication( appInfo.getId() );
 
@@ -450,7 +422,7 @@ public class ApplicationResourceIT extends AbstractRestIT {
         Form payload = new Form();
         payload.add( "grant_type", "client_credentials" );
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/token" ).header( "Authorization", "Basic " + token )
+        JsonNode node = mapper.readTree( resource().path( orgAppPath + "token" ).header( "Authorization", "Basic " + token )
                         .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).accept( MediaType.APPLICATION_JSON )
                         .post( String.class, payload ));
 
@@ -461,7 +433,6 @@ public class ApplicationResourceIT extends AbstractRestIT {
 
     @Test
     public void clientCredentialsFlowWithPayload() throws Exception {
-        ApplicationInfo appInfo = setup.getMgmtSvc().getApplicationInfo( "test-organization/test-app" );
         String clientId = setup.getMgmtSvc().getClientIdForApplication( appInfo.getId() );
         String clientSecret = setup.getMgmtSvc().getClientSecretForApplication( appInfo.getId() );
 
@@ -470,7 +441,7 @@ public class ApplicationResourceIT extends AbstractRestIT {
         payload.add( "client_id", clientId );
         payload.add( "client_secret", clientSecret );
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/token" )
+        JsonNode node = mapper.readTree( resource().path( orgAppPath + "token" )
                 .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).accept( MediaType.APPLICATION_JSON )
                 .post( String.class, payload ));
 
@@ -481,7 +452,6 @@ public class ApplicationResourceIT extends AbstractRestIT {
 
     @Test
     public void clientCredentialsFlowWithHeaderAuthorizationAndPayload() throws Exception {
-        ApplicationInfo appInfo = setup.getMgmtSvc().getApplicationInfo( "test-organization/test-app" );
         String clientId = setup.getMgmtSvc().getClientIdForApplication( appInfo.getId() );
         String clientSecret = setup.getMgmtSvc().getClientSecretForApplication( appInfo.getId() );
 
@@ -490,7 +460,7 @@ public class ApplicationResourceIT extends AbstractRestIT {
 
         Map<String, String> payload = hashMap( "grant_type", "client_credentials" );
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/token" ).header( "Authorization", "Basic " + token )
+        JsonNode node = mapper.readTree( resource().path( orgAppPath + "token" ).header( "Authorization", "Basic " + token )
                         .type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
                         .post( String.class, payload ));
 
@@ -504,7 +474,7 @@ public class ApplicationResourceIT extends AbstractRestIT {
         JsonNode node = null;
 
         try {
-            node = mapper.readTree( resource().path( "/test-organization/test-app/apm/apigeeMobileConfig" ).get( String.class ));
+            node = mapper.readTree( resource().path( orgAppPath + "apm/apigeeMobileConfig" ).get( String.class ));
             //if things are kosher then JSON should have value for instaOpsApplicationId
             assertTrue( "it's valid json for APM", node.has( "instaOpsApplicationId" ) );
         }
@@ -519,12 +489,10 @@ public class ApplicationResourceIT extends AbstractRestIT {
     @Test
     public void appTokenFromOrgCreds() throws Exception {
 
-        OrganizationInfo orgInfo = setup.getMgmtSvc().getOrganizationByName( "test-organization" );
-
         String clientId = setup.getMgmtSvc().getClientIdForOrganization( orgInfo.getUuid() );
         String clientSecret = setup.getMgmtSvc().getClientSecretForOrganization( orgInfo.getUuid() );
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/token" )
+        JsonNode node = mapper.readTree( resource().path( orgAppPath + "token" )
                 .queryParam( "client_id", clientId )
                 .queryParam( "client_secret", clientSecret )
                 .queryParam( "grant_type", "client_credentials" )
@@ -539,7 +507,7 @@ public class ApplicationResourceIT extends AbstractRestIT {
         //check it's 1 day, should be the same as the default
         assertEquals( 604800, ttl );
 
-        node = mapper.readTree( resource().path( "/test-organization/test-app/users" )
+        node = mapper.readTree( resource().path( orgAppPath + "users" )
                 .queryParam( "access_token", accessToken )
                 .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
 
@@ -550,12 +518,10 @@ public class ApplicationResourceIT extends AbstractRestIT {
     @Test
     public void appTokenFromAppCreds() throws Exception {
 
-        ApplicationInfo appInfo = setup.getMgmtSvc().getApplicationInfo( "test-organization/test-app" );
-
         String clientId = setup.getMgmtSvc().getClientIdForApplication( appInfo.getId() );
         String clientSecret = setup.getMgmtSvc().getClientSecretForApplication( appInfo.getId() );
 
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/token" )
+        JsonNode node = mapper.readTree( resource().path( orgAppPath + "token" )
                 .queryParam( "client_id", clientId )
                 .queryParam( "client_secret", clientSecret )
                 .queryParam( "grant_type", "client_credentials" )
@@ -570,7 +536,7 @@ public class ApplicationResourceIT extends AbstractRestIT {
         //check it's 7 days, should be the same as the default
         assertEquals( 604800, ttl );
 
-        node = mapper.readTree( resource().path( "/test-organization/test-app/users" )
+        node = mapper.readTree( resource().path( orgAppPath + "users" )
                 .queryParam( "access_token", accessToken )
                 .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));