use of com.zimbra.soap.account.type.DistributionListGranteeInfo in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method kvpForGetDLRespWithOwner.
/**
* Ensuring that JAXB can handle having an owner in a list that is not an empty array when there are no owners
*/
@Test
public void kvpForGetDLRespWithOwner() throws Exception {
Element jsonElem = JSONElement.mFactory.createElement(QName.get(AccountConstants.E_GET_DISTRIBUTION_LIST_RESPONSE, AccountConstants.NAMESPACE_STR));
populateGetDlResp(jsonElem);
Element xmlElem = XMLElement.mFactory.createElement(QName.get(AccountConstants.E_GET_DISTRIBUTION_LIST_RESPONSE, AccountConstants.NAMESPACE_STR));
populateGetDlResp(xmlElem);
logDebug("XmlElement (for comparison) ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
List<KeyValuePair> attrs = Lists.newArrayList();
attrs.add(new KeyValuePair("mail", "fun@example.test"));
attrs.add(new KeyValuePair("zimbraMailStatus", "enabled"));
DistributionListInfo dl = new DistributionListInfo("myId", "my name", null, attrs);
dl.setDynamic(true);
DistributionListGranteeInfo grantee = new DistributionListGranteeInfo(GranteeType.usr, "ownerId", "ownerName");
dl.addOwner(grantee);
GetDistributionListResponse jaxb = new GetDistributionListResponse(dl);
Element xmlJaxbElem = JaxbUtil.jaxbToElement(jaxb, XMLElement.mFactory);
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
GetDistributionListResponse roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, GetDistributionListResponse.class);
GetDistributionListResponse roundtrippedX = JaxbUtil.elementToJaxb(xmlJaxbElem, GetDistributionListResponse.class);
logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
logDebug("XMLElement from JAXB ---> prettyPrint\n%1$s", xmlJaxbElem.prettyPrint());
List<? extends KeyValuePair> kvps = roundtripped.getDl().getAttrList();
Assert.assertEquals("roundtripped kvps num", 2, kvps.size());
Assert.assertEquals("roundtripped owner num", 1, roundtripped.getDl().getOwners().size());
Assert.assertEquals("roundtrippedX owner num", 1, roundtrippedX.getDl().getOwners().size());
}
use of com.zimbra.soap.account.type.DistributionListGranteeInfo in project zm-mailbox by Zimbra.
the class TestDelegatedDL method getDistributionListRights.
/*
* verify rights are returned
*/
@Test
public void getDistributionListRights() throws Exception {
String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
Group group = createGroupAndAddOwner(GROUP_NAME);
String right1 = Right.RT_sendToDistList;
String right2 = Right.RT_viewDistList;
Account grantee1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
Account grantee2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
SoapTransport transport = authUser(USER_OWNER);
//
// grantRights
//
DistributionListAction action = new DistributionListAction(Operation.grantRights);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
DistributionListRightSpec dlRight1 = new DistributionListRightSpec(right1);
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee1.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee2.getName()));
DistributionListRightSpec dlRight2 = new DistributionListRightSpec(right2);
dlRight2.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.all, null, null));
action.addRight(dlRight1);
action.addRight(dlRight2);
DistributionListActionResponse resp = invokeJaxb(transport, req);
/*
* verify rights are returned
*/
GetDistributionListRequest getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.FALSE, right1 + "," + right2);
GetDistributionListResponse getDLResp = invokeJaxb(transport, getDLReq);
DistributionListInfo dlInfo = getDLResp.getDl();
List<? extends DistributionListRightInfo> rights = dlInfo.getRights();
Set<String> right1GranteeNames = Sets.newHashSet();
Set<String> right2GranteeNames = Sets.newHashSet();
for (DistributionListRightInfo rightInfo : rights) {
String right = rightInfo.getRight();
List<DistributionListGranteeInfo> grantees = rightInfo.getGrantees();
if (right1.equals(right)) {
for (DistributionListGranteeInfo grantee : grantees) {
right1GranteeNames.add(Verify.makeResultStr(grantee.getType().name(), grantee.getName()));
}
} else if (right2.equals(right)) {
for (DistributionListGranteeInfo grantee : grantees) {
right2GranteeNames.add(Verify.makeResultStr(grantee.getType().name(), grantee.getName()));
}
}
}
Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee1.getName()), Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee2.getName())), right1GranteeNames);
Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(GranteeType.GT_AUTHUSER.getCode(), "null")), right2GranteeNames);
}
Aggregations