BusinessObjectDataInitiateRestoreHelperServiceImpl implements BusinessObjectDataInitiateRestoreHelperService { @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) public void executeS3SpecificSteps(BusinessObjectDataRestoreDto businessObjectDataRestoreDto) { executeS3SpecificStepsImpl(businessObjectDataRestoreDto); }  @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectData executeInitiateRestoreAfterStep(BusinessObjectDataRestoreDto businessObjectDataRestoreDto); @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) void executeS3SpecificSteps(BusinessObjectDataRestoreDto businessObjectDataRestoreDto); @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectDataRestoreDto prepareToInitiateRestore(BusinessObjectDataKey businessObjectDataKey, Integer expirationInDays,
        String archiveRetrievalOption);  }
@Test public void testExecuteS3SpecificSteps() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); List<StorageFile> storageFiles = Collections.singletonList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT)); BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFiles, NO_EXCEPTION, ARCHIVE_RETRIEVAL_OPTION); S3FileTransferRequestParamsDto initialS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); S3FileTransferRequestParamsDto updatedS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); updatedS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME); updatedS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT); updatedS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/"); S3ObjectSummary glacierS3ObjectSummary = mock(S3ObjectSummary.class); when(glacierS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Glacier.toString()); List<S3ObjectSummary> actualS3Files = Collections.singletonList(glacierS3ObjectSummary); List<StorageFile> storageFilesCreatedFromActualS3Files = Collections.singletonList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT)); List<File> filesToBeRestored = Collections.singletonList(new File(S3_KEY)); S3FileTransferRequestParamsDto finalS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); finalS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME); finalS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT); finalS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/"); finalS3FileTransferRequestParamsDto.setFiles(filesToBeRestored); when(storageHelper.getS3FileTransferRequestParamsDto()).thenReturn(initialS3FileTransferRequestParamsDto); when(s3Service.listDirectory(updatedS3FileTransferRequestParamsDto, true)).thenReturn(actualS3Files); when(storageFileHelper.createStorageFilesFromS3ObjectSummaries(actualS3Files)).thenReturn(storageFilesCreatedFromActualS3Files); when(storageFileHelper.getFiles(storageFilesCreatedFromActualS3Files)).thenReturn(filesToBeRestored); businessObjectDataInitiateRestoreHelperServiceImpl.executeS3SpecificSteps(businessObjectDataRestoreDto); verify(storageHelper).getS3FileTransferRequestParamsDto(); verify(s3Service).listDirectory(any(S3FileTransferRequestParamsDto.class), eq(true)); verify(storageFileHelper).validateRegisteredS3Files(storageFiles, actualS3Files, STORAGE_NAME, businessObjectDataKey); verify(storageFileHelper).createStorageFilesFromS3ObjectSummaries(actualS3Files); verify(storageFileHelper).getFiles(storageFilesCreatedFromActualS3Files); verify(s3Service).restoreObjects(finalS3FileTransferRequestParamsDto, 36135, ARCHIVE_RETRIEVAL_OPTION); verifyNoMoreInteractionsHelper(); assertEquals(new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFiles, NO_EXCEPTION, ARCHIVE_RETRIEVAL_OPTION), businessObjectDataRestoreDto); }
@Test public void testExecuteS3SpecificStepsNonGlacierObjectFound() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); List<StorageFile> storageFiles = Collections.singletonList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT)); BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFiles, NO_EXCEPTION, ARCHIVE_RETRIEVAL_OPTION); S3FileTransferRequestParamsDto initialS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); S3FileTransferRequestParamsDto updatedS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); updatedS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME); updatedS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT); updatedS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/"); S3ObjectSummary standardS3ObjectSummary = mock(S3ObjectSummary.class); when(standardS3ObjectSummary.getKey()).thenReturn(S3_KEY); when(standardS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Standard.toString()); List<S3ObjectSummary> actualS3Files = Collections.singletonList(standardS3ObjectSummary); when(storageHelper.getS3FileTransferRequestParamsDto()).thenReturn(initialS3FileTransferRequestParamsDto); when(s3Service.listDirectory(updatedS3FileTransferRequestParamsDto, true)).thenReturn(actualS3Files); businessObjectDataInitiateRestoreHelperServiceImpl.executeS3SpecificSteps(businessObjectDataRestoreDto); verify(storageHelper).getS3FileTransferRequestParamsDto(); verify(s3Service).listDirectory(any(S3FileTransferRequestParamsDto.class), eq(true)); verify(storageFileHelper).validateRegisteredS3Files(storageFiles, actualS3Files, STORAGE_NAME, businessObjectDataKey); verify(jsonHelper).objectToJson(businessObjectDataKey); verifyNoMoreInteractionsHelper(); assertNotNull(businessObjectDataRestoreDto.getException()); assertEquals(IllegalArgumentException.class, businessObjectDataRestoreDto.getException().getClass()); assertEquals(String.format("S3 file \"%s\" is not archived (found %s storage class when expecting %s or %s). S3 Bucket Name: \"%s\"", S3_KEY, StorageClass.Standard.toString(), StorageClass.Glacier.toString(), StorageClass.DeepArchive.toString(), S3_BUCKET_NAME), businessObjectDataRestoreDto.getException().getMessage()); businessObjectDataRestoreDto.setException(NO_EXCEPTION); assertEquals(new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFiles, NO_EXCEPTION, ARCHIVE_RETRIEVAL_OPTION), businessObjectDataRestoreDto); }