private Host setCluster(Host host, org.ovirt.engine.api.model.Cluster cluster) { if (cluster.isSetId()) { host.setCluster(cluster); } else { host.setCluster(new org.ovirt.engine.api.model.Cluster()); host.getCluster().setId(lookupClusterByName(cluster.getName()).getId().toString()); } return host; }
@Test public void testBadGuidValidation() { setUpGetEntityExpectations(false); Host host = new Host(); host.setCluster(new Cluster()); host.getCluster().setId("!!!"); assertThrows(MalformedIdException.class, () -> resource.update(host)); }
@Test public void testAddHostClusterById() { setUriInfo(setUpBasicUriExpectations()); setUpCreationExpectations(ActionType.AddVds, AddVdsActionParameters.class, new String[] { "RootPassword" }, new Object[] { ROOT_PASSWORD }, true, true, GUIDS[0], QueryType.GetVdsByVdsId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0)); Host model = getModel(0); model.setCluster(new Cluster()); model.getCluster().setId(GUIDS[1].toString()); Response response = collection.add(model); assertEquals(201, response.getStatus()); assertTrue(response.getEntity() instanceof Host); verifyModel((Host) response.getEntity(), 0); }
@Test public void testAddHostClusterByName() { setUriInfo(setUpBasicUriExpectations()); setUpEntityQueryExpectations(QueryType.GetClusterByName, NameQueryParameters.class, new String[] { "Name" }, new Object[] { NAMES[1] }, setUpCluster(GUIDS[1])); setUpCreationExpectations(ActionType.AddVds, AddVdsActionParameters.class, new String[] { "RootPassword" }, new Object[] { ROOT_PASSWORD }, true, true, GUIDS[0], QueryType.GetVdsByVdsId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0)); Host model = getModel(0); model.setCluster(new Cluster()); model.getCluster().setName(NAMES[1]); Response response = collection.add(model); assertEquals(201, response.getStatus()); assertTrue(response.getEntity() instanceof Host); verifyModel((Host) response.getEntity(), 0); }
@Test public void testUpdateWithClusterId() { setUpGetEntityExpectations(3); setUriInfo(setUpActionExpectations(ActionType.ChangeVDSCluster, ChangeVDSClusterParameters.class, new String[] { "ClusterId", "VdsId" }, new Object[] { GUIDS[1], GUIDS[0]}, true, true, new ActionReturnValue(), false)); setUriInfo(setUpActionExpectations(ActionType.UpdateVds, UpdateVdsActionParameters.class, new String[] { "RootPassword" }, new Object[] { ROOT_PASSWORD }, true, true)); org.ovirt.engine.api.model.Cluster cluster = new org.ovirt.engine.api.model.Cluster(); cluster.setId(GUIDS[1].toString()); Host host = getModel(0); host.setCluster(cluster); verifyModel(resource.update(host), 0); }
@Test public void testUpdateWithClusterName() { String clusterName = "Default"; setUpGetEntityExpectations(3); setUpEntityQueryExpectations(QueryType.GetClusterByName, NameQueryParameters.class, new String[] { "Name" }, new Object[] { clusterName }, getCluster(clusterName, GUIDS[1])); setUriInfo(setUpActionExpectations(ActionType.ChangeVDSCluster, ChangeVDSClusterParameters.class, new String[] { "ClusterId", "VdsId" }, new Object[] { GUIDS[1], GUIDS[0] }, true, true, new ActionReturnValue(), false)); setUriInfo(setUpActionExpectations(ActionType.UpdateVds, UpdateVdsActionParameters.class, new String[] { "RootPassword" }, new Object[] { ROOT_PASSWORD }, true, true)); org.ovirt.engine.api.model.Cluster cluster = new org.ovirt.engine.api.model.Cluster(); cluster.setName(clusterName); Host host = getModel(0); host.setCluster(cluster); verifyModel(resource.update(host), 0); }
Cluster cluster = new Cluster(); cluster.setId(entity.getClusterId().toString()); model.setCluster(cluster);
to.setCluster(adaptIn(from.getCluster()));