use of com.zimbra.soap.mail.message.SearchRequest in project zm-mailbox by Zimbra.
the class TextQueryTest method sortByIsFlagged.
@Test
public void sortByIsFlagged() throws Exception {
Account acct = Provisioning.getInstance().getAccountById(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// setup: add a message
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
Message msg = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_FLAGGED);
Message msgWithFlag = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject flag"), dopt, null);
SearchResponse resp;
List<SearchHit> hits;
int msgId;
int msgWithFlagId;
SearchRequest sr = new SearchRequest();
sr.setSearchTypes("message");
sr.setQuery("test");
sr.setSortBy(SortBy.FLAG_ASC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 2, hits.size());
msgId = Integer.parseInt(hits.get(0).getId());
msgWithFlagId = Integer.parseInt(hits.get(1).getId());
Assert.assertEquals("correct hit ascending unflagged", msg.getId(), msgId);
Assert.assertEquals("correct hit ascending flagged", msgWithFlag.getId(), msgWithFlagId);
/* Check that we get them in the opposite order if we change the search direction */
sr.setSortBy(SortBy.FLAG_DESC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 2, hits.size());
msgId = Integer.parseInt(hits.get(1).getId());
msgWithFlagId = Integer.parseInt(hits.get(0).getId());
Assert.assertEquals("correct hit descending unflagged", msg.getId(), msgId);
Assert.assertEquals("correct hit descending flagged", msgWithFlag.getId(), msgWithFlagId);
}
use of com.zimbra.soap.mail.message.SearchRequest in project zm-mailbox by Zimbra.
the class TextQueryTest method sortByPriority.
@Test
public void sortByPriority() throws Exception {
Account acct = Provisioning.getInstance().getAccountById(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// setup: add a message
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
Message msg = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Message msgWithHighPri = mbox.addMessage(null, MailboxTestUtil.generateHighPriorityMessage("test subject is HI-PRI"), dopt, null);
Message msgWithLowPri = mbox.addMessage(null, MailboxTestUtil.generateLowPriorityMessage("test subject is LOW-PRI"), dopt, null);
SearchResponse resp;
List<SearchHit> hits;
int msgId;
int msgWithLowPriId;
int msgWithHiPriId;
SearchRequest sr = new SearchRequest();
sr.setSearchTypes("message");
sr.setQuery("test");
sr.setSortBy(SortBy.PRIORITY_ASC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 3, hits.size());
msgId = Integer.parseInt(hits.get(1).getId());
msgWithHiPriId = Integer.parseInt(hits.get(2).getId());
msgWithLowPriId = Integer.parseInt(hits.get(0).getId());
Assert.assertEquals("correct hit ascending high", msgWithHighPri.getId(), msgWithHiPriId);
Assert.assertEquals("correct hit ascending med", msg.getId(), msgId);
Assert.assertEquals("correct hit ascending low", msgWithLowPri.getId(), msgWithLowPriId);
/* Check that we get them in the opposite order if we change the search direction */
sr.setSortBy(SortBy.PRIORITY_DESC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 3, hits.size());
msgId = Integer.parseInt(hits.get(1).getId());
msgWithHiPriId = Integer.parseInt(hits.get(0).getId());
msgWithLowPriId = Integer.parseInt(hits.get(2).getId());
Assert.assertEquals("correct hit descending high", msgWithHighPri.getId(), msgWithHiPriId);
Assert.assertEquals("correct hit descending med", msg.getId(), msgId);
Assert.assertEquals("correct hit descending low", msgWithLowPri.getId(), msgWithLowPriId);
}
use of com.zimbra.soap.mail.message.SearchRequest in project zm-mailbox by Zimbra.
the class TextQueryTest method sortByHasAttach.
@Test
public void sortByHasAttach() throws Exception {
Account acct = Provisioning.getInstance().getAccountById(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// setup: add a message
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
Message msg = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Message msgWithAttach = mbox.addMessage(null, MailboxTestUtil.generateMessageWithAttachment("test subject has attach"), dopt, null);
SearchResponse resp;
List<SearchHit> hits;
int msgId;
int msgWithAttachId;
SearchRequest sr = new SearchRequest();
sr.setSearchTypes("message");
sr.setQuery("test");
sr.setSortBy(SortBy.ATTACHMENT_ASC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 2, hits.size());
msgId = Integer.parseInt(hits.get(0).getId());
msgWithAttachId = Integer.parseInt(hits.get(1).getId());
Assert.assertEquals("correct hit ascending no attachments", msg.getId(), msgId);
Assert.assertEquals("correct hit ascending has attachments", msgWithAttach.getId(), msgWithAttachId);
/* Check that we get them in the opposite order if we change the search direction */
sr.setSortBy(SortBy.ATTACHMENT_DESC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 2, hits.size());
msgId = Integer.parseInt(hits.get(1).getId());
msgWithAttachId = Integer.parseInt(hits.get(0).getId());
Assert.assertEquals("correct hit descending no attachments", msg.getId(), msgId);
Assert.assertEquals("correct hit descending has attachments", msgWithAttach.getId(), msgWithAttachId);
}
use of com.zimbra.soap.mail.message.SearchRequest in project zm-mailbox by Zimbra.
the class TestCookieReuse method testInvalidSearchRequest.
/**
* Verify that we canNOT RE-use the cookie taken from a legitimate HTTP session for a SOAP request after
* ending the original session
*/
@Test
public void testInvalidSearchRequest() throws ServiceException, IOException {
//establish legitimate connection
TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraForceClearCookies, "FALSE");
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
URI uri = mbox.getRestURI("Inbox?fmt=rss");
mbox.getHttpClient(uri);
ZAuthToken authT = mbox.getAuthToken();
//create evesdropper's SOAP client
SoapHttpTransport transport = new HttpCookieSoapTransport(TestUtil.getSoapUrl());
transport.setAuthToken(authT);
//check that search returns something
SearchRequest searchReq = new SearchRequest();
searchReq.setSearchTypes(MailItem.Type.MESSAGE.toString());
searchReq.setQuery("in:inbox");
Element req = JaxbUtil.jaxbToElement(searchReq, SoapProtocol.SoapJS.getFactory());
Element res = transport.invoke(req);
SearchResponse searchResp = JaxbUtil.elementToJaxb(res);
List<SearchHit> searchHits = searchResp.getSearchHits();
Assert.assertFalse("this search request should return some conversations", searchHits.isEmpty());
//explicitely end cookie session
Account a = TestUtil.getAccount(USER_NAME);
a.setForceClearCookies(false);
EndSessionRequest esr = new EndSessionRequest();
esr.setLogOff(true);
mbox.invokeJaxb(esr);
//check that search returns nothing
transport = new HttpCookieSoapTransport(TestUtil.getSoapUrl());
transport.setAuthToken(authT);
searchReq = new SearchRequest();
searchReq.setSearchTypes(MailItem.Type.MESSAGE.toString());
searchReq.setQuery("in:inbox");
try {
req = JaxbUtil.jaxbToElement(searchReq, SoapProtocol.SoapJS.getFactory());
res = transport.invoke(req);
searchResp = JaxbUtil.elementToJaxb(res);
searchHits = searchResp.getSearchHits();
Assert.assertTrue("this search request should fail", searchHits.isEmpty());
} catch (SoapFaultException ex) {
Assert.assertEquals("Should be getting 'auth required' exception", ServiceException.AUTH_EXPIRED, ex.getCode());
}
}
use of com.zimbra.soap.mail.message.SearchRequest in project zm-mailbox by Zimbra.
the class TestExpandGroupInfo method search.
@Test
public void search() throws Exception {
// send a to acct, recipient is a group
String SUBJECT = getTestName();
sendMsg(acct, group.getName(), SUBJECT, "blah");
SoapTransport transport = authUser(acct.getName());
SearchRequest searchReq = new SearchRequest();
searchReq.setSearchTypes(MailItem.Type.MESSAGE.toString());
searchReq.setQuery(String.format("in:inbox and subject:%s", SUBJECT));
searchReq.setFetch(SearchParams.ExpandResults.ALL.toString());
SearchResponse searchResp = invokeJaxb(transport, searchReq);
List<SearchHit> searchHits = searchResp.getSearchHits();
assertEquals(1, searchHits.size());
verifyGroupInfo((MessageHitInfo) searchHits.get(0), null, null);
/*
* search again with needExp
*/
searchReq.setNeedCanExpand(Boolean.TRUE);
searchResp = invokeJaxb(transport, searchReq);
searchHits = searchResp.getSearchHits();
assertEquals(1, searchHits.size());
verifyGroupInfo((MessageHitInfo) searchHits.get(0), Boolean.TRUE, Boolean.TRUE);
}
Aggregations