Esempio n. 1
0
  /** Tests {@link Attachment#getContent()} (bug 36974). */
  @Test
  public void getAttachmentContent() throws Exception {
    // Create a contact with an attachment.
    Map<String, String> attrs = new HashMap<String, String>();
    attrs.put("fullName", "Get Attachment Content");
    byte[] attachData = "attachment 1".getBytes();
    Attachment textAttachment = new Attachment(attachData, "text/plain", "customField", "text.txt");
    Mailbox mbox =
        MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);

    mbox.createContact(
        null,
        new ParsedContact(attrs, Lists.newArrayList(textAttachment)),
        Mailbox.ID_FOLDER_CONTACTS,
        null);

    // Call getContent() on all attachments.
    for (Contact contact : mbox.getContactList(null, Mailbox.ID_FOLDER_CONTACTS)) {
      List<Attachment> attachments = contact.getAttachments();
      for (Attachment attach : attachments) {
        attach.getContent();
      }
    }
  }