Search in sources :

Example 36 with CalendarResource

use of com.zimbra.cs.account.CalendarResource in project zm-mailbox by Zimbra.

the class TestLdapProvSearchDirectory method renameDomainSearchAcctCrDl.

@Test
public void renameDomainSearchAcctCrDl() throws Exception {
    Account acct = createAccount(genAcctNameLocalPart("acct"));
    CalendarResource cr = createCalendarResource(genAcctNameLocalPart("cr"));
    DistributionList dl = createDistributionList(genGroupNameLocalPart("dl"));
    String domainDN = ((LdapDomain) domain).getDN();
    String searchBase = ((LdapProv) prov).getDIT().domainDNToAccountSearchDN(domainDN);
    final List<NamedEntry> entries = Lists.newArrayList();
    NamedEntry.Visitor visitor = new NamedEntry.Visitor() {

        @Override
        public void visit(NamedEntry entry) throws ServiceException {
            // System.out.println(entry.getName());
            entries.add(entry);
        }
    };
    SearchDirectoryOptions options = new SearchDirectoryOptions();
    options.setDomain(domain);
    options.setOnMaster(true);
    options.setFilterString(FilterId.RENAME_DOMAIN, null);
    options.setTypes(ObjectType.accounts, ObjectType.resources, ObjectType.distributionlists);
    prov.searchDirectory(options, visitor);
    Verify.verifyEquals(Lists.newArrayList(acct, cr, dl), entries, false);
    /*
         // legacy code and ldap trace
        int flags = Provisioning.SD_ACCOUNT_FLAG + Provisioning.SD_CALENDAR_RESOURCE_FLAG + Provisioning.SD_DISTRIBUTION_LIST_FLAG;
        ((LdapProvisioning) prov).searchObjects(null, null, searchBase, flags, visitor, 0);
         *
         Oct 12 22:10:43 pshao-macbookpro-2 slapd[3065]: conn=1081 op=434 SRCH base="ou=people,dc=com,dc=zimbra,dc=qa,dc=unittest,dc=testldapprovsearchdirectory" scope=2 deref=0 filter="(|(objectClass=zimbraAccount)(objectClass=zimbraDistributionList)(objectClass=zimbraCalendarResource))"
         Oct 12 22:10:43 pshao-macbookpro-2 slapd[3065]: conn=1081 op=434 SEARCH RESULT tag=101 err=0 nentries=3 text=

         */
    deleteAccount(acct);
    deleteAccount(cr);
    deleteGroup(dl);
}
Also used : Account(com.zimbra.cs.account.Account) NamedEntry(com.zimbra.cs.account.NamedEntry) SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) CalendarResource(com.zimbra.cs.account.CalendarResource) DistributionList(com.zimbra.cs.account.DistributionList) ProvTest(com.zimbra.qa.unittest.prov.ProvTest)

Example 37 with CalendarResource

use of com.zimbra.cs.account.CalendarResource in project zm-mailbox by Zimbra.

the class TestLdapProvSearchDirectory method searchAccountsOnServer.

