use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class CheckedOutTest method checkPWCs.
private int checkPWCs(Session session, ItemIterable<Document> pwcs, boolean checkOrder) {
if (pwcs == null) {
return 0;
}
CmisTestResult f;
int i = 0;
int orderByNameIssues = 0;
String lastName = null;
for (Document pwc : pwcs) {
if (pwc == null) {
addResult(createResult(FAILURE, "The list of checked out documents contains a null entry!"));
continue;
}
String[] propertiesToCheck = getAllProperties(pwc);
addResult(checkObject(session, pwc, propertiesToCheck, "PWC check: " + pwc.getId()));
if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
f = createResult(WARNING, "PWC is not the latest version! Id: " + pwc.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(assertIsTrue(pwc.isLatestVersion(), null, f));
} else {
f = createResult(FAILURE, "The property value of 'cmis:isLatestVersion' is TRUE for a PWC! Id: " + pwc.getId());
addResult(assertIsFalse(pwc.isLatestVersion(), null, f));
f = createResult(FAILURE, "The property value of 'cmis:isLatestMajorVersion' is TRUE for a PWC! Id: " + pwc.getId());
addResult(assertIsFalse(pwc.isLatestMajorVersion(), null, f));
}
if (lastName != null && pwc.getName() != null) {
if (pwc.getName().compareToIgnoreCase(lastName) < 0) {
orderByNameIssues++;
}
}
lastName = pwc.getName();
i++;
}
if (checkOrder) {
f = createResult(WARNING, "Checked-out documents should be ordered by cmis:name, but they are not! (It might be a collation mismatch.)");
addResult(assertEquals(0, orderByNameIssues, null, f));
} else {
addResult(createResult(INFO, "Repository doesn't support Order By for getCheckedOutDocs()."));
}
return i;
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class LatestAccessibleStateIdTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
try {
// create folder and document
Folder testFolder = createTestFolder(session);
Document doc = createDocument(session, testFolder, "lateststate.txt", "latest state");
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
if (!docType.getPropertyDefinitions().containsKey(PropertyIds.LATEST_ACCESSIBLE_STATE_ID)) {
addResult(createResult(SKIPPED, "Repository does not support the Latest State Identifier feature extension. Test skipped!"));
doc.delete(true);
return;
}
// check latest accessible state ID
f = createResult(FAILURE, "Latest Accessible State ID is not set!");
addResult(assertStringNotEmpty(doc.getLatestAccessibleStateId(), null, f));
// get document with latest accessible state ID
try {
CmisObject latestStateObject = session.getObject(doc.getLatestAccessibleStateId(), SELECT_ALL_NO_CACHE_OC);
if (latestStateObject instanceof Document) {
f = createResult(FAILURE, "Latest Accessible State IDs of the orignal and the retrieved document don't match!");
addResult(assertEquals(doc.getLatestAccessibleStateId(), ((Document) latestStateObject).getLatestAccessibleStateId(), null, f));
} else {
addResult(createResult(FAILURE, "Object retrieved with the Latest Accessible State ID is not a document!"));
}
} catch (CmisObjectNotFoundException onf) {
addResult(createResult(FAILURE, "Document could not be retrieved with the Latest Accessible State ID!"));
}
doc.delete(true);
} finally {
// delete the test folder
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class VerSmokeForCustomTypeTest method run.
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;
}
// 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);
CmisTestResultImpl 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();
deleteType(session, docType.getId());
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project copper-cms by PogeyanOSS.
the class VerSmokeForCustomTypeTest method checkVersionSeries.
private CmisTestResult checkVersionSeries(Session session, List<Document> versions, String[] properties, String message) {
List<CmisTestResult> results = new ArrayList<CmisTestResult>();
CmisTestResult f;
// make sure there is only one latest version
// and zero or one latest major version
int countLatest = 0;
int countLatestMajor = 0;
String latestId = null;
for (Document version : versions) {
addResult(results, checkObject(session, version, properties, "Version object check: " + version.getId()));
if (Boolean.TRUE.equals(version.isLatestVersion())) {
countLatest++;
latestId = version.getId();
}
if (Boolean.TRUE.equals(version.isLatestMajorVersion())) {
countLatestMajor++;
}
}
f = createResult(FAILURE, "The version series must have exactly one latest version, but it has " + countLatest + "!");
addResult(results, assertEquals(1, countLatest, null, f));
f = createResult(FAILURE, "The version series must have zero or one latest major version, but it has " + countLatestMajor + "!");
addResult(results, assertIsTrue(countLatestMajor < 2, null, f));
// check getObjectOfLatestVersion()
if (countLatest == 1) {
Document latestVersion = versions.get(0).getObjectOfLatestVersion(false, SELECT_ALL_NO_CACHE_OC);
addResult(results, checkObject(session, latestVersion, properties, "Latest version object check: " + latestVersion.getId()));
f = createResult(FAILURE, "The version that is flagged as latest version is not returned by getObjectOfLatestVersion()!");
addResult(results, assertEquals(latestId, latestVersion.getId(), null, f));
// check with session.getLatestDocumentVersion()
Document latestVersion2 = session.getLatestDocumentVersion(versions.get(versions.size() - 1).getId(), SELECT_ALL_NO_CACHE_OC);
addResult(results, checkObject(session, latestVersion2, properties, "Latest version object check (2): " + latestVersion2.getId()));
f = createResult(FAILURE, "The version that is flagged as latest version is not returned by getObjectOfLatestVersion()!");
addResult(results, assertEquals(latestId, latestVersion2.getId(), null, f));
}
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 VerSmokeForCustomTypeTestWithoutContentStream method checkVersionSeries.
private CmisTestResult checkVersionSeries(Session session, List<Document> versions, String[] properties, String message) {
List<CmisTestResult> results = new ArrayList<CmisTestResult>();
CmisTestResult f;
// make sure there is only one latest version
// and zero or one latest major version
int countLatest = 0;
int countLatestMajor = 0;
String latestId = null;
for (Document version : versions) {
addResult(results, checkObject(session, version, properties, "Version object check: " + version.getId()));
if (Boolean.TRUE.equals(version.isLatestVersion())) {
countLatest++;
latestId = version.getId();
}
if (Boolean.TRUE.equals(version.isLatestMajorVersion())) {
countLatestMajor++;
}
}
f = createResult(FAILURE, "The version series must have exactly one latest version, but it has " + countLatest + "!");
addResult(results, assertEquals(1, countLatest, null, f));
f = createResult(FAILURE, "The version series must have zero or one latest major version, but it has " + countLatestMajor + "!");
addResult(results, assertIsTrue(countLatestMajor < 2, null, f));
// check getObjectOfLatestVersion()
if (countLatest == 1) {
Document latestVersion = versions.get(0).getObjectOfLatestVersion(false, SELECT_ALL_NO_CACHE_OC);
addResult(results, checkObject(session, latestVersion, properties, "Latest version object check: " + latestVersion.getId()));
f = createResult(FAILURE, "The version that is flagged as latest version is not returned by getObjectOfLatestVersion()!");
addResult(results, assertEquals(latestId, latestVersion.getId(), null, f));
// check with session.getLatestDocumentVersion()
Document latestVersion2 = session.getLatestDocumentVersion(versions.get(versions.size() - 1).getId(), SELECT_ALL_NO_CACHE_OC);
addResult(results, checkObject(session, latestVersion2, properties, "Latest version object check (2): " + latestVersion2.getId()));
f = createResult(FAILURE, "The version that is flagged as latest version is not returned by getObjectOfLatestVersion()!");
addResult(results, assertEquals(latestId, latestVersion2.getId(), null, f));
}
CmisTestResultImpl result = createResult(getWorst(results), message);
result.getChildren().addAll(results);
return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
Aggregations