use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class BusinessObjectDataInitiateDestroyHelperServiceImplTest method testValidateStorageValidatePathPrefixNotEnabled.
@Test
public void testValidateStorageValidatePathPrefixNotEnabled() {
// Create a storage entity without any attributes.
StorageEntity storageEntity = new StorageEntity();
storageEntity.setName(STORAGE_NAME);
// Mock the external calls.
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(false);
// Try to call the method under test.
try {
businessObjectDataInitiateDestroyHelperServiceImpl.validateStorage(storageEntity);
fail();
} catch (IllegalStateException e) {
assertEquals(String.format("Path prefix validation must be enabled on \"%s\" storage.", STORAGE_NAME), e.getMessage());
}
// Verify the external calls.
verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX);
verify(storageHelper).getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX, storageEntity, false, true);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class UploadDownloadHelperServiceImplTest method testPrepareForFileMove.
@Test
public void testPrepareForFileMove() {
// Create an object key.
String objectKey = UUID_VALUE;
// Create a complete upload single parameters DTO.
CompleteUploadSingleParamsDto completeUploadSingleParamsDto = new CompleteUploadSingleParamsDto();
// Create a business object data status entity.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.UPLOADING);
// Create a source storage entity.
StorageEntity sourceStorageEntity = new StorageEntity();
// Create a source business object data key.
BusinessObjectDataKey sourceBusinessObjectDataKey = new BusinessObjectDataKey();
sourceBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
// Create a source business object data entity.
BusinessObjectDataEntity sourceBusinessObjectDataEntity = new BusinessObjectDataEntity();
sourceBusinessObjectDataEntity.setId(ID);
sourceBusinessObjectDataEntity.setPartitionValue(objectKey);
sourceBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
// Create a list of source storage files.
List<StorageFileEntity> sourceStorageFileEntities = new ArrayList<>();
// Create a source storage unit.
StorageUnitEntity sourceStorageUnitEntity = new StorageUnitEntity();
sourceStorageUnitEntity.setBusinessObjectData(sourceBusinessObjectDataEntity);
sourceStorageUnitEntity.setStorage(sourceStorageEntity);
sourceStorageUnitEntity.setStorageFiles(sourceStorageFileEntities);
// Create a source storage file entity.
StorageFileEntity sourceStorageFileEntity = new StorageFileEntity();
sourceStorageFileEntities.add(sourceStorageFileEntity);
sourceStorageFileEntity.setStorageUnit(sourceStorageUnitEntity);
sourceStorageFileEntity.setPath(S3_KEY);
sourceStorageFileEntity.setFileSizeBytes(FILE_SIZE);
// Create a target storage entity.
StorageEntity targetStorageEntity = new StorageEntity();
// Create a target business object data key.
BusinessObjectDataKey targetBusinessObjectDataKey = new BusinessObjectDataKey();
targetBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE_2);
// Create a list of source storage files.
List<StorageFileEntity> targetStorageFileEntities = new ArrayList<>();
// Create a target storage unit.
StorageUnitEntity targetStorageUnitEntity = new StorageUnitEntity();
targetStorageUnitEntity.setStorage(targetStorageEntity);
targetStorageUnitEntity.setStorageFiles(targetStorageFileEntities);
// Create a source storage file entity.
StorageFileEntity targetStorageFileEntity = new StorageFileEntity();
targetStorageFileEntities.add(targetStorageFileEntity);
targetStorageFileEntity.setPath(S3_KEY_2);
// Create a target business object data entity.
BusinessObjectDataEntity targetBusinessObjectDataEntity = new BusinessObjectDataEntity();
targetBusinessObjectDataEntity.setId(ID_2);
targetBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
targetBusinessObjectDataEntity.setStorageUnits(Collections.singletonList(targetStorageUnitEntity));
// Create an AWS parameters DTO.
AwsParamsDto awsParamsDto = new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
// Mock the external calls.
when(storageFileDaoHelper.getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey)).thenReturn(sourceStorageFileEntity);
when(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity)).thenReturn(sourceBusinessObjectDataKey);
when(businessObjectDataDao.getBusinessObjectDataEntitiesByPartitionValue(objectKey)).thenReturn(Arrays.asList(sourceBusinessObjectDataEntity, targetBusinessObjectDataEntity));
when(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity)).thenReturn(targetBusinessObjectDataKey);
when(storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE)).thenReturn(sourceStorageEntity);
when(storageHelper.getStorageBucketName(sourceStorageEntity)).thenReturn(S3_BUCKET_NAME);
when(storageUnitDaoHelper.getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity)).thenReturn(sourceStorageUnitEntity);
when(awsHelper.getAwsParamsDto()).thenReturn(awsParamsDto);
when(storageHelper.getStorageBucketName(targetStorageEntity)).thenReturn(S3_BUCKET_NAME_2);
when(storageHelper.getStorageKmsKeyId(targetStorageEntity)).thenReturn(AWS_KMS_KEY_ID);
// Call the method under test.
uploadDownloadHelperService.prepareForFileMoveImpl(objectKey, completeUploadSingleParamsDto);
// Verify the external calls.
verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey);
verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey);
verify(businessObjectDataHelper).getBusinessObjectDataKey(sourceBusinessObjectDataEntity);
verify(businessObjectDataDao).getBusinessObjectDataEntitiesByPartitionValue(objectKey);
verify(businessObjectDataHelper).getBusinessObjectDataKey(targetBusinessObjectDataEntity);
verify(storageDaoHelper).getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE);
verify(storageHelper).getStorageBucketName(sourceStorageEntity);
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(s3Dao).s3FileExists(any(S3FileTransferRequestParamsDto.class));
verify(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(sourceBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
verify(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(targetBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, sourceBusinessObjectDataKey, BusinessObjectDataStatusEntity.RE_ENCRYPTING, BusinessObjectDataStatusEntity.UPLOADING);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, targetBusinessObjectDataKey, BusinessObjectDataStatusEntity.RE_ENCRYPTING, BusinessObjectDataStatusEntity.UPLOADING);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(new CompleteUploadSingleParamsDto(sourceBusinessObjectDataKey, S3_BUCKET_NAME, S3_KEY, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, targetBusinessObjectDataKey, S3_BUCKET_NAME_2, S3_KEY_2, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, AWS_KMS_KEY_ID, awsParamsDto), completeUploadSingleParamsDto);
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class UploadDownloadHelperServiceImplTest method testPrepareForFileMoveImplOptimisticLockException.
@Test
public void testPrepareForFileMoveImplOptimisticLockException() {
// Create an object key.
String objectKey = UUID_VALUE;
// Create a complete upload single parameters DTO.
CompleteUploadSingleParamsDto completeUploadSingleParamsDto = new CompleteUploadSingleParamsDto();
// Create a business object data status entity.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.UPLOADING);
// Create a source storage entity.
StorageEntity sourceStorageEntity = new StorageEntity();
// Create a source business object data key.
BusinessObjectDataKey sourceBusinessObjectDataKey = new BusinessObjectDataKey();
sourceBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
// Create a source business object data entity.
BusinessObjectDataEntity sourceBusinessObjectDataEntity = new BusinessObjectDataEntity();
sourceBusinessObjectDataEntity.setId(ID);
sourceBusinessObjectDataEntity.setPartitionValue(objectKey);
sourceBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
// Create a list of source storage files.
List<StorageFileEntity> sourceStorageFileEntities = new ArrayList<>();
// Create a source storage unit.
StorageUnitEntity sourceStorageUnitEntity = new StorageUnitEntity();
sourceStorageUnitEntity.setBusinessObjectData(sourceBusinessObjectDataEntity);
sourceStorageUnitEntity.setStorage(sourceStorageEntity);
sourceStorageUnitEntity.setStorageFiles(sourceStorageFileEntities);
// Create a source storage file entity.
StorageFileEntity sourceStorageFileEntity = new StorageFileEntity();
sourceStorageFileEntities.add(sourceStorageFileEntity);
sourceStorageFileEntity.setStorageUnit(sourceStorageUnitEntity);
sourceStorageFileEntity.setPath(S3_KEY);
sourceStorageFileEntity.setFileSizeBytes(FILE_SIZE);
// Create a target storage entity.
StorageEntity targetStorageEntity = new StorageEntity();
// Create a target business object data key.
BusinessObjectDataKey targetBusinessObjectDataKey = new BusinessObjectDataKey();
targetBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE_2);
// Create a list of source storage files.
List<StorageFileEntity> targetStorageFileEntities = new ArrayList<>();
// Create a target storage unit.
StorageUnitEntity targetStorageUnitEntity = new StorageUnitEntity();
targetStorageUnitEntity.setStorage(targetStorageEntity);
targetStorageUnitEntity.setStorageFiles(targetStorageFileEntities);
// Create a source storage file entity.
StorageFileEntity targetStorageFileEntity = new StorageFileEntity();
targetStorageFileEntities.add(targetStorageFileEntity);
targetStorageFileEntity.setPath(S3_KEY_2);
// Create a target business object data entity.
BusinessObjectDataEntity targetBusinessObjectDataEntity = new BusinessObjectDataEntity();
targetBusinessObjectDataEntity.setId(ID_2);
targetBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
targetBusinessObjectDataEntity.setStorageUnits(Collections.singletonList(targetStorageUnitEntity));
// Create an AWS parameters DTO.
AwsParamsDto awsParamsDto = new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
// Mock the external calls.
when(storageFileDaoHelper.getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey)).thenReturn(sourceStorageFileEntity);
when(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity)).thenReturn(sourceBusinessObjectDataKey);
when(businessObjectDataDao.getBusinessObjectDataEntitiesByPartitionValue(objectKey)).thenReturn(Arrays.asList(sourceBusinessObjectDataEntity, targetBusinessObjectDataEntity));
when(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity)).thenReturn(targetBusinessObjectDataKey);
when(storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE)).thenReturn(sourceStorageEntity);
when(storageHelper.getStorageBucketName(sourceStorageEntity)).thenReturn(S3_BUCKET_NAME);
when(storageUnitDaoHelper.getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity)).thenReturn(sourceStorageUnitEntity);
when(awsHelper.getAwsParamsDto()).thenReturn(awsParamsDto);
when(storageHelper.getStorageBucketName(targetStorageEntity)).thenReturn(S3_BUCKET_NAME_2);
when(storageHelper.getStorageKmsKeyId(targetStorageEntity)).thenReturn(AWS_KMS_KEY_ID);
doThrow(new OptimisticLockException(ERROR_MESSAGE)).when(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(sourceBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
when(jsonHelper.objectToJson(sourceBusinessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING);
when(jsonHelper.objectToJson(targetBusinessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING_2);
// Try to call the method under test.
try {
uploadDownloadHelperService.prepareForFileMoveImpl(objectKey, completeUploadSingleParamsDto);
} catch (OptimisticLockException e) {
assertEquals(String.format("Ignoring S3 notification due to an optimistic lock exception caused by duplicate S3 event notifications. " + "sourceBusinessObjectDataKey=%s targetBusinessObjectDataKey=%s", BUSINESS_OBJECT_DATA_KEY_AS_STRING, BUSINESS_OBJECT_DATA_KEY_AS_STRING_2), e.getMessage());
}
// Verify the external calls.
verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey);
verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey);
verify(businessObjectDataHelper).getBusinessObjectDataKey(sourceBusinessObjectDataEntity);
verify(businessObjectDataDao).getBusinessObjectDataEntitiesByPartitionValue(objectKey);
verify(businessObjectDataHelper).getBusinessObjectDataKey(targetBusinessObjectDataEntity);
verify(storageDaoHelper).getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE);
verify(storageHelper).getStorageBucketName(sourceStorageEntity);
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(s3Dao).s3FileExists(any(S3FileTransferRequestParamsDto.class));
verify(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(sourceBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
verify(jsonHelper).objectToJson(sourceBusinessObjectDataKey);
verify(jsonHelper).objectToJson(targetBusinessObjectDataKey);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(new CompleteUploadSingleParamsDto(sourceBusinessObjectDataKey, S3_BUCKET_NAME, S3_KEY, BusinessObjectDataStatusEntity.UPLOADING, NO_BDATA_STATUS, targetBusinessObjectDataKey, S3_BUCKET_NAME_2, S3_KEY_2, BusinessObjectDataStatusEntity.UPLOADING, NO_BDATA_STATUS, AWS_KMS_KEY_ID, awsParamsDto), completeUploadSingleParamsDto);
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class StorageHelperTest method testGetStorageAttributeIntegerValueByName_2.
/**
* Storage attribute: 1234 Attribute required: true Attribute required if exists: false Assert result = 1234
*/
@Test
public void testGetStorageAttributeIntegerValueByName_2() {
String attributeName = "test";
String attributeValue = "1234";
StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue);
boolean attributeRequired = true;
boolean attributeValueRequiredIfExists = false;
Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists);
assertEquals(new Integer(attributeValue), value);
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class StorageHelperTest method testGetStorageAttributeValueByNameFromStorageEntity.
@Test
public void testGetStorageAttributeValueByNameFromStorageEntity() {
// Create an S3 storage entity.
List<Attribute> attributes = new ArrayList<>();
attributes.add(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1));
attributes.add(new Attribute(ATTRIBUTE_NAME_2_MIXED_CASE, BLANK_TEXT));
attributes.add(new Attribute(ATTRIBUTE_NAME_3_MIXED_CASE, null));
StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3, attributes);
// Retrieve optional attribute values.
Assert.assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE, storageEntity, false));
Assert.assertEquals(BLANK_TEXT, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_2_MIXED_CASE, storageEntity, false));
Assert.assertNull(storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_3_MIXED_CASE, storageEntity, false));
// Validate case insensitivity.
Assert.assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE.toUpperCase(), storageEntity, false));
Assert.assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE.toLowerCase(), storageEntity, false));
// Retrieve a required attribute value.
Assert.assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE, storageEntity, true));
// Try to retrieve a missing required attribute values when
// - attribute does not exist
// - attribute exists with a blank text value
// - attribute exists with a null value
String attributeNoExist = "I_DO_NOT_EXIST";
for (String attributeName : Arrays.asList(attributeNoExist, ATTRIBUTE_NAME_2_MIXED_CASE, ATTRIBUTE_NAME_3_MIXED_CASE)) {
try {
storageHelper.getStorageAttributeValueByName(attributeName, storageEntity, true);
} catch (IllegalStateException e) {
if (attributeName.equals(attributeNoExist)) {
Assert.assertEquals(String.format("Attribute \"%s\" for \"%s\" storage must be configured.", attributeName, STORAGE_NAME), e.getMessage());
} else {
Assert.assertEquals(String.format("Attribute \"%s\" for \"%s\" storage must have a value that is not blank.", attributeName, STORAGE_NAME), e.getMessage());
}
}
}
}
Aggregations