Search in sources :

Example 21 with AccountServiceException

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

the class TestLdapProvAccount method renameAccountAlreadyExists.

@Test
public void renameAccountAlreadyExists() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String ACCT_NAME_EXISTS_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart("exists"));
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    Account acctExists = createAccount(ACCT_NAME_EXISTS_LOCALPART);
    String acctId = acct.getId();
    String ACCT_NEW_NAME = acctExists.getName();
    boolean caughtException = false;
    try {
        prov.renameAccount(acctId, ACCT_NEW_NAME);
    } catch (AccountServiceException e) {
        if (AccountServiceException.ACCOUNT_EXISTS.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    deleteAccount(acct);
    deleteAccount(acctExists);
}
Also used : Account(com.zimbra.cs.account.Account) AccountServiceException(com.zimbra.cs.account.AccountServiceException)

Example 22 with AccountServiceException

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

the class TestLdapProvSignature method createSignatureWithExistingId.

@Test
public void createSignatureWithExistingId() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String SIGNATURE_NAME = Names.makeSignatureName(genSignatureName());
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    Signature signature = createSignature(acct, SIGNATURE_NAME);
    String id = signature.getAttr("zimbraSignatureId");
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put("zimbraSignatureId", id);
    try {
        prov.createSignature(acct, SIGNATURE_NAME + "_NEW", attrs);
        fail("Create signature should not have succeeded, as signatureId exists.");
    } catch (AccountServiceException e) {
        assertEquals(AccountServiceException.SIGNATURE_EXISTS, e.getCode());
    }
}
Also used : Account(com.zimbra.cs.account.Account) AccountServiceException(com.zimbra.cs.account.AccountServiceException) HashMap(java.util.HashMap) Signature(com.zimbra.cs.account.Signature) Test(org.junit.Test)

Example 23 with AccountServiceException

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

the class TestLdapProvXMPPComponent method createXMPPComponentAlreadyExists.

@Test
public void createXMPPComponentAlreadyExists() throws Exception {
    String XMPPCPNT_NAME = Names.makeXMPPName(genXMPPName());
    XMPPComponent xmppCpnt = createXMPPComponent(XMPPCPNT_NAME);
    boolean caughtException = false;
    try {
        Map<String, Object> attrs = new HashMap<String, Object>();
        attrs.put(Provisioning.A_zimbraXMPPComponentCategory, "whatever");
        attrs.put(Provisioning.A_zimbraXMPPComponentClassName, "whatever");
        attrs.put(Provisioning.A_zimbraXMPPComponentType, "whatever");
        prov.createXMPPComponent(XMPPCPNT_NAME, domain, server, attrs);
    } catch (AccountServiceException e) {
        if (AccountServiceException.IM_COMPONENT_EXISTS.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    deleteXMPPComponent(xmppCpnt);
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) HashMap(java.util.HashMap) XMPPComponent(com.zimbra.cs.account.XMPPComponent)

Example 24 with AccountServiceException

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

the class TestLdapProvDomain method createDomainAlreadyExists.

@Test
public void createDomainAlreadyExists() throws Exception {
    String DOMAIN_NAME = makeTestDomainName(genDomainSegmentName());
    Domain domain = createDomain(DOMAIN_NAME);
    boolean caughtException = false;
    try {
        prov.createDomain(DOMAIN_NAME, new HashMap<String, Object>());
    } catch (AccountServiceException e) {
        if (AccountServiceException.DOMAIN_EXISTS.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    deleteDomain(domain);
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) Domain(com.zimbra.cs.account.Domain)

Example 25 with AccountServiceException

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

the class TestLdapProvModifyAttrs method invalidAttrValue.

@Test
public void invalidAttrValue() throws Exception {
    // set multiple values to a single-valued attr
    String ATTR_NAME = Provisioning.A_zimbraPrefSkin;
    String ATTR_VALUE_1 = "invalidAttrValue-1";
    String ATTR_VALUE_2 = "invalidAttrValue-2";
    Account acct = createAccount(genAcctNameLocalPart());
    boolean caughtException = false;
    try {
        modifyMultiValue(acct, "+" + ATTR_NAME, new String[] { ATTR_VALUE_1, ATTR_VALUE_2 });
    } catch (AccountServiceException e) {
        if (AccountServiceException.INVALID_ATTR_VALUE.equals(e.getCode())) {
            caughtException = true;
        }
    } catch (ServiceException e) {
        if (InMemoryLdapServer.isOn()) {
            /*
                 * ubid InMemoryDirectoryServer returns OBJECT_CLASS_VIOLATION instead of 
                 * CONSTRAINT_VIOLATION/INVALID_ATTRIBUTE_SYNTAX.  OBJECT_CLASS_VIOLATION 
                 * is mapped to FAILURE in LdapProvisioning
                 */
            if (AccountServiceException.FAILURE.equals(e.getCode())) {
                caughtException = true;
            }
        }
    }
    assertTrue(caughtException);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException)

Aggregations

AccountServiceException (com.zimbra.cs.account.AccountServiceException)44 ServiceException (com.zimbra.common.service.ServiceException)22 LdapException (com.zimbra.cs.ldap.LdapException)20 LdapEntryAlreadyExistException (com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException)20 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)20 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)19 Account (com.zimbra.cs.account.Account)14 ZMutableEntry (com.zimbra.cs.ldap.ZMutableEntry)14 CallbackContext (com.zimbra.cs.account.callback.CallbackContext)13 Date (java.util.Date)13 Domain (com.zimbra.cs.account.Domain)10 HashMap (java.util.HashMap)10 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)8 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)5 Cos (com.zimbra.cs.account.Cos)4 Test (org.junit.Test)4 DistributionList (com.zimbra.cs.account.DistributionList)3 GuestAccount (com.zimbra.cs.account.GuestAccount)3 Server (com.zimbra.cs.account.Server)3 Signature (com.zimbra.cs.account.Signature)3