Search in sources :

Example 1 with VirtualMachine

use of com.emc.storageos.db.client.model.uimodels.VirtualMachine in project coprhd-controller by CoprHD.

the class VirtualMachineTest method testFindByDatacenter.

@Test
public void testFindByDatacenter() throws Exception {
    _logger.info("Starting findByDatacenter test");
    ModelClient modelClient = getModelClient();
    Vcenter v2 = createVCenterWithLabel("v2");
    modelClient.save(v2);
    VcenterDataCenter dc2 = createDatacenterWithLabel("dc2");
    dc2.setVcenter(v2.getId());
    modelClient.save(dc2);
    VirtualMachine vm1 = createWithLabel("vm1");
    vm1.setDatacenterId(new NamedURI(dc2.getId(), dc2.getLabel()));
    modelClient.save(vm1);
    VcenterDataCenter dc3 = createDatacenterWithLabel("dc3");
    dc3.setVcenter(v2.getId());
    modelClient.save(dc3);
    VirtualMachine vm2 = createWithLabel("vm2");
    vm2.setDatacenterId(new NamedURI(dc3.getId(), dc3.getLabel()));
    modelClient.save(vm2);
    VirtualMachine vm3 = createWithLabel("vm3");
    vm3.setDatacenterId(new NamedURI(dc3.getId(), dc3.getLabel()));
    modelClient.save(vm3);
    List<VirtualMachine> virtualMachines = modelClient.virtualMachines().findByDatacenter(dc2.getId());
    Assert.assertNotNull(virtualMachines);
    Assert.assertEquals(1, virtualMachines.size());
    virtualMachines = modelClient.virtualMachines().findByDatacenter(dc3.getId());
    Assert.assertNotNull(virtualMachines);
    Assert.assertEquals(2, virtualMachines.size());
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) NamedURI(com.emc.storageos.db.client.model.NamedURI) ModelClient(com.emc.sa.model.dao.ModelClient) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VirtualMachine(com.emc.storageos.db.client.model.uimodels.VirtualMachine) Test(org.junit.Test)

Example 2 with VirtualMachine

use of com.emc.storageos.db.client.model.uimodels.VirtualMachine in project coprhd-controller by CoprHD.

the class VirtualMachineTest method testPersistObject.

@Test
public void testPersistObject() throws Exception {
    _logger.info("Starting persist VirtualMachine test");
    ModelClient modelClient = getModelClient();
    VirtualMachine model = new VirtualMachine();
    model.setId(URIUtil.createId(VirtualMachine.class));
    model.setLabel("foo");
    model.setRunning(false);
    model.setTemplate(true);
    URI datacenterUri = URIUtil.createId(VcenterDataCenter.class);
    NamedURI datacenterId = new NamedURI(datacenterUri, "dc1");
    model.setDatacenterId(datacenterId);
    modelClient.save(model);
    model = modelClient.virtualMachines().findById(model.getId());
    Assert.assertNotNull(model);
    Assert.assertEquals("foo", model.getLabel());
    Assert.assertEquals(false, model.getRunning());
    Assert.assertEquals(true, model.getTemplate());
    Assert.assertEquals(datacenterId, model.getDatacenterId());
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) ModelClient(com.emc.sa.model.dao.ModelClient) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) VirtualMachine(com.emc.storageos.db.client.model.uimodels.VirtualMachine) Test(org.junit.Test)

Example 3 with VirtualMachine

use of com.emc.storageos.db.client.model.uimodels.VirtualMachine in project coprhd-controller by CoprHD.

the class VirtualMachineTest method createWithLabel.

private VirtualMachine createWithLabel(String label) {
    VirtualMachine model = new VirtualMachine();
    model.setId(URIUtil.createId(VirtualMachine.class));
    model.setLabel(label);
    model.setRunning(false);
    model.setTemplate(true);
    return model;
}
Also used : VirtualMachine(com.emc.storageos.db.client.model.uimodels.VirtualMachine)

Aggregations

VirtualMachine (com.emc.storageos.db.client.model.uimodels.VirtualMachine)3 ModelClient (com.emc.sa.model.dao.ModelClient)2 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 Test (org.junit.Test)2 Vcenter (com.emc.storageos.db.client.model.Vcenter)1 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)1 URI (java.net.URI)1