Author: btellier Date: Thu Jul 9 07:41:05 2015 New Revision: 1689999 URL: http://svn.apache.org/r1689999 Log: JAMES-1584 Command to delete all mailboxes of a user
Added: james/server/trunk/container/mailbox-adapter/src/test/ james/server/trunk/container/mailbox-adapter/src/test/java/ james/server/trunk/container/mailbox-adapter/src/test/java/org/ james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/ james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/ james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/ james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/ james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java Modified: james/server/trunk/container/cli/pom.xml james/server/trunk/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java james/server/trunk/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java james/server/trunk/container/mailbox-adapter/pom.xml james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java james/server/trunk/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml james/server/trunk/pom.xml Modified: james/server/trunk/container/cli/pom.xml URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/pom.xml?rev=1689999&r1=1689998&r2=1689999&view=diff ============================================================================== --- james/server/trunk/container/cli/pom.xml (original) +++ james/server/trunk/container/cli/pom.xml Thu Jul 9 07:41:05 2015 @@ -44,6 +44,10 @@ <artifactId>james-server-spring</artifactId> </dependency> <dependency> + <groupId>org.apache.james</groupId> + <artifactId>james-server-mailbox-adapter</artifactId> + </dependency> + <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli</artifactId> </dependency> Modified: james/server/trunk/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java?rev=1689999&r1=1689998&r2=1689999&view=diff ============================================================================== --- james/server/trunk/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java (original) +++ james/server/trunk/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java Thu Jul 9 07:41:05 2015 @@ -221,6 +221,13 @@ public class ServerCmd { printUsage(); System.exit(1); } + } else if (CmdType.DELETEUSERMAILBOXES.equals(cmdType)) { + if (cmdType.hasCorrectArguments(arguments.length)) { + probe.deleteUserMailboxesNames(arguments[1]); + } else { + printUsage(); + System.exit(1); + } } else { System.err.println("Unrecognized command: " + cmdName + "."); printUsage(); @@ -284,7 +291,8 @@ public class ServerCmd { "removeregexmapping <user> <domain> <regex>%n" + // "listuserdomainmappings <user> <domain>%n" + // "listmappings%n" + // - "copymailbox <srcbean> <dstbean>%n" // + "copymailbox <srcbean> <dstbean>%n" + // + "deleteusermailboxes <user>%n" // ); String usage = String.format("java %s --host <arg> <command>%n", ServerCmd.class.getName()); hf.printHelp(usage, "", options, header); Modified: james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java?rev=1689999&r1=1689998&r2=1689999&view=diff ============================================================================== --- james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java (original) +++ james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java Thu Jul 9 07:41:05 2015 @@ -23,164 +23,172 @@ import java.util.Collection; import java.util.Map; public interface ServerProbe extends Closeable { - /** - * Add a user to this mail server. - * - * @param userName - * The name of the user being added. - * @param password - * The password of the user being added. - * @throws Exception - */ - public void addUser(String userName, String password) throws Exception; - - /** - * Delete a user from this mail server. - * - * @param username - * The name of the user being deleted. - * @throws Exception - */ - public void removeUser(String username) throws Exception; - - /** - * Get a List the names of all users. - * - * @return a List of all user names. - * @throws Exception - */ - public String[] listUsers() throws Exception; - - /** - * Set a user's password. - * - * @param userName - * The name of the user whose password will be changed. - * @param password - * The new password. - * @throws Exception - */ - public void setPassword(String userName, String password) throws Exception; - - /** - * Add domain to the service. - * - * @param domain - * The domain to add. - * @throws Exception - */ - public void addDomain(String domain) throws Exception; - - /** - * Return true if the domain exists in the service - * - * @param domain - * The domain to remove. - * @throws Exception - */ - public boolean containsDomain(String domain) throws Exception; - - /** - * Remove domain from the service - * - * @param domain - * The domain to remove. - * @throws Exception - */ - public void removeDomain(String domain) throws Exception; - - /** - * Get a list of domains for the service. - * - * @return domains an array of domains, or null if no domains exist. - * @throws Exception - */ - public String[] listDomains() throws Exception; - - /** - * Get a Map which holds all mappings. The key is the user@domain and the - * value is a Collection which holds all mappings. - * - * @return a Map which holds all mappings. - * @throws Exception - */ - public Map<String, Collection<String>> listMappings() throws Exception; - - /** - * Add address mapping. - * - * @param user - * The username, or null if no username should be used. - * @param domain - * The domain, or null if no domain should be used. - * @param toAddress - * The address. - * @throws Exception - */ - public void addAddressMapping(String user, String domain, String toAddress) throws Exception; - - /** - * Remove address mapping. - * - * @param user - * The username, or null if no username should be used. - * @param domain - * The domain, or null if no domain should be used - * @param fromAddress - * The address. - * @throws Exception - */ - public void removeAddressMapping(String user, String domain, String fromAddress) throws Exception; - - /** - * Return the explicit mapping stored for the given user and domain. Return - * null if no mapping was found - * - * @param user - * The username. - * @param domain - * The domain. - * @return the collection which holds the mappings, or null if no mapping is - * found. - * @throws Exception - */ - public Collection<String> listUserDomainMappings(String user, String domain) throws Exception; - - /** - * Remove regex mapping. - * - * @param user - * The username, or null if no username should be used. - * @param domain - * The domain, or null if no domain should be used. - * @param regex - * The regex. - * @throws Exception - */ - public void addRegexMapping(String user, String domain, String regex) throws Exception; - - /** - * Remove regex mapping. - * - * @param user - * The username, or null if no username should be used. - * @param domain - * The domain, or null if no domain should be used. - * @param regex - * The regex. - * @throws Exception - */ - public void removeRegexMapping(String user, String domain, String regex) throws Exception; - - /** - * Copy Mailbox. - * - * @param srcBean - * The name of the bean that manages the source mailbox. - * @param dstBean - * The name of the bean that manages the destination mailbox. - * @throws Exception - */ - void copyMailbox(String srcBean, String dstBean) throws Exception; - + /** + * Add a user to this mail server. + * + * @param userName + * The name of the user being added. + * @param password + * The password of the user being added. + * @throws Exception + */ + public void addUser(String userName, String password) throws Exception; + + /** + * Delete a user from this mail server. + * + * @param username + * The name of the user being deleted. + * @throws Exception + */ + public void removeUser(String username) throws Exception; + + /** + * Get a List the names of all users. + * + * @return a List of all user names. + * @throws Exception + */ + public String[] listUsers() throws Exception; + + /** + * Set a user's password. + * + * @param userName + * The name of the user whose password will be changed. + * @param password + * The new password. + * @throws Exception + */ + public void setPassword(String userName, String password) throws Exception; + + /** + * Add domain to the service. + * + * @param domain + * The domain to add. + * @throws Exception + */ + public void addDomain(String domain) throws Exception; + + /** + * Return true if the domain exists in the service + * + * @param domain + * The domain to remove. + * @throws Exception + */ + public boolean containsDomain(String domain) throws Exception; + + /** + * Remove domain from the service + * + * @param domain + * The domain to remove. + * @throws Exception + */ + public void removeDomain(String domain) throws Exception; + + /** + * Get a list of domains for the service. + * + * @return domains an array of domains, or null if no domains exist. + * @throws Exception + */ + public String[] listDomains() throws Exception; + + /** + * Get a Map which holds all mappings. The key is the user@domain and the + * value is a Collection which holds all mappings. + * + * @return a Map which holds all mappings. + * @throws Exception + */ + public Map<String, Collection<String>> listMappings() throws Exception; + + /** + * Add address mapping. + * + * @param user + * The username, or null if no username should be used. + * @param domain + * The domain, or null if no domain should be used. + * @param toAddress + * The address. + * @throws Exception + */ + public void addAddressMapping(String user, String domain, String toAddress) throws Exception; + + /** + * Remove address mapping. + * + * @param user + * The username, or null if no username should be used. + * @param domain + * The domain, or null if no domain should be used + * @param fromAddress + * The address. + * @throws Exception + */ + public void removeAddressMapping(String user, String domain, String fromAddress) throws Exception; + + /** + * Return the explicit mapping stored for the given user and domain. Return + * null if no mapping was found + * + * @param user + * The username. + * @param domain + * The domain. + * @return the collection which holds the mappings, or null if no mapping is + * found. + * @throws Exception + */ + public Collection<String> listUserDomainMappings(String user, String domain) throws Exception; + + /** + * Remove regex mapping. + * + * @param user + * The username, or null if no username should be used. + * @param domain + * The domain, or null if no domain should be used. + * @param regex + * The regex. + * @throws Exception + */ + public void addRegexMapping(String user, String domain, String regex) throws Exception; + + /** + * Remove regex mapping. + * + * @param user + * The username, or null if no username should be used. + * @param domain + * The domain, or null if no domain should be used. + * @param regex + * The regex. + * @throws Exception + */ + public void removeRegexMapping(String user, String domain, String regex) throws Exception; + + /** + * Copy Mailbox. + * + * @param srcBean + * The name of the bean that manages the source mailbox. + * @param dstBean + * The name of the bean that manages the destination mailbox. + * @throws Exception + */ + void copyMailbox(String srcBean, String dstBean) throws Exception; + + /** + * Return the name of all mailboxes belonging to #private:${user} + * + * @param user Username of the user we want to list mailboxes on + * @return Collection of the mailboxes names + * @throws Exception + */ + void deleteUserMailboxesNames(String user) throws Exception; } Modified: james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java?rev=1689999&r1=1689998&r2=1689999&view=diff ============================================================================== --- james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java (original) +++ james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java Thu Jul 9 07:41:05 2015 @@ -18,6 +18,7 @@ ****************************************************************/ package org.apache.james.cli.probe.impl; +import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean; import org.apache.james.cli.probe.ServerProbe; import org.apache.james.container.spring.mailbox.MailboxCopierManagementMBean; import org.apache.james.domainlist.api.DomainListManagementMBean; @@ -42,6 +43,7 @@ public class JmxServerProbe implements S private final static String VIRTUALUSERTABLE_OBJECT_NAME = "org.apache.james:type=component,name=recipientrewritetable"; private final static String USERSREPOSITORY_OBJECT_NAME = "org.apache.james:type=component,name=usersrepository"; private final static String MAILBOXCOPIER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxcopier"; + private final static String MAILBOXMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxmanagerbean"; private JMXConnector jmxc; @@ -49,6 +51,7 @@ public class JmxServerProbe implements S private RecipientRewriteTableManagementMBean virtualUserTableProxy; private UsersRepositoryManagementMBean usersRepositoryProxy; private MailboxCopierManagementMBean mailboxCopierManagement; + private MailboxManagerManagementMBean mailboxManagerManagement; private static final String fmtUrl = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi"; private static final int defaultPort = 9999; @@ -103,6 +106,9 @@ public class JmxServerProbe implements S name = new ObjectName(MAILBOXCOPIER_OBJECT_NAME); mailboxCopierManagement = MBeanServerInvocationHandler.newProxyInstance( mbeanServerConn, name, MailboxCopierManagementMBean.class, true); + name = new ObjectName(MAILBOXMANAGER_OBJECT_NAME); + mailboxManagerManagement = MBeanServerInvocationHandler.newProxyInstance( + mbeanServerConn, name, MailboxManagerManagementMBean.class, true); } catch (MalformedObjectNameException e) { throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e); } @@ -188,4 +194,8 @@ public class JmxServerProbe implements S mailboxCopierManagement.copy(srcBean, dstBean); } + @Override + public void deleteUserMailboxesNames(String user) throws Exception { + mailboxManagerManagement.deleteMailboxes(user); + } } Modified: james/server/trunk/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java?rev=1689999&r1=1689998&r2=1689999&view=diff ============================================================================== --- james/server/trunk/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java (original) +++ james/server/trunk/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java Thu Jul 9 07:41:05 2015 @@ -36,7 +36,8 @@ public enum CmdType { ADDREGEXMAPPING("addregexmapping", 4), // REMOVEREGEXMAPPING("removeregexmapping", 4), // SETPASSWORD("setpassword", 3), // - COPYMAILBOX("copymailbox", 3) // + COPYMAILBOX("copymailbox", 3), // + DELETEUSERMAILBOXES("deleteusermailboxes", 2) // ; private final String command; private final int arguments; Modified: james/server/trunk/container/mailbox-adapter/pom.xml URL: http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/pom.xml?rev=1689999&r1=1689998&r2=1689999&view=diff ============================================================================== --- james/server/trunk/container/mailbox-adapter/pom.xml (original) +++ james/server/trunk/container/mailbox-adapter/pom.xml Thu Jul 9 07:41:05 2015 @@ -28,7 +28,6 @@ <relativePath>../../pom.xml</relativePath> </parent> - <groupId>org.apache.james</groupId> <artifactId>james-server-mailbox-adapter</artifactId> <packaging>bundle</packaging> @@ -63,6 +62,28 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-mailbox-memory</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-mailbox-store</artifactId> + <type>test-jar</type> + <scope>test</scope> + <version>${mailbox.version}</version> + </dependency> </dependencies> <build> Modified: james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java?rev=1689999&r1=1689998&r2=1689999&view=diff ============================================================================== --- james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java (original) +++ james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java Thu Jul 9 07:41:05 2015 @@ -22,14 +22,18 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import javax.annotation.Resource; import javax.inject.Inject; +import javax.inject.Named; import javax.management.NotCompliantMBeanException; import javax.management.StandardMBean; +import com.google.common.base.Preconditions; import org.apache.james.lifecycle.api.LogEnabled; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxMetaData; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.MailboxQuery; @@ -44,7 +48,8 @@ public class MailboxManagerManagement ex private Logger log; @Inject - public void setMailboxManager(MailboxManager mailboxManager) { + @Resource(name = "mailboxmanager") + public void setMailboxManager(@Named("mailboxmanager") MailboxManager mailboxManager) { this.mailboxManager = mailboxManager; } @@ -55,12 +60,14 @@ public class MailboxManagerManagement ex /** * @see org.apache.james.adapter.mailbox.MailboxManagerManagementMBean#deleteMailboxes(java.lang.String) */ + @Override public boolean deleteMailboxes(String username) { + Preconditions.checkArgument(username != null, "Username should not be null"); MailboxSession session = null; try { session = mailboxManager.createSystemSession(username, log); mailboxManager.startProcessingRequest(session); - List<MailboxMetaData> mList = mailboxManager.search(new MailboxQuery(MailboxPath.inbox(session), "", session.getPathDelimiter()), session); + List<MailboxMetaData> mList = retrieveAllUserMailboxes(username, session); for (MailboxMetaData aMList : mList) { mailboxManager.deleteMailbox(aMList.getPath(), session); } @@ -92,13 +99,14 @@ public class MailboxManagerManagement ex * org.apache.james.adapter.mailbox.MailboxManagerManagementMBean#listMailboxes * (java.lang.String) */ + @Override public List<String> listMailboxes(String username) { List<String> boxes = new ArrayList<String>(); MailboxSession session = null; try { session = mailboxManager.createSystemSession(username, log); mailboxManager.startProcessingRequest(session); - List<MailboxMetaData> mList = mailboxManager.search(new MailboxQuery(MailboxPath.inbox(session), "", session.getPathDelimiter()), session); + List<MailboxMetaData> mList = retrieveAllUserMailboxes(username, session); for (MailboxMetaData aMList : mList) { boxes.add(aMList.getPath().getName()); } @@ -117,4 +125,12 @@ public class MailboxManagerManagement ex } return boxes; } + + private List<MailboxMetaData> retrieveAllUserMailboxes(String username, MailboxSession session) throws MailboxException { + return mailboxManager.search( + new MailboxQuery(new MailboxPath(MailboxConstants.USER_NAMESPACE, username, ""), + "*", + session.getPathDelimiter()), + session); + } } \ No newline at end of file Added: james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java?rev=1689999&view=auto ============================================================================== --- james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java (added) +++ james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java Thu Jul 9 07:41:05 2015 @@ -0,0 +1,125 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.adapter.mailbox; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.james.mailbox.MailboxSession; +import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver; +import org.apache.james.mailbox.acl.UnionMailboxACLResolver; +import org.apache.james.mailbox.inmemory.InMemoryId; +import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory; +import org.apache.james.mailbox.model.MailboxConstants; +import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.store.JVMMailboxPathLocker; +import org.apache.james.mailbox.store.MockAuthenticator; +import org.apache.james.mailbox.store.StoreMailboxManager; +import org.apache.james.mailbox.store.mail.model.Mailbox; +import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MailboxManagementTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(MailboxManagementTest.class); + public static final String USER = "user"; + public static final int UID_VALIDITY = 10; + + private MailboxManagerManagement mailboxManagerManagement; + private InMemoryMailboxSessionMapperFactory inMemoryMapperFactory; + private MailboxSession session; + + @Before + public void setUp() throws Exception { + inMemoryMapperFactory = new InMemoryMailboxSessionMapperFactory(); + StoreMailboxManager<InMemoryId> mailboxManager = new StoreMailboxManager<InMemoryId>( + inMemoryMapperFactory, + new MockAuthenticator(), + new JVMMailboxPathLocker(), + new UnionMailboxACLResolver(), + new SimpleGroupMembershipResolver()); + mailboxManager.init(); + mailboxManagerManagement = new MailboxManagerManagement(); + mailboxManagerManagement.setMailboxManager(mailboxManager); + mailboxManagerManagement.setLog(LOGGER); + session = mailboxManager.createSystemSession("TEST", LOGGER); + } + + @Test + public void deleteMailboxesShouldDeleteMailboxes() throws Exception { + inMemoryMapperFactory.createMailboxMapper(session).save(new SimpleMailbox<InMemoryId>(new MailboxPath(MailboxConstants.USER_NAMESPACE, USER, "name"), UID_VALIDITY)); + mailboxManagerManagement.deleteMailboxes(USER); + assertThat(inMemoryMapperFactory.createMailboxMapper(session).list()).isEmpty(); + } + + @Test + public void deleteMailboxesShouldDeleteInbox() throws Exception { + inMemoryMapperFactory.createMailboxMapper(session).save(new SimpleMailbox<InMemoryId>(new MailboxPath(MailboxConstants.USER_NAMESPACE, USER, "INBOX"), UID_VALIDITY)); + mailboxManagerManagement.deleteMailboxes(USER); + assertThat(inMemoryMapperFactory.createMailboxMapper(session).list()).isEmpty(); + } + + @Test + public void deleteMailboxesShouldDeleteMailboxesChildren() throws Exception { + inMemoryMapperFactory.createMailboxMapper(session).save(new SimpleMailbox<InMemoryId>(new MailboxPath(MailboxConstants.USER_NAMESPACE, USER, "INBOX.test"), UID_VALIDITY)); + mailboxManagerManagement.deleteMailboxes(USER); + assertThat(inMemoryMapperFactory.createMailboxMapper(session).list()).isEmpty(); + } + + @Test + public void deleteMailboxesShouldNotDeleteMailboxesBelongingToNotPrivateNamespace() throws Exception { + Mailbox<InMemoryId> mailbox = new SimpleMailbox<InMemoryId>(new MailboxPath("#top", USER, "name"), UID_VALIDITY); + inMemoryMapperFactory.createMailboxMapper(session).save(mailbox); + mailboxManagerManagement.deleteMailboxes(USER); + assertThat(inMemoryMapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox); + } + + @Test + public void deleteMailboxesShouldNotDeleteMailboxesBelongingToOtherUsers() throws Exception { + Mailbox<InMemoryId> mailbox = new SimpleMailbox<InMemoryId>(new MailboxPath(MailboxConstants.USER_NAMESPACE, "userbis", "name"), UID_VALIDITY); + inMemoryMapperFactory.createMailboxMapper(session).save(mailbox); + mailboxManagerManagement.deleteMailboxes(USER); + assertThat(inMemoryMapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox); + } + + @Test + public void deleteMailboxesShouldDeleteMailboxesWithEmptyNames() throws Exception { + inMemoryMapperFactory.createMailboxMapper(session).save(new SimpleMailbox<InMemoryId>(new MailboxPath(MailboxConstants.USER_NAMESPACE, USER, ""), UID_VALIDITY)); + mailboxManagerManagement.deleteMailboxes(USER); + assertThat(inMemoryMapperFactory.createMailboxMapper(session).list()).isEmpty(); + } + + @Test(expected = IllegalArgumentException.class) + public void deleteMailboxesShouldThrowOnNullUserName() throws Exception { + mailboxManagerManagement.deleteMailboxes(null); + } + + @Test + public void deleteMailboxesShouldDeleteMultipleMailboxes() throws Exception { + inMemoryMapperFactory.createMailboxMapper(session).save(new SimpleMailbox<InMemoryId>(new MailboxPath(MailboxConstants.USER_NAMESPACE, USER, "name"), UID_VALIDITY)); + inMemoryMapperFactory.createMailboxMapper(session).save(new SimpleMailbox<InMemoryId>(new MailboxPath(MailboxConstants.USER_NAMESPACE, USER, "INBOX"), UID_VALIDITY)); + inMemoryMapperFactory.createMailboxMapper(session).save(new SimpleMailbox<InMemoryId>(new MailboxPath(MailboxConstants.USER_NAMESPACE, USER, "INBOX.test"), UID_VALIDITY)); + mailboxManagerManagement.deleteMailboxes(USER); + assertThat(inMemoryMapperFactory.createMailboxMapper(session).list()).isEmpty(); + } + +} Modified: james/server/trunk/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml URL: http://svn.apache.org/viewvc/james/server/trunk/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml?rev=1689999&r1=1689998&r2=1689999&view=diff ============================================================================== --- james/server/trunk/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml (original) +++ james/server/trunk/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml Thu Jul 9 07:41:05 2015 @@ -212,8 +212,8 @@ <entry key="org.apache.james:type=component,name=usersrepository" value-ref="usersrepositorymanagement"/> <entry key="org.apache.james:type=component,name=fetchmail" value-ref="fetchmail"/> - <entry key="org.apache.james:type=component,name=mailboxmanagement" - value-ref="mailboxmanagermanagement"/> + <entry key="org.apache.james:type=component,name=mailboxmanagerbean" + value-ref="mailboxmanagermanagementbean"/> <entry key="org.apache.james:type=component,component=mailetcontainer,name=mailspooler" value-ref="mailspooler"/> <entry key="org.apache.james:type=component,name=mailboxcopier" value-ref="mailboxcopiermanagement"/> @@ -234,7 +234,7 @@ <bean id="usersrepositorymanagement" class="org.apache.james.user.lib.UsersRepositoryManagement"/> <bean id="recipientrewritetablemanagement" class="org.apache.james.rrt.lib.RecipientRewriteTableManagement"/> <bean id="domainlistmanagement" class="org.apache.james.domainlist.lib.DomainListManagement"/> - <bean id="mailboxmanagermanagement" class="org.apache.james.adapter.mailbox.MailboxManagerManagement"/> + <bean id="mailboxmanagermanagementbean" class="org.apache.james.adapter.mailbox.MailboxManagerManagement"/> <bean id="mailboxcopiermanagement" class="org.apache.james.container.spring.mailbox.MailboxCopierManagement"/> <!-- <bean id="james23importermanagement" class="org.apache.james.container.spring.tool.James23ImporterManagement" /> Modified: james/server/trunk/pom.xml URL: http://svn.apache.org/viewvc/james/server/trunk/pom.xml?rev=1689999&r1=1689998&r2=1689999&view=diff ============================================================================== --- james/server/trunk/pom.xml (original) +++ james/server/trunk/pom.xml Thu Jul 9 07:41:05 2015 @@ -840,6 +840,11 @@ <version>${jmock.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>3.0.0</version> + </dependency> <dependency> <groupId>org.mockito</groupId> --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org