Search in sources :

Example 16 with SearchResponse

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

Example 17 with SearchResponse

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);
}
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 18 with SearchResponse

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());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) ZMailbox(com.zimbra.client.ZMailbox) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) SearchHit(com.zimbra.soap.type.SearchHit) HttpMethodExecutor(com.zimbra.qa.unittest.TestCalDav.HttpMethodExecutor) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Example 19 with SearchResponse

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

Example 20 with SearchResponse

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));
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) ZMailbox(com.zimbra.client.ZMailbox) GetContactsRequest(com.zimbra.soap.mail.message.GetContactsRequest) SearchHit(com.zimbra.soap.type.SearchHit) ContactInfo(com.zimbra.soap.mail.type.ContactInfo) Id(com.zimbra.soap.type.Id) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Aggregations

SearchResponse (com.zimbra.soap.mail.message.SearchResponse)20 SearchRequest (com.zimbra.soap.mail.message.SearchRequest)18 SearchHit (com.zimbra.soap.type.SearchHit)18 Test (org.junit.Test)17 Account (com.zimbra.cs.account.Account)12 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)8 Mailbox (com.zimbra.cs.mailbox.Mailbox)8 ZMailbox (com.zimbra.client.ZMailbox)7 Message (com.zimbra.cs.mailbox.Message)6 Element (com.zimbra.common.soap.Element)3 ContactInfo (com.zimbra.soap.mail.type.ContactInfo)3 SoapTransport (com.zimbra.common.soap.SoapTransport)2 Search (com.zimbra.cs.service.mail.Search)2 HttpMethodExecutor (com.zimbra.qa.unittest.TestCalDav.HttpMethodExecutor)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