@Test
public void searchAccountsOnServer() throws Exception {
    // create a search domain
    String DOMAIN_NAME = genDomainSegmentName() + "." + baseDomainName();
    Domain searchDomain = provUtil.createDomain(DOMAIN_NAME, null);
    // create an account and a calendar resource on the domain
    String ACCT_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart("acct"));
    String CR_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart("cr"));
    Map<String, Object> crAttrs = Maps.newHashMap();
    crAttrs.put(Provisioning.A_displayName, "ACCT_LOCALPART");
    crAttrs.put(Provisioning.A_zimbraCalResType, Provisioning.CalResType.Equipment.name());
    Account acct = createAccount(prov, ACCT_LOCALPART, searchDomain, null);
    CalendarResource cr = createCalendarResource(CR_LOCALPART, searchDomain, crAttrs);
    Server server = prov.getLocalServer();
    List<NamedEntry> result;
    SearchAccountsOptions opts;
    // 1. test search accounts, including cr
    opts = new SearchAccountsOptions(searchDomain, new String[] { Provisioning.A_zimbraId });
    opts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
    result = prov.searchAccountsOnServer(server, opts);
    Verify.verifyEquals(Lists.newArrayList(acct, cr), result, false);
    // 2. test maxResults
    boolean caughtTooManySearchResultsException = false;
    try {
        opts = new SearchAccountsOptions(searchDomain, new String[] { Provisioning.A_zimbraId });
        opts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
        opts.setMaxResults(1);
        result = prov.searchAccountsOnServer(server, opts);
    } catch (ServiceException e) {
        if (AccountServiceException.TOO_MANY_SEARCH_RESULTS.equals(e.getCode())) {
            caughtTooManySearchResultsException = true;
        }
    }
    assertTrue(caughtTooManySearchResultsException);
    // 3. search accounts only
    opts = new SearchAccountsOptions(searchDomain, new String[] { Provisioning.A_zimbraId });
    opts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
    opts.setIncludeType(IncludeType.ACCOUNTS_ONLY);
    result = prov.searchAccountsOnServer(server, opts);
    Verify.verifyEquals(Lists.newArrayList(acct), result, false);
    // 4. test sorting
    opts = new SearchAccountsOptions(searchDomain, new String[] { Provisioning.A_zimbraId });
    opts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
    opts.setSortOpt(SortOpt.SORT_DESCENDING);
    result = prov.searchAccountsOnServer(server, opts);
    Verify.verifyEquals(Lists.newArrayList(cr, acct), result, true);
    opts = new SearchAccountsOptions(searchDomain, new String[] { Provisioning.A_zimbraId });
    opts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
    opts.setSortOpt(SortOpt.SORT_ASCENDING);
    result = prov.searchAccountsOnServer(server, opts);
    Verify.verifyEquals(Lists.newArrayList(acct, cr), result, true);
}
Also used : Account(com.zimbra.cs.account.Account) NamedEntry(com.zimbra.cs.account.NamedEntry) SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions) Server(com.zimbra.cs.account.Server) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Domain(com.zimbra.cs.account.Domain) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) CalendarResource(com.zimbra.cs.account.CalendarResource) ProvTest(com.zimbra.qa.unittest.prov.ProvTest)

Example 38 with CalendarResource

use of com.zimbra.cs.account.CalendarResource in project zm-mailbox by Zimbra.

the class TestSearchCalendarResources method searchByName.

private void searchByName(boolean ldap, String domainName) throws Exception {
    SoapTransport transport = authUser(TestUtil.getAddress(AUTHED_USER, domainName));
    Element request = Element.create(transport.getRequestProtocol(), AccountConstants.SEARCH_CALENDAR_RESOURCES_REQUEST);
    request.addAttribute(MailConstants.A_QUERY_OFFSET, 1);
    request.addAttribute(MailConstants.A_QUERY_LIMIT, 2);
    request.addElement(AccountConstants.E_NAME).setText(KEY_FOR_SEARCH_BY_NAME);
    Element response = transport.invoke(request);
    boolean paginationSupported = response.getAttributeBool(AccountConstants.A_PAGINATION_SUPPORTED);
    boolean found1 = false;
    boolean found2 = false;
    boolean found3 = false;
    List<CalendarResource> resources = new ArrayList<CalendarResource>();
    for (Element eResource : response.listElements(AccountConstants.E_CALENDAR_RESOURCE)) {
        CalendarResource resource = new MockCalendarResource(eResource);
        resources.add(resource);
        if (resource.getName().equals(TestUtil.getAddress(ROOM_1, domainName))) {
            found1 = true;
        }
        if (resource.getName().equals(TestUtil.getAddress(ROOM_2, domainName))) {
            found2 = true;
        }
        if (resource.getName().equals(TestUtil.getAddress(ROOM_3, domainName))) {
            found3 = true;
        }
    }
    if (ldap) {
        // pagination is not supported
        Assert.assertFalse(paginationSupported);
        // offset and limit are not honored
        Assert.assertEquals(3, resources.size());
        Assert.assertTrue(found1);
        Assert.assertTrue(found2);
        Assert.assertTrue(found3);
    } else {
        // pagination is supported
        Assert.assertTrue(paginationSupported);
        // offset and limit are honored
        Assert.assertEquals(2, resources.size());
        // not within specified offset, at offset 0
        Assert.assertTrue(!found1);
        // (gal sync acount mailbox search is by nameAcs order)
        Assert.assertTrue(found2);
        Assert.assertTrue(found3);
    }
}
Also used : Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) CalendarResource(com.zimbra.cs.account.CalendarResource) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 39 with CalendarResource

use of com.zimbra.cs.account.CalendarResource in project zm-mailbox by Zimbra.

the class TestProvIDN method testAccount.

