@Test(expected = ObjectNotFoundException.class) public void testValidateS3FileObjectNotFoundException() throws IOException, InterruptedException { // Try to validate a non-existing S3 file. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3KeyPrefix(TARGET_S3_KEY); s3Dao.validateS3File(s3FileTransferRequestParamsDto, FILE_SIZE_1_KB); }
@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); } }
@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); }
@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); }
verify(storageUnitDaoHelper).getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity); verify(awsHelper, times(2)).getAwsParamsDto(); verify(s3Dao).validateS3File(any(S3FileTransferRequestParamsDto.class), eq(FILE_SIZE)); verify(storageHelper).getStorageBucketName(targetStorageEntity); verify(storageHelper).getStorageKmsKeyId(targetStorageEntity);
verify(storageUnitDaoHelper).getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity); verify(awsHelper, times(2)).getAwsParamsDto(); verify(s3Dao).validateS3File(any(S3FileTransferRequestParamsDto.class), eq(FILE_SIZE)); verify(storageHelper).getStorageBucketName(targetStorageEntity); verify(storageHelper).getStorageKmsKeyId(targetStorageEntity);
.withS3KeyPrefix(completeUploadSingleParamsDto.getSourceFilePath()).withHttpProxyHost(awsParamsDto.getHttpProxyHost()) .withHttpProxyPort(awsParamsDto.getHttpProxyPort()).build(); s3Dao.validateS3File(s3FileTransferRequestParamsDto, sourceStorageFileEntity.getFileSizeBytes());
.withS3KeyPrefix(completeUploadSingleParamsDto.getSourceFilePath()).withHttpProxyHost(awsParamsDto.getHttpProxyHost()) .withHttpProxyPort(awsParamsDto.getHttpProxyPort()).build(); s3Dao.validateS3File(s3FileTransferRequestParamsDto, sourceStorageFileEntity.getFileSizeBytes());