Search in sources :

Example 51 with Template

use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.

the class BackendTemplatesResourceTest method testAddSetAndUploadIconFailure.

@Test
public void testAddSetAndUploadIconFailure() throws Exception {
    final Template restModel = getRestModel(0);
    restModel.setLargeIcon(IconTestHelpler.createIconWithData());
    restModel.setSmallIcon(IconTestHelpler.createIcon(GUIDS[2]));
    try {
        collection.add(restModel);
        fail("expected WebApplicationException");
    } catch (WebApplicationException wae) {
        verifyFault(wae, BAD_REQUEST);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Test(org.junit.Test)

Example 52 with Template

use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.

the class BackendTemplatesResourceTest method getModel.

static Template getModel(int index) {
    Template model = new Template();
    model.setName(NAMES[index]);
    model.setDescription(DESCRIPTIONS[index]);
    model.setVm(new Vm());
    model.getVm().setId(GUIDS[1].toString());
    model.setCluster(new org.ovirt.engine.api.model.Cluster());
    model.getCluster().setId(GUIDS[2].toString());
    if (index == 2) {
        populateVersion(model);
    }
    return model;
}
Also used : Vm(org.ovirt.engine.api.model.Vm) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 53 with Template

use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.

the class BackendTemplatesResourceTest method doTestAddAsync.

private void doTestAddAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus creationStatus) throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpGetGraphicsExpectations(1);
    setUpGetConsoleExpectations(0, 1);
    setUpGetVirtioScsiExpectations(0);
    setUpGetSoundcardExpectations(0, 1);
    setUpGetRngDeviceExpectations(0);
    setUpGetBallooningExpectations(new Integer[] { 0 });
    setUpGetEntityExpectations(QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[1] }, setUpVm(GUIDS[1]));
    setUpCreationExpectations(ActionType.AddVmTemplate, AddVmTemplateParameters.class, new String[] { "Name", "Description" }, new Object[] { NAMES[0], DESCRIPTIONS[0] }, true, true, GUIDS[0], asList(GUIDS[2]), asList(new AsyncTaskStatus(asyncStatus)), QueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    Response response = collection.add(getModel(0));
    assertEquals(202, response.getStatus());
    assertTrue(response.getEntity() instanceof Template);
    verifyModel((Template) response.getEntity(), 0);
    Template created = (Template) response.getEntity();
    assertNotNull(created.getCreationStatus());
    assertEquals(creationStatus.value(), created.getCreationStatus());
}
Also used : Response(javax.ws.rs.core.Response) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 54 with Template

use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.

the class BackendTemplatesResourceTest method testAddIncompleteParameters.

@Test
public void testAddIncompleteParameters() throws Exception {
    Template model = new Template();
    model.setName(NAMES[0]);
    setUriInfo(setUpBasicUriExpectations());
    try {
        collection.add(model);
        fail("expected WebApplicationException on incomplete parameters");
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Template", "add", "vm.id|name");
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Test(org.junit.Test)

Example 55 with Template

use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.

the class BackendTemplatesResourceTest method testAddUseExistingIcons.

@Test
public void testAddUseExistingIcons() throws Exception {
    setUpGetGraphicsExpectations(1);
    setUpGetConsoleExpectations(0, 0, 1);
    setUpGetSoundcardExpectations(1);
    setUpGetBallooningExpectations(0, 0);
    setUpGetEntityExpectations(QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[1] }, setUpVm(GUIDS[1]));
    setUpAddExpectations();
    setUpCreationExpectations(ActionType.AddVmTemplate, AddVmTemplateParameters.class, new String[] { "Name", "Description" }, new Object[] { NAMES[0], DESCRIPTIONS[0] }, true, true, GUIDS[0], asList(GUIDS[2]), asList(new AsyncTaskStatus(AsyncTaskStatusEnum.finished)), QueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    final Template restModel = getRestModel(0);
    restModel.setSmallIcon(IconTestHelpler.createIcon(GUIDS[2]));
    restModel.setLargeIcon(IconTestHelpler.createIcon(GUIDS[3]));
    Response response = doAdd(restModel);
    assertEquals(201, response.getStatus());
    verifyModel((Template) response.getEntity(), 0);
    assertNull(((Template) response.getEntity()).getCreationStatus());
}
Also used : Response(javax.ws.rs.core.Response) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Test(org.junit.Test)

Aggregations

Template (org.ovirt.engine.api.model.Template)57 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)32 Test (org.junit.Test)21 Response (javax.ws.rs.core.Response)16 AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)12 Vm (org.ovirt.engine.api.model.Vm)11 WebApplicationException (javax.ws.rs.WebApplicationException)6 VmPool (org.ovirt.engine.api.model.VmPool)4 Cluster (org.ovirt.engine.api.model.Cluster)3 InstanceType (org.ovirt.engine.api.model.InstanceType)3 TimeZone (org.ovirt.engine.api.model.TimeZone)3 GetVmTemplateParameters (org.ovirt.engine.core.common.queries.GetVmTemplateParameters)3 ArrayList (java.util.ArrayList)2 Boot (org.ovirt.engine.api.model.Boot)2 Host (org.ovirt.engine.api.model.Host)2 OperatingSystem (org.ovirt.engine.api.model.OperatingSystem)2 StorageDomain (org.ovirt.engine.api.model.StorageDomain)2 Tag (org.ovirt.engine.api.model.Tag)2 TemplateVersion (org.ovirt.engine.api.model.TemplateVersion)2 Templates (org.ovirt.engine.api.model.Templates)2