@Test
public void testAccount() throws Exception {
    Names.IDNName domainName = new Names.IDNName(makeTestDomainName("domain-acct-test."));
    Domain domain = createDomain(domainName.uName(), domainName.uName());
    Names.IDNName acct1Name = new Names.IDNName("acct-1", domainName.uName());
    Names.IDNName acct2Name = new Names.IDNName("acct-2", domainName.uName());
    Names.IDNName acct2RenamedName = new Names.IDNName("acct-2-renamed", domainName.uName());
    Names.IDNName alias1Name = new Names.IDNName("alias-1-of-acct-1", domainName.uName());
    Names.IDNName alias2Name = new Names.IDNName("alias-2-of-acct-1", domainName.uName());
    Names.IDNName cr1Name = new Names.IDNName("cr-1", domainName.uName());
    Names.IDNName cr2Name = new Names.IDNName("cr-2", domainName.uName());
    Names.IDNName cr2RenamedName = new Names.IDNName("cr-2-renamed", domainName.uName());
    /*
         * account
         */
    // create test
    Account acct1 = (Account) createTest(EntryType.ACCOUNT, NameType.UNAME, acct1Name);
    Account acct2 = (Account) createTest(EntryType.ACCOUNT, NameType.ANAME, acct2Name);
    // get by name test
    getTest(EntryType.ACCOUNT, acct1, acct1Name);
    getTest(EntryType.ACCOUNT, acct2, acct2Name);
    // set address attrs tets
    setAddressAttrsTest(EntryType.ACCOUNT, acct1, acct1Name);
    // add aliases
    // add alias by uname
    prov.addAlias(acct1, alias1Name.uName());
    // add alias by aname
    prov.addAlias(acct1, alias2Name.aName());
    // get by alias name test
    getTest(EntryType.ACCOUNT, acct1, alias1Name);
    getTest(EntryType.ACCOUNT, acct1, alias2Name);
    // remove aliases
    prov.removeAlias(acct1, alias1Name.aName());
    prov.removeAlias(acct1, alias2Name.uName());
    getTest(EntryType.ACCOUNT, null, alias1Name);
    getTest(EntryType.ACCOUNT, null, alias2Name);
    // add aliases back so we can view them after the test
    // add alias by uname
    prov.addAlias(acct1, alias1Name.uName());
    // add alias by aname
    prov.addAlias(acct1, alias2Name.aName());
    // rename test
    renameTest(EntryType.ACCOUNT, acct2, acct2RenamedName);
    getTest(EntryType.ACCOUNT, acct2, acct2RenamedName);
    /*
         * cr
         */
    // create test
    CalendarResource cr1 = (CalendarResource) createTest(EntryType.CR, NameType.UNAME, cr1Name);
    CalendarResource cr2 = (CalendarResource) createTest(EntryType.CR, NameType.ANAME, cr2Name);
    // get by name test
    getTest(EntryType.CR, cr1, cr1Name);
    getTest(EntryType.CR, cr2, cr2Name);
    // rename test
    renameTest(EntryType.CR, cr2, cr2RenamedName);
    getTest(EntryType.CR, cr2, cr2RenamedName);
}
Also used : Names(com.zimbra.qa.unittest.prov.Names) Account(com.zimbra.cs.account.Account) Domain(com.zimbra.cs.account.Domain) CalendarResource(com.zimbra.cs.account.CalendarResource) Test(org.junit.Test)

Example 40 with CalendarResource

use of com.zimbra.cs.account.CalendarResource in project zm-mailbox by Zimbra.

the class TestProvIDN method createCalendarResource.

private CalendarResource createCalendarResource(String email, String description) throws Exception {
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_description, "=====" + description + "=====");
    attrs.put(Provisioning.A_displayName, email);
    attrs.put(Provisioning.A_zimbraCalResType, "Equipment");
    CalendarResource cr = prov.createCalendarResource(email, PASSWORD, attrs);
    assertNotNull(cr);
    return cr;
}
Also used : HashMap(java.util.HashMap) CalendarResource(com.zimbra.cs.account.CalendarResource)

Aggregations

CalendarResource (com.zimbra.cs.account.CalendarResource)40 Account (com.zimbra.cs.account.Account)23 Element (com.zimbra.common.soap.Element)12 Provisioning (com.zimbra.cs.account.Provisioning)11 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)11 Test (org.junit.Test)8 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)7 NamedEntry (com.zimbra.cs.account.NamedEntry)6 ArrayList (java.util.ArrayList)6 ServiceException (com.zimbra.common.service.ServiceException)5 Server (com.zimbra.cs.account.Server)4 Mailbox (com.zimbra.cs.mailbox.Mailbox)4 Invite (com.zimbra.cs.mailbox.calendar.Invite)4 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)4 ZAttendee (com.zimbra.cs.mailbox.calendar.ZAttendee)4 HashMap (java.util.HashMap)4 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)3 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)3 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)3 SoapTransport (com.zimbra.common.soap.SoapTransport)3