use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class SaveDraftTest method updateRace.
@Test
public void updateRace() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("test@zimbra.com");
// create a draft via SOAP
Element request = new Element.JSONElement(MailConstants.SAVE_DRAFT_REQUEST);
Element m = request.addNonUniqueElement(MailConstants.E_MSG).addAttribute(MailConstants.E_SUBJECT, "dinner appt");
m.addUniqueElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, ORIGINAL_CONTENT);
Element response = new SaveDraft() {
@Override
protected Element generateResponse(ZimbraSoapContext zsc, ItemIdFormatter ifmt, OperationContext octxt, Mailbox mbox, Message msg, boolean wantImapUid, boolean wantModSeq) {
// trigger the failure case by re-saving the draft before it's serialized out
Message snapshotMsg = msg;
try {
snapshotMsg = (Message) msg.snapshotItem();
MimeMessage mm = new MimeMessage(JMSession.getSession());
mm.setText(MODIFIED_CONTENT);
mm.saveChanges();
mbox.saveDraft(null, new ParsedMessage(mm, false), snapshotMsg.getId());
} catch (Exception e) {
return null;
}
return super.generateResponse(zsc, ifmt, octxt, mbox, snapshotMsg, wantImapUid, wantModSeq);
}
}.handle(request, ServiceTestUtil.getRequestContext(acct));
// make sure the response has the correct message content
Assert.assertEquals("picked up modified content", MODIFIED_CONTENT, response.getElement(MailConstants.E_MSG).getElement(MailConstants.E_MIMEPART).getAttribute(MailConstants.E_CONTENT));
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class GetContactBackupListTest method testGetContactBackupListJSON.
@Test
public void testGetContactBackupListJSON() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
Folder folder = mbox.createFolder(null, "Briefcase/ContactsBackup", new Folder.FolderOptions().setDefaultView(MailItem.Type.DOCUMENT));
OperationContext octxt = new OperationContext(acct);
// Upload the contacts backup file to ContactsBackup folder in briefcase
mbox.createDocument(octxt, folder.getId(), "backup_dummy_test1.tgz", MimeConstants.CT_APPLICATION_ZIMBRA_DOC, "author", "description", new ByteArrayInputStream("dummy data".getBytes()));
mbox.createDocument(octxt, folder.getId(), "backup_dummy_test2.tgz", MimeConstants.CT_APPLICATION_ZIMBRA_DOC, "author", "description", new ByteArrayInputStream("dummy data".getBytes()));
Element request = new Element.JSONElement(MailConstants.E_GET_CONTACT_BACKUP_LIST_REQUEST);
Map<String, Object> context = new HashMap<String, Object>();
context.put(SoapEngine.ZIMBRA_CONTEXT, new ZimbraSoapContext(AuthProvider.getAuthToken(acct), acct.getId(), SoapProtocol.Soap12, SoapProtocol.SoapJS));
context.put(SoapServlet.SERVLET_REQUEST, new MockHttpServletRequest("test".getBytes("UTF-8"), new URL("http://localhost:7070/service/FooRequest"), ""));
context.put(SoapEngine.ZIMBRA_ENGINE, new MockSoapEngine(new MailService()));
Element response = new GetContactBackupList().handle(request, context);
String expectedResponse = "{\n" + " \"backups\": [{\n" + " \"backup\": [\n" + " {\n" + " \"_content\": \"backup_dummy_test1.tgz\"\n" + " },\n" + " {\n" + " \"_content\": \"backup_dummy_test2.tgz\"\n" + " }]\n" + " }],\n" + " \"_jsns\": \"urn:zimbraMail\"\n" + "}";
Assert.assertEquals("GetContactBackupListResponse is not as expected", expectedResponse, response.prettyPrint());
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class SearchActionTest method testSearchActionRead.
@Test
public void testSearchActionRead() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("testRead@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// Add two messages to inbox, one with search match and other with no match
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_MUTED);
Message message1 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Message message2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("unmatched subject"), dopt, null);
TypedIdList ids = mbox.getItemIds(null, 2);
Assert.assertEquals(2, ids.size());
Assert.assertEquals(true, message1.isUnread());
Assert.assertEquals(true, message2.isUnread());
SearchRequest sRequest = new SearchRequest();
sRequest.setSearchTypes("conversation");
// search with query 'test'
sRequest.setQuery("test");
BulkAction bAction = new BulkAction();
// search action - mark search result with 'read'
bAction.setOp(BulkAction.Operation.read);
Map<String, Object> context = ServiceTestUtil.getRequestContext(acct);
ZimbraSoapContext zsc = (ZimbraSoapContext) context.get(SoapEngine.ZIMBRA_CONTEXT);
Element searchResponse = new Search().handle(zsc.jaxbToElement(sRequest), ServiceTestUtil.getRequestContext(acct));
com.zimbra.soap.mail.message.SearchResponse sResponse = zsc.elementToJaxb(searchResponse);
List<SearchHit> searchHits = sResponse.getSearchHits();
ConvActionRequest req = SearchAction.getConvActionRequest(searchHits, "read");
ConvAction convAction = new ConvAction();
PowerMockito.stub(PowerMockito.method(SoapHttpTransport.class, "invokeWithoutSession")).toReturn(convAction.handle(zsc.jaxbToElement(req), ServiceTestUtil.getRequestContext(acct)));
SearchAction.performAction(bAction, sRequest, searchHits, mbox, null);
// check search result message is marked read
Assert.assertEquals(false, message1.isUnread());
Assert.assertEquals(true, message2.isUnread());
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class ParseMimeMessageTest method staleReference.
@Test
public void staleReference() throws Exception {
Account acct = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// first, create the original draft
OperationContext octxt = new OperationContext(acct);
Document doc = mbox.createDocument(octxt, Mailbox.ID_FOLDER_BRIEFCASE, "testdoc", MimeConstants.CT_TEXT_PLAIN, null, null, randomContent("test1", 8192));
Document doc2 = mbox.createDocument(octxt, Mailbox.ID_FOLDER_BRIEFCASE, "testdoc2", MimeConstants.CT_TEXT_PLAIN, null, null, randomContent("test2", 8192));
Element el = new Element.JSONElement(MailConstants.E_MSG), attach;
el.addAttribute(MailConstants.E_SUBJECT, "has attachment");
el.addElement(MailConstants.E_EMAIL).addAttribute(MailConstants.A_ADDRESS_TYPE, EmailType.TO.toString()).addAttribute(MailConstants.A_ADDRESS, "rcpt@zimbra.com");
el.addElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, "This is the content.");
attach = el.addElement(MailConstants.E_ATTACH);
attach.addElement(MailConstants.E_DOC).addAttribute(MailConstants.A_ID, doc.getId());
attach.addElement(MailConstants.E_DOC).addAttribute(MailConstants.A_ID, doc2.getId());
ZimbraSoapContext zsc = getMockSoapContext();
MimeMessage mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, null, el, null, new ParseMimeMessage.MimeMessageData());
Message draft = mbox.saveDraft(octxt, new ParsedMessage(mm, false), -1);
// then, create a new draft that references one of the original draft's attachments
attach.detach();
(attach = el.addElement(MailConstants.E_ATTACH)).addElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_MESSAGE_ID, draft.getId()).addAttribute(MailConstants.A_PART, "3");
mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, null, el, null, new ParseMimeMessage.MimeMessageData());
// delete the draft itself and then try to save the new draft
mbox.delete(octxt, draft.getId(), MailItem.Type.MESSAGE);
Message draft2 = mbox.saveDraft(octxt, new ParsedMessage(mm, false), -1);
// check that the attachment's content is present and correct
MimeMultipart multi = (MimeMultipart) (draft2.getMimeMessage().getContent());
Assert.assertEquals("2 parts in draft", 2, multi.getCount());
Assert.assertEquals("attached part content", "test2", firstLine((MimeBodyPart) multi.getBodyPart(1)));
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class ParseMimeMessageTest method parseMimeMsgSoap.
@Test
public void parseMimeMsgSoap() throws Exception {
Element el = new Element.JSONElement(MailConstants.E_MSG);
el.addAttribute(MailConstants.E_SUBJECT, "dinner appt");
el.addUniqueElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, "foo bar");
el.addElement(MailConstants.E_EMAIL).addAttribute(MailConstants.A_ADDRESS_TYPE, EmailType.TO.toString()).addAttribute(MailConstants.A_ADDRESS, "rcpt@zimbra.com");
Account acct = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
OperationContext octxt = new OperationContext(acct);
ZimbraSoapContext zsc = getMockSoapContext();
MimeMessage mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, null, el, null, new ParseMimeMessage.MimeMessageData());
Assert.assertEquals("text/plain; charset=utf-8", mm.getContentType());
Assert.assertEquals("dinner appt", mm.getSubject());
Assert.assertEquals("rcpt@zimbra.com", mm.getHeader("To", ","));
Assert.assertEquals("7bit", mm.getHeader("Content-Transfer-Encoding", ","));
Assert.assertEquals("foo bar", mm.getContent());
}
Aggregations