You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/04/06 22:50:49 UTC

[1/9] incubator-usergrid git commit: Introduce app create IT, rename app delete test

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-533-create-app-test [created] a5a014cfd
  refs/heads/two-dot-o-dev 2464c628f -> 6ff6d049d


Introduce app create IT, rename app delete test


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

Branch: refs/heads/USERGRID-533-create-app-test
Commit: 721e385ab681d84bede22ec66b6af9d7788192db
Parents: 4d75716
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Apr 3 15:33:55 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Apr 3 15:33:55 2015 -0400

----------------------------------------------------------------------
 .../rest/applications/ApplicationCreateIT.java  |  98 +++++
 .../rest/applications/ApplicationDeleteIT.java  | 382 ++++++++++++++++++
 .../applications/ApplicationDeleteTest.java     | 387 -------------------
 3 files changed, 480 insertions(+), 387 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/721e385a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
new file mode 100644
index 0000000..ba5e1d9
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
@@ -0,0 +1,98 @@
+/*
+ * 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.applications;
+
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.Application;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.rest.test.resource2point0.model.Token;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.MediaType;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.UUID;
+
+import static org.junit.Assert.fail;
+
+
+public class ApplicationCreateIT extends AbstractRestIT {
+    private static final Logger logger = LoggerFactory.getLogger(ApplicationCreateIT.class);
+
+
+    /**
+     * Ensure that we can create many apps and successfully page through them.
+     * https://issues.apache.org/jira/browse/USERGRID-491
+     *
+     * <pre>
+     * </pre>
+     */
+    @Test
+    public void testCreateAndRetreieveApps() throws Exception {
+
+        // create app with a collection of "things"
+
+        String orgName = clientSetup.getOrganization().getName();
+        String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
+        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
+
+        List<Entity> entities = new ArrayList<>();
+
+        UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+    }
+
+
+    private UUID createAppWithCollection(
+        String orgName, String appName, Token orgAdminToken, List<Entity> entities) {
+
+        ApiResponse appCreateResponse = clientSetup.getRestClient()
+            .management().orgs().organization( orgName ).app().getResource()
+            .queryParam( "access_token", orgAdminToken.getAccessToken() )
+            .type( MediaType.APPLICATION_JSON )
+            .post( ApiResponse.class, new Application( appName ) );
+        UUID appId = appCreateResponse.getEntities().get(0).getUuid();
+
+        for ( int i=0; i<10; i++ ) {
+
+            final String entityName = "entity" + i;
+            Entity entity = new Entity();
+            entity.setProperties(new HashMap<String, Object>() {{
+                put("name", entityName );
+            }});
+
+            ApiResponse createResponse = clientSetup.getRestClient()
+                .org(orgName).app( appName ).collection("things").getResource()
+                .queryParam("access_token", orgAdminToken.getAccessToken())
+                .type(MediaType.APPLICATION_JSON)
+                .post( ApiResponse.class, entity );
+
+            entities.add( createResponse.getEntities().get(0) );
+        }
+        return appId;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/721e385a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
new file mode 100644
index 0000000..0727239
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
@@ -0,0 +1,382 @@
+/*
+ * 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.applications;
+
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.*;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.ws.rs.core.MediaType;
+import java.util.*;
+
+import static org.junit.Assert.fail;
+
+
+public class ApplicationDeleteIT extends AbstractRestIT {
+    private static final Logger logger = LoggerFactory.getLogger(ApplicationDeleteIT.class);
+
+
+    /**
+     * Test most common use cases.
+     * <pre>
+     *  - create app with collection of things
+     *  - delete the app
+     *  - test that attempts to get the app, its collections and entities throw 400 with message
+     *  - test that we cannot delete the app a second time
+     *  - test that we can create a new app with the same name as the deleted app
+     * </pre>
+     */
+    @Test
+    public void testBasicOperation() throws Exception {
+
+        // create app with a collection of "things"
+
+        String orgName = clientSetup.getOrganization().getName();
+        String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
+        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
+
+        List<Entity> entities = new ArrayList<>();
+
+        UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+
+        // delete the app
+
+        try {
+            clientSetup.getRestClient()
+                .org(orgName).app(appToDeleteId.toString()).getResource()
+                .queryParam("access_token", orgAdminToken.getAccessToken())
+                .delete();
+
+            fail("Delete must fail without app_delete_confirm parameter");
+
+        } catch ( Exception e ) {
+            logger.error("Error", e);
+        }
+
+        clientSetup.getRestClient()
+            .org(orgName).app(appToDeleteId.toString() ).getResource()
+            .queryParam("access_token", orgAdminToken.getAccessToken() )
+            .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
+            .delete();
+
+        // test that we can no longer get the app
+
+        try {
+            clientSetup.getRestClient()
+                .org(orgName).app(appToDeleteName).getResource()
+                .queryParam("access_token", orgAdminToken.getAccessToken())
+                .type(MediaType.APPLICATION_JSON)
+                .get(ApiResponse.class);
+
+            fail("Must not be able to get deleted app");
+
+        } catch ( UniformInterfaceException expected ) {
+            Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus() );
+            JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
+            Assert.assertEquals("organization_application_not_found", node.get("error").textValue());
+        }
+
+        // test that we can no longer get deleted app's collection
+
+        try {
+            clientSetup.getRestClient()
+                .org(orgName).app(appToDeleteName).collection("things").getResource()
+                .queryParam("access_token", orgAdminToken.getAccessToken() )
+                .type(MediaType.APPLICATION_JSON )
+                .get(ApiResponse.class);
+
+            fail("Must not be able to get deleted app's collection");
+
+        } catch ( UniformInterfaceException expected ) {
+            Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus() );
+            JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
+            Assert.assertEquals("organization_application_not_found", node.get("error").textValue());
+        }
+
+        // test that we can no longer get an app entity
+
+        try {
+            UUID entityId = entities.get(0).getUuid();
+            clientSetup.getRestClient()
+                .org(orgName).app(appToDeleteName).collection("things").entity( entityId ).getResource()
+                .queryParam( "access_token", orgAdminToken.getAccessToken())
+                .type( MediaType.APPLICATION_JSON)
+                .get(ApiResponse.class);
+
+            fail("Must not be able to get deleted app entity");
+
+        } catch ( UniformInterfaceException expected ) {
+            // TODO: why not a 404?
+            Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus() );
+            JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
+            Assert.assertEquals("organization_application_not_found", node.get("error").textValue());
+        }
+
+        // test that we cannot see the application in the list of applications returned
+        // by the management resource's get organization's applications end-point
+
+        refreshIndex();
+
+        ManagementResponse orgAppResponse = clientSetup.getRestClient()
+            .management().orgs().organization( orgName ).apps().getOrganizationApplications();
+
+        for ( String appName : orgAppResponse.getData().keySet() ) {
+            if ( orgAppResponse.getData().get( appName ).equals( appToDeleteId.toString() )) {
+                fail("Deleted app must not be included in list of org apps");
+            }
+        }
+
+        // test that we cannot delete the application a second time
+
+        try {
+            clientSetup.getRestClient()
+                .org(orgName).app(appToDeleteId.toString()).getResource()
+                .queryParam("access_token", orgAdminToken.getAccessToken())
+                .delete();
+
+        } catch ( UniformInterfaceException expected ) {
+            Assert.assertEquals("Error must be 404", 404, expected.getResponse().getStatus() );
+            JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
+            Assert.assertEquals("not_found", node.get("error").textValue());
+        }
+
+        // test that we can create a new application with the same name
+
+        ApiResponse appCreateAgainResponse = clientSetup.getRestClient()
+            .management().orgs().organization( orgName ).app().getResource()
+            .queryParam( "access_token", orgAdminToken.getAccessToken() )
+            .type( MediaType.APPLICATION_JSON )
+            .post( ApiResponse.class, new Application( appToDeleteName ) );
+
+        Assert.assertEquals("Must be able to create app with same name as deleted app",
+            (orgName + "/" + appToDeleteName).toLowerCase(),
+            appCreateAgainResponse.getEntities().get(0).get("name"));
+    }
+
+
+   /**
+    * Test restore of deleted app.
+    * <pre>
+    *  - create app with collection of things
+    *  - delete the app
+    *  - restore the app
+    *  - test that we can get the app, its collections and an entity
+    * </pre>
+    */
+    @Test
+    public void testAppRestore() throws Exception {
+
+        // create app with a collection of "things"
+
+        String orgName = clientSetup.getOrganization().getName();
+        String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
+        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
+
+        List<Entity> entities = new ArrayList<>();
+
+        UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+
+        // delete the app
+
+        logger.debug("\n\nDeleting app\n");
+
+        clientSetup.getRestClient()
+            .org(orgName).app( appToDeleteName ).getResource()
+            .queryParam("access_token", orgAdminToken.getAccessToken() )
+            .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
+            .delete();
+
+        Thread.sleep(1000);
+
+        // restore the app
+
+        logger.debug("\n\nRestoring app\n");
+
+        clientSetup.getRestClient()
+            .org(orgName).app( appToDeleteId.toString() ).getResource()
+            .queryParam("access_token", orgAdminToken.getAccessToken() )
+            .put();
+
+        // test that we can see the application in the list of applications
+
+        logger.debug("\n\nGetting app list from management end-point\n");
+
+        ManagementResponse orgAppResponse = clientSetup.getRestClient()
+            .management().orgs().organization( orgName ).apps().getOrganizationApplications();
+
+        boolean found = false;
+        for ( String appName : orgAppResponse.getData().keySet() ) {
+            if ( orgAppResponse.getData().get( appName ).equals( appToDeleteId.toString() )) {
+                found = true;
+                break;
+            }
+        }
+
+        Assert.assertTrue( found );
+
+        // test that we can get an app entity
+
+        logger.debug("\n\nGetting entities from app\n");
+
+        UUID entityId = entities.get(0).getUuid();
+        ApiResponse entityResponse = clientSetup.getRestClient()
+            .org(orgName).app(appToDeleteName).collection("things").entity( entityId ).getResource()
+            .queryParam("access_token", orgAdminToken.getAccessToken())
+            .type(MediaType.APPLICATION_JSON)
+            .get(ApiResponse.class);
+        Assert.assertEquals( entityId, entityResponse.getEntities().get(0).getUuid() );
+
+        // test that we can get deleted app's collection
+
+        ApiResponse collectionReponse = clientSetup.getRestClient()
+            .org(orgName).app(appToDeleteName).collection("things").getResource()
+            .queryParam("access_token", orgAdminToken.getAccessToken())
+            .type(MediaType.APPLICATION_JSON)
+            .get(ApiResponse.class);
+        Assert.assertEquals( entities.size(), collectionReponse.getEntityCount() );
+    }
+
+
+    /**
+     * Test that we cannot restore deleted app with same name as
+     */
+    @Test
+    public void testAppRestoreConflict() throws Exception {
+
+        // create app with a collection of "things"
+
+        String orgName = clientSetup.getOrganization().getName();
+        String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
+        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
+
+        List<Entity> entities = new ArrayList<>();
+
+        UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+
+        // delete the app
+
+        clientSetup.getRestClient()
+            .org( orgName ).app(appToDeleteId.toString() ).getResource()
+            .queryParam( "access_token", orgAdminToken.getAccessToken() )
+            .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
+            .delete();
+
+        // create new app with same name
+
+        createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+
+        // attempt to restore original app, should get 409
+
+        try {
+
+            clientSetup.getRestClient()
+                .org(orgName).app(appToDeleteId.toString()).getResource()
+                .queryParam("access_token", orgAdminToken.getAccessToken())
+                .put();
+
+            fail("Must fail to restore app with same name as existing app");
+
+        } catch ( UniformInterfaceException e ) {
+            Assert.assertEquals(409, e.getResponse().getStatus());
+        }
+    }
+
+
+    /**
+     * Test that we cannot delete an app with same name as an app that is already deleted.
+     * TODO: investigate way to support this, there should be no such restriction.
+     */
+    @Test
+    public void testAppDeleteConflict() throws Exception {
+
+        // create app with a collection of "things"
+
+        String orgName = clientSetup.getOrganization().getName();
+        String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
+        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
+
+        List<Entity> entities = new ArrayList<>();
+
+        UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+
+        // delete the app
+
+        clientSetup.getRestClient()
+            .org( orgName ).app(appToDeleteId.toString() ).getResource()
+            .queryParam( "access_token", orgAdminToken.getAccessToken() )
+            .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
+            .delete();
+
+        // create new app with same name
+
+        UUID newAppId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+
+        // attempt to delete new app, it should fail
+
+        try {
+
+            clientSetup.getRestClient()
+                .org(orgName).app( newAppId.toString() ).getResource()
+                .queryParam("access_token", orgAdminToken.getAccessToken())
+                .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
+                .delete();
+
+            fail("Must fail to delete app with same name as deleted app");
+
+        } catch ( UniformInterfaceException e ) {
+            Assert.assertEquals( 409, e.getResponse().getStatus() );
+        }
+    }
+
+
+    private UUID createAppWithCollection(
+        String orgName, String appName, Token orgAdminToken, List<Entity> entities) {
+
+        ApiResponse appCreateResponse = clientSetup.getRestClient()
+            .management().orgs().organization( orgName ).app().getResource()
+            .queryParam( "access_token", orgAdminToken.getAccessToken() )
+            .type( MediaType.APPLICATION_JSON )
+            .post( ApiResponse.class, new Application( appName ) );
+        UUID appId = appCreateResponse.getEntities().get(0).getUuid();
+
+        for ( int i=0; i<10; i++ ) {
+
+            final String entityName = "entity" + i;
+            Entity entity = new Entity();
+            entity.setProperties(new HashMap<String, Object>() {{
+                put("name", entityName );
+            }});
+
+            ApiResponse createResponse = clientSetup.getRestClient()
+                .org(orgName).app( appName ).collection("things").getResource()
+                .queryParam("access_token", orgAdminToken.getAccessToken())
+                .type(MediaType.APPLICATION_JSON)
+                .post( ApiResponse.class, entity );
+
+            entities.add( createResponse.getEntities().get(0) );
+        }
+        return appId;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/721e385a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
deleted file mode 100644
index 0eaf566..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
+++ /dev/null
@@ -1,387 +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.applications;
-
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import org.apache.usergrid.corepersistence.ApplicationIdCacheImpl;
-import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
-import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResponse;
-import org.apache.usergrid.rest.test.resource2point0.model.*;
-import org.junit.Assert;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import javax.ws.rs.core.MediaType;
-import java.io.StringReader;
-import java.util.*;
-import java.util.regex.Pattern;
-
-import static org.junit.Assert.fail;
-
-
-public class ApplicationDeleteTest  extends AbstractRestIT {
-    private static final Logger logger = LoggerFactory.getLogger(ApplicationDeleteTest.class);
-
-
-    /**
-     * Test most common use cases.
-     * <pre>
-     *  - create app with collection of things
-     *  - delete the app
-     *  - test that attempts to get the app, its collections and entities throw 400 with message
-     *  - test that we cannot delete the app a second time
-     *  - test that we can create a new app with the same name as the deleted app
-     * </pre>
-     */
-    @Test
-    public void testBasicOperation() throws Exception {
-
-        // create app with a collection of "things"
-
-        String orgName = clientSetup.getOrganization().getName();
-        String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
-        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
-
-        List<Entity> entities = new ArrayList<>();
-
-        UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
-
-        // delete the app
-
-        try {
-            clientSetup.getRestClient()
-                .org(orgName).app(appToDeleteId.toString()).getResource()
-                .queryParam("access_token", orgAdminToken.getAccessToken())
-                .delete();
-
-            fail("Delete must fail without app_delete_confirm parameter");
-
-        } catch ( Exception e ) {
-            logger.error("Error", e);
-        }
-
-        clientSetup.getRestClient()
-            .org(orgName).app(appToDeleteId.toString() ).getResource()
-            .queryParam("access_token", orgAdminToken.getAccessToken() )
-            .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
-            .delete();
-
-        // test that we can no longer get the app
-
-        try {
-            clientSetup.getRestClient()
-                .org(orgName).app(appToDeleteName).getResource()
-                .queryParam("access_token", orgAdminToken.getAccessToken())
-                .type(MediaType.APPLICATION_JSON)
-                .get(ApiResponse.class);
-
-            fail("Must not be able to get deleted app");
-
-        } catch ( UniformInterfaceException expected ) {
-            Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus() );
-            JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
-            Assert.assertEquals("organization_application_not_found", node.get("error").textValue());
-        }
-
-        // test that we can no longer get deleted app's collection
-
-        try {
-            clientSetup.getRestClient()
-                .org(orgName).app(appToDeleteName).collection("things").getResource()
-                .queryParam("access_token", orgAdminToken.getAccessToken() )
-                .type(MediaType.APPLICATION_JSON )
-                .get(ApiResponse.class);
-
-            fail("Must not be able to get deleted app's collection");
-
-        } catch ( UniformInterfaceException expected ) {
-            Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus() );
-            JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
-            Assert.assertEquals("organization_application_not_found", node.get("error").textValue());
-        }
-
-        // test that we can no longer get an app entity
-
-        try {
-            UUID entityId = entities.get(0).getUuid();
-            clientSetup.getRestClient()
-                .org(orgName).app(appToDeleteName).collection("things").entity( entityId ).getResource()
-                .queryParam( "access_token", orgAdminToken.getAccessToken())
-                .type( MediaType.APPLICATION_JSON)
-                .get(ApiResponse.class);
-
-            fail("Must not be able to get deleted app entity");
-
-        } catch ( UniformInterfaceException expected ) {
-            // TODO: why not a 404?
-            Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus() );
-            JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
-            Assert.assertEquals("organization_application_not_found", node.get("error").textValue());
-        }
-
-        // test that we cannot see the application in the list of applications returned
-        // by the management resource's get organization's applications end-point
-
-        refreshIndex();
-
-        ManagementResponse orgAppResponse = clientSetup.getRestClient()
-            .management().orgs().organization( orgName ).apps().getOrganizationApplications();
-
-        for ( String appName : orgAppResponse.getData().keySet() ) {
-            if ( orgAppResponse.getData().get( appName ).equals( appToDeleteId.toString() )) {
-                fail("Deleted app must not be included in list of org apps");
-            }
-        }
-
-        // test that we cannot delete the application a second time
-
-        try {
-            clientSetup.getRestClient()
-                .org(orgName).app(appToDeleteId.toString()).getResource()
-                .queryParam("access_token", orgAdminToken.getAccessToken())
-                .delete();
-
-        } catch ( UniformInterfaceException expected ) {
-            Assert.assertEquals("Error must be 404", 404, expected.getResponse().getStatus() );
-            JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
-            Assert.assertEquals("not_found", node.get("error").textValue());
-        }
-
-        // test that we can create a new application with the same name
-
-        ApiResponse appCreateAgainResponse = clientSetup.getRestClient()
-            .management().orgs().organization( orgName ).app().getResource()
-            .queryParam( "access_token", orgAdminToken.getAccessToken() )
-            .type( MediaType.APPLICATION_JSON )
-            .post( ApiResponse.class, new Application( appToDeleteName ) );
-
-        Assert.assertEquals("Must be able to create app with same name as deleted app",
-            (orgName + "/" + appToDeleteName).toLowerCase(),
-            appCreateAgainResponse.getEntities().get(0).get("name"));
-    }
-
-
-   /**
-    * Test restore of deleted app.
-    * <pre>
-    *  - create app with collection of things
-    *  - delete the app
-    *  - restore the app
-    *  - test that we can get the app, its collections and an entity
-    * </pre>
-    */
-    @Test
-    public void testAppRestore() throws Exception {
-
-        // create app with a collection of "things"
-
-        String orgName = clientSetup.getOrganization().getName();
-        String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
-        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
-
-        List<Entity> entities = new ArrayList<>();
-
-        UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
-
-        // delete the app
-
-        logger.debug("\n\nDeleting app\n");
-
-        clientSetup.getRestClient()
-            .org(orgName).app( appToDeleteName ).getResource()
-            .queryParam("access_token", orgAdminToken.getAccessToken() )
-            .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
-            .delete();
-
-        Thread.sleep(1000);
-
-        // restore the app
-
-        logger.debug("\n\nRestoring app\n");
-
-        clientSetup.getRestClient()
-            .org(orgName).app( appToDeleteId.toString() ).getResource()
-            .queryParam("access_token", orgAdminToken.getAccessToken() )
-            .put();
-
-        // test that we can see the application in the list of applications
-
-        logger.debug("\n\nGetting app list from management end-point\n");
-
-        ManagementResponse orgAppResponse = clientSetup.getRestClient()
-            .management().orgs().organization( orgName ).apps().getOrganizationApplications();
-
-        boolean found = false;
-        for ( String appName : orgAppResponse.getData().keySet() ) {
-            if ( orgAppResponse.getData().get( appName ).equals( appToDeleteId.toString() )) {
-                found = true;
-                break;
-            }
-        }
-
-        Assert.assertTrue( found );
-
-        // test that we can get an app entity
-
-        logger.debug("\n\nGetting entities from app\n");
-
-        UUID entityId = entities.get(0).getUuid();
-        ApiResponse entityResponse = clientSetup.getRestClient()
-            .org(orgName).app(appToDeleteName).collection("things").entity( entityId ).getResource()
-            .queryParam("access_token", orgAdminToken.getAccessToken())
-            .type(MediaType.APPLICATION_JSON)
-            .get(ApiResponse.class);
-        Assert.assertEquals( entityId, entityResponse.getEntities().get(0).getUuid() );
-
-        // test that we can get deleted app's collection
-
-        ApiResponse collectionReponse = clientSetup.getRestClient()
-            .org(orgName).app(appToDeleteName).collection("things").getResource()
-            .queryParam("access_token", orgAdminToken.getAccessToken())
-            .type(MediaType.APPLICATION_JSON)
-            .get(ApiResponse.class);
-        Assert.assertEquals( entities.size(), collectionReponse.getEntityCount() );
-    }
-
-
-    /**
-     * Test that we cannot restore deleted app with same name as
-     */
-    @Test
-    public void testAppRestoreConflict() throws Exception {
-
-        // create app with a collection of "things"
-
-        String orgName = clientSetup.getOrganization().getName();
-        String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
-        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
-
-        List<Entity> entities = new ArrayList<>();
-
-        UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
-
-        // delete the app
-
-        clientSetup.getRestClient()
-            .org( orgName ).app(appToDeleteId.toString() ).getResource()
-            .queryParam( "access_token", orgAdminToken.getAccessToken() )
-            .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
-            .delete();
-
-        // create new app with same name
-
-        createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
-
-        // attempt to restore original app, should get 409
-
-        try {
-
-            clientSetup.getRestClient()
-                .org(orgName).app(appToDeleteId.toString()).getResource()
-                .queryParam("access_token", orgAdminToken.getAccessToken())
-                .put();
-
-            fail("Must fail to restore app with same name as existing app");
-
-        } catch ( UniformInterfaceException e ) {
-            Assert.assertEquals(409, e.getResponse().getStatus());
-        }
-    }
-
-
-    /**
-     * Test that we cannot delete an app with same name as an app that is already deleted.
-     * TODO: investigate way to support this, there should be no such restriction.
-     */
-    @Test
-    public void testAppDeleteConflict() throws Exception {
-
-        // create app with a collection of "things"
-
-        String orgName = clientSetup.getOrganization().getName();
-        String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
-        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
-
-        List<Entity> entities = new ArrayList<>();
-
-        UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
-
-        // delete the app
-
-        clientSetup.getRestClient()
-            .org( orgName ).app(appToDeleteId.toString() ).getResource()
-            .queryParam( "access_token", orgAdminToken.getAccessToken() )
-            .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
-            .delete();
-
-        // create new app with same name
-
-        UUID newAppId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
-
-        // attempt to delete new app, it should fail
-
-        try {
-
-            clientSetup.getRestClient()
-                .org(orgName).app( newAppId.toString() ).getResource()
-                .queryParam("access_token", orgAdminToken.getAccessToken())
-                .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
-                .delete();
-
-            fail("Must fail to delete app with same name as deleted app");
-
-        } catch ( UniformInterfaceException e ) {
-            Assert.assertEquals( 409, e.getResponse().getStatus() );
-        }
-    }
-
-
-    private UUID createAppWithCollection(
-        String orgName, String appName, Token orgAdminToken, List<Entity> entities) {
-
-        ApiResponse appCreateResponse = clientSetup.getRestClient()
-            .management().orgs().organization( orgName ).app().getResource()
-            .queryParam( "access_token", orgAdminToken.getAccessToken() )
-            .type( MediaType.APPLICATION_JSON )
-            .post( ApiResponse.class, new Application( appName ) );
-        UUID appId = appCreateResponse.getEntities().get(0).getUuid();
-
-        for ( int i=0; i<10; i++ ) {
-
-            final String entityName = "entity" + i;
-            Entity entity = new Entity();
-            entity.setProperties(new HashMap<String, Object>() {{
-                put("name", entityName );
-            }});
-
-            ApiResponse createResponse = clientSetup.getRestClient()
-                .org(orgName).app( appName ).collection("things").getResource()
-                .queryParam("access_token", orgAdminToken.getAccessToken())
-                .type(MediaType.APPLICATION_JSON)
-                .post( ApiResponse.class, entity );
-
-            entities.add( createResponse.getEntities().get(0) );
-        }
-        return appId;
-    }
-}
-


