use of org.finra.herd.model.api.xml.StoragePolicyUpdateRequest in project herd by FINRAOS.
the class StoragePolicyRestControllerTest method testUpdateStoragePolicy.
@Test
public void testUpdateStoragePolicy() {
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
StoragePolicy storagePolicy = new StoragePolicy(ID, storagePolicyKey, new StoragePolicyRule(STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE), new StoragePolicyFilter(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME), new StoragePolicyTransition(STORAGE_POLICY_TRANSITION_TYPE), StoragePolicyStatusEntity.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, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.DISABLED);
when(storagePolicyService.updateStoragePolicy(storagePolicyKey, request)).thenReturn(storagePolicy);
// Update a storage policy.
StoragePolicy resultStoragePolicy = storagePolicyRestController.updateStoragePolicy(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME, request);
// Verify the external calls.
verify(storagePolicyService).updateStoragePolicy(storagePolicyKey, request);
verifyNoMoreInteractions(storagePolicyService);
// Validate the returned object.
assertEquals(storagePolicy, resultStoragePolicy);
}
use of org.finra.herd.model.api.xml.StoragePolicyUpdateRequest in project herd by FINRAOS.
the class StoragePolicyServiceTestHelper method createStoragePolicyUpdateRequest.
/**
* Creates a storage policy update request.
*
* @param storagePolicyRuleType the storage policy rule type
* @param storagePolicyRuleValue the storage policy rule value
* @param businessObjectDefinitionNamespace the business object definition namespace
* @param businessObjectDefinitionName the business object definition name
* @param businessObjectFormatUsage the business object usage
* @param businessObjectFormatFileType the business object format file type
* @param storageName the storage name
* @param storagePolicyTransitionType the storage policy transition type
* @param storagePolicyStatus the storage policy status
*
* @return the newly created storage policy create request
*/
public StoragePolicyUpdateRequest createStoragePolicyUpdateRequest(String storagePolicyRuleType, Integer storagePolicyRuleValue, String businessObjectDefinitionNamespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, String storageName, String storagePolicyTransitionType, String storagePolicyStatus) {
StoragePolicyUpdateRequest request = new StoragePolicyUpdateRequest();
StoragePolicyRule storagePolicyRule = new StoragePolicyRule();
request.setStoragePolicyRule(storagePolicyRule);
storagePolicyRule.setRuleType(storagePolicyRuleType);
storagePolicyRule.setRuleValue(storagePolicyRuleValue);
StoragePolicyFilter storagePolicyFilter = new StoragePolicyFilter();
request.setStoragePolicyFilter(storagePolicyFilter);
storagePolicyFilter.setNamespace(businessObjectDefinitionNamespace);
storagePolicyFilter.setBusinessObjectDefinitionName(businessObjectDefinitionName);
storagePolicyFilter.setBusinessObjectFormatUsage(businessObjectFormatUsage);
storagePolicyFilter.setBusinessObjectFormatFileType(businessObjectFormatFileType);
storagePolicyFilter.setStorageName(storageName);
StoragePolicyTransition storagePolicyTransition = new StoragePolicyTransition();
request.setStoragePolicyTransition(storagePolicyTransition);
storagePolicyTransition.setTransitionType(storagePolicyTransitionType);
request.setStatus(storagePolicyStatus);
return request;
}
use of org.finra.herd.model.api.xml.StoragePolicyUpdateRequest 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.StoragePolicyUpdateRequest in project herd by FINRAOS.
the class StoragePolicyServiceTest method testUpdateStoragePolicyStoragePolicyFilterStoragePathPrefixValidationNotEnabled.
@Test
public void testUpdateStoragePolicyStoragePolicyFilterStoragePathPrefixValidationNotEnabled() {
// 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, but without the S3 path prefix validation option configured.
storageDaoTestHelper.createStorageEntity(STORAGE_NAME_5, StoragePlatformEntity.S3, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME);
// Try to update a storage policy when storage policy filter storage has no S3 path prefix 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 path prefix validation enabled.");
} catch (IllegalStateException e) {
assertEquals(String.format("Path prefix validation must be enabled on \"%s\" storage.", request.getStoragePolicyFilter().getStorageName()), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.StoragePolicyUpdateRequest in project herd by FINRAOS.
the class StoragePolicyServiceTest method testUpdateStoragePolicyStoragePolicyFilterStorageInvalidStoragePlatform.
@Test
public void testUpdateStoragePolicyStoragePolicyFilterStorageInvalidStoragePlatform() {
// 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 a non-S3 storage.
storageDaoTestHelper.createStorageEntity(STORAGE_NAME_3, STORAGE_PLATFORM_CODE);
// 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);
// Try to update a storage policy using storage of a non-S3 storage platform type.
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_3, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.DISABLED);
try {
storagePolicyService.updateStoragePolicy(storagePolicyKey, request);
fail("Should throw an IllegalArgumentException when using non-S3 storage platform for storage policy filter storage.");
} catch (IllegalArgumentException e) {
assertEquals(String.format("Storage platform for storage with name \"%s\" is not \"%s\".", request.getStoragePolicyFilter().getStorageName(), StoragePlatformEntity.S3), e.getMessage());
}
}
Aggregations