Repository: incubator-usergrid Updated Branches: refs/heads/USERGRID-348 [created] 66fdc6123
[USERGRID-348] Added first working test under ExportResourseIT. Found bug using management gets with AppName so I created the ability to get with the stored application uuid instead. Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2ad1c045 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2ad1c045 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2ad1c045 Branch: refs/heads/USERGRID-348 Commit: 2ad1c045343f746b201187d0f5165ce32099f191 Parents: fb90854 Author: GERey <[email protected]> Authored: Mon Mar 23 16:35:57 2015 -0700 Committer: GERey <[email protected]> Committed: Mon Mar 23 16:35:57 2015 -0700 ---------------------------------------------------------------------- .../rest/management/ExportResourceIT.java | 1436 +++++++++--------- .../rest/test/resource2point0/ClientSetup.java | 9 +- .../endpoints/mgmt/ApplicationResource.java | 8 +- 3 files changed, 729 insertions(+), 724 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2ad1c045/stack/rest/src/test/java/org/apache/usergrid/rest/management/ExportResourceIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ExportResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ExportResourceIT.java index c8c221b..fbfc2b9 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ExportResourceIT.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ExportResourceIT.java @@ -30,8 +30,10 @@ import java.util.UUID; import javax.ws.rs.core.MediaType; -import org.apache.usergrid.rest.AbstractRestIT; +import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT; + import org.apache.usergrid.rest.TestContextSetup; +import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse; import static org.apache.usergrid.utils.MapUtils.hashMap; import static org.junit.Assert.assertEquals; @@ -52,7 +54,6 @@ public class ExportResourceIT extends AbstractRestIT { } - @Test public void exportCallSuccessful() throws Exception { ClientResponse.Status responseStatus = ClientResponse.Status.OK; @@ -60,734 +61,729 @@ public class ExportResourceIT extends AbstractRestIT { HashMap<String, Object> payload = payloadBuilder(); - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - try { - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) - .queryParam( "access_token", token ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - - assertEquals( ClientResponse.Status.OK, responseStatus ); - } - - - @Ignore( "is this test still valid knowing that the sch. won't run in intelliJ?" ) - public void exportCallCreationEntities100() throws Exception { - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - JsonNode node = null; - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - HashMap<String, Object> payload = new HashMap<String, Object>(); - Map<String, Object> properties = new HashMap<String, Object>(); - Map<String, Object> storage_info = new HashMap<String, Object>(); - //TODO: make sure to put a valid admin token here. - //TODO: always put dummy values here and ignore this test. - - - properties.put( "storage_provider", "s3" ); - properties.put( "storage_info", storage_info ); - - payload.put( "properties", properties ); - - for ( int i = 0; i < 100; i++ ) { - Map<String, String> userCreation = hashMap( "type", "app_user" ).map( "name", "fred" + i ); - - node = mapper.readTree( resource().path( "/test-organization/" + appName + "/app_users" ) - .queryParam( "access_token", access_token ) - .accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ) - .post( String.class, userCreation ) ); - } - - try { - node = mapper.readTree( resource().path( "/management/orgs/test-organization/apps/" + appName + "/export" ) - .queryParam( "access_token", adminToken() ) - .accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - - assertEquals( ClientResponse.Status.OK, responseStatus ); - } - - - @Test - public void exportApplicationUUIDRetTest() throws Exception { - ClientResponse.Status responseStatus = ClientResponse.Status.ACCEPTED; - String uuid; - UUID jobUUID = null; - JsonNode node = null; - - HashMap<String, Object> payload = payloadBuilder(); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - - assertEquals( ClientResponse.Status.ACCEPTED, responseStatus ); - assertNotNull( node.get( "Export Entity" ) ); - } - - - // - @Test - public void exportCollectionUUIDRetTest() throws Exception { - ClientResponse.Status responseStatus = ClientResponse.Status.ACCEPTED; - String uuid; - UUID jobUUID = null; - JsonNode node = null; - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - HashMap<String, Object> payload = payloadBuilder(); - - try { - node = mapper.readTree( - resource().path( "/management/orgs/"+orgName+"/apps/" + appName + "/collection/users/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - - assertEquals( ClientResponse.Status.ACCEPTED, responseStatus ); - assertNotNull( node.get( "Export Entity" ) ); - } - - - @Test - public void exportGetOrganizationJobStatTest() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - HashMap<String, Object> payload = payloadBuilder(); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - try { - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.OK, responseStatus ); - - String uuid = String.valueOf( node.get( "Export Entity" ) ); - uuid = uuid.replaceAll( "\"", "" ); - - try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/export/" + uuid ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - - - assertEquals( ClientResponse.Status.OK, responseStatus ); - assertEquals( "SCHEDULED", node.get( "state" ).textValue() );//TODO: do tests for other states in service tier - } - - - //all tests should be moved to OrganizationResourceIT ( *not* Organizations there is a difference) - @Test - public void exportGetApplicationJobStatTest() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - HashMap<String, Object> payload = payloadBuilder(); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - String uuid = String.valueOf( node.get( "Export Entity" ) ); - uuid = uuid.replaceAll( "\"", "" ); - - try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/export/" + uuid ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - - - assertEquals( ClientResponse.Status.OK, responseStatus ); - assertEquals( "SCHEDULED", node.get( "state" ).textValue() );//TODO: do tests for other states in service tier - } - - - @Test - public void exportGetCollectionJobStatTest() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - HashMap<String, Object> payload = payloadBuilder(); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - String uuid = String.valueOf( node.get( "Export Entity" ) ); - uuid = uuid.replaceAll( "\"", "" ); try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/export/" + uuid ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid()).addToPath( "collection" ) + .addToPath( "users" ).addToPath( "export" ).postWithToken(ApiResponse.class,payload ); } catch ( UniformInterfaceException uie ) { responseStatus = uie.getResponse().getClientResponseStatus(); } - assertEquals( ClientResponse.Status.OK, responseStatus ); - assertEquals( "SCHEDULED", node.get( "state" ).textValue() );//TODO: do tests for other states in service tier - } - - - // //do an unauthorized test for both post and get - @Test - public void exportGetWrongUUID() throws Exception { - JsonNode node = null; - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); - try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/export/" + fake ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - // - @Test - public void exportPostApplicationNullPointerProperties() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - HashMap<String, Object> payload = new HashMap<String, Object>(); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - @Test - public void exportPostOrganizationNullPointerProperties() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - HashMap<String, Object> payload = new HashMap<String, Object>(); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - try { - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - // - @Test - public void exportPostCollectionNullPointer() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - HashMap<String, Object> payload = new HashMap<String, Object>(); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - try { - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - @Test - public void exportGetCollectionUnauthorized() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - try { - node = mapper.readTree( resource() - .path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export/" + fake ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.UNAUTHORIZED, responseStatus ); - } - - - @Test - public void exportGetApplicationUnauthorized() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - try { - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export/" + fake ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .get( String.class ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.UNAUTHORIZED, responseStatus ); - } - - - @Test - public void exportGetOrganizationUnauthorized() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/export/" + fake ) - .accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.UNAUTHORIZED, responseStatus ); - } - - - @Test - public void exportPostOrganizationNullPointerStorageInfo() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - HashMap<String, Object> payload = payloadBuilder(); - HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); - //remove storage_info field - properties.remove( "storage_info" ); - - try { - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - @Test - public void exportPostApplicationNullPointerStorageInfo() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - HashMap<String, Object> payload = payloadBuilder(); - HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); - //remove storage_info field - properties.remove( "storage_info" ); - - try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - @Test - public void exportPostCollectionNullPointerStorageInfo() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - HashMap<String, Object> payload = payloadBuilder(); - HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); - //remove storage_info field - properties.remove( "storage_info" ); - - try { - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - @Test - public void exportPostOrganizationNullPointerStorageProvider() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - HashMap<String, Object> payload = payloadBuilder(); - HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); - //remove storage_info field - properties.remove( "storage_provider" ); - - - try { - node = resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .post( JsonNode.class, payload ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - @Test - public void exportPostApplicationNullPointerStorageProvider() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - HashMap<String, Object> payload = payloadBuilder(); - HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); - //remove storage_info field - properties.remove( "storage_provider" ); - - - try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - @Test - public void exportPostCollectionNullPointerStorageProvider() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - HashMap<String, Object> payload = payloadBuilder(); - HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); - //remove storage_info field - properties.remove( "storage_provider" ); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - - try { - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - @Test - public void exportPostOrganizationNullPointerStorageVerification() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - HashMap<String, Object> payload = payloadBuilder(); - HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); - HashMap<String, Object> storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); - //remove storage_key field - storage_info.remove( "s3_key" ); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - try { - node = resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .post( JsonNode.class, payload ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - - payload = payloadBuilder(); - properties = ( HashMap<String, Object> ) payload.get( "properties" ); - storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); - //remove storage_key field - storage_info.remove( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ); - - try { - node = resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .post( JsonNode.class, payload ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - - payload = payloadBuilder(); - properties = ( HashMap<String, Object> ) payload.get( "properties" ); - storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); - //remove storage_key field - storage_info.remove( "bucket_location" ); - - try { - node = resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .post( JsonNode.class, payload ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - @Test - public void exportPostApplicationNullPointerStorageVerification() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - HashMap<String, Object> payload = payloadBuilder(); - HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); - HashMap<String, Object> storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); - //remove storage_key field - storage_info.remove( "s3_key" ); - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - - payload = payloadBuilder(); - properties = ( HashMap<String, Object> ) payload.get( "properties" ); - storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); - //remove storage_key field - storage_info.remove( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ); - - try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - - payload = payloadBuilder(); - properties = ( HashMap<String, Object> ) payload.get( "properties" ); - storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); - //remove storage_key field - storage_info.remove( "bucket_location" ); - - try { - node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - @Test - public void exportPostCollectionNullPointerStorageVerification() throws Exception { - JsonNode node = null; - ClientResponse.Status responseStatus = ClientResponse.Status.OK; - - String orgName = context.getOrgName(); - String appName = context.getAppName(); - String token = context.getActiveUser().getToken(); - - HashMap<String, Object> payload = payloadBuilder(); - HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); - HashMap<String, Object> storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); - //remove storage_key field - storage_info.remove( "s3_key" ); - - try { - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - - payload = payloadBuilder(); - properties = ( HashMap<String, Object> ) payload.get( "properties" ); - storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); - //remove storage_key field - storage_info.remove( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR); - - try { - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - - payload = payloadBuilder(); - properties = ( HashMap<String, Object> ) payload.get( "properties" ); - storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); - storage_info.remove( "bucket_location" ); - - try { - node = mapper.readTree( - resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); } - +// +// @Ignore( "is this test still valid knowing that the sch. won't run in intelliJ?" ) +// public void exportCallCreationEntities100() throws Exception { +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// JsonNode node = null; +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// HashMap<String, Object> payload = new HashMap<String, Object>(); +// Map<String, Object> properties = new HashMap<String, Object>(); +// Map<String, Object> storage_info = new HashMap<String, Object>(); +// //TODO: make sure to put a valid admin token here. +// //TODO: always put dummy values here and ignore this test. +// +// +// properties.put( "storage_provider", "s3" ); +// properties.put( "storage_info", storage_info ); +// +// payload.put( "properties", properties ); +// +// for ( int i = 0; i < 100; i++ ) { +// Map<String, String> userCreation = hashMap( "type", "app_user" ).map( "name", "fred" + i ); +// +// node = mapper.readTree( resource().path( "/test-organization/" + appName + "/app_users" ) +// .queryParam( "access_token", access_token ) +// .accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ) +// .post( String.class, userCreation ) ); +// } +// +// try { +// node = mapper.readTree( resource().path( "/management/orgs/test-organization/apps/" + appName + "/export" ) +// .queryParam( "access_token", adminToken() ) +// .accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// +// assertEquals( ClientResponse.Status.OK, responseStatus ); +// } +// +// +// @Test +// public void exportApplicationUUIDRetTest() throws Exception { +// ClientResponse.Status responseStatus = ClientResponse.Status.ACCEPTED; +// String uuid; +// UUID jobUUID = null; +// JsonNode node = null; +// +// HashMap<String, Object> payload = payloadBuilder(); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// +// assertEquals( ClientResponse.Status.ACCEPTED, responseStatus ); +// assertNotNull( node.get( "Export Entity" ) ); +// } +// +// +// // +// @Test +// public void exportCollectionUUIDRetTest() throws Exception { +// ClientResponse.Status responseStatus = ClientResponse.Status.ACCEPTED; +// String uuid; +// UUID jobUUID = null; +// JsonNode node = null; +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// HashMap<String, Object> payload = payloadBuilder(); +// +// try { +// node = mapper.readTree( +// resource().path( "/management/orgs/"+orgName+"/apps/" + appName + "/collection/users/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// +// assertEquals( ClientResponse.Status.ACCEPTED, responseStatus ); +// assertNotNull( node.get( "Export Entity" ) ); +// } +// +// +// @Test +// public void exportGetOrganizationJobStatTest() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// HashMap<String, Object> payload = payloadBuilder(); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// try { +// node = mapper.readTree( +// resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) +// .post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.OK, responseStatus ); +// +// String uuid = String.valueOf( node.get( "Export Entity" ) ); +// uuid = uuid.replaceAll( "\"", "" ); +// +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/export/" + uuid ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// +// +// assertEquals( ClientResponse.Status.OK, responseStatus ); +// assertEquals( "SCHEDULED", node.get( "state" ).textValue() );//TODO: do tests for other states in service tier +// } +// +// +// //all tests should be moved to OrganizationResourceIT ( *not* Organizations there is a difference) +// @Test +// public void exportGetApplicationJobStatTest() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// HashMap<String, Object> payload = payloadBuilder(); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// String uuid = String.valueOf( node.get( "Export Entity" ) ); +// uuid = uuid.replaceAll( "\"", "" ); +// +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/export/" + uuid ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// +// +// assertEquals( ClientResponse.Status.OK, responseStatus ); +// assertEquals( "SCHEDULED", node.get( "state" ).textValue() );//TODO: do tests for other states in service tier +// } +// +// +// @Test +// public void exportGetCollectionJobStatTest() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// HashMap<String, Object> payload = payloadBuilder(); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// node = mapper.readTree( +// resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// String uuid = String.valueOf( node.get( "Export Entity" ) ); +// uuid = uuid.replaceAll( "\"", "" ); +// +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/export/" + uuid ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// +// +// assertEquals( ClientResponse.Status.OK, responseStatus ); +// assertEquals( "SCHEDULED", node.get( "state" ).textValue() );//TODO: do tests for other states in service tier +// } +// +// +// // //do an unauthorized test for both post and get +// @Test +// public void exportGetWrongUUID() throws Exception { +// JsonNode node = null; +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/export/" + fake ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// // +// @Test +// public void exportPostApplicationNullPointerProperties() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// HashMap<String, Object> payload = new HashMap<String, Object>(); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// @Test +// public void exportPostOrganizationNullPointerProperties() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// HashMap<String, Object> payload = new HashMap<String, Object>(); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// try { +// node = mapper.readTree( +// resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) +// .post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// // +// @Test +// public void exportPostCollectionNullPointer() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// HashMap<String, Object> payload = new HashMap<String, Object>(); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// try { +// node = mapper.readTree( +// resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// @Test +// public void exportGetCollectionUnauthorized() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// try { +// node = mapper.readTree( resource() +// .path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export/" + fake ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.UNAUTHORIZED, responseStatus ); +// } +// +// +// @Test +// public void exportGetApplicationUnauthorized() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// try { +// node = mapper.readTree( +// resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export/" + fake ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) +// .get( String.class ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.UNAUTHORIZED, responseStatus ); +// } +// +// +// @Test +// public void exportGetOrganizationUnauthorized() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/export/" + fake ) +// .accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.UNAUTHORIZED, responseStatus ); +// } +// +// +// @Test +// public void exportPostOrganizationNullPointerStorageInfo() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// HashMap<String, Object> payload = payloadBuilder(); +// HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// //remove storage_info field +// properties.remove( "storage_info" ); +// +// try { +// node = mapper.readTree( +// resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) +// .post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// @Test +// public void exportPostApplicationNullPointerStorageInfo() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// HashMap<String, Object> payload = payloadBuilder(); +// HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// //remove storage_info field +// properties.remove( "storage_info" ); +// +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// @Test +// public void exportPostCollectionNullPointerStorageInfo() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// HashMap<String, Object> payload = payloadBuilder(); +// HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// //remove storage_info field +// properties.remove( "storage_info" ); +// +// try { +// node = mapper.readTree( +// resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// @Test +// public void exportPostOrganizationNullPointerStorageProvider() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// HashMap<String, Object> payload = payloadBuilder(); +// HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// //remove storage_info field +// properties.remove( "storage_provider" ); +// +// +// try { +// node = resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) +// .post( JsonNode.class, payload ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// @Test +// public void exportPostApplicationNullPointerStorageProvider() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// HashMap<String, Object> payload = payloadBuilder(); +// HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// //remove storage_info field +// properties.remove( "storage_provider" ); +// +// +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// @Test +// public void exportPostCollectionNullPointerStorageProvider() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// HashMap<String, Object> payload = payloadBuilder(); +// HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// //remove storage_info field +// properties.remove( "storage_provider" ); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// +// try { +// node = mapper.readTree( +// resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// @Test +// public void exportPostOrganizationNullPointerStorageVerification() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// HashMap<String, Object> payload = payloadBuilder(); +// HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// HashMap<String, Object> storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); +// //remove storage_key field +// storage_info.remove( "s3_key" ); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// try { +// node = resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) +// .post( JsonNode.class, payload ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// +// payload = payloadBuilder(); +// properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); +// //remove storage_key field +// storage_info.remove( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ); +// +// try { +// node = resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) +// .post( JsonNode.class, payload ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// +// payload = payloadBuilder(); +// properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); +// //remove storage_key field +// storage_info.remove( "bucket_location" ); +// +// try { +// node = resource().path( "/management/orgs/" + orgName + "/export" ).queryParam( "access_token", token ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) +// .post( JsonNode.class, payload ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// @Test +// public void exportPostApplicationNullPointerStorageVerification() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// HashMap<String, Object> payload = payloadBuilder(); +// HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// HashMap<String, Object> storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); +// //remove storage_key field +// storage_info.remove( "s3_key" ); +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// +// payload = payloadBuilder(); +// properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); +// //remove storage_key field +// storage_info.remove( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ); +// +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// +// payload = payloadBuilder(); +// properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); +// //remove storage_key field +// storage_info.remove( "bucket_location" ); +// +// try { +// node = mapper.readTree( resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// @Test +// public void exportPostCollectionNullPointerStorageVerification() throws Exception { +// JsonNode node = null; +// ClientResponse.Status responseStatus = ClientResponse.Status.OK; +// +// String orgName = context.getOrgName(); +// String appName = context.getAppName(); +// String token = context.getActiveUser().getToken(); +// +// HashMap<String, Object> payload = payloadBuilder(); +// HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// HashMap<String, Object> storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); +// //remove storage_key field +// storage_info.remove( "s3_key" ); +// +// try { +// node = mapper.readTree( +// resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// +// payload = payloadBuilder(); +// properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); +// //remove storage_key field +// storage_info.remove( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR); +// +// try { +// node = mapper.readTree( +// resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// +// payload = payloadBuilder(); +// properties = ( HashMap<String, Object> ) payload.get( "properties" ); +// storage_info = ( HashMap<String, Object> ) properties.get( "storage_info" ); +// storage_info.remove( "bucket_location" ); +// +// try { +// node = mapper.readTree( +// resource().path( "/management/orgs/" + orgName + "/apps/" + appName + "/collection/users/export" ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// /*Creates fake payload for testing purposes.*/ public HashMap<String, Object> payloadBuilder() { HashMap<String, Object> payload = new HashMap<String, Object>(); http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2ad1c045/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java index 65f6749..207a962 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java @@ -23,6 +23,7 @@ package org.apache.usergrid.rest.test.resource2point0; import java.io.IOException; +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.Credentials; import org.apache.usergrid.rest.test.resource2point0.model.Entity; @@ -48,6 +49,7 @@ public class ClientSetup implements TestRule { protected String password; protected String orgName; protected String appName; + protected String appUuid; protected Token superuserToken; protected String superuserName = "superuser"; protected String superuserPassword = "superpassword"; @@ -112,7 +114,8 @@ public class ClientSetup implements TestRule { //restClient.management().token().post(Token.class,new Token(username,password)); - restClient.management().orgs().organization(organization.getName()).app().post(new Application(appName)); + ApiResponse appResponse = restClient.management().orgs().organization(organization.getName()).app().post(new Application(appName)); + appUuid = ( String ) appResponse.getEntities().get( 0 ).get( "uuid" ); refreshIndex(); } @@ -129,6 +132,10 @@ public class ClientSetup implements TestRule { public String getAppName() {return appName;} + public String getAppUuid() { + return appUuid; + } + public Token getSuperuserToken() { return superuserToken; } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2ad1c045/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java index be480f8..90e2c64 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java @@ -22,6 +22,7 @@ package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt; import javax.ws.rs.core.MediaType; +import org.apache.usergrid.rest.test.resource2point0.endpoints.CollectionEndpoint; import org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource; import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource; import org.apache.usergrid.rest.test.resource2point0.model.Application; @@ -46,9 +47,10 @@ public class ApplicationResource extends NamedResource { } - public void post(Application application) { - getResource(true).type(MediaType.APPLICATION_JSON_TYPE) - .accept(MediaType.APPLICATION_JSON).post(application); + public ApiResponse post(Application application) { + ApiResponse apiResponse =getResource(true).type(MediaType.APPLICATION_JSON_TYPE) + .accept(MediaType.APPLICATION_JSON).post(ApiResponse.class,application); + return apiResponse; } // public Entity post(Entity payload){
