Search in sources :

Example 41 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class GetVmConfigurationBySnapshotQueryTest method testQuery.

@Test
public void testQuery() throws Exception {
    GetVmConfigurationBySnapshotQuery<IdQueryParameters> query = setupQueryBySnapshotId(existingSnapshotId);
    VM vm = new VM();
    doReturn(vm).when(snapshotVmConfigurationHelper).getVmFromConfiguration(any(), any(), any());
    query.execute();
    QueryReturnValue returnValue = query.getQueryReturnValue();
    assertNotNull("Return value from query cannot be null", returnValue);
    VM returnedVm = returnValue.getReturnValue();
    assertEquals(vm, returnedVm);
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VM(org.ovirt.engine.core.common.businessentities.VM) Test(org.junit.Test)

Example 42 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class GetVmsByStorageDomainQueryTest method testExecuteQueryCommandNoDisks.

@Test
public void testExecuteQueryCommandNoDisks() {
    List<VM> vmsOfDomain = new ArrayList<>();
    VM vm1 = mock(VM.class);
    VM vm2 = mock(VM.class);
    vmsOfDomain.add(vm1);
    vmsOfDomain.add(vm2);
    when(vmDao.getAllForStorageDomain(domainId)).thenReturn(vmsOfDomain);
    QueryReturnValue returnValue = new QueryReturnValue();
    returnValue.setSucceeded(true);
    List<DiskImage> diskImages = new ArrayList<>();
    returnValue.setReturnValue(diskImages);
    doReturn(returnValue).when(query).getAllDisksByStorageDomain(domainId);
    query.executeQueryCommand();
    List<VM> vms = query.getQueryReturnValue().getReturnValue();
    assertEquals(2, vms.size());
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 43 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class StorageDomainValidatorTest method invalidRunningVmsAndVmLeasesForBackupDomain.

@Test
public void invalidRunningVmsAndVmLeasesForBackupDomain() {
    QueryReturnValue ret = new QueryReturnValue();
    List<VmBase> vmLeases = new ArrayList<>();
    VM vmWithLease = new VM();
    vmWithLease.setName("firstVM");
    vmLeases.add(vmWithLease.getStaticData());
    ret.setReturnValue(vmLeases);
    ret.setSucceeded(true);
    // VM1
    VM vm1 = new VM();
    vm1.setName("firstVM");
    Map<Guid, Disk> attachedDisksForVm1 = new HashMap<>();
    DiskImage diskVm1 = new DiskImage();
    diskVm1.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
    diskVm1.setPlugged(true);
    attachedDisksForVm1.put(Guid.newGuid(), diskVm1);
    vm1.setDiskMap(attachedDisksForVm1);
    // VM2
    VM vm2 = new VM();
    vm2.setName("secondVM");
    Map<Guid, Disk> attachedDisksForVm2 = new HashMap<>();
    DiskImage diskVm2 = new DiskImage();
    diskVm2.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
    diskVm2.setPlugged(true);
    attachedDisksForVm2.put(Guid.newGuid(), diskVm2);
    vm2.setDiskMap(attachedDisksForVm2);
    List<VM> runningVMs = new ArrayList<>();
    runningVMs.add(vm1);
    runningVMs.add(vm2);
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(runningVMs);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), failsWith(EngineMessage.ACTION_TYPE_FAILED_RUNNING_VM_OR_VM_LEASES_PRESENT_ON_STORAGE_DOMAIN));
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 44 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class StorageDomainValidatorTest method validRunningVmsOrVmLeasesForBackupDomain.

@Test
public void validRunningVmsOrVmLeasesForBackupDomain() {
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(Collections.EMPTY_LIST);
    QueryReturnValue ret = new QueryReturnValue();
    ret.setReturnValue(new ArrayList<VmBase>());
    ret.setSucceeded(true);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), isValid());
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Test(org.junit.Test)

Example 45 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class StorageDomainValidatorTest method invalidVmLeasesQueryForBackupDomain.

@Test
public void invalidVmLeasesQueryForBackupDomain() {
    QueryReturnValue ret = new QueryReturnValue();
    ret.setSucceeded(false);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), failsWith(EngineMessage.ACTION_TYPE_FAILED_RETRIEVE_VMS_FOR_WITH_LEASES));
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) Test(org.junit.Test)

Aggregations

QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)265 ArrayList (java.util.ArrayList)123 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)97 QueryType (org.ovirt.engine.core.common.queries.QueryType)85 List (java.util.List)74 Guid (org.ovirt.engine.core.compat.Guid)66 Frontend (org.ovirt.engine.ui.frontend.Frontend)64 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)54 VM (org.ovirt.engine.core.common.businessentities.VM)49 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)47 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)42 HashMap (java.util.HashMap)40 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)39 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)39 Test (org.junit.Test)38 Collection (java.util.Collection)34 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)33 Map (java.util.Map)31 ActionType (org.ovirt.engine.core.common.action.ActionType)31 VDS (org.ovirt.engine.core.common.businessentities.VDS)31