[5/9] incubator-usergrid git commit: Remove commented out code.

Posted by sn...@apache.org.
Remove commented out code.


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

Branch: refs/heads/USERGRID-533-create-app-test
Commit: 122e9aeee190ee4bb2dea89d65856f894196a9ad
Parents: 3a1ee57
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Apr 3 16:12:48 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Apr 3 16:12:48 2015 -0400

----------------------------------------------------------------------
 .../usergrid/corepersistence/CpEntityManager.java      | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/122e9aee/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 6013d54..c94fe5e 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -2243,14 +2243,11 @@ public class CpEntityManager implements EntityManager {
     private Id getIdForUniqueEntityField( final String collectionName, final String propertyName,
                                           final Object propertyValue ) {
 
-        //convert to a string, that's what we store
-        final Id results = ecm.getIdField( Inflector.getInstance().singularize( collectionName ), new StringField(
-                propertyName, propertyValue.toString() ) ).toBlocking() .lastOrDefault( null );
-
-//        final Id results = ecm.getIdField(
-//            Inflector.getInstance().singularize( collectionName ),
-//            new StringField( propertyName, propertyValue.toString() )
-//        ).toBlocking() .lastOrDefault( null );
+        // convert to a string, that's what we store
+        final Id results = ecm.getIdField(
+            Inflector.getInstance().singularize( collectionName ),
+            new StringField( propertyName, propertyValue.toString() )
+        ).toBlocking() .lastOrDefault( null );
 
         return results;
     }


[6/9] incubator-usergrid git commit: Merge branch 'two-dot-o-dev' into USERGRID-533-create-app-test

Posted by sn...@apache.org.
Merge branch 'two-dot-o-dev' into USERGRID-533-create-app-test

Conflicts:
	stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java


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

Branch: refs/heads/USERGRID-533-create-app-test
Commit: f9d538de911156eb0165122ad355e312194a87b3
Parents: 122e9ae 602a0a9
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Apr 6 10:07:45 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Apr 6 10:07:45 2015 -0400

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 39 ++++++-----
 .../corepersistence/util/CpNamingUtils.java     |  3 +-
 .../org/apache/usergrid/CoreApplication.java    |  2 +-
 .../usergrid/persistence/CollectionIT.java      |  1 +
 .../persistence/query/IteratingQueryIT.java     |  1 +
 .../serialization/impl/TypeField.java           | 43 ++++++++++++
 .../impl/UniqueTypeFieldRowKeySerializer.java   | 60 ++++++++++++++++
 .../UniqueValueSerializationStrategyV2Impl.java | 16 ++---
 .../collection/EntityCollectionManagerIT.java   | 72 +++++++++++---------
 .../index/ApplicationEntityIndex.java           |  2 +-
 .../persistence/index/impl/EntityIndexTest.java |  4 +-
 .../org/apache/usergrid/rest/ApiResponse.java   | 50 +++++++++-----
 .../exceptions/AbstractExceptionMapper.java     | 11 ++-
 .../rest/exceptions/UncaughtException.java      | 36 ++++++++++
 .../org/apache/usergrid/ServiceApplication.java |  2 +-
 .../usergrid/services/CollectionServiceIT.java  |  2 +
 16 files changed, 257 insertions(+), 87 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f9d538de/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index 5bc2036,baceeb4..d61a12e
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@@ -710,18 -711,27 +710,28 @@@ public class EntityCollectionManagerIT 
      public void testGetIdField() throws Exception {
  
          ApplicationScope context =  new ApplicationScopeImpl( new SimpleId( "organization" ) );
 +
+         EntityCollectionManager manager = factory.createCollectionManager( context );
+ 
+         // create an entity of type "item" with a unique_id field value = 1
+ 
          Entity entity1 = new Entity( new SimpleId( "item" ) );
          entity1.setField( new StringField( "unique_id", "1", true ));
-         EntityCollectionManager manager = factory.createCollectionManager( context );
          manager.write( entity1 ).toBlocking().last();
  
-         final Observable<Id> idO = manager.getIdField("item", new StringField("unique_id", "1"));
-         Id id = idO.toBlocking().lastOrDefault(null);
+         final Observable<Id> idObs = manager.getIdField("item", new StringField("unique_id", "1"));
+         Id id = idObs.toBlocking().lastOrDefault(null);
          assertEquals(entity1.getId(), id);
  
-         final Observable<Id> badIdO = manager.getIdField("deleted_item", new StringField("unique_id", "1"));
-         Id badId = badIdO.toBlocking().lastOrDefault(null);
-         assertEquals(entity1.getId(), badId );
+         // create an entity of type "deleted_item" with a unique_id field value = 1
+ 
+         Entity entity2 = new Entity( new SimpleId( "deleted_item" ) );
+         entity2.setField( new StringField( "unique_id", "1", true ));
+         manager = factory.createCollectionManager( context );
+         manager.write( entity2 ).toBlocking().last();
+ 
+         final Observable<Id> id2Obs = manager.getIdField("deleted_item", new StringField("unique_id", "1"));
+         Id id2 = id2Obs.toBlocking().lastOrDefault(null);
+         assertEquals(entity2.getId(), id2);
      }
  }


