@Test public void getObjectStorageMetadataThrows() { AmazonS3Exception exception = new AmazonS3Exception(ERROR_MESSAGE); thrown.expect(CloudConnectorException.class); thrown.expectMessage(String.format("Cannot get object storage location for %s. Provider error message: %s", BUCKET_NAME, ERROR_MESSAGE)); when(s3Client.getBucketLocation(BUCKET_NAME)).thenThrow(exception); ObjectStorageMetadataRequest request = ObjectStorageMetadataRequest.builder().withObjectStoragePath(BUCKET_NAME).build(); underTest.getObjectStorageMetadata(request); }
@Override public ObjectStorageMetadataResponse getObjectStorageMetadata(ObjectStorageMetadataRequest request) { AwsCredentialView awsCredentialView = new AwsCredentialView(request.getCredential()); try { AmazonS3 s3Client = awsClient.createS3Client(awsCredentialView); String bucketLocation = fixBucketLocation(s3Client.getBucketLocation(request.getObjectStoragePath())); return ObjectStorageMetadataResponse.builder() .withRegion(bucketLocation) .withStatus(ResponseStatus.OK) .build(); } catch (AmazonS3Exception e) { if (e.getStatusCode() != ACCESS_DENIED_ERROR_CODE) { throw new CloudConnectorException(String.format("Cannot get object storage location for %s. " + "Provider error message: %s", request.getObjectStoragePath(), e.getErrorMessage()), e); } return ObjectStorageMetadataResponse.builder() .withStatus(ResponseStatus.ACCESS_DENIED) .build(); } }
AwsObjectStorageConnector implements ObjectStorageConnector { @Override public ObjectStorageMetadataResponse getObjectStorageMetadata(ObjectStorageMetadataRequest request) { AwsCredentialView awsCredentialView = new AwsCredentialView(request.getCredential()); try { AmazonS3 s3Client = awsClient.createS3Client(awsCredentialView); String bucketLocation = fixBucketLocation(s3Client.getBucketLocation(request.getObjectStoragePath())); return ObjectStorageMetadataResponse.builder() .withRegion(bucketLocation) .withStatus(ResponseStatus.OK) .build(); } catch (AmazonS3Exception e) { if (e.getStatusCode() != ACCESS_DENIED_ERROR_CODE) { throw new CloudConnectorException(String.format("Cannot get object storage location for %s. " + "Provider error message: %s", request.getObjectStoragePath(), e.getErrorMessage()), e); } return ObjectStorageMetadataResponse.builder() .withStatus(ResponseStatus.ACCESS_DENIED) .build(); } } }
AwsObjectStorageConnector implements ObjectStorageConnector { @Override public ObjectStorageMetadataResponse getObjectStorageMetadata(ObjectStorageMetadataRequest request) { AwsCredentialView awsCredentialView = new AwsCredentialView(request.getCredential()); try { AmazonS3 s3Client = awsClient.createS3Client(awsCredentialView); String bucketLocation = fixBucketLocation(s3Client.getBucketLocation(request.getObjectStoragePath())); return ObjectStorageMetadataResponse.builder() .withRegion(bucketLocation) .withStatus(ResponseStatus.OK) .build(); } catch (AmazonS3Exception e) { if (e.getStatusCode() != ACCESS_DENIED_ERROR_CODE) { throw new CloudConnectorException(String.format("Cannot get object storage location for %s. " + "Provider error message: %s", request.getObjectStoragePath(), e.getErrorMessage()), e); } return ObjectStorageMetadataResponse.builder() .withStatus(ResponseStatus.ACCESS_DENIED) .build(); } }  }
AwsObjectStorageConnector implements ObjectStorageConnector { @Override public ObjectStorageMetadataResponse getObjectStorageMetadata(ObjectStorageMetadataRequest request) { AwsCredentialView awsCredentialView = new AwsCredentialView(request.getCredential()); try { AmazonS3 s3Client = awsClient.createS3Client(awsCredentialView); String bucketLocation = fixBucketLocation(s3Client.getBucketLocation(request.getObjectStoragePath())); return ObjectStorageMetadataResponse.builder() .withRegion(bucketLocation) .withStatus(ResponseStatus.OK) .build(); } catch (AmazonS3Exception e) { if (e.getStatusCode() != ACCESS_DENIED_ERROR_CODE) { throw new CloudConnectorException(String.format("Cannot get object storage location for %s. " + "Provider error message: %s", request.getObjectStoragePath(), e.getErrorMessage()), e); } return ObjectStorageMetadataResponse.builder() .withStatus(ResponseStatus.ACCESS_DENIED) .build(); } }  @Override ObjectStorageMetadataResponse getObjectStorageMetadata(ObjectStorageMetadataRequest request); @Override ObjectStorageValidateResponse validateObjectStorage(ObjectStorageValidateRequest request); @Override Platform platform(); @Override Variant variant(); }
AwsObjectStorageConnector implements ObjectStorageConnector { @Override public ObjectStorageMetadataResponse getObjectStorageMetadata(ObjectStorageMetadataRequest request) { AwsCredentialView awsCredentialView = new AwsCredentialView(request.getCredential()); try { AmazonS3 s3Client = awsClient.createS3Client(awsCredentialView); String bucketLocation = fixBucketLocation(s3Client.getBucketLocation(request.getObjectStoragePath())); return ObjectStorageMetadataResponse.builder() .withRegion(bucketLocation) .withStatus(ResponseStatus.OK) .build(); } catch (AmazonS3Exception e) { if (e.getStatusCode() != ACCESS_DENIED_ERROR_CODE) { throw new CloudConnectorException(String.format("Cannot get object storage location for %s. " + "Provider error message: %s", request.getObjectStoragePath(), e.getErrorMessage()), e); } return ObjectStorageMetadataResponse.builder() .withStatus(ResponseStatus.ACCESS_DENIED) .build(); } }  @Override ObjectStorageMetadataResponse getObjectStorageMetadata(ObjectStorageMetadataRequest request); @Override ObjectStorageValidateResponse validateObjectStorage(ObjectStorageValidateRequest request); @Override Platform platform(); @Override Variant variant();  }