use of org.finra.herd.model.api.xml.Attribute in project herd by FINRAOS.
the class UploadDownloadServiceTest method testUploadBusinessObjectDefinitionSampleFile.
@Test
public void testUploadBusinessObjectDefinitionSampleFile() {
String s3_velocity_template = "$namespace/$businessObjectDefinitionName";
String expectedS3Keyprefix = NAMESPACE.toLowerCase() + "/" + BDEF_NAME.toLowerCase() + "/";
expectedS3Keyprefix = expectedS3Keyprefix.replace("_", "-");
// Create a test storage.
storageDaoTestHelper.createStorageEntity(StorageEntity.SAMPLE_DATA_FILE_STORAGE, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_UPLOAD_ROLE_ARN), UPLOADER_ROLE_ARN), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), s3_velocity_template)));
// Create and persist a business object definition entity with sample data files.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes());
UploadBusinessObjectDefinitionSampleDataFileInitiationRequest request = new UploadBusinessObjectDefinitionSampleDataFileInitiationRequest();
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME);
request.setBusinessObjectDefinitionKey(businessObjectDefinitionKey);
UploadBusinessObjectDefinitionSampleDataFileInitiationResponse response = uploadDownloadService.initiateUploadSampleFile(request);
assertEquals(response.getBusinessObjectDefinitionKey(), businessObjectDefinitionKey);
assertEquals(response.getAwsS3BucketName(), S3_BUCKET_NAME);
assertEquals(response.getS3KeyPrefix(), expectedS3Keyprefix);
assertEquals(response.getAwsAccessKey(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_ACCESS_KEY);
assertEquals(response.getAwsSecretKey(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SECRET_KEY);
assertEquals(response.getAwsSessionToken(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SESSION_TOKEN);
}
use of org.finra.herd.model.api.xml.Attribute in project herd by FINRAOS.
the class UploadDownloadServiceTest method testUploadBusinessObjectDefinitionSampleFileMissingTemplate.
@Test
public void testUploadBusinessObjectDefinitionSampleFileMissingTemplate() {
// String s3_velocity_template = "$namespace/$businessObjectDefinitionName";
String expectedS3Keyprefix = NAMESPACE.toLowerCase() + "/" + BDEF_NAME.toLowerCase() + "/";
expectedS3Keyprefix = expectedS3Keyprefix.replace("_", "-");
// Create a test storage.
storageDaoTestHelper.createStorageEntity(StorageEntity.SAMPLE_DATA_FILE_STORAGE, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_UPLOAD_ROLE_ARN), UPLOADER_ROLE_ARN)));
// Create and persist a business object definition entity with sample data files.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes());
UploadBusinessObjectDefinitionSampleDataFileInitiationRequest request = new UploadBusinessObjectDefinitionSampleDataFileInitiationRequest();
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME);
request.setBusinessObjectDefinitionKey(businessObjectDefinitionKey);
try {
uploadDownloadService.initiateUploadSampleFile(request);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Storage \"%s\" has no S3 key prefix velocity template configured.", StorageEntity.SAMPLE_DATA_FILE_STORAGE), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.Attribute in project herd by FINRAOS.
the class UploadDownloadServiceTest method testUploadBusinessObjectDefinitionSampleFileLowerCase.
@Test
public void testUploadBusinessObjectDefinitionSampleFileLowerCase() {
String s3_velocity_template = "$namespace/$businessObjectDefinitionName";
// Create a test storage.
storageDaoTestHelper.createStorageEntity(StorageEntity.SAMPLE_DATA_FILE_STORAGE, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_UPLOAD_ROLE_ARN), UPLOADER_ROLE_ARN), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), s3_velocity_template)));
// Create and persist a business object definition entity with sample data files.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes());
UploadBusinessObjectDefinitionSampleDataFileInitiationRequest request = new UploadBusinessObjectDefinitionSampleDataFileInitiationRequest();
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME);
BusinessObjectDefinitionKey businessObjectDefinitionKeyLowerCase = new BusinessObjectDefinitionKey(NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase());
request.setBusinessObjectDefinitionKey(businessObjectDefinitionKeyLowerCase);
UploadBusinessObjectDefinitionSampleDataFileInitiationResponse response = uploadDownloadService.initiateUploadSampleFile(request);
assertEquals(response.getBusinessObjectDefinitionKey(), businessObjectDefinitionKey);
assertEquals(response.getAwsS3BucketName(), S3_BUCKET_NAME);
assertEquals(response.getAwsAccessKey(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_ACCESS_KEY);
assertEquals(response.getAwsSecretKey(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SECRET_KEY);
assertEquals(response.getAwsSessionToken(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SESSION_TOKEN);
}
use of org.finra.herd.model.api.xml.Attribute in project herd by FINRAOS.
the class StoragePolicyServiceTest method testUpdateStoragePolicyStoragePolicyFilterStorageFileExistenceValidationNotEnabled.
@Test
public void testUpdateStoragePolicyStoragePolicyFilterStorageFileExistenceValidationNotEnabled() {
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
// Create and persist the relative database entities.
storagePolicyServiceTestHelper.createDatabaseEntitiesForStoragePolicyTesting();
// Create and persist a storage policy entity.
storagePolicyDaoTestHelper.createStoragePolicyEntity(storagePolicyKey, STORAGE_POLICY_RULE_TYPE_2, STORAGE_POLICY_RULE_VALUE_2, BDEF_NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, STORAGE_NAME_2, STORAGE_POLICY_TRANSITION_TYPE_2, StoragePolicyStatusEntity.ENABLED, INITIAL_VERSION, LATEST_VERSION_FLAG_SET);
// Create an S3 storage with the bucket name configured, the S3 path prefix validation enabled, but without S3 file existence validation enabled.
// Enable the S3 path prefix validation for this storage.
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_PATH_PREFIX), Boolean.TRUE.toString()));
storageDaoTestHelper.createStorageEntity(STORAGE_NAME_5, StoragePlatformEntity.S3, attributes);
// Try to update a storage policy when storage policy filter storage has no S3 file existence validation enabled.
StoragePolicyUpdateRequest request = storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME_5, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.DISABLED);
try {
storagePolicyService.updateStoragePolicy(storagePolicyKey, request);
fail("Should throw an IllegalStateException when storage policy filter storage has no S3 file existence validation enabled.");
} catch (IllegalStateException e) {
assertEquals(String.format("File existence validation must be enabled on \"%s\" storage.", request.getStoragePolicyFilter().getStorageName()), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.Attribute in project herd by FINRAOS.
the class StoragePolicyServiceTest method testCreateStoragePolicyStoragePolicyFilterStorageFileExistenceValidationNotEnabled.
@Test
public void testCreateStoragePolicyStoragePolicyFilterStorageFileExistenceValidationNotEnabled() {
// Create and persist the relative database entities.
storagePolicyServiceTestHelper.createDatabaseEntitiesForStoragePolicyTesting();
// Create an S3 storage with the bucket name configured, the S3 path prefix validation enabled, but without S3 file existence validation enabled.
// Enable the S3 path prefix validation for this storage.
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_PATH_PREFIX), Boolean.TRUE.toString()));
storageDaoTestHelper.createStorageEntity(STORAGE_NAME_3, StoragePlatformEntity.S3, attributes);
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
// Try to create a storage policy when storage policy filter storage has no S3 file existence validation enabled.
StoragePolicyCreateRequest request = storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME_3, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED);
try {
storagePolicyService.createStoragePolicy(request);
fail("Should throw an IllegalStateException when storage policy filter storage has no S3 file existence validation enabled.");
} catch (IllegalStateException e) {
assertEquals(String.format("File existence validation must be enabled on \"%s\" storage.", request.getStoragePolicyFilter().getStorageName()), e.getMessage());
}
}
Aggregations