use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class SetAndDeleteContentTest method getNewVersion.
private Document getNewVersion(Session session, Document orgDoc, boolean checkedout, ObjectId newObjectId, String operation) {
Document result = orgDoc;
if (newObjectId != null) {
// -> Non AtomPub binding
if (!orgDoc.getId().equals(newObjectId.getId())) {
if (checkedout) {
addResult(createResult(FAILURE, operation + " created a new version from a PWC!"));
} else {
result = (Document) session.getObject(newObjectId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, result, getAllProperties(result), "Version created by " + operation + " compliance"));
}
}
} else {
if (getBinding() != BindingType.ATOMPUB) {
addResult(createResult(FAILURE, operation + " did not return an object id!"));
}
// -> AtomPub binding or incompliant other binding
if (checkedout) {
// we cannot check if the repository does the right thing,
// but if there is a problem the versioning tests should
// catch it
} else if (Boolean.TRUE.equals(((DocumentTypeDefinition) orgDoc.getType()).isVersionable())) {
List<Document> versions = orgDoc.getAllVersions();
if (versions == null || versions.isEmpty()) {
addResult(createResult(FAILURE, operation + " created a new version but the version history is empty!"));
} else if (!orgDoc.getId().equals(versions.get(0).getId())) {
result = (Document) session.getObject(versions.get(0), SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, result, getAllProperties(result), "Version created by " + operation + " compliance"));
}
}
}
return result;
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class SetAndDeleteContentTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
if (getContentStreamUpdatesCapbility(session) == CapabilityContentStreamUpdates.NONE) {
addResult(createResult(SKIPPED, "Stream updates are not supported. Test skipped!"));
return;
}
try {
// create folder and document
Folder testFolder = createTestFolder(session);
Document doc = createDocument(session, testFolder, "contenttest.txt", CONTENT1);
Document workDoc = doc;
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
// test if check out is required and possible
boolean checkedout = false;
if (!doc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) {
if (!docType.isVersionable()) {
addResult(createResult(SKIPPED, "The test document does not accept a new content stream. Test skipped!"));
doc.delete(true);
return;
} else {
workDoc = (Document) session.getObject(doc.checkOut(), SELECT_ALL_NO_CACHE_OC);
checkedout = true;
if (!workDoc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) {
addResult(createResult(SKIPPED, "The test PWC does not accept a new content stream. Test skipped!"));
workDoc.cancelCheckOut();
doc.delete(true);
return;
}
}
}
// test if the content stream can be deleted
if (docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
addResult(createResult(SKIPPED, "A content stream is required for this document type. deleteContentStream() test skipped!"));
} else {
// delete content stream
try {
ObjectId newObjectId = workDoc.deleteContentStream(true);
// deleteContentStream may have created a new version
Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "deleteContentStream()");
f = createResult(FAILURE, "Document still has content after deleteContentStream() has been called!");
addResult(assertNull(contentDoc.getContentStream(), null, f));
f = createResult(FAILURE, "Document still has a MIME type after deleteContentStream() has been called: " + contentDoc.getContentStreamMimeType());
addResult(assertNull(contentDoc.getContentStreamMimeType(), null, f));
f = createResult(FAILURE, "Document still has a content length after deleteContentStream() has been called: " + contentDoc.getContentStreamLength());
addResult(assertEquals(-1L, contentDoc.getContentStreamLength(), null, f));
f = createResult(FAILURE, "Document still has a file name after deleteContentStream() has been called: " + contentDoc.getContentStreamFileName());
addResult(assertNull(contentDoc.getContentStreamFileName(), null, f));
workDoc = contentDoc;
} catch (CmisNotSupportedException e) {
addResult(createResult(WARNING, "deleteContentStream() is not supported!"));
}
}
// set a new content stream
byte[] contentBytes = IOUtils.toUTF8Bytes(CONTENT2);
try {
ContentStream contentStream = session.getObjectFactory().createContentStream(workDoc.getName(), contentBytes.length, "text/plain", new ByteArrayInputStream(contentBytes));
ObjectId newObjectId = workDoc.setContentStream(contentStream, true, true);
IOUtils.closeQuietly(contentStream);
// setContentStream may have created a new version
Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "setContentStream()");
// test new content
try {
String content = getStringFromContentStream(contentDoc.getContentStream());
f = createResult(FAILURE, "Document content doesn't match the content set by setContentStream()!");
addResult(assertEquals(CONTENT2, content, null, f));
} catch (IOException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document content couldn't be read! Exception: " + e.getMessage(), e, true));
}
workDoc = contentDoc;
} catch (CmisNotSupportedException e) {
addResult(createResult(WARNING, "setContentStream() is not supported!"));
}
// test appendContentStream
if (session.getRepositoryInfo().getCmisVersion() != CmisVersion.CMIS_1_0) {
contentBytes = IOUtils.toUTF8Bytes(CONTENT3);
try {
ContentStream contentStream = session.getObjectFactory().createContentStream(workDoc.getName(), contentBytes.length, "text/plain", new ByteArrayInputStream(contentBytes));
ObjectId newObjectId = workDoc.appendContentStream(contentStream, true);
// appendContentStream may have created a new version
Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "appendContentStream()");
// test new content
try {
String content = getStringFromContentStream(contentDoc.getContentStream());
f = createResult(FAILURE, "Document content doesn't match the content set by setContentStream() followed by appendContentStream()!");
addResult(assertEquals(CONTENT2 + CONTENT3, content, null, f));
} catch (IOException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document content couldn't be read! Exception: " + e.getMessage(), e, true));
}
// test append stream
testAppendStream(session, testFolder, 16 * 1024);
testAppendStream(session, testFolder, 8);
testAppendStream(session, testFolder, 0);
} catch (CmisNotSupportedException e) {
addResult(createResult(WARNING, "appendContentStream() is not supported!"));
}
}
// cancel a possible check out
if (checkedout) {
workDoc.cancelCheckOut();
}
// remove the document
deleteObject(doc);
} finally {
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class VerDeleteForCustomTypeTest method run.
@Override
public void run(Session session) {
DocumentTypeDefinition docType = null;
try {
// create folder and document
Folder testFolder = createTestFolder(session);
ObjectType parentType = session.getTypeDefinition(getDocumentTestTypeId());
docType = createTypeWithProperties(session, parentType);
Document doc = testFolder.createDocument(getProperties("versiondeletetest.txt", docType), getContentStream(), null, null, null, null, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, doc, getAllProperties(doc), "Document spec compliance"));
if (!docType.isVersionable()) {
addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
doc.delete(true);
return;
}
// add versions
Document doc2 = createVersion(session, doc, "v2", 2);
Document doc3 = createVersion(session, doc2, "v3", 3);
Document doc4 = createVersion(session, doc3, "v4", 4);
// delete versions
deleteVersion(doc4, doc3, 4);
deleteVersion(doc3, doc2, 3);
deleteVersion(doc2, doc, 2);
deleteVersion(doc, null, 1);
} finally {
deleteTestFolder();
deleteType(session, docType.getId());
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class VerDeleteForCustomTypeTest method deleteVersion.
private void deleteVersion(Document versionDoc, Document previousDoc, int version) {
CmisTestResult f;
// check Allowable Action
if (!versionDoc.hasAllowableAction(Action.CAN_DELETE_OBJECT)) {
addResult(createResult(WARNING, "Version " + version + " does not have the Allowable Action 'canDeleteObject'."));
return;
}
// get version history before delete
List<Document> versionsBefore = versionDoc.getAllVersions();
// delete and check
try {
versionDoc.delete(false);
} catch (CmisInvalidArgumentException iae) {
addResult(createResult(WARNING, "Deletion of version " + version + " failed with an invalidArgument exception. " + "Removing just one version doesn't seem to be supported."));
return;
} catch (CmisConstraintException ce) {
addResult(createResult(WARNING, "Deletion of version " + version + " failed with an constraint exception. " + "Removing just one version doesn't seem to be supported."));
return;
}
f = createResult(FAILURE, "Deleted version " + version + " still exists!");
addResult(assertIsFalse(exists(versionDoc), null, f));
// check version history after delete
if (previousDoc != null) {
List<Document> versionsAfter = previousDoc.getAllVersions();
f = createResult(FAILURE, "After version " + version + " has been deleted, the version history should consist of " + (versionsBefore.size() - 1) + " documents but is has " + versionsAfter.size() + " !");
addResult(assertEquals(versionsBefore.size() - 1, versionsAfter.size(), null, f));
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class BulkUpdatePropertiesTest method run.
@Override
public void run(Session session) {
if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
addResult(createResult(SKIPPED, "Bulk Update Properties is not supported by CMIS 1.0. Test skipped!"));
return;
}
CmisTestResult failure = null;
int numOfObjects = 20;
// create a test folder
Folder testFolder = createTestFolder(session);
try {
Map<String, Folder> folders = new HashMap<String, Folder>();
Map<String, Document> documents = new HashMap<String, Document>();
// create folders and documents
for (int i = 0; i < numOfObjects; i++) {
Folder newFolder = createFolder(session, testFolder, "bufolder" + i);
folders.put(newFolder.getId(), newFolder);
Document newDocument = createDocument(session, newFolder, "budoc" + i + ".txt", CONTENT);
documents.put(newDocument.getId(), newDocument);
}
// update cmis:name of all the documents
List<CmisObject> objects = new ArrayList<CmisObject>(documents.values());
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, NEW_NAME);
List<BulkUpdateObjectIdAndChangeToken> updatedIds = session.bulkUpdateProperties(objects, properties, null, null);
// check the result
if (getBinding() == BindingType.WEBSERVICES) {
// TODO: review after TC clarification
addResult(createResult(INFO, "The Web Services binding does not return the updated ids." + " This issue has to be clarified by the CMIS TC and the test to adopted later."));
} else {
if (updatedIds == null || updatedIds.isEmpty()) {
addResult(createResult(FAILURE, "Bulk Update Properties did not update any documents!"));
} else {
failure = createResult(FAILURE, "Bulk Update Properties did not update all test documents!");
addResult(assertEquals(documents.size(), updatedIds.size(), null, failure));
}
}
// check all documents
for (Folder folder : folders.values()) {
List<CmisObject> children = new ArrayList<CmisObject>();
for (CmisObject child : folder.getChildren(SELECT_ALL_NO_CACHE_OC)) {
children.add(child);
}
if (children.size() != 1) {
addResult(createResult(FAILURE, "Test folder should have exactly one child, but it has " + children.size() + "!"));
} else {
failure = createResult(FAILURE, "Document does not have the new name! Id: " + children.get(0).getId());
addResult(assertEquals(NEW_NAME, children.get(0).getName(), null, failure));
}
}
// delete folders and documents
for (Folder folder : folders.values()) {
folder.deleteTree(true, null, true);
}
} finally {
// delete the test folder
deleteTestFolder();
}
}
Aggregations