You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2010/12/18 11:52:45 UTC

svn commit: r1050615 - /james/server/trunk/remotemanager/src/test/java/org/apache/james/remotemanager/AbstractRemoteManagerTest.java

Author: norman
Date: Sat Dec 18 10:52:45 2010
New Revision: 1050615

URL: http://svn.apache.org/viewvc?rev=1050615&view=rev
Log:
Replace tabs with spaces

Modified:
    james/server/trunk/remotemanager/src/test/java/org/apache/james/remotemanager/AbstractRemoteManagerTest.java

Modified: james/server/trunk/remotemanager/src/test/java/org/apache/james/remotemanager/AbstractRemoteManagerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager/src/test/java/org/apache/james/remotemanager/AbstractRemoteManagerTest.java?rev=1050615&r1=1050614&r2=1050615&view=diff
==============================================================================
--- james/server/trunk/remotemanager/src/test/java/org/apache/james/remotemanager/AbstractRemoteManagerTest.java (original)
+++ james/server/trunk/remotemanager/src/test/java/org/apache/james/remotemanager/AbstractRemoteManagerTest.java Sat Dec 18 10:52:45 2010
@@ -30,7 +30,6 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
-
 import junit.framework.TestCase;
 
 import org.apache.commons.logging.impl.SimpleLog;
