use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class BackendVmsResourceTest method testClone.
@Test
public void testClone() throws Exception {
setUriInfo(addMatrixParameterExpectations(setUpBasicUriExpectations(), BackendVmsResource.CLONE, "true"));
setUpGetPayloadExpectations(1, 2);
setUpGetBallooningExpectations(1, 2);
setUpGetGraphicsExpectations(1);
setUpGetConsoleExpectations(1, 2);
setUpGetVmOvfExpectations(2);
setUpGetVirtioScsiExpectations(2);
setUpGetSoundcardExpectations(1, 2);
setUpGetRngDeviceExpectations(1, 2);
setUpGetCertuficateExpectations(1, 2);
setUpEntityQueryExpectations(QueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[] { "Id" }, new Object[] { GUIDS[1] }, getTemplateEntity(1));
setUpEntityQueryExpectations(QueryType.GetClusterById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getClusterEntity());
setUpCreationExpectations(ActionType.AddVmFromTemplate, AddVmParameters.class, new String[] { "StorageDomainId" }, new Object[] { GUIDS[0] }, true, true, GUIDS[2], QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getEntity(2));
Response response = collection.add(createModel(new DiskAttachments()));
assertEquals(201, response.getStatus());
assertTrue(response.getEntity() instanceof Vm);
verifyModel((Vm) response.getEntity(), 2);
}
use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class BackendVmsResourceTest method testAddFromConfigurationWithRegenerateTrue.
@Test
public void testAddFromConfigurationWithRegenerateTrue() throws Exception {
setUriInfo(setUpBasicUriExpectations());
setUpGetPayloadExpectations(1, 3);
setUpGetBallooningExpectations(1, 3);
setUpGetGraphicsExpectations(1);
setUpGetCertuficateExpectations(1, 3);
setUpGetConsoleExpectations(3);
setUpGetVmOvfExpectations(3);
setUpGetVirtioScsiExpectations(3);
setUpGetSoundcardExpectations(3);
setUpGetRngDeviceExpectations(3);
Vm model = createModel(null);
org.ovirt.engine.core.common.businessentities.VM returnedVM = getEntity(2);
model.setInitialization(new Initialization());
model.getInitialization().setRegenerateIds(Boolean.TRUE);
model.getInitialization().setConfiguration(new Configuration());
model.getInitialization().getConfiguration().setData("asdasdasd");
model.getInitialization().getConfiguration().setType(org.ovirt.engine.api.model.ConfigurationType.OVF);
setUpGetEntityExpectations(QueryType.GetVmFromConfiguration, GetVmFromConfigurationQueryParameters.class, new String[] { "VmConfiguration", "ConfigurationType" }, new Object[] { model.getInitialization().getConfiguration().getData(), ConfigurationType.OVF }, returnedVM);
Guid newId = GUIDS[3];
setUpCreationExpectations(ActionType.ImportVmFromConfiguration, ImportVmFromConfParameters.class, new String[] { "Vm", "ClusterId", "ImportAsNewEntity" }, new Object[] { returnedVM, Guid.createGuidFromString(model.getCluster().getId()), true }, true, true, newId, QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { newId }, getEntityWithProvidedId(2, newId));
Response response = collection.add(model);
assertEquals(201, response.getStatus());
assertTrue(response.getEntity() instanceof Vm);
Vm queriedVm = (Vm) response.getEntity();
assertEquals(newId.toString(), queriedVm.getId());
queriedVm.setId(GUIDS[2].toString());
verifyModel((Vm) response.getEntity(), 2);
}
use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class BackendVmsResourceTest method verifyCollection.
@Override
protected void verifyCollection(List<Vm> collection) throws Exception {
super.verifyCollection(collection);
List<String> populateHeader = httpHeaders.getRequestHeader(BackendResource.POPULATE);
boolean populated = populateHeader != null ? populateHeader.contains("true") : false;
for (Vm vm : collection) {
assertTrue(populated ? vm.isSetConsole() : !vm.isSetConsole());
}
}
use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class BackendVmsResourceTest method testListIncludeStatistics.
@Test
public void testListIncludeStatistics() throws Exception {
try {
accepts.add("application/xml; detail=statistics");
UriInfo uriInfo = setUpUriExpectations(null);
org.ovirt.engine.core.common.businessentities.VM vm = new org.ovirt.engine.core.common.businessentities.VM();
VmStatistics vmStatistics = new VmStatistics();
vmStatistics.setCpuSys(0D);
vmStatistics.setCpuUser(0D);
vmStatistics.setElapsedTime(0D);
vmStatistics.setUsageCpuPercent(0);
vmStatistics.setUsageMemPercent(0);
vmStatistics.setUsageNetworkPercent(0);
vm.setStatisticsData(vmStatistics);
vm.setMigrationProgressPercent(50);
for (int i = 0; i < GUIDS.length - 1; i++) {
setUpGetEntityExpectations(QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[i] }, vm);
}
setUpGetGraphicsMultipleExpectations(3);
setUpQueryExpectations("");
collection.setUriInfo(uriInfo);
List<Vm> vms = getCollection();
assertTrue(vms.get(0).isSetStatistics());
verifyCollection(vms);
} finally {
accepts.clear();
}
}
use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class BackendVmsResourceTest method testAddIncompleteParameters2.
@Test
public void testAddIncompleteParameters2() throws Exception {
Vm model = createModel(null);
model.setTemplate(null);
setUriInfo(setUpBasicUriExpectations());
try {
collection.add(model);
fail("expected WebApplicationException on incomplete parameters");
} catch (WebApplicationException wae) {
verifyIncompleteException(wae, "Vm", "add", "template.id|name");
}
}
Aggregations