@Override public void deleteDirectory(S3FileTransferRequestParamsDto params) { s3Dao.deleteDirectory(params); }
@Override public void deleteDirectory(S3FileTransferRequestParamsDto params) { s3Dao.deleteDirectory(params); }
@Override public void deleteDirectoryIgnoreException(S3FileTransferRequestParamsDto params) { try { s3Dao.deleteDirectory(params); } catch (Exception e) { LOGGER.warn(e.getMessage(), e); } }
@Override public void deleteDirectoryIgnoreException(S3FileTransferRequestParamsDto params) { try { s3Dao.deleteDirectory(params); } catch (Exception e) { LOGGER.warn(e.getMessage(), e); } }
@Test public void testDeleteDirectoryIgnoreExceptionWhenRuntimeExceptionOccurs() { // Create an S3 file transfer request parameters DTO. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); // Mock the external calls. doThrow(new RuntimeException()).when(s3Dao).deleteDirectory(s3FileTransferRequestParamsDto); // Call the method under test. s3Service.deleteDirectoryIgnoreException(s3FileTransferRequestParamsDto); // Verify the external calls. verify(s3Dao).deleteDirectory(s3FileTransferRequestParamsDto); verifyNoMoreInteractions(s3Dao); }
@Test public void testDeleteDirectoryIgnoreException() { // Create an S3 file transfer request parameters DTO. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); // Call the method under test. s3Service.deleteDirectoryIgnoreException(s3FileTransferRequestParamsDto); // Verify the external calls. verify(s3Dao).deleteDirectory(s3FileTransferRequestParamsDto); verifyNoMoreInteractions(s3Dao); }
@Test public void testDeleteDirectory() { // Create an S3 file transfer request parameters DTO. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); // Call the method under test. s3Service.deleteDirectory(s3FileTransferRequestParamsDto); // Verify the external calls. verify(s3Dao).deleteDirectory(s3FileTransferRequestParamsDto); verifyNoMoreInteractions(s3Dao); }
/** * 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()); // Clean up the destination S3 folder. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3KeyPrefix(testS3KeyPrefix); s3Dao.deleteDirectory(s3FileTransferRequestParamsDto); }
/** * 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()); // Clean up the destination S3 folders. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto(); for (String keyPrefix : Arrays.asList(testS3KeyPrefix, TEST_S3_KEY_PREFIX)) { // Since the key prefix represents a directory, we add a trailing '/' character to it. s3FileTransferRequestParamsDto.setS3KeyPrefix(keyPrefix + "/"); s3Dao.deleteDirectory(s3FileTransferRequestParamsDto); } }
/** * Cleans up the local temp directory and S3 test path that we are using. */ @After public void cleanEnv() throws IOException { try { // Clean up the local directory. FileUtils.deleteDirectory(localTempPath.toFile()); // Clean up the destination S3 folder. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3KeyPrefix(testS3KeyPrefix); s3Dao.deleteDirectory(s3FileTransferRequestParamsDto); } catch (Exception ex) { // If an exception is thrown by one of the @Test methods, some cleanup operations could also fail. This is why we are just logging a warning here. LOGGER.warn("Unable to cleanup environment.", ex); } }
@Test public void testDeleteDirectoryNullParamsDto() { // Try to delete an S3 directory when transfer request parameters DTO is null. try { s3Dao.deleteDirectory(null); fail("Suppose to throw a NullPointerException."); } catch (NullPointerException e) { assertNull(e.getMessage()); } }
/** * Cleans up the S3 test path that we are using. */ @After public void cleanEnv() throws IOException { // Clean up the destination S3 folder. s3Dao.deleteDirectory(s3DaoTestHelper.getTestS3FileTransferRequestParamsDto()); s3Operations.rollback(); }
/** * Deletes a source S3 object based on the given bucket name and file path. * * @param s3BucketName the S3 bucket name * @param storageFilePath the storage file path * @param businessObjectDataKey the business object key */ private void deleteSourceS3ObjectAfterError(String s3BucketName, String storageFilePath, BusinessObjectDataKey businessObjectDataKey) { // Delete the file from S3 if storage file information exists. if (!StringUtils.isEmpty(storageFilePath)) { try { // Delete the source file from S3. AwsParamsDto awsParams = awsHelper.getAwsParamsDto(); S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = S3FileTransferRequestParamsDto.builder().withS3BucketName(s3BucketName).withS3KeyPrefix(storageFilePath) .withHttpProxyHost(awsParams.getHttpProxyHost()).withHttpProxyPort(awsParams.getHttpProxyPort()).build(); s3Dao.deleteDirectory(s3FileTransferRequestParamsDto); } catch (Exception e) { LOGGER.error("Failed to delete source business object data file. s3Key=\"{}\" sourceS3BucketName=\"{}\" sourceBusinessObjectDataKey={}", storageFilePath, s3BucketName, jsonHelper.objectToJson(businessObjectDataKey), e); } } }
/** * Deletes a source S3 object based on the given bucket name and file path. * * @param s3BucketName the S3 bucket name * @param storageFilePath the storage file path * @param businessObjectDataKey the business object key */ private void deleteSourceS3ObjectAfterError(String s3BucketName, String storageFilePath, BusinessObjectDataKey businessObjectDataKey) { // Delete the file from S3 if storage file information exists. if (!StringUtils.isEmpty(storageFilePath)) { try { // Delete the source file from S3. AwsParamsDto awsParams = awsHelper.getAwsParamsDto(); S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = S3FileTransferRequestParamsDto.builder().withS3BucketName(s3BucketName).withS3KeyPrefix(storageFilePath) .withHttpProxyHost(awsParams.getHttpProxyHost()).withHttpProxyPort(awsParams.getHttpProxyPort()).build(); s3Dao.deleteDirectory(s3FileTransferRequestParamsDto); } catch (Exception e) { LOGGER.error("Failed to delete source business object data file. s3Key=\"{}\" sourceS3BucketName=\"{}\" sourceBusinessObjectDataKey={}", storageFilePath, s3BucketName, jsonHelper.objectToJson(businessObjectDataKey), e); } } }
@Test public void testDeleteDirectoryRootKeyPrefix() { for (String s3KeyPrefix : Arrays.asList(null, BLANK_TEXT, "/")) { try { s3Dao.deleteDirectory(S3FileTransferRequestParamsDto.builder().withS3KeyPrefix(s3KeyPrefix).build()); fail("Should throw an IllegalArgumentException when S3 key prefix specifies a root directory."); } catch (IllegalArgumentException e) { assertEquals("Deleting from root directory is not allowed.", e.getMessage()); } } }
/** * 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()); }
/** * 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(); }
/** * Delete the source file from S3 * * @param completeUploadSingleParamsDto the DTO that contains complete upload single message parameters */ protected void deleteSourceFileFromS3Impl(CompleteUploadSingleParamsDto completeUploadSingleParamsDto) { try { // Delete the source file from S3. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = S3FileTransferRequestParamsDto.builder().withS3BucketName(completeUploadSingleParamsDto.getSourceBucketName()) .withS3KeyPrefix(completeUploadSingleParamsDto.getSourceFilePath()) .withHttpProxyHost(completeUploadSingleParamsDto.getAwsParams().getHttpProxyHost()) .withHttpProxyPort(completeUploadSingleParamsDto.getAwsParams().getHttpProxyPort()).build(); s3Dao.deleteDirectory(s3FileTransferRequestParamsDto); } catch (Exception e) { // Log the error if failed to delete the file from source S3 bucket. LOGGER.error("Failed to delete the upload single file. s3Key=\"{}\" sourceS3BucketName=\"{}\" sourceBusinessObjectDataKey={}", completeUploadSingleParamsDto.getSourceFilePath(), completeUploadSingleParamsDto.getSourceBucketName(), jsonHelper.objectToJson(completeUploadSingleParamsDto.getSourceBusinessObjectDataKey()), e); } }
/** * Delete the source file from S3 * * @param completeUploadSingleParamsDto the DTO that contains complete upload single message parameters */ protected void deleteSourceFileFromS3Impl(CompleteUploadSingleParamsDto completeUploadSingleParamsDto) { try { // Delete the source file from S3. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = S3FileTransferRequestParamsDto.builder().withS3BucketName(completeUploadSingleParamsDto.getSourceBucketName()) .withS3KeyPrefix(completeUploadSingleParamsDto.getSourceFilePath()) .withHttpProxyHost(completeUploadSingleParamsDto.getAwsParams().getHttpProxyHost()) .withHttpProxyPort(completeUploadSingleParamsDto.getAwsParams().getHttpProxyPort()).build(); s3Dao.deleteDirectory(s3FileTransferRequestParamsDto); } catch (Exception e) { // Log the error if failed to delete the file from source S3 bucket. LOGGER.error("Failed to delete the upload single file. s3Key=\"{}\" sourceS3BucketName=\"{}\" sourceBusinessObjectDataKey={}", completeUploadSingleParamsDto.getSourceFilePath(), completeUploadSingleParamsDto.getSourceBucketName(), jsonHelper.objectToJson(completeUploadSingleParamsDto.getSourceBusinessObjectDataKey()), e); } }
/** * Cleans up the S3 test path that we are using. */ @After public void cleanEnv() throws IOException { // Clean up the source and target S3 folders. Since test S3 key prefix represents a directory, we add a trailing '/' character to it. for (S3FileTransferRequestParamsDto params : Arrays.asList( 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(); }