Search in sources :

Example 36 with Document

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));
    }
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) Document(com.zimbra.cs.mailbox.Document) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) File(java.io.File) Test(org.junit.Test)

Aggregations

Document (com.zimbra.cs.mailbox.Document)36 Mailbox (com.zimbra.cs.mailbox.Mailbox)24 MailItem (com.zimbra.cs.mailbox.MailItem)16 Test (org.junit.Test)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ParsedDocument (com.zimbra.cs.mime.ParsedDocument)12 ServiceException (com.zimbra.common.service.ServiceException)10 Folder (com.zimbra.cs.mailbox.Folder)10 InputStream (java.io.InputStream)10 Account (com.zimbra.cs.account.Account)9 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)9 OperationContext (com.zimbra.cs.mailbox.OperationContext)9 Element (com.zimbra.common.soap.Element)8 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)8 IOException (java.io.IOException)8 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)7 ZMailbox (com.zimbra.client.ZMailbox)6 Message (com.zimbra.cs.mailbox.Message)6 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)6 MimeMessage (javax.mail.internet.MimeMessage)6