@Test(dataProvider = "IsoFileNames") public void testPrepareVmAttachIso(String isoFileName) throws Throwable { TaskEntity task = vmDcpBackend.prepareVmAttachIso(vmId, inputStream, isoFileName); assertThat(task, is(notNullValue())); assertThat(task.getState(), is(TaskEntity.State.QUEUED)); assertThat(task.getSteps().size(), is(2)); assertThat( task.getSteps().get(0).getOperation(), is(com.vmware.photon.controller.api.Operation.UPLOAD_ISO)); IsoEntity iso = (IsoEntity) task.getSteps().get(0).getTransientResourceEntities().get(1); assertThat(iso.getName(), is(isoName)); assertThat(task.getToBeLockedEntityIds().size(), is(2)); assertThat(task.getToBeLockedEntityIds().get(0), is(iso.getId())); assertThat(task.getToBeLockedEntityIds().get(1), is(vmId)); }
@Test public void testPrepareVmDelete() throws Throwable { TaskEntity task = vmDcpBackend.prepareVmDelete(vmId); assertThat(task, is(notNullValue())); assertThat(task.getState(), is(TaskEntity.State.QUEUED)); assertThat(task.getSteps().size(), is(1)); assertThat( task.getSteps().get(0).getOperation(), is(com.vmware.photon.controller.api.Operation.DELETE_VM)); assertThat(task.getToBeLockedEntityIds().size(), is(1)); assertThat(task.getToBeLockedEntityIds().get(0), is(vmId)); }
@Test public void testPrepareVmCreate() throws Throwable { String vmId = createdVmTaskEntity.getEntityId(); assertThat(createdVmTaskEntity.getSteps().size(), is(2)); assertThat( createdVmTaskEntity.getSteps().get(0).getOperation(), is(com.vmware.photon.controller.api.Operation.RESERVE_RESOURCE)); assertThat( createdVmTaskEntity .getSteps() .get(0) .getTransientResourceEntities(ProjectEntity.KIND) .size(), is(1)); assertThat( createdVmTaskEntity .getSteps() .get(0) .getTransientResourceEntities(ProjectEntity.KIND) .get(0) .getId(), is(projectId)); assertThat( createdVmTaskEntity.getSteps().get(1).getOperation(), is(com.vmware.photon.controller.api.Operation.CREATE_VM)); assertThat(createdVmTaskEntity.getToBeLockedEntityIds().size(), is(1)); assertThat(createdVmTaskEntity.getToBeLockedEntityIds().get(0), is(vmId)); VmEntity vm = vmDcpBackend.findById(vmId); assertThat(vm, is(notNullValue())); assertThat(getUsage("vm.cost"), is(1.0)); assertThat(vm.getImageId(), is(imageId)); assertThat(vm.getAffinities().get(0).getResourceId(), is("disk-id1")); assertThat(vm.getAffinities().get(0).getKind(), is("disk")); assertThat(vm.getAffinities().get(1).getResourceId(), is("disk-id2")); assertThat(vm.getAffinities().get(1).getKind(), is("disk")); Set<TagEntity> tags = vm.getTags(); assertThat(tags.size(), is(2)); TagEntity tag1 = new TagEntity(); tag1.setValue("value1"); TagEntity tag2 = new TagEntity(); tag2.setValue("value2"); assertTrue(tags.contains(tag1)); assertTrue(tags.contains(tag2)); assertThat(vmCreateSpec.getNetworks().equals(vm.getNetworks()), is(true)); }