Search in sources :

Example 6 with KeyValuePair

use of com.zimbra.soap.type.KeyValuePair in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method wrappedZimbraKeyValuePairsAnnotation.

/**
     * Desired JSON :
     * {
     *   "wrapper": {
     *     "_attrs": {
     *       "key1": "value1",
     *       "key2": "value2"
     *     }
     *   },
     *   "_jsns": "urn:zimbraTest"
     * }
     */
@Test
public void wrappedZimbraKeyValuePairsAnnotation() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get("key-value-pairs", "urn:zimbraTest"));
    Element wrapperElem = jsonElem.addUniqueElement("wrapper");
    wrapperElem.addKeyValuePair("key1", "value1");
    wrapperElem.addKeyValuePair("key2", "value2");
    List<KeyValuePair> attrs = Lists.newArrayList();
    attrs.add(new KeyValuePair("key1", "value1"));
    attrs.add(new KeyValuePair("key2", "value2"));
    WrappedKeyValuePairsTester jaxb = new WrappedKeyValuePairsTester(attrs);
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    Assert.assertEquals("prettyPrint", jsonElem.prettyPrint(), jsonJaxbElem.prettyPrint());
    WrappedKeyValuePairsTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, WrappedKeyValuePairsTester.class);
    List<com.zimbra.common.soap.Element.KeyValuePair> elemKVPs = jsonJaxbElem.getElement("wrapper").listKeyValuePairs();
    Assert.assertEquals("elemKVP num", 2, elemKVPs.size());
    List<KeyValuePair> kvps = roundtripped.getAttrList();
    Assert.assertEquals("roundtripped kvps num", 2, kvps.size());
}
Also used : KeyValuePair(com.zimbra.soap.type.KeyValuePair) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement) WrappedKeyValuePairsTester(com.zimbra.soap.jaxb.WrappedKeyValuePairsTester) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 7 with KeyValuePair

use of com.zimbra.soap.type.KeyValuePair in project zm-mailbox by Zimbra.

the class JaxbToElementTest method searchAutoProvDirectoryResponse.

// AutoProvDirectoryEntry contains 2 lists - one via extending AdminKeyValuePairs
// No order is specified for elements via XmlType propOrder.  Checking how well this works.
@Test
public void searchAutoProvDirectoryResponse() throws Exception {
    Element resp = Element.XMLElement.mFactory.createElement(AdminConstants.SEARCH_AUTO_PROV_DIRECTORY_RESPONSE);
    resp.addAttribute(AdminConstants.A_MORE, false);
    resp.addAttribute(AdminConstants.A_SEARCH_TOTAL, 1);
    Element entryE = resp.addNonUniqueElement(AdminConstants.E_ENTRY);
    entryE.addAttribute(AdminConstants.A_DN, "displayNam");
    entryE.addNonUniqueElement(AdminConstants.E_KEY).setText("keyValue1");
    entryE.addNonUniqueElement(AdminConstants.E_KEY).setText("keyValue2");
    entryE.addNonUniqueElement(AdminConstants.E_A).addAttribute(AdminConstants.A_N, "nVal1").setText("attr1Txt");
    entryE.addNonUniqueElement(AdminConstants.E_A).addAttribute(AdminConstants.A_N, "nVal2").setText("attr2Txt");
    SearchAutoProvDirectoryResponse jaxb = JaxbUtil.elementToJaxb(resp);
    Assert.assertNotNull("Unmarshal soap object", jaxb);
    List<AutoProvDirectoryEntry> entries = jaxb.getEntries();
    Assert.assertNotNull("entries list", entries);
    Assert.assertEquals("Number of entries", 1, entries.size());
    AutoProvDirectoryEntry entry = entries.get(0);
    List<KeyValuePair> kvps = entry.getKeyValuePairs();
    Assert.assertNotNull("entry - attrs list", kvps);
    Assert.assertEquals("entry - Number of attrs", 2, kvps.size());
    List<String> keys = entry.getKeys();
    Assert.assertNotNull("entry - keys list", keys);
    Assert.assertEquals("entry - Number of keys", 2, keys.size());
}
Also used : SearchAutoProvDirectoryResponse(com.zimbra.soap.admin.message.SearchAutoProvDirectoryResponse) AutoProvDirectoryEntry(com.zimbra.soap.admin.type.AutoProvDirectoryEntry) KeyValuePair(com.zimbra.soap.type.KeyValuePair) 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 8 with KeyValuePair

use of com.zimbra.soap.type.KeyValuePair in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method keyValuePairs.

/**
     * Desired JSON :
     * {
     *   "_attrs": {
     *     "key1": "value1",
     *     "key2": [
     *       "value2-a",
     *       "value2-b"]
     *   },
     *   "_jsns": "urn:zimbraTest"
     * }
     */
