use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.
the class CheckedOutTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
boolean supportsOrderByName = isOrderByNameSupported(session);
OperationContext orderContext = (supportsOrderByName ? SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME : SELECT_ALL_NO_CACHE_OC);
Document pwc = null;
try {
// create folder and a checked-out document
Folder testFolder = createTestFolder(session);
Document doc = createDocument(session, testFolder, "checkedouttest.txt", "checked out");
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
if (!docType.isVersionable()) {
addResult(createResult(WARNING, "Test type is not versionable. Check out skipped!"));
} else {
ObjectId pwcId = doc.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
}
// test all checked-out documents
int sessionCheckedOut = checkPWCs(session, session.getCheckedOutDocs(orderContext), supportsOrderByName);
addResult(createInfoResult(sessionCheckedOut + " checked out document(s) overall."));
if (pwc != null) {
f = createResult(FAILURE, "There should be at least one checked out document in the repository!");
addResult(assertIsTrue(sessionCheckedOut >= 1, null, f));
}
// test checked-out documents in the test folder
int testFolderCheckedOut = checkPWCs(session, testFolder.getCheckedOutDocs(orderContext), supportsOrderByName);
addResult(createInfoResult(testFolderCheckedOut + " checked out document(s) in the test folder."));
if (pwc != null) {
f = createResult(FAILURE, "There should be at least one checked out document in the test folder!");
addResult(assertIsTrue(testFolderCheckedOut >= 1, null, f));
}
// remove the PWC and document
if (pwc != null) {
pwc.cancelCheckOut();
pwc = null;
}
deleteObject(doc);
} finally {
if (pwc != null) {
pwc.cancelCheckOut();
}
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.
the class VersioningStateCreateTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
try {
// create folder and document
Folder testFolder = createTestFolder(session);
DocumentTypeDefinition docType = (DocumentTypeDefinition) session.getTypeDefinition(getDocumentTestTypeId());
if (!docType.isVersionable()) {
addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
return;
}
// major version
Document docMajor = testFolder.createDocument(getProperties("major.txt"), getContentStream(), VersioningState.MAJOR, null, null, null, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, docMajor, getAllProperties(docMajor), "Major version compliance"));
f = createResult(FAILURE, "Document should be major version.");
addResult(assertIsTrue(docMajor.isMajorVersion(), null, f));
List<Document> versions = docMajor.getAllVersions();
f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
addResult(assertEquals(1, versions.size(), null, f));
deleteObject(docMajor);
// minor version
try {
Document docMinor = testFolder.createDocument(getProperties("minor.txt"), getContentStream(), VersioningState.MINOR, null, null, null, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, docMinor, getAllProperties(docMinor), "Minor version compliance"));
f = createResult(FAILURE, "Document should be minor version.");
addResult(assertIsFalse(docMinor.isMajorVersion(), null, f));
versions = docMinor.getAllVersions();
f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
addResult(assertEquals(1, versions.size(), null, f));
deleteObject(docMinor);
} catch (CmisConstraintException ce) {
addResult(createResult(WARNING, "Creating a minor version failed! " + "The repository might not support minor versions. Exception: " + ce, ce, false));
} catch (CmisInvalidArgumentException iae) {
addResult(createResult(WARNING, "Creating a minor version failed! " + "The repository might not support minor versions. Exception: " + iae, iae, false));
}
// checked out version
try {
Document docCheckedOut = testFolder.createDocument(getProperties("checkout.txt"), getContentStream(), VersioningState.CHECKEDOUT, null, null, null, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, docCheckedOut, getAllProperties(docCheckedOut), "Checked out version compliance"));
f = createResult(FAILURE, "Version series should be checked out.");
addResult(assertIsTrue(docCheckedOut.isVersionSeriesCheckedOut(), null, f));
versions = docCheckedOut.getAllVersions();
f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
addResult(assertEquals(1, versions.size(), null, f));
docCheckedOut.cancelCheckOut();
} catch (CmisConstraintException ce) {
addResult(createResult(WARNING, "Creating a checked out version failed! " + "The repository might not support creating checked out versions. Exception: " + ce, ce, false));
} catch (CmisInvalidArgumentException iae) {
addResult(createResult(WARNING, "Creating a checked out version failed! " + "The repository might not support creating checked out versions. Exception: " + iae, iae, false));
}
} finally {
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.
the class CreateBigDocument method run.
@Override
public void run(Session session) {
CmisTestResult f;
// create a test folder
Folder testFolder = createTestFolder(session);
try {
String name = "bigdoc";
String objectTypeId = getDocumentTestTypeId();
String mimetype = "application/octet-stream";
// 10 MiB
final long size = 10 * 1024 * 1024;
InputStream in = new InputStream() {
private int counter = -1;
@Override
public int read() throws IOException {
counter++;
if (counter >= size) {
return -1;
}
return '0' + (counter / 10);
}
};
// create stream and properties
ContentStream contentStream = session.getObjectFactory().createContentStream(name, size, mimetype, in);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
// check type
TypeDefinition type = session.getTypeDefinition(objectTypeId);
if (!(type instanceof DocumentTypeDefinition)) {
addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
return;
}
DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
// create and fetch the document
ObjectId id = session.createDocument(properties, testFolder, contentStream, versioningState);
Document doc = (Document) session.getObject(id, SELECT_ALL_NO_CACHE_OC);
// check the new document
addResult(checkObject(session, doc, getAllProperties(doc), "New document object spec compliance"));
// check the size
f = createResult(FAILURE, "Content stream length doesn't match the uploaded content!", true);
assertEquals(size, doc.getContentStreamLength(), null, f);
// delete it
// doc.delete(true);
} finally {
// delete the test folder
// deleteTestFolder();
}
}
Aggregations