Search in sources :

Example 1 with GetContactsRequest

use of com.zimbra.soap.mail.message.GetContactsRequest in project zm-mailbox by Zimbra.

the class JaxbToElementTest method jaxbElementsFixupTest.

/**
     * Check that @{link JaxbUtil.elementToJaxb} will accept XML where
     * JAXB expects various attributes that have been specified as elements.
     * Ensure that @XmlElements is handled
     * @throws Exception
     */
@Test
public void jaxbElementsFixupTest() throws Exception {
    Element rootElem = Element.XMLElement.mFactory.createElement(MailConstants.GET_CONTACTS_REQUEST);
    // JAXB Attribute A_SYNC
    rootElem.addNonUniqueElement(MailConstants.A_SYNC).addText("true");
    // JAXB Attribute A_FOLDER
    rootElem.addAttribute(MailConstants.A_FOLDER, "folderId");
    // JAXB Attribute A_SORTBY
    rootElem.addNonUniqueElement(MailConstants.A_SORTBY).addText("sortBy");
    // JAXB Elements:
    //    Element E_ATTRIBUTE --> AttributeName
    //    Element E_CONTACT --> Id
    Element attrName1 = rootElem.addNonUniqueElement(MailConstants.E_ATTRIBUTE);
    attrName1.addAttribute(MailConstants.A_ATTRIBUTE_NAME, "aName1");
    Element contact1 = rootElem.addNonUniqueElement(MailConstants.E_CONTACT);
    contact1.addNonUniqueElement(MailConstants.A_ID).addText("ctctId1");
    Element contact2 = rootElem.addNonUniqueElement(MailConstants.E_CONTACT);
    contact2.addAttribute(MailConstants.A_ID, "ctctId2");
    Element attrName2 = rootElem.addNonUniqueElement(MailConstants.E_ATTRIBUTE);
    attrName2.addNonUniqueElement(MailConstants.A_ATTRIBUTE_NAME).addText("aName2");
    Element memAttr1 = rootElem.addNonUniqueElement(MailConstants.E_CONTACT_GROUP_MEMBER_ATTRIBUTE);
    memAttr1.addNonUniqueElement(MailConstants.A_ATTRIBUTE_NAME).addText("grpAttrName1");
    GetContactsRequest req = JaxbUtil.elementToJaxb(rootElem);
    Assert.assertEquals("Sync", true, req.getSync().booleanValue());
    Assert.assertEquals("FolderID", "folderId", req.getFolderId());
    Assert.assertEquals("SortBy", "sortBy", req.getSortBy());
}
Also used : GetContactsRequest(com.zimbra.soap.mail.message.GetContactsRequest) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) JAXBElement(javax.xml.bind.JAXBElement) Test(org.junit.Test)

Example 2 with GetContactsRequest

use of com.zimbra.soap.mail.message.GetContactsRequest in project zm-mailbox by Zimbra.

the class TestContactGroup method createAndGetContactGroup.

@Test
@Bug(bug = 70558)
public void createAndGetContactGroup() throws Exception {
    SoapTransport transport = authUser(acct.getName());
    /*
         * search gal to get ref of the member account in GAL
         */
    SearchGalRequest searchGalReq = new SearchGalRequest();
    searchGalReq.setName(memberAcct.getName());
    SearchGalResponse searchGalResp = invokeJaxb(transport, searchGalReq);
    List<ContactInfo> entries = searchGalResp.getContacts();
    assertEquals(1, entries.size());
    ContactInfo galEntry = entries.get(0);
    String galMemberRef = galEntry.getReference();
    /*
         * create a contact group
         */
    NewContactGroupMember contactGroupMemer = NewContactGroupMember.createForTypeAndValue(ContactGroup.Member.Type.GAL_REF.getSoapEncoded(), galMemberRef);
    NewContactAttr contactAttr = new NewContactAttr(ContactConstants.A_type);
    contactAttr.setValue(ContactConstants.TYPE_GROUP);
    ContactSpec contactSpec = new ContactSpec();
    contactSpec.addAttr(contactAttr);
    contactSpec.addContactGroupMember(contactGroupMemer);
    CreateContactRequest createContactReq = new CreateContactRequest(contactSpec);
    CreateContactResponse createContactResp = invokeJaxb(transport, createContactReq);
    String contactGroupId = createContactResp.getContact().getId();
    /*
         * get the contact group, derefed
         */
    GetContactsRequest getContactsReq = new GetContactsRequest();
    getContactsReq.addContact(new Id(contactGroupId));
    getContactsReq.setDerefGroupMember(Boolean.TRUE);
    GetContactsResponse getContactsResp = invokeJaxb(transport, getContactsReq, SoapProtocol.SoapJS);
    List<com.zimbra.soap.mail.type.ContactInfo> contacts = getContactsResp.getContacts();
    assertEquals(1, contacts.size());
    com.zimbra.soap.mail.type.ContactInfo contact = contacts.get(0);
    List<ContactGroupMember> members = contact.getContactGroupMembers();
    assertEquals(1, members.size());
    ContactGroupMember member = members.get(0);
    String memberType = member.getType();
    String memberValue = member.getValue();
    assertEquals(ContactGroup.Member.Type.GAL_REF.getSoapEncoded(), memberType);
    assertEquals(galMemberRef, memberValue);
}
Also used : ContactSpec(com.zimbra.soap.mail.type.ContactSpec) ContactGroupMember(com.zimbra.soap.mail.type.ContactGroupMember) NewContactGroupMember(com.zimbra.soap.mail.type.NewContactGroupMember) SearchGalResponse(com.zimbra.soap.account.message.SearchGalResponse) CreateContactResponse(com.zimbra.soap.mail.message.CreateContactResponse) SearchGalRequest(com.zimbra.soap.account.message.SearchGalRequest) CreateContactRequest(com.zimbra.soap.mail.message.CreateContactRequest) GetContactsResponse(com.zimbra.soap.mail.message.GetContactsResponse) GetContactsRequest(com.zimbra.soap.mail.message.GetContactsRequest) NewContactAttr(com.zimbra.soap.mail.type.NewContactAttr) ContactInfo(com.zimbra.soap.account.type.ContactInfo) NewContactGroupMember(com.zimbra.soap.mail.type.NewContactGroupMember) Id(com.zimbra.soap.type.Id) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Aggregations

GetContactsRequest (com.zimbra.soap.mail.message.GetContactsRequest)2 Test (org.junit.Test)2 Element (com.zimbra.common.soap.Element)1 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 SoapTransport (com.zimbra.common.soap.SoapTransport)1 Bug (com.zimbra.qa.QA.Bug)1 SearchGalRequest (com.zimbra.soap.account.message.SearchGalRequest)1 SearchGalResponse (com.zimbra.soap.account.message.SearchGalResponse)1 ContactInfo (com.zimbra.soap.account.type.ContactInfo)1 CreateContactRequest (com.zimbra.soap.mail.message.CreateContactRequest)1 CreateContactResponse (com.zimbra.soap.mail.message.CreateContactResponse)1 GetContactsResponse (com.zimbra.soap.mail.message.GetContactsResponse)1 ContactGroupMember (com.zimbra.soap.mail.type.ContactGroupMember)1 ContactSpec (com.zimbra.soap.mail.type.ContactSpec)1 NewContactAttr (com.zimbra.soap.mail.type.NewContactAttr)1 NewContactGroupMember (com.zimbra.soap.mail.type.NewContactGroupMember)1 Id (com.zimbra.soap.type.Id)1 JAXBElement (javax.xml.bind.JAXBElement)1