Author: btellier
Date: Thu Jul  9 07:43:50 2015
New Revision: 1690004

URL: http://svn.apache.org/r1690004
Log:
JAMES-1584 Refactor and test ServerCmd

Added:
    
james/server/trunk/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
Modified:
    james/server/trunk/container/cli/pom.xml
    
james/server/trunk/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java

Modified: james/server/trunk/container/cli/pom.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container/cli/pom.xml?rev=1690004&r1=1690003&r2=1690004&view=diff
==============================================================================
--- james/server/trunk/container/cli/pom.xml (original)
+++ james/server/trunk/container/cli/pom.xml Thu Jul  9 07:43:50 2015
@@ -56,6 +56,12 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <version>3.3.1</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

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=1690004&r1=1690003&r2=1690004&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:43:50 2015
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.cli;
 
+import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.HelpFormatter;
@@ -44,14 +45,20 @@ public class ServerCmd {
     private static final String HOST_OPT_SHORT = "h";
     private static final String PORT_OPT_LONG = "port";
     private static final String PORT_OPT_SHORT = "p";
-    private static final int defaultPort = 9999;
-    private static final Options options = new Options();
+    private static final int DEFAULT_PORT = 9999;
+    private static final Options OPTIONS = new Options();
+
+    private ServerProbe probe;
 
     static {
         Option optHost = new Option(HOST_OPT_SHORT, HOST_OPT_LONG, true, "node 
hostname or ip address");
         optHost.setRequired(true);
-        options.addOption(optHost);
-        options.addOption(PORT_OPT_SHORT, PORT_OPT_LONG, true, "remote jmx 
agent port number");
+        OPTIONS.addOption(optHost);
+        OPTIONS.addOption(PORT_OPT_SHORT, PORT_OPT_LONG, true, "remote jmx 
agent port number");
+    }
+
+    public ServerCmd(ServerProbe probe) {
+        this.probe = probe;
     }
 
     /**
@@ -63,206 +70,137 @@ public class ServerCmd {
      * @throws ParseException
      */
     public static void main(String[] args) throws IOException, 
InterruptedException, ParseException {
-
         long start = Calendar.getInstance().getTimeInMillis();
-
-        CommandLineParser parser = new PosixParser();
-        CommandLine cmd = null;
-
+        CommandLine cmd = parseCommandLine(args);
+        if (cmd.getArgs().length < 1) {
+            failWithMessage("Missing argument for command.");
+        }
         try {
-            cmd = parser.parse(options, args);
-        } catch (ParseException parseExcep) {
-            System.err.println(parseExcep);
-            printUsage();
-            System.exit(1);
+            new ServerCmd(new 
JmxServerProbe(cmd.getOptionValue(HOST_OPT_LONG), getPort(cmd)))
+                .executeCommandLine(start, cmd);
+        } catch (IOException ioe) {
+            System.err.println("Error connecting to remote JMX agent!");
+            ioe.printStackTrace();
+            System.exit(3);
+        } catch (Exception e) {
+            failWithMessage("Error while executing command:" + e.getMessage());
         }
+        System.exit(0);
+    }
 
-        // Verify arguments
-        if (cmd.getArgs().length < 1) {
-            System.err.println("Missing argument for command.");
+    @VisibleForTesting
+    static CommandLine parseCommandLine(String[] args) {
+        try {
+            CommandLineParser parser = new PosixParser();
+            return parser.parse(OPTIONS, args);
+        } catch (ParseException parseExcep) {
+            System.err.println(parseExcep.getMessage());
             printUsage();
+            parseExcep.printStackTrace(System.err);
             System.exit(1);
+            return null;
         }
+    }
 
-        String host = cmd.getOptionValue(HOST_OPT_LONG);
-        int port = defaultPort;
-
+    private static int getPort(CommandLine cmd) throws ParseException {
         String portNum = cmd.getOptionValue(PORT_OPT_LONG);
         if (portNum != null) {
             try {
-                port = Integer.parseInt(portNum);
+                return Integer.parseInt(portNum);
             } catch (NumberFormatException e) {
                 throw new ParseException("Port must be a number");
             }
         }
+        return DEFAULT_PORT;
+    }
 
-        ServerProbe probe = null;
-        try {
-            probe = new JmxServerProbe(host, port);
-        } catch (IOException ioe) {
-            System.err.println("Error connecting to remote JMX agent!");
-            ioe.printStackTrace();
-            System.exit(3);
-        }
-
-        ServerCmd sCmd = new ServerCmd();
+    private static void failWithMessage(String s) {
+        System.err.println(s);
+        printUsage();
+        System.exit(1);
+    }
 
-        // Execute the requested command.
+    @VisibleForTesting
+    void executeCommandLine(long start, CommandLine cmd) throws Exception {
         String[] arguments = cmd.getArgs();
         String cmdName = arguments[0];
-        CmdType cmdType = null;
-        try {
+        CmdType cmdType = CmdType.lookup(cmdName);
 
-            cmdType = CmdType.lookup(cmdName);
-
-            if (CmdType.ADDUSER.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.addUser(arguments[1], arguments[2]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.REMOVEUSER.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.removeUser(arguments[1]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.LISTUSERS.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    sCmd.print(probe.listUsers(), System.out);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.ADDDOMAIN.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.addDomain(arguments[1]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.REMOVEDOMAIN.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.removeDomain(arguments[1]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.CONTAINSDOMAIN.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.containsDomain(arguments[1]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.LISTDOMAINS.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    sCmd.print(probe.listDomains(), System.out);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.LISTMAPPINGS.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    sCmd.print(probe.listMappings(), System.out);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.LISTUSERDOMAINMAPPINGS.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    Collection<String> userDomainMappings = 
probe.listUserDomainMappings(arguments[1], arguments[2]);
-                    sCmd.print(userDomainMappings.toArray(new 
String[userDomainMappings.size()]), System.out);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.ADDADDRESSMAPPING.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.addAddressMapping(arguments[1], arguments[2], 
arguments[3]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.REMOVEADDRESSMAPPING.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.removeAddressMapping(arguments[1], arguments[2], 
arguments[3]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.ADDREGEXMAPPING.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.addRegexMapping(arguments[1], arguments[2], 
arguments[3]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.REMOVEREGEXMAPPING.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.removeRegexMapping(arguments[1], arguments[2], 
arguments[3]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.SETPASSWORD.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.setPassword(arguments[1], arguments[2]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.COPYMAILBOX.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.copyMailbox(arguments[1], arguments[2]);
-                } else {
-                    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 if (CmdType.CREATEMAILBOX.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.createMailbox(arguments[1], arguments[2], 
arguments[3]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.LISTUSERMAILBOXES.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    Collection<String> mailboxes = 
probe.listUserMailboxes(arguments[1]);
-                    sCmd.print(mailboxes.toArray(new 
String[mailboxes.size()]), System.out);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else if (CmdType.DELETEMAILBOX.equals(cmdType)) {
-                if (cmdType.hasCorrectArguments(arguments.length)) {
-                    probe.deleteMailbox(arguments[1], arguments[2], 
arguments[3]);
-                } else {
-                    printUsage();
-                    System.exit(1);
-                }
-            } else {
-                System.err.println("Unrecognized command: " + cmdName + ".");
-                printUsage();
-                System.exit(1);
-            }
-        } catch (Exception e) {
-            sCmd.onException(e, System.err);
-            System.exit(1);
+        if (! cmdType.hasCorrectArguments(arguments.length)) {
+            throw new Exception(String.format("%s is expecting %d arguments 
but got %d",
+                cmdType.getCommand(),
+                cmdType.getArguments(),
+                arguments.length));
+        }
+        executeCommand(arguments, cmdName, cmdType);
+
+        this.print(new String[] { cmdType.getCommand() + " command executed 
sucessfully in " + (Calendar.getInstance().getTimeInMillis() - start) + " ms." 
}, System.out);
+    }
+
+    private void executeCommand(String[] arguments, String cmdName, CmdType 
cmdType) throws Exception {
+        switch (cmdType) {
+        case ADDUSER:
+            probe.addUser(arguments[1], arguments[2]);
+            break;
+        case REMOVEUSER:
+            probe.removeUser(arguments[1]);
+            break;
+        case LISTUSERS:
+            print(probe.listUsers(), System.out);
+            break;
+        case ADDDOMAIN:
+            probe.addDomain(arguments[1]);
+            break;
+        case REMOVEDOMAIN:
+            probe.removeDomain(arguments[1]);
+            break;
+        case CONTAINSDOMAIN:
+            probe.containsDomain(arguments[1]);
+            break;
+        case LISTDOMAINS:
+            print(probe.listDomains(), System.out);
+            break;
+        case LISTMAPPINGS:
+            print(probe.listMappings(), System.out);
+            break;
+        case LISTUSERDOMAINMAPPINGS:
+            Collection<String> userDomainMappings = 
probe.listUserDomainMappings(arguments[1], arguments[2]);
+            this.print(userDomainMappings.toArray(new 
String[userDomainMappings.size()]), System.out);
+            break;
+        case ADDADDRESSMAPPING:
+            probe.addAddressMapping(arguments[1], arguments[2], arguments[3]);
+            break;
+        case REMOVEADDRESSMAPPING:
+            probe.removeAddressMapping(arguments[1], arguments[2], 
arguments[3]);
+            break;
+        case ADDREGEXMAPPING:
+            probe.addRegexMapping(arguments[1], arguments[2], arguments[3]);
+            break;
+        case REMOVEREGEXMAPPING:
+            probe.removeRegexMapping(arguments[1], arguments[2], arguments[3]);
+            break;
+        case SETPASSWORD:
+            probe.setPassword(arguments[1], arguments[2]);
+            break;
+        case COPYMAILBOX:
+            probe.copyMailbox(arguments[1], arguments[2]);
+            break;
+        case DELETEUSERMAILBOXES:
+            probe.deleteUserMailboxesNames(arguments[1]);
+            break;
+        case CREATEMAILBOX:
+            probe.createMailbox(arguments[1], arguments[2], arguments[3]);
+            break;
+        case LISTUSERMAILBOXES:
+            Collection<String> mailboxes = 
probe.listUserMailboxes(arguments[1]);
+            this.print(mailboxes.toArray(new String[mailboxes.size()]), 
System.out);
+            break;
+        case DELETEMAILBOX:
+            probe.deleteMailbox(arguments[1], arguments[2], arguments[3]);
+            break;
+        default:
+            throw new Exception("Unrecognized command: " + cmdName + ".");
         }
-
-        sCmd.print(new String[]{cmdType.getCommand() + " command executed 
sucessfully in "
-                + (Calendar.getInstance().getTimeInMillis() - start) + " 
ms."}, System.out);
-        System.exit(0);
     }
 
     /**
@@ -274,60 +212,56 @@ public class ServerCmd {
     public void print(String[] data, PrintStream out) {
         if (data == null)
             return;
-
         for (String u : data) {
             out.println(u);
         }
-
         out.println();
     }
 
     public void print(Map<String, Collection<String>> map, PrintStream out) {
         if (map == null)
             return;
-
         for (Entry<String, Collection<String>> entry : map.entrySet()) {
-            out.print(entry.getKey());
-            out.print("=");
-            out.println(entry.getValue().toString());
+            out.println(entry.getKey() + '=' + collectionToString(entry));
         }
         out.println();
     }
 
+    private String collectionToString(Entry<String, Collection<String>> entry) 
{
+        StringBuilder stringBuilder = new StringBuilder();
+        for (String value : entry.getValue()) {
+            stringBuilder.append(value).append(',');
+        }
+        return stringBuilder.toString();
+    }
+
     /**
      * Prints usage information to stdout.
      */
     private static void printUsage() {
         HelpFormatter hf = new HelpFormatter();
-        String header = String.format("%nAvailable commands:%n" + //
-                "adduser <username> <password>%n" + //
-                "setpassword <username> <password>%n" + //
-                "removeuser <username>%n" + "listusers%n" + //
-                "adddomain <domainname>%n" + //
-                "containsdomain <domainname>%n" + //
-                "removedomain <domainname>%n" + //
-                "listdomains%n" + //
-                "addaddressmapping <user> <domain> <fromaddress>%n" + //
-                "removeaddressmapping <user> <domain> <fromaddress>%n" + //
-                "addregexmapping <user> <domain> <regex>%n" + //
-                "removeregexmapping <user> <domain> <regex>%n" + //
-                "listuserdomainmappings <user> <domain>%n" + //
-                "listmappings%n" + //
-                "copymailbox <srcbean> <dstbean>%n" + //
-                "deleteusermailboxes <user>%n" + //
-                "createmailbox <namespace> <user> <name>%n" + //
-                "listusermailboxes <user>%n" + //
+        String footer = String.format("%nAvailable commands:%n" +
+                "adduser <username> <password>%n" +
+                "setpassword <username> <password>%n" +
+                "removeuser <username>%n" + "listusers%n" +
+                "adddomain <domainname>%n" +
+                "containsdomain <domainname>%n" +
+                "removedomain <domainname>%n" +
+                "listdomains%n" +
+                "addaddressmapping <user> <domain> <fromaddress>%n" +
+                "removeaddressmapping <user> <domain> <fromaddress>%n" +
+                "addregexmapping <user> <domain> <regex>%n" +
+                "removeregexmapping <user> <domain> <regex>%n" +
+                "listuserdomainmappings <user> <domain>%n" +
+                "listmappings%n" +
+                "copymailbox <srcbean> <dstbean>%n" +
+                "deleteusermailboxes <user>%n" +
+                "createmailbox <namespace> <user> <name>%n" +
+                "listusermailboxes <user>%n" +
                 "deletemailbox <namespace> <user> <name>%n"
         );
         String usage = String.format("java %s --host <arg> <command>%n", 
ServerCmd.class.getName());
-        hf.printHelp(usage, "", options, header);
+        hf.printHelp(usage, "", OPTIONS, footer);
     }
 
-    /**
-     * Handle an exception.
-     */
-    private void onException(Exception e, PrintStream out) {
-        out.println("Error while execute command:");
-        out.println(e.getMessage());
-    }
 }

Added: 
james/server/trunk/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java?rev=1690004&view=auto
==============================================================================
--- 
james/server/trunk/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
 (added)
+++ 
james/server/trunk/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
 Thu Jul  9 07:43:50 2015
@@ -0,0 +1,832 @@
+/****************************************************************
+ * 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.cli;
+
+import static org.easymock.EasyMock.createControl;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.HashMap;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.james.cli.probe.ServerProbe;
+import org.apache.james.cli.type.CmdType;
+import org.easymock.IMocksControl;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class ServerCmdTest {
+
+    public static final String ADDITIONAL_ARGUMENT = "additionalArgument";
+    private IMocksControl control;
+
+    private ServerProbe serverProbe;
+
+    private ServerCmd testee;
+
+    @Before
+    public void setup() {
+        control = createControl();
+        serverProbe = control.createMock(ServerProbe.class);
+        testee = new ServerCmd(serverProbe);
+    }
+
+    @Test
+    public void addDomainCommandShouldWork() throws Exception {
+        String domain = "example.com";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDDOMAIN.getCommand(), domain};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.addDomain(domain);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void removeDomainCommandShouldWork() throws Exception {
+        String domain = "example.com";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEDOMAIN.getCommand(), domain};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.removeDomain(domain);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void containsDomainCommandShouldWork() throws Exception {
+        String domain = "example.com";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.CONTAINSDOMAIN.getCommand(), domain};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        expect(serverProbe.containsDomain(domain)).andReturn(true);
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void listDomainsCommandShouldWork() throws Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTDOMAINS.getCommand()};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        String[] res = {};
+        expect(serverProbe.listDomains()).andReturn(res);
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void addUserCommandShouldWork() throws Exception {
+        String user = "user@domain";
+        String password = "password";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDUSER.getCommand(), user, password};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.addUser(user, password);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void removeUserCommandShouldWork() throws Exception {
+        String user = "user@domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEUSER.getCommand(), user};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.removeUser(user);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void listUsersCommandShouldWork() throws Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTUSERS.getCommand()};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        String[] res = {};
+        expect(serverProbe.listUsers()).andReturn(res);
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void listMappingsCommandShouldWork() throws Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTMAPPINGS.getCommand()};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        expect(serverProbe.listMappings()).andReturn(new HashMap<String, 
Collection<String>>());
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void listUserDomainMappingsCommandShouldWork() throws Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTUSERDOMAINMAPPINGS.getCommand(), user, domain};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        expect(serverProbe.listUserDomainMappings(user, domain)).andReturn(new 
ArrayList<String>());
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void addAddressCommandShouldWork() throws Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String address = "b...@apache.org";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDADDRESSMAPPING.getCommand(), user, domain, address};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.addAddressMapping(user, domain, address);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void removeAddressCommandShouldWork() throws Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String address = "b...@apache.org";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEADDRESSMAPPING.getCommand(), user, domain, address};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.removeAddressMapping(user, domain, address);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void addRegexMappingCommandShouldWork() throws Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String regex = "bis.*@apache.org";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDREGEXMAPPING.getCommand(), user, domain, regex};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.addRegexMapping(user, domain, regex);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void removeRegexMappingCommandShouldWork() throws Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String regex = "bis.*@apache.org";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEREGEXMAPPING.getCommand(), user, domain, regex};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.removeRegexMapping(user, domain, regex);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void setPasswordMappingCommandShouldWork() throws Exception {
+        String user = "user@domain";
+        String password = "pass";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.SETPASSWORD.getCommand(), user, password};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.setPassword(user, password);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void copyMailboxMappingCommandShouldWork() throws Exception {
+        String srcBean = "srcBean";
+        String dstBean = "dstBean";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.COPYMAILBOX.getCommand(), srcBean, dstBean};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.copyMailbox(srcBean, dstBean);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void deleteUserMailboxesMappingCommandShouldWork() throws Exception 
{
+        String user = "user@domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.DELETEUSERMAILBOXES.getCommand(), user};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.deleteUserMailboxesNames(user);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void createMailboxMappingCommandShouldWork() throws Exception {
+        String user = "user@domain";
+        String namespace = "#private";
+        String name = "INBOX.test";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.CREATEMAILBOX.getCommand(), namespace, user, name};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.createMailbox(namespace, user, name);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void deleteMailboxMappingCommandShouldWork() throws Exception {
+        String user = "user@domain";
+        String namespace = "#private";
+        String name = "INBOX.test";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.DELETEMAILBOX.getCommand(), namespace, user, name};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        serverProbe.deleteMailbox(namespace, user, name);
+        expectLastCall();
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test
+    public void listUserMailboxesMappingsCommandShouldWork() throws Exception {
+        String user = "user@domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTUSERMAILBOXES.getCommand(), user};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        expect(serverProbe.listUserMailboxes(user)).andReturn(new 
ArrayList<String>());
+
+        control.replay();
+        testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        control.verify();
+    }
+
+    @Test(expected = Exception.class)
+    public void addDomainCommandShouldThrowOnMissingArguments() throws 
Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDDOMAIN.getCommand()};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void removeDomainCommandShouldThrowOnMissingArguments() throws 
Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEDOMAIN.getCommand()};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void containsDomainCommandShouldThrowOnMissingArguments() throws 
Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.CONTAINSDOMAIN.getCommand()};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void addUserCommandShouldThrowOnMissingArguments() throws Exception 
{
+        String user = "user@domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDUSER.getCommand(), user};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void removeUserCommandShouldThrowOnMissingArguments() throws 
Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEUSER.getCommand()};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void listUserDomainMappingsCommandShouldThrowOnMissingArguments() 
throws Exception {
+        String user = "user@domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTUSERDOMAINMAPPINGS.getCommand(), user};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void addAddressCommandShouldThrowOnMissingArguments() throws 
Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDADDRESSMAPPING.getCommand(), user, domain};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void removeAddressCommandShouldThrowOnMissingArguments() throws 
Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEADDRESSMAPPING.getCommand(), user, domain};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void addRegexMappingCommandShouldThrowOnMissingArguments() throws 
Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDREGEXMAPPING.getCommand(), user, domain};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void removeRegexMappingCommandShouldThrowOnMissingArguments() 
throws Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEREGEXMAPPING.getCommand(), user, domain};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void setPasswordMappingCommandShouldThrowOnMissingArguments() 
throws Exception {
+        String user = "user@domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.SETPASSWORD.getCommand(), user};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void copyMailboxMappingCommandShouldThrowOnMissingArguments() 
throws Exception {
+        String srcBean = "srcBean";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.COPYMAILBOX.getCommand(), srcBean};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void 
deleteUserMailboxesMappingCommandShouldThrowOnMissingArguments() throws 
Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.DELETEUSERMAILBOXES.getCommand()};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void createMailboxMappingCommandShouldThrowOnMissingArguments() 
throws Exception {
+        String user = "user@domain";
+        String namespace = "#private";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.CREATEMAILBOX.getCommand(), namespace, user};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void deleteMailboxMappingCommandShouldThrowOnMissingArguments() 
throws Exception {
+        String user = "user@domain";
+        String namespace = "#private";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.DELETEMAILBOX.getCommand(), namespace, user};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void 
listUserMailboxesMappingsCommandShouldThrowOnMissingArguments() throws 
Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTUSERMAILBOXES.getCommand()};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void addDomainCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String domain = "example.com";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDDOMAIN.getCommand(), domain, ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void removeDomainCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String domain = "example.com";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEDOMAIN.getCommand(), domain, ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void containsDomainCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String domain = "example.com";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.CONTAINSDOMAIN.getCommand(), domain, ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void listDomainsCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTDOMAINS.getCommand(), ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void addUserCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String user = "user@domain";
+        String password = "password";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDUSER.getCommand(), user, password, ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void removeUserCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String user = "user@domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEUSER.getCommand(), user, ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void listUsersCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTUSERS.getCommand(), ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void listMappingsCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTMAPPINGS.getCommand(), ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void 
listUserDomainMappingsCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTUSERDOMAINMAPPINGS.getCommand(), user, domain, ADDITIONAL_ARGUMENT 
};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void addAddressCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String address = "b...@apache.org";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDADDRESSMAPPING.getCommand(), user, domain, address, 
ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void removeAddressCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String address = "b...@apache.org";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEADDRESSMAPPING.getCommand(), user, domain, address, 
ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void addRegexMappingCommandShouldThrowOnAdditionalArguments() 
throws Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String regex = "bis.*@apache.org";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.ADDREGEXMAPPING.getCommand(), user, domain, regex, ADDITIONAL_ARGUMENT 
};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void removeRegexMappingCommandShouldThrowOnAdditionalArguments() 
throws Exception {
+        String user = "user@domain";
+        String domain = "domain";
+        String regex = "bis.*@apache.org";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.REMOVEREGEXMAPPING.getCommand(), user, domain, regex, 
ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void setPasswordMappingCommandShouldThrowOnAdditionalArguments() 
throws Exception {
+        String user = "user@domain";
+        String password = "pass";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.SETPASSWORD.getCommand(), user, password, ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void copyMailboxMappingCommandShouldThrowOnAdditionalArguments() 
throws Exception {
+        String srcBean = "srcBean";
+        String dstBean = "dstBean";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.COPYMAILBOX.getCommand(), srcBean, dstBean, ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void 
deleteUserMailboxesMappingCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String user = "user@domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.DELETEUSERMAILBOXES.getCommand(), user, ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void createMailboxMappingCommandShouldThrowOnAdditionalArguments() 
throws Exception {
+        String user = "user@domain";
+        String namespace = "#private";
+        String name = "INBOX.test";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.CREATEMAILBOX.getCommand(), namespace, user, name, ADDITIONAL_ARGUMENT 
};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void deleteMailboxMappingCommandShouldThrowOnAdditionalArguments() 
throws Exception {
+        String user = "user@domain";
+        String namespace = "#private";
+        String name = "INBOX.test";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.DELETEMAILBOX.getCommand(), namespace, user, name, ADDITIONAL_ARGUMENT 
};
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+
+    @Test(expected = Exception.class)
+    public void 
listUserMailboxesMappingsCommandShouldThrowOnAdditionalArguments() throws 
Exception {
+        String user = "user@domain";
+        String[] arguments = { "-h", "127.0.0.1", "-p", "9999", 
CmdType.LISTUSERMAILBOXES.getCommand(), user, ADDITIONAL_ARGUMENT };
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        control.replay();
+        try {
+            
testee.executeCommandLine(Calendar.getInstance().getTimeInMillis(), 
commandLine);
+        } finally {
+            control.verify();
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to