Search in sources :

Example 1 with S3FileTransferResultsDto

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));
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) File(java.io.File) S3FileTransferResultsDto(org.finra.herd.model.dto.S3FileTransferResultsDto) Test(org.junit.Test)

Example 2 with S3FileTransferResultsDto

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());
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) File(java.io.File) S3FileTransferResultsDto(org.finra.herd.model.dto.S3FileTransferResultsDto) Test(org.junit.Test)

Example 3 with S3FileTransferResultsDto

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);
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) ArrayList(java.util.ArrayList) S3FileTransferResultsDto(org.finra.herd.model.dto.S3FileTransferResultsDto) Test(org.junit.Test)

Example 4 with S3FileTransferResultsDto

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));
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) File(java.io.File) S3FileTransferResultsDto(org.finra.herd.model.dto.S3FileTransferResultsDto) Test(org.junit.Test)

Example 5 with S3FileTransferResultsDto

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());
    }
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) S3FileTransferResultsDto(org.finra.herd.model.dto.S3FileTransferResultsDto) Test(org.junit.Test)

Aggregations

S3FileTransferResultsDto (org.finra.herd.model.dto.S3FileTransferResultsDto)31 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)21 Test (org.junit.Test)21 File (java.io.File)16 Transfer (com.amazonaws.services.s3.transfer.Transfer)7 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)7 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)4 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)3 S3KeyPrefixInformation (org.finra.herd.model.api.xml.S3KeyPrefixInformation)3 Storage (org.finra.herd.model.api.xml.Storage)3 StorageUnit (org.finra.herd.model.api.xml.StorageUnit)3 DownloaderInputManifestDto (org.finra.herd.model.dto.DownloaderInputManifestDto)3 RegServerAccessParamsDto (org.finra.herd.model.dto.RegServerAccessParamsDto)3 S3FileCopyRequestParamsDto (org.finra.herd.model.dto.S3FileCopyRequestParamsDto)3 S3Service (org.finra.herd.service.S3Service)3 BusinessObjectDataHelper (org.finra.herd.service.helper.BusinessObjectDataHelper)3 StorageFileHelper (org.finra.herd.service.helper.StorageFileHelper)3