use of org.finra.herd.model.api.xml.StoragePolicy in project herd by FINRAOS.
the class StoragePolicyServiceImpl method createStoragePolicyFromEntity.
/**
* Creates the storage policy registration from the persisted entity.
*
* @param storagePolicyEntity the storage policy registration entity
*
* @return the storage policy registration
*/
private StoragePolicy createStoragePolicyFromEntity(StoragePolicyEntity storagePolicyEntity) {
StoragePolicy storagePolicy = new StoragePolicy();
storagePolicy.setId(storagePolicyEntity.getId());
StoragePolicyKey storagePolicyKey = new StoragePolicyKey();
storagePolicy.setStoragePolicyKey(storagePolicyKey);
storagePolicyKey.setNamespace(storagePolicyEntity.getNamespace().getCode());
storagePolicyKey.setStoragePolicyName(storagePolicyEntity.getName());
StoragePolicyRule storagePolicyRule = new StoragePolicyRule();
storagePolicy.setStoragePolicyRule(storagePolicyRule);
storagePolicyRule.setRuleType(storagePolicyEntity.getStoragePolicyRuleType().getCode());
storagePolicyRule.setRuleValue(storagePolicyEntity.getStoragePolicyRuleValue());
StoragePolicyFilter storagePolicyFilter = new StoragePolicyFilter();
storagePolicy.setStoragePolicyFilter(storagePolicyFilter);
storagePolicyFilter.setNamespace(storagePolicyEntity.getBusinessObjectDefinition() != null ? storagePolicyEntity.getBusinessObjectDefinition().getNamespace().getCode() : null);
storagePolicyFilter.setBusinessObjectDefinitionName(storagePolicyEntity.getBusinessObjectDefinition() != null ? storagePolicyEntity.getBusinessObjectDefinition().getName() : null);
storagePolicyFilter.setBusinessObjectFormatUsage(storagePolicyEntity.getUsage());
storagePolicyFilter.setBusinessObjectFormatFileType(storagePolicyEntity.getFileType() != null ? storagePolicyEntity.getFileType().getCode() : null);
storagePolicyFilter.setStorageName(storagePolicyEntity.getStorage().getName());
StoragePolicyTransition storagePolicyTransition = new StoragePolicyTransition();
storagePolicy.setStoragePolicyTransition(storagePolicyTransition);
storagePolicyTransition.setTransitionType(storagePolicyEntity.getStoragePolicyTransitionType().getCode());
storagePolicy.setStatus(storagePolicyEntity.getStatus().getCode());
return storagePolicy;
}
use of org.finra.herd.model.api.xml.StoragePolicy in project herd by FINRAOS.
the class StoragePolicyRestControllerTest method testGetStoragePolicy.
@Test
public void testGetStoragePolicy() {
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);
when(storagePolicyService.getStoragePolicy(storagePolicyKey)).thenReturn(storagePolicy);
StoragePolicy resultStoragePolicy = storagePolicyRestController.getStoragePolicy(storagePolicyKey.getNamespace(), storagePolicyKey.getStoragePolicyName());
// Verify the external calls.
verify(storagePolicyService).getStoragePolicy(storagePolicyKey);
verifyNoMoreInteractions(storagePolicyService);
// Validate the returned object.
assertEquals(storagePolicy, resultStoragePolicy);
}
use of org.finra.herd.model.api.xml.StoragePolicy 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.StoragePolicy in project herd by FINRAOS.
the class StoragePolicyServiceTest method testUpdateStoragePolicyMissingOptionalParametersPassedAsWhitespace.
@Test
public void testUpdateStoragePolicyMissingOptionalParametersPassedAsWhitespace() {
// 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 without specifying any of the optional parameters (passing them as whitespace characters).
StoragePolicy resultStoragePolicy = storagePolicyService.updateStoragePolicy(storagePolicyKey, storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BLANK_TEXT, BLANK_TEXT, BLANK_TEXT, BLANK_TEXT, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.DISABLED));
// 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.DISABLED), resultStoragePolicy);
assertTrue(resultStoragePolicy.getId() > storagePolicyEntity.getId());
}
use of org.finra.herd.model.api.xml.StoragePolicy in project herd by FINRAOS.
the class StoragePolicyServiceTest method testCreateStoragePolicy.
// Unit tests for createStoragePolicy().
@Test
public void testCreateStoragePolicy() {
// 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.
StoragePolicy resultStoragePolicy = 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));
// Validate the returned object.
assertEquals(new StoragePolicy(resultStoragePolicy.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);
}
Aggregations