Search in sources :

Example 1 with ZSearchParams

use of com.zimbra.client.ZSearchParams in project zm-mailbox by Zimbra.

the class TestSearchSortByDate method testMessagesSortDateAsc.

@Test
public void testMessagesSortDateAsc() {
    try {
        Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT);
        long timestamp = System.currentTimeMillis() - 3600 * 60 * 1000;
        int numMessages = 3309;
        int firstLimit = 100;
        int incLimit = 50;
        int offset = 0;
        ArrayList<String> expectedIds = new ArrayList<String>();
        for (int i = 0; i < numMessages; i++) {
            Message msg = TestUtil.addMessage(recieverMbox, TestUtil.getAddress(RECIPIENT), TestUtil.getAddress(SENDER), NAME_PREFIX + " testing bug " + i, String.format("this message contains a search string %s which we are searching for and a number %d and timestamp %d", SEARCH_STRING, i, timestamp), timestamp);
            expectedIds.add(Integer.toString(msg.getId()));
            timestamp += 1000;
        // Thread.sleep(100);
        }
        // Collections.reverse(expectedIds);
        Thread.sleep(100);
        ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT);
        ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
        searchParams.setSortBy(SearchSortBy.dateAsc);
        searchParams.setLimit(firstLimit);
        searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
        List<String> msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
        assertEquals(firstLimit, msgIds.size());
        int gotMessages = msgIds.size();
        List<String> seenIds = new ArrayList<String>();
        seenIds.addAll(msgIds);
        int recCount = 1;
        offset += firstLimit;
        while (gotMessages > 0) {
            searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
            searchParams.setSortBy(SearchSortBy.dateAsc);
            searchParams.setLimit(incLimit);
            searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
            searchParams.setOffset(offset);
            msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
            recCount++;
            gotMessages = msgIds.size();
            int resCount = 0;
            for (String szId : msgIds) {
                assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, szId, seenIds.indexOf(szId)), seenIds.contains(szId));
                seenIds.add(szId);
                resCount++;
            }
            //Thread.sleep(100); //jetty sometimes crashes on Mac when bombarded with request without a timeout
            offset += incLimit;
        }
        for (int i = 0; i < expectedIds.size(); i++) {
            assertEquals("IDs at index " + i + " do not match", expectedIds.get(i), seenIds.get(i));
        }
        assertEquals("Returned incorrect number of messages", numMessages, seenIds.size());
    } catch (ServiceException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZMessage(com.zimbra.client.ZMessage) Message(com.zimbra.cs.mailbox.Message) ServiceException(com.zimbra.common.service.ServiceException) ZSearchParams(com.zimbra.client.ZSearchParams) ArrayList(java.util.ArrayList) ServiceException(com.zimbra.common.service.ServiceException) Test(org.junit.Test)

Example 2 with ZSearchParams

use of com.zimbra.client.ZSearchParams in project zm-mailbox by Zimbra.

the class TestSearchTask method testTaskSearch.

@Test
public void testTaskSearch() throws Exception {
    boolean hasMore;
    int offset = 0;
    do {
        ZSearchParams params = new ZSearchParams("in:tasks");
        params.setTypes("task");
        params.setOffset(offset);
        params.setLimit(limit);
        params.setSortBy(SearchSortBy.taskDueAsc);
        ZSearchResult resp = mbox.search(params);
        int numResults = resp.getHits().size();
        hasMore = resp.hasMore();
        assertEquals(Math.min(limit, numTasks - offset), numResults);
        offset += numResults;
    } while (hasMore == true);
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) ZSearchParams(com.zimbra.client.ZSearchParams) Test(org.junit.Test)

Example 3 with ZSearchParams

use of com.zimbra.client.ZSearchParams in project zm-mailbox by Zimbra.

the class TestSearchHeaders method testSearchNonTopLevelHeaders.

@Test
public void testSearchNonTopLevelHeaders() throws ServiceException {
    ZSearchParams params = new ZSearchParams("\"header search test\" #Content-Transfer-Encoding:8bit");
    params.setTypes("message");
    ZSearchResult result = mbox.search(params);
    boolean found = false;
    for (ZSearchHit hit : result.getHits()) {
        if (found == false && hit.getId().equals(id)) {
            found = true;
        }
    }
    assertTrue(found);
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) ZSearchHit(com.zimbra.client.ZSearchHit) ZSearchParams(com.zimbra.client.ZSearchParams) Test(org.junit.Test)

Example 4 with ZSearchParams

use of com.zimbra.client.ZSearchParams in project zm-mailbox by Zimbra.

the class TestSearchJunkTrash method testNotNotTrashOrJunk.

@Test
public void testNotNotTrashOrJunk() throws ServiceException {
    //resolves to junk only
    ZSearchParams params = new ZSearchParams(String.format("(NOT(in:trash OR NOT in:junk)) (inid:%s OR is:local)", folder.getId()));
    ZSearchResult results = mbox.search(params);
    assertEquals(2, results.getHits().size());
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) ZSearchParams(com.zimbra.client.ZSearchParams) Test(org.junit.Test)

Example 5 with ZSearchParams

use of com.zimbra.client.ZSearchParams in project zm-mailbox by Zimbra.

the class TestSearchJunkTrash method testTrashOrJunk.

@Test
public void testTrashOrJunk() throws ServiceException {
    ZSearchParams params = new ZSearchParams(String.format("(in:trash OR in:junk) (inid:%s OR is:local)", folder.getId()));
    ZSearchResult results = mbox.search(params);
    assertEquals(3, results.getHits().size());
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) ZSearchParams(com.zimbra.client.ZSearchParams) Test(org.junit.Test)

Aggregations

ZSearchParams (com.zimbra.client.ZSearchParams)31 Test (org.junit.Test)21 ZSearchResult (com.zimbra.client.ZSearchResult)17 ArrayList (java.util.ArrayList)12 ZMailbox (com.zimbra.client.ZMailbox)11 ZSearchHit (com.zimbra.client.ZSearchHit)9 ServiceException (com.zimbra.common.service.ServiceException)9 Mailbox (com.zimbra.cs.mailbox.Mailbox)9 Message (com.zimbra.cs.mailbox.Message)9 ZMessage (com.zimbra.client.ZMessage)5 Cursor (com.zimbra.client.ZSearchParams.Cursor)4 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)2 SearchSortBy (com.zimbra.soap.type.SearchSortBy)2 ZMessageHit (com.zimbra.client.ZMessageHit)1 ZSearchPagerResult (com.zimbra.client.ZSearchPagerResult)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 Account (com.zimbra.cs.account.Account)1 Date (java.util.Date)1