Add delays to the App Delete tests as UV cleanup and take a couple of seconds.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/db6950b9 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/db6950b9 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/db6950b9 Branch: refs/heads/apigee-sso-provider Commit: db6950b9a476e0f1b77f1333d8852486232e4a9c Parents: 670248d Author: Dave Johnson <snoopd...@apache.org> Authored: Tue Jul 5 15:16:13 2016 -0400 Committer: Dave Johnson <snoopd...@apache.org> Committed: Tue Jul 5 15:16:13 2016 -0400 ---------------------------------------------------------------------- ...ApplicationAlreadyExistsExceptionMapper.java | 32 ++++++ .../rest/applications/ApplicationDeleteIT.java | 115 +++++++++++++++++-- 2 files changed, 135 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/db6950b9/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ApplicationAlreadyExistsExceptionMapper.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ApplicationAlreadyExistsExceptionMapper.java b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ApplicationAlreadyExistsExceptionMapper.java new file mode 100644 index 0000000..2c90f5d --- /dev/null +++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ApplicationAlreadyExistsExceptionMapper.java @@ -0,0 +1,32 @@ +/* + * 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.exceptions; + + +import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException; + +import javax.ws.rs.core.Response; + +import static javax.ws.rs.core.Response.Status.CONFLICT; + + +public class ApplicationAlreadyExistsExceptionMapper extends AbstractExceptionMapper<ApplicationAlreadyExistsException> { + @Override + public Response toResponse(ApplicationAlreadyExistsException e ) { + return toResponse( CONFLICT, e ); + } +} http://git-wip-us.apache.org/repos/asf/usergrid/blob/db6950b9/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 index 5858289..cc635ed 100644 --- 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 @@ -51,6 +51,55 @@ public class ApplicationDeleteIT extends AbstractRestIT { public static final int INDEXING_WAIT = 3000; + @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 + + clientSetup.getRestClient().management().orgs() + .org(orgName).apps().app(appToDeleteId.toString() ).getTarget() + .queryParam("access_token", orgAdminToken.getAccessToken() ) + .queryParam(CONFIRM_APPLICATION_IDENTIFIER, appToDeleteId) + .request().delete(); + + // test that we can create a new application with the same name + + ApiResponse appCreateAgainResponse = null; + + int retries = 0; + while ( retries++ < 100 ) { + try { + appCreateAgainResponse = clientSetup.getRestClient() + .management().orgs().org( orgName ).app().getTarget() + .queryParam( "access_token", orgAdminToken.getAccessToken() ).request() + .post( javax.ws.rs.client.Entity.json( new Application( appToDeleteName ) ), ApiResponse.class ); + + break; + + } catch (Exception e) { + logger.error("App not deleted yet. Waiting ... ({})", retries); + Thread.sleep( 1000 ); + } + } + + Assert.assertNotNull( appCreateAgainResponse ); + + Assert.assertEquals("Must be able to create app with same name as deleted app", + (orgName + "/" + appToDeleteName).toLowerCase(), + appCreateAgainResponse.getEntities().get(0).get( "name" )); + } + + /** * Test most common use cases. * <pre> @@ -62,7 +111,7 @@ public class ApplicationDeleteIT extends AbstractRestIT { * </pre> */ @Test - public void testBasicOperation() throws Exception { + public void testCommonUseCases() throws Exception { // create app with a collection of "things" @@ -91,9 +140,11 @@ public class ApplicationDeleteIT extends AbstractRestIT { .request() .delete(); + // test that we can no longer get the app - try { + try { // using /management/orgs/{org-name}/app/{app-name} + clientSetup.getRestClient().management().orgs() .org(orgName).apps().app(appToDeleteName).getTarget() .queryParam("access_token", orgAdminToken.getAccessToken()) @@ -109,7 +160,8 @@ public class ApplicationDeleteIT extends AbstractRestIT { } - try { + try { // using /{org-name}/{app-name} path + clientSetup.getRestClient().org( orgName ).app( appToDeleteName ).getTarget() .queryParam( "access_token", orgAdminToken.getAccessToken() ).request() .get( ApiResponse.class ); @@ -185,11 +237,25 @@ public class ApplicationDeleteIT extends AbstractRestIT { // test that we can create a new application with the same name - ApiResponse appCreateAgainResponse = clientSetup.getRestClient() - .management().orgs().org( orgName ).app().getTarget() - .queryParam( "access_token", orgAdminToken.getAccessToken() ) - .request() - .post( javax.ws.rs.client.Entity.json( new Application( appToDeleteName ) ), ApiResponse.class ); + ApiResponse appCreateAgainResponse = null; + + int retries = 0; + while ( retries++ < 20 ) { + try { + appCreateAgainResponse = clientSetup.getRestClient() + .management().orgs().org( orgName ).app().getTarget() + .queryParam( "access_token", orgAdminToken.getAccessToken() ).request() + .post( javax.ws.rs.client.Entity.json( new Application( appToDeleteName ) ), ApiResponse.class ); + + break; + + } catch (Exception e) { + logger.error("App not deleted yet. Waiting ... ({})", retries); + Thread.sleep( 1000 ); + } + } + + Assert.assertNotNull( appCreateAgainResponse ); Assert.assertEquals("Must be able to create app with same name as deleted app", (orgName + "/" + appToDeleteName).toLowerCase(), @@ -312,7 +378,20 @@ public class ApplicationDeleteIT extends AbstractRestIT { // create new app with same name - createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities); + UUID newAppId = null; + int retries = 0; + while ( retries++ < 20 ) { + try { + newAppId = createAppWithCollection( orgName, appToDeleteName, orgAdminToken, entities ); + break; + + } catch ( Exception e ) { + logger.error("Application not deleted yet. Waiting... ({})", retries); + Thread.sleep(1000); + } + } + + Assert.assertNotNull( newAppId ); // attempt to restore original app, should get 409 @@ -349,12 +428,24 @@ public class ApplicationDeleteIT extends AbstractRestIT { .orgs().org( orgName ).apps().app( appToDeleteId.toString() ).getTarget() .queryParam( "access_token", orgAdminToken.getAccessToken() ) .queryParam( CONFIRM_APPLICATION_IDENTIFIER, appToDeleteId ) - .request() - .delete(); + .request().delete(); // create new app with same name - UUID newAppId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities); + UUID newAppId = null; + int retries = 0; + while ( retries++ < 20 ) { + try { + newAppId = createAppWithCollection( orgName, appToDeleteName, orgAdminToken, entities ); + break; + + } catch ( Exception e ) { + logger.error("Application not deleted yet. Waiting... ({})", retries); + Thread.sleep(1000); + } + } + + Assert.assertNotNull( newAppId ); // attempt to delete new app, it should fail