use of org.finra.herd.model.api.xml.StoragePolicyKey in project herd by FINRAOS.
the class StoragePolicyServiceTest method testCreateStoragePolicyTrimParameters.
@Test
public void testCreateStoragePolicyTrimParameters() {
// Create and persist the relative database entities.
storagePolicyServiceTestHelper.createDatabaseEntitiesForStoragePolicyTesting();
// Create a storage policy using input parameters with leading and trailing empty spaces.
StoragePolicy resultStoragePolicy = storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(new StoragePolicyKey(addWhitespace(STORAGE_POLICY_NAMESPACE_CD), addWhitespace(STORAGE_POLICY_NAME)), addWhitespace(STORAGE_POLICY_RULE_TYPE), STORAGE_POLICY_RULE_VALUE, addWhitespace(BDEF_NAMESPACE), addWhitespace(BDEF_NAME), addWhitespace(FORMAT_USAGE_CODE), addWhitespace(FORMAT_FILE_TYPE_CODE), addWhitespace(STORAGE_NAME), addWhitespace(STORAGE_POLICY_TRANSITION_TYPE), addWhitespace(StoragePolicyStatusEntity.ENABLED)));
// 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, 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 testGetStoragePolicy.
// Unit tests for getStoragePolicy().
@Test
public void testGetStoragePolicy() {
// 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.
StoragePolicy resultStoragePolicy = storagePolicyService.getStoragePolicy(storagePolicyKey);
// 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 testUpdateStoragePolicyNoExists.
@Test
public void testUpdateStoragePolicyNoExists() {
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
// Try to update a storage policy when it already exists.
try {
storagePolicyService.updateStoragePolicy(storagePolicyKey, 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));
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 testCreateStoragePolicyMissingRequiredParameters.
@Test
public void testCreateStoragePolicyMissingRequiredParameters() {
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
// Try to create a storage policy instance when storage policy namespace is not specified.
try {
storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(new StoragePolicyKey(BLANK_TEXT, 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 is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
// Try to create a storage policy instance when storage policy name is not specified.
try {
storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, BLANK_TEXT), STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, STORAGE_POLICY_NAMESPACE_CD, 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 is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A storage policy name must be specified.", e.getMessage());
}
// Try to create a storage policy instance when storage policy rule type is not specified.
try {
storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, BLANK_TEXT, 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 rule type is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A storage policy rule type must be specified.", e.getMessage());
}
// Try to create a storage policy instance when storage policy rule value is not specified.
try {
storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, null, 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 rule value is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A storage policy rule value must be specified.", e.getMessage());
}
// Try to create a storage policy instance when business object definition name is specified without business object definition namespace.
try {
storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BLANK_TEXT, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED));
fail("Should throw an IllegalArgumentException when business object definition name is specified without business object definition namespace.");
} catch (IllegalArgumentException e) {
assertEquals("Business object definition name and namespace must be specified together.", e.getMessage());
}
// Try to create a storage policy instance when business object definition namespace is specified without business object definition name.
try {
storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BLANK_TEXT, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED));
fail("Should throw an IllegalArgumentException when business object definition namespace is specified without business object definition name.");
} catch (IllegalArgumentException e) {
assertEquals("Business object definition name and namespace must be specified together.", e.getMessage());
}
// Try to create a storage policy instance when business object format file type is specified without business object format usage.
try {
storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, BLANK_TEXT, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED));
fail("Should throw an IllegalArgumentException when business object format file type is specified without business object format usage.");
} catch (IllegalArgumentException e) {
assertEquals("Business object format usage and file type must be specified together.", e.getMessage());
}
// Try to create a storage policy instance when business object format usage is specified without business object format file type.
try {
storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, BLANK_TEXT, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED));
fail("Should throw an IllegalArgumentException when business object format usage is specified without business object format file type.");
} catch (IllegalArgumentException e) {
assertEquals("Business object format usage and file type must be specified together.", e.getMessage());
}
// Try to create a storage policy instance when storage name is not specified.
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, BLANK_TEXT, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED));
fail("Should throw an IllegalArgumentException when storage name is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A storage name must be specified.", e.getMessage());
}
// Try to create a storage policy instance when storage policy transition type is not specified.
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, BLANK_TEXT, StoragePolicyStatusEntity.ENABLED));
fail("Should throw an IllegalArgumentException when storage policy transition type is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A storage policy transition type must be specified.", e.getMessage());
}
// Try to create a storage policy instance when storage policy status is not specified.
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, BLANK_TEXT));
fail("Should throw an IllegalArgumentException when storage policy status is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A storage policy status must be specified.", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.StoragePolicyKey in project herd by FINRAOS.
the class StoragePolicyServiceTest method testCreateStoragePolicyMissingOptionalParametersPassedAsNulls.
@Test
public void testCreateStoragePolicyMissingOptionalParametersPassedAsNulls() {
// 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 storage policy without specifying any of the optional parameters (passing them as null values).
StoragePolicy resultStoragePolicy = storagePolicyService.createStoragePolicy(storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, null, null, null, null, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED));
// Validate the returned object.
assertEquals(new StoragePolicy(resultStoragePolicy.getId(), storagePolicyKey, new StoragePolicyRule(STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE), new StoragePolicyFilter(null, null, null, null, STORAGE_NAME), new StoragePolicyTransition(STORAGE_POLICY_TRANSITION_TYPE), StoragePolicyStatusEntity.ENABLED), resultStoragePolicy);
}
Aggregations