use of com.zimbra.cs.account.ldap.LdapHelper in project zm-mailbox by Zimbra.
the class TestLdapProvDomain method verifyAllDomains.
private void verifyAllDomains(List<Domain> allDomains) throws Exception {
// domains created by r-t-w
// TODO: this verification is very fragile
Set<String> expectedDomains = new HashSet<String>();
String defaultDomainName = prov.getInstance().getConfig().getDefaultDomainName();
expectedDomains.add(defaultDomainName);
expectedDomains.add("example.com");
assertEquals(expectedDomains.size(), allDomains.size());
for (Domain domain : allDomains) {
assertTrue(expectedDomains.contains(domain.getName()));
}
//
// another verification
//
LdapHelper ldapHelper = ((LdapProv) prov).getHelper();
final List<String> /* zimbraId */
domainIds = new ArrayList<String>();
SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor() {
@Override
public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
try {
domainIds.add(ldapAttrs.getAttrString(Provisioning.A_zimbraId));
} catch (ServiceException e) {
fail();
}
}
};
SearchLdapOptions searchOpts = new SearchLdapOptions(LdapConstants.DN_ROOT_DSE, ZLdapFilterFactory.getInstance().fromFilterString(FilterId.UNITTEST, "(objectclass=zimbraDomain)"), new String[] { Provisioning.A_zimbraId }, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapUsage.UNITTEST);
ldapHelper.searchLdap(zlc, searchOpts);
} finally {
LdapClient.closeContext(zlc);
}
assertEquals(domainIds.size(), allDomains.size());
for (Domain domain : allDomains) {
assertTrue(domainIds.contains(domain.getId()));
}
}
Aggregations