Search in sources :

Example 16 with VmStatic

use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.

the class LabelDaoTest method testCreateAndGetWithVM.

@Test
public void testCreateAndGetWithVM() {
    Guid guid = Guid.newGuid();
    VmStatic vm = createAndSaveVm();
    Label label = new LabelBuilder().name("test label").id(guid).vm(vm.getId()).build();
    labelDao.save(label);
    Label read = labelDao.get(guid);
    assertNotNull(read);
    assertEquals(guid, read.getId());
    assertEquals(label.getName(), read.getName());
    assertNotNull(read.getVms());
    assertEquals(1, read.getVms().size());
    assertEquals(0, read.getHosts().size());
    assertEquals(vm.getId(), read.getVms().iterator().next());
}
Also used : Label(org.ovirt.engine.core.common.businessentities.Label) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 17 with VmStatic

use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.

the class LabelDaoTest method testCreateAndGetByReferencedId.

@Test
public void testCreateAndGetByReferencedId() {
    Label label = new LabelBuilder().name("test label").id(Guid.newGuid()).entity(host).build();
    labelDao.save(label);
    VmStatic vm = createAndSaveVm();
    label = new LabelBuilder().name("test label 2").id(Guid.newGuid()).entity(vm).build();
    labelDao.save(label);
    VmStatic vm2 = createAndSaveVm();
    label = new LabelBuilder().name("test label not in result").id(Guid.newGuid()).entity(vm2).build();
    labelDao.save(label);
    List<Label> read = labelDao.getAllByEntityIds(Lists.newArrayList(host.getId(), vm.getId(), Guid.newGuid()));
    assertNotNull(read);
    assertEquals(2, read.size());
}
Also used : Label(org.ovirt.engine.core.common.businessentities.Label) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Test(org.junit.Test)

Example 18 with VmStatic

use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.

the class LabelDaoTest method testUpdateLabelsForVm.

@Test
public void testUpdateLabelsForVm() {
    VmStatic vm = createAndSaveVm();
    Label label = createAndSaveLabel("test_label");
    labelDao.addVmToLabels(vm.getId(), Lists.newArrayList(label.getId()));
    Label label2 = createAndSaveLabel("test_label_2");
    labelDao.updateLabelsForVm(vm.getId(), Lists.newArrayList(label2.getId()));
    List<Label> assignedLabels = labelDao.getAllByEntityIds(Lists.newArrayList(vm.getId()));
    assertNotNull(assignedLabels);
    assertEquals(Lists.newArrayList(label2), assignedLabels);
}
Also used : Label(org.ovirt.engine.core.common.businessentities.Label) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Test(org.junit.Test)

Example 19 with VmStatic

use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.

the class LabelDaoTest method testRemoveLabelFromVm.

@Test
public void testRemoveLabelFromVm() {
    Label label = createAndSaveLabel("test_label");
    Label label2 = createAndSaveLabel("test_label_2");
    VmStatic vm = createAndSaveVm();
    List<Label> labelsToAssign = Lists.newArrayList(label, label2);
    List<Guid> guidsForLabelsToAssign = labelsToAssign.stream().map(Label::getId).collect(Collectors.toList());
    labelDao.addVmToLabels(vm.getId(), guidsForLabelsToAssign);
    guidsForLabelsToAssign.remove(label2.getId());
    labelDao.updateLabelsForVm(vm.getId(), guidsForLabelsToAssign);
    List<Label> labelsForVm = labelDao.getAllByEntityIds(Lists.newArrayList(vm.getId()));
    assertTrue(labelsForVm.size() == 1);
    assertEquals(label, labelsForVm.get(0));
}
Also used : Label(org.ovirt.engine.core.common.businessentities.Label) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 20 with VmStatic

use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.

the class BackendTemplatesResourceTest method setUpVm.

protected org.ovirt.engine.core.common.businessentities.VM setUpVm(Guid id) {
    VmStatic vmStatic = mock(VmStatic.class);
    when(vmStatic.getId()).thenReturn(id);
    org.ovirt.engine.core.common.businessentities.VM vm = mock(org.ovirt.engine.core.common.businessentities.VM.class);
    when(vm.getId()).thenReturn(id);
    when(vm.getStaticData()).thenReturn(vmStatic);
    return vm;
}
Also used : VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Aggregations

VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)87 Test (org.junit.Test)26 Guid (org.ovirt.engine.core.compat.Guid)15 VM (org.ovirt.engine.core.common.businessentities.VM)11 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)9 VmDynamic (org.ovirt.engine.core.common.businessentities.VmDynamic)8 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)8 Label (org.ovirt.engine.core.common.businessentities.Label)7 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Response (javax.ws.rs.core.Response)4 AddVmTemplateParameters (org.ovirt.engine.core.common.action.AddVmTemplateParameters)4 LabelBuilder (org.ovirt.engine.core.common.businessentities.LabelBuilder)4 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)4 VmStatistics (org.ovirt.engine.core.common.businessentities.VmStatistics)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 PostConstruct (javax.annotation.PostConstruct)3 Before (org.junit.Before)3