DeviceRepository { public boolean deleteDevice(String id, String log) throws DeviceException, DeviceNotFoundException { checkDeviceId(id); RemoteObject robject = remoteStorage.find(id); try { if (remoteStorage.getSearch().isDeviceInUse(id)) { return false; } else { robject.purge(log); return true; } } catch (DigitalObjectNotFoundException ex) { throw new DeviceNotFoundException(null, ex, id); } catch (FedoraClientException ex) { if (ex.getStatus() == Status.NOT_FOUND.getStatusCode()) { throw new DeviceNotFoundException(null, ex, id); } else { throw new DeviceException(id, ex); } } catch (DigitalObjectException | IOException ex) { throw new DeviceException(id, ex); } } DeviceRepository(RemoteStorage remoteStorage); Device addDevice(String owner, String model, String label, String log); boolean deleteDevice(String id, String log); List<Device> find(String id); List<Device> find(String id, boolean fetchDescription, int offset); Device update(Device update, String log); List<Device> findAllDevices(int offset); static XmlStreamEditor getMixDescriptionEditor(FedoraObject robj); static XmlStreamEditor getPremisDescriptionEditor(FedoraObject robj); XmlStreamEditor getDescriptionEditor(String id); Mets repairNkComplexType(Mets mets); static final String DESCRIPTION_DS_ID; static final String AUDIODESCRIPTION_DS_ID; static final String DESCRIPTION_DS_LABEL; static final String AUDIO_DESCRIPTION_DS_LABEL; static final String METAMODEL_ID; static final String METAMODEL_AUDIODEVICE_ID; static final String METAMODEL_ID_LABEL; static final String METAMODEL_AUDIODEVICE_ID_LABEL; }
@Test public void testDeleteDevice() throws Exception { Device delete = addTestDevice("testDeleteDevice"); assertTrue(repository.deleteDevice(delete.getId(), "testDeleteDevice")); List<Device> result = repository.find(delete.getId()); assertTrue(String.valueOf(result), result.isEmpty()); }
@Test public void testDeleteUnknownDevice() throws Exception { String[] expected = {"device:testDeleteUnknownDevice"}; try { repository.deleteDevice(expected[0], "testDeleteDevice"); fail("Expected " + DeviceNotFoundException.class.getName()); } catch (DeviceNotFoundException ex) { assertArrayEquals(expected, ex.getIds()); } }