use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class VersionDeleteTest method run.
@Override
public void run(Session session) {
try {
// create folder and document
Folder testFolder = createTestFolder(session);
Document doc = createDocument(session, testFolder, "versiondeletetest.txt", "v1");
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
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();
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class VersionDeleteTest method createVersion.
private Document createVersion(Session session, Document doc, String content, int version) {
CmisTestResult f;
// check out
ObjectId pwcId = doc.checkOut();
Document pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC " + version + " compliance"));
// check in
byte[] contentBytes = IOUtils.toUTF8Bytes(content);
ContentStream contentStream = new ContentStreamImpl(doc.getName(), BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
ObjectId newVersionId = pwc.checkIn(true, null, contentStream, "test version " + version);
IOUtils.closeQuietly(contentStream);
Document newVersion = (Document) session.getObject(newVersionId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, newVersion, getAllProperties(newVersion), "Version " + version + " compliance"));
// check version history
List<Document> versions = doc.getAllVersions();
f = createResult(FAILURE, "Version series should have " + version + " versions but has " + versions.size() + "!");
addResult(assertEquals(version, versions.size(), null, f));
if (!versions.isEmpty()) {
f = createResult(FAILURE, "Newly created version " + version + " is not the latest version!");
addResult(assertEquals(newVersion.getId(), versions.get(0).getId(), null, f));
if (versions.size() > 1) {
f = createResult(FAILURE, "The previous version of version " + version + " is not the document it has been created from!");
addResult(assertEquals(doc.getId(), versions.get(1).getId(), null, f));
}
}
return newVersion;
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class VerStateCreateForCustomTypeTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
DocumentTypeDefinition docType = null;
try {
// create folder and document
Folder testFolder = createTestFolder(session);
ObjectType parentType = session.getTypeDefinition(getDocumentTestTypeId());
docType = createTypeWithProperties(session, parentType);
if (!docType.isVersionable()) {
addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
return;
}
// major version
Document docMajor = testFolder.createDocument(getProperties("major.txt", docType), 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", docType), 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", docType), 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();
deleteType(session, docType.getId());
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class VersioningSmokeTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
try {
// create folder and document
Folder testFolder = createTestFolder(session);
Document doc = createDocument(session, testFolder, "versioningtest.txt", "versioning");
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
if (!docType.isVersionable()) {
addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
doc.delete(true);
return;
}
// gather properties for later
String[] propertiesToCheck = new String[doc.getType().getPropertyDefinitions().size()];
int i = 0;
for (String propId : doc.getType().getPropertyDefinitions().keySet()) {
propertiesToCheck[i++] = propId;
}
Map<String, Object> writableProperties = new HashMap<String, Object>();
for (Property<?> property : doc.getProperties()) {
if (property.getDefinition().getUpdatability() == Updatability.READWRITE) {
writableProperties.put(property.getId(), property.getValue());
}
}
// check out
ObjectId pwcId = doc.checkOut();
Document pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 1"));
checkCheckedOut(pwc);
// check version series
addResult(checkVersionSeries(session, pwc.getAllVersions(SELECT_ALL_NO_CACHE_OC), propertiesToCheck, "Test version series after check out"));
// cancel checkout
pwc.cancelCheckOut();
doc.refresh();
checkCheckedIn(doc);
// check out again
pwcId = doc.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 2"));
checkCheckedOut(pwc);
// check in
ObjectId newVersionId = pwc.checkIn(true, null, null, "Test Version 2");
Document newVersion = (Document) session.getObject(newVersionId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, newVersion, getAllProperties(newVersion), "New version compliance"));
checkCheckedIn(newVersion);
// check version history
List<Document> versions = newVersion.getAllVersions(SELECT_ALL_NO_CACHE_OC);
f = createResult(FAILURE, "Version series should have 2 versions but has " + versions.size() + "!");
addResult(assertEquals(2, versions.size(), null, f));
if (!versions.isEmpty()) {
f = createResult(FAILURE, "Version history order is incorrect! The first version should be the new version.");
addResult(assertEquals(newVersion.getId(), versions.get(0).getId(), null, f));
f = createResult(FAILURE, "The new version should be the latest version, but cmis:isLatestVersion is not TRUE.");
addResult(assertEquals(true, versions.get(0).isLatestVersion(), null, f));
f = createResult(FAILURE, "The new version should be the latest major version, but cmis:isLatestMajorVersion is not TRUE.");
addResult(assertEquals(true, versions.get(0).isLatestMajorVersion(), null, f));
}
if (versions.size() > 1) {
f = createResult(FAILURE, "Version history order is incorrect! The second version should be the origin document.");
addResult(assertEquals(doc.getId(), versions.get(1).getId(), null, f));
}
// check version series
addResult(checkVersionSeries(session, versions, propertiesToCheck, "Test version series after check in"));
// check out again
pwcId = newVersion.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 3"));
checkCheckedOut(pwc);
// check in giving back all updateable properties
ObjectId thirdVersionId = pwc.checkIn(true, writableProperties, null, "Test Version 3");
Document thirdVersion = (Document) session.getObject(thirdVersionId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, thirdVersion, getAllProperties(thirdVersion), "New version compliance"));
// check out again
pwcId = thirdVersion.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 4"));
checkCheckedOut(pwc);
// check in giving a new content stream
String fourthContent = "new content";
byte[] fourthContentBytes = IOUtils.toUTF8Bytes(fourthContent);
ContentStream fourthContentStream = new ContentStreamImpl("version4", BigInteger.valueOf(fourthContentBytes.length), "text/plain", new ByteArrayInputStream(fourthContentBytes));
ObjectId fourthVersionId = pwc.checkIn(true, null, fourthContentStream, "Test Version 5");
Document fourthVersion = (Document) session.getObject(fourthVersionId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, fourthVersion, getAllProperties(fourthVersion), "New version compliance"));
checkCheckedIn(fourthVersion);
// check out again
pwcId = fourthVersion.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 5"));
checkCheckedOut(pwc);
// check in giving properties and a new content stream
String fifthContent = "brand-new content";
byte[] fifthContentBytes = IOUtils.toUTF8Bytes(fifthContent);
ContentStream fifthContentStream = new ContentStreamImpl("version5", BigInteger.valueOf(fifthContentBytes.length), "text/plain", new ByteArrayInputStream(fifthContentBytes));
ObjectId fifthVersionId = pwc.checkIn(true, writableProperties, fifthContentStream, "Test Version 5");
Document fifthVersion = (Document) session.getObject(fifthVersionId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, fifthVersion, getAllProperties(fifthVersion), "New version compliance"));
checkCheckedIn(fifthVersion);
// test the latest version
Document latest = session.getLatestDocumentVersion(doc, SELECT_ALL_NO_CACHE_OC);
f = createResult(FAILURE, "getObjectOfLatestVersion() did not return the expected version!");
addResult(assertEquals(fifthVersion.getId(), latest.getId(), null, f));
// repository
try {
pwcId = doc.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
pwc.cancelCheckOut();
addResult(createInfoResult("Repository allows check out on a version that is not the latest version."));
} catch (CmisBaseException e) {
addResult(createInfoResult("Repository only support check out on the latest version."));
}
// remove the document
deleteObject(doc);
// test if all versions have been deleted
f = createResult(FAILURE, "Version 2 has not been deleted!");
addResult(assertIsFalse(session.exists(newVersion), null, f));
f = createResult(FAILURE, "Version 3 has not been deleted!");
addResult(assertIsFalse(session.exists(thirdVersion), null, f));
f = createResult(FAILURE, "Version 4 has not been deleted!");
addResult(assertIsFalse(session.exists(fourthVersion), null, f));
f = createResult(FAILURE, "Version 5 has not been deleted!");
addResult(assertIsFalse(session.exists(fifthVersion), null, f));
} finally {
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class OperationContextTest method runHighLevelApiTests.
/**
* Checks for not requested properties, Allowable Actions, ACLs, renditions,
* relationships, and policies.
*/
public void runHighLevelApiTests(Session session, Folder testFolder, Document testDocument) {
CmisTestResult f;
// only select some base properties
Set<String> properties = new HashSet<String>();
properties.add("cmis:objectId");
properties.add("cmis:baseTypeId");
properties.add("cmis:objectTypeId");
OperationContext context = session.createOperationContext();
context.setCacheEnabled(false);
context.setFilter(properties);
context.setIncludeAcls(false);
context.setIncludeAllowableActions(false);
context.setIncludePathSegments(false);
context.setIncludePolicies(false);
context.setIncludeRelationships(IncludeRelationships.NONE);
context.setLoadSecondaryTypeProperties(false);
context.setRenditionFilterString("cmis:none");
// get the object with the OperationContext
Document doc1 = (Document) session.getObject(testDocument, context);
// check properties
for (Property<?> prop : doc1.getProperties()) {
if (!properties.contains(prop.getDefinition().getQueryName())) {
addResult(createResult(CmisTestResultStatus.WARNING, "getObject() delivered the property '" + prop.getId() + "', although it has not been requested."));
}
}
// check other details
f = createResult(CmisTestResultStatus.WARNING, "getObject() delivered ACLs, although they have not been requested.");
addResult(assertNull(doc1.getAcl(), null, f));
f = createResult(CmisTestResultStatus.WARNING, "getObject() delivered Allowable Actions, although they have not been requested.");
addResult(assertNull(doc1.getAllowableActions(), null, f));
f = createResult(CmisTestResultStatus.WARNING, "getObject() delivered policies, although they have not been requested.");
addResult(assertListNullOrEmpty(doc1.getPolicies(), null, f));
f = createResult(CmisTestResultStatus.WARNING, "getObject() delivered relationships, although they have not been requested.");
addResult(assertListNullOrEmpty(doc1.getRelationships(), null, f));
f = createResult(CmisTestResultStatus.WARNING, "getObject() delivered renditions, although they have not been requested.");
addResult(assertListNullOrEmpty(doc1.getRenditions(), null, f));
// get the test folder children with the OperationContext
for (CmisObject child : testFolder.getChildren(context)) {
if (child.getId().equals(testDocument.getId())) {
// check properties
for (Property<?> prop : child.getProperties()) {
if (!properties.contains(prop.getDefinition().getQueryName())) {
addResult(createResult(CmisTestResultStatus.WARNING, "getChildren() delivered the property '" + prop.getId() + "', although it has not been requested."));
}
}
// check other details
f = createResult(CmisTestResultStatus.INFO, "getChildren() delivered ACLs, which is not required.");
addResult(assertNull(child.getAcl(), null, f));
f = createResult(CmisTestResultStatus.WARNING, "getChildren() delivered Allowable Actions, although they have not been requested.");
addResult(assertNull(child.getAllowableActions(), null, f));
f = createResult(CmisTestResultStatus.INFO, "getChildren() delivered policies, which is not required.");
addResult(assertListNullOrEmpty(child.getPolicies(), null, f));
f = createResult(CmisTestResultStatus.WARNING, "getChildren() delivered relationships, although they have not been requested.");
addResult(assertListNullOrEmpty(child.getRelationships(), null, f));
f = createResult(CmisTestResultStatus.WARNING, "getChildren() delivered renditions, although they have not been requested.");
addResult(assertListNullOrEmpty(child.getRenditions(), null, f));
break;
}
}
}
Aggregations