Results 1 to 4 of 4

Thread: Test Delete Zimbra account coding

  1. #1
    fsloke is offline Loyal Member
    Join Date
    Jul 2008
    Posts
    91
    Rep Power
    7

    Default Test Delete Zimbra account coding

    This is the sample code that can I found in the google.
    This code is a unitTest for deleteAccount

    Code:
    package zimbra;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import com.zimbra.cs.account.Account;
    import com.zimbra.cs.account.Provisioning;
    import com.zimbra.cs.account.Provisioning.AccountBy;
    import com.zimbra.cs.client.LmcSession;
    import com.zimbra.cs.client.soap.LmcDeleteAccountRequest;
    import com.zimbra.cs.db.DbMailbox;
    import com.zimbra.cs.db.DbResults;
    import com.zimbra.cs.db.DbUtil;
    import com.zimbra.common.localconfig.LC;
    import com.zimbra.cs.mailbox.Mailbox;
    import com.zimbra.cs.mailbox.MailboxManager;
    import com.zimbra.common.util.ZimbraLog;
    
    import com.zimbra.qa.unittest.TestUtil;
    
    
    /**
     * @author bburtin
     */
    public class TestAccount{
    
        private static String USER_NAME = "TestAccount";
        // xxx move this to TestUtil
        private static String PASSWORD = "123456";
    
        public static void main(String [] args)
        throws Exception {
            cleanUp();
            
            Map<String, Object> attrs = new HashMap<String, Object>();
            attrs.put("https://3.244.4.16:7071/zimbraAdmin", LC.zimbra_server_hostname.value());
            attrs.put("cn", "TestAccount");
            attrs.put("displayName", "TestAccount unit test user");
            Provisioning.getInstance().createAccount(TestUtil.getAddress(USER_NAME), PASSWORD, attrs);
        }
        
        public void tearDown()
        throws Exception {
            cleanUp();
        }
        
        public void testDeleteAccount()
        throws Exception {
            ZimbraLog.test.debug("testDeleteAccount()");
            
            // Get the account and mailbox
            Account account = TestUtil.getAccount(USER_NAME);
            Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
            String dbName = DbMailbox.getDatabaseName(mbox);
            ZimbraLog.test.debug("Account=" + account.getId() + ", mbox=" + mbox.getId());
            
            // Confirm that the mailbox database exists
            DbResults results = DbUtil.executeQuery(
                "SELECT COUNT(*) FROM mailbox WHERE id = " + mbox.getId());
            System.out.println("Could not find row in mailbox table"+ " 1 " + results.getInt(1));
            
            results = DbUtil.executeQuery("SHOW DATABASES LIKE '" + dbName + "'");
            System.out.println("Could not find mailbox database"+" 1 " + results.size());
            
            // Delete the account
            LmcSession session = TestUtil.getAdminSoapSession();
            LmcDeleteAccountRequest req = new LmcDeleteAccountRequest(account.getId());
            req.setSession(session);
            req.invoke(TestUtil.getAdminSoapUrl());
            
            // Confirm that the mailbox was deleted
            results = DbUtil.executeQuery(
                "SELECT COUNT(*) FROM mailbox WHERE id = " + mbox.getId());
             System.out.println("Unexpected row in mailbox table"+" 0 "+ results.getInt(1));
        }
        
        private static void cleanUp()
        throws Exception {
            Provisioning prov = Provisioning.getInstance(); 
            Account account = prov.get(AccountBy.name, TestUtil.getAddress(USER_NAME));
            if (account != null) {
                prov.deleteAccount(account.getId());
            }
        }
    }
    The code no manage to executed...

    init:
    deps-jar:
    Compiling 1 source file to C:\Practice\Zimbra\build\classes
    compile-single:
    run-single:
    log4j:WARN No appenders could be found for logger (zimbra.misc).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/map/LRUMap
    at com.zimbra.cs.account.AccountCache.<init>(AccountC ache.java:54)
    at com.zimbra.cs.account.ldap.LdapProvisioning.<clini t>(LdapProvisioning.java:155)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at com.zimbra.cs.account.Provisioning.getInstance(Pro visioning.java:1538)
    at zimbra.TestAccount.cleanUp(TestAccount.java:79)
    at zimbra.TestAccount.main(TestAccount.java:33)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.map.LRUMap
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
    ... 7 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)
    Thank you

  2. #2
    fsloke is offline Loyal Member
    Join Date
    Jul 2008
    Posts
    91
    Rep Power
    7

    Default

    Problem solved : add the commons-collections-3.1.jar

    But the code still didn't work:

    init:
    deps-jar:
    Compiling 1 source file to C:\Practice\Zimbra\build\classes
    compile-single:
    run-single:
    log4j:WARN No appenders could be found for logger (zimbra.misc).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread "main" com.zimbra.common.service.ServiceException: system failure: ZimbraLdapContext
    ExceptionId:main:1220411105562:c823b76077bc7e50
    Code:service.FAILURE
    at com.zimbra.common.service.ServiceException.FAILURE (ServiceException.java:253)
    at com.zimbra.cs.account.ldap.ZimbraLdapContext.<init >(ZimbraLdapContext.java:268)
    at com.zimbra.cs.account.ldap.ZimbraLdapContext.<init >(ZimbraLdapContext.java:232)
    at com.zimbra.cs.account.ldap.ZimbraLdapContext.<init >(ZimbraLdapContext.java:225)
    at com.zimbra.cs.account.ldap.LdapProvisioning.getCon fig(LdapProvisioning.java:372)
    at com.zimbra.qa.unittest.TestUtil.getDomain(TestUtil .java:106)
    at com.zimbra.qa.unittest.TestUtil.getAddress(TestUti l.java:120)
    at zimbra.TestAccount.cleanUp(TestAccount.java:80)
    at zimbra.TestAccount.main(TestAccount.java:33)
    Caused by: javax.naming.CommunicationException: localhost:389 [Root exception is java.net.ConnectException: Connection refused: connect]
    at com.sun.jndi.ldap.Connection.<init>(Connection.jav a:197)
    at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.jav a:118)
    at com.sun.jndi.ldap.LdapClientFactory.createPooledCo nnection(LdapClientFactory.java:46)
    at com.sun.jndi.ldap.pool.Connections.<init>(Connecti ons.java:97)
    at com.sun.jndi.ldap.pool.Pool.getPooledConnection(Po ol.java:114)
    at com.sun.jndi.ldap.LdapPoolManager.getLdapClient(Ld apPoolManager.java:310)
    at com.sun.jndi.ldap.LdapClient.getInstance(LdapClien t.java:1572)
    at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:261 6)
    at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:287)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapC txFactory.java:175)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(Ldap CtxFactory.java:193)
    at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstanc e(LdapCtxFactory.java:136)
    at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext (LdapCtxFactory.java:66)
    at javax.naming.spi.NamingManager.getInitialContext(N amingManager.java:667)
    at javax.naming.InitialContext.getDefaultInitCtx(Init ialContext.java:288)
    at javax.naming.InitialContext.init(InitialContext.ja va:223)
    at javax.naming.ldap.InitialLdapContext.<init>(Initia lLdapContext.java:134)
    at com.zimbra.cs.account.ldap.ZimbraLdapContext.<init >(ZimbraLdapContext.java:247)
    ... 7 more
    Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl .java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSoc ketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:366)
    at java.net.Socket.connect(Socket.java:519)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.jndi.ldap.Connection.createSocket(Connecti on.java:336)
    at com.sun.jndi.ldap.Connection.<init>(Connection.jav a:184)
    ... 24 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 3 seconds)
    I hope no file need to be added...

    Thank you

  3. #3
    Shikha Sood is offline Active Member
    Join Date
    Jul 2008
    Location
    New Delhi, India
    Posts
    30
    Rep Power
    7

    Default Try Soap provisioning API

    try the following code:

    Code:
    public boolean DeleteAccount(String emailId) {
    		boolean isAccountDeleted = false;
    
    		ZimbraUser zimbraUser = new ZimbraUser();
    
    		try {
    			logger.debug("Delete account:" + emailId);
    			SoapProvisioning sp = new SoapProvisioning();
    			sp.soapSetURI(zimbraUser.ZIMBRA_URL_ADMIN
    					+ ZimbraServlet.ADMIN_SERVICE_URI);
    			sp.soapAdminAuthenticate(zimbraUser.ADMIN_USER,
    					zimbraUser.ADMIN_PASSWORD);
    			Account account = sp.get(AccountBy.name, emailId);
    			sp.deleteAccount(account.getId());
    			isAccountDeleted = true;
    		} catch (Exception e) {
    			isAccountDeleted = false;
    			e.printStackTrace();
    			logger.debug("COULD NOT DELETE ACCOUNT");
    		}
    
    		return isAccountDeleted;
    	}
    You can also try the script in the following link, if require bulk deletion:
    Bulk Provisioning - Zimbra :: Wiki

  4. #4
    saman is offline Junior Member
    Join Date
    Nov 2008
    Posts
    6
    Rep Power
    6

    Thumbs up Thank you very much.The code is working fine for me..

    Thank you very much.The code is working fine for me..I was also facing problem in deleting account from zimbra...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. slapd message error
    By smoke in forum Administrators
    Replies: 7
    Last Post: 04-27-2008, 03:23 PM
  2. Replies: 12
    Last Post: 02-25-2008, 07:28 PM
  3. Zimbra shutdowns every n hours.
    By Andrewb in forum Administrators
    Replies: 13
    Last Post: 08-14-2007, 08:55 AM
  4. Zimbra server crashed
    By goetzi in forum Administrators
    Replies: 6
    Last Post: 03-25-2006, 01:00 PM
  5. port 7071 not listening OS X install
    By leeimber in forum Installation
    Replies: 7
    Last Post: 03-21-2006, 10:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •