use of com.zimbra.client.ZMailbox.OpenIMAPFolderParams in project zm-mailbox by Zimbra.
the class TestZClient method testOpenImapFolder.
@Test
public void testOpenImapFolder() throws Exception {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
Folder folder = mbox.createFolder(null, "TestOpenImapFolder", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
ItemIdentifier folderId = folder.getFolderItemIdentifier();
List<ImapMessage> expected = new LinkedList<ImapMessage>();
for (int i = 1; i <= 10; i++) {
Message msg = TestUtil.addMessage(mbox, folderId.id, String.format("imap message %s", i), System.currentTimeMillis());
expected.add(new ImapMessage(msg));
}
// test pagination
OpenIMAPFolderParams params = new OpenIMAPFolderParams(folderId);
// test fetching all results
params.setLimit(100);
OpenIMAPFolderResponse result = zmbox.fetchImapFolderChunk(params);
assertEquals(10, result.getImapMessageInfo().size());
assertFalse(result.getHasMore());
// test fetching first 5
params.setLimit(5);
result = zmbox.fetchImapFolderChunk(params);
List<ImapMessageInfo> messages = result.getImapMessageInfo();
assertEquals(5, messages.size());
for (int i = 0; i < messages.size(); i++) {
assertEquals(messages.get(i).getId(), expected.get(i).getMsgId());
}
assertTrue(result.getHasMore());
// test fetching 5 items starting at 3rd item, (more results left)
Integer cursorId = expected.get(2).getMsgId();
params.setCursorId(String.valueOf(cursorId));
result = zmbox.fetchImapFolderChunk(params);
messages = result.getImapMessageInfo();
assertEquals(5, messages.size());
for (int i = 0; i < messages.size(); i++) {
assertEquals(messages.get(i).getId(), expected.get(i + 3).getMsgId());
}
assertTrue(result.getHasMore());
// test fetching 5 items starting at 7th item, exhausting all results
cursorId = expected.get(6).getMsgId();
params.setCursorId(String.valueOf(cursorId));
result = zmbox.fetchImapFolderChunk(params);
messages = result.getImapMessageInfo();
assertEquals(3, messages.size());
for (int i = 0; i < messages.size(); i++) {
assertEquals(messages.get(i).getId(), expected.get(i + 7).getMsgId());
}
assertFalse(result.getHasMore());
// test getting all messages in batches of 3, so pagination is used
List<ImapMessageInfo> actual = zmbox.openImapFolder(folderId, 3);
Collections.sort(expected);
Collections.sort(actual);
assertEquals("expected and actual lists have different lengths", expected.size(), actual.size());
for (int i = 0; i < expected.size(); i++) {
assertEquals(expected.get(i).getImapUid(), actual.get(i).getImapUid());
}
}
Aggregations