[8/9] incubator-usergrid git commit: Fix to lookupApplication() and some initial test code.

Posted by sn...@apache.org.
Fix to lookupApplication() and some initial test code.


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

Branch: refs/heads/USERGRID-533-create-app-test
Commit: a5a014cfd6a9c7834e1e528f559db2cc86721200
Parents: 35e0453
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Apr 6 14:14:35 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Apr 6 14:14:35 2015 -0400

----------------------------------------------------------------------
 .../corepersistence/ApplicationIdCacheImpl.java | 22 ++++++-
 .../cassandra/EntityManagerFactoryImplIT.java   | 16 +++++
 .../rest/applications/ApplicationCreateIT.java  | 68 +++++++++++++++-----
 3 files changed, 88 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a5a014cf/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
index e2d1f5a..657f662 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
@@ -29,15 +29,19 @@ import org.apache.usergrid.persistence.EntityManagerFactory;
 import org.apache.usergrid.persistence.Schema;
 import org.apache.usergrid.persistence.collection.EntityCollectionManager;
 import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
+import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.field.StringField;
+import org.apache.usergrid.utils.UUIDUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import rx.Observable;
 
 import java.util.UUID;
 
+import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
+
 
 /**
  * Implements the org app cache for faster runtime lookups.  These values are immutable, so this LRU cache can stay
@@ -89,7 +93,8 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
         final UUID value;
 
         EntityCollectionManager ecm = emf.getManagerCache().getEntityCollectionManager(
-            new ApplicationScopeImpl( new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, Schema.TYPE_APPLICATION ) ) );
+            new ApplicationScopeImpl(
+                new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, Schema.TYPE_APPLICATION ) ) );
 
         try {
             if ( rootEm.getApplication() == null ) {
@@ -100,11 +105,22 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
         }
 
         try {
+
+            // look up application_info ID for application using unique "name" field
             final Observable<Id> idObs = ecm.getIdField(
-                Schema.TYPE_APPLICATION, new StringField( Schema.PROPERTY_NAME, applicationName ));
+                CpNamingUtils.APPLICATION_INFO, new StringField(Schema.PROPERTY_NAME, applicationName));
 
             Id id = idObs.toBlocking().lastOrDefault(null);
-            value = id.getUuid();
+            UUID applicationInfoId = id.getUuid();
+
+            // get the application_info by ID
+            Entity applicationInfo = ecm.load(
+                new SimpleId( applicationInfoId, CpNamingUtils.APPLICATION_INFO ))
+            .toBlocking().lastOrDefault( null );
+
+            // extract application UUID from application_info
+            value = UUIDUtils.tryExtractUUID(
+                applicationInfo.getField( PROPERTY_APPLICATION_ID ).getValue().toString() );
 
             logger.debug("Loaded for key {} value {}", applicationName, value );
             return value;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a5a014cf/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index b64f0b5..da3fde6 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
+import junit.framework.Assert;
 import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.utils.UUIDUtils;
 import org.junit.AfterClass;
@@ -309,4 +310,19 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 		 */
         traceTagReporter.report( traceTagManager.detach() );
     }
