try {
Map<String, Document> documents = new HashMap<String, Document>();
// create documents
for (int i = 0; i < numOfDocuments; i++) {
Document newDocument = createDocument(session, testFolder, "doc" + i, CONTENT);
documents.put(newDocument.getId(), newDocument);
}
// 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 folders does not match the number of existing folders!");
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 paging
int pageSize = 5;
CmisObject lastObject = null;
int count = 0;
ItemIterable<CmisObject> page1 = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME).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));
count = 0;
ItemIterable<CmisObject> page2 = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME)
.skipTo(pageSize - 1).getPage(pageSize);
for (CmisObject child : page2) {
count++;
if (count == 1) {
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));
// 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 {
try {
contentStream.getStream().close();
} catch (IOException e) {
}
}
// 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();