@@ -50,541 +49,519 @@ import org.apache.james.vut.lib.mock.Moc
 
 public abstract class AbstractRemoteManagerTest extends TestCase {
     private int m_remoteManagerListenerPort = TestUtil.getNonPrivilegedPort();
-	private RemoteManagerTestConfiguration m_testConfiguration;
-	private String m_host = "127.0.0.1";
-	private BufferedReader m_reader;
-	private InternetPrintWriter m_writer;
-	private TelnetClient m_telnetClient;
-	private MockUsersRepository m_mockUsersRepository;
-	private MockJSR250Loader serviceManager;
-	protected DNSService dnsservice;
-	protected MockFileSystem filesystem;
-	private MockVirtualUserTableManagementImpl vutManagement;
-	protected MockProtocolHandlerChain chain;
-	
-	protected void setUp() throws Exception {
-		setUpFakeLoader();
+    private RemoteManagerTestConfiguration m_testConfiguration;
+    private String m_host = "127.0.0.1";
+    private BufferedReader m_reader;
+    private InternetPrintWriter m_writer;
+    private TelnetClient m_telnetClient;
+    private MockUsersRepository m_mockUsersRepository;
+    private MockJSR250Loader serviceManager;
+    protected DNSService dnsservice;
+    protected MockFileSystem filesystem;
+    private MockVirtualUserTableManagementImpl vutManagement;
+    protected MockProtocolHandlerChain chain;
+
+    protected void setUp() throws Exception {
+        setUpFakeLoader();
 
         chain = new MockProtocolHandlerChain();
-	    chain.setLoader(serviceManager);
-	    chain.setLog(new SimpleLog("ChainLog"));
-	        
-	    setUpRemoteManager();
-		m_testConfiguration = new RemoteManagerTestConfiguration(
-				m_remoteManagerListenerPort);
-	}
-
-
-	protected void finishSetUp(RemoteManagerTestConfiguration testConfiguration)
-			throws Exception {
-		testConfiguration.init();
-        chain.configure(testConfiguration);        
-		chain.init();
-		initRemoteManager(testConfiguration);
-	}
+        chain.setLoader(serviceManager);
+        chain.setLog(new SimpleLog("ChainLog"));
 
+        setUpRemoteManager();
+        m_testConfiguration = new RemoteManagerTestConfiguration(m_remoteManagerListenerPort);
+    }
+
+    protected void finishSetUp(RemoteManagerTestConfiguration testConfiguration) throws Exception {
+        testConfiguration.init();
+        chain.configure(testConfiguration);
+        chain.init();
+        initRemoteManager(testConfiguration);
+    }
 
     protected abstract void setUpRemoteManager() throws Exception;
+
     protected abstract void initRemoteManager(RemoteManagerTestConfiguration testConfiguration) throws Exception;
-    
-    
-	protected void login() throws IOException {
-		login(m_testConfiguration.getLoginName(), m_testConfiguration
-				.getLoginPassword());
-	}
-
-	protected void login(String name, String password) throws IOException {
-		sendCommand(name);
-		List answers = readAnswer();
-		String last = getLastLine(answers);
-		assertTrue("Last line does not start with Password: " + last, last
-				.startsWith("Password:"));
-		sendCommand(password);
-		answers = readAnswer();
-		last = getLastLine(answers);
-		assertTrue("Last line does not start with Welcome: " + last, last
-				.startsWith("Welcome"));
-	}
-
-	protected String getLastLine(List list) {
-		if (list == null || list.isEmpty())
-			return null;
-		return (String) list.get(list.size() - 1);
-	}
-
-	protected List readAnswer() {
-		return readAnswer(1);
-	}
-
-	protected List readAnswer(int numLines) {
-		List allAnswerLines = new ArrayList();
-		try {
-			if (numLines > 0) {
-				for (int i = 0; i < numLines; i++) {
-					allAnswerLines.add(m_reader.readLine());
-				}
-			} else {
-				String line = m_reader.readLine();
-				allAnswerLines.add(line);
-
-				while (m_reader.ready()) {
-					allAnswerLines.add(m_reader.readLine());
-				}
-			}
-			return allAnswerLines;
-		} catch (IOException e) {
-			return null;
-		}
-	}
-
-	protected void sendCommand(String command) throws IOException {
-		m_writer.println(command);
-		m_writer.flush();
-	}
-
-	protected void connect() throws IOException {
-		m_telnetClient = new TelnetClient();
-		m_telnetClient.connect(m_host, m_remoteManagerListenerPort);
-
-		m_reader = new BufferedReader(new InputStreamReader(
-				new BufferedInputStream(m_telnetClient.getInputStream(), 1024),
-				"ASCII"));
-		m_writer = new InternetPrintWriter(new BufferedOutputStream(
-				m_telnetClient.getOutputStream(), 1024), true);
-
-		readAnswer(3);
-	}
-
-	protected void setUpFakeLoader() throws Exception {
-		serviceManager = new MockJSR250Loader();
-
-		m_mockUsersRepository = new MockUsersRepository();
-		serviceManager.put("usersrepository", m_mockUsersRepository);
-
-		
-		filesystem = new MockFileSystem();
-		serviceManager.put("filesystem", filesystem);
-
-
-		dnsservice = setUpDNSServer();
-		serviceManager.put("dnsservice", dnsservice);
-		
-		vutManagement = new MockVirtualUserTableManagementImpl();
-		serviceManager.put("virtualusertable", vutManagement);
-	
-		DomainList xml = new SimpleDomainList();
-
-	
-		serviceManager.put("domainlist", xml);
-
-		serviceManager.put("mailStore", new MockMailRepositoryStore());
-	
-	}
-
-	private DNSService setUpDNSServer() {
-		DNSService dns = new MockDNSService() {
-			public String getHostName(InetAddress addr) {
-				return "localhost";
-			}
-
-			public InetAddress getLocalHost() throws UnknownHostException {
-				return InetAddress.getLocalHost();
-			}
-
-			public InetAddress[] getAllByName(String name)
-					throws UnknownHostException {
-				return new InetAddress[] { InetAddress.getLocalHost() };
-			}
-		};
-
-		return dns;
-	}
-
-	/*
-	 * public void testCustomCommand() throws Exception {
-	 * finishSetUp(m_testConfiguration); connect(); login();
-	 * 
-	 * sendCommand("echo hsif eht lla rof sknaht"); String lastLine =
-	 * getLastLine(readAnswer()); assertEquals("Arguments echoed",
-	 * "hsif eht lla rof sknaht", lastLine); }
-	 */
-	public void testLogin() throws Exception {
-		finishSetUp(m_testConfiguration);
-		connect();
-
-		login();
-	}
-
-	public void testWrongLoginUser() throws Exception {
-		finishSetUp(m_testConfiguration);
-		connect();
-
-		sendCommand("sindbad");
-		List answers = readAnswer();
-		sendCommand(m_testConfiguration.getLoginPassword());
-
-		// we should receive the fail message and a new Login id.
-		answers = readAnswer(2);
-		String last = getLastLine(answers);
-		assertTrue("Last line does not start with 'Login id:' but with '"
-				+ last + "'", last.startsWith("Login id:")); // login failed,
-																// getting new
-																// login prompt
-	}
-
-	public void testWrongLoginPassword() throws Exception {
-		finishSetUp(m_testConfiguration);
-		connect();
-
-		sendCommand(m_testConfiguration.getLoginName());
-		List answers = readAnswer();
-		sendCommand("getmethru");
-
-		answers = readAnswer(2);
-		String last = getLastLine(answers);
-		assertTrue("Line does not start with 'Login id:' but with '" + last
-				+ "'", last.startsWith("Login id:")); // login failed, getting
-														// new login prompt
-	}
-
-	public void testUserCount() throws Exception {
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("countusers");
-		assertTrue(getLastLine(readAnswer()).endsWith(" 0")); // no user yet
-
-		sendCommand("adduser testCount1 testCount");
-		assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
-
-		sendCommand("countusers");
-		assertTrue(getLastLine(readAnswer()).endsWith(" 1")); // 1 total
-
-		sendCommand("adduser testCount2 testCount");
-		assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
-
-		sendCommand("countusers");
-		assertTrue(getLastLine(readAnswer()).endsWith(" 2")); // 2 total
-
-		m_mockUsersRepository.removeUser("testCount1");
-
-		sendCommand("countusers");
-		assertTrue(getLastLine(readAnswer()).endsWith(" 1")); // 1 total
-	}
-
-	public void testAddUserAndVerify() throws Exception {
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("adduser testAdd test");
-		assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
-
-		sendCommand("verify testNotAdded");
-		assertTrue(getLastLine(readAnswer()).endsWith(" does not exist"));
-
-		sendCommand("verify testAdd");
-		assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
-
-		sendCommand("deluser testAdd");
-		readAnswer();
-
-		sendCommand("verify testAdd");
-		assertTrue(getLastLine(readAnswer()).endsWith(" does not exist"));
-	}
-
-	public void testDelUser() throws Exception {
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("adduser testDel test");
-		assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
-
-		sendCommand("deluser testNotDeletable");
-		assertTrue(getLastLine(readAnswer()).endsWith(" doesn't exist"));
-
-		sendCommand("verify testDel");
-		assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
-
-		sendCommand("deluser testDel");
-		assertTrue(getLastLine(readAnswer()).endsWith(" deleted"));
-
-		sendCommand("verify testDel");
-		assertTrue(getLastLine(readAnswer()).endsWith(" does not exist"));
-	}
-
-	public void testQuit() throws Exception {
-
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("help");
-		delay();
-		assertTrue("command line is effective", readAnswer().size() > 0);
-
-		sendCommand("quit");
-		delay();
-		assertTrue("", readAnswer(39).contains("Bye"));
-
-		sendCommand("help");
-		delay();
-		assertNull("connection is closed", m_reader.readLine());
-	}
-
-	public void testListUsers() throws Exception {
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		String[] users = new String[] { "ccc", "aaa", "dddd", "bbbbb" };
-
-		for (int i = 0; i < users.length; i++) {
-			String user = users[i];
-			sendCommand("adduser " + user + " test");
-			readAnswer(1);
-		}
-
-		delay();
-
-		sendCommand("listusers");
-		List list = readAnswer(5);
-
-		assertEquals("user count line", "Existing accounts " + users.length,
-				list.get(0));
-
-		List readUserNames = new ArrayList();
-		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
-			String answerLine = (String) iterator.next();
-			if (!answerLine.startsWith("user: "))
-				continue;
-			readUserNames.add(answerLine.substring(6));
-		}
-		assertEquals("user count", users.length, readUserNames.size());
-
-		for (int i = 0; i < users.length; i++) {
-			String user = users[i];
-			assertTrue("name found", readUserNames.contains(user));
-		}
-	}
-
-	private void delay() {
-		try {
-			Thread.sleep(100);
-		} catch (InterruptedException e) {
-			; // ignore
-		}
-	}
-
-	public void testCommandCaseInsensitive() throws Exception {
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("adduser testDel test");
-		assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
-
-		sendCommand("verify testDel");
-		assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
-
-		sendCommand("VERIFY testDel");
-		assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
-
-		sendCommand("vErIfY testDel");
-		assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
-	}
-
-	public void testParameterCaseSensitive() throws Exception {
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("adduser testDel test");
-		assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
-
-		sendCommand("verify testDel");
-		assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
-
-		sendCommand("verify TESTDEL");
-		assertTrue(getLastLine(readAnswer()).endsWith(" does not exist"));
-
-		sendCommand("verify testdel");
-		assertTrue(getLastLine(readAnswer()).endsWith(" does not exist"));
-	}
-
-	
-
-	public void testSetPassword() throws Exception {
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		String lastLine;
-
-		sendCommand("adduser testPwdUser pwd1");
-		lastLine = getLastLine(readAnswer());
-		assertTrue(lastLine.endsWith(" added"));
-
-		assertTrue("initial password", m_mockUsersRepository.test(
-				"testPwdUser", "pwd1"));
-
-		sendCommand("setpassword testPwdUser     ");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("password changed to empty: " + lastLine,
-				m_mockUsersRepository.test("testPwdUser", "pwd1"));
-
-		// change pwd
-		sendCommand("setpassword testPwdUser pwd2");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("password not changed to pwd2: " + lastLine,
-				m_mockUsersRepository.test("testPwdUser", "pwd2"));
-
-		// assure case sensitivity
-		sendCommand("setpassword testPwdUser pWD2");
-		lastLine = getLastLine(readAnswer());
-		assertFalse("password not changed to pWD2: " + lastLine,
-				m_mockUsersRepository.test("testPwdUser", "pwd2"));
-		assertTrue("password not changed to pWD2: " + lastLine,
-				m_mockUsersRepository.test("testPwdUser", "pWD2"));
-
-	}
-
-	public void testAddMapping() throws Exception {
-		String lastLine;
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("addmapping test@test junit");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Add mapping", lastLine.endsWith("true"));
-
-		sendCommand("addmapping test@test junit");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Not add mapping... allready exists", lastLine
-				.endsWith("false"));
-	}
-
-	public void testRemoveMapping() throws Exception {
-		String lastLine;
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("addmapping test@test junit");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Add mapping", lastLine.endsWith("true"));
-
-		sendCommand("removemapping test@test junit");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("remove mapping", lastLine.endsWith("true"));
-
-		sendCommand("removemapping test@test junit");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Not remove mapping... mapping not exists", lastLine
-				.endsWith("false"));
-	}
-
-	public void testListAllMappings() throws Exception {
-		String lastLine;
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("addmapping test@test junit");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Add mapping", lastLine.endsWith("true"));
-
-		sendCommand("addmapping test2@test junit2");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Add mapping", lastLine.endsWith("true"));
-
-		sendCommand("listallmappings");
-		List answer = readAnswer(3);
-		assertTrue("Read first mapping", answer.get(1).toString().contains(
-				"junit"));
-		assertTrue("Read second mapping line", answer.get(2).toString()
-				.contains("junit2"));
-	}
-
-	public void testListMapping() throws Exception {
-		String lastLine;
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("addmapping test@test junit");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Add mapping", lastLine.endsWith("true"));
-
-		sendCommand("addmapping test2@test junit2");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Add mapping", lastLine.endsWith("true"));
-
-		sendCommand("listmapping test@test");
-		lastLine = readAnswer(2).get(1).toString();
-		assertTrue("list mapping", lastLine.endsWith("junit"));
-	}
-
-	public void testaddDomain() throws Exception {
-		String lastLine;
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("adddomain domain");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Add domain", lastLine.endsWith("successful"));
-
-		sendCommand("adddomain domain");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Add domain which exists", lastLine.endsWith("fail"));
-
-		sendCommand("listdomains");
-
-		lastLine = readAnswer(2).get(1).toString();
-		assertTrue("list domain", lastLine.endsWith("domain"));
-	}
-
-	public void testremoveDomain() throws Exception {
-		String lastLine;
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("adddomain domain");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Add domain", lastLine.endsWith("successful"));
-
-		sendCommand("removedomain domain");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Remove domain", lastLine.endsWith("successful"));
-
-		sendCommand("removedomain domain");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Remove domain which not exist", lastLine.endsWith("fail"));
-	}
-
-	public void testListDomains() throws Exception {
-		String lastLine;
-		finishSetUp(m_testConfiguration);
-		connect();
-		login();
-
-		sendCommand("adddomain domain");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Add domain", lastLine.endsWith("successful"));
-
-		sendCommand("adddomain domain2");
-		lastLine = getLastLine(readAnswer());
-		assertTrue("Add domain", lastLine.endsWith("successful"));
-
-		sendCommand("listdomains");
-		List answer = readAnswer(3);
-		assertTrue("list domain 1", answer.get(1).toString().endsWith("domain"));
-		assertTrue("list domain 2", answer.get(2).toString()
-				.endsWith("domain2"));
-	}
+
+    protected void login() throws IOException {
+        login(m_testConfiguration.getLoginName(), m_testConfiguration.getLoginPassword());
+    }
+
+    protected void login(String name, String password) throws IOException {
+        sendCommand(name);
+        List answers = readAnswer();
+        String last = getLastLine(answers);
+        assertTrue("Last line does not start with Password: " + last, last.startsWith("Password:"));
+        sendCommand(password);
+        answers = readAnswer();
+        last = getLastLine(answers);
+        assertTrue("Last line does not start with Welcome: " + last, last.startsWith("Welcome"));
+    }
+
+    protected String getLastLine(List list) {
+        if (list == null || list.isEmpty())
+            return null;
+        return (String) list.get(list.size() - 1);
+    }
+
+    protected List readAnswer() {
+        return readAnswer(1);
+    }
+
+    protected List readAnswer(int numLines) {
+        List allAnswerLines = new ArrayList();
+        try {
+            if (numLines > 0) {
+                for (int i = 0; i < numLines; i++) {
+                    allAnswerLines.add(m_reader.readLine());
+                }
+            } else {
+                String line = m_reader.readLine();
+                allAnswerLines.add(line);
+
+                while (m_reader.ready()) {
+                    allAnswerLines.add(m_reader.readLine());
+                }
+            }
+            return allAnswerLines;
+        } catch (IOException e) {
+            return null;
+        }
+    }
+
+    protected void sendCommand(String command) throws IOException {
+        m_writer.println(command);
+        m_writer.flush();
+    }
+
+    protected void connect() throws IOException {
+        m_telnetClient = new TelnetClient();
+        m_telnetClient.connect(m_host, m_remoteManagerListenerPort);
+
+        m_reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(m_telnetClient.getInputStream(), 1024), "ASCII"));
+        m_writer = new InternetPrintWriter(new BufferedOutputStream(m_telnetClient.getOutputStream(), 1024), true);
+
+        readAnswer(3);
+    }
+
+    protected void setUpFakeLoader() throws Exception {
+        serviceManager = new MockJSR250Loader();
+
+        m_mockUsersRepository = new MockUsersRepository();
+        serviceManager.put("usersrepository", m_mockUsersRepository);
+
+        filesystem = new MockFileSystem();
+        serviceManager.put("filesystem", filesystem);
+
+        dnsservice = setUpDNSServer();
+        serviceManager.put("dnsservice", dnsservice);
+
+        vutManagement = new MockVirtualUserTableManagementImpl();
+        serviceManager.put("virtualusertable", vutManagement);
+
+        DomainList xml = new SimpleDomainList();
+
+        serviceManager.put("domainlist", xml);
+
+        serviceManager.put("mailStore", new MockMailRepositoryStore());
+
+    }
+
+    private DNSService setUpDNSServer() {
+        DNSService dns = new MockDNSService() {
+            public String getHostName(InetAddress addr) {
+                return "localhost";
+            }
+
+            public InetAddress getLocalHost() throws UnknownHostException {
+                return InetAddress.getLocalHost();
+            }
+
+            public InetAddress[] getAllByName(String name) throws UnknownHostException {
+                return new InetAddress[] { InetAddress.getLocalHost() };
+            }
+        };
+
+        return dns;
+    }
+
+    /*
+     * public void testCustomCommand() throws Exception {
+     * finishSetUp(m_testConfiguration); connect(); login();
+     * 
+     * sendCommand("echo hsif eht lla rof sknaht"); String lastLine =
+     * getLastLine(readAnswer()); assertEquals("Arguments echoed",
+     * "hsif eht lla rof sknaht", lastLine); }
+     */
+    public void testLogin() throws Exception {
+        finishSetUp(m_testConfiguration);
+        connect();
+
+        login();
+    }
+
+    public void testWrongLoginUser() throws Exception {
+        finishSetUp(m_testConfiguration);
+        connect();
+
+        sendCommand("sindbad");
+        List answers = readAnswer();
+        sendCommand(m_testConfiguration.getLoginPassword());
+
+        // we should receive the fail message and a new Login id.
+        answers = readAnswer(2);
+        String last = getLastLine(answers);
+        assertTrue("Last line does not start with 'Login id:' but with '" + last + "'", last.startsWith("Login id:")); // login
+                                                                                                                       // failed,
+                                                                                                                       // getting
+                                                                                                                       // new
+                                                                                                                       // login
+                                                                                                                       // prompt
+    }
+
+    public void testWrongLoginPassword() throws Exception {
+        finishSetUp(m_testConfiguration);
+        connect();
+
+        sendCommand(m_testConfiguration.getLoginName());
+        List answers = readAnswer();
+        sendCommand("getmethru");
+
+        answers = readAnswer(2);
+        String last = getLastLine(answers);
+        assertTrue("Line does not start with 'Login id:' but with '" + last + "'", last.startsWith("Login id:")); // login
+                                                                                                                  // failed,
+                                                                                                                  // getting
+                                                                                                                  // new
+                                                                                                                  // login
+                                                                                                                  // prompt
+    }
+
+    public void testUserCount() throws Exception {
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("countusers");
+        assertTrue(getLastLine(readAnswer()).endsWith(" 0")); // no user yet
+
+        sendCommand("adduser testCount1 testCount");
+        assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
+
+        sendCommand("countusers");
+        assertTrue(getLastLine(readAnswer()).endsWith(" 1")); // 1 total
+
+        sendCommand("adduser testCount2 testCount");
+        assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
+
+        sendCommand("countusers");
+        assertTrue(getLastLine(readAnswer()).endsWith(" 2")); // 2 total
+
+        m_mockUsersRepository.removeUser("testCount1");
+
+        sendCommand("countusers");
+        assertTrue(getLastLine(readAnswer()).endsWith(" 1")); // 1 total
+    }
+
+    public void testAddUserAndVerify() throws Exception {
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("adduser testAdd test");
+        assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
+
+        sendCommand("verify testNotAdded");
+        assertTrue(getLastLine(readAnswer()).endsWith(" does not exist"));
+
+        sendCommand("verify testAdd");
+        assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
+
+        sendCommand("deluser testAdd");
+        readAnswer();
+
+        sendCommand("verify testAdd");
+        assertTrue(getLastLine(readAnswer()).endsWith(" does not exist"));
+    }
+
+    public void testDelUser() throws Exception {
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("adduser testDel test");
+        assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
+
+        sendCommand("deluser testNotDeletable");
+        assertTrue(getLastLine(readAnswer()).endsWith(" doesn't exist"));
+
+        sendCommand("verify testDel");
+        assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
+
+        sendCommand("deluser testDel");
+        assertTrue(getLastLine(readAnswer()).endsWith(" deleted"));
+
+        sendCommand("verify testDel");
+        assertTrue(getLastLine(readAnswer()).endsWith(" does not exist"));
+    }
+
+    public void testQuit() throws Exception {
+
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("help");
+        delay();
+        assertTrue("command line is effective", readAnswer().size() > 0);
+
+        sendCommand("quit");
+        delay();
+        assertTrue("", readAnswer(39).contains("Bye"));
+
+        sendCommand("help");
+        delay();
+        assertNull("connection is closed", m_reader.readLine());
+    }
+
+    public void testListUsers() throws Exception {
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        String[] users = new String[] { "ccc", "aaa", "dddd", "bbbbb" };
+
+        for (int i = 0; i < users.length; i++) {
+            String user = users[i];
+            sendCommand("adduser " + user + " test");
+            readAnswer(1);
+        }
+
+        delay();
+
+        sendCommand("listusers");
+        List list = readAnswer(5);
+
+        assertEquals("user count line", "Existing accounts " + users.length, list.get(0));
+
+        List readUserNames = new ArrayList();
+        for (Iterator iterator = list.iterator(); iterator.hasNext();) {
+            String answerLine = (String) iterator.next();
+            if (!answerLine.startsWith("user: "))
+                continue;
+            readUserNames.add(answerLine.substring(6));
+        }
+        assertEquals("user count", users.length, readUserNames.size());
+
+        for (int i = 0; i < users.length; i++) {
+            String user = users[i];
+            assertTrue("name found", readUserNames.contains(user));
+        }
+    }
+
+    private void delay() {
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException e) {
+            ; // ignore
+        }
+    }
+
+    public void testCommandCaseInsensitive() throws Exception {
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("adduser testDel test");
+        assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
+
+        sendCommand("verify testDel");
+        assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
+
+        sendCommand("VERIFY testDel");
+        assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
+
+        sendCommand("vErIfY testDel");
+        assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
+    }
+
+    public void testParameterCaseSensitive() throws Exception {
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("adduser testDel test");
+        assertTrue(getLastLine(readAnswer()).endsWith(" added")); // success
+
+        sendCommand("verify testDel");
+        assertTrue(getLastLine(readAnswer()).endsWith(" exists"));
+
+        sendCommand("verify TESTDEL");
+        assertTrue(getLastLine(readAnswer()).endsWith(" does not exist"));
+
+        sendCommand("verify testdel");
+        assertTrue(getLastLine(readAnswer()).endsWith(" does not exist"));
+    }
+
+    public void testSetPassword() throws Exception {
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        String lastLine;
+
+        sendCommand("adduser testPwdUser pwd1");
+        lastLine = getLastLine(readAnswer());
+        assertTrue(lastLine.endsWith(" added"));
+
+        assertTrue("initial password", m_mockUsersRepository.test("testPwdUser", "pwd1"));
+
+        sendCommand("setpassword testPwdUser     ");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("password changed to empty: " + lastLine, m_mockUsersRepository.test("testPwdUser", "pwd1"));
+
+        // change pwd
+        sendCommand("setpassword testPwdUser pwd2");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("password not changed to pwd2: " + lastLine, m_mockUsersRepository.test("testPwdUser", "pwd2"));
+
+        // assure case sensitivity
+        sendCommand("setpassword testPwdUser pWD2");
+        lastLine = getLastLine(readAnswer());
+        assertFalse("password not changed to pWD2: " + lastLine, m_mockUsersRepository.test("testPwdUser", "pwd2"));
+        assertTrue("password not changed to pWD2: " + lastLine, m_mockUsersRepository.test("testPwdUser", "pWD2"));
+
+    }
+
+    public void testAddMapping() throws Exception {
+        String lastLine;
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("addmapping test@test junit");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add mapping", lastLine.endsWith("true"));
+
+        sendCommand("addmapping test@test junit");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Not add mapping... allready exists", lastLine.endsWith("false"));
+    }
+
+    public void testRemoveMapping() throws Exception {
+        String lastLine;
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("addmapping test@test junit");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add mapping", lastLine.endsWith("true"));
+
+        sendCommand("removemapping test@test junit");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("remove mapping", lastLine.endsWith("true"));
+
+        sendCommand("removemapping test@test junit");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Not remove mapping... mapping not exists", lastLine.endsWith("false"));
+    }
+
+    public void testListAllMappings() throws Exception {
+        String lastLine;
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("addmapping test@test junit");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add mapping", lastLine.endsWith("true"));
+
+        sendCommand("addmapping test2@test junit2");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add mapping", lastLine.endsWith("true"));
+
+        sendCommand("listallmappings");
+        List answer = readAnswer(3);
+        assertTrue("Read first mapping", answer.get(1).toString().contains("junit"));
+        assertTrue("Read second mapping line", answer.get(2).toString().contains("junit2"));
+    }
+
+    public void testListMapping() throws Exception {
+        String lastLine;
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("addmapping test@test junit");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add mapping", lastLine.endsWith("true"));
+
+        sendCommand("addmapping test2@test junit2");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add mapping", lastLine.endsWith("true"));
+
+        sendCommand("listmapping test@test");
+        lastLine = readAnswer(2).get(1).toString();
+        assertTrue("list mapping", lastLine.endsWith("junit"));
+    }
+
+    public void testaddDomain() throws Exception {
+        String lastLine;
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("adddomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add domain", lastLine.endsWith("successful"));
+
+        sendCommand("adddomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add domain which exists", lastLine.endsWith("fail"));
+
+        sendCommand("listdomains");
+
+        lastLine = readAnswer(2).get(1).toString();
+        assertTrue("list domain", lastLine.endsWith("domain"));
+    }
+
+    public void testremoveDomain() throws Exception {
+        String lastLine;
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("adddomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add domain", lastLine.endsWith("successful"));
+
+        sendCommand("removedomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Remove domain", lastLine.endsWith("successful"));
+
+        sendCommand("removedomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Remove domain which not exist", lastLine.endsWith("fail"));
+    }
+
+    public void testListDomains() throws Exception {
+        String lastLine;
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("adddomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add domain", lastLine.endsWith("successful"));
+
+        sendCommand("adddomain domain2");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add domain", lastLine.endsWith("successful"));
+
+        sendCommand("listdomains");
+        List answer = readAnswer(3);
+        assertTrue("list domain 1", answer.get(1).toString().endsWith("domain"));
+        assertTrue("list domain 2", answer.get(2).toString().endsWith("domain2"));
+    }
 }



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