package org.ovirt.engine.core.bll.validator.storage; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.ovirt.engine.core.bll.validator.ValidationResultMatchers.failsWith; import static org.ovirt.engine.core.bll.validator.ValidationResultMatchers.isValid; import org.junit.Before; import org.junit.Test; import org.ovirt.engine.core.common.businessentities.StoragePool; import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; import org.ovirt.engine.core.common.errors.EngineMessage; public class StoragePoolValidatorTest { private StoragePoolValidator validator; private StoragePool storagePool; @Before public void setup() { storagePool = new StoragePool(); storagePool.setStatus(StoragePoolStatus.Up); validator = spy(new StoragePoolValidator(storagePool)); } @Test public void testIsNotLocalFsWithDefaultCluster() { storagePool.setIsLocal(true); doReturn(false).when(validator).containsDefaultCluster(); assertThat(validator.isNotLocalfsWithDefaultCluster(), isValid()); } @Test public void testIsNotLocalFsWithDefaultClusterWhenClusterIsDefault() { storagePool.setIsLocal(true); doReturn(true).when(validator).containsDefaultCluster(); assertThat(validator.isNotLocalfsWithDefaultCluster(), failsWith(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_WITH_DEFAULT_CLUSTER_CANNOT_BE_LOCALFS)); } @Test public void testIsUpdValid() { assertThat("Storage pool should be up", validator.isUp(), isValid()); } @Test public void testIsUpdInvalid() { storagePool.setStatus(StoragePoolStatus.NonResponsive); assertThat(validator.isUp(), failsWith(EngineMessage.ACTION_TYPE_FAILED_IMAGE_REPOSITORY_NOT_FOUND)); } }