use of org.finra.herd.model.api.xml.StoragePolicyKey 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());
}
}
use of org.finra.herd.model.api.xml.StoragePolicyKey in project herd by FINRAOS.
the class StoragePolicyServiceTest method testUpdateStoragePolicyLowerCaseParameters.
@Test
public void testUpdateStoragePolicyLowerCaseParameters() {
// 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.
StoragePolicyEntity storagePolicyEntity = 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);
// Update a storage policy using lower case input parameters.
StoragePolicy resultStoragePolicy = storagePolicyService.updateStoragePolicy(new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD.toLowerCase(), STORAGE_POLICY_NAME.toLowerCase()), storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(STORAGE_POLICY_RULE_TYPE.toLowerCase(), STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), STORAGE_NAME.toLowerCase(), STORAGE_POLICY_TRANSITION_TYPE.toLowerCase(), StoragePolicyStatusEntity.DISABLED.toLowerCase()));
// Validate the returned object.
assertEquals(new StoragePolicy(resultStoragePolicy.getId(), new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME), new StoragePolicyRule(STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE), new StoragePolicyFilter(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE, STORAGE_NAME), new StoragePolicyTransition(STORAGE_POLICY_TRANSITION_TYPE), StoragePolicyStatusEntity.DISABLED), resultStoragePolicy);
assertTrue(resultStoragePolicy.getId() > storagePolicyEntity.getId());
}
use of org.finra.herd.model.api.xml.StoragePolicyKey in project herd by FINRAOS.
the class StoragePolicyServiceTest method testGetStoragePolicyUpperCaseParameters.
@Test
public void testGetStoragePolicyUpperCaseParameters() {
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
// Create and persist a storage policy entity.
StoragePolicyEntity storagePolicyEntity = 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);
// Retrieve the storage policy using upper case input parameters.
StoragePolicy resultStoragePolicy = storagePolicyService.getStoragePolicy(new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD.toUpperCase(), STORAGE_POLICY_NAME.toUpperCase()));
// Validate the returned object.
assertEquals(new StoragePolicy(storagePolicyEntity.getId(), 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), resultStoragePolicy);
}
use of org.finra.herd.model.api.xml.StoragePolicyKey in project herd by FINRAOS.
the class StoragePolicyServiceTest method testGetStoragePolicyNoExists.
@Test
public void testGetStoragePolicyNoExists() {
// Try to retrieve a non-existing storage policy.
try {
storagePolicyService.getStoragePolicy(new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME));
fail("Should throw an ObjectNotFoundException when trying to retrieve a non-existing storage policy.");
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Storage policy with name \"%s\" does not exist for \"%s\" namespace.", STORAGE_POLICY_NAME, STORAGE_POLICY_NAMESPACE_CD), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.StoragePolicyKey in project herd by FINRAOS.
the class StoragePolicyServiceTest method testCreateStoragePolicyAlreadyExists.
@Test
public void testCreateStoragePolicyAlreadyExists() {
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
// 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);
// Try to create a storage policy when it already exists.
try {
storagePolicyService.createStoragePolicy(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));
fail("Should throw an AlreadyExistsException when storage policy already exists.");
} catch (AlreadyExistsException e) {
assertEquals(String.format("Unable to create storage policy with name \"%s\" because it already exists for namespace \"%s\".", storagePolicyKey.getStoragePolicyName(), storagePolicyKey.getNamespace()), e.getMessage());
}
}
Aggregations