use of com.zimbra.soap.mail.type.ContactInfo in project zm-mailbox by Zimbra.
the class TestGetContactsRequest method checkMemberOf.
private void checkMemberOf(List<ContactInfo> contacts, String id, String... grpIds) {
ContactInfo contact = getContactWithId(contacts, id);
assertNotNull(String.format("No contact in list with id=%s", id), contact);
List<ContactAttr> attrs = contact.getAttrs();
String name = "unknown";
for (ContactAttr attr : attrs) {
if (ContactConstants.A_fullName.equals(attr.getKey())) {
name = attr.getValue();
break;
}
}
Collection<String> memberOf = contact.getMemberOf();
List<String> groups = Lists.newArrayList(grpIds);
if (groups.isEmpty()) {
assertTrue("memberOf info should be empty or null", (memberOf == null) || memberOf.isEmpty());
return;
}
assertNotNull(String.format("No memberOf for contact in list with id=%s/name=%s", id, name), memberOf);
assertEquals(String.format("Number of groups contact with id=%s/name=%s is a member of", id, name), groups.size(), memberOf.size());
for (String grp : groups) {
assertTrue(String.format("Contact with id=%s/name=%s should be a member of %s", id, name, grp), memberOf.contains(grp));
}
}
use of com.zimbra.soap.mail.type.ContactInfo in project zm-mailbox by Zimbra.
the class TestCalDav method testAppleStyleGroup.
@Test
public void testAppleStyleGroup() throws ServiceException, IOException {
Account dav1 = users[1].create();
String contactsFolderUrl = getFolderUrl(dav1, "Contacts");
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(contactsFolderUrl);
addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addRequestHeader("Content-Type", "text/vcard");
postMethod.setRequestEntity(new ByteArrayRequestEntity(rachelVcard.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
postMethod = new PostMethod(contactsFolderUrl);
addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addRequestHeader("Content-Type", "text/vcard");
postMethod.setRequestEntity(new ByteArrayRequestEntity(blueGroupCreate.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor exe = HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
String groupLocation = null;
for (Header hdr : exe.respHeaders) {
if ("Location".equals(hdr.getName())) {
groupLocation = hdr.getValue();
}
}
assertNotNull("Location Header returned when creating Group", groupLocation);
postMethod = new PostMethod(contactsFolderUrl);
addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addRequestHeader("Content-Type", "text/vcard");
postMethod.setRequestEntity(new ByteArrayRequestEntity(parisVcard.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
String url = String.format("%s%s", contactsFolderUrl, "F53A6F96-566F-46CC-8D48-A5263FAB5E38.vcf");
PutMethod putMethod = new PutMethod(url);
addBasicAuthHeaderForUser(putMethod, dav1);
putMethod.addRequestHeader("Content-Type", "text/vcard");
putMethod.setRequestEntity(new ByteArrayRequestEntity(blueGroupModify.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_NO_CONTENT);
GetMethod getMethod = new GetMethod(url);
addBasicAuthHeaderForUser(getMethod, dav1);
getMethod.addRequestHeader("Content-Type", "text/vcard");
exe = HttpMethodExecutor.execute(client, getMethod, HttpStatus.SC_OK);
String respBody = new String(exe.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
String[] expecteds = { "X-ADDRESSBOOKSERVER-KIND:group", "X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:BE43F16D-336E-4C3E-BAE6-22B8F245A986", "X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:07139DE2-EA7B-46CB-A970-C4DF7F72D9AE" };
for (String expected : expecteds) {
assertTrue(String.format("GET should contain '%s'\nBODY=%s", expected, respBody), respBody.contains(expected));
}
// members are actually stored in a different way. Make sure it isn't a fluke
// that the GET response contained the correct members by checking that the members
// appear where expected in a search hit.
SearchRequest searchRequest = new SearchRequest();
searchRequest.setSortBy("dateDesc");
searchRequest.setLimit(8);
searchRequest.setSearchTypes("contact");
searchRequest.setQuery("in:Contacts");
ZMailbox mbox = users[1].getZMailbox();
SearchResponse searchResp = mbox.invokeJaxb(searchRequest);
assertNotNull("JAXB SearchResponse object", searchResp);
List<SearchHit> hits = searchResp.getSearchHits();
assertNotNull("JAXB SearchResponse hits", hits);
assertEquals("JAXB SearchResponse hits", 3, hits.size());
boolean seenGroup = false;
for (SearchHit hit : hits) {
ContactInfo contactInfo = (ContactInfo) hit;
if ("BlueGroup".equals(contactInfo.getFileAs())) {
seenGroup = true;
assertEquals("Number of members of group in search hit", 2, contactInfo.getContactGroupMembers().size());
}
ZimbraLog.test.info("Hit %s class=%s", hit, hit.getClass().getName());
}
assertTrue("Seen group", seenGroup);
}
use of com.zimbra.soap.mail.type.ContactInfo 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