use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class VersioningSmokeTest 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.tck.CmisTestResult 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.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class CreateAndDeleteDocumentTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
int numOfDocuments = 20;
OperationContext orderContext = isOrderByNameSupported(session) ? SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME : SELECT_ALL_NO_CACHE_OC;
// create a test folder
Folder testFolder = createTestFolder(session);
try {
Map<String, Document> documents = new HashMap<String, Document>();
Set<String> versionSeriesIds = new HashSet<String>();
// create documents
for (int i = 0; i < numOfDocuments; i++) {
Document newDocument = createDocument(session, testFolder, "doc" + i, CONTENT);
documents.put(newDocument.getId(), newDocument);
versionSeriesIds.add(newDocument.getVersionSeriesId());
}
// simple children test
addResult(checkChildren(session, testFolder, "Test folder children check"));
// check if all documents are there
ItemIterable<CmisObject> children = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC);
List<String> childrenIds = new ArrayList<String>();
for (CmisObject child : children) {
if (child != null) {
childrenIds.add(child.getId());
Document document = documents.get(child.getId());
f = createResult(FAILURE, "Document and test folder child don't match! Id: " + child.getId());
addResult(assertShallowEquals(document, child, null, f));
}
}
f = createResult(FAILURE, "Number of created documents does not match the number of existing documents!");
addResult(assertEquals(numOfDocuments, childrenIds.size(), null, f));
for (Document document : documents.values()) {
if (!childrenIds.contains(document.getId())) {
addResult(createResult(FAILURE, "Created document not found in test folder children! Id: " + document.getId()));
}
}
// check version series ids
if (Boolean.TRUE.equals(((DocumentType) documents.values().iterator().next().getType()).isVersionable())) {
f = createResult(FAILURE, "Although the created documents are independent, some documents share a Version Series Id!");
} else {
f = createResult(INFO, "Some documents share the same Version Series Id.");
}
addResult(assertEquals(numOfDocuments, versionSeriesIds.size(), null, f));
// check paging
int pageSize = 5;
CmisObject lastObject = null;
int count = 0;
ItemIterable<CmisObject> page1 = testFolder.getChildren(orderContext).getPage(pageSize);
for (CmisObject child : page1) {
count++;
lastObject = child;
}
f = createResult(FAILURE, "Returned number of children doesn't match the page size!");
addResult(assertEquals(pageSize, count, null, f));
if (page1.getTotalNumItems() == -1) {
addResult(createResult(WARNING, "Repository did not return numItems for the first test page."));
} else {
f = createResult(FAILURE, "Returned numItems doesn't match the number of documents!");
addResult(assertEquals((long) numOfDocuments, page1.getTotalNumItems(), null, f));
}
f = createResult(FAILURE, "hasMoreItems of the first test page must be TRUE!");
addResult(assertEquals(true, page1.getHasMoreItems(), null, f));
// check second page
count = 0;
ItemIterable<CmisObject> page2 = testFolder.getChildren(orderContext).skipTo(pageSize - 1).getPage(pageSize);
for (CmisObject child : page2) {
count++;
if (count == 1 && lastObject != null) {
f = createResult(FAILURE, "Last object of the first page doesn't match the first object of the second page.");
addResult(assertEquals(lastObject.getId(), child.getId(), null, f));
}
}
f = createResult(FAILURE, "Returned number of children doesn't match the page size!");
addResult(assertEquals(pageSize, count, null, f));
if (page2.getTotalNumItems() == -1) {
addResult(createResult(WARNING, "Repository did not return numItems for the second test page."));
} else {
f = createResult(FAILURE, "Returned numItems doesn't match the number of documents!");
addResult(assertEquals((long) numOfDocuments, page2.getTotalNumItems(), null, f));
}
f = createResult(FAILURE, "hasMoreItems of the second test page must be TRUE!");
addResult(assertEquals(true, page2.getHasMoreItems(), null, f));
// check third page
count = 0;
ItemIterable<CmisObject> page3 = testFolder.getChildren(orderContext).skipTo(numOfDocuments - 5).getPage(10);
for (@SuppressWarnings("unused") CmisObject child : page3) {
count++;
}
f = createResult(FAILURE, "Returned number of children should be 5 because page startetd at (numOfDocuments - 5).");
addResult(assertEquals(5, count, null, f));
if (page3.getTotalNumItems() == -1) {
addResult(createResult(WARNING, "Repository did not return numItems for the third test page."));
} else {
f = createResult(FAILURE, "Returned numItems doesn't match the number of documents!");
addResult(assertEquals((long) numOfDocuments, page3.getTotalNumItems(), null, f));
}
f = createResult(FAILURE, "hasMoreItems of the third test page must be FALSE!");
addResult(assertEquals(false, page3.getHasMoreItems(), null, f));
// check non-existing page
count = 0;
ItemIterable<CmisObject> pageNotExisting = testFolder.getChildren(orderContext).skipTo(100000).getPage(pageSize);
for (@SuppressWarnings("unused") CmisObject child : pageNotExisting) {
count++;
}
f = createResult(FAILURE, "The page size of a non-existing page must be 0!");
addResult(assertEquals(0, count, null, f));
if (pageNotExisting.getTotalNumItems() == -1) {
addResult(createResult(WARNING, "Repository did not return numItems for a non-existing page."));
} else {
f = createResult(FAILURE, "Returned numItems doesn't match the number of documents!");
addResult(assertEquals((long) numOfDocuments, pageNotExisting.getTotalNumItems(), null, f));
}
f = createResult(FAILURE, "hasMoreItems of a non-existing page must be FALSE!");
addResult(assertEquals(false, pageNotExisting.getHasMoreItems(), null, f));
// check content
for (Document document : documents.values()) {
ContentStream contentStream = document.getContentStream();
if (contentStream == null || contentStream.getStream() == null) {
addResult(createResult(FAILURE, "Document has no content! Id: " + document.getId()));
continue;
} else {
IOUtils.closeQuietly(contentStream);
}
// TODO: content checks
}
// delete all documents
for (Document document : documents.values()) {
document.delete(true);
f = createResult(FAILURE, "Document should not exist anymore but it is still there! Id: " + document.getId());
addResult(assertIsFalse(exists(document), null, f));
}
} finally {
// delete the test folder
deleteTestFolder();
}
addResult(createInfoResult("Tested the creation and deletion of " + numOfDocuments + " documents."));
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class CreateAndDeletePolicyTest method run.
@Override
public void run(Session session) {
if (hasPolicies(session)) {
CmisTestResult f;
// create a test folder
Folder testFolder = createTestFolder(session);
try {
// create policy object
Policy policy = createPolicy(session, testFolder, "testPolicy", "TCK Test Policy");
// create document and apply policy
Document doc = createDocument(session, testFolder, "testDocument", "Policy Test");
if (Boolean.TRUE.equals(doc.getType().isControllablePolicy())) {
doc.applyPolicy(policy);
// check if policy has been applied
List<Policy> policies1 = doc.getPolicies();
boolean found1 = false;
for (Policy p : policies1) {
if (p.getId().equals(policy.getId())) {
found1 = true;
break;
}
}
f = createResult(FAILURE, "Policy has not been applied to document! Policy Id: " + policy.getId() + ", Doc Id: " + doc.getId());
addResult(assertIsTrue(found1, null, f));
// get the policies
List<ObjectData> policiesData2 = session.getBinding().getPolicyService().getAppliedPolicies(session.getRepositoryInfo().getId(), doc.getId(), "*", null);
boolean found2 = false;
if (policiesData2 != null && !policiesData2.isEmpty()) {
for (ObjectData p : policiesData2) {
if (p.getId().equals(policy.getId())) {
found2 = true;
break;
}
}
}
f = createResult(FAILURE, "Applied policy is not returned by the repository! Policy Id: " + policy.getId() + ", Doc Id: " + doc.getId());
addResult(assertIsTrue(found2, null, f));
// remove policy
doc.removePolicy(policy);
// check if policy has been applied
List<Policy> policies3 = doc.getPolicies();
if (policies3 != null) {
boolean found3 = false;
for (Policy p : policies3) {
if (p.getId().equals(policy.getId())) {
found3 = true;
break;
}
}
f = createResult(FAILURE, "Policy has not been removed from document! Policy Id: " + policy.getId() + ", Doc Id: " + doc.getId());
addResult(assertIsFalse(found3, null, f));
}
} else {
addResult(createResult(INFO, "Document type " + doc.getType().getId() + " does not allow applying and removing policies. Choose a different document type for this test."));
}
// delete document
deleteObject(doc);
// delete policy object
deleteObject(policy);
} finally {
// delete the test folder
deleteTestFolder();
}
} else {
addResult(createResult(SKIPPED, "Policies not supported. Test skipped!"));
}
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class CreateAndDeleteRelationshipTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
boolean found;
if (hasRelationships(session)) {
// create a test folder
Folder testFolder = createTestFolder(session);
try {
// create documents
Document doc1 = createDocument(session, testFolder, "doc1.txt", "doc1");
Document doc2 = createDocument(session, testFolder, "doc2.txt", "doc2");
// create relationship
Relationship rel = createRelationship(session, "rel1", doc1, doc2);
f = createResult(FAILURE, "Source document id does not match relationship source id!");
addResult(assertEquals(doc1.getId(), rel.getSourceId().getId(), null, f));
f = createResult(FAILURE, "Target document id does not match relationship target id!");
addResult(assertEquals(doc2.getId(), rel.getTarget().getId(), null, f));
// check the source document
doc1.refresh();
List<Relationship> doc1rels = doc1.getRelationships();
f = createResult(FAILURE, "Source document has no relationships but must have at least one!");
addResult(assertListNotEmpty(doc1rels, null, f));
if (doc1rels != null) {
found = false;
for (Relationship r : doc1rels) {
if (rel.getId().equals(r.getId())) {
found = true;
break;
}
}
f = createResult(FAILURE, "Newly created relationship not found in the relationships of the source document!");
addResult(assertIsTrue(found, null, f));
}
found = false;
for (Relationship r : session.getRelationships(doc1, true, RelationshipDirection.SOURCE, null, SELECT_ALL_NO_CACHE_OC)) {
if (rel.getId().equals(r.getId())) {
found = true;
break;
}
}
f = createResult(FAILURE, "Newly created relationship not found in the relationships returned by getObjectRelationships() for the source document!");
addResult(assertIsTrue(found, null, f));
// check the target document
doc2.refresh();
List<Relationship> doc2rels = doc2.getRelationships();
f = createResult(FAILURE, "Target document has no relationships but must have at least one!");
addResult(assertListNotEmpty(doc2rels, null, f));
if (doc2rels != null) {
found = false;
for (Relationship r : doc2rels) {
if (rel.getId().equals(r.getId())) {
found = true;
break;
}
}
f = createResult(FAILURE, "Newly created relationship not found in the relationships of the target document!");
addResult(assertIsTrue(found, null, f));
}
found = false;
for (Relationship r : session.getRelationships(doc2, true, RelationshipDirection.TARGET, null, SELECT_ALL_NO_CACHE_OC)) {
if (rel.getId().equals(r.getId())) {
found = true;
break;
}
}
f = createResult(FAILURE, "Newly created relationship not found in the relationships returned by getObjectRelationships() for the target document!");
addResult(assertIsTrue(found, null, f));
// remove
deleteObject(rel);
deleteObject(doc2);
deleteObject(doc1);
} finally {
// delete the test folder
deleteTestFolder();
}
} else {
addResult(createResult(SKIPPED, "Relationships not supported. Test skipped!"));
}
}
Aggregations