oc.setFilterString("*");
oc.setCacheEnabled(false);
// set new name and save
Document doc2 = (Document) this.session.getObject(id, oc);
TransientDocument tdoc2 = doc2.getTransientDocument();
assertEquals(filename1, tdoc2.getName());
ContentStream cs2 = tdoc2.getContentStream();
assertNotNull(cs2);
assertContent(buf1, readContent(cs2));
String filename2 = UUID.randomUUID().toString();
tdoc2.setName(filename2);
assertEquals(filename2, tdoc2.getName());
ObjectId id2 = tdoc2.save();
assertNotNull(id2);
// set new content and save
Document doc3 = (Document) this.session.getObject(id2, oc);
TransientDocument tdoc3 = doc3.getTransientDocument();
assertEquals(filename2, tdoc3.getName());
ContentStream cs3 = tdoc3.getContentStream();
assertNotNull(cs3);
assertContent(buf1, readContent(cs3));
String content3 = "Es rauscht noch.";
byte[] buf3 = content3.getBytes("UTF-8");
ByteArrayInputStream in3 = new ByteArrayInputStream(buf3);
ContentStream contentStream3 = this.session.getObjectFactory()
.createContentStream(tdoc3.getName(), buf3.length, mimetype,
in3);
assertNotNull(contentStream3);
tdoc3.setContentStream(contentStream3, true);
ObjectId id3 = tdoc3.save();
assertNotNull(id3);
// set new name, delete content and save
Document doc4 = (Document) this.session.getObject(id3, oc);
TransientDocument tdoc4 = doc4.getTransientDocument();
assertEquals(tdoc3.getName(), tdoc4.getName());
ContentStream cs4 = tdoc4.getContentStream();
assertNotNull(cs4);
assertContent(buf3, readContent(cs4));
String filename4 = UUID.randomUUID().toString();
tdoc4.setName(filename4);
assertEquals(filename4, tdoc4.getName());
tdoc4.deleteContentStream();
ObjectId id4 = tdoc4.save();
assertNotNull(id4);
// delete object
Document doc5 = (Document) this.session.getObject(id4, oc);
TransientDocument tdoc5 = doc5.getTransientDocument();
assertEquals(filename4, tdoc5.getName());
ContentStream cs5 = tdoc4.getContentStream();
assertNull(cs5);
assertEquals(false, tdoc5.isMarkedForDelete());
tdoc5.delete(true);
assertEquals(true, tdoc5.isMarkedForDelete());
ObjectId id5 = tdoc5.save();
assertNull(id5);
// check
try {
this.session.getObject(id4, oc);