[USERGRID-348] Added fixes for ExportResourceIT and changed Export endpoint t use the old method of looking for payloads so that it is consistent with imports.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/66fdc612 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/66fdc612 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/66fdc612 Branch: refs/heads/USERGRID-348 Commit: 66fdc61237923809b47d496e3bfbd9db2ca80735 Parents: ee48768 Author: GERey <[email protected]> Authored: Tue Mar 24 15:10:07 2015 -0700 Committer: GERey <[email protected]> Committed: Tue Mar 24 15:10:07 2015 -0700 ---------------------------------------------------------------------- .../organizations/OrganizationResource.java | 26 +- .../applications/ApplicationResource.java | 44 +- .../applications/imports/ImportsResource.java | 4 - .../rest/management/ExportResourceIT.java | 931 ++++++++----------- .../endpoints/NamedResource.java | 12 +- 5 files changed, 438 insertions(+), 579 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66fdc612/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationResource.java index 988af0b..9f32f03 100644 --- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationResource.java +++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationResource.java @@ -20,6 +20,7 @@ package org.apache.usergrid.rest.management.organizations; import com.sun.jersey.api.json.JSONWithPadding; import com.sun.jersey.api.view.Viewable; import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.commons.lang.NullArgumentException; import org.apache.usergrid.corepersistence.util.CpNamingUtils; import org.apache.usergrid.management.ActivationState; @@ -292,40 +293,45 @@ public class OrganizationResource extends AbstractContextResource { try { if((properties = ( Map<String, Object> ) json.get( "properties" )) == null){ - throw new NullPointerException("Could not find 'properties'"); + throw new NullArgumentException("Could not find 'properties'"); } storage_info = ( Map<String, Object> ) properties.get( "storage_info" ); String storage_provider = ( String ) properties.get( "storage_provider" ); if(storage_provider == null) { - throw new NullPointerException( "Could not find field 'storage_provider'" ); + throw new NullArgumentException( "Could not find field 'storage_provider'" ); } if(storage_info == null) { - throw new NullPointerException( "Could not find field 'storage_info'" ); + throw new NullArgumentException( "Could not find field 'storage_info'" ); } - String bucketName = ( String ) storage_info.get( "bucket_location" ); - uac.getAWSAccessKeyIdJson( storage_info ); - uac.getAWSSecretKeyJson( storage_info ); + String accessId = ( String ) storage_info.get( "s3_access_id" ); + String secretKey = ( String ) storage_info.get( "s3_key" ); - if(bucketName == null) { - throw new NullPointerException( "Could not find field 'bucketName'" ); + if ( bucketName == null ) { + throw new NullArgumentException( "Could not find field 'bucketName'" ); + } + if ( accessId == null ) { + throw new NullArgumentException( "Could not find field 's3_access_id'" ); } + if ( secretKey == null ) { + throw new NullArgumentException( "Could not find field 's3_key'" ); + } json.put( "organizationId",organization.getUuid()); jobUUID = exportService.schedule( json ); uuidRet.put( "Export Entity", jobUUID.toString() ); } - catch ( NullPointerException e ) { + catch ( NullArgumentException e ) { return Response.status( SC_BAD_REQUEST ).type( JSONPUtils.jsonMediaType( callback ) ) .entity( ServiceResource.wrapWithCallback( e.getMessage(), callback ) ).build(); } catch ( Exception e ) { //TODO:throw descriptive error message and or include on in the response //TODO:fix below, it doesn't work if there is an exception. Make it look like the OauthResponse. - return Response.status( SC_INTERNAL_SERVER_ERROR ).type( JSONPUtils.jsonMediaType( callback ) ) + return Response.status( SC_INTERNAL_SERVER_ERROR ).type( JSONPUtils.jsonMediaType( callback ) ) .entity( ServiceResource.wrapWithCallback( e.getMessage(), callback ) ).build(); } return Response.status( SC_ACCEPTED ).entity( uuidRet ).build(); http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66fdc612/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java index 639c41b..d7dcd87 100644 --- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java +++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java @@ -24,6 +24,7 @@ import com.google.common.base.Preconditions; import com.sun.jersey.api.json.JSONWithPadding; import org.apache.amber.oauth2.common.exception.OAuthSystemException; import org.apache.amber.oauth2.common.message.OAuthResponse; +import org.apache.commons.lang.NullArgumentException; import org.apache.commons.lang.StringUtils; import org.apache.usergrid.corepersistence.util.CpNamingUtils; @@ -243,25 +244,31 @@ public class ApplicationResource extends AbstractContextResource { try { if((properties = ( Map<String, Object> ) json.get( "properties" )) == null){ - throw new NullPointerException("Could not find 'properties'"); + throw new NullArgumentException("Could not find 'properties'"); } storage_info = ( Map<String, Object> ) properties.get( "storage_info" ); String storage_provider = ( String ) properties.get( "storage_provider" ); if(storage_provider == null) { - throw new NullPointerException( "Could not find field 'storage_provider'" ); + throw new NullArgumentException( "Could not find field 'storage_provider'" ); } if(storage_info == null) { - throw new NullPointerException( "Could not find field 'storage_info'" ); + throw new NullArgumentException( "Could not find field 'storage_info'" ); } String bucketName = ( String ) storage_info.get( "bucket_location" ); + String accessId = ( String ) storage_info.get( "s3_access_id" ); + String secretKey = ( String ) storage_info.get( "s3_key" ); - uac.getAWSAccessKeyIdJson( storage_info ); - uac.getAWSSecretKeyJson( storage_info ); + if ( bucketName == null ) { + throw new NullArgumentException( "Could not find field 'bucketName'" ); + } + if ( accessId == null ) { + throw new NullArgumentException( "Could not find field 's3_access_id'" ); + } + if ( secretKey == null ) { - if(bucketName == null) { - throw new NullPointerException( "Could not find field 'bucketName'" ); + throw new NullArgumentException( "Could not find field 's3_key'" ); } json.put("organizationId", organization.getUuid()); @@ -270,7 +277,7 @@ public class ApplicationResource extends AbstractContextResource { jobUUID = exportService.schedule( json ); uuidRet.put( "Export Entity", jobUUID.toString() ); } - catch ( NullPointerException e ) { + catch ( NullArgumentException e ) { return Response.status( SC_BAD_REQUEST ) .type( JSONPUtils.jsonMediaType( callback ) ) .entity( ServiceResource.wrapWithCallback( e.getMessage(), callback ) ).build(); @@ -307,25 +314,30 @@ public class ApplicationResource extends AbstractContextResource { try { //checkJsonExportProperties(json); if((properties = ( Map<String, Object> ) json.get( "properties" )) == null){ - throw new NullPointerException("Could not find 'properties'"); + throw new NullArgumentException("Could not find 'properties'"); } storage_info = ( Map<String, Object> ) properties.get( "storage_info" ); String storage_provider = ( String ) properties.get( "storage_provider" ); if(storage_provider == null) { - throw new NullPointerException( "Could not find field 'storage_provider'" ); + throw new NullArgumentException( "Could not find field 'storage_provider'" ); } if(storage_info == null) { - throw new NullPointerException( "Could not find field 'storage_info'" ); + throw new NullArgumentException( "Could not find field 'storage_info'" ); } String bucketName = ( String ) storage_info.get( "bucket_location" ); + String accessId = ( String ) storage_info.get( "s3_access_id" ); + String secretKey = ( String ) storage_info.get( "s3_key" ); - //check to make sure that access key and secret key are there. - uac.getAWSAccessKeyIdJson( storage_info ); - uac.getAWSSecretKeyJson( storage_info ); + if ( accessId == null ) { + throw new NullArgumentException( "Could not find field 's3_access_id'" ); + } + if ( secretKey == null ) { + throw new NullArgumentException( "Could not find field 's3_key'" ); + } if(bucketName == null) { - throw new NullPointerException( "Could not find field 'bucketName'" ); + throw new NullArgumentException( "Could not find field 'bucketName'" ); } json.put( "organizationId",organization.getUuid() ); @@ -335,7 +347,7 @@ public class ApplicationResource extends AbstractContextResource { jobUUID = exportService.schedule( json ); uuidRet.put( "Export Entity", jobUUID.toString() ); } - catch ( NullPointerException e ) { + catch ( NullArgumentException e ) { return Response.status( SC_BAD_REQUEST ) .type( JSONPUtils.jsonMediaType( callback ) ) .entity( ServiceResource.wrapWithCallback( e.getMessage(), callback ) ) http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66fdc612/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java index 900b7b0..bb5f958 100644 --- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java +++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java @@ -113,10 +113,6 @@ public class ImportsResource extends AbstractContextResource { Map<String, Object> properties; Map<String, Object> storage_info; - // UsergridAwsCredentialsProvider uacp = new UsergridAwsCredentialsProvider(); - - // try { - //checkJsonExportProperties(json); if ( ( properties = ( Map<String, Object> ) json.get( "properties" ) ) == null ) { http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66fdc612/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 020fce1..0465d69 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 @@ -18,32 +18,24 @@ package org.apache.usergrid.rest.management; -import com.amazonaws.SDKGlobalConfiguration; -import com.fasterxml.jackson.databind.JsonNode; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.UniformInterfaceException; - import java.util.HashMap; import java.util.Map; import java.util.UUID; -import javax.ws.rs.core.MediaType; - - -import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT; +import org.junit.Rule; +import org.junit.Test; import org.apache.usergrid.rest.TestContextSetup; +import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT; import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse; -import static org.apache.usergrid.utils.MapUtils.hashMap; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.UniformInterfaceException; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; - public class ExportResourceIT extends AbstractRestIT { @@ -55,52 +47,6 @@ public class ExportResourceIT extends AbstractRestIT { } -// -// @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 { @@ -113,9 +59,7 @@ public class ExportResourceIT extends AbstractRestIT { } } - - - // + @Test public void exportCollectionUUIDRetTest() throws Exception { @@ -252,10 +196,9 @@ public class ExportResourceIT extends AbstractRestIT { // // //do an unauthorized test for both post and get @Test public void exportGetWrongUUID() throws Exception { - ApiResponse exportEntity = null; UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); try { - exportEntity = management().orgs().organization( clientSetup.getOrganizationName() ) + management().orgs().organization( clientSetup.getOrganizationName() ) .addToPath( "export" ).addToPath( fake.toString() ).get( ApiResponse.class ); fail( "Should not have been able to get fake uuid" ); } @@ -265,486 +208,380 @@ public class ExportResourceIT extends AbstractRestIT { } } -// -// // -// @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 ); -// } -// -// + + // + @Test + public void exportPostApplicationNullPointerProperties() throws Exception { + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, + new HashMap<String, Object>() ); + fail( "Should not have passed, The payload is empty." ); + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + + @Test + public void exportPostOrganizationNullPointerProperties() throws Exception { + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, new HashMap<String, Object>() ); + fail( "Should not have passed, The payload is empty." ); + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + // + @Test + public void exportPostCollectionNullPointer() throws Exception { + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "collection" ).addToPath( "users" ) + .addToPath( "export" ).postWithToken( ApiResponse.class, new HashMap<String, Object>() ); + + fail( "Should not have passed, The payload is empty." ); + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + @Test + public void exportGetCollectionUnauthorized() throws Exception { + UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "collection" ).addToPath( "users" ) + .addToPath( "export" ).addToPath( fake.toString() ).getWithoutToken( ApiResponse.class ); + fail( "Should not have passed as we didn't have an access token." ); + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.UNAUTHORIZED, uie.getResponse().getClientResponseStatus() ); + } + } + + @Test + public void exportGetApplicationUnauthorized() throws Exception { + UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "export" ).addToPath( fake.toString() ).getWithoutToken( ApiResponse.class ); + fail( "Should not have passed as we didn't have an access token." ); + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.UNAUTHORIZED, uie.getResponse().getClientResponseStatus() ); + } + } + + @Test + public void exportGetOrganizationUnauthorized() throws Exception { + UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .addToPath( "export" ).addToPath( fake.toString() ).getWithoutToken( ApiResponse.class ); + fail( "Should not have passed as we didn't have an access token." ); + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.UNAUTHORIZED, uie.getResponse().getClientResponseStatus() ); + } + } + + @Test + public void exportPostOrganizationNullPointerStorageInfo() throws Exception { + HashMap<String, Object> payload = payloadBuilder(); + HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); + //remove storage_info field + properties.remove( "storage_info" ); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + + @Test + public void exportPostApplicationNullPointerStorageInfo() throws Exception { + HashMap<String, Object> payload = payloadBuilder(); + HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); + //remove storage_info field + properties.remove( "storage_info" ); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, + payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + @Test + public void exportPostCollectionNullPointerStorageInfo() throws Exception { + HashMap<String, Object> payload = payloadBuilder(); + HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); + //remove storage_info field + properties.remove( "storage_info" ); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "collection" ).addToPath( "users" ) + .addToPath( "export" ).postWithToken( ApiResponse.class, + payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + @Test + public void exportPostOrganizationNullPointerStorageProvider() throws Exception { + HashMap<String, Object> payload = payloadBuilder(); + HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); + //remove storage_info field + properties.remove( "storage_provider" ); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + + @Test + public void exportPostApplicationNullPointerStorageProvider() throws Exception { + HashMap<String, Object> payload = payloadBuilder(); + HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); + //remove storage_info field + properties.remove( "storage_provider" ); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, + payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + @Test + public void exportPostCollectionNullPointerStorageProvider() throws Exception { + HashMap<String, Object> payload = payloadBuilder(); + HashMap<String, Object> properties = ( HashMap<String, Object> ) payload.get( "properties" ); + //remove storage_info field + properties.remove( "storage_provider" ); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "collection" ).addToPath( "users" ) + .addToPath( "export" ).postWithToken( ApiResponse.class, + payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + + @Test + public void exportPostOrganizationNullPointerStorageVerification() throws Exception { + 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 { + management().orgs().organization( clientSetup.getOrganizationName() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + + 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( "s3_access_id"); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + + 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 { + management().orgs().organization( clientSetup.getOrganizationName() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + @Test + public void exportPostApplicationNullPointerStorageVerification() throws Exception { + 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 { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + + 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( "s3_access_id" ); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + + 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 { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "export" ).postWithToken( ApiResponse.class, payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + @Test + public void exportPostCollectionNullPointerStorageVerification() throws Exception { + 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 { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "collection" ).addToPath( "users" ) + .addToPath( "export" ).postWithToken( ApiResponse.class, payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + + 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( "s3_access_id" ); + + try { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "collection" ).addToPath( "users" ) + .addToPath( "export" ).postWithToken( ApiResponse.class, payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + + 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 { + management().orgs().organization( clientSetup.getOrganizationName() ) + .app().addToPath( clientSetup.getAppUuid() ) + .addToPath( "collection" ).addToPath( "users" ) + .addToPath( "export" ).postWithToken( ApiResponse.class, payload ); + fail( "Should not have passed as we were missing an important part of the payload" ); + + } + catch ( UniformInterfaceException uie ) { + assertEquals( ClientResponse.Status.BAD_REQUEST, uie.getResponse().getClientResponseStatus() ); + } + } + + /*Creates fake payload for testing purposes.*/ public HashMap<String, Object> payloadBuilder() { HashMap<String, Object> payload = new HashMap<String, Object>(); @@ -752,8 +589,8 @@ public class ExportResourceIT extends AbstractRestIT { Map<String, Object> storage_info = new HashMap<String, Object>(); //TODO: always put dummy values here and ignore this test. //TODO: add a ret for when s3 values are invalid. - storage_info.put( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, "insert key here" ); - storage_info.put( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, "insert access id here" ); + storage_info.put( "s3_key", "insert key here" ); + storage_info.put( "s3_access_id", "insert access id here" ); storage_info.put( "bucket_location", "insert bucket name here" ); properties.put( "storage_provider", "s3" ); properties.put( "storage_info", storage_info ); http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66fdc612/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/NamedResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/NamedResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/NamedResource.java index daf3502..fe9d73e 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/NamedResource.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/NamedResource.java @@ -193,8 +193,16 @@ public abstract class NamedResource implements UrlResource { public <T> T get(Class<T> type) { GenericType<T> gt = new GenericType<>((Class) type); return getResource( true ).type(MediaType.APPLICATION_JSON_TYPE) - .accept( MediaType.APPLICATION_JSON ) - .get( gt.getRawClass() ); + .accept( MediaType.APPLICATION_JSON ) + .get( gt.getRawClass() ); + + } + + public <T> T getWithoutToken(Class<T> type) { + GenericType<T> gt = new GenericType<>((Class) type); + return getResource().type(MediaType.APPLICATION_JSON_TYPE) + .accept( MediaType.APPLICATION_JSON ) + .get( gt.getRawClass() ); }
