use of com.zimbra.soap.mail.message.SearchResponse in project zm-mailbox by Zimbra.
the class ItemQueryTest method testNoneItemsQuery.
@Test
public void testNoneItemsQuery() 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);
mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
SearchResponse resp;
List<SearchHit> hits;
SearchRequest sr = new SearchRequest();
sr.setSearchTypes("message");
sr.setQuery("item:{none}");
sr.setSortBy(SortBy.ATTACHMENT_ASC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 0, hits.size());
}
use of com.zimbra.soap.mail.message.SearchResponse in project zm-mailbox by Zimbra.
the class ItemQueryTest method testListOfItemsQuery.
@Test
public void testListOfItemsQuery() 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);
mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject2"), dopt, null);
Message msg3 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject3"), 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", 2, 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", msg3.getId(), msgId);
}
use of com.zimbra.soap.mail.message.SearchResponse in project zm-mailbox by Zimbra.
the class TestCardDav method xBusyMacAttach.
@Test
public void xBusyMacAttach() throws ServiceException, IOException {
String contactsFolderUrl = TestCalDav.getFolderUrl(dav1, "Contacts");
HttpClient client = HttpClientBuilder.create().build();
HttpPost postMethod = new HttpPost(contactsFolderUrl);
TestCalDav.addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addHeader("Content-Type", "text/vcard");
postMethod.setEntity(new ByteArrayEntity(smallBusyMacAttach.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
HttpMethodExecutor exe = HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
String location = exe.getNonNullHeaderValue("Location", "When creating VCARD");
String url = String.format("%s%s", contactsFolderUrl, location.substring(location.lastIndexOf('/') + 1));
HttpGet getMethod = new HttpGet(url);
TestCalDav.addBasicAuthHeaderForUser(getMethod, dav1);
getMethod.addHeader("Content-Type", "text/vcard");
exe = HttpMethodExecutor.execute(client, getMethod, HttpStatus.SC_OK);
String respBody = exe.getResponseAsString();
String[] expecteds = { "\r\nX-BUSYMAC-ATTACH;X-FILENAME=favicon.ico;ENCODING=B:AAABAAEAEBAAAAEAIABoBA\r\n", "\r\n AAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAABMLAAATCwAAAAAAAAAAAAAAAAAAw4cAY8\r\n", "\r\nX-BUSYMAC-MODIFIED-BY:Gren Elliot\r\n", "\r\nX-CUSTOM:one two three four five six seven eight nine ten eleven twelve t\r\n hirteen fourteen fifteen", "\r\nX-CUSTOM:Here are my simple\\Nmultiline\\Nnotes\r\n", "\r\nX-CUSTOM;TYPE=pref:semi-colon\\;seperated\\;\"stuff\"\\;here\r\n", "\r\nX-CUSTOM:comma\\,\"stuff\"\\,'there'\\,too\r\n", "\r\nX-HOBBY:my backslash\\\\ hobbies\r\n", "\r\nX-CREATED:2015-04-05T09:50:44Z\r\n" };
for (String expected : expecteds) {
assertTrue(String.format("GET should contain '%s'\nBODY=%s", expected, respBody), respBody.contains(expected));
}
SearchRequest searchRequest = new SearchRequest();
searchRequest.setSortBy("dateDesc");
searchRequest.setLimit(8);
searchRequest.setSearchTypes("contact");
searchRequest.setQuery("in:Contacts");
ZMailbox mbox = TestUtil.getZMailbox(DAV1);
SearchResponse searchResp = mbox.invokeJaxb(searchRequest);
assertNotNull("JAXB SearchResponse object", searchResp);
List<SearchHit> hits = searchResp.getSearchHits();
assertNotNull("JAXB SearchResponse hits", hits);
assertEquals("JAXB SearchResponse hits", 1, hits.size());
}
use of com.zimbra.soap.mail.message.SearchResponse in project zm-mailbox by Zimbra.
the class TestExpandGroupInfo method searchConversation.
@Test
public void searchConversation() 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.CONVERSATION.toString());
searchReq.setQuery(String.format("in:inbox and subject:%s", SUBJECT));
SearchResponse searchResp = invokeJaxb(transport, searchReq);
List<SearchHit> searchHits = searchResp.getSearchHits();
assertEquals(1, searchHits.size());
SearchHit searchHit = searchHits.get(0);
String convId = searchHit.getId();
SearchConvRequest searchConvReq = new SearchConvRequest(convId);
searchConvReq.setNeedCanExpand(Boolean.TRUE);
searchConvReq.setFetch(SearchParams.ExpandResults.ALL.toString());
SearchConvResponse searchConvResp = invokeJaxb(transport, searchConvReq);
List<MessageHitInfo> hits = searchConvResp.getMessages();
// 2 - one in inbox, one in sent folder
assertEquals(2, hits.size());
verifyGroupInfo(hits.get(0), Boolean.TRUE, Boolean.TRUE);
verifyGroupInfo(hits.get(1), Boolean.TRUE, Boolean.TRUE);
}
use of com.zimbra.soap.mail.message.SearchResponse in project zm-mailbox by Zimbra.
the class TestGetContactsRequest method contactGroupMembership.
@Test
public void contactGroupMembership() throws Exception {
Account acct2 = TestUtil.createAccount(USER2_NAME);
transport2 = authUser(acct2.getName());
List<ContactInfo> groups = Lists.newArrayListWithExpectedSize(3);
groups.add(createContactGroup(transport, USER_NAME + "-GROUP1", ids.get(0)));
groups.add(createContactGroup(transport, USER_NAME + "-GROUP2", ids.get(0), ids.get(1)));
groups.add(createContactGroup(transport, USER_NAME + "-GROUP3", ids.get(0)));
List<String> u2ids = createContacts(transport2, USER2_NAME + "-contact%s", 4);
List<ContactInfo> u2grps = Lists.newArrayListWithExpectedSize(3);
u2grps.add(createContactGroup(transport2, USER2_NAME + "-GROUP1", u2ids.get(0)));
u2grps.add(createContactGroup(transport2, USER2_NAME + "-GROUP2", u2ids.get(0), u2ids.get(1)));
u2grps.add(createContactGroup(transport2, USER2_NAME + "-GROUP3", u2ids.get(3)));
ZMailbox u1zmbox = TestUtil.getZMailbox(USER_NAME);
ZMailbox u2zmbox = TestUtil.getZMailbox(USER2_NAME);
TestUtil.createMountpoint(u2zmbox, "/Contacts", u1zmbox, "U2-Contacts");
List<String> remIds = Lists.newArrayList();
for (String u2id : u2ids) {
remIds.add(ItemIdentifier.fromOwnerAndRemoteId(acct2.getId(), u2id).toString(acct.getId()));
}
for (ContactInfo grp : u2grps) {
remIds.add(ItemIdentifier.fromOwnerAndRemoteId(acct2.getId(), grp.getId()).toString(acct.getId()));
}
GetContactsRequest getContactsReq = new GetContactsRequest();
getContactsReq.addContact(new Id(ids.get(0)));
getContactsReq.addContact(new Id(ids.get(1)));
for (String remId : remIds) {
getContactsReq.addContact(new Id(remId));
}
getContactsReq.setIncludeMemberOf(true);
getContactsReq.setSortBy(ZimbraSortBy.nameAsc.name());
checkGetContactsMemberOf(transport, getContactsReq, groups, remIds, SoapProtocol.SoapJS);
checkGetContactsMemberOf(transport, getContactsReq, groups, remIds, SoapProtocol.Soap12);
SearchRequest searchReq = new SearchRequest();
searchReq.setIncludeMemberOf(true);
searchReq.setQuery("in:Contacts or in:\"U2-Contacts\"");
searchReq.setSearchTypes("contact");
searchReq.setSortBy(ZimbraSortBy.nameAsc.name());
SearchResponse searchResp = invokeJaxb(transport, searchReq);
assertNotNull("SearchResponse should not be null", searchResp);
List<SearchHit> hits = searchResp.getSearchHits();
assertNotNull("SearchResponse Hits should not be null", hits);
List<ContactInfo> cHits = Lists.newArrayListWithExpectedSize(hits.size());
for (SearchHit hit : hits) {
if (hit instanceof ContactInfo) {
cHits.add((ContactInfo) hit);
} else {
fail(String.format("SearchHit %s should be a ContactInfo", hit.getClass().getName()));
}
}
checkMemberOf(cHits, ids.get(0), groups.get(0).getId(), groups.get(1).getId(), groups.get(2).getId());
checkMemberOf(cHits, ids.get(1), groups.get(1).getId());
checkMemberOf(cHits, remIds.get(0), remIds.get(4), remIds.get(5));
}
Aggregations