LocalStorage { public LocalObject create() { return create((String) null, null); }  LocalObject load(String pid, File foxml); LocalObject create(); LocalObject create(String pid); LocalObject create(DigitalObject dobj); LocalObject create(File foxml, DigitalObject dobj); LocalObject create(File foxml); LocalObject create(String pid, File foxml);  }
@Test public void testCreate_0args() throws Exception { LocalStorage instance = new LocalStorage(); LocalObject result = instance.create(); assertLocalObject(result); assertNull(result.getFoxml()); }
@Test public void testCreate_String() throws Exception { String pid = "PID"; LocalStorage instance = new LocalStorage(); LocalObject result = instance.create(pid); assertLocalObject(result); assertEquals(pid, result.getPid()); assertEquals(pid, result.getDigitalObject().getPID()); assertNull(result.getFoxml()); }
@Test public void testCreate_DigitalObject() throws Exception { String pid = "PID"; DigitalObject dobj = FoxmlUtils.createFoxml(pid); LocalStorage instance = new LocalStorage(); LocalObject result = instance.create(dobj); assertLocalObject(result); assertEquals(pid, result.getPid()); assertEquals(pid, result.getDigitalObject().getPID()); assertNull(result.getFoxml()); }
@Test public void testCreate_File_DigitalObject() throws Exception { File foxml = tmp.newFile(); String pid = "PID"; DigitalObject dobj = FoxmlUtils.createFoxml(pid); LocalStorage instance = new LocalStorage(); LocalObject result = instance.create(foxml, dobj); assertLocalObject(result); assertEquals(pid, result.getPid()); assertEquals(pid, result.getDigitalObject().getPID()); assertEquals(foxml, result.getFoxml()); assertEquals(0, foxml.length()); }
@Test public void testCreate_File() throws Exception { File foxml = tmp.newFile(); LocalStorage instance = new LocalStorage(); LocalObject result = instance.create(foxml); assertLocalObject(result); assertEquals(foxml, result.getFoxml()); assertEquals(0, foxml.length()); }
@Test public void testCreate_String_File() throws Exception { File foxml = tmp.newFile(); String pid = "PID"; LocalStorage instance = new LocalStorage(); LocalObject result = instance.create(pid, foxml); assertLocalObject(result); assertEquals(pid, result.getPid()); assertEquals(pid, result.getDigitalObject().getPID()); assertEquals(foxml, result.getFoxml()); assertEquals(0, foxml.length()); }
@Test public void testDatastreamEditorWriteBytes_ManagedAsInlined() throws Exception { LocalStorage storage = new LocalStorage(); LocalObject lobject = storage.create(); String dsID = "dsID"; MediaType mime = MediaType.TEXT_PLAIN_TYPE; String label = "label"; XmlStreamEditor editor = lobject.getEditor(FoxmlUtils.managedProfile(dsID, mime, label)); assertNotNull(editor); assertNotNull(editor.getProfile()); assertEquals(mime.toString(), editor.getProfile().getDsMIME()); assertNull(editor.getProfile().getDsFormatURI()); byte[] data = "data".getBytes("UTF-8"); editor.write(data, 0, null); lobject.flush(); DigitalObject dobj = lobject.getDigitalObject(); DatastreamType ds = FoxmlUtils.findDatastream(dobj, dsID); assertNotNull(ds); assertEquals(ControlGroup.MANAGED.toExternal(), ds.getCONTROLGROUP()); DatastreamVersionType dsv = FoxmlUtils.findDataStreamVersion(dobj, dsID); assertNotNull(dsv); assertEquals(mime.toString(), dsv.getMIMETYPE()); assertEquals(label, dsv.getLABEL()); assertArrayEquals(data, dsv.getBinaryContent()); assertNull(dsv.getContentLocation()); }
@Test public void testDatastreamEditorWriteBytes_ManagedAsAttached() throws Exception { LocalStorage storage = new LocalStorage(); LocalObject lobject = storage.create(); String dsID = "dsID"; MediaType mime = MediaType.TEXT_PLAIN_TYPE; String label = "label"; XmlStreamEditor editor = lobject.getEditor(FoxmlUtils.managedProfile(dsID, mime, label)); assertNotNull(editor); assertNotNull(editor.getProfile()); assertEquals(mime.toString(), editor.getProfile().getDsMIME()); assertNull(editor.getProfile().getDsFormatURI()); byte[] data = "data".getBytes("UTF-8"); File attachment = tmp.newFile(); editor.write(attachment.toURI(), 0, null); editor.write(data, editor.getLastModified(), null); lobject.flush(); DigitalObject dobj = lobject.getDigitalObject(); DatastreamType ds = FoxmlUtils.findDatastream(dobj, dsID); assertNotNull(ds); assertEquals(ControlGroup.MANAGED.toExternal(), ds.getCONTROLGROUP()); DatastreamVersionType dsv = FoxmlUtils.findDataStreamVersion(dobj, dsID); assertNotNull(dsv); assertEquals(mime.toString(), dsv.getMIMETYPE()); assertEquals(label, dsv.getLABEL()); assertNull(dsv.getBinaryContent()); assertNotNull(dsv.getContentLocation()); FileInputStream fis = new FileInputStream(attachment); byte[] readdata = new byte[data.length]; assertEquals(data.length, fis.read(readdata)); fis.close(); assertArrayEquals(data, readdata); }
@Test public void testDatastreamEditorWriteStream_ManagedAsInlined() throws Exception { LocalStorage storage = new LocalStorage(); LocalObject lobject = storage.create(); String dsID = "dsID"; MediaType mime = MediaType.TEXT_PLAIN_TYPE; String label = "label"; XmlStreamEditor editor = lobject.getEditor(FoxmlUtils.managedProfile(dsID, mime, label)); assertNotNull(editor); assertNotNull(editor.getProfile()); assertEquals(mime.toString(), editor.getProfile().getDsMIME()); assertNull(editor.getProfile().getDsFormatURI()); byte[] data = "data".getBytes("UTF-8"); editor.write(new ByteArrayInputStream(data), 0, null); lobject.flush(); DigitalObject dobj = lobject.getDigitalObject(); DatastreamType ds = FoxmlUtils.findDatastream(dobj, dsID); assertNotNull(ds); assertEquals(ControlGroup.MANAGED.toExternal(), ds.getCONTROLGROUP()); DatastreamVersionType dsv = FoxmlUtils.findDataStreamVersion(dobj, dsID); assertNotNull(dsv); assertEquals(mime.toString(), dsv.getMIMETYPE()); assertEquals(label, dsv.getLABEL()); assertArrayEquals(data, dsv.getBinaryContent()); assertNull(dsv.getContentLocation()); }
@Test public void testDatastreamEditorWriteStream_ManagedAsAttached() throws Exception { LocalStorage storage = new LocalStorage(); LocalObject lobject = storage.create(); String dsID = "dsID"; MediaType mime = MediaType.TEXT_PLAIN_TYPE; String label = "label"; XmlStreamEditor editor = lobject.getEditor(FoxmlUtils.managedProfile(dsID, mime, label)); assertNotNull(editor); assertNotNull(editor.getProfile()); assertEquals(mime.toString(), editor.getProfile().getDsMIME()); assertNull(editor.getProfile().getDsFormatURI()); byte[] data = "data".getBytes("UTF-8"); File attachment = tmp.newFile(); editor.write(attachment.toURI(), 0, null); editor.write(new ByteArrayInputStream(data), editor.getLastModified(), null); lobject.flush(); DigitalObject dobj = lobject.getDigitalObject(); DatastreamType ds = FoxmlUtils.findDatastream(dobj, dsID); assertNotNull(ds); assertEquals(ControlGroup.MANAGED.toExternal(), ds.getCONTROLGROUP()); DatastreamVersionType dsv = FoxmlUtils.findDataStreamVersion(dobj, dsID); assertNotNull(dsv); assertEquals(mime.toString(), dsv.getMIMETYPE()); assertEquals(label, dsv.getLABEL()); assertNull(dsv.getBinaryContent()); assertNotNull(dsv.getContentLocation()); FileInputStream fis = new FileInputStream(attachment); byte[] readdata = new byte[data.length]; assertEquals(data.length, fis.read(readdata)); fis.close(); assertArrayEquals(data, readdata); }
@Test public void testDatastreamEditorWriteXml_Inlined() throws Exception { LocalStorage storage = new LocalStorage(); LocalObject lobject = storage.create(); String dsID = "dsID"; MediaType mime = MediaType.TEXT_XML_TYPE; String label = "label"; String formatUri = "formatUri"; XmlStreamEditor editor = lobject.getEditor(FoxmlUtils.inlineProfile(dsID, formatUri, label)); assertNotNull(editor); assertNotNull(editor.getProfile()); assertEquals(mime.toString(), editor.getProfile().getDsMIME()); assertEquals(formatUri, editor.getProfile().getDsFormatURI()); XmlData xdata = new XmlData("data"); EditorResult xmlResult = editor.createResult(); JAXB.marshal(xdata, xmlResult); editor.write(xmlResult, 0, null); lobject.flush(); DigitalObject dobj = lobject.getDigitalObject(); DatastreamType ds = FoxmlUtils.findDatastream(dobj, dsID); assertNotNull(ds); assertEquals(ControlGroup.INLINE.toExternal(), ds.getCONTROLGROUP()); DatastreamVersionType dsv = FoxmlUtils.findDataStreamVersion(dobj, dsID); assertNotNull(dsv); assertEquals(mime.toString(), dsv.getMIMETYPE()); assertEquals(label, dsv.getLABEL()); assertEquals(formatUri, dsv.getFORMATURI()); assertNotNull(dsv.getXmlContent()); assertNull(dsv.getContentLocation()); assertNull(dsv.getBinaryContent()); }
@Test public void testDatastreamEditorWriteXml_ManagedAsAttached() throws Exception { LocalStorage storage = new LocalStorage(); LocalObject lobject = storage.create(); String dsID = "dsID"; MediaType mime = MediaType.TEXT_XML_TYPE; String label = "label"; String formatUri = "formatUri"; XmlStreamEditor editor = lobject.getEditor(FoxmlUtils.managedProfile(dsID, formatUri, label)); assertNotNull(editor); assertNotNull(editor.getProfile()); assertEquals(mime.toString(), editor.getProfile().getDsMIME()); assertEquals(formatUri, editor.getProfile().getDsFormatURI()); File attachment = tmp.newFile(); editor.write(attachment.toURI(), 0, null); XmlData xdata = new XmlData("data"); EditorResult xmlResult = editor.createResult(); JAXB.marshal(xdata, xmlResult); editor.write(xmlResult, editor.getLastModified(), null); lobject.flush(); DigitalObject dobj = lobject.getDigitalObject(); DatastreamType ds = FoxmlUtils.findDatastream(dobj, dsID); assertNotNull(ds); assertEquals(ControlGroup.MANAGED.toExternal(), ds.getCONTROLGROUP()); DatastreamVersionType dsv = FoxmlUtils.findDataStreamVersion(dobj, dsID); assertNotNull(dsv); assertEquals(mime.toString(), dsv.getMIMETYPE()); assertEquals(label, dsv.getLABEL()); assertEquals(formatUri, dsv.getFORMATURI()); assertNull(dsv.getBinaryContent()); assertNull(dsv.getXmlContent()); assertNotNull(dsv.getContentLocation()); XmlData result = JAXB.unmarshal(attachment, XmlData.class); assertEquals(xdata, result); }
@Test public void testSetDatastreamProfile() throws Exception { LocalStorage storage = new LocalStorage(); LocalObject lobject = storage.create(); String dsID = "dsID"; MediaType mime = MediaType.TEXT_PLAIN_TYPE; String label = "label"; XmlStreamEditor editor = lobject.getEditor(FoxmlUtils.managedProfile(dsID, mime, label)); assertNotNull(editor); assertNotNull(editor.getProfile()); assertEquals(mime.toString(), editor.getProfile().getDsMIME()); assertNull(editor.getProfile().getDsFormatURI()); byte[] data = "data".getBytes("UTF-8"); File attachment = tmp.newFile(); editor.write(attachment.toURI(), 0, null); editor.write(new ByteArrayInputStream(data), editor.getLastModified(), null); lobject.flush(); editor = lobject.getEditor(FoxmlUtils.managedProfile(dsID, mime, label)); String expectedMimetype = MediaType.APPLICATION_JSON; DatastreamProfile profile = editor.getProfile(); profile.setDsMIME(expectedMimetype); editor.setProfile(profile); editor.write(data, editor.getLastModified(), label); lobject.flush(); editor = lobject.getEditor(FoxmlUtils.managedProfile(dsID, mime, label)); assertEquals(expectedMimetype, editor.getProfile().getDsMIME()); }
@Test public void testGetStreamProfile() throws Exception { LocalStorage storage = new LocalStorage(); LocalObject lobject = storage.create(); String dsID = BinaryEditor.FULL_ID; MediaType mime = MediaType.TEXT_PLAIN_TYPE; String label = "label"; XmlStreamEditor editor = lobject.getEditor(FoxmlUtils.managedProfile(dsID, mime, label)); assertNotNull(editor); assertNotNull(editor.getProfile()); assertEquals(mime.toString(), editor.getProfile().getDsMIME()); assertNull(editor.getProfile().getDsFormatURI()); byte[] data = "data".getBytes("UTF-8"); editor.write(data, 0, null); lobject.flush(); List<DatastreamProfile> resultProfiles = lobject.getStreamProfile(null); assertNotNull(resultProfiles); assertEquals(1, resultProfiles.size()); assertEquals(dsID, resultProfiles.get(0).getDsID()); }