@Test
public void keyValuePairs() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get("key-value-pairs", "urn:zimbraTest"));
    jsonElem.addKeyValuePair("key1", "value1");
    jsonElem.addKeyValuePair("key2", "value2-a");
    jsonElem.addKeyValuePair("key2", "value2-b");
    KVPairs kvPairs = new KVPairs();
    kvPairs.addKeyValuePair(new KeyValuePair("key1", "value1"));
    kvPairs.addKeyValuePair(new KeyValuePair("key2", "value2-a"));
    kvPairs.addKeyValuePair(new KeyValuePair("key2", "value2-b"));
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(kvPairs);
    KVPairs roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, KVPairs.class);
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    List<com.zimbra.common.soap.Element.KeyValuePair> elemKVPs = jsonJaxbElem.listKeyValuePairs();
    Assert.assertEquals("elemKVP num", 3, elemKVPs.size());
    List<KeyValuePair> kvps = roundtripped.getKeyValuePairs();
    Assert.assertEquals("roundtripped kvps num", 3, kvps.size());
    Assert.assertEquals("prettyPrint", jsonElem.prettyPrint(), jsonJaxbElem.prettyPrint());
}
Also used : KeyValuePair(com.zimbra.soap.type.KeyValuePair) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement) KVPairs(com.zimbra.soap.jaxb.KVPairs) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 9 with KeyValuePair

use of com.zimbra.soap.type.KeyValuePair in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionModify.

@Test
public void distributionListActionModify() throws Exception {
    String ATTR = Provisioning.A_description;
    String VALUE = "test description";
    SoapTransport transport = authUser(USER_OWNER);
    DistributionListAction action = new DistributionListAction(Operation.modify);
    List<KeyValuePair> attrs = Lists.newArrayList(new KeyValuePair(ATTR, VALUE));
    action.setKeyValuePairs(attrs);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(DL_NAME), action);
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    Group group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
    assertEquals(VALUE, group.getAttr(ATTR));
}
Also used : Group(com.zimbra.cs.account.Group) KeyValuePair(com.zimbra.soap.type.KeyValuePair) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) Test(org.junit.Test)

Example 10 with KeyValuePair

use of com.zimbra.soap.type.KeyValuePair in project zm-mailbox by Zimbra.

the class TestDelegatedDL method getAccountDistributionLists.

