/** * Create an instance of {@link File } * */ public File createFile() { return new File(); }
@Mapping(from = String.class, to = File.class) public static File map(String entity, File template) { File model = template != null ? template : new File(); model.setId(entity); model.setName(entity); return model; } }
/** * Bi-directional Cdrom->VmTemplate not required as * template device collections are always read-only */ @Mapping(from = VmTemplate.class, to = Cdrom.class) public static Cdrom map(VmTemplate entity, Cdrom template) { Cdrom model = template != null ? template : new Cdrom(); model.setId(CDROM_ID.toString()); if (!StringUtils.isEmpty(entity.getIsoPath())) { model.setFile(new File()); model.getFile().setId(entity.getIsoPath()); } return model; } }
@Mapping(from = VM.class, to = Cdrom.class) public static Cdrom map(VM entity, Cdrom template) { Cdrom model = template != null ? template : new Cdrom(); model.setId(CDROM_ID.toString()); if (!StringUtils.isEmpty(entity.getStaticData().getIsoPath())) { model.setFile(new File()); model.getFile().setId(entity.getStaticData().getIsoPath()); } return model; }
@Mapping(from = VmPayload.class, to = Payload.class) public static Payload map(VmPayload entity, Payload template) { if (entity.getDeviceType() != null || entity.getFiles().isEmpty()) { Payload model = template != null ? template : new Payload(); if (entity.getDeviceType() != null) { org.ovirt.engine.api.model.VmDeviceType deviceType = map(entity.getDeviceType(), null); if (deviceType != null) { model.setType(deviceType); } } model.setVolumeId(entity.getVolumeId()); if (entity.getFiles().size() > 0) { model.setFiles(new Files()); for (Map.Entry<String, String> entry : entity.getFiles().entrySet()) { File file = new File(); file.setName(entry.getKey()); file.setContent(entry.getValue()); model.getFiles().getFiles().add(file); } } return model; } return null; }
private Cdrom getCdrom() { Cdrom model = new Cdrom(); model.setFile(new File()); model.getFile().setId(ISO_PATH); return model; }
private Cdrom getCdrom(String path) { Cdrom cdrom = new Cdrom(); cdrom.setFile(new File()); cdrom.getFile().setId(path); return cdrom; }
@Test public void testAddIncompleteParameters() { Cdrom model = new Cdrom(); model.setName(NAMES[0]); model.setFile(new File()); setUriInfo(setUpBasicUriExpectations()); verifyIncompleteException( assertThrows(WebApplicationException.class, () -> collection.add(model)), "Cdrom", "add", "file.id"); }
@Test public void testFileLinks() { File file = new File(); file.setId(FILE_ID); file.setStorageDomain(new StorageDomain()); file.getStorageDomain().setId(STORAGE_DOMAIN_ID); LinkHelper.addLinks(file); assertEquals(FILE_HREF, file.getHref()); }
@Test public void testStartWithCdRomAndFloppy() { setUpWindowsGetEntityExpectations(1, false); setUriInfo(setUpActionExpectations(ActionType.RunVmOnce, RunVmOnceParams.class, new String[] { "VmId", "DiskPath", "FloppyPath" }, new Object[] { GUIDS[0], ISO_ID, FLOPPY_ID })); Action action = new Action(); action.setVm(new Vm()); action.getVm().setCdroms(new Cdroms()); action.getVm().getCdroms().getCdroms().add(new Cdrom()); action.getVm().getCdroms().getCdroms().get(0).setFile(new File()); action.getVm().getCdroms().getCdroms().get(0).getFile().setId(ISO_ID); action.getVm().setFloppies(new Floppies()); action.getVm().getFloppies().getFloppies().add(new Floppy()); action.getVm().getFloppies().getFloppies().get(0).setFile(new File()); action.getVm().getFloppies().getFloppies().get(0).getFile().setId(FLOPPY_ID); verifyActionResponse(resource.start(action)); }
@Override public File adapt(V3File from) { File to = new File(); if (from.isSetLinks()) { to.getLinks().addAll(adaptIn(from.getLinks()));
private ExternalVmImport createVmImport() { File file = new File(); file.setId(DRIVERS_ISO); ExternalVmImport vmImport = new ExternalVmImport(); vmImport.setName(EXTERNAL_VM_NAME); vmImport.setVm(new Vm()); vmImport.getVm().setName(CREATED_VM_NAME); vmImport.setCluster(new Cluster()); vmImport.getCluster().setId(CLUSTER_ID.toString()); vmImport.setStorageDomain(new StorageDomain()); vmImport.getStorageDomain().setId(STORAGE_DOMAIN_ID.toString()); vmImport.setHost(new Host()); vmImport.getHost().setId(HOST_ID.toString()); vmImport.setSparse(true); vmImport.setProvider(ExternalVmProviderType.VMWARE); vmImport.setDriversIso(file); vmImport.setUsername(USERNAME); vmImport.setPassword(PASSWORD); vmImport.setUrl(VMWARE_URL); return vmImport; } }