use of org.apache.chemistry.opencmis.client.api.Tree in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method checkChildren.
protected CmisTestResult checkChildren(Session session, Folder folder, String message) {
List<CmisTestResult> results = new ArrayList<CmisTestResult>();
CmisTestResult f;
if (folder == null) {
return createResult(FAILURE, "Folder is null!");
}
// getChildren
boolean supportsOrderByName = isOrderByNameSupported(session);
OperationContext orderContext = (supportsOrderByName ? SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME : SELECT_ALL_NO_CACHE_OC);
long childrenCount = 0;
long childrenFolderCount = 0;
ItemIterable<CmisObject> children = folder.getChildren(orderContext);
int orderByNameIssues = 0;
String lastName = null;
for (CmisObject child : children) {
childrenCount++;
if (child instanceof Folder) {
childrenFolderCount++;
}
checkChild(session, results, folder, child);
if (lastName != null && child.getName() != null) {
if (child.getName().compareToIgnoreCase(lastName) < 0) {
orderByNameIssues++;
}
}
lastName = child.getName();
}
if (children.getTotalNumItems() >= 0) {
f = createResult(WARNING, "Number of children doesn't match the reported total number of items!");
addResult(results, assertEquals(childrenCount, children.getTotalNumItems(), null, f));
} else {
addResult(results, createResult(WARNING, "getChildren did not report the total number of items!"));
}
if (supportsOrderByName) {
f = createResult(WARNING, "Children should be ordered by cmis:name, but they are not! (It might be a collation mismtach.)");
addResult(results, assertEquals(0, orderByNameIssues, null, f));
} else {
addResult(results, createResult(INFO, "Repository doesn't support Order By for getChildren()."));
}
// test path segments
ObjectInFolderList pathSegementChildren = session.getBinding().getNavigationService().getChildren(session.getRepositoryInfo().getId(), folder.getId(), "cmis:objectId,cmis:name", null, null, null, null, Boolean.TRUE, BigInteger.valueOf(10), BigInteger.ZERO, null);
if (pathSegementChildren != null && pathSegementChildren.getObjects() != null) {
for (ObjectInFolderData objectInFolder : pathSegementChildren.getObjects()) {
String pathSegement = objectInFolder.getPathSegment();
String objectId = (String) objectInFolder.getObject().getProperties().getProperties().get(PropertyIds.OBJECT_ID).getFirstValue();
if (pathSegement == null) {
addResult(results, createResult(FAILURE, "getChildren omitted path segement! ID: " + objectId));
} else {
CmisObject pathSegementChild = session.getObjectByPath(folder.getPath(), pathSegement);
f = createResult(FAILURE, "Combining the path of the parent folder and the path segement of a child returns a different object! ID: " + objectId);
addResult(results, assertEquals(objectId, pathSegementChild.getId(), null, f));
}
}
}
if (isGetDescendantsSupported(session)) {
long descendantsCount = 0;
List<Tree<FileableCmisObject>> descendants = folder.getDescendants(1, SELECT_ALL_NO_CACHE_OC);
for (Tree<FileableCmisObject> child : descendants) {
descendantsCount++;
if (child == null) {
addResult(results, createResult(FAILURE, "Folder descendants contain a null tree!"));
} else {
checkChild(session, results, folder, child.getItem());
}
}
f = createResult(FAILURE, "Number of descendants doesn't match the number of children returned by getChildren!");
addResult(results, assertEquals(childrenCount, descendantsCount, null, f));
} else {
addResult(results, createResult(SKIPPED, "getDescendants is not supported."));
}
if (isGetFolderTreeSupported(session)) {
long folderTreeCount = 0;
List<Tree<FileableCmisObject>> folderTree = folder.getFolderTree(1, SELECT_ALL_NO_CACHE_OC);
for (Tree<FileableCmisObject> child : folderTree) {
folderTreeCount++;
if (child == null) {
addResult(results, createResult(FAILURE, "Folder tree contains a null tree!"));
} else {
checkChild(session, results, folder, child.getItem());
}
}
f = createResult(FAILURE, "Number of folders doesn't match the number of folders returned by getChildren!");
addResult(results, assertEquals(childrenFolderCount, folderTreeCount, null, f));
} else {
addResult(results, createResult(SKIPPED, "getFolderTree is not supported."));
}
// --- wrap up ---
CmisTestResultImpl result = createResult(getWorst(results), message);
result.getChildren().addAll(results);
return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
Aggregations