Search in sources :

Example 21 with ZSearchParams

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

the class TestSearchJunkTrash method testTrashOrNotJunk.

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

Example 22 with ZSearchParams

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

the class TestSearchJunkTrash method testJunk.

@Test
public void testJunk() throws ServiceException {
    ZSearchParams params = new ZSearchParams(String.format("(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 23 with ZSearchParams

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

the class TestSearchSortByDate method testMessagesCloseTimestamps.

@Test
public void testMessagesCloseTimestamps() {
    try {
        Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT);
        // - 3600*60*1000;
        long timestamp = System.currentTimeMillis();
        int numMessages = 2207;
        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()));
        }
        for (int i = 0; i < numMessages; i++) {
            Message msg = TestUtil.addMessage(recieverMbox, TestUtil.getAddress(RECIPIENT), TestUtil.getAddress(SENDER), NAME_PREFIX + " testing bug " + i, "this message does not contains a search string which we are searching for", timestamp);
        }
        Collections.reverse(expectedIds);
        Thread.sleep(100);
        ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT);
        ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
        searchParams.setSortBy(SearchSortBy.dateDesc);
        searchParams.setLimit(firstLimit);
        searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
        List<ZMessage> resultSet = TestUtil.search(zmbx, searchParams);
        assertEquals(firstLimit, resultSet.size());
        int gotMessages = resultSet.size();
        List<String> seenIds = new ArrayList<String>();
        ZMessage lastHit = null;
        for (ZMessage m : resultSet) {
            seenIds.add(m.getId());
            lastHit = m;
        }
        int recCount = 1;
        offset += firstLimit;
        while (gotMessages > 0) {
            searchParams.setCursor((new Cursor(lastHit.getId(), Long.toString(lastHit.getReceivedDate()))));
            searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
            searchParams.setSortBy(SearchSortBy.dateDesc);
            searchParams.setLimit(incLimit);
            searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
            searchParams.setOffset(offset);
            resultSet = TestUtil.search(zmbx, searchParams);
            recCount++;
            gotMessages = resultSet.size();
            int resCount = 0;
            for (ZMessage msg : resultSet) {
                assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, msg.getId(), seenIds.indexOf(msg.getId())), seenIds.contains(msg.getId()));
                seenIds.add(msg.getId());
                resCount++;
                lastHit = msg;
            }
            // Thread.sleep(100); //jetty sometimes crashes on Mac when bombarded with request without a timeout
            offset += incLimit;
        }
        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 : ZMessage(com.zimbra.client.ZMessage) ZMessage(com.zimbra.client.ZMessage) Message(com.zimbra.cs.mailbox.Message) ArrayList(java.util.ArrayList) Cursor(com.zimbra.client.ZSearchParams.Cursor) ServiceException(com.zimbra.common.service.ServiceException) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) ZSearchParams(com.zimbra.client.ZSearchParams) Test(org.junit.Test)

Example 24 with ZSearchParams

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

the class TestSearchSortByDate method testMessagesCloseTimestamps2.

