Search in sources :

Example 6 with ZDocument

use of com.zimbra.client.ZDocument in project zm-mailbox by Zimbra.

the class TestDocument method testMoveNote.

/**
 * Tests moving of documents created with the {@code Note} flag set.
 */
@Test
public void testMoveNote() throws Exception {
    TestUtil.createAccount(USER_NAME);
    TestUtil.createAccount(USER2_NAME);
    String filename = NAME_PREFIX + "-testMoveNote.txt";
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, TestUtil.getAddress(USER_NAME));
    Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, TestUtil.getAddress(USER2_NAME));
    // Create a note.
    ZMailbox zmbx = TestUtil.getZMailbox(USER_NAME);
    String folderId = Integer.toString(Mailbox.ID_FOLDER_BRIEFCASE);
    ZDocument note = TestUtil.createDocument(zmbx, folderId, filename, "text/plain", "note".getBytes(), true);
    String flags = Character.toString(ZItem.Flag.NOTE.getFlagChar());
    // Confirm that note flag is set.
    Assert.assertEquals(flags, note.getFlags());
    Mailbox remoteMbox = MailboxManager.getInstance().getMailboxByAccount(acct2);
    Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct);
    // Clean up test data for user2.
    TestUtil.deleteTestData(USER2_NAME, NAME_PREFIX);
    // reset the access if there are any present.
    remoteMbox.revokeAccess(null, Mailbox.ID_FOLDER_BRIEFCASE, acct.getId());
    mbox1.revokeAccess(null, Mailbox.ID_FOLDER_BRIEFCASE, acct2.getId());
    // Give write permissions on user2's Briefcase for user1 and user1's Briefcase for user2.
    remoteMbox.grantAccess(null, Mailbox.ID_FOLDER_BRIEFCASE, acct.getId(), ACL.GRANTEE_USER, (short) (ACL.RIGHT_READ | ACL.RIGHT_WRITE | ACL.RIGHT_INSERT), null);
    mbox1.grantAccess(null, Mailbox.ID_FOLDER_BRIEFCASE, acct2.getId(), ACL.GRANTEE_USER, (short) (ACL.RIGHT_READ | ACL.RIGHT_WRITE | ACL.RIGHT_INSERT), null);
    // move the note to user2
    zmbx.moveItem(note.getId(), acct2.getId() + ":" + Mailbox.ID_FOLDER_BRIEFCASE, null);
    ZMailbox remoteZmbx = TestUtil.getZMailbox(USER2_NAME);
    String idStr = TestUtil.search(remoteZmbx, "in:briefcase " + filename, ZSearchParams.TYPE_DOCUMENT).get(0);
    Document doc = remoteMbox.getDocumentById(null, Integer.parseInt(idStr));
    // make sure moved document has note flag.
    Assert.assertEquals(note.getFlags(), doc.getFlagString());
    // move the note back to user1
    remoteZmbx.moveItem(String.valueOf(doc.getId()), acct.getId() + ":" + Mailbox.ID_FOLDER_BRIEFCASE, null);
    // reset the access
    remoteMbox.revokeAccess(null, Mailbox.ID_FOLDER_BRIEFCASE, acct.getId());
    mbox1.revokeAccess(null, Mailbox.ID_FOLDER_BRIEFCASE, acct2.getId());
    idStr = TestUtil.search(zmbx, "in:briefcase " + filename, ZSearchParams.TYPE_DOCUMENT).get(0);
    doc = mbox1.getDocumentById(null, Integer.parseInt(idStr));
    // make sure moved document has note flag.
    Assert.assertEquals(note.getFlags(), doc.getFlagString());
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) ZDocument(com.zimbra.client.ZDocument) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZDocument(com.zimbra.client.ZDocument) Document(com.zimbra.cs.mailbox.Document) Test(org.junit.Test)

Aggregations

ZDocument (com.zimbra.client.ZDocument)6 Test (org.junit.Test)5 ZMailbox (com.zimbra.client.ZMailbox)4 Account (com.zimbra.cs.account.Account)2 ZAppointmentHit (com.zimbra.client.ZAppointmentHit)1 ZContactHit (com.zimbra.client.ZContactHit)1 ZConversationHit (com.zimbra.client.ZConversationHit)1 ZDocumentHit (com.zimbra.client.ZDocumentHit)1 ZMessageHit (com.zimbra.client.ZMessageHit)1 ZMountpoint (com.zimbra.client.ZMountpoint)1 ZSearchHit (com.zimbra.client.ZSearchHit)1 Document (com.zimbra.cs.mailbox.Document)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 Calendar (java.util.Calendar)1