use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto in project herd by FINRAOS.
the class BusinessObjectDataInitiateRestoreHelperServiceImplTest method testExecuteS3SpecificSteps.
@Test
public void testExecuteS3SpecificSteps() {
// Create a business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
// Create a list of storage files to be passed as an input.
List<StorageFile> storageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT));
// Create a DTO for business object data restore parameters.
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);
// Create an S3 file transfer parameters DTO to access the S3 bucket.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
// Create an updated version of the S3 file transfer request parameters DTO.
S3FileTransferRequestParamsDto updatedS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
updatedS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
updatedS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
updatedS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/");
// Create a mock S3 object summary for S3 object that does not belong to Glacier storage class.
S3ObjectSummary glacierS3ObjectSummary = mock(S3ObjectSummary.class);
when(glacierS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Glacier.toString());
// Create a mock S3 object summary for S3 object that does not belong to Glacier storage class.
S3ObjectSummary standardS3ObjectSummary = mock(S3ObjectSummary.class);
when(standardS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Standard.toString());
// Create a list of S3 files.
List<S3ObjectSummary> s3Files = Arrays.asList(glacierS3ObjectSummary, standardS3ObjectSummary);
// Create a list of S3 objects that belong to Glacier storage class.
List<S3ObjectSummary> glacierS3Files = Arrays.asList(glacierS3ObjectSummary);
// Create a list of storage files that represent S3 objects of Glacier storage class.
List<StorageFile> glacierStorageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT));
// Create a list of storage files selected for S3 object tagging.
List<File> filesSelectedForRestore = Arrays.asList(new File(S3_KEY));
// Create a final version of DTO for business object data restore parameters.
S3FileTransferRequestParamsDto finalS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
finalS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
finalS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
finalS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/");
finalS3FileTransferRequestParamsDto.setFiles(filesSelectedForRestore);
// Mock the external calls.
when(storageHelper.getS3FileTransferRequestParamsDto()).thenReturn(s3FileTransferRequestParamsDto);
when(s3Service.listDirectory(updatedS3FileTransferRequestParamsDto, true)).thenReturn(s3Files);
when(storageFileHelper.createStorageFilesFromS3ObjectSummaries(glacierS3Files)).thenReturn(glacierStorageFiles);
when(storageFileHelper.getFiles(glacierStorageFiles)).thenReturn(filesSelectedForRestore);
// Call the method under test.
businessObjectDataInitiateRestoreHelperServiceImpl.executeS3SpecificSteps(businessObjectDataRestoreDto);
// Verify the external calls.
verify(storageHelper).getS3FileTransferRequestParamsDto();
verify(s3Service).listDirectory(any(S3FileTransferRequestParamsDto.class), eq(true));
verify(storageFileHelper).validateRegisteredS3Files(storageFiles, s3Files, STORAGE_NAME, businessObjectDataKey);
verify(storageFileHelper).createStorageFilesFromS3ObjectSummaries(glacierS3Files);
verify(storageFileHelper).getFiles(glacierStorageFiles);
verify(s3Service).restoreObjects(finalS3FileTransferRequestParamsDto, 36135);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto in project herd by FINRAOS.
the class ExpireRestoredBusinessObjectDataServiceImplTest method testExpireS3StorageUnit.
@Test
public void testExpireS3StorageUnit() {
// Create a business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
// Create a storage unit key.
BusinessObjectDataStorageUnitKey storageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
// Create a DTO for business object data restore parameters.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, StorageUnitStatusEntity.EXPIRING, StorageUnitStatusEntity.RESTORED, Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT)), NO_EXCEPTION);
// Mock the external calls.
when(expireRestoredBusinessObjectDataHelperService.prepareToExpireStorageUnit(storageUnitKey)).thenReturn(businessObjectDataRestoreDto);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
// Get the parameters DTO for the business object data restore.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = (BusinessObjectDataRestoreDto) invocation.getArguments()[0];
// Set the value for the new and old storage unit statuses.
businessObjectDataRestoreDto.setNewStorageUnitStatus(StorageUnitStatusEntity.ARCHIVED);
businessObjectDataRestoreDto.setOldStorageUnitStatus(StorageUnitStatusEntity.EXPIRING);
return null;
}
}).when(expireRestoredBusinessObjectDataHelperService).completeStorageUnitExpiration(businessObjectDataRestoreDto);
// Call the method under test.
expireRestoredBusinessObjectDataServiceImpl.expireS3StorageUnit(storageUnitKey);
// Verify the external calls.
verify(expireRestoredBusinessObjectDataHelperService).prepareToExpireStorageUnit(storageUnitKey);
verify(notificationEventService).processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, STORAGE_NAME, StorageUnitStatusEntity.EXPIRING, StorageUnitStatusEntity.RESTORED);
verify(expireRestoredBusinessObjectDataHelperService).executeS3SpecificSteps(businessObjectDataRestoreDto);
verify(expireRestoredBusinessObjectDataHelperService).completeStorageUnitExpiration(businessObjectDataRestoreDto);
verify(notificationEventService).processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, STORAGE_NAME, StorageUnitStatusEntity.ARCHIVED, StorageUnitStatusEntity.EXPIRING);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto in project herd by FINRAOS.
the class BusinessObjectDataFinalizeRestoreHelperServiceImplTest method testExecuteS3SpecificSteps.
@Test
public void testExecuteS3SpecificSteps() {
// Create a business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
// Create a list of storage files.
List<StorageFile> storageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT), new StorageFile(S3_KEY_2, FILE_SIZE_2, ROW_COUNT_2));
// Create a DTO for business object data restore parameters.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, STORAGE_UNIT_STATUS_2, STORAGE_UNIT_STATUS, storageFiles, NO_EXCEPTION);
// Create an initial instance of S3 file transfer parameters DTO.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
// Create an updated version of S3 file transfer parameters DTO.
S3FileTransferRequestParamsDto updatedS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
updatedS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
updatedS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
updatedS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/");
// Create a mock S3 object summary for S3 object that belongs to Glacier storage class.
S3ObjectSummary glacierS3ObjectSummary = mock(S3ObjectSummary.class);
when(glacierS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Glacier.toString());
// Create a mock S3 object summary for S3 object that does not belong to Glacier storage class.
S3ObjectSummary standardS3ObjectSummary = mock(S3ObjectSummary.class);
when(standardS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Standard.toString());
// Create a list of S3 files.
List<S3ObjectSummary> s3Files = Arrays.asList(glacierS3ObjectSummary, standardS3ObjectSummary);
// Create a list of S3 objects that belong to Glacier storage class.
List<S3ObjectSummary> glacierS3Files = Arrays.asList(glacierS3ObjectSummary);
// Create a list of storage files that represent S3 objects of Glacier storage class.
List<StorageFile> glacierStorageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT));
// Create a list of files.
List<File> files = Arrays.asList(new File(S3_KEY));
// Create a final version of DTO for business object data restore parameters.
S3FileTransferRequestParamsDto finalS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
finalS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
finalS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
finalS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/");
finalS3FileTransferRequestParamsDto.setFiles(files);
// Mock the external calls.
when(storageHelper.getS3FileTransferRequestParamsDto()).thenReturn(s3FileTransferRequestParamsDto);
when(s3Service.listDirectory(updatedS3FileTransferRequestParamsDto, true)).thenReturn(s3Files);
when(storageFileHelper.createStorageFilesFromS3ObjectSummaries(glacierS3Files)).thenReturn(glacierStorageFiles);
when(storageFileHelper.getFiles(glacierStorageFiles)).thenReturn(files);
// Call the method under test.
businessObjectDataFinalizeRestoreHelperServiceImpl.executeS3SpecificSteps(businessObjectDataRestoreDto);
// Verify the external calls.
verify(storageHelper).getS3FileTransferRequestParamsDto();
verify(s3Service).listDirectory(any(S3FileTransferRequestParamsDto.class), eq(true));
verify(storageFileHelper).validateRegisteredS3Files(storageFiles, s3Files, STORAGE_NAME, businessObjectDataKey);
verify(storageFileHelper).createStorageFilesFromS3ObjectSummaries(glacierS3Files);
verify(storageFileHelper).getFiles(glacierStorageFiles);
verify(s3Service).validateGlacierS3FilesRestored(finalS3FileTransferRequestParamsDto);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto in project herd by FINRAOS.
the class ExpireRestoredBusinessObjectDataHelperServiceImplTest method testCompleteStorageUnitExpiration.
@Test
public void testCompleteStorageUnitExpiration() {
// Create a business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
// Create a DTO for business object data restore parameters.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT)), NO_EXCEPTION);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
// Create a new storage unit status entity.
StorageUnitStatusEntity newStorageUnitStatusEntity = new StorageUnitStatusEntity();
newStorageUnitStatusEntity.setCode(StorageUnitStatusEntity.ARCHIVED);
// Create an old storage unit status entity.
StorageUnitStatusEntity oldStorageUnitStatusEntity = new StorageUnitStatusEntity();
oldStorageUnitStatusEntity.setCode(StorageUnitStatusEntity.EXPIRING);
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStatus(oldStorageUnitStatusEntity);
// Mock the external calls.
when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
// Get the storage unit entity.
StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0];
// Update the storage unit status.
storageUnitEntity.setStatus(newStorageUnitStatusEntity);
return null;
}
}).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, StorageUnitStatusEntity.ARCHIVED);
// Call the method under test.
expireRestoredBusinessObjectDataHelperServiceImpl.completeStorageUnitExpiration(businessObjectDataRestoreDto);
// Verify the external calls.
verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
verify(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, StorageUnitStatusEntity.ARCHIVED);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(StorageUnitStatusEntity.ARCHIVED, businessObjectDataRestoreDto.getNewStorageUnitStatus());
assertEquals(StorageUnitStatusEntity.EXPIRING, businessObjectDataRestoreDto.getOldStorageUnitStatus());
}
use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto in project herd by FINRAOS.
the class ExpireRestoredBusinessObjectDataHelperServiceImplTest method testExecuteS3SpecificSteps.
@Test
public void testExecuteS3SpecificSteps() {
// Create a business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
// Create a list of storage files.
List<StorageFile> storageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT), new StorageFile(S3_KEY_2, FILE_SIZE_2, ROW_COUNT_2));
// Create a DTO for business object data restore parameters.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, STORAGE_UNIT_STATUS_2, STORAGE_UNIT_STATUS, storageFiles, NO_EXCEPTION);
// Create an initial instance of S3 file transfer parameters DTO.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
// Create an updated version of S3 file transfer parameters DTO.
S3FileTransferRequestParamsDto updatedS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
updatedS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
updatedS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
updatedS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/");
// Create a mock S3 object summary for S3 object that belongs to Glacier storage class.
S3ObjectSummary glacierS3ObjectSummary = mock(S3ObjectSummary.class);
when(glacierS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Glacier.toString());
// Create a mock S3 object summary for S3 object that does not belong to Glacier storage class.
S3ObjectSummary standardS3ObjectSummary = mock(S3ObjectSummary.class);
when(standardS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Standard.toString());
// Create a list of S3 files.
List<S3ObjectSummary> s3Files = Arrays.asList(glacierS3ObjectSummary, standardS3ObjectSummary);
// Create a list of S3 objects that belong to Glacier storage class.
List<S3ObjectSummary> glacierS3Files = Arrays.asList(glacierS3ObjectSummary);
// Create a list of storage files that represent S3 objects of Glacier storage class.
List<StorageFile> glacierStorageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT));
// Create a list of files.
List<File> files = Arrays.asList(new File(S3_KEY));
// Create a final version of DTO for business object data restore parameters.
S3FileTransferRequestParamsDto finalS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
finalS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
finalS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
finalS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/");
finalS3FileTransferRequestParamsDto.setFiles(files);
// Mock the external calls.
when(storageHelper.getS3FileTransferRequestParamsDto()).thenReturn(s3FileTransferRequestParamsDto);
when(s3Service.listDirectory(updatedS3FileTransferRequestParamsDto, true)).thenReturn(s3Files);
when(storageFileHelper.createStorageFilesFromS3ObjectSummaries(glacierS3Files)).thenReturn(glacierStorageFiles);
when(storageFileHelper.getFiles(glacierStorageFiles)).thenReturn(files);
// Call the method under test.
expireRestoredBusinessObjectDataHelperServiceImpl.executeS3SpecificSteps(businessObjectDataRestoreDto);
// Verify the external calls.
verify(storageHelper).getS3FileTransferRequestParamsDto();
verify(s3Service).listDirectory(any(S3FileTransferRequestParamsDto.class), eq(true));
verify(storageFileHelper).validateRegisteredS3Files(storageFiles, s3Files, STORAGE_NAME, businessObjectDataKey);
verify(storageFileHelper).createStorageFilesFromS3ObjectSummaries(glacierS3Files);
verify(storageFileHelper).getFiles(glacierStorageFiles);
verify(s3Service).restoreObjects(finalS3FileTransferRequestParamsDto, 1);
verifyNoMoreInteractionsHelper();
}
Aggregations