use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testGetAWSCredentialsProviderAssertStaticCredentialsSet.
@Test
public void testGetAWSCredentialsProviderAssertStaticCredentialsSet() {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
try {
String s3BucketName = "s3BucketName";
String s3KeyPrefix = "s3KeyPrefix";
String s3AccessKey = "s3AccessKey";
String s3SecretKey = "s3SecretKey";
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName);
s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix);
s3FileTransferRequestParamsDto.setAwsAccessKeyId(s3AccessKey);
s3FileTransferRequestParamsDto.setAwsSecretKey(s3SecretKey);
when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() {
@SuppressWarnings("unchecked")
@Override
public PutObjectResult answer(InvocationOnMock invocation) throws Throwable {
AmazonS3Client amazonS3Client = invocation.getArgument(1);
AWSCredentialsProviderChain awsCredentialsProviderChain = (AWSCredentialsProviderChain) ReflectionTestUtils.getField(amazonS3Client, "awsCredentialsProvider");
List<AWSCredentialsProvider> credentialsProviders = (List<AWSCredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProviderChain, "credentialsProviders");
// Expect 2 providers: the static provider, and the default provider
assertEquals(2, credentialsProviders.size());
// Only verify the static value
assertEquals(StaticCredentialsProvider.class, credentialsProviders.get(0).getClass());
StaticCredentialsProvider staticCredentialsProvider = (StaticCredentialsProvider) credentialsProviders.get(0);
assertEquals(s3AccessKey, staticCredentialsProvider.getCredentials().getAWSAccessKeyId());
assertEquals(s3SecretKey, staticCredentialsProvider.getCredentials().getAWSSecretKey());
return new PutObjectResult();
}
});
s3Dao.createDirectory(s3FileTransferRequestParamsDto);
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
}
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testS3FileExistsGenericAmazonError.
/**
* Throws the exception as-is without wrapping if the exception is of type AmazonServiceException or children.
*/
@Test
public void testS3FileExistsGenericAmazonError() {
try {
S3FileTransferRequestParamsDto params = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto();
params.setS3BucketName(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_INTERNAL_ERROR);
params.setS3KeyPrefix(TARGET_S3_KEY);
s3Dao.s3FileExists(params);
Assert.fail("expected AmazonServiceException to be thrown, but no exceptions were thrown");
} catch (Exception e) {
Assert.assertEquals("thrown exception type", AmazonServiceException.class, e.getClass());
}
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testGetAmazonS3AssertV4SigningAlwaysPresent.
@Test
public void testGetAmazonS3AssertV4SigningAlwaysPresent() {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
try {
String s3BucketName = "s3BucketName";
String s3KeyPrefix = "s3KeyPrefix";
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName);
s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix);
when(mockS3Operations.putObject(any(), any())).then(invocation -> {
AmazonS3Client amazonS3Client = invocation.getArgument(1);
ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonS3Client, "clientConfiguration");
assertEquals(S3Dao.SIGNER_OVERRIDE_V4, clientConfiguration.getSignerOverride());
return new PutObjectResult();
});
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
}
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testDeleteFileList.
/**
* Test that we are able to perform the deleteFileList S3Dao operation on S3 using our DAO tier.
*/
@Test
public void testDeleteFileList() throws IOException, InterruptedException {
// Upload local directory to s3Dao.
testUploadDirectory();
// Validate that S3 directory is not empty.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3KeyPrefix(TEST_S3_KEY_PREFIX + "/");
List<S3ObjectSummary> s3ObjectSummaries = s3Dao.listDirectory(s3FileTransferRequestParamsDto);
Assert.assertTrue(s3ObjectSummaries.size() > 0);
// Delete a list of files from S3 using s3Dao.
List<File> requestFileList = new ArrayList<>();
for (S3ObjectSummary s3ObjectSummary : s3ObjectSummaries) {
requestFileList.add(new File(s3ObjectSummary.getKey()));
}
s3FileTransferRequestParamsDto.setFiles(requestFileList);
s3FileTransferRequestParamsDto.setS3KeyPrefix(null);
s3Dao.deleteFileList(s3FileTransferRequestParamsDto);
// Validate that S3 directory got deleted.
s3FileTransferRequestParamsDto.setS3KeyPrefix(TEST_S3_KEY_PREFIX + "/");
Assert.assertEquals(0, s3Dao.listDirectory(s3FileTransferRequestParamsDto).size());
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testRestoreObjects.
@Test
public void testRestoreObjects() {
// Put a 1 byte Glacier storage class file in S3.
ObjectMetadata metadata = new ObjectMetadata();
metadata.setHeader(Headers.STORAGE_CLASS, StorageClass.Glacier);
metadata.setOngoingRestore(false);
s3Operations.putObject(new PutObjectRequest(storageDaoTestHelper.getS3ManagedBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), metadata), null);
// Initiate a restore request for the test S3 file.
S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto();
params.setS3BucketName(storageDaoTestHelper.getS3ManagedBucketName());
params.setFiles(Arrays.asList(new File(TARGET_S3_KEY)));
s3Dao.restoreObjects(params, S3_RESTORE_OBJECT_EXPIRATION_IN_DAYS);
// Validate that there is an ongoing restore request for this object.
ObjectMetadata objectMetadata = s3Operations.getObjectMetadata(storageDaoTestHelper.getS3ManagedBucketName(), TARGET_S3_KEY, null);
assertTrue(objectMetadata.getOngoingRestore());
}
Aggregations