@Test
public void testMessagesCloseTimestamps2() {
    try {
        Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT2);
        // - 3600*60*1000;
        long timestamp = System.currentTimeMillis();
        int numMessages = 4307;
        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(RECIPIENT2), 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 += 10;
        }
        for (int i = 0; i < numMessages; i++) {
            Message msg = TestUtil.addMessage(recieverMbox, TestUtil.getAddress(RECIPIENT), TestUtil.getAddress(SENDER), NAME_PREFIX + " testing bug " + i, "this message does not contains a search string which we are searching for", timestamp);
        }
        Collections.reverse(expectedIds);
        Thread.sleep(100);
        ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT2);
        ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
        searchParams.setSortBy(SearchSortBy.dateDesc);
        searchParams.setLimit(firstLimit);
        searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
        List<ZMessage> resultSet = TestUtil.search(zmbx, searchParams);
        assertEquals(firstLimit, resultSet.size());
        int gotMessages = resultSet.size();
        List<String> seenIds = new ArrayList<String>();
        ZMessage lastHit = null;
        for (ZMessage m : resultSet) {
            seenIds.add(m.getId());
            lastHit = m;
        }
        int recCount = 1;
        offset += firstLimit;
        while (gotMessages > 0) {
            searchParams.setCursor((new Cursor(lastHit.getId(), Long.toString(lastHit.getReceivedDate()))));
            searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
            searchParams.setSortBy(SearchSortBy.dateDesc);
            searchParams.setLimit(incLimit);
            searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
            searchParams.setOffset(offset);
            resultSet = TestUtil.search(zmbx, searchParams);
            recCount++;
            gotMessages = resultSet.size();
            int resCount = 0;
            for (ZMessage msg : resultSet) {
                assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, msg.getId(), seenIds.indexOf(msg.getId())), seenIds.contains(msg.getId()));
                seenIds.add(msg.getId());
                resCount++;
                lastHit = msg;
            }
            // Thread.sleep(100); //jetty sometimes crashes on Mac when bombarded with request without a timeout
            offset += incLimit;
        }
        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 : ZMessage(com.zimbra.client.ZMessage) ZMessage(com.zimbra.client.ZMessage) Message(com.zimbra.cs.mailbox.Message) ArrayList(java.util.ArrayList) Cursor(com.zimbra.client.ZSearchParams.Cursor) ServiceException(com.zimbra.common.service.ServiceException) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) ZSearchParams(com.zimbra.client.ZSearchParams) Test(org.junit.Test)

Example 25 with ZSearchParams

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

the class TestBug89152 method testMessagesWithSimilarTimestamps.

@Test
public void testMessagesWithSimilarTimestamps() {
    try {
        int numMessages = 5207;
        int firstLimit = 150;
        int incLimit = 50;
        int offset = 0;
        Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT1);
        long timestamp = System.currentTimeMillis();
        byte[] msgBytes = Files.readAllBytes(FileSystems.getDefault().getPath(TEST_MESSAGE_FILE));
        for (int i = 0; i < numMessages; i++) {
            ParsedMessage pm = new ParsedMessage(msgBytes, timestamp, true);
            pm.getMimeMessage().setSentDate(new Date());
            Message msg = TestUtil.addMessage(recieverMbox, pm);
            timestamp += 1;
        //Thread.sleep(300);
        }
        Thread.sleep(150);
        ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT1);
        ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
        searchParams.setSortBy(SearchSortBy.dateDesc);
        searchParams.setLimit(firstLimit);
        searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
        List<ZMessage> resultSet = TestUtil.search(zmbx, searchParams);
        assertEquals(firstLimit, resultSet.size());
        int gotMessages = resultSet.size();
        List<String> seenIds = new ArrayList<String>();
        ZMessage lastHit = null;
        for (ZMessage m : resultSet) {
            seenIds.add(m.getId());
            lastHit = m;
        }
        int recCount = 1;
        offset += firstLimit;
        while (gotMessages > 0) {
            searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
            searchParams.setCursor((new Cursor(lastHit.getId(), Long.toString(lastHit.getReceivedDate()))));
            searchParams.setSortBy(SearchSortBy.dateDesc);
            searchParams.setLimit(incLimit);
            searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
            searchParams.setOffset(offset);
            resultSet = TestUtil.search(zmbx, searchParams);
            recCount++;
            gotMessages = resultSet.size();
            int resCount = 0;
            for (ZMessage m : resultSet) {
                assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, m.getId(), seenIds.indexOf(m.getId())), seenIds.contains(m.getId()));
                seenIds.add(m.getId());
                resCount++;
                lastHit = m;
            }
            Thread.sleep(300);
            offset += incLimit;
        }
        assertEquals("expecting " + numMessages + " messages. Got " + seenIds.size(), numMessages, seenIds.size());
    } catch (ServiceException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMessage(com.zimbra.client.ZMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ArrayList(java.util.ArrayList) Cursor(com.zimbra.client.ZSearchParams.Cursor) Date(java.util.Date) ServiceException(com.zimbra.common.service.ServiceException) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) 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