use of org.finra.herd.model.api.xml.StorageKey in project herd by FINRAOS.
the class StorageServiceTest method testUpdateStorageAttributesStorageHasDuplicateAttributes.
@Test
public void testUpdateStorageAttributesStorageHasDuplicateAttributes() {
// Create and persist a valid storage.
StorageCreateRequest request = getNewStorageCreateRequest();
Storage storage = storageService.createStorage(request);
// Add a duplicate attribute to the storage.
StorageEntity storageEntity = storageDao.getStorageByName(storage.getName());
StorageAttributeEntity storageAttributeEntity = new StorageAttributeEntity();
storageAttributeEntity.setStorage(storageEntity);
storageAttributeEntity.setName(request.getAttributes().get(0).getName().toUpperCase());
storageEntity.getAttributes().add(storageAttributeEntity);
storageDao.saveAndRefresh(storageEntity);
// Try to update attributes for the storage.
try {
storageService.updateStorageAttributes(new StorageKey(storage.getName()), new StorageAttributesUpdateRequest(businessObjectDefinitionServiceTestHelper.getNewAttributes2()));
} catch (IllegalStateException e) {
assertEquals(String.format("Found duplicate attribute with name \"%s\" for \"%s\" storage.", request.getAttributes().get(0).getName().toLowerCase(), storage.getName()), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.StorageKey in project herd by FINRAOS.
the class StorageDaoImpl method getAllStorage.
@Override
public List<StorageKey> getAllStorage() {
// Create the criteria builder and a tuple style criteria query.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<String> criteria = builder.createQuery(String.class);
// The criteria root is the storage.
Root<StorageEntity> storageEntity = criteria.from(StorageEntity.class);
// Get the columns.
Path<String> storageNameColumn = storageEntity.get(StorageEntity_.name);
// Add the select clause.
criteria.select(storageNameColumn);
// Add the order by clause.
criteria.orderBy(builder.asc(storageNameColumn));
// Run the query to get a list of storage names back.
List<String> storageNames = entityManager.createQuery(criteria).getResultList();
// Populate the "keys" objects from the returned storage names.
List<StorageKey> storageKeys = new ArrayList<>();
for (String storageName : storageNames) {
storageKeys.add(new StorageKey(storageName));
}
return storageKeys;
}
use of org.finra.herd.model.api.xml.StorageKey in project herd by FINRAOS.
the class StorageRestControllerTest method testDeleteStorage.
@Test
public void testDeleteStorage() {
// Create a storage key.
StorageKey storageKey = new StorageKey(STORAGE_NAME);
// Create a storage.
Storage storage = new Storage(STORAGE_NAME, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES);
// Mock the external calls.
when(storageService.deleteStorage(storageKey)).thenReturn(storage);
// Call the method under test.
Storage result = storageRestController.deleteStorage(STORAGE_NAME);
// Verify the external calls.
verify(storageService).deleteStorage(storageKey);
verifyNoMoreInteractions(storageService);
// Validate the returned object.
assertEquals(storage, result);
}
use of org.finra.herd.model.api.xml.StorageKey in project herd by FINRAOS.
the class StorageRestControllerTest method testUpdateStorage.
@Test
public void testUpdateStorage() {
// Create a storage key.
StorageKey storageKey = new StorageKey(STORAGE_NAME);
// Create a storage update request.
StorageUpdateRequest storageUpdateRequest = new StorageUpdateRequest();
// Create a storage.
Storage storage = new Storage(STORAGE_NAME, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES);
// Mock the external calls.
when(storageService.updateStorage(storageKey, storageUpdateRequest)).thenReturn(storage);
// Call the method under test.
Storage result = storageRestController.updateStorage(STORAGE_NAME, storageUpdateRequest);
// Verify the external calls.
verify(storageService).updateStorage(storageKey, storageUpdateRequest);
verifyNoMoreInteractions(storageService);
// Validate the returned object.
assertEquals(storage, result);
}
use of org.finra.herd.model.api.xml.StorageKey in project herd by FINRAOS.
the class StorageServiceTest method testUpdateStorageAttributesStorageNoExists.
@Test
public void testUpdateStorageAttributesStorageNoExists() {
// Try to update attributes for a storage that doesn't yet exist.
try {
storageService.updateStorageAttributes(new StorageKey(INVALID_VALUE), new StorageAttributesUpdateRequest(businessObjectDefinitionServiceTestHelper.getNewAttributes()));
fail();
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Storage with name \"%s\" doesn't exist.", INVALID_VALUE), e.getMessage());
}
}
Aggregations