byte[] contentBytes = null;
Document result = null;
try {
contentBytes = content.getBytes("UTF-8");
ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(contentBytes.length),
"text/plain", new ByteArrayInputStream(contentBytes));
// create the document
result = parent.createDocument(properties, contentStream, versioningState, null, null, null,
SELECT_ALL_NO_CACHE_OC);
contentStream.getStream().close();
} catch (Exception e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document could not be created! Exception: " + e.getMessage(),
e, true));
return null;
}
try {
CmisTestResult f;
// check document name
f = createResult(FAILURE, "Document name does not match!", false);
addResult(assertEquals(name, result.getName(), null, f));
// check the new document
addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
// check content
try {
ContentStream contentStream = result.getContentStream();
f = createResult(WARNING, "Document filename does not match!", false);
addResult(assertEquals(name, contentStream.getFileName(), null, f));
f = createResult(WARNING,
"cmis:contentStreamFileName and the filename of the content stream do not match!", false);
addResult(assertEquals(result.getContentStreamFileName(), contentStream.getFileName(), null, f));
String fetchedContent = getStringFromContentStream(result.getContentStream());
if (!content.equals(fetchedContent)) {
addResult(createResult(FAILURE,
"Content of newly created document doesn't match the orign content!"));