Search in sources :

Example 1 with StoragePolicyCreateRequest

use of org.finra.herd.model.api.xml.StoragePolicyCreateRequest in project herd by FINRAOS.

the class StoragePolicyServiceTestHelper method createStoragePolicyCreateRequest.

/**
 * Creates a storage policy create request.
 *
 * @param storagePolicyKey the storage policy key
 * @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 StoragePolicyCreateRequest createStoragePolicyCreateRequest(StoragePolicyKey storagePolicyKey, String storagePolicyRuleType, Integer storagePolicyRuleValue, String businessObjectDefinitionNamespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, String storageName, String storagePolicyTransitionType, String storagePolicyStatus) {
    StoragePolicyCreateRequest request = new StoragePolicyCreateRequest();
    request.setStoragePolicyKey(storagePolicyKey);
    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;
}
Also used : StoragePolicyRule(org.finra.herd.model.api.xml.StoragePolicyRule) StoragePolicyTransition(org.finra.herd.model.api.xml.StoragePolicyTransition) StoragePolicyFilter(org.finra.herd.model.api.xml.StoragePolicyFilter) StoragePolicyCreateRequest(org.finra.herd.model.api.xml.StoragePolicyCreateRequest)

Example 2 with StoragePolicyCreateRequest

use of org.finra.herd.model.api.xml.StoragePolicyCreateRequest in project herd by FINRAOS.

the class StoragePolicyServiceTest method testCreateStoragePolicyInvalidParameters.

@Test
public void testCreateStoragePolicyInvalidParameters() {
    // Create and persist the relative database entities.
    storagePolicyServiceTestHelper.createDatabaseEntitiesForStoragePolicyTesting();
    // Create a storage policy key.
    StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
    StoragePolicyCreateRequest request;
    // Try to create a storage policy using non-existing storage policy namespace.
    request = storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(new StoragePolicyKey("I_DO_NOT_EXIST", STORAGE_POLICY_NAME), 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.ENABLED);
    try {
        storagePolicyService.createStoragePolicy(request);
        fail("Should throw an ObjectNotFoundException when using non-existing storage policy namespace.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Namespace \"%s\" doesn't exist.", request.getStoragePolicyKey().getNamespace()), e.getMessage());
    }
    // Try to create a storage policy when storage policy namespace contains a forward slash character.
    try {
        storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(new StoragePolicyKey(addSlash(STORAGE_POLICY_NAMESPACE_CD), STORAGE_POLICY_NAME), 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.ENABLED));
        fail("Should throw an IllegalArgumentException when storage policy namespace contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("Namespace can not contain a forward slash character.", e.getMessage());
    }
    // Try to create a storage policy when storage policy name contains a forward slash character.
    try {
        storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, addSlash(STORAGE_POLICY_NAME)), 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.ENABLED));
        fail("Should throw an IllegalArgumentException when storage policy name contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("Storage policy name can not contain a forward slash character.", e.getMessage());
    }
    // Try to create a storage policy using non-existing storage policy rule type.
    request = storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, "I_DO_NOT_EXIST", STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED);
    try {
        storagePolicyService.createStoragePolicy(request);
        fail("Should throw an ObjectNotFoundException when using non-existing storage policy rule type.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Storage policy rule type with code \"%s\" doesn't exist.", request.getStoragePolicyRule().getRuleType()), e.getMessage());
    }
    // Try to create a storage policy using a negative storage policy rule value.
    request = storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, -1, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED);
    try {
        storagePolicyService.createStoragePolicy(request);
        fail("Should throw an IllegalArgumentException when using a negative storage policy rule value.");
    } catch (IllegalArgumentException e) {
        assertEquals("Storage policy rule value must be a positive integer or zero.", e.getMessage());
    }
    // Try to create a storage policy using non-existing business object definition namespace.
    request = storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, "I_DO_NOT_EXIST", BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED);
    try {
        storagePolicyService.createStoragePolicy(request);
        fail("Should throw an ObjectNotFoundException when using non-existing business object definition namespace.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Business object definition with name \"%s\" doesn't exist for namespace \"%s\".", request.getStoragePolicyFilter().getBusinessObjectDefinitionName(), request.getStoragePolicyFilter().getNamespace()), e.getMessage());
    }
    // Try to create a storage policy using non-existing business object definition name.
    request = storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, "I_DO_NOT_EXIST", FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED);
    try {
        storagePolicyService.createStoragePolicy(request);
        fail("Should throw an ObjectNotFoundException when using non-existing business object definition name.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Business object definition with name \"%s\" doesn't exist for namespace \"%s\".", request.getStoragePolicyFilter().getBusinessObjectDefinitionName(), request.getStoragePolicyFilter().getNamespace()), e.getMessage());
    }
    // Try to create a storage policy using non-existing business object format file type.
    request = storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, "I_DO_NOT_EXIST", STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED);
    try {
        storagePolicyService.createStoragePolicy(request);
        fail("Should throw an ObjectNotFoundException when using non-existing business object format file type.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("File type with code \"%s\" doesn't exist.", request.getStoragePolicyFilter().getBusinessObjectFormatFileType()), e.getMessage());
    }
    // Try to create a storage policy using non-existing storage name.
    request = storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, "I_DO_NOT_EXIST", STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED);
    try {
        storagePolicyService.createStoragePolicy(request);
        fail("Should throw an ObjectNotFoundException when using non-existing storage name.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Storage with name \"%s\" doesn't exist.", request.getStoragePolicyFilter().getStorageName()), e.getMessage());
    }
    // Try to create a storage policy using non-existing destination storage name.
    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, I_DO_NOT_EXIST, StoragePolicyStatusEntity.ENABLED);
    try {
        storagePolicyService.createStoragePolicy(request);
        fail("Should throw an ObjectNotFoundException when using non-existing storage policy transition type.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Storage policy transition type with code \"%s\" doesn't exist.", request.getStoragePolicyTransition().getTransitionType()), e.getMessage());
    }
    // Try to create a storage policy using non-existing storage policy status.
    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, STORAGE_POLICY_TRANSITION_TYPE, "I_DO_NOT_EXIST");
    try {
        storagePolicyService.createStoragePolicy(request);
        fail("Should throw an ObjectNotFoundException when using non-existing storage policy status.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Storage policy status \"%s\" doesn't exist.", request.getStatus()), e.getMessage());
    }
}
Also used : StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) StoragePolicyCreateRequest(org.finra.herd.model.api.xml.StoragePolicyCreateRequest) Test(org.junit.Test)

Example 3 with StoragePolicyCreateRequest

use of org.finra.herd.model.api.xml.StoragePolicyCreateRequest 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());
    }
}
Also used : Attribute(org.finra.herd.model.api.xml.Attribute) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) ArrayList(java.util.ArrayList) StoragePolicyCreateRequest(org.finra.herd.model.api.xml.StoragePolicyCreateRequest) Test(org.junit.Test)

Example 4 with StoragePolicyCreateRequest

use of org.finra.herd.model.api.xml.StoragePolicyCreateRequest in project herd by FINRAOS.

the class StoragePolicyRestControllerTest method testCreateStoragePolicy.

@Test
public void testCreateStoragePolicy() {
    // 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);
    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, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED);
    when(storagePolicyService.createStoragePolicy(request)).thenReturn(storagePolicy);
    // Create a storage policy.
    StoragePolicy resultStoragePolicy = storagePolicyRestController.createStoragePolicy(request);
    // Verify the external calls.
    verify(storagePolicyService).createStoragePolicy(request);
    verifyNoMoreInteractions(storagePolicyService);
    // Validate the returned object.
    assertEquals(storagePolicy, resultStoragePolicy);
}
Also used : StoragePolicyRule(org.finra.herd.model.api.xml.StoragePolicyRule) StoragePolicyTransition(org.finra.herd.model.api.xml.StoragePolicyTransition) StoragePolicyFilter(org.finra.herd.model.api.xml.StoragePolicyFilter) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StoragePolicy(org.finra.herd.model.api.xml.StoragePolicy) StoragePolicyCreateRequest(org.finra.herd.model.api.xml.StoragePolicyCreateRequest) Test(org.junit.Test)

Example 5 with StoragePolicyCreateRequest

use of org.finra.herd.model.api.xml.StoragePolicyCreateRequest in project herd by FINRAOS.

the class StoragePolicyServiceTest method testCreateStoragePolicyStoragePolicyFilterStorageInvalidStoragePlatform.

@Test
public void testCreateStoragePolicyStoragePolicyFilterStorageInvalidStoragePlatform() {
    // 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);
    // Try to create a storage policy using storage of a non-S3 storage platform type.
    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 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());
    }
}
Also used : StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StoragePolicyCreateRequest(org.finra.herd.model.api.xml.StoragePolicyCreateRequest) Test(org.junit.Test)

Aggregations

StoragePolicyCreateRequest (org.finra.herd.model.api.xml.StoragePolicyCreateRequest)7 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)6 Test (org.junit.Test)6 StoragePolicyFilter (org.finra.herd.model.api.xml.StoragePolicyFilter)2 StoragePolicyRule (org.finra.herd.model.api.xml.StoragePolicyRule)2 StoragePolicyTransition (org.finra.herd.model.api.xml.StoragePolicyTransition)2 ArrayList (java.util.ArrayList)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 Attribute (org.finra.herd.model.api.xml.Attribute)1 StoragePolicy (org.finra.herd.model.api.xml.StoragePolicy)1