RestModelImporter { public HardwareType importHardwareType(ImportableHardwareType importable) { final HardwareType hardwareType = mapper.fromImportable(importable); hardwareTypeService.save(hardwareType); return hardwareType; } RestModelImporter(ImportModelMapper mapper, HardwareTypeService hardwareTypeService, ApplicationService applicationService, ClientService clientService, DeviceService deviceService, LocationService locationService, PrinterService printerService); Device importDevice(org.openthinclient.api.rest.model.Device importable); HardwareType importHardwareType(ImportableHardwareType importable); Printer importPrinter(org.openthinclient.api.rest.model.Printer importable); Location importLocation(ImportableLocation importable); Application importApplication(org.openthinclient.api.rest.model.Application importable); Client importClient(ImportableClient importable); Profile importProfileObject(AbstractProfileObject importable);  }
@Test public void testImportSimpleHardwareType() throws Exception { final ImportableHardwareType hw = new ImportableHardwareType(); hw.setName("Simple Hardware Type"); final HardwareType hardwareType = importer.importHardwareType(hw); assertNotNull(hardwareType); then(hardwareTypeService).should().save(any()); }
@Test(expected = MissingReferencedObjectException.class) public void testImportHardwareTypeWithMissingDevice() throws Exception { final ImportableHardwareType hw = new ImportableHardwareType(); hw.setName("Incomplete Hardware Type"); hw.getDevices().add(new ProfileReference(ProfileType.DEVICE, "Missing Device")); importer.importHardwareType(hw); }
@Test public void testImportHardwareTypeWithReferencedDevice() throws Exception { final Device existingDevice = new Device(); existingDevice.setName("RequiredDevice"); given(deviceService.findByName("Required Device")).willReturn(existingDevice); final ImportableHardwareType hw = new ImportableHardwareType(); hw.setName("Complete Hardware Type"); hw.getDevices().add(new ProfileReference(ProfileType.DEVICE, "Required Device")); final HardwareType result = importer.importHardwareType(hw); assertNotNull(result); assertSame(existingDevice, result.getDevices().iterator().next()); then(hardwareTypeService).should().save(any()); }