use of org.apache.chemistry.opencmis.client.api.Document in project manifoldcf by apache.
the class APISanityHSQLDBIT method changeDocument.
/**
* change the document content with the new one provided as an argument
* @param session
* @param name
* @param newContent
*/
public void changeDocument(Session session, String name, String newContent) {
String cmisQuery = StringUtils.replace(CMIS_TEST_QUERY_CHANGE_DOC, REPLACER, name);
ItemIterable<QueryResult> results = session.query(cmisQuery, false);
String objectId = StringUtils.EMPTY;
for (QueryResult result : results) {
objectId = result.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue().toString();
}
byte[] newContentByteArray = newContent.getBytes(StandardCharsets.UTF_8);
InputStream stream = new ByteArrayInputStream(newContentByteArray);
ContentStream contentStream = new ContentStreamImpl(name, new BigInteger(newContentByteArray), "text/plain", stream);
Document documentToUpdate = (Document) session.getObject(objectId);
documentToUpdate.setContentStream(contentStream, true);
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class AwsLocalStorageTest method createDocumentWithCustomProperties.
/**
* Creates a document with custom properties
*/
protected Document createDocumentWithCustomProperties(Session session, Folder parent, String name, String objectTypeId, String[] secondaryTypeIds, String content) {
if (parent == null) {
throw new IllegalArgumentException("Parent is not set!");
}
if (name == null) {
throw new IllegalArgumentException("Name is not set!");
}
if (objectTypeId == null) {
throw new IllegalArgumentException("Object Type ID is not set!");
}
if (content == null) {
content = "";
}
// check type
ObjectType type;
try {
type = session.getTypeDefinition(objectTypeId);
} catch (CmisObjectNotFoundException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Document type '" + objectTypeId + "' is not creatable!", true));
return null;
}
// create
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
if (secondaryTypeIds != null) {
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList(secondaryTypeIds));
}
type = session.getTypeDefinition(objectTypeId);
if (!(type instanceof DocumentTypeDefinition)) {
addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
return null;
}
DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
for (Map.Entry<String, PropertyDefinition<?>> propDef : docType.getPropertyDefinitions().entrySet()) {
if (propDef.getValue().getChoices().size() > 0) {
if (propDef.getValue().getPropertyType().equals(PropertyType.BOOLEAN)) {
List<Boolean> booleanList = new ArrayList<Boolean>();
booleanList.add((Boolean) propDef.getValue().getChoices().get(0).getValue().get(0));
properties.put(propDef.getValue().getId(), booleanList);
} else if (propDef.getValue().getPropertyType().equals(PropertyType.STRING)) {
List<String> stringList = new ArrayList<String>();
stringList.add((String) propDef.getValue().getChoices().get(0).getValue().get(0));
properties.put(propDef.getValue().getId(), stringList);
} else if (propDef.getValue().getPropertyType().equals(PropertyType.INTEGER)) {
List<BigInteger> intList = new ArrayList<BigInteger>();
intList.add((BigInteger) propDef.getValue().getChoices().get(0).getValue().get(0));
properties.put(propDef.getValue().getId(), intList);
}
}
if (!(propDef.getKey().equalsIgnoreCase(PropertyIds.NAME) || propDef.getKey().equalsIgnoreCase(PropertyIds.LAST_MODIFIED_BY) || propDef.getKey().equalsIgnoreCase(PropertyIds.OBJECT_TYPE_ID) || propDef.getKey().equalsIgnoreCase(PropertyIds.CREATED_BY) || propDef.getKey().equalsIgnoreCase(PropertyIds.PATH) || propDef.getKey().equalsIgnoreCase(PropertyIds.DESCRIPTION) || propDef.getKey().equalsIgnoreCase(PropertyIds.CHANGE_TOKEN) || propDef.getKey().equalsIgnoreCase(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS) || propDef.getKey().equalsIgnoreCase(PropertyIds.SECONDARY_OBJECT_TYPE_IDS) || propDef.getKey().equalsIgnoreCase(PropertyIds.PARENT_ID) || propDef.getKey().equalsIgnoreCase(PropertyIds.BASE_TYPE_ID) || propDef.getKey().equalsIgnoreCase(PropertyIds.OBJECT_ID) || propDef.getKey().equalsIgnoreCase(PropertyIds.LAST_MODIFICATION_DATE) || propDef.getKey().equalsIgnoreCase(PropertyIds.CREATION_DATE) || propDef.getKey().equalsIgnoreCase(PropertyIds.CONTENT_STREAM_LENGTH) || propDef.getKey().equalsIgnoreCase(PropertyIds.CONTENT_STREAM_FILE_NAME) || propDef.getKey().equalsIgnoreCase(PropertyIds.CONTENT_STREAM_MIME_TYPE) || propDef.getKey().equalsIgnoreCase(PropertyIds.CHECKIN_COMMENT) || propDef.getKey().equalsIgnoreCase(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY) || propDef.getKey().equalsIgnoreCase(PropertyIds.VERSION_LABEL) || propDef.getKey().equalsIgnoreCase(PropertyIds.IS_MAJOR_VERSION) || propDef.getKey().equalsIgnoreCase(PropertyIds.IS_LATEST_VERSION) || propDef.getKey().equalsIgnoreCase(PropertyIds.CONTENT_STREAM_ID) || propDef.getKey().equalsIgnoreCase(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID) || propDef.getKey().equalsIgnoreCase(PropertyIds.VERSION_SERIES_ID) || propDef.getKey().equalsIgnoreCase("cmis:previousVersionObjectId") || propDef.getKey().equalsIgnoreCase(PropertyIds.IS_IMMUTABLE))) {
if (propDef.getValue().getPropertyType().equals(PropertyType.ID)) {
properties.put(propDef.getValue().getId(), "123");
} else if (propDef.getValue().getPropertyType().equals(PropertyType.DATETIME)) {
properties.put(propDef.getValue().getId(), new GregorianCalendar());
} else if (propDef.getValue().getPropertyType().equals(PropertyType.DECIMAL)) {
properties.put(propDef.getValue().getId(), new BigDecimal("0.2"));
} else if (propDef.getValue().getPropertyType().equals(PropertyType.HTML)) {
properties.put(propDef.getValue().getId(), "<html>");
} else if (propDef.getValue().getPropertyType().equals(PropertyType.URI)) {
properties.put(propDef.getValue().getId(), AbstractRunner.BROWSER_URL);
}
}
}
byte[] contentBytes = null;
Document result = null;
try {
contentBytes = IOUtils.toUTF8Bytes(content);
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 content length
f = createResult(WARNING, "Content length does not match!", false);
addResult(assertEquals((long) contentBytes.length, result.getContentStreamLength(), 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 and the filename of the content stream do 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!"));
}
} catch (IOException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Content of newly created document couldn't be read! Exception: " + e.getMessage(), e, true));
}
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created document is invalid! Exception: " + e.getMessage(), e, true));
}
return result;
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method checkVersionHistory.
protected CmisTestResult checkVersionHistory(Session session, CmisObject object, String[] properties, String message) {
List<CmisTestResult> results = new ArrayList<CmisTestResult>();
CmisTestResult f;
if (object.getBaseTypeId() != BaseTypeId.CMIS_DOCUMENT) {
// skip non-document objects
return null;
}
if (!Boolean.TRUE.equals(((DocumentTypeDefinition) object.getType()).isVersionable())) {
// skip non-versionable types
return null;
}
Document doc = (Document) object;
// check version series ID
String versionSeriesId = doc.getVersionSeriesId();
f = createResult(FAILURE, "Versionable document has no version series ID property!");
addResult(results, assertStringNotEmpty(versionSeriesId, null, f));
if (versionSeriesId == null) {
CmisTestResultImpl result = createResult(getWorst(results), message);
result.getChildren().addAll(results);
return result;
}
// get version history
List<Document> versions = doc.getAllVersions(SELECT_ALL_NO_CACHE_OC);
f = createResult(FAILURE, "Version history is null!");
addResult(results, assertNotNull(versions, null, f));
if (versions == null) {
CmisTestResultImpl result = createResult(getWorst(results), message);
result.getChildren().addAll(results);
return result;
}
f = createResult(FAILURE, "Version history must have at least one version!");
addResult(results, assertListNotEmpty(versions, null, f));
if (!versions.isEmpty()) {
// get latest version
Document lastestVersion = doc.getObjectOfLatestVersion(false, SELECT_ALL_NO_CACHE_OC);
addResult(results, checkObject(session, lastestVersion, properties, "Latest version check: " + lastestVersion.getId()));
f = createResult(FAILURE, "Latest version is not flagged as latest version! ID: " + lastestVersion.getId());
addResult(results, assertIsTrue(lastestVersion.isLatestVersion(), null, f));
// get latest major version
Document lastestMajorVersion = null;
try {
lastestMajorVersion = doc.getObjectOfLatestVersion(true, SELECT_ALL_NO_CACHE_OC);
f = createResult(FAILURE, "getObjectOfLatestVersion returned an invalid object!");
addResult(results, assertNotNull(lastestMajorVersion, null, f));
} catch (CmisObjectNotFoundException e) {
// no latest major version
}
if (lastestMajorVersion != null) {
addResult(results, checkObject(session, lastestMajorVersion, properties, "Latest major version check: " + lastestMajorVersion.getId()));
f = createResult(FAILURE, "Latest major version is not flagged as latest major version! ID: " + lastestMajorVersion.getId());
addResult(results, assertIsTrue(lastestMajorVersion.isLatestMajorVersion(), null, f));
}
// iterate through the version history and test each version
// document
long creatationDate = Long.MAX_VALUE;
int latestVersion = 0;
int latestMajorVersion = 0;
long latestModificationDate = Long.MAX_VALUE;
int latestModifictaionIndex = Integer.MIN_VALUE;
Set<String> versionLabels = new HashSet<String>();
boolean found = false;
boolean foundLastestVersion = false;
boolean foundLastestMajorVersion = false;
for (int i = 0; i < versions.size(); i++) {
Document version = versions.get(i);
f = createResult(FAILURE, "Version " + i + " is null!");
addResult(results, assertNotNull(version, null, f));
if (version == null) {
continue;
}
addResult(results, checkObject(session, version, properties, "Version check: " + version.getId()));
// check first entry
if (i == 0) {
if (version.isVersionSeriesCheckedOut()) {
f = createResult(WARNING, "Version series is checked-out and the PWC is not the latest version! ID: " + version.getId() + " (Note: The words of the CMIS specification define that the PWC is the latest version." + " But that is not the intention of the spec and will be changed in CMIS 1.1." + " Thus this a warning, not an error.)");
addResult(results, assertIsTrue(version.isLatestVersion(), null, f));
} else {
f = createResult(FAILURE, "Version series is not checked-out and first version history entry is not the latest version! ID: " + version.getId());
addResult(results, assertIsTrue(version.isLatestVersion(), null, f));
}
}
// check version ID
f = createResult(FAILURE, "Version series id does not match! ID: " + version.getId());
addResult(results, assertEquals(versionSeriesId, version.getVersionSeriesId(), null, f));
// check creation date
if (creatationDate == version.getCreationDate().getTimeInMillis()) {
addResult(results, createResult(WARNING, "Two or more versions have the same creation date!"));
} else {
f = createResult(FAILURE, "Version history order incorrect! Must be sorted bei creation date!");
addResult(results, assertIsTrue(version.getCreationDate().getTimeInMillis() <= creatationDate, null, f));
}
// count latest versions and latest major versions
if (version.isLatestVersion()) {
latestVersion++;
}
if (version.isLatestMajorVersion()) {
latestMajorVersion++;
}
// find latest modification date
if (latestModificationDate == version.getLastModificationDate().getTimeInMillis()) {
addResult(results, createResult(WARNING, "Two or more versions have the same last modification date!"));
} else if (latestModificationDate < version.getLastModificationDate().getTimeInMillis()) {
latestModificationDate = version.getLastModificationDate().getTimeInMillis();
latestModifictaionIndex = i;
}
// check for version label duplicates
String versionLabel = version.getVersionLabel();
f = createResult(WARNING, "More than one version have this version label: " + versionLabel);
addResult(results, assertIsFalse(versionLabels.contains(versionLabel), null, f));
versionLabels.add(versionLabel);
// check PWC
if (version.getId().equals(version.getVersionSeriesCheckedOutId())) {
f = createResult(FAILURE, "PWC must not be flagged as latest major version! ID: " + version.getId());
addResult(results, assertIsFalse(version.isLatestMajorVersion(), null, f));
}
// check checked out
if (Boolean.TRUE.equals(doc.isVersionSeriesCheckedOut())) {
f = createResult(WARNING, "Version series is marked as checked out but cmis:versionSeriesCheckedOutId is not set! ID: " + version.getId());
addResult(results, assertStringNotEmpty(doc.getVersionSeriesCheckedOutId(), null, f));
f = createResult(WARNING, "Version series is marked as checked out but cmis:versionSeriesCheckedOutBy is not set! ID: " + version.getId());
addResult(results, assertStringNotEmpty(doc.getVersionSeriesCheckedOutBy(), null, f));
} else if (Boolean.FALSE.equals(doc.isVersionSeriesCheckedOut())) {
f = createResult(FAILURE, "Version series is not marked as checked out but cmis:versionSeriesCheckedOutId is set! ID: " + version.getId());
addResult(results, assertNull(doc.getVersionSeriesCheckedOutId(), null, f));
f = createResult(FAILURE, "Version series is not marked as checked out but cmis:versionSeriesCheckedOutIdBy is set! ID: " + version.getId());
addResult(results, assertNull(doc.getVersionSeriesCheckedOutBy(), null, f));
}
// found origin object?
if (version.getId().equals(object.getId())) {
found = true;
}
// found latest version?
if (version.getId().equals(lastestVersion.getId())) {
foundLastestVersion = true;
}
// found latest major version?
if (lastestMajorVersion != null && version.getId().equals(lastestMajorVersion.getId())) {
foundLastestMajorVersion = true;
}
}
// check latest versions
f = createResult(FAILURE, "Version series ID has " + latestVersion + " latest versions! There must be only one!");
addResult(results, assertEquals(1, latestVersion, null, f));
if (!foundLastestVersion) {
addResult(results, createResult(FAILURE, "Latest version not found in version history!"));
}
// check latest major versions
if (lastestMajorVersion == null) {
f = createResult(FAILURE, "Version series ID has " + latestMajorVersion + " latest major version(s) but getObjectOfLatestVersion() didn't return a major version!");
addResult(results, assertEquals(0, latestMajorVersion, null, f));
} else {
f = createResult(FAILURE, "Version series ID has " + latestMajorVersion + " latest major versions but there should be exactly one!");
addResult(results, assertEquals(1, latestMajorVersion, null, f));
if (!foundLastestMajorVersion) {
addResult(results, createResult(FAILURE, "Latest major version not found in version history!"));
}
}
// check latest version
if (latestModifictaionIndex >= 0) {
f = createResult(FAILURE, "Version with the latest modification date is not flagged as latest version! ID: " + versions.get(latestModifictaionIndex));
addResult(results, assertIsTrue(versions.get(latestModifictaionIndex).isLatestVersion(), null, f));
}
// check if the origin object was found
if (!found) {
addResult(results, createResult(FAILURE, "Document not found in its version history!"));
}
}
CmisTestResultImpl result = createResult(getWorst(results), message);
result.getChildren().addAll(results);
return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method checkDocumentContent.
private void checkDocumentContent(Session session, List<CmisTestResult> results, CmisObject object) {
if (!(object instanceof Document)) {
// only documents have content
return;
}
CmisTestResult f;
Document doc = (Document) object;
DocumentTypeDefinition type = (DocumentTypeDefinition) doc.getType();
// check ContentStreamAllowed flag
boolean hasContentProperties = (doc.getContentStreamFileName() != null) || (doc.getContentStreamId() != null) || (doc.getContentStreamLength() > -1) || (doc.getContentStreamMimeType() != null);
if (hasContentProperties) {
if (type.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
addResult(results, createResult(FAILURE, "Content properties have values but the document type doesn't allow content!"));
}
} else {
if (type.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
addResult(results, createResult(FAILURE, "Content properties are not set but the document type demands content!"));
}
}
// get the content stream
ContentStream contentStream = doc.getContentStream();
if (contentStream == null) {
if (hasContentProperties && doc.getContentStreamLength() > 0) {
addResult(results, createResult(FAILURE, "Content properties have values but the document has no content!"));
}
if (type.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
addResult(results, createResult(FAILURE, "The document type demands content but the document has no content!"));
}
return;
}
if (type.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
addResult(results, createResult(FAILURE, "Document type doesn't allow content but document has content!"));
}
// file name check
f = createResult(FAILURE, "Content file names don't match!");
addResult(results, assertEquals(doc.getContentStreamFileName(), contentStream.getFileName(), null, f));
if (doc.getContentStreamLength() > -1 && contentStream.getLength() > -1) {
f = createResult(FAILURE, "Content lengths don't match!");
addResult(results, assertEquals(doc.getContentStreamLength(), contentStream.getLength(), null, f));
}
// MIME type check
String docMimeType = doc.getContentStreamMimeType();
if (docMimeType != null) {
int x = docMimeType.indexOf(';');
if (x > -1) {
docMimeType = docMimeType.substring(0, x);
}
docMimeType = docMimeType.trim();
}
String contentMimeType = contentStream.getMimeType();
if (contentMimeType != null) {
int x = contentMimeType.indexOf(';');
if (x > -1) {
contentMimeType = contentMimeType.substring(0, x);
}
contentMimeType = contentMimeType.trim();
}
f = createResult(FAILURE, "Content MIME types don't match!");
addResult(results, assertEquals(docMimeType, contentMimeType, null, f));
if (contentStream.getMimeType() != null) {
if (contentMimeType.equals(docMimeType)) {
f = createResult(WARNING, "Content MIME types don't match!");
addResult(results, assertEquals(doc.getContentStreamMimeType(), contentStream.getMimeType(), null, f));
}
f = createResult(FAILURE, "Content MIME types is invalid: " + contentStream.getMimeType());
addResult(results, assertIsTrue(contentStream.getMimeType().length() > 2 && contentStream.getMimeType().indexOf('/') > 0, null, f));
}
// check stream
InputStream stream = contentStream.getStream();
if (stream == null) {
addResult(results, createResult(FAILURE, "Docuemnt has no content stream!"));
return;
}
try {
long bytes = 0;
byte[] buffer = new byte[64 * 1024];
int b = stream.read(buffer);
while (b > -1) {
bytes += b;
b = stream.read(buffer);
}
stream.close();
// check content length
if (doc.getContentStreamLength() > -1) {
f = createResult(FAILURE, "Content stream length property value doesn't match the actual content length!");
addResult(results, assertEquals(doc.getContentStreamLength(), bytes, null, f));
}
if (contentStream.getLength() > -1) {
f = createResult(FAILURE, "Content length value doesn't match the actual content length!");
addResult(results, assertEquals(contentStream.getLength(), bytes, null, f));
}
} catch (Exception e) {
addResult(results, createResult(FAILURE, "Reading content failed: " + e, e, false));
} finally {
IOUtils.closeQuietly(stream);
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createDocument.
/**
* Creates a document.
*/
protected Document createDocument(Session session, Folder parent, String name, String objectTypeId, String[] secondaryTypeIds, String content) {
if (parent == null) {
throw new IllegalArgumentException("Parent is not set!");
}
if (name == null) {
throw new IllegalArgumentException("Name is not set!");
}
if (objectTypeId == null) {
throw new IllegalArgumentException("Object Type ID is not set!");
}
if (content == null) {
content = "";
}
// check type
ObjectType type;
try {
type = session.getTypeDefinition(objectTypeId);
} catch (CmisObjectNotFoundException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Document type '" + objectTypeId + "' is not creatable!", true));
return null;
}
// create
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
if (secondaryTypeIds != null) {
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList(secondaryTypeIds));
}
type = session.getTypeDefinition(objectTypeId);
if (!(type instanceof DocumentTypeDefinition)) {
addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
return null;
}
DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
byte[] contentBytes = null;
Document result = null;
try {
contentBytes = IOUtils.toUTF8Bytes(content);
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 content length
f = createResult(WARNING, "Content length does not match!", false);
addResult(assertEquals((long) contentBytes.length, result.getContentStreamLength(), 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 and the filename of the content stream do 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!"));
}
} catch (IOException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Content of newly created document couldn't be read! Exception: " + e.getMessage(), e, true));
}
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created document is invalid! Exception: " + e.getMessage(), e, true));
}
// check parents
List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
boolean found = false;
for (Folder folder : parents) {
if (parent.getId().equals(folder.getId())) {
found = true;
break;
}
}
if (!found) {
addResult(createResult(FAILURE, "The folder the document has been created in is not in the list of the document parents!"));
}
return result;
}
Aggregations