Search in sources :

Example 11 with StorageKey

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());
    }
}
Also used : Storage(org.finra.herd.model.api.xml.Storage) StorageAttributeEntity(org.finra.herd.model.jpa.StorageAttributeEntity) StorageAttributesUpdateRequest(org.finra.herd.model.api.xml.StorageAttributesUpdateRequest) StorageEntity(org.finra.herd.model.jpa.StorageEntity) StorageCreateRequest(org.finra.herd.model.api.xml.StorageCreateRequest) StorageKey(org.finra.herd.model.api.xml.StorageKey) Test(org.junit.Test)

Example 12 with StorageKey

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) StorageKey(org.finra.herd.model.api.xml.StorageKey)

Example 13 with StorageKey

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);
}
Also used : Storage(org.finra.herd.model.api.xml.Storage) StorageKey(org.finra.herd.model.api.xml.StorageKey) Test(org.junit.Test)

Example 14 with StorageKey

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);
}
Also used : Storage(org.finra.herd.model.api.xml.Storage) StorageUpdateRequest(org.finra.herd.model.api.xml.StorageUpdateRequest) StorageKey(org.finra.herd.model.api.xml.StorageKey) Test(org.junit.Test)

Example 15 with StorageKey

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());
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) StorageAttributesUpdateRequest(org.finra.herd.model.api.xml.StorageAttributesUpdateRequest) StorageKey(org.finra.herd.model.api.xml.StorageKey) Test(org.junit.Test)

Aggregations

StorageKey (org.finra.herd.model.api.xml.StorageKey)19 Test (org.junit.Test)18 Storage (org.finra.herd.model.api.xml.Storage)10 StorageAttributesUpdateRequest (org.finra.herd.model.api.xml.StorageAttributesUpdateRequest)5 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)4 StorageCreateRequest (org.finra.herd.model.api.xml.StorageCreateRequest)3 StorageUpdateRequest (org.finra.herd.model.api.xml.StorageUpdateRequest)3 StorageKeys (org.finra.herd.model.api.xml.StorageKeys)2 StorageEntity (org.finra.herd.model.jpa.StorageEntity)2 ArrayList (java.util.ArrayList)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Command (org.finra.herd.core.Command)1 StorageAttributeEntity (org.finra.herd.model.jpa.StorageAttributeEntity)1 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)1 Ignore (org.junit.Ignore)1