use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataValidateFileExistenceNoValidatePrefixDirectoryInvalid.
@Test
public void testCreateBusinessObjectDataValidateFileExistenceNoValidatePrefixDirectoryInvalid() throws Exception {
// Create an S3 storage entity.
List<Attribute> attributes = new ArrayList<>();
attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME));
attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE), Boolean.TRUE.toString()));
storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3, attributes);
// Create relative database entities.
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, true, PARTITION_KEY);
businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS);
// Build a list of storage files.
List<StorageFile> storageFiles = businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES);
// Create and upload to S3 managed storage a set of test files.
businessObjectDataServiceTestHelper.prepareTestS3Files(S3_BUCKET_NAME, testS3KeyPrefix, localTempPath, LOCAL_FILES, new ArrayList<String>());
// Build a new business object data create request.
BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BDATA_STATUS, STORAGE_NAME, "INVALID_DIRECTORY_PATH", storageFiles);
try {
// Try to create a business object data instance.
businessObjectDataService.createBusinessObjectData(request);
fail("Should throw an IllegalArgumentException when a directory path doesn't match the S3 uploaded files.");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains(String.format("does not match the storage directory path \"%s\"", "INVALID_DIRECTORY_PATH")));
}
}
use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataInvalidStorageFileRowCount.
@Test
public void testCreateBusinessObjectDataInvalidStorageFileRowCount() {
// Create relative database entities.
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, true, PARTITION_KEY);
storageDaoTestHelper.createStorageEntity(STORAGE_NAME);
// Try to create a business object data instance when storage file row count has a negative value.
List<StorageFile> storageFiles = businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, Arrays.asList(LOCAL_FILE));
storageFiles.get(0).setRowCount(-1L);
BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, storageFiles);
try {
businessObjectDataService.createBusinessObjectData(request);
fail("Should throw an IllegalArgumentException when storage file size is not specified.");
} catch (IllegalArgumentException e) {
assertEquals(String.format("File \"%s/%s\" has a row count which is < 0.", testS3KeyPrefix, LOCAL_FILE), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataTrimParameters.
@Test
public void testCreateBusinessObjectDataTrimParameters() {
// Create relative database entities.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, true, PARTITION_KEY);
businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS);
storageDaoTestHelper.createStorageEntity(STORAGE_NAME);
// Build a business object data create request with some of the request parameters having leading and trailing whitespace characters.
BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, addWhitespace(BDEF_NAME), addWhitespace(FORMAT_USAGE_CODE), addWhitespace(FORMAT_FILE_TYPE_CODE), INITIAL_FORMAT_VERSION, addWhitespace(PARTITION_KEY), addWhitespace(PARTITION_VALUE), addWhitespace(BDATA_STATUS), addWhitespace(STORAGE_NAME), addWhitespace(testS3KeyPrefix), businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
for (StorageFile storageFile : request.getStorageUnits().get(0).getStorageFiles()) {
storageFile.setFilePath(addWhitespace(storageFile.getFilePath()));
}
BusinessObjectData resultBusinessObjectData = businessObjectDataService.createBusinessObjectData(request);
// Verify the results.
businessObjectDataServiceTestHelper.validateBusinessObjectData(businessObjectFormatEntity, PARTITION_VALUE, NO_SUBPARTITION_VALUES, INITIAL_DATA_VERSION, true, BDATA_STATUS, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, SORTED_LOCAL_FILES), CollectionUtils.isEmpty(request.getAttributes()) ? new ArrayList<Attribute>() : request.getAttributes(), resultBusinessObjectData);
}
use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.
the class StoragePolicyProcessorHelperServiceImplTest method testCompleteStoragePolicyTransitionImpl.
@Test
public void testCompleteStoragePolicyTransitionImpl() {
// 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, NO_SUBPARTITION_VALUES, DATA_VERSION);
// Create a business object data status entity.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.VALID);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
// Create a storage unit status entity.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(StorageUnitStatusEntity.ARCHIVING);
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStatus(storageUnitStatusEntity);
// Create a list of storage files.
List<StorageFile> storageFiles = Arrays.asList(new StorageFile(TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE, FILE_SIZE_1_KB, ROW_COUNT_1000));
// Create a storage policy transition parameters DTO.
StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto = new StoragePolicyTransitionParamsDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ARCHIVING, storageFiles, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
// 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 new storage unit status.
String storageUnitStatus = (String) invocation.getArguments()[1];
// Create a storage unit status entity for the new storage unit status.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(storageUnitStatus);
// Update the storage unit with the new status.
StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0];
storageUnitEntity.setStatus(storageUnitStatusEntity);
return null;
}
}).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, StorageUnitStatusEntity.ARCHIVED);
// Call the method under test.
storagePolicyProcessorHelperServiceImpl.completeStoragePolicyTransitionImpl(storagePolicyTransitionParamsDto);
// Verify the external calls.
verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
verify(businessObjectDataHelper, times(2)).businessObjectDataKeyToString(businessObjectDataKey);
verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
verify(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, StorageUnitStatusEntity.ARCHIVED);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(new StoragePolicyTransitionParamsDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, StorageUnitStatusEntity.ARCHIVED, StorageUnitStatusEntity.ARCHIVING, storageFiles, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME), storagePolicyTransitionParamsDto);
}
use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.
the class StoragePolicyProcessorHelperServiceImplTest method testInitiateStoragePolicyTransitionImpl.
@Test
public void testInitiateStoragePolicyTransitionImpl() {
// Create an empty storage policy transition parameters DTO.
StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto = new StoragePolicyTransitionParamsDto();
// 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, NO_SUBPARTITION_VALUES, DATA_VERSION);
// Create a business object format entity.
BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
// Create a business object data status entity.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.VALID);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
// Create a storage platform entity.
StoragePlatformEntity storagePlatformEntity = new StoragePlatformEntity();
storagePlatformEntity.setName(StoragePlatformEntity.S3);
// Create a storage entity.
StorageEntity storageEntity = new StorageEntity();
storageEntity.setStoragePlatform(storagePlatformEntity);
storageEntity.setName(STORAGE_NAME);
// Create a storage policy entity.
StoragePolicyTransitionTypeEntity storagePolicyTransitionTypeEntity = new StoragePolicyTransitionTypeEntity();
storagePolicyTransitionTypeEntity.setCode(StoragePolicyTransitionTypeEntity.GLACIER);
// Create a storage policy entity.
StoragePolicyEntity storagePolicyEntity = new StoragePolicyEntity();
storagePolicyEntity.setStorage(storageEntity);
storagePolicyEntity.setStoragePolicyTransitionType(storagePolicyTransitionTypeEntity);
// Create a list of storage file entities.
List<StorageFileEntity> storageFileEntities = Arrays.asList(new StorageFileEntity());
// Create a storage unit status entity.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(StorageUnitStatusEntity.ENABLED);
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStorage(storageEntity);
storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
storageUnitEntity.setStorageFiles(storageFileEntities);
storageUnitEntity.setStatus(storageUnitStatusEntity);
// Create a list of storage files.
List<StorageFile> storageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE_1_KB, ROW_COUNT_1000));
// Mock the external calls.
when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
when(storagePolicyDaoHelper.getStoragePolicyEntityByKeyAndVersion(storagePolicyKey, STORAGE_POLICY_VERSION)).thenReturn(storagePolicyEntity);
when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX)).thenReturn(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX);
when(storageHelper.getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX, storageEntity, false, true)).thenReturn(true);
when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE)).thenReturn(S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE);
when(storageHelper.getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE, storageEntity, false, true)).thenReturn(true);
when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME)).thenReturn(S3_ATTRIBUTE_NAME_BUCKET_NAME);
when(storageHelper.getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true)).thenReturn(S3_BUCKET_NAME);
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_KEY)).thenReturn(S3_OBJECT_TAG_KEY);
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_VALUE)).thenReturn(S3_OBJECT_TAG_VALUE);
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_ARN)).thenReturn(S3_OBJECT_TAGGER_ROLE_ARN);
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_SESSION_NAME)).thenReturn(S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity);
when(s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey)).thenReturn(S3_KEY_PREFIX);
when(storageFileHelper.getAndValidateStorageFiles(storageUnitEntity, S3_KEY_PREFIX, STORAGE_NAME, businessObjectDataKey)).thenReturn(storageFiles);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
// Get the new storage unit status.
String storageUnitStatus = (String) invocation.getArguments()[1];
// Create a storage unit status entity for the new storage unit status.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(storageUnitStatus);
// Update the storage unit with the new status.
StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0];
storageUnitEntity.setStatus(storageUnitStatusEntity);
return null;
}
}).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ARCHIVING);
when(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT)).thenReturn(S3_ENDPOINT);
// Call the method under test.
storagePolicyProcessorHelperServiceImpl.initiateStoragePolicyTransitionImpl(storagePolicyTransitionParamsDto, new StoragePolicySelection(businessObjectDataKey, storagePolicyKey, STORAGE_POLICY_VERSION));
// Verify the external calls.
verify(businessObjectDataHelper).validateBusinessObjectDataKey(businessObjectDataKey, true, true);
verify(storagePolicyHelper).validateStoragePolicyKey(storagePolicyKey);
verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
verify(businessObjectDataHelper, times(2)).businessObjectDataKeyToString(businessObjectDataKey);
verify(storagePolicyDaoHelper).getStoragePolicyEntityByKeyAndVersion(storagePolicyKey, STORAGE_POLICY_VERSION);
verify(storagePolicyHelper, times(2)).storagePolicyKeyAndVersionToString(storagePolicyKey, STORAGE_POLICY_VERSION);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX);
verify(storageHelper).getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX, storageEntity, false, true);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE);
verify(storageHelper).getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE, storageEntity, false, true);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME);
verify(storageHelper).getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_KEY);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_VALUE);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_ARN);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_SESSION_NAME);
verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
verify(s3KeyPrefixHelper).buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey);
verify(storageFileHelper).getAndValidateStorageFiles(storageUnitEntity, S3_KEY_PREFIX, STORAGE_NAME, businessObjectDataKey);
verify(storageFileDaoHelper).validateStorageFilesCount(STORAGE_NAME, businessObjectDataKey, S3_KEY_PREFIX, storageFileEntities.size());
verify(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ARCHIVING);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ENDPOINT);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(new StoragePolicyTransitionParamsDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ENABLED, storageFiles, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME), storagePolicyTransitionParamsDto);
}
Aggregations