use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testS3FileExistsKeyNoExists.
@Test
public void testS3FileExistsKeyNoExists() {
S3FileTransferRequestParamsDto params = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto();
params.setS3BucketName(S3_BUCKET_NAME);
params.setS3KeyPrefix(TARGET_S3_KEY);
Assert.assertFalse(s3Dao.s3FileExists(params));
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testValidateS3File.
@Test
public void testValidateS3File() throws IOException, InterruptedException {
// Put a 1 KB file in S3.
PutObjectRequest putObjectRequest = new PutObjectRequest(storageDaoTestHelper.getS3ManagedBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[(int) FILE_SIZE_1_KB]), null);
s3Operations.putObject(putObjectRequest, null);
// Validate the S3 file.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3KeyPrefix(TARGET_S3_KEY);
s3Dao.validateS3File(s3FileTransferRequestParamsDto, FILE_SIZE_1_KB);
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method cleanEnv.
/**
* Cleans up the local temp directory and S3 test path that we are using.
*/
@After
public void cleanEnv() throws IOException {
// Clean up the local directory.
FileUtils.deleteDirectory(localTempPath.toFile());
// Delete test files from S3 storage. Since test S3 key prefix represents a directory, we add a trailing '/' character to it.
for (S3FileTransferRequestParamsDto params : Arrays.asList(s3DaoTestHelper.getTestS3FileTransferRequestParamsDto(), S3FileTransferRequestParamsDto.builder().withS3BucketName(storageDaoTestHelper.getS3LoadingDockBucketName()).withS3KeyPrefix(TEST_S3_KEY_PREFIX + "/").build(), S3FileTransferRequestParamsDto.builder().withS3BucketName(storageDaoTestHelper.getS3ExternalBucketName()).withS3KeyPrefix(TEST_S3_KEY_PREFIX + "/").build())) {
if (!s3Dao.listDirectory(params).isEmpty()) {
s3Dao.deleteDirectory(params);
}
}
s3Operations.rollback();
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testValidateS3FileRuntimeExceptionFileSizeDoesNotMatch.
@Test(expected = IllegalArgumentException.class)
public void testValidateS3FileRuntimeExceptionFileSizeDoesNotMatch() throws IOException, InterruptedException {
// Put a 1 KB file in S3.
PutObjectRequest putObjectRequest = new PutObjectRequest(storageDaoTestHelper.getS3ManagedBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[(int) FILE_SIZE_1_KB]), null);
s3Operations.putObject(putObjectRequest, null);
// Try to validate an S3 file by specifying an incorrect file size.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3KeyPrefix(TARGET_S3_KEY);
s3Dao.validateS3File(s3FileTransferRequestParamsDto, FILE_SIZE_1_KB + 999);
}
use of org.finra.herd.model.dto.S3FileTransferRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testValidateS3FileSkipSizeValidationWhenSizeIsNull.
@Test
public void testValidateS3FileSkipSizeValidationWhenSizeIsNull() throws IOException, InterruptedException {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
try {
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
when(mockS3Operations.getObjectMetadata(any(), any(), any())).thenReturn(new ObjectMetadata());
s3Dao.validateS3File(s3FileTransferRequestParamsDto, null);
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
}
}
Aggregations