Search in sources :

Example 1 with SearchHit

use of com.zimbra.soap.type.SearchHit 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);
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) SearchHit(com.zimbra.soap.type.SearchHit) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Example 2 with SearchHit

use of com.zimbra.soap.type.SearchHit 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);
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) SearchHit(com.zimbra.soap.type.SearchHit) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Example 3 with SearchHit

use of com.zimbra.soap.type.SearchHit 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);
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) SearchHit(com.zimbra.soap.type.SearchHit) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Example 4 with SearchHit

use of com.zimbra.soap.type.SearchHit 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());
    }
}
Also used : SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Account(com.zimbra.cs.account.Account) SearchHit(com.zimbra.soap.type.SearchHit) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) URI(java.net.URI) ZAuthToken(com.zimbra.common.auth.ZAuthToken) SoapFaultException(com.zimbra.common.soap.SoapFaultException) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) ZMailbox(com.zimbra.client.ZMailbox) EndSessionRequest(com.zimbra.soap.account.message.EndSessionRequest) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Test(org.junit.Test)

Example 5 with SearchHit

use of com.zimbra.soap.type.SearchHit 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);
}
Also used : SearchRequest(com.zimbra.soap.mail.message.SearchRequest) SearchHit(com.zimbra.soap.type.SearchHit) SoapTransport(com.zimbra.common.soap.SoapTransport) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Aggregations

SearchRequest (com.zimbra.soap.mail.message.SearchRequest)10 SearchResponse (com.zimbra.soap.mail.message.SearchResponse)10 SearchHit (com.zimbra.soap.type.SearchHit)10 Test (org.junit.Test)9 Account (com.zimbra.cs.account.Account)6 ZMailbox (com.zimbra.client.ZMailbox)4 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 Message (com.zimbra.cs.mailbox.Message)3 SoapTransport (com.zimbra.common.soap.SoapTransport)2 AppointmentHitInfo (com.zimbra.soap.mail.type.AppointmentHitInfo)2 Header (org.apache.commons.httpclient.Header)2 HttpClient (org.apache.commons.httpclient.HttpClient)2 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2 ZInvite (com.zimbra.client.ZInvite)1 ZMessage (com.zimbra.client.ZMessage)1 ZAuthToken (com.zimbra.common.auth.ZAuthToken)1 Element (com.zimbra.common.soap.Element)1