@Test
public void getAccountDistributionLists() throws Exception {
    String GROUP_1_NAME = getAddress(genGroupNameLocalPart("1"));
    String GROUP_1_DISPLAY_NAME = "last";
    String GROUP_2_NAME = getAddress(genGroupNameLocalPart("2"));
    String GROUP_2_DISPLAY_NAME = "first";
    String GROUP_3_NAME = getAddress(genGroupNameLocalPart("3"));
    String GROUP_3_DISPLAY_NAME = "first";
    String GROUP_4_NAME = getAddress(genGroupNameLocalPart("4"));
    String GROUP_4_DISPLAY_NAME = "first";
    Group group1 = provUtil.createGroup(GROUP_1_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_1_DISPLAY_NAME), DYNAMIC);
    Group group2 = provUtil.createGroup(GROUP_2_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_2_DISPLAY_NAME), DYNAMIC);
    Group group3 = provUtil.createGroup(GROUP_3_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_3_DISPLAY_NAME), DYNAMIC);
    Group group4 = provUtil.createGroup(GROUP_4_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_4_DISPLAY_NAME), DYNAMIC);
    // create an account
    String ACCT_NAME = getAddress(genAcctNameLocalPart());
    Account acct = provUtil.createAccount(ACCT_NAME);
    // add the account in groups
    prov.addGroupMembers(group1, new String[] { ACCT_NAME });
    prov.addGroupMembers(group2, new String[] { ACCT_NAME });
    prov.addGroupMembers(group3, new String[] { ACCT_NAME });
    // make the account owner of groups
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group1.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, Group.GroupOwner.GROUP_OWNER_RIGHT.getName(), null);
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group4.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, Group.GroupOwner.GROUP_OWNER_RIGHT.getName(), null);
    SoapTransport transport = authUser(ACCT_NAME);
    GetAccountDistributionListsRequest req = new GetAccountDistributionListsRequest(Boolean.TRUE, MemberOfSelector.all, Sets.newHashSet(Provisioning.A_zimbraMailStatus, Provisioning.A_zimbraDistributionListSubscriptionPolicy, Provisioning.A_zimbraDistributionListUnsubscriptionPolicy));
    GetAccountDistributionListsResponse resp = invokeJaxb(transport, req);
    List<String> result = Lists.newArrayList();
    List<DLInfo> groups = resp.getDlList();
    for (DLInfo dlInfo : groups) {
        String id = dlInfo.getId();
        String name = dlInfo.getName();
        String displayName = dlInfo.getDisplayName();
        Boolean isOwner = dlInfo.isOwner();
        Boolean isMember = dlInfo.isMember();
        List<? extends KeyValuePair> attrs = dlInfo.getAttrList();
        List<String> attrValues = Lists.newArrayList();
        for (KeyValuePair attr : attrs) {
            String key = attr.getKey();
            String value = attr.getValue();
            attrValues.add(Verify.makeResultStr(key, value));
        }
        Collections.sort(attrValues);
        result.add(Verify.makeResultStr(id, name, displayName, isOwner, isMember, attrValues));
    }
    List<String> expectedAttrValuesOwner = Lists.newArrayList();
    expectedAttrValuesOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListSubscriptionPolicy, ZAttrProvisioning.DistributionListSubscriptionPolicy.REJECT.name()));
    expectedAttrValuesOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListUnsubscriptionPolicy, ZAttrProvisioning.DistributionListUnsubscriptionPolicy.REJECT.name()));
    expectedAttrValuesOwner.add(Verify.makeResultStr(Provisioning.A_zimbraMailStatus, ZAttrProvisioning.MailStatus.enabled.name()));
    List<String> expectedAttrValuesNonOwner = Lists.newArrayList();
    expectedAttrValuesNonOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListSubscriptionPolicy, ZAttrProvisioning.DistributionListSubscriptionPolicy.REJECT.name()));
    expectedAttrValuesNonOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListUnsubscriptionPolicy, ZAttrProvisioning.DistributionListUnsubscriptionPolicy.REJECT.name()));
    // result should be sorted by displayName.
    // If displayName are the same, sorted by entry.getLabel()
    Verify.verifyEquals(Lists.newArrayList(Verify.makeResultStr(group2.getId(), group2.getName(), group2.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group3.getId(), group3.getName(), group3.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group4.getId(), group4.getName(), group4.getDisplayName(), Boolean.TRUE, Boolean.FALSE, expectedAttrValuesOwner), Verify.makeResultStr(group1.getId(), group1.getName(), group1.getDisplayName(), Boolean.TRUE, Boolean.TRUE, expectedAttrValuesOwner)), result);
    // rename group
    String GROUP_NEW_NAME = getAddress(genGroupNameLocalPart("new"));
    prov.renameGroup(group1.getId(), GROUP_NEW_NAME);
    // get membership again, should show the new name
    result.clear();
    groups = resp.getDlList();
    for (DLInfo dlInfo : groups) {
        String id = dlInfo.getId();
        String name = dlInfo.getName();
        String displayName = dlInfo.getDisplayName();
        Boolean isOwner = dlInfo.isOwner();
        Boolean isMember = dlInfo.isMember();
        List<? extends KeyValuePair> attrs = dlInfo.getAttrList();
        List<String> attrValues = Lists.newArrayList();
        for (KeyValuePair attr : attrs) {
            String key = attr.getKey();
            String value = attr.getValue();
            attrValues.add(Verify.makeResultStr(key, value));
        }
        Collections.sort(attrValues);
        result.add(Verify.makeResultStr(id, name, displayName, isOwner, isMember, attrValues));
    }
    // result should be sorted by displayName
    Verify.verifyEquals(Lists.newArrayList(Verify.makeResultStr(group2.getId(), group2.getName(), group2.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group3.getId(), group3.getName(), group3.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group4.getId(), group4.getName(), group4.getDisplayName(), Boolean.TRUE, Boolean.FALSE, expectedAttrValuesOwner), Verify.makeResultStr(group1.getId(), group1.getName(), group1.getDisplayName(), Boolean.TRUE, Boolean.TRUE, expectedAttrValuesOwner)), result);
}
Also used : Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) KeyValuePair(com.zimbra.soap.type.KeyValuePair) GetAccountDistributionListsResponse(com.zimbra.soap.account.message.GetAccountDistributionListsResponse) GetAccountDistributionListsRequest(com.zimbra.soap.account.message.GetAccountDistributionListsRequest) DLInfo(com.zimbra.soap.account.type.DLInfo) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Aggregations

KeyValuePair (com.zimbra.soap.type.KeyValuePair)12 Test (org.junit.Test)11 Element (com.zimbra.common.soap.Element)8 JSONElement (com.zimbra.common.soap.Element.JSONElement)8 XMLElement (com.zimbra.common.soap.Element.XMLElement)8 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)7 XmlElement (javax.xml.bind.annotation.XmlElement)7 FilterTest (com.zimbra.soap.mail.type.FilterTest)6 SoapTransport (com.zimbra.common.soap.SoapTransport)4 Group (com.zimbra.cs.account.Group)4 GetDistributionListResponse (com.zimbra.soap.account.message.GetDistributionListResponse)3 DLInfo (com.zimbra.soap.account.type.DLInfo)3 DistributionListInfo (com.zimbra.soap.account.type.DistributionListInfo)3 CreateDistributionListResponse (com.zimbra.soap.account.message.CreateDistributionListResponse)2 WrappedKeyValuePairsTester (com.zimbra.soap.jaxb.WrappedKeyValuePairsTester)2 Account (com.zimbra.cs.account.Account)1 CreateDistributionListRequest (com.zimbra.soap.account.message.CreateDistributionListRequest)1 DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)1 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)1 GetAccountDistributionListsRequest (com.zimbra.soap.account.message.GetAccountDistributionListsRequest)1