use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testTagObjects.
@Test
public void testTagObjects() {
// Create an S3 object tag.
Tag tag = new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE);
// Put a file in S3.
s3Operations.putObject(new PutObjectRequest(S3_BUCKET_NAME, TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), new ObjectMetadata()), null);
// Tag the file with an S3 object tag.
S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto();
params.setS3BucketName(S3_BUCKET_NAME);
params.setFiles(Arrays.asList(new File(TARGET_S3_KEY)));
s3Dao.tagObjects(params, new S3FileTransferRequestParamsDto(), tag);
// Validate that the object got tagged.
GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null);
assertEquals(Arrays.asList(tag), getObjectTaggingResult.getTagSet());
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testDeleteDirectory.
/**
* Test that we are able to perform the deleteDirectory S3Dao operation on S3 using our DAO tier.
*/
@Test
public void testDeleteDirectory() 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 + "/");
Assert.assertTrue(s3Dao.listDirectory(s3FileTransferRequestParamsDto).size() > 0);
// Delete directory from S3 using s3Dao.
s3Dao.deleteDirectory(s3FileTransferRequestParamsDto);
// Validate that S3 directory got deleted.
Assert.assertEquals(0, s3Dao.listDirectory(s3FileTransferRequestParamsDto).size());
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testUploadFileUseRrs.
/**
* Test that we are able to perform the uploadFile S3Dao operation utilizing Reduced Redundancy Storage (RRS) storage option.
*/
@Test
public void testUploadFileUseRrs() throws IOException, InterruptedException {
// Create local test file.
File targetFile = createLocalFile(localTempPath.toString(), LOCAL_FILE, FILE_SIZE_1_KB);
Assert.assertTrue(targetFile.isFile());
Assert.assertTrue(targetFile.length() == FILE_SIZE_1_KB);
// Upload test file to s3Dao.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3KeyPrefix(TARGET_S3_KEY);
s3FileTransferRequestParamsDto.setLocalPath(targetFile.getPath());
s3FileTransferRequestParamsDto.setUseRrs(true);
S3FileTransferResultsDto results = s3Dao.uploadFile(s3FileTransferRequestParamsDto);
// Validate results.
Assert.assertTrue(results.getTotalFilesTransferred() == 1L);
// Validate the file upload.
s3DaoTestHelper.validateS3FileUpload(s3FileTransferRequestParamsDto, Arrays.asList(TARGET_S3_KEY));
// TODO: Validate Reduced Redundancy Storage (RRS) storage option.
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method runUploadFileListTest.
private void runUploadFileListTest() throws IOException, InterruptedException {
// Create local test files.
for (String file : LOCAL_FILES) {
createLocalFile(localTempPath.toString(), file, FILE_SIZE_1_KB);
}
// Create a list of files to be uploaded along with the list of expected S3 key values.
List<File> requestFileList = new ArrayList<>();
List<String> expectedKeys = new ArrayList<>();
for (String file : LOCAL_FILES_SUBSET) {
requestFileList.add(Paths.get(localTempPath.toString(), file).toFile());
expectedKeys.add(TEST_S3_KEY_PREFIX + "/" + file.replaceAll("\\\\", "/"));
}
// Upload test file to s3Dao.
// Since the S3 key prefix represents a directory, we add a trailing '/' character to it.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3KeyPrefix(TEST_S3_KEY_PREFIX + "/");
s3FileTransferRequestParamsDto.setLocalPath(localTempPath.toString());
s3FileTransferRequestParamsDto.setFiles(requestFileList);
S3FileTransferResultsDto results = s3Dao.uploadFileList(s3FileTransferRequestParamsDto);
// Validate results.
Assert.assertTrue(results.getTotalFilesTransferred() == LOCAL_FILES_SUBSET.size());
// Validate the upload.
s3DaoTestHelper.validateS3FileUpload(s3FileTransferRequestParamsDto, expectedKeys);
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testGetObjectMetadataS3BucketNoExists.
/**
* Test "bucket not found" scenario for the getObjectMetadata S3Dao operation.
*/
@Test
public void testGetObjectMetadataS3BucketNoExists() {
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto();
// Try to retrieve S3 object metadata when S3 bucket does not exist.
s3FileTransferRequestParamsDto.setS3BucketName(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION);
s3FileTransferRequestParamsDto.setS3KeyPrefix(TARGET_S3_KEY);
assertNull(s3Dao.getObjectMetadata(s3FileTransferRequestParamsDto));
}
Aggregations