Search in sources :

Example 6 with StoragePolicyUpdateRequest

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

the class StoragePolicyServiceTest method testUpdateStoragePolicyStoragePolicyFilterStorageBucketNameNotConfigured.

@Test
public void testUpdateStoragePolicyStoragePolicyFilterStorageBucketNameNotConfigured() {
    // 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 without any attributes.
    storageDaoTestHelper.createStorageEntity(STORAGE_NAME_5, StoragePlatformEntity.S3);
    // Try to update a storage policy when storage policy filter storage has no S3 bucket name attribute configured.
    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 bucket name attribute configured.");
    } catch (IllegalStateException e) {
        assertEquals(String.format("Attribute \"%s\" for \"%s\" storage must be configured.", configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), request.getStoragePolicyFilter().getStorageName()), e.getMessage());
    }
}
Also used : StoragePolicyUpdateRequest(org.finra.herd.model.api.xml.StoragePolicyUpdateRequest) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) Test(org.junit.Test)

Example 7 with StoragePolicyUpdateRequest

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

the class StoragePolicyServiceTest method testUpdateStoragePolicyInvalidParameters.

@Test
public void testUpdateStoragePolicyInvalidParameters() {
    // 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, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED, INITIAL_VERSION, LATEST_VERSION_FLAG_SET);
    StoragePolicyUpdateRequest request;
    // Try to update a storage policy using non-existing storage policy rule type.
    request = storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest("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.DISABLED);
    try {
        storagePolicyService.updateStoragePolicy(storagePolicyKey, 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 update a storage policy using a negative storage policy rule value.
    try {
        storagePolicyService.updateStoragePolicy(storagePolicyKey, storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(STORAGE_POLICY_RULE_TYPE, -1, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.DISABLED));
        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 update a storage policy using non-existing business object definition namespace.
    request = storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(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.DISABLED);
    try {
        storagePolicyService.updateStoragePolicy(storagePolicyKey, 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 update a storage policy using non-existing business object definition name.
    request = storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(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.DISABLED);
    try {
        storagePolicyService.updateStoragePolicy(storagePolicyKey, 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 update a storage policy using non-existing business object format file type.
    request = storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(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.DISABLED);
    try {
        storagePolicyService.updateStoragePolicy(storagePolicyKey, 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 update a storage policy using non-existing storage name.
    request = storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(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.DISABLED);
    try {
        storagePolicyService.updateStoragePolicy(storagePolicyKey, 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 update a storage policy using non-existing storage policy transition type.
    request = storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(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.DISABLED);
    try {
        storagePolicyService.updateStoragePolicy(storagePolicyKey, 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 update a storage policy using non-existing storage policy status.
    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, "I_DO_NOT_EXIST");
    try {
        storagePolicyService.updateStoragePolicy(storagePolicyKey, 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 : StoragePolicyUpdateRequest(org.finra.herd.model.api.xml.StoragePolicyUpdateRequest) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test)

Aggregations

StoragePolicyUpdateRequest (org.finra.herd.model.api.xml.StoragePolicyUpdateRequest)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