use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class ItemQueryTest method testRangeOfItemsQuery.
@Test
public void testRangeOfItemsQuery() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("zero@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
Message msg1 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Message msg2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject2"), dopt, null);
Message msg3 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject3"), dopt, null);
mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject4"), dopt, null);
SearchResponse resp;
List<SearchHit> hits;
SearchRequest sr = new SearchRequest();
sr.setSearchTypes("message");
sr.setQuery(String.format("item:{%d--%d}", msg1.getId(), msg3.getId()));
sr.setSortBy(SortBy.ATTACHMENT_ASC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 3, hits.size());
int msgId = Integer.parseInt(hits.get(0).getId());
Assert.assertEquals("correct hit 1", msg1.getId(), msgId);
msgId = Integer.parseInt(hits.get(1).getId());
Assert.assertEquals("correct hit 2", msg2.getId(), msgId);
msgId = Integer.parseInt(hits.get(2).getId());
Assert.assertEquals("correct hit 3", msg3.getId(), msgId);
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class ItemQueryTest method testSyntax.
@Test
public void testSyntax() throws ServiceException {
Account account = Provisioning.getInstance().getAccountByName("zero@zimbra.com");
Mailbox mailbox = MailboxManager.getInstance().getMailboxByAccount(account);
ItemQuery q = (ItemQuery) ItemQuery.create(mailbox, "1,2");
Assert.assertEquals(String.format("Q(ITEMID,%s:1,%s:2)", MockProvisioning.DEFAULT_ACCOUNT_ID, MockProvisioning.DEFAULT_ACCOUNT_ID), q.toString());
q = (ItemQuery) ItemQuery.create(mailbox, "1");
Assert.assertEquals(String.format("Q(ITEMID,%s:1)", MockProvisioning.DEFAULT_ACCOUNT_ID), q.toString());
q = (ItemQuery) ItemQuery.create(mailbox, "all");
Assert.assertEquals("Q(ITEMID,all)", q.toString());
q = (ItemQuery) ItemQuery.create(mailbox, "none");
Assert.assertEquals("Q(ITEMID,none)", q.toString());
q = (ItemQuery) ItemQuery.create(mailbox, "1--10");
Assert.assertEquals(String.format("Q(ITEMID,%s:1--%s:10)", MockProvisioning.DEFAULT_ACCOUNT_ID, MockProvisioning.DEFAULT_ACCOUNT_ID), q.toString());
}
use of com.zimbra.cs.account.Account 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.cs.account.Account 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.cs.account.Account 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);
}
Aggregations