use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class TestJaxbProvisioning method testDistributionList.
@Test
public void testDistributionList() throws Exception {
ZimbraLog.test.debug("Starting testDistributionList");
Domain dom = ensureDomainExists(testDlDomain);
assertNotNull("Domain for " + testDlDomain, dom);
deleteDlIfExists(testDl);
deleteDlIfExists(parentDl);
DistributionList dl = prov.createDistributionList(testDl, null);
assertNotNull("DistributionList for " + testDl, dl);
prov.renameDistributionList(dl.getId(), testDlNewName);
prov.addAlias(dl, testDlAlias);
dl = prov.get(Key.DistributionListBy.name, testDlAlias);
prov.removeAlias(dl, testDlAlias);
String[] members = { "one@example.com", "two@example.test", "three@example.net" };
String[] rmMembers = { "two@example.test", "three@example.net" };
prov.addMembers(dl, members);
prov.removeMembers(dl, rmMembers);
// DL Membership test
DistributionList dadDl = prov.createDistributionList(parentDl, null);
assertNotNull("DistributionList for " + parentDl, dadDl);
String[] dlMembers = { "one@example.com", testDlNewName };
prov.addMembers(dadDl, dlMembers);
Map<String, String> via = Maps.newHashMap();
List<DistributionList> containingDls = prov.getDistributionLists(dl, false, via);
assertEquals("Number of DLs a DL is a member of", 1, containingDls.size());
// Account Membership test
Account acct = ensureMailboxExists(testAcctEmail);
String[] dlAcctMembers = { testAcctEmail };
prov.addMembers(dadDl, dlAcctMembers);
containingDls = prov.getDistributionLists(acct, false, via);
assertEquals("Number of DLs an acct is a member of", 1, containingDls.size());
List<DistributionList> dls = prov.getAllDistributionLists(dom);
assertNotNull("All DLs", dls);
assertTrue("Number of DL objects=" + dls.size() + " should be >=2", dls.size() >= 2);
prov.deleteDistributionList(dadDl.getId());
prov.deleteDistributionList(dl.getId());
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class TestJaxbProvisioning method deleteDlIfExists.
public static void deleteDlIfExists(String name) {
try {
ZimbraLog.test.debug("Deleting DL %s", name);
Provisioning prov = TestUtil.newSoapProvisioning();
DistributionList res = prov.get(Key.DistributionListBy.name, name);
if (res != null) {
prov.deleteDistributionList(res.getId());
}
} catch (Exception ex) {
ZimbraLog.test.error("Problem deleting Distribution List %s", name, ex);
}
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class TestProvAlias method testRemoveAlias_entryNotExist_aliasExist_aliasPointToOtherEntry.
//
// C - alias points to other existing entry
//
@Test
public void testRemoveAlias_entryNotExist_aliasExist_aliasPointToOtherEntry() throws Exception {
String testName = getTestName();
// create the domain
String domainName = "EN-AE-aliasPointToOtherEntry" + "." + BASE_DOMAIN_NAME;
domainName = domainName.toLowerCase();
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDomainType, Provisioning.DomainType.local.name());
Domain domain = prov.createDomain(domainName, attrs);
// create the account the alias points to
String acctName = getEmail("acct-1", domainName);
Account acct = prov.createAccount(acctName, PASSWORD, new HashMap<String, Object>());
// add an alias to the account
String aliasName = getEmail("alias-1", domainName);
prov.addAlias(acct, aliasName);
// create 2 DLs
String dl1Name = getEmail("dl-1", domainName);
DistributionList dl1 = prov.createDistributionList(dl1Name, new HashMap<String, Object>());
String dl2Name = getEmail("dl-2", domainName);
DistributionList dl2 = prov.createDistributionList(dl2Name, new HashMap<String, Object>());
// add the alias to the two DLs
prov.addMembers(dl1, new String[] { aliasName });
prov.addMembers(dl2, new String[] { aliasName });
// non-existing entry account
Account nonExistingAcct = null;
// remove the alias, on a "not found" account, and the alias is pointing to another existing target
// we should *not* get the NO_SUCH_ALIAS exception
prov.removeAlias(nonExistingAcct, aliasName);
// reload all entries
prov.reload(acct);
prov.reload(dl1);
prov.reload(dl2);
Set<String> values;
// ensure the alias is still on the account
values = acct.getMultiAttrSet(Provisioning.A_mail);
assertTrue(values.contains(aliasName));
values = acct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
assertTrue(values.contains(aliasName));
// ensure the alias is *not* removed from any the DLs
values = dl1.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
assertTrue(values.contains(aliasName));
values = dl2.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
assertTrue(values.contains(aliasName));
// ensure the alias entry is *not* removed
List<NamedEntry> aliases = searchAliasesInDomain(domain);
assertEquals(aliases.size(), 1);
assertTrue(aliases.get(0).getName().equals(aliasName));
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class TestProvAlias method testRemoveAlias_aliasNameExistsButIsNotAnAlias.
@Test
public void testRemoveAlias_aliasNameExistsButIsNotAnAlias() throws Exception {
String testName = getTestName();
// create the domain
String domainName = underscoreToHyphen(testName) + "." + BASE_DOMAIN_NAME;
domainName = domainName.toLowerCase();
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDomainType, Provisioning.DomainType.local.name());
Domain domain = prov.createDomain(domainName, attrs);
// create the account
String acctName = getEmail("acct-1", domainName);
Account acct = prov.createAccount(acctName, PASSWORD, new HashMap<String, Object>());
// create another account
String acct2Name = getEmail("acct-2", domainName);
Account acct2 = prov.createAccount(acct2Name, PASSWORD, new HashMap<String, Object>());
String acct2Id = acct2.getId();
// create a distribution list
String dlName = getEmail("dl", domainName);
DistributionList dl = prov.createDistributionList(dlName, new HashMap<String, Object>());
String dlId = dl.getId();
boolean good = false;
try {
prov.removeAlias(acct, acct2Name);
} catch (ServiceException e) {
if (AccountServiceException.NO_SUCH_ALIAS.equals(e.getCode()))
good = true;
}
assertTrue(good);
// make sure the account is not touched
prov.flushCache(CacheEntryType.account, new CacheEntry[] { new CacheEntry(Key.CacheEntryBy.id, acct2Id) });
acct2 = prov.get(AccountBy.id, acct2Id);
assertNotNull(acct2);
assertEquals(acct2Id, acct2.getId());
assertEquals(acct2Name, acct2.getName());
try {
prov.removeAlias(acct, dlName);
} catch (ServiceException e) {
if (AccountServiceException.NO_SUCH_ALIAS.equals(e.getCode()))
good = true;
}
assertTrue(good);
// make sure the dl is not touched
// mProv.flushCache(CacheEntryType.account, new CacheEntry[]{new CacheEntry(CacheEntryBy.id, acct2Id)});
dl = prov.get(Key.DistributionListBy.id, dlId);
assertNotNull(dl);
assertEquals(dlId, dl.getId());
assertEquals(dlName, dl.getName());
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class TestProvAlias method testRemoveAlias_entryExist_aliasExist_aliasPointToEntry.
/*
* test removing alias
*
* 1. remove alias from mail and zimbraMailAlias attributes of the entry
* 2. remove alias from all distribution lists
* 3. delete the alias entry
*
* A. entry exists, alias exists
* - if alias points to the entry: do 1, 2, 3
* - if alias points to other existing entry: do 1, and then throw NO_SUCH_ALIAS
* - if alias points to a non-existing entry: do 1, 2, 3, and then throw NO_SUCH_ALIAS
*
* B. entry exists, alias does not exist: do 1, 2, and then throw NO_SUCH_ALIAS
*
* C. entry does not exist, alias exists:
* - if alias points to other existing entry: do nothing (and then throw NO_SUCH_ACCOUNT/NO_SUCH_DISTRIBUTION_LIST in ProvUtil)
* - if alias points to a non-existing entry: do 2, 3 (and then throw NO_SUCH_ACCOUNT/NO_SUCH_DISTRIBUTION_LIST in ProvUtil)
*
* D. entry does not exist, alias does not exist: do 2 (and then throw NO_SUCH_ACCOUNT/NO_SUCH_DISTRIBUTION_LIST in ProvUtil)
*
*
*/
//
// A - alias points to the entry
//
@Test
public void testRemoveAlias_entryExist_aliasExist_aliasPointToEntry() throws Exception {
// getTestName retusn all lower case. This avoids the bug that we don't convert
// an address to lower case when it is added as a DL member, and later the address
// can't be removed from the DL because case does not match.
String testName = getTestName();
// create the domain
String domainName = "EE-AE-aliasPointToEntry" + "." + BASE_DOMAIN_NAME;
domainName = domainName.toLowerCase();
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDomainType, Provisioning.DomainType.local.name());
Domain domain = prov.createDomain(domainName, attrs);
// create the account
String acctName = getEmail("acct-1", domainName);
Account acct = prov.createAccount(acctName, PASSWORD, new HashMap<String, Object>());
// add an alias to the account
String aliasName = getEmail("alias-1", domainName);
prov.addAlias(acct, aliasName);
// create 2 DLs
String dl1Name = getEmail("dl-1", domainName);
DistributionList dl1 = prov.createDistributionList(dl1Name, new HashMap<String, Object>());
String dl2Name = getEmail("dl-2", domainName);
DistributionList dl2 = prov.createDistributionList(dl2Name, new HashMap<String, Object>());
// add the alias to the two DLs
prov.addMembers(dl1, new String[] { aliasName });
prov.addMembers(dl2, new String[] { aliasName });
// remove the alias
prov.removeAlias(acct, aliasName);
// reload all entries
prov.reload(acct);
prov.reload(dl1);
prov.reload(dl2);
Set<String> values;
// ensure the alias is removed from the account's mail/zimbraMailAlias attrs
values = acct.getMultiAttrSet(Provisioning.A_mail);
assertFalse(values.contains(aliasName));
values = acct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
assertFalse(values.contains(aliasName));
// ensure the alias is removed from all the DLs
values = dl1.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
assertFalse(values.contains(aliasName));
values = dl2.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
assertFalse(values.contains(aliasName));
// ensure the alias entry is removed
List<NamedEntry> aliases = searchAliasesInDomain(domain);
assertEquals(aliases.size(), 0);
}
Aggregations