ObjectContentManager ocm = this.getObjectContentManager();
//---------------------------------------------------------------------------------------------------------
// Insert a Document
//---------------------------------------------------------------------------------------------------------
DocumentImpl document = new DocumentImpl();
document.setPath("/document1");
document.setName("document name");
document.setContentType("plain/text");
DocumentStream documentStream = new DocumentStream();
documentStream.setEncoding("utf-8");
documentStream.setContent("Test Content".getBytes());
document.setDocumentStream(documentStream);
ocm.insert(document);
ocm.save();
//---------------------------------------------------------------------------------------------------------
// Retrieve a document object
//---------------------------------------------------------------------------------------------------------
document = (DocumentImpl) ocm.getObject( "/document1");
assertEquals("Document path is invalid", document.getPath(), "/document1");
assertEquals("Content type is invalid", document.getContentType(), "plain/text");
assertNotNull("document stream is null", document.getDocumentStream());
assertTrue("Invalid document stream ", document.getDocumentStream().getEncoding().equals("utf-8"));
//---------------------------------------------------------------------------------------------------------
// Update a descendant object
//---------------------------------------------------------------------------------------------------------
document.setName("anotherName");
ocm.update(document);
ocm.save();
//---------------------------------------------------------------------------------------------------------
// Retrieve the updated descendant object
//---------------------------------------------------------------------------------------------------------
document = (DocumentImpl) ocm.getObject( "/document1");
assertEquals("document name is incorrect", document.getName(), "anotherName");
assertEquals("Document path is invalid", document.getPath(), "/document1");
assertEquals("Content type is invalid", document.getContentType(), "plain/text");
assertNotNull("document stream is null", document.getDocumentStream());
assertTrue("Invalid document stream", document.getDocumentStream().getEncoding().equals("utf-8"));
CmsObjectImpl cmsObject = (CmsObjectImpl) ocm.getObject( "/document1");
assertEquals("cmsObject name is incorrect", cmsObject.getName(), "anotherName");
assertEquals("cmsObject path is invalid", cmsObject.getPath(), "/document1");