// OK we can create an Digital Object from the test resource data, we need a URL
System.out.println("Testing storage of Digital Object");
URI purl = new File(AllStorageSuite.TEST_DATA_BASE, FILE).toURI();
/* Create the content: */
System.out.println("Creating DigitalObjectContent c1");
DigitalObjectContent c1 = Content.byReference(purl.toURL().openStream());
System.out.println("Creating DigitalObject object");
/* Given these, we can instantiate our object: */
DigitalObject object = new DigitalObject.Builder(c1).permanentUri(purl).title(purl.toString()).build();
// Check digital object. Title should not be null
System.out.println("Setting store flag to true");
boolean storeFlag = true;
// Now store it
URI pdURI = null;
try {
System.out.println("calling this.dom.storeAsNew(object)");
pdURI = DigitalObjectManagerTests.dom.storeAsNew(object);
System.out.println("StoreAsNew returned the URI:" + pdURI);
} catch (Exception e) {
System.out.println("Caught an exception in storeAsNew, here's the details");
e.printStackTrace();
System.out.println("Asserting it's a not stored exception");
assertTrue("Expecting exception to be DigitalObjectNotStoredException", e.getClass().equals(DigitalObjectNotStoredException.class));
System.out.println("Setting storeFlag to false");
storeFlag = false;
} catch (Throwable t) {
System.out.println("Caught a throwable in storeAsNew, here's the details");
t.printStackTrace();
System.out.println("Setting storeFlag to false");
storeFlag = false;
}
System.out.println("Creating new version of object");
object = new DigitalObject.Builder(object.getContent()).title("mytitle").build();
System.out.println("asserting the title is not null");
assertNotNull("NOT expecting object.getTitle() to be null", object.getTitle());
if (storeFlag)
{
DigitalObject retObject = null;
// Then retrieve it and check it's the same
System.out.println("now retrieving object to test (ret object)");
System.out.println("Retrieving the test object using URI:" + pdURI);
try {
retObject = DigitalObjectManagerTests.dom.retrieve(pdURI);
} catch (DigitalObjectNotFoundException e) {
e.printStackTrace();
throw e;
} catch (Exception e) {
System.out.println("Caught unexpected exception calling retrieve()");
e.printStackTrace();
fail("this.dom.retrive failed with an unexpected exception");
}
System.out.println("Creating new Purl");
URI newPurl = new File(AllStorageSuite.TEST_DATA_BASE, FILE).toURI();
System.out.println("Creating digital object c2");
DigitalObjectContent c2 = Content.byReference(newPurl.toURL().openStream());
System.out.println("Creating new Expected object");
DigitalObject expectedObject = new DigitalObject.Builder(c2).build();
// Check that retObject is not null
assertNotNull("Not expecting returned object to be null", retObject);