+
+
+    @Test
+    public void testCreateAndImmediateGet() throws Exception {
+
+        String random = RandomStringUtils.randomAlphabetic(10);
+        String orgName = "org_" + random;
+        String appName = "app_" + random;
+        String orgAppName = orgName + "/" + appName;
+
+        UUID appId = setup.createApplication(orgName, appName);
+        UUID lookedUpId = setup.getEmf().lookupApplication( orgAppName );
+
+        Assert.assertEquals(appId, lookedUpId);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a5a014cf/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
index ba5e1d9..2dfdf78 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.rest.applications;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.sun.jersey.api.client.UniformInterfaceException;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResponse;
 import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
@@ -32,11 +33,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.ws.rs.core.MediaType;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
 
@@ -45,24 +44,62 @@ public class ApplicationCreateIT extends AbstractRestIT {
 
 
     /**
-     * Ensure that we can create many apps and successfully page through them.
+     * Test that we can create and then immediately retrieve an app by name.
      * https://issues.apache.org/jira/browse/USERGRID-491
-     *
-     * <pre>
-     * </pre>
      */
     @Test
-    public void testCreateAndRetreieveApps() throws Exception {
+    public void testCreateAndImmediateGet() throws Exception {
 
-        // create app with a collection of "things"
+        // create app
 
         String orgName = clientSetup.getOrganization().getName();
-        String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
-        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
+        String appName = clientSetup.getAppName() + "_new_app";
+        Token orgAdminToken = getAdminToken(clientSetup.getUsername(), clientSetup.getUsername());
 
-        List<Entity> entities = new ArrayList<>();
+        ApiResponse appCreateResponse = clientSetup.getRestClient()
+            .management().orgs().organization( orgName ).app().getResource()
+            .queryParam( "access_token", orgAdminToken.getAccessToken() )
+            .type( MediaType.APPLICATION_JSON )
+            .post(ApiResponse.class, new Application(appName));
+        appCreateResponse.getEntities().get(0).getUuid();
+
+        // should be able to immediate get the application's roles collection
+
+        String response = clientSetup.getRestClient().getResource()
+            .path("/" + clientSetup.getOrganizationName() + "/" + appName + "/roles" )
+            .get(String.class);
+        logger.error( response );
 
-        UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+    }
+
+
+    /**
+     * Test that we can create applications and the immediately retrieve them all.
+     */
+    @Test
+    public void testCreateAndImmediateList() throws Exception {
+
+        int appCount = 40;
+
+        String random = RandomStringUtils.randomAlphabetic(10);
+        String orgName = "org_" + random;
+        String appName = "app_" + random;
+        Token orgAdminToken = getAdminToken(clientSetup.getUsername(), clientSetup.getUsername());
+
+        for ( int i=0; i<appCount; i++ ) {
+           createAppWithCollection( orgName, appName + i, orgAdminToken, new ArrayList<>() );
+        }
+
+        // test that we get all applications back from the management end-point
+
+        ManagementResponse orgAppResponse = clientSetup.getRestClient()
+            .management().orgs().organization( orgName ).apps().getOrganizationApplications();
+
+        int count = 0;
+        for ( String name : orgAppResponse.getData().keySet() ) {
+            count++;
+        }
+        assertEquals( appCount, count );
     }
 
 
@@ -76,7 +113,8 @@ public class ApplicationCreateIT extends AbstractRestIT {
             .post( ApiResponse.class, new Application( appName ) );
         UUID appId = appCreateResponse.getEntities().get(0).getUuid();
 
-        for ( int i=0; i<10; i++ ) {
+
+        for ( int i=0; i<5; i++ ) {
 
             final String entityName = "entity" + i;
             Entity entity = new Entity();


[9/9] incubator-usergrid git commit: Minor fix to app delete to prevent unchecked cast warning.

Posted by sn...@apache.org.
Minor fix to app delete to prevent unchecked cast warning.


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

Branch: refs/heads/two-dot-o-dev
Commit: 6ff6d049db72b5fa36c15ba233ae9c98b2349c80
Parents: 2464c62
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Apr 6 16:50:25 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Apr 6 16:50:25 2015 -0400

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 22 ++++++++++++--------
 1 file changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6ff6d049/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index c157dc5..7e49231 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -74,6 +74,7 @@ import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
 import rx.Observable;
+import rx.observables.BlockingObservable;
 
 import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -316,7 +317,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
             managementAppId, edgeType, Long.MAX_VALUE,
             SearchByEdgeType.Order.DESCENDING, null));
 
-        appInfoEdges.flatMap(appInfoEdge -> {
+        final Observable<Edge> observable = appInfoEdges.flatMap(appInfoEdge -> {
             try {
                 Entity appInfoToDelete = managementEm.get(appInfoEdge.getTargetNode().getUuid());
                 final Id deletedAppId = new SimpleId(appInfoToDelete.getUuid(), appInfoToDelete.getType());
@@ -324,6 +325,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
                 final ApplicationEntityIndex aei = entityIndexFactory.createApplicationEntityIndex(deletedAppScope);
 
                 // ensure that there is not already a deleted app with the same name
+
                 final EntityRef alias = managementEm.getAlias(
                     CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getName());
                 if (alias != null) {
@@ -334,6 +336,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
                 final Entity deletedApp = managementEm.create(
                     CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getProperties());
+
                 // copy its connections too
 
                 final Set<String> connectionTypes = managementEm.getConnectionTypes(appInfoToDelete);
@@ -358,17 +361,18 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
                 return Observable.concat(copyConnections, deleteNodeGraph, deleteAppFromIndex)
                     .doOnCompleted(() -> {
-                    try {
-                        managementEm.delete(appInfoToDelete);
-                        applicationIdCache.evictAppId(appInfoToDelete.getName());
-                    }catch (Exception e){
-                        throw  new RuntimeException(e);
-                    }
-                });
+                        try {
+                            managementEm.delete(appInfoToDelete);
+                            applicationIdCache.evictAppId(appInfoToDelete.getName());
+                        } catch (Exception e) {
+                            throw new RuntimeException(e);
+                        }
+                    });
             } catch (Exception e) {
                 throw new RuntimeException(e);
             }
-        }).toBlocking().lastOrDefault(null);
+        });
+        observable.toBlocking().lastOrDefault(null);
 
     }
 


[3/9] incubator-usergrid git commit: New test for getIdField()

Posted by sn...@apache.org.
New test for getIdField()


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

Branch: refs/heads/USERGRID-533-create-app-test
Commit: d159bec75f9ae7a1699ad870a66e634e9d07c605
Parents: fdd7193
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Apr 3 15:36:14 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Apr 3 15:36:14 2015 -0400

----------------------------------------------------------------------
 .../collection/EntityCollectionManagerIT.java    | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d159bec7/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index f6d9782..53f8052 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@ -719,4 +719,23 @@ public class EntityCollectionManagerIT {
         assertFalse( uniqueValues.iterator().hasNext() );
 
     }
+
+    @Test
+    public void testGetIdField() throws Exception {
+
+        ApplicationScope context =  new ApplicationScopeImpl( new SimpleId( "organization" ) );
+
+        Entity entity1 = new Entity( new SimpleId( "item" ) );
+        entity1.setField( new StringField( "unique_id", "1", true ));
+        EntityCollectionManager manager = factory.createCollectionManager( context );
+        manager.write( entity1 ).toBlocking().last();
+
+        final Observable<Id> idO = manager.getIdField("item", new StringField("unique_id", "1"));
+        Id id = idO.toBlocking().lastOrDefault(null);
+        assertEquals(entity1.getId(), id);
+
+        final Observable<Id> badIdO = manager.getIdField("deleted_item", new StringField("unique_id", "1"));
+        Id badId = badIdO.toBlocking().lastOrDefault(null);
+        assertEquals(entity1.getId(), badId );
+    }
 }


[4/9] incubator-usergrid git commit: Merge branch 'two-dot-o-dev' into USERGRID-533-create-app-test

Posted by sn...@apache.org.
Merge branch 'two-dot-o-dev' into USERGRID-533-create-app-test


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

Branch: refs/heads/USERGRID-533-create-app-test
Commit: 3a1ee574ccc2a4bd9a0de6ede5ea732619aa65f7
Parents: d159bec 29f231b
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Apr 3 15:59:46 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Apr 3 15:59:46 2015 -0400

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 180 +++------
 .../corepersistence/CpEntityManagerFactory.java |  62 ++--
 .../corepersistence/CpManagerCache.java         |  10 +-
 .../corepersistence/CpRelationManager.java      | 129 ++-----
 .../usergrid/corepersistence/CpWalker.java      |   4 +-
 .../usergrid/corepersistence/ManagerCache.java  |   4 +-
 .../events/EntityDeletedHandler.java            |  34 +-
 .../events/EntityVersionCreatedHandler.java     |  14 +-
 .../events/EntityVersionDeletedHandler.java     |  89 +++--
 .../migration/AppInfoMigrationPlugin.java       |  14 +-
 .../migration/EntityTypeMappingMigration.java   |   4 +-
 .../results/ElasticSearchQueryExecutor.java     |   5 +
 .../results/FilteringLoader.java                | 113 +++---
 .../rx/impl/AllApplicationsObservableImpl.java  |   8 +-
 .../rx/impl/AllEntitiesInSystemImpl.java        |  13 +-
 .../corepersistence/util/CpNamingUtils.java     | 146 ++++++--
 .../usergrid/persistence/EntityManager.java     |   6 +-
 .../persistence/EntityManagerFactory.java       |   6 +-
 .../cassandra/EntityManagerFactoryImpl.java     |   7 +
 .../cassandra/EntityManagerImpl.java            |   6 +-
 .../org/apache/usergrid/CoreApplication.java    |  10 +-
 .../org/apache/usergrid/CoreITSetupImpl.java    |   9 +-
 .../corepersistence/StaleIndexCleanupTest.java  |  21 +-
 .../migration/EntityTypeMappingMigrationIT.java |  10 +-
 .../rx/AllEntitiesInSystemObservableIT.java     |   2 +-
 .../rx/EdgesFromSourceObservableIT.java         |   9 +-
 .../rx/EdgesToTargetObservableIT.java           |  53 ++-
 .../usergrid/persistence/CollectionIT.java      |   2 +-
 .../persistence/query/IteratingQueryIT.java     |   2 +
 .../apache/usergrid/utils/EdgeTestUtils.java    |  50 +++
 .../persistence/collection/CollectionScope.java |  45 ---
 .../collection/EntityCollectionManager.java     |  49 ++-
 .../EntityCollectionManagerFactory.java         |  13 +-
 .../persistence/collection/FieldSet.java        |   2 +-
 .../cache/CachedEntityCollectionManager.java    |  14 +-
 .../collection/event/EntityDeleted.java         |   8 +-
 .../collection/event/EntityVersionCreated.java  |   7 +-
 .../collection/event/EntityVersionDeleted.java  |   8 +-
 .../exception/CollectionRuntimeException.java   |  30 +-
 .../exception/EntityTooLargeException.java      |   6 +-
 .../exception/WriteCommitException.java         |  11 +-
 .../WriteOptimisticVerifyException.java         |  11 +-
 .../exception/WriteStartException.java          |  11 +-
 .../exception/WriteUniqueVerifyException.java   |   6 +-
 .../collection/guice/CollectionModule.java      |   3 +-
 .../guice/CollectionTaskExecutor.java           |   4 +-
 .../collection/impl/CollectionScopeImpl.java    | 102 -----
 .../EntityCollectionManagerFactoryImpl.java     |  21 +-
 .../impl/EntityCollectionManagerImpl.java       |  44 ++-
 .../collection/impl/EntityDeletedTask.java      |  36 +-
 .../impl/EntityVersionCleanupTask.java          |  18 +-
 .../impl/EntityVersionCreatedTask.java          |  13 +-
 .../impl/EntityVersionTaskFactory.java          |  17 +-
 .../mvcc/MvccLogEntrySerializationStrategy.java |  80 ----
 .../collection/mvcc/changelog/ChangeLog.java    |   2 -
 .../mvcc/entity/MvccValidationUtils.java        |  16 -
 .../mvcc/entity/impl/MvccEntityDeleteEvent.java |   8 +-
 .../mvcc/entity/impl/MvccEntityEvent.java       |  11 +-
 .../mvcc/entity/impl/MvccEntityWriteEvent.java  |   6 +-
 .../mvcc/stage/CollectionIoEvent.java           |   9 +-
 .../mvcc/stage/EntityUpdateEvent.java           |  34 --
 .../mvcc/stage/delete/MarkCommit.java           |  15 +-
 .../collection/mvcc/stage/delete/MarkStart.java |  20 +-
 .../mvcc/stage/write/RollbackAction.java        |  12 +-
 .../mvcc/stage/write/WriteCommit.java           |  25 +-
 .../mvcc/stage/write/WriteOptimisticVerify.java |  12 +-
 .../collection/mvcc/stage/write/WriteStart.java |  16 +-
 .../mvcc/stage/write/WriteUniqueVerify.java     |  41 +-
 .../MvccEntitySerializationStrategy.java        |  18 +-
 .../MvccLogEntrySerializationStrategy.java      |  82 ++++
 .../collection/serialization/UniqueValue.java   |   1 -
 .../UniqueValueSerializationStrategy.java       |  37 +-
 .../serialization/UniqueValueSet.java           |   3 -
 .../impl/CollectionDataVersions.java            |  12 +-
 .../impl/EntityVersionSerializer.java           |   9 +-
 .../serialization/impl/LogEntryIterator.java    |   8 +-
 .../serialization/impl/MutableFieldSet.java     |   6 +-
 .../MvccEntitySerializationStrategyImpl.java    |  73 ++--
 ...vccEntitySerializationStrategyProxyImpl.java |  18 +-
 .../MvccEntitySerializationStrategyV3Impl.java  |  83 ++---
 .../MvccLogEntrySerializationProxyImpl.java     | 149 ++++++++
 .../MvccLogEntrySerializationStrategyImpl.java  |  92 ++---
 ...MvccLogEntrySerializationStrategyV1Impl.java | 118 ++++++
 ...MvccLogEntrySerializationStrategyV2Impl.java | 106 ++++++
 .../serialization/impl/SerializationModule.java | 151 +++++---
 .../serialization/impl/UniqueFieldEntry.java    |   1 -
 .../impl/UniqueFieldEntrySerializer.java        |   3 -
 .../serialization/impl/UniqueValueImpl.java     |   5 +-
 .../UniqueValueSerializationStrategyImpl.java   | 212 ++++++-----
 ...iqueValueSerializationStrategyProxyImpl.java | 179 +++++++++
 .../UniqueValueSerializationStrategyV1Impl.java | 159 ++++++++
 .../UniqueValueSerializationStrategyV2Impl.java | 139 +++++++
 .../migration/CollectionMigrationPlugin.java    |   2 +-
 .../impl/migration/EntityIdScope.java           |  12 +-
 .../migration/MvccEntityDataMigrationImpl.java  |  56 ++-
 .../serialization/impl/util/Inflector.java      | 370 +++++++++++++++++++
 .../impl/util/LegacyScopeUtils.java             |  51 +++
 .../collection/ApplicationContextImplTest.java  |  33 ++
 .../collection/CollectionContextImplTest.java   |  53 ---
 .../EntityCollectionManagerFactoryTest.java     |   9 +-
 .../collection/EntityCollectionManagerIT.java   |  92 ++---
 .../EntityCollectionManagerStressTest.java      |  14 +-
 .../impl/EntityVersionCleanupTaskTest.java      |  35 +-
 .../impl/EntityVersionCreatedTaskTest.java      |  27 +-
 .../mvcc/stage/AbstractEntityStageTest.java     |   6 +-
 .../mvcc/stage/AbstractIdStageTest.java         |   4 +-
 .../mvcc/stage/AbstractMvccEntityStageTest.java |   6 +-
 .../mvcc/stage/TestEntityGenerator.java         |   2 +-
 .../mvcc/stage/delete/MarkCommitTest.java       |  14 +-
 .../mvcc/stage/delete/MarkStartTest.java        |   6 +-
 ...niqueValueSerializationStrategyImplTest.java | 330 -----------------
 .../mvcc/stage/write/WriteCommitTest.java       |  12 +-
 .../stage/write/WriteOptimisticVerifyTest.java  |  35 +-
 .../mvcc/stage/write/WriteStartTest.java        |  20 +-
 .../mvcc/stage/write/WriteUniqueVerifyIT.java   |  34 +-
 .../mvcc/stage/write/WriteUniqueVerifyTest.java |  13 +-
 .../impl/LogEntryIteratorTest.java              |  14 +-
 ...MvccEntitySerializationStrategyImplTest.java |  50 +--
 ...ntitySerializationStrategyProxyV1_3Test.java |   2 -
 ...ntitySerializationStrategyProxyV2_3Test.java |   2 -
 ...ccEntitySerializationStrategyV1ImplTest.java |  10 +-
 ...ccEntitySerializationStrategyV2ImplTest.java |  10 +-
 .../MvccEntitySerializationStrategyV2Test.java  |  20 +-
 ...ccEntitySerializationStrategyV3ImplTest.java |  16 +-
 .../impl/MvccLESSTransientTest.java             |  27 +-
 ...ccLogEntrySerializationStrategyImplTest.java | 107 +++---
 ...EntrySerializationStrategyProxyImplTest.java |  90 +++++
 ...LogEntrySerializationStrategyV1ImplTest.java |  55 +++
 ...LogEntrySerializationStrategyV2ImplTest.java |  53 +++
 .../impl/ScopedRowKeySerializerTest.java        |   2 +-
 .../impl/SerializationComparison.java           |   2 +-
 .../impl/SettingsValidationTest.java            |   1 -
 ...niqueValueSerializationStrategyImplTest.java | 344 +++++++++++++++++
 ...ValueSerializationStrategyProxyImplTest.java | 100 +++++
 ...queValueSerializationStrategyV1ImplTest.java |  57 +++
 ...queValueSerializationStrategyV2ImplTest.java |  58 +++
 ...ctMvccEntityDataMigrationV1ToV3ImplTest.java |   9 +-
 .../MvccEntityDataMigrationV1ToV3ImplTest.java  |   6 -
 .../collection/util/EntityHelper.java           |   1 -
 .../collection/util/LogEntryMock.java           |  10 +-
 .../collection/util/UniqueValueEntryMock.java   |  17 +-
 .../persistence/core/guice/ProxyImpl.java       |  42 ---
 .../core/migration/data/VersionedData.java      |   2 +-
 .../core/migration/schema/Migration.java        |   2 +-
 .../persistence/core/rx/ObservableIterator.java |   2 +
 .../core/scope/ApplicationScopeImpl.java        |   3 +
 .../persistence/graph/guice/GraphModule.java    |   5 +-
 .../graph/impl/GraphManagerImpl.java            |   3 +-
 .../graph/impl/stage/EdgeMetaRepairImpl.java    |   3 +-
 .../impl/stage/NodeDeleteListenerImpl.java      |   3 +-
 .../shard/count/NodeShardApproximationImpl.java |  11 +-
 .../graph/impl/EdgeDeleteListenerTest.java      |   3 -
 .../graph/impl/NodeDeleteListenerTest.java      |   3 -
 .../graph/impl/stage/EdgeMetaRepairTest.java    |   3 -
 .../EdgeMetaDataSerializationProxyV1Test.java   |   3 -
 .../EdgeMetaDataSerializationProxyV2Test.java   |   2 -
 .../index/impl/EntityToMapConverter.java        |  10 +-
 .../impl/EsApplicationEntityIndexImpl.java      |  14 +-
 .../index/impl/EsIndexBufferConsumerImpl.java   |  79 ++--
 .../persistence/index/impl/EntityIndexTest.java |   2 +-
 .../apache/usergrid/rest/MigrateResource.java   |   2 +
 .../org/apache/usergrid/rest/RootResource.java  |   6 +-
 .../applications/ApplicationResource.java       |   2 +-
 .../organizations/AdminEmailEncodingIT.java     |   6 +-
 .../cassandra/ApplicationCreatorImpl.java       |  12 +-
 .../apns/FailedConnectionListener.java          |  31 +-
 .../org/apache/usergrid/ServiceITSetup.java     |   2 +
 .../org/apache/usergrid/ServiceITSetupImpl.java |  11 +-
 .../migration/AppInfoMigrationPluginTest.java   |   7 +-
 .../apache/usergrid/management/EmailFlowIT.java |   3 +-
 .../cassandra/ApplicationCreatorIT.java         |  10 +-
 171 files changed, 3744 insertions(+), 2314 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3a1ee574/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 2ae9e64,5647d18..6013d54
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@@ -2296,20 -2243,9 +2243,15 @@@ public class CpEntityManager implement
      private Id getIdForUniqueEntityField( final String collectionName, final String propertyName,
                                            final Object propertyValue ) {
  
-         CollectionScope collectionScope = getCollectionScopeNameFromEntityType(
-             getApplicationScope().getApplication(), collectionName);
- 
-         final EntityCollectionManager ecm = managerCache.getEntityCollectionManager(collectionScope);
- 
          //convert to a string, that's what we store
-         final Id results = ecm.getIdField( new StringField(
+         final Id results = ecm.getIdField( Inflector.getInstance().singularize( collectionName ), new StringField(
                  propertyName, propertyValue.toString() ) ).toBlocking() .lastOrDefault( null );
 +
 +//        final Id results = ecm.getIdField(
 +//            Inflector.getInstance().singularize( collectionName ),
 +//            new StringField( propertyName, propertyValue.toString() )
 +//        ).toBlocking() .lastOrDefault( null );
 +
          return results;
      }
  

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3a1ee574/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------


[2/9] incubator-usergrid git commit: Look up app by name from EntityCollectionManager instead of using search.

Posted by sn...@apache.org.
Look up app by name from EntityCollectionManager instead of using search.


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

Branch: refs/heads/USERGRID-533-create-app-test
Commit: fdd719306a3937e2cd0916c03494ccdb3ece66d1
Parents: 721e385
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Apr 3 15:35:25 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Apr 3 15:35:25 2015 -0400

----------------------------------------------------------------------
 .../corepersistence/ApplicationIdCacheImpl.java | 51 +++++++++-----------
 .../corepersistence/CpEntityManager.java        |  6 +++
 2 files changed, 29 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fdd71930/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
index 379f306..ebd7798 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
@@ -20,20 +20,23 @@
 package org.apache.usergrid.corepersistence;
 
 
-import java.util.UUID;
-import java.util.concurrent.ExecutionException;
-
-import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.*;
-
-import com.google.common.base.Optional;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.utils.UUIDUtils;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.Schema;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.field.StringField;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import rx.Observable;
+
+import java.util.UUID;
 
 
 /**
@@ -48,6 +51,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
      * Cache the pointer to our root entity manager for reference
      */
     private final EntityManager rootEm;
+    private final CpEntityManagerFactory emf;
 
     private final LoadingCache<String, UUID> appCache =
         CacheBuilder.newBuilder().maximumSize( 10000 ).build( new CacheLoader<String, UUID>() {
@@ -59,6 +63,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
 
 
     public ApplicationIdCacheImpl(final EntityManagerFactory emf) {
+        this.emf = (CpEntityManagerFactory)emf;
         this.rootEm = emf.getEntityManager( emf.getManagementAppId());
     }
 
@@ -81,35 +86,25 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
      */
     private UUID fetchApplicationId( final String applicationName ) {
 
-        UUID value = null;
+        final UUID value;
+
+        EntityCollectionManager ecm = emf.getManagerCache().getEntityCollectionManager(
+            new ApplicationScopeImpl( new SimpleId( CpNamingUtils.SYSTEM_APP_ID, Schema.TYPE_APPLICATION ) ) );
 
         try {
             if ( rootEm.getApplication() == null ) {
                 return null;
             }
         } catch ( Exception e ) {
-            logger.error("Error looking up app", e);
+            logger.error("Error looking up management app", e);
         }
 
         try {
-            Query q = Query.fromQL( Schema.PROPERTY_NAME + " = '" + applicationName.toLowerCase() + "'" );
-
-            Results results = rootEm.searchCollection(
-                rootEm.getApplicationRef(), CpNamingUtils.APPLICATION_INFOS, q);
-
-            if ( !results.isEmpty() ) {
+            final Observable<Id> idObs = ecm.getIdField(
+                Schema.TYPE_APPLICATION, new StringField( Schema.PROPERTY_NAME, applicationName ));
 
-                Entity entity = results.iterator().next();
-                Object uuidObject = entity.getProperty(Schema.PROPERTY_APPLICATION_ID);
-
-                if (uuidObject instanceof UUID) {
-                    value = (UUID) uuidObject;
-                } else {
-                    value = UUIDUtils.tryExtractUUID(
-                        entity.getProperty(Schema.PROPERTY_APPLICATION_ID).toString());
-                }
-
-            }
+            Id id = idObs.toBlocking().lastOrDefault(null);
+            value = id.getUuid();
 
             logger.debug("Loaded    for key {} value {}", applicationName, value );
             return value;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fdd71930/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index efdad6d..2ae9e64 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -2304,6 +2304,12 @@ public class CpEntityManager implements EntityManager {
         //convert to a string, that's what we store
         final Id results = ecm.getIdField( new StringField(
                 propertyName, propertyValue.toString() ) ).toBlocking() .lastOrDefault( null );
+
+//        final Id results = ecm.getIdField(
+//            Inflector.getInstance().singularize( collectionName ),
+//            new StringField( propertyName, propertyValue.toString() )
+//        ).toBlocking() .lastOrDefault( null );
+
         return results;
     }
 


[7/9] incubator-usergrid git commit: System app is deprecated.

Posted by sn...@apache.org.
System app is deprecated.


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

Branch: refs/heads/USERGRID-533-create-app-test
Commit: 35e04534505a8e8ef490ac8139f31daa227f785f
Parents: f9d538d
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Apr 6 13:06:13 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Apr 6 13:06:13 2015 -0400

----------------------------------------------------------------------
 .../apache/usergrid/corepersistence/ApplicationIdCacheImpl.java  | 4 ++--
 .../apache/usergrid/corepersistence/CpEntityManagerFactory.java  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/35e04534/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
index ebd7798..e2d1f5a 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
@@ -89,7 +89,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
         final UUID value;
 
         EntityCollectionManager ecm = emf.getManagerCache().getEntityCollectionManager(
-            new ApplicationScopeImpl( new SimpleId( CpNamingUtils.SYSTEM_APP_ID, Schema.TYPE_APPLICATION ) ) );
+            new ApplicationScopeImpl( new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, Schema.TYPE_APPLICATION ) ) );
 
         try {
             if ( rootEm.getApplication() == null ) {
@@ -106,7 +106,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
             Id id = idObs.toBlocking().lastOrDefault(null);
             value = id.getUuid();
 
-            logger.debug("Loaded    for key {} value {}", applicationName, value );
+            logger.debug("Loaded for key {} value {}", applicationName, value );
             return value;
         }
         catch ( Exception e ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/35e04534/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 1a9091e..15520b4 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -156,7 +156,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
             entityIndex.refresh();
 
         } catch (Exception ex) {
-            throw new RuntimeException("Fatal error creating system application", ex);
+            throw new RuntimeException("Fatal error creating management application", ex);
         }
     }