use of org.apache.chemistry.opencmis.commons.enums.VersioningState in project copper-cms by PogeyanOSS.
the class CreateDocumentWithoutContent method run.
@Override
public void run(Session session) {
CmisTestResult f;
String objectTypeId = getDocumentTestTypeId();
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;
if (docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
addResult(createResult(SKIPPED, "The test document type does not support documents without content. Test skipped!"));
return;
}
// create a test folder
Folder testFolder = createTestFolder(session);
try {
String name = "nocontent";
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
// create and fetch the document
ObjectId id = session.createDocument(properties, testFolder, null, 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 MIME type
f = createResult(FAILURE, "The document has no content but a MIME type!", true);
assertNull(doc.getContentStreamMimeType(), null, f);
// check the content size
if (doc.getContentStreamLength() == 0) {
addResult(createResult(WARNING, "The document has no content but the content length is set to 0! " + "The content length shouldn't be set."));
} else if (doc.getContentStreamLength() > 0) {
addResult(createResult(FAILURE, "The document has no content but the content length is set and >0! " + "(content length: " + doc.getContentStreamLength() + ")"));
}
// delete it
doc.delete(true);
} finally {
// delete the test folder
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.commons.enums.VersioningState 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