use of com.zimbra.cs.mailbox.Document in project zm-mailbox by Zimbra.
the class TestDocumentServer method testDeleteRevisions.
/**
* Server-side test that confirms that all blobs are cleaned up when
* a document with multiple revisions is deleted.
*/
@Test
public void testDeleteRevisions() throws Exception {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
// Create first revision.
String content = "one";
ParsedDocument pd = new ParsedDocument(new ByteArrayInputStream(content.getBytes()), NAME_PREFIX + "-testDeleteRevisions.txt", "text/plain", System.currentTimeMillis(), USER_NAME, "one", true);
Document doc = mbox.createDocument(null, Mailbox.ID_FOLDER_BRIEFCASE, pd, MailItem.Type.DOCUMENT, 0);
int docId = doc.getId();
MailItem.Type type = doc.getType();
File blobDir = getBlobDir(doc);
List<Document> revisions = mbox.getAllRevisions(null, docId, type);
Assert.assertEquals(1, revisions.size());
if (TestUtil.checkLocalBlobs()) {
Assert.assertEquals(1, getBlobCount(blobDir, docId));
}
Assert.assertEquals(true, doc.isDescriptionEnabled());
// Add a second revision.
content = "two";
pd = new ParsedDocument(new ByteArrayInputStream(content.getBytes()), NAME_PREFIX + "-testDeleteRevisions2.txt", "text/plain", System.currentTimeMillis(), USER_NAME, "two", false);
doc = mbox.addDocumentRevision(null, docId, pd);
Assert.assertEquals(2, mbox.getAllRevisions(null, docId, type).size());
if (TestUtil.checkLocalBlobs()) {
Assert.assertEquals(2, getBlobCount(blobDir, docId));
}
Assert.assertEquals(false, doc.isDescriptionEnabled());
// Move to trash, empty trash, and confirm that both blobs were deleted.
mbox.move(null, doc.getId(), doc.getType(), Mailbox.ID_FOLDER_TRASH);
mbox.emptyFolder(null, Mailbox.ID_FOLDER_TRASH, false);
mbox.emptyDumpster(null);
if (TestUtil.checkLocalBlobs()) {
Assert.assertEquals(0, getBlobCount(blobDir, docId));
}
}
Aggregations