use of org.finra.herd.model.dto.S3FileTransferResultsDto in project herd by FINRAOS.
the class S3DaoTest method testUploadFile.
/**
* Test that we are able to perform the uploadFile S3Dao operation on S3 using our DAO tier.
*/
@Test
public void testUploadFile() 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());
S3FileTransferResultsDto results = s3Dao.uploadFile(s3FileTransferRequestParamsDto);
// Validate results.
Assert.assertTrue(results.getTotalFilesTransferred() == 1L);
// Validate the file upload.
s3DaoTestHelper.validateS3FileUpload(s3FileTransferRequestParamsDto, Arrays.asList(TARGET_S3_KEY));
}
use of org.finra.herd.model.dto.S3FileTransferResultsDto in project herd by FINRAOS.
the class S3DaoTest method testDownloadFile.
/**
* Test that we are able to perform the uploadFile S3Dao operation on S3 using our DAO tier.
*/
@Test
public void testDownloadFile() throws IOException, InterruptedException {
// Upload local file to s3Dao.
testUploadFile();
// Clean up the local directory, so we can test the download.
FileUtils.deleteDirectory(localTempPath.toFile());
// Create local temp directory - this also validates that clean up was really executed.
Assert.assertTrue(localTempPath.toFile().mkdir());
// Destination local file.
File destinationLocalFile = Paths.get(localTempPath.toString(), LOCAL_FILE).toFile();
// Execute download.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3KeyPrefix(TARGET_S3_KEY);
s3FileTransferRequestParamsDto.setLocalPath(destinationLocalFile.getPath());
S3FileTransferResultsDto results = s3Dao.downloadFile(s3FileTransferRequestParamsDto);
// Validate results.
Assert.assertTrue(results.getTotalFilesTransferred() == 1L);
// Validate that we have the file downloaded from S3.
Assert.assertTrue(destinationLocalFile.isFile());
}
use of org.finra.herd.model.dto.S3FileTransferResultsDto in project herd by FINRAOS.
the class S3DaoTest method testUploadDirectory.
/**
* Test that we are able to perform the uploadDirectory S3Dao operation on S3 using our DAO tier.
*/
@Test
public void testUploadDirectory() throws IOException, InterruptedException {
// Create local test files.
for (String file : LOCAL_FILES) {
createLocalFile(localTempPath.toString(), file, FILE_SIZE_1_KB);
}
// 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.setRecursive(true);
S3FileTransferResultsDto results = s3Dao.uploadDirectory(s3FileTransferRequestParamsDto);
// Validate results.
Assert.assertTrue(results.getTotalFilesTransferred() == LOCAL_FILES.size());
// Build a list of expected S3 key values.
List<String> expectedKeys = new ArrayList<>();
for (String file : LOCAL_FILES) {
expectedKeys.add(TEST_S3_KEY_PREFIX + "/" + file.replaceAll("\\\\", "/"));
}
// Validate the file upload.
s3DaoTestHelper.validateS3FileUpload(s3FileTransferRequestParamsDto, expectedKeys);
}
use of org.finra.herd.model.dto.S3FileTransferResultsDto in project herd by FINRAOS.
the class S3DaoTest method testUploadFileZeroBytes.
/**
* Test that we are able to upload a zero byte file to S3 using our DAO tier.
*/
@Test
public void testUploadFileZeroBytes() throws IOException, InterruptedException {
// Create an empty local file.
File targetFile = createLocalFile(localTempPath.toString(), LOCAL_FILE, FILE_SIZE_0_BYTE);
Assert.assertTrue(targetFile.isFile());
Assert.assertTrue(targetFile.length() == FILE_SIZE_0_BYTE);
// Upload test file to s3Dao.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3KeyPrefix(TARGET_S3_KEY);
s3FileTransferRequestParamsDto.setLocalPath(targetFile.getPath());
S3FileTransferResultsDto results = s3Dao.uploadFile(s3FileTransferRequestParamsDto);
// Validate results.
Assert.assertTrue(results.getTotalFilesTransferred() == 1L);
// Validate the file upload.
s3DaoTestHelper.validateS3FileUpload(s3FileTransferRequestParamsDto, Arrays.asList(TARGET_S3_KEY));
}
use of org.finra.herd.model.dto.S3FileTransferResultsDto in project herd by FINRAOS.
the class S3DaoTest method testDownloadDirectory.
/**
* Test that we are able to perform the uploadDirectory S3Dao operation on S3 using our DAO tier.
*/
@Test
public void testDownloadDirectory() throws IOException, InterruptedException {
// Upload local directory to s3Dao.
testUploadDirectory();
// Clean up the local directory, so we can test the download.
FileUtils.deleteDirectory(localTempPath.toFile());
// Create local temp directory - this also validates that clean up was really executed.
Assert.assertTrue(localTempPath.toFile().mkdir());
// Execute download.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3KeyPrefix(TEST_S3_KEY_PREFIX + "/");
s3FileTransferRequestParamsDto.setLocalPath(localTempPath.toString());
s3FileTransferRequestParamsDto.setRecursive(true);
S3FileTransferResultsDto results = s3Dao.downloadDirectory(s3FileTransferRequestParamsDto);
// Validate results.
Assert.assertTrue(results.getTotalFilesTransferred() == LOCAL_FILES.size());
// Validate that we have the directory downloaded from S3.
for (String file : LOCAL_FILES) {
Assert.assertTrue(Paths.get(localTempPath.toString(), TEST_S3_KEY_PREFIX, file).toFile().isFile());
}
}
Aggregations