Search in sources :

Example 16 with StorageKey

use of org.finra.herd.model.api.xml.StorageKey in project herd by FINRAOS.

the class StorageServiceTest method testGetStorageInvalidStorageName.

@Test
public void testGetStorageInvalidStorageName() {
    // Try getting a storage that doesn't exist.
    try {
        storageService.getStorage(new StorageKey(INVALID_VALUE));
        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) StorageKey(org.finra.herd.model.api.xml.StorageKey) Test(org.junit.Test)

Example 17 with StorageKey

use of org.finra.herd.model.api.xml.StorageKey in project herd by FINRAOS.

the class StorageServiceTest method testDeleteStorageInvalidName.

@Test
public void testDeleteStorageInvalidName() {
    // Try to delete a storage which doesn't exist.
    try {
        storageService.deleteStorage(new StorageKey(INVALID_VALUE));
        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) StorageKey(org.finra.herd.model.api.xml.StorageKey) Test(org.junit.Test)

Example 18 with StorageKey

use of org.finra.herd.model.api.xml.StorageKey in project herd by FINRAOS.

the class StorageServiceTest method testDeleteStorageConstraintViolation.

/*
     * This test is ignored because the constraint validation is a DB dependent feature. This method had inconsistent behavior between Oracle and PostgreSQL.
     * Oracle was throwing the error after each statement, whereas PostgreSQL would not because it by default raises error only when transaction is committed.
     *
     * Besides, this test case is not valid as a use case as normal transactions wouldn't delete after insert within same transaction.
     */
@Ignore
@Test(expected = PersistenceException.class)
public void testDeleteStorageConstraintViolation() throws Exception {
    // Create a storage unit entity that refers to a newly created storage.
    final StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
    executeWithoutLogging(SqlExceptionHelper.class, new Command() {

        @Override
        public void execute() {
            // Delete the storage which is invalid because there still exists a storage unit entity that references it.
            StorageKey alternateKey = new StorageKey(storageUnitEntity.getStorage().getName());
            storageService.deleteStorage(alternateKey);
        }
    });
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) Command(org.finra.herd.core.Command) StorageKey(org.finra.herd.model.api.xml.StorageKey) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with StorageKey

use of org.finra.herd.model.api.xml.StorageKey in project herd by FINRAOS.

the class StorageServiceTest method testGetAllStorage.

@Test
public void testGetAllStorage() {
    // Get a list of test storage keys.
    List<StorageKey> storageKeys = storageDaoTestHelper.getTestStorageKeys();
    // Create and persist test storage entities.
    for (StorageKey storageKey : storageKeys) {
        storageDaoTestHelper.createStorageEntity(storageKey.getStorageName());
    }
    // Retrieve a list of storage keys.
    StorageKeys result = storageService.getAllStorage();
    // Validate the results.
    assertNotNull(result);
    assertTrue(result.getStorageKeys().containsAll(storageKeys));
}
Also used : StorageKeys(org.finra.herd.model.api.xml.StorageKeys) 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