use of com.zimbra.soap.mail.type.ContactInfo in project zm-mailbox by Zimbra.
the class TestCardDav method appleStyleGroup.
@Test
public void appleStyleGroup() 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(rachelVcard.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
postMethod = new HttpPost(contactsFolderUrl);
TestCalDav.addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addHeader("Content-Type", "text/vcard");
postMethod.setEntity(new ByteArrayEntity(blueGroupCreate.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
HttpMethodExecutor exe = HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
exe.getNonNullHeaderValue("Location", "When creating Group");
postMethod = new HttpPost(contactsFolderUrl);
TestCalDav.addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addHeader("Content-Type", "text/vcard");
postMethod.setEntity(new ByteArrayEntity(parisVcard.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
String url = String.format("%s%s", contactsFolderUrl, "F53A6F96-566F-46CC-8D48-A5263FAB5E38.vcf");
HttpPut putMethod = new HttpPut(url);
TestCalDav.addBasicAuthHeaderForUser(putMethod, dav1);
putMethod.addHeader("Content-Type", "text/vcard");
putMethod.setEntity(new ByteArrayEntity(blueGroupModify.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_NO_CONTENT);
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 = { "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 = 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", 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 createContact.
public ContactInfo createContact(SoapTransport soapTrans, String fullName) throws ServiceException, IOException, HttpException {
ContactSpec contactSpec = new ContactSpec();
contactSpec.addAttr(NewContactAttr.fromNameAndValue(ContactConstants.A_fullName, fullName));
CreateContactResponse resp = invokeJaxb(soapTrans, new CreateContactRequest(contactSpec));
assertNotNull(String.format("CreateContactResponse when creating %s should not be null", fullName), resp);
ContactInfo contact = resp.getContact();
assertNotNull(String.format("CreateContactResponse/cn when creating %s should not be null", fullName), contact);
return contact;
}
use of com.zimbra.soap.mail.type.ContactInfo in project zm-mailbox by Zimbra.
the class TestGetContactsRequest method testComaSeparatedIds.
@Test
public void testComaSeparatedIds() throws Exception {
Element req = new JSONElement(MailConstants.GET_CONTACTS_REQUEST);
req.addAttribute(MailConstants.A_SYNC, true);
req.addNonUniqueElement(MailConstants.E_CONTACT).addAttribute(MailConstants.A_ID, String.format("%s,%s", ids.get(0), ids.get(1)));
Element resp = transport.invoke(req);
GetContactsResponse getContactsResp = JaxbUtil.elementToJaxb(resp);
List<ContactInfo> contacts = getContactsResp.getContacts();
assertEquals(2, contacts.size());
}
use of com.zimbra.soap.mail.type.ContactInfo in project zm-mailbox by Zimbra.
the class TestGetContactsRequest method checkGetContactsMemberOf.
private void checkGetContactsMemberOf(SoapTransport soapTrans, GetContactsRequest getContactsReq, List<ContactInfo> groups, List<String> remIds, SoapProtocol proto) throws ServiceException, IOException, HttpException {
GetContactsResponse getContactsResp;
getContactsResp = invokeJaxb(soapTrans, getContactsReq, proto);
List<ContactInfo> contacts = getContactsResp.getContacts();
assertEquals("List of contacts returned when ask for contacts by ID", 2 + remIds.size(), contacts.size());
checkMemberOf(contacts, ids.get(0), groups.get(0).getId(), groups.get(1).getId(), groups.get(2).getId());
checkMemberOf(contacts, ids.get(1), groups.get(1).getId());
checkMemberOf(contacts, remIds.get(0), remIds.get(4), remIds.get(5));
getContactsReq.setIncludeMemberOf(false);
getContactsResp = invokeJaxb(soapTrans, getContactsReq, proto);
contacts = getContactsResp.getContacts();
assertEquals("List of contacts returned when ask for contacts by ID without memberOf info", 2 + remIds.size(), contacts.size());
checkMemberOf(contacts, ids.get(0));
checkMemberOf(contacts, ids.get(1));
checkMemberOf(contacts, remIds.get(0));
// Back to what it should have been at the start
getContactsReq.setIncludeMemberOf(true);
}
use of com.zimbra.soap.mail.type.ContactInfo in project zm-mailbox by Zimbra.
the class TestGetContactsRequest method createContactGroup.
public ContactInfo createContactGroup(SoapTransport soapTrans, String fullName, String... memberIds) throws ServiceException, IOException, HttpException {
ContactSpec contactSpec = new ContactSpec();
contactSpec.addAttr(NewContactAttr.fromNameAndValue(ContactConstants.A_fullName, fullName));
contactSpec.addAttr(NewContactAttr.fromNameAndValue(ContactConstants.A_type, ContactConstants.TYPE_GROUP));
for (String id : memberIds) {
contactSpec.addContactGroupMember(NewContactGroupMember.createForTypeAndValue(ContactGroup.Member.Type.CONTACT_REF.getSoapEncoded(), id));
}
CreateContactResponse resp = invokeJaxb(soapTrans, new CreateContactRequest(contactSpec));
assertNotNull(String.format("CreateContactResponse when creating ContactGroup %s should not be null", fullName), resp);
ContactInfo contact = resp.getContact();
assertNotNull(String.format("CreateContactResponse/cn when creating ContactGroup %s should not be null", fullName), contact);
return contact;
}
Aggregations