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 ba...@apache.org on 2006/05/10 18:46:58 UTC

svn commit: r405795 [2/5] - in /james/server/trunk: ./ src/test/org/apache/james/ src/test/org/apache/james/core/ src/test/org/apache/james/mailrepository/ src/test/org/apache/james/pop3server/ src/test/org/apache/james/remotemanager/ src/test/org/apac...

Added: james/server/trunk/src/test/org/apache/james/mailrepository/JDBCMailRepositoryTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/mailrepository/JDBCMailRepositoryTest.java?rev=405795&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/mailrepository/JDBCMailRepositoryTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/mailrepository/JDBCMailRepositoryTest.java Wed May 10 09:46:54 2006
@@ -0,0 +1,304 @@
+package org.apache.james.mailrepository;
+
+import org.apache.avalon.cornerstone.blocks.datasources.DefaultDataSourceSelector;
+import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
+import org.apache.avalon.cornerstone.services.store.Store;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.james.context.AvalonContextConstants;
+import org.apache.james.core.MailImpl;
+import org.apache.james.mailrepository.filepair.File_Persistent_Stream_Repository;
+import org.apache.james.remotemanager.RemoteManagerTestConfiguration;
+import org.apache.james.test.mock.avalon.MockContext;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.james.test.mock.avalon.MockServiceManager;
+import org.apache.james.test.mock.avalon.MockStore;
+import org.apache.james.util.io.IOUtil;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+import javax.mail.util.SharedFileInputStream;
+
+import java.io.File;
+import java.io.FileOutputStream;
+//import java.lang.management.ManagementFactory;
+//import java.lang.management.MemoryMXBean;
+//import java.lang.management.MemoryUsage;
+import java.util.Arrays;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+/**
+ * test for the JDBCMailRepository
+ */
+public class JDBCMailRepositoryTest extends TestCase {
+
+    protected JDBCMailRepository mailRepository;
+    protected JDBCMailRepository mailRepository2;
+    protected RemoteManagerTestConfiguration m_testConfiguration;
+    private MockContext context;
+    
+    protected void setUp() throws Exception {
+        context = new MockContext() {
+
+            public Object get(Object object) throws ContextException {
+                if (AvalonContextConstants.APPLICATION_HOME.equals(object)) {
+                    return new File("./src");
+                } else {
+                    return null;
+                }
+            }
+            
+        };
+        
+        mailRepository = new JDBCMailRepository();
+        mailRepository.enableLogging(new MockLogger());
+        mailRepository.contextualize(context);
+        DefaultConfiguration mr = new DefaultConfiguration("mailrepository");
+        // db or dbfile doesn't change the result, the difference is in the presence of
+        // the filestore configuration.
+        mr.setAttribute("destinationURL","dbfile://maildb/testtable/testrepository");
+        mr.addChild(new AttrValConfiguration("sqlFile","file://conf/sqlResources.xml"));
+        //mr.addChild(new AttrValConfiguration("filestore","file://var/dbmail"));
+        
+        mailRepository.service(setUpServiceManager());
+        mailRepository.configure(mr);
+        mailRepository.initialize();
+
+    
+        mailRepository2 = new JDBCMailRepository();
+        mailRepository2.enableLogging(new MockLogger());
+        mailRepository2.contextualize(context);
+        DefaultConfiguration mr2 = new DefaultConfiguration("mailrepository2");
+        // db or dbfile doesn't change the result, the difference is in the presence of
+        // the filestore configuration.
+        mr2.setAttribute("destinationURL","dbfile://maildb/testtable/testrepository22");
+        mr2.addChild(new AttrValConfiguration("sqlFile","file://conf/sqlResources.xml"));
+        //mr.addChild(new AttrValConfiguration("filestore","file://var/dbmail"));
+        
+        mailRepository2.service(setUpServiceManager());
+        mailRepository2.configure(mr2);
+        mailRepository2.initialize();
+
+    }
+    
+    public void testStoreAndRetrieve() throws Exception {
+//        MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
+//        mbean.gc();
+//        MemoryUsage mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory1: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+        
+        String key = "1234";
+        String key2 = "1235";
+        MailImpl m = new MailImpl();
+        m.setRecipients(Arrays.asList(new MailAddress[] {new MailAddress("test@test.com")}));
+        m.setName(key);
+//      SharedFileInputStream sbais = new SharedFileInputStream("\\dsfasdfasdfas.eml");
+//        String inputName = "\\dsfasdfasdfas.eml";
+        String inputName = "\\a.eml";
+        SharedFileInputStream sbais = new SharedFileInputStream(inputName);
+        MimeMessage mm = new MimeMessage(Session.getDefaultInstance(new Properties()),sbais);
+        
+        /*
+        String filename1 = "\\temp1.tmp";
+        FileOutputStream tempFile = new FileOutputStream(new File(filename1));
+        mm.writeTo(tempFile);
+        tempFile.close();
+        */
+        
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory1: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+//        mbean.gc();
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory1b: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+        
+        mm.addHeader("TEST","MIAO");
+        mm.setContent("TEST TEST TEST","text/plain");
+        ///mm.saveChanges();
+
+        m.setMessage(mm);
+        mailRepository.store(m);
+        
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory2: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+//        mbean.gc();
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory2b: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+
+        m.setName(key2);
+        mailRepository.store(m);
+        
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory3: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+//        mbean.gc();
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory3b: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+
+        
+        Mail m2 = mailRepository.retrieve(key);
+        
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory4: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+//        mbean.gc();
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory4b: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+
+        assertNotNull(m2);
+        //TEMPassertEquals(key,m2.getName());
+//        System.out.println("Miao: "+sbais.available());
+        
+        MimeMessage m3 = m2.getMessage();
+        
+
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory5: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+//        mbean.gc();
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory5b: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+
+        String filename = "\\temp.tmp";
+
+        System.out.println("Writing to file: "+filename);
+        System.out.flush();
+        
+        FileOutputStream f = new FileOutputStream(new File(filename));
+        m3.writeTo(f);
+        
+        System.out.println("File written.");
+        System.out.flush();
+        f.close();
+
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory6: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+//        mbean.gc();
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory6b: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+
+        SharedFileInputStream s1 = new SharedFileInputStream(inputName);
+        SharedFileInputStream s2 = new SharedFileInputStream(filename);
+        
+        //TEMP assertTrue(IOUtil.contentEquals(s1,s2));
+
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory7: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+//        mbean.gc();
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory7b: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+
+        mailRepository.remove(key);
+        
+        m2 = mailRepository.retrieve(key);
+        assertNull(m2);
+        
+        
+        m2 = mailRepository.retrieve(key2);
+        mailRepository2.store(m2);
+        mailRepository.remove(key2);
+        
+        mailRepository2.retrieve(key2);
+        mailRepository2.remove(key2);
+        
+        
+        
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory8: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+//        mbean.gc();
+//        mu1 = mbean.getHeapMemoryUsage();
+//        System.out.println("Memory8b: "+mu1.getInit()+"|"+mu1.getUsed()+"|"+mu1.getCommitted()+"|"+mu1.getMax());
+
+    }
+    
+    private class AttrValConfiguration extends DefaultConfiguration {
+        
+        public AttrValConfiguration(String name, String value) {
+            super(name);
+            //setName(name+"1");
+            setValue(value);
+        }
+        
+        public AttrValConfiguration(String name, String attrName, String value) {
+            super(name);
+            addChild(new AttrValConfiguration(attrName,value));
+        }
+        
+    }
+
+    private MockServiceManager setUpServiceManager() throws Exception {
+        MockServiceManager serviceManager = new MockServiceManager();
+        DefaultDataSourceSelector dataSourceSelector = new DefaultDataSourceSelector();
+        dataSourceSelector.enableLogging(new MockLogger());
+        DefaultConfiguration dc = new DefaultConfiguration("database-connections");
+        DefaultConfiguration ds = new DefaultConfiguration("data-source");
+        ds.setAttribute("name","maildb");
+        ds.setAttribute("class","org.apache.james.util.dbcp.JdbcDataSource");
+        
+        /* derby 
+        ds.addChild(new AttrValConfiguration("driver","org.apache.derby.jdbc.EmbeddedDriver"));
+        ds.addChild(new AttrValConfiguration("dburl","jdbc:derby:derbydb;create=true"));
+        ds.addChild(new AttrValConfiguration("user","james"));
+        ds.addChild(new AttrValConfiguration("password","james8en2"));
+        */
+        /* mysql */
+        ds.addChild(new AttrValConfiguration("driver","com.mysql.jdbc.Driver"));
+        // ds.addChild(new AttrValConfiguration("dburl","jdbc:mysql://elysium/james?autoReconnect=true&emulateLocators=true"));
+        ds.addChild(new AttrValConfiguration("dburl","jdbc:mysql://192.168.0.33/james?autoReconnect=true&emulateLocators=true"));
+        ds.addChild(new AttrValConfiguration("user","james"));
+        ds.addChild(new AttrValConfiguration("password","james8en2"));
+        /* */
+
+        /* hsqldb
+        ds.addChild(new AttrValConfiguration("driver","org.hsqldb.jdbcDriver"));
+        ds.addChild(new AttrValConfiguration("dburl","jdbc:hsqldb:file:mydb;ifexists=false"));
+        ds.addChild(new AttrValConfiguration("user","sa"));
+        ds.addChild(new AttrValConfiguration("password",""));
+        */
+        
+        /* postgresql
+        ds.addChild(new AttrValConfiguration("driver","org.postgresql.Driver"));
+        ds.addChild(new AttrValConfiguration("dburl","jdbc:postgresql://192.168.0.35:5432/postgres"));
+        ds.addChild(new AttrValConfiguration("user","postgres"));
+        ds.addChild(new AttrValConfiguration("password","pg8en2"));
+        */
+        
+        /*
+        ds.addChild(new AttrValConfiguration("driver","oracle.jdbc.OracleDriver"));
+        ds.addChild(new AttrValConfiguration("dburl","jdbc:oracle:thin:@elysium:1521:ORA920"));
+        ds.addChild(new AttrValConfiguration("user","NAO12"));
+        ds.addChild(new AttrValConfiguration("password","NAO8EN2"));
+        */
+        ds.addChild(new AttrValConfiguration("max","20"));
+        dc.addChild(ds);
+        dataSourceSelector.configure(dc);
+        dataSourceSelector.contextualize(context);
+        dataSourceSelector.initialize();
+        
+        MockStore store = new MockStore();
+        File_Persistent_Stream_Repository fs = new File_Persistent_Stream_Repository();
+        fs.enableLogging(new MockLogger());
+        DefaultConfiguration c = new DefaultConfiguration("temp");
+        c.setAttribute("destinationURL","file://var/dbmail");
+        fs.configure(c);
+        fs.service(serviceManager);
+        fs.contextualize(context);
+        fs.initialize();
+        store.add("dbmail",fs);
+        serviceManager.put(Store.ROLE, store);
+        serviceManager.put(DataSourceSelector.ROLE, dataSourceSelector);
+        return serviceManager;
+    }
+
+
+    /**
+     * Temporary method to improve debugging
+     */
+    public static void main(String[] args) throws Exception {
+        JDBCMailRepositoryTest t = new JDBCMailRepositoryTest();
+        t.setUp();
+        t.testStoreAndRetrieve();
+        t.tearDown();
+    }
+
+}

Propchange: james/server/trunk/src/test/org/apache/james/mailrepository/JDBCMailRepositoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/test/org/apache/james/pop3server/POP3ServerTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/pop3server/POP3ServerTest.java?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/pop3server/POP3ServerTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/pop3server/POP3ServerTest.java Wed May 10 09:46:54 2006
@@ -1,419 +1,419 @@
-/***********************************************************************
- * Copyright (c) 1999-2006 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed 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.pop3server;
-
-import org.apache.avalon.cornerstone.services.sockets.SocketManager;
-import org.apache.avalon.cornerstone.services.threads.ThreadManager;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.james.core.MailImpl;
-import org.apache.james.core.MimeMessageCopyOnWriteProxy;
-import org.apache.james.core.MimeMessageInputStreamSource;
-import org.apache.james.services.JamesConnectionManager;
-import org.apache.james.services.MailServer;
-import org.apache.james.services.UsersRepository;
-import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.james.test.mock.avalon.MockServiceManager;
-import org.apache.james.test.mock.avalon.MockSocketManager;
-import org.apache.james.test.mock.avalon.MockThreadManager;
-import org.apache.james.test.mock.james.MockMailRepository;
-import org.apache.james.test.mock.james.MockMailServer;
-import org.apache.james.test.util.Util;
-import org.apache.james.userrepository.MockUsersRepository;
-import org.apache.james.util.connection.SimpleConnectionManager;
-import org.apache.mailet.MailAddress;
-import org.columba.ristretto.io.Source;
-import org.columba.ristretto.pop3.POP3Exception;
-import org.columba.ristretto.pop3.POP3Protocol;
-import org.columba.ristretto.pop3.POP3Response;
-import org.columba.ristretto.pop3.ScanListEntry;
-
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-import javax.mail.util.SharedByteArrayInputStream;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-
-import junit.framework.TestCase;
-
-/**
- * Tests the org.apache.james.smtpserver.SMTPServer unit
- */
-public class POP3ServerTest extends TestCase {
-    private int m_pop3ListenerPort = Util.getNonPrivilegedPort();
-
-    private MockMailServer m_mailServer;
-
-    private POP3TestConfiguration m_testConfiguration;
-
-    private POP3Server m_pop3Server;
-
-    private MockUsersRepository m_usersRepository = new MockUsersRepository();
-
-    public POP3ServerTest() {
-        super("POP3ServerTest");
-    }
-
-    protected void setUp() throws Exception {
-        m_pop3Server = new POP3Server();
-        ContainerUtil.enableLogging(m_pop3Server, new MockLogger());
-        ContainerUtil.service(m_pop3Server, setUpServiceManager());
-        m_testConfiguration = new POP3TestConfiguration(m_pop3ListenerPort);
-    }
-
-    private void finishSetUp(POP3TestConfiguration testConfiguration)
-            throws Exception {
-        testConfiguration.init();
-        ContainerUtil.configure(m_pop3Server, testConfiguration);
-        ContainerUtil.initialize(m_pop3Server);
-    }
-
-    private MockServiceManager setUpServiceManager() {
-        MockServiceManager serviceManager = new MockServiceManager();
-        SimpleConnectionManager connectionManager = new SimpleConnectionManager();
-        ContainerUtil.enableLogging(connectionManager, new MockLogger());
-        serviceManager.put(JamesConnectionManager.ROLE, connectionManager);
-        m_mailServer = new MockMailServer();
-        serviceManager
-                .put(MailServer.ROLE, m_mailServer);
-        serviceManager.put(UsersRepository.ROLE,
-                m_usersRepository);
-        serviceManager.put(SocketManager.ROLE, new MockSocketManager(
-                m_pop3ListenerPort));
-        serviceManager.put(ThreadManager.ROLE, new MockThreadManager());
-        return serviceManager;
-    }
-
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        m_pop3Server.dispose();
-    }
-
-    public void testAuthenticationFail() throws Exception, POP3Exception {
-        finishSetUp(m_testConfiguration);
-
-        POP3Protocol pop3Protocol = new POP3Protocol("127.0.0.1",
-                m_pop3ListenerPort);
-        pop3Protocol.openPort();
-
-        m_usersRepository.addUser("known", "test2");
-
-        int res = 0;
-        try {
-            pop3Protocol.userPass("known", "test".toCharArray());
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-        }
-
-        assertEquals(-1, res);
-
-        pop3Protocol.quit();
-    }
-
-    public void testUnknownUser() throws Exception, POP3Exception {
-        finishSetUp(m_testConfiguration);
-
-        POP3Protocol pop3Protocol = new POP3Protocol("127.0.0.1",
-                m_pop3ListenerPort);
-        pop3Protocol.openPort();
-
-        int res = 0;
-        try {
-            pop3Protocol.userPass("unknown", "test".toCharArray());
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-        }
-
-        assertEquals(-1, res);
-
-        pop3Protocol.quit();
-    }
-
-    public void testKnownUserEmptyInbox() throws Exception, POP3Exception {
-        finishSetUp(m_testConfiguration);
-
-        POP3Protocol pop3Protocol = new POP3Protocol("127.0.0.1",
-                m_pop3ListenerPort);
-        pop3Protocol.openPort();
-
-        m_usersRepository.addUser("foo", "bar");
-        m_mailServer.setUserInbox("foo", new MockMailRepository());
-
-        int res = 0;
-        
-        try {
-            pop3Protocol.userPass("foo", "bar".toCharArray());
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-            fail("pass failed");
-        }
-
-        assertEquals(0, res);
-
-        res = 0;
-        ScanListEntry[] entries = null;
-        try {
-            entries = pop3Protocol.list();
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-        }
-
-        assertNotNull(entries);
-        assertEquals(entries.length, 0);
-        assertEquals(res, 0);
-
-        pop3Protocol.quit();
-    }
-
-    public void testNotAsciiCharsInPassword() throws Exception, POP3Exception {
-        finishSetUp(m_testConfiguration);
-
-        POP3Protocol pop3Protocol = new POP3Protocol("127.0.0.1",
-                m_pop3ListenerPort);
-        pop3Protocol.openPort();
-
-        String pass = "bar" + (new String(new char[] { 200, 210 })) + "foo";
-        m_usersRepository.addUser("foo", pass);
-        m_mailServer.setUserInbox("foo", new MockMailRepository());
-
-        int res = 0;
-        try {
-            pop3Protocol.userPass("foo", pass.toCharArray());
-        } catch (POP3Exception e) {
-            res = e.getResponse() != null ? e.getResponse().getType() : -1;
-        }
-
-        assertEquals(0, res);
-
-        pop3Protocol.quit();
-    }
-
-    public void testKnownUserInboxWithMessages() throws Exception,
-            POP3Exception {
-        finishSetUp(m_testConfiguration);
-
-        POP3Protocol pop3Protocol = new POP3Protocol("127.0.0.1",
-                m_pop3ListenerPort);
-        pop3Protocol.openPort();
-
-        m_usersRepository.addUser("foo2", "bar2");
-        MockMailRepository mailRep = new MockMailRepository();
-
-        setupTestMails(mailRep);
-
-        m_mailServer.setUserInbox("foo2", mailRep);
-
-        int res = 0;
-        try {
-            pop3Protocol.userPass("foo2", "bar2".toCharArray());
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-        }
-
-        assertEquals(0, res);
-
-        res = 0;
-        ScanListEntry[] entries = null;
-        try {
-            entries = pop3Protocol.list();
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-        }
-
-        assertNotNull(entries);
-        assertEquals(2, entries.length);
-        assertEquals(res, 0);
-
-        Source i = null;
-        try {
-            i = pop3Protocol.top(entries[0].getIndex(), 0);
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-        }
-
-        assertNotNull(i);
-        i.close();
-
-        InputStream i2 = null;
-        try {
-            i2 = pop3Protocol.retr(entries[0].getIndex());
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-        }
-
-        assertNotNull(i2);
-        
-        i2.close();
-
-        boolean deleted = false;
-        try {
-            deleted = pop3Protocol.dele(entries[0].getIndex());
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-        }
-
-        assertTrue(deleted);
-        assertEquals(res, 0);
-
-        pop3Protocol.quit();
-
-        pop3Protocol.openPort();
-
-        res = 0;
-        try {
-            pop3Protocol.userPass("foo2", "bar2".toCharArray());
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-        }
-
-        assertEquals(0, res);
-
-        res = 0;
-        entries = null;
-        
-        try {
-            int[] stats = pop3Protocol.stat();
-            assertEquals(2, stats.length);
-            assertEquals(1, stats[0]);
-            assertEquals(92, stats[1]);
-        } catch (POP3Exception e) {
-            fail("stat failed");
-        }
-        
-        try {
-            entries = pop3Protocol.list();
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-        } finally {
-            assertNotNull(entries);
-            assertEquals(1, entries.length);
-            assertEquals(res, 0);
-        }
-
-        i = null;
-        try {
-            i = pop3Protocol.top(entries[0].getIndex(), 0);
-        } catch (POP3Exception e) {
-            res = e.getResponse().getType();
-        } finally {
-            assertNotNull(i);
-            i.close();
-        }
-        pop3Protocol.quit();
-    }
-
-    private void setupTestMails(MockMailRepository mailRep) throws MessagingException {
-        ArrayList recipients = new ArrayList();
-        recipients.add(new MailAddress("recipient@test.com"));
-        MimeMessage mw = new MimeMessageCopyOnWriteProxy(
-                new MimeMessageInputStreamSource(
-                        "test",
-                        new SharedByteArrayInputStream(
-                                ("Return-path: return@test.com\r\n"+
-                                 "Content-Transfer-Encoding: plain\r\n"+
-                                 "Subject: test\r\n\r\n"+
-                                 "Body Text\r\n").getBytes())));
-        mailRep.store(new MailImpl("name", new MailAddress("from@test.com"),
-                recipients, mw));
-        MimeMessage mw2 = new MimeMessageCopyOnWriteProxy(
-                new MimeMessageInputStreamSource(
-                        "test2",
-                        new SharedByteArrayInputStream(
-                                ("").getBytes())));
-        mailRep.store(new MailImpl("name2", new MailAddress("from@test.com"),
-                recipients, mw2));
-    }
-
-    public void testTwoSimultaneousMails() throws Exception {
-        finishSetUp(m_testConfiguration);
-
-        // make two user/repositories, open both
-        m_usersRepository.addUser("foo1", "bar1");
-        MockMailRepository mailRep1 = new MockMailRepository();
-        setupTestMails(mailRep1);
-        m_mailServer.setUserInbox("foo1", mailRep1);
-
-        m_usersRepository.addUser("foo2", "bar2");
-        MockMailRepository mailRep2 = new MockMailRepository();
-        //do not setupTestMails, this is done later
-        m_mailServer.setUserInbox("foo2", mailRep2);
-
-        // open two connections
-        POP3Protocol pop3Protocol1 = new POP3Protocol("127.0.0.1",
-                m_pop3ListenerPort);
-        POP3Protocol pop3Protocol2 = new POP3Protocol("127.0.0.1",
-                m_pop3ListenerPort);
-        pop3Protocol1.openPort();
-        pop3Protocol2.openPort();
-
-        assertEquals("first connection taken", 1, pop3Protocol1.getState());
-        assertEquals("second connection taken", 1, pop3Protocol2.getState());
-
-        // open two accounts
-        try {
-            pop3Protocol1.userPass("foo1", "bar1".toCharArray());
-        } catch (POP3Exception e) {
-            e.getResponse().getType();
-        }
-
-        try {
-            pop3Protocol2.userPass("foo2", "bar2".toCharArray());
-        } catch (POP3Exception e) {
-            e.getResponse().getType();
-        }
-
-        ScanListEntry[] entries = null;
-        try {
-            entries = pop3Protocol1.list();
-            assertEquals("foo1 has mails", 2, entries.length);
-        } catch (POP3Exception e) {
-            e.getResponse().getType();
-        }
-
-        try {
-            entries = pop3Protocol2.list();
-            assertEquals("foo2 has no mails", 0, entries.length);
-        } catch (POP3Exception e) {
-            e.getResponse().getType();
-        }
-
-        // put both to rest
-        pop3Protocol1.quit();
-        pop3Protocol2.quit();
-    }
-
-}
-
-class MyPOP3Protocol extends POP3Protocol {
-
-    public MyPOP3Protocol(String s, int i) {
-        super(s, i);
-    }
-
-    public MyPOP3Protocol(String s) {
-        super(s);
-    }
-
-    public void sendCommand(String string, String[] strings) throws IOException {
-        super.sendCommand(string, strings);
-    }
-
-    public POP3Response getResponse() throws IOException, POP3Exception {
-        return super.readSingleLineResponse();
-    }
-}
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.pop3server;
+
+import org.apache.avalon.cornerstone.services.sockets.SocketManager;
+import org.apache.avalon.cornerstone.services.threads.ThreadManager;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.james.core.MailImpl;
+import org.apache.james.core.MimeMessageCopyOnWriteProxy;
+import org.apache.james.core.MimeMessageInputStreamSource;
+import org.apache.james.services.JamesConnectionManager;
+import org.apache.james.services.MailServer;
+import org.apache.james.services.UsersRepository;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.james.test.mock.avalon.MockServiceManager;
+import org.apache.james.test.mock.avalon.MockSocketManager;
+import org.apache.james.test.mock.avalon.MockThreadManager;
+import org.apache.james.test.mock.james.MockMailRepository;
+import org.apache.james.test.mock.james.MockMailServer;
+import org.apache.james.test.util.Util;
+import org.apache.james.userrepository.MockUsersRepository;
+import org.apache.james.util.connection.SimpleConnectionManager;
+import org.apache.mailet.MailAddress;
+import org.columba.ristretto.io.Source;
+import org.columba.ristretto.pop3.POP3Exception;
+import org.columba.ristretto.pop3.POP3Protocol;
+import org.columba.ristretto.pop3.POP3Response;
+import org.columba.ristretto.pop3.ScanListEntry;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import javax.mail.util.SharedByteArrayInputStream;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the org.apache.james.smtpserver.SMTPServer unit
+ */
+public class POP3ServerTest extends TestCase {
+    private int m_pop3ListenerPort = Util.getNonPrivilegedPort();
+
+    private MockMailServer m_mailServer;
+
+    private POP3TestConfiguration m_testConfiguration;
+
+    private POP3Server m_pop3Server;
+
+    private MockUsersRepository m_usersRepository = new MockUsersRepository();
+
+    public POP3ServerTest() {
+        super("POP3ServerTest");
+    }
+
+    protected void setUp() throws Exception {
+        m_pop3Server = new POP3Server();
+        ContainerUtil.enableLogging(m_pop3Server, new MockLogger());
+        ContainerUtil.service(m_pop3Server, setUpServiceManager());
+        m_testConfiguration = new POP3TestConfiguration(m_pop3ListenerPort);
+    }
+
+    private void finishSetUp(POP3TestConfiguration testConfiguration)
+            throws Exception {
+        testConfiguration.init();
+        ContainerUtil.configure(m_pop3Server, testConfiguration);
+        ContainerUtil.initialize(m_pop3Server);
+    }
+
+    private MockServiceManager setUpServiceManager() {
+        MockServiceManager serviceManager = new MockServiceManager();
+        SimpleConnectionManager connectionManager = new SimpleConnectionManager();
+        ContainerUtil.enableLogging(connectionManager, new MockLogger());
+        serviceManager.put(JamesConnectionManager.ROLE, connectionManager);
+        m_mailServer = new MockMailServer();
+        serviceManager
+                .put(MailServer.ROLE, m_mailServer);
+        serviceManager.put(UsersRepository.ROLE,
+                m_usersRepository);
+        serviceManager.put(SocketManager.ROLE, new MockSocketManager(
+                m_pop3ListenerPort));
+        serviceManager.put(ThreadManager.ROLE, new MockThreadManager());
+        return serviceManager;
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        m_pop3Server.dispose();
+    }
+
+    public void testAuthenticationFail() throws Exception, POP3Exception {
+        finishSetUp(m_testConfiguration);
+
+        POP3Protocol pop3Protocol = new POP3Protocol("127.0.0.1",
+                m_pop3ListenerPort);
+        pop3Protocol.openPort();
+
+        m_usersRepository.addUser("known", "test2");
+
+        int res = 0;
+        try {
+            pop3Protocol.userPass("known", "test".toCharArray());
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+        }
+
+        assertEquals(-1, res);
+
+        pop3Protocol.quit();
+    }
+
+    public void testUnknownUser() throws Exception, POP3Exception {
+        finishSetUp(m_testConfiguration);
+
+        POP3Protocol pop3Protocol = new POP3Protocol("127.0.0.1",
+                m_pop3ListenerPort);
+        pop3Protocol.openPort();
+
+        int res = 0;
+        try {
+            pop3Protocol.userPass("unknown", "test".toCharArray());
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+        }
+
+        assertEquals(-1, res);
+
+        pop3Protocol.quit();
+    }
+
+    public void testKnownUserEmptyInbox() throws Exception, POP3Exception {
+        finishSetUp(m_testConfiguration);
+
+        POP3Protocol pop3Protocol = new POP3Protocol("127.0.0.1",
+                m_pop3ListenerPort);
+        pop3Protocol.openPort();
+
+        m_usersRepository.addUser("foo", "bar");
+        m_mailServer.setUserInbox("foo", new MockMailRepository());
+
+        int res = 0;
+        
+        try {
+            pop3Protocol.userPass("foo", "bar".toCharArray());
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+            fail("pass failed");
+        }
+
+        assertEquals(0, res);
+
+        res = 0;
+        ScanListEntry[] entries = null;
+        try {
+            entries = pop3Protocol.list();
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+        }
+
+        assertNotNull(entries);
+        assertEquals(entries.length, 0);
+        assertEquals(res, 0);
+
+        pop3Protocol.quit();
+    }
+
+    public void testNotAsciiCharsInPassword() throws Exception, POP3Exception {
+        finishSetUp(m_testConfiguration);
+
+        POP3Protocol pop3Protocol = new POP3Protocol("127.0.0.1",
+                m_pop3ListenerPort);
+        pop3Protocol.openPort();
+
+        String pass = "bar" + (new String(new char[] { 200, 210 })) + "foo";
+        m_usersRepository.addUser("foo", pass);
+        m_mailServer.setUserInbox("foo", new MockMailRepository());
+
+        int res = 0;
+        try {
+            pop3Protocol.userPass("foo", pass.toCharArray());
+        } catch (POP3Exception e) {
+            res = e.getResponse() != null ? e.getResponse().getType() : -1;
+        }
+
+        assertEquals(0, res);
+
+        pop3Protocol.quit();
+    }
+
+    public void testKnownUserInboxWithMessages() throws Exception,
+            POP3Exception {
+        finishSetUp(m_testConfiguration);
+
+        POP3Protocol pop3Protocol = new POP3Protocol("127.0.0.1",
+                m_pop3ListenerPort);
+        pop3Protocol.openPort();
+
+        m_usersRepository.addUser("foo2", "bar2");
+        MockMailRepository mailRep = new MockMailRepository();
+
+        setupTestMails(mailRep);
+
+        m_mailServer.setUserInbox("foo2", mailRep);
+
+        int res = 0;
+        try {
+            pop3Protocol.userPass("foo2", "bar2".toCharArray());
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+        }
+
+        assertEquals(0, res);
+
+        res = 0;
+        ScanListEntry[] entries = null;
+        try {
+            entries = pop3Protocol.list();
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+        }
+
+        assertNotNull(entries);
+        assertEquals(2, entries.length);
+        assertEquals(res, 0);
+
+        Source i = null;
+        try {
+            i = pop3Protocol.top(entries[0].getIndex(), 0);
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+        }
+
+        assertNotNull(i);
+        i.close();
+
+        InputStream i2 = null;
+        try {
+            i2 = pop3Protocol.retr(entries[0].getIndex());
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+        }
+
+        assertNotNull(i2);
+        
+        i2.close();
+
+        boolean deleted = false;
+        try {
+            deleted = pop3Protocol.dele(entries[0].getIndex());
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+        }
+
+        assertTrue(deleted);
+        assertEquals(res, 0);
+
+        pop3Protocol.quit();
+
+        pop3Protocol.openPort();
+
+        res = 0;
+        try {
+            pop3Protocol.userPass("foo2", "bar2".toCharArray());
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+        }
+
+        assertEquals(0, res);
+
+        res = 0;
+        entries = null;
+        
+        try {
+            int[] stats = pop3Protocol.stat();
+            assertEquals(2, stats.length);
+            assertEquals(1, stats[0]);
+            assertEquals(92, stats[1]);
+        } catch (POP3Exception e) {
+            fail("stat failed");
+        }
+        
+        try {
+            entries = pop3Protocol.list();
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+        } finally {
+            assertNotNull(entries);
+            assertEquals(1, entries.length);
+            assertEquals(res, 0);
+        }
+
+        i = null;
+        try {
+            i = pop3Protocol.top(entries[0].getIndex(), 0);
+        } catch (POP3Exception e) {
+            res = e.getResponse().getType();
+        } finally {
+            assertNotNull(i);
+            i.close();
+        }
+        pop3Protocol.quit();
+    }
+
+    private void setupTestMails(MockMailRepository mailRep) throws MessagingException {
+        ArrayList recipients = new ArrayList();
+        recipients.add(new MailAddress("recipient@test.com"));
+        MimeMessage mw = new MimeMessageCopyOnWriteProxy(
+                new MimeMessageInputStreamSource(
+                        "test",
+                        new SharedByteArrayInputStream(
+                                ("Return-path: return@test.com\r\n"+
+                                 "Content-Transfer-Encoding: plain\r\n"+
+                                 "Subject: test\r\n\r\n"+
+                                 "Body Text\r\n").getBytes())));
+        mailRep.store(new MailImpl("name", new MailAddress("from@test.com"),
+                recipients, mw));
+        MimeMessage mw2 = new MimeMessageCopyOnWriteProxy(
+                new MimeMessageInputStreamSource(
+                        "test2",
+                        new SharedByteArrayInputStream(
+                                ("").getBytes())));
+        mailRep.store(new MailImpl("name2", new MailAddress("from@test.com"),
+                recipients, mw2));
+    }
+
+    public void testTwoSimultaneousMails() throws Exception {
+        finishSetUp(m_testConfiguration);
+
+        // make two user/repositories, open both
+        m_usersRepository.addUser("foo1", "bar1");
+        MockMailRepository mailRep1 = new MockMailRepository();
+        setupTestMails(mailRep1);
+        m_mailServer.setUserInbox("foo1", mailRep1);
+
+        m_usersRepository.addUser("foo2", "bar2");
+        MockMailRepository mailRep2 = new MockMailRepository();
+        //do not setupTestMails, this is done later
+        m_mailServer.setUserInbox("foo2", mailRep2);
+
+        // open two connections
+        POP3Protocol pop3Protocol1 = new POP3Protocol("127.0.0.1",
+                m_pop3ListenerPort);
+        POP3Protocol pop3Protocol2 = new POP3Protocol("127.0.0.1",
+                m_pop3ListenerPort);
+        pop3Protocol1.openPort();
+        pop3Protocol2.openPort();
+
+        assertEquals("first connection taken", 1, pop3Protocol1.getState());
+        assertEquals("second connection taken", 1, pop3Protocol2.getState());
+
+        // open two accounts
+        try {
+            pop3Protocol1.userPass("foo1", "bar1".toCharArray());
+        } catch (POP3Exception e) {
+            e.getResponse().getType();
+        }
+
+        try {
+            pop3Protocol2.userPass("foo2", "bar2".toCharArray());
+        } catch (POP3Exception e) {
+            e.getResponse().getType();
+        }
+
+        ScanListEntry[] entries = null;
+        try {
+            entries = pop3Protocol1.list();
+            assertEquals("foo1 has mails", 2, entries.length);
+        } catch (POP3Exception e) {
+            e.getResponse().getType();
+        }
+
+        try {
+            entries = pop3Protocol2.list();
+            assertEquals("foo2 has no mails", 0, entries.length);
+        } catch (POP3Exception e) {
+            e.getResponse().getType();
+        }
+
+        // put both to rest
+        pop3Protocol1.quit();
+        pop3Protocol2.quit();
+    }
+
+}
+
+class MyPOP3Protocol extends POP3Protocol {
+
+    public MyPOP3Protocol(String s, int i) {
+        super(s, i);
+    }
+
+    public MyPOP3Protocol(String s) {
+        super(s);
+    }
+
+    public void sendCommand(String string, String[] strings) throws IOException {
+        super.sendCommand(string, strings);
+    }
+
+    public POP3Response getResponse() throws IOException, POP3Exception {
+        return super.readSingleLineResponse();
+    }
+}

Propchange: james/server/trunk/src/test/org/apache/james/pop3server/POP3ServerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/test/org/apache/james/pop3server/POP3TestConfiguration.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/pop3server/POP3TestConfiguration.java?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/pop3server/POP3TestConfiguration.java (original)
+++ james/server/trunk/src/test/org/apache/james/pop3server/POP3TestConfiguration.java Wed May 10 09:46:54 2006
@@ -1,41 +1,41 @@
-/***********************************************************************
- * Copyright (c) 2000-2006 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed 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.pop3server;
-
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.james.test.util.Util;
-
-public class POP3TestConfiguration extends DefaultConfiguration {
-
-    private int m_pop3ListenerPort;
-
-    public POP3TestConfiguration(int pop3ListenerPort) {
-        super("pop3server");
-        m_pop3ListenerPort = pop3ListenerPort;
-    }
-
-    public void init() {
-        setAttribute("enabled", true);
-        addChild(Util.getValuedConfiguration("port", "" + m_pop3ListenerPort));
-        DefaultConfiguration handlerConfig = new DefaultConfiguration("handler");
-        handlerConfig.addChild(Util.getValuedConfiguration("helloName", "myMailServer"));
-        handlerConfig.addChild(Util.getValuedConfiguration("connectiontimeout", "360000"));
-
-        addChild(handlerConfig);
-    }
-
-}
+/***********************************************************************
+ * Copyright (c) 2000-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.pop3server;
+
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.james.test.util.Util;
+
+public class POP3TestConfiguration extends DefaultConfiguration {
+
+    private int m_pop3ListenerPort;
+
+    public POP3TestConfiguration(int pop3ListenerPort) {
+        super("pop3server");
+        m_pop3ListenerPort = pop3ListenerPort;
+    }
+
+    public void init() {
+        setAttribute("enabled", true);
+        addChild(Util.getValuedConfiguration("port", "" + m_pop3ListenerPort));
+        DefaultConfiguration handlerConfig = new DefaultConfiguration("handler");
+        handlerConfig.addChild(Util.getValuedConfiguration("helloName", "myMailServer"));
+        handlerConfig.addChild(Util.getValuedConfiguration("connectiontimeout", "360000"));
+
+        addChild(handlerConfig);
+    }
+
+}

Propchange: james/server/trunk/src/test/org/apache/james/pop3server/POP3TestConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java Wed May 10 09:46:54 2006
@@ -1,489 +1,489 @@
-/***********************************************************************
- * Copyright (c) 2000-2005 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed 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.remotemanager;
-
-import org.apache.avalon.cornerstone.services.sockets.SocketManager;
-import org.apache.avalon.cornerstone.services.threads.ThreadManager;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.commons.net.telnet.TelnetClient;
-import org.apache.james.services.JamesConnectionManager;
-import org.apache.james.services.MailServer;
-import org.apache.james.services.UsersRepository;
-import org.apache.james.services.UsersStore;
-import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.james.test.mock.avalon.MockServiceManager;
-import org.apache.james.test.mock.avalon.MockSocketManager;
-import org.apache.james.test.mock.avalon.MockThreadManager;
-import org.apache.james.test.mock.james.MockMailServer;
-import org.apache.james.test.mock.james.MockUsersStore;
-import org.apache.james.test.util.Util;
-import org.apache.james.userrepository.MockUsersRepository;
-import org.apache.james.util.connection.SimpleConnectionManager;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-/**
- * Tests the org.apache.james.remotemanager.RemoteManager
- * TODO: impl missing command tests for: 
- *       USER 
- *       SHUTDOWN (hard to test, because it does shutdown the whole (testing) JVM 
- */
-
-public class RemoteManagerTest extends TestCase {
-    
-    public static final String LINE_SEPARATOR = System.getProperties().getProperty("line.separator"); 
-
-    protected int m_remoteManagerListenerPort = Util.getNonPrivilegedPort();
-    protected RemoteManager m_remoteManager;
-    protected RemoteManagerTestConfiguration m_testConfiguration;
-    protected String m_host = "127.0.0.1";
-    protected BufferedReader m_reader;
-    protected OutputStreamWriter m_writer;
-    protected TelnetClient m_telnetClient;
-    private MockUsersRepository m_mockUsersRepository;
-
-    protected void setUp() throws Exception {
-        m_remoteManager = new RemoteManager();
-        ContainerUtil.enableLogging(m_remoteManager, new MockLogger());
-        ContainerUtil.service(m_remoteManager, setUpServiceManager());
-        m_testConfiguration = new RemoteManagerTestConfiguration(m_remoteManagerListenerPort);
-    }
-
-    protected void finishSetUp(RemoteManagerTestConfiguration testConfiguration) {
-        testConfiguration.init();
-        try {
-            ContainerUtil.configure(m_remoteManager, testConfiguration);
-            ContainerUtil.initialize(m_remoteManager);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    protected void login() throws IOException {
-        login(m_testConfiguration.getLoginName(), m_testConfiguration.getLoginPassword());
-    }
-
-    protected void login(String name, String password) throws IOException {
-        sendCommand(name);
-        sendCommand(password);
-
-        List answers = readAnswer();
-        String 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() {
-        try {
-            while (!m_reader.ready()) { ; }
-        } catch (IOException e) {
-            return null;
-        }
-
-        StringBuffer stringBuffer = new StringBuffer();
-        char[] charBuffer = new char[100];
-        List allAnswerLines = new ArrayList();
-        try {
-            int readCount;
-            while ((m_reader.ready() && (readCount = m_reader.read(charBuffer)) > 0)) {
-                stringBuffer.append(charBuffer, 0, readCount);
-            }
-        } catch (IOException e) {
-            fail("reading remote manager answer failed");
-        }
-
-        allAnswerLines.addAll(Arrays.asList(stringBuffer.toString().split(LINE_SEPARATOR)));
-        if ("".equals(getLastLine(allAnswerLines))) allAnswerLines.remove(allAnswerLines.size()-1);
-        return allAnswerLines;
-    }
-
-    protected void sendCommand(String command) throws IOException {
-        m_writer.write(command + LINE_SEPARATOR);
-        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(m_telnetClient.getInputStream()));
-        m_writer = new OutputStreamWriter(m_telnetClient.getOutputStream());
-    }
-
-    private MockServiceManager setUpServiceManager() {
-        MockServiceManager serviceManager = new MockServiceManager();
-        SimpleConnectionManager connectionManager = new SimpleConnectionManager();
-        ContainerUtil.enableLogging(connectionManager, new MockLogger());
-        serviceManager.put(JamesConnectionManager.ROLE, connectionManager);
-        MockMailServer mailServer = new MockMailServer();
-        serviceManager.put(MailServer.ROLE, mailServer);
-        m_mockUsersRepository = mailServer.getUsersRepository();
-        serviceManager.put(UsersRepository.ROLE, m_mockUsersRepository);
-        serviceManager.put(UsersStore.ROLE, new MockUsersStore(m_mockUsersRepository));
-        serviceManager.put(SocketManager.ROLE, new MockSocketManager(m_remoteManagerListenerPort));
-        serviceManager.put(ThreadManager.ROLE, new MockThreadManager());
-        return serviceManager;
-    }
-
-    public void testLogin() throws IOException {
-        finishSetUp(m_testConfiguration);
-        connect();
-
-        login();
-    }
-
-    public void testWrongLoginUser() throws IOException {
-        finishSetUp(m_testConfiguration);
-        connect();
-
-        sendCommand("sindbad");
-        sendCommand(m_testConfiguration.getLoginPassword());
-
-        List answers = readAnswer();
-        String last = getLastLine(answers);
-        assertTrue(last.startsWith("Login id:")); // login failed, getting new login prompt
-    }
-
-    public void testWrongLoginPassword() throws IOException {
-        finishSetUp(m_testConfiguration);
-        connect();
-
-        sendCommand(m_testConfiguration.getLoginName());
-        sendCommand("getmethru");
-
-        List answers = readAnswer();
-        String last = getLastLine(answers);
-        assertTrue(last.startsWith("Login id:")); // login failed, getting new login prompt
-    }
-
-    public void testUserCount() throws IOException {
-        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 IOException {
-        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 IOException {
-        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 IOException {
-        finishSetUp(m_testConfiguration);
-        connect();
-        login();
-
-        sendCommand("help");
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException e) {
-            ; // ignore
-        }
-        assertTrue("command line is effective", readAnswer().size() > 0);
-
-        sendCommand("quit");
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException e) {
-            ; // ignore
-        }
-        readAnswer();
-
-        sendCommand("help");
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException e) {
-            ; // ignore
-        }
-        assertNull("connection is closed", m_reader.readLine());
-    }   
-
-    public void testListUsers() throws IOException {
-        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");
-        }
-        
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException e) {
-            ; // ignore
-        }
-        readAnswer();
-
-        sendCommand("listusers");
-        List list = readAnswer();
-
-        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));
-        }
-    }
-
-    public void testCommandCaseInsensitive() throws IOException {
-        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 IOException {
-        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 testAlias() throws IOException {
-        m_mockUsersRepository.setForceUseJamesUser();
-        finishSetUp(m_testConfiguration);
-        connect();
-        login();
-        
-        // do some tests when parameter users don't exist
-        sendCommand("setalias testNonExist1 testNonExist2");
-        assertTrue(getLastLine(readAnswer()).equals("No such user testNonExist1"));
-
-        sendCommand("adduser testAlias1 test");
-        assertTrue(getLastLine(readAnswer()).endsWith(" added"));
-
-        sendCommand("showalias testAlias1");
-        assertTrue(getLastLine(readAnswer()).equals("User testAlias1 does not currently have an alias"));
-
-        sendCommand("setalias testAlias1 testNonExist2");
-        assertTrue(getLastLine(readAnswer()).equals("Alias unknown to server - create that user first."));
-
-        sendCommand("setalias testNonExist1 testAlias");
-        assertTrue(getLastLine(readAnswer()).equals("No such user testNonExist1"));
-
-        sendCommand("adduser testAlias2 test");
-        assertTrue(getLastLine(readAnswer()).endsWith(" added"));
-
-        // regular alias
-        sendCommand("setalias testAlias1 testAlias2");
-        assertTrue(getLastLine(readAnswer()).equals("Alias for testAlias1 set to:testAlias2"));
-
-        //TODO: is this correct? even primitive circular aliasing allowed!
-        sendCommand("setalias testAlias2 testAlias1");
-        assertTrue(getLastLine(readAnswer()).equals("Alias for testAlias2 set to:testAlias1"));
-
-        // did first one persist?
-        sendCommand("showalias testAlias1");
-        assertTrue(getLastLine(readAnswer()).equals("Current alias for testAlias1 is: testAlias2"));
-
-        //TODO: is this correct? setting self as alias!
-        sendCommand("setalias testAlias1 testAlias1");
-        assertTrue(getLastLine(readAnswer()).equals("Alias for testAlias1 set to:testAlias1"));
-
-        sendCommand("adduser testAlias3 test");
-        assertTrue(getLastLine(readAnswer()).endsWith(" added"));
-
-        // re-set, simply overwrites
-        sendCommand("setalias testAlias1 testAlias3");
-        assertTrue(getLastLine(readAnswer()).equals("Alias for testAlias1 set to:testAlias3"));
-
-        // check overwrite
-        sendCommand("showalias testAlias1");
-        assertTrue(getLastLine(readAnswer()).equals("Current alias for testAlias1 is: testAlias3"));
-
-        // retreat
-        sendCommand("unsetalias testAlias1");
-        assertTrue(getLastLine(readAnswer()).equals("Alias for testAlias1 unset"));
-
-        // check removed alias
-        sendCommand("showalias testAlias1");
-        assertTrue(getLastLine(readAnswer()).equals("User testAlias1 does not currently have an alias"));
-
-    }
-
-    public void testForward() throws IOException {
-        m_mockUsersRepository.setForceUseJamesUser();
-        finishSetUp(m_testConfiguration);
-        connect();
-        login();
-
-        // do some tests when parameter users don't exist
-        sendCommand("setforwarding testNonExist1 testForward1@locahost");
-        assertTrue(getLastLine(readAnswer()).equals("No such user testNonExist1"));
-        
-        sendCommand("adduser testForwardUser test");
-        assertTrue(getLastLine(readAnswer()).endsWith(" added"));
-
-        sendCommand("showforwarding testForwardUser");
-        assertTrue(getLastLine(readAnswer()).equals("User testForwardUser is not currently being forwarded"));
-
-        sendCommand("setforwarding testForwardUser testForward1@locahost");
-        assertTrue(getLastLine(readAnswer()).equals("Forwarding destination for testForwardUser set to:testForward1@locahost"));
-        
-        // did it persist?
-        sendCommand("showforwarding testForwardUser");
-        assertTrue(getLastLine(readAnswer()).equals("Current forwarding destination for testForwardUser is: testForward1@locahost"));
-
-        // re-set, simply overwrites
-        sendCommand("setforwarding testForwardUser testForward2@locahost");
-        assertTrue(getLastLine(readAnswer()).equals("Forwarding destination for testForwardUser set to:testForward2@locahost"));
-
-        // check overwrite
-        sendCommand("showforwarding testForwardUser");
-        assertTrue(getLastLine(readAnswer()).equals("Current forwarding destination for testForwardUser is: testForward2@locahost"));
-
-        // retreat
-        sendCommand("unsetforwarding testForwardUser");
-        assertTrue(getLastLine(readAnswer()).equals("Forward for testForwardUser unset"));
-
-        // check removed forward
-        sendCommand("showforwarding testForwardUser");
-        assertTrue(getLastLine(readAnswer()).equals("User testForwardUser is not currently being forwarded"));
-
-    }
-
-    public void testSetPassword() throws IOException {
-        finishSetUp(m_testConfiguration);
-        connect();
-        login();
-
-        sendCommand("adduser testPwdUser pwd1");
-        assertTrue(getLastLine(readAnswer()).endsWith(" added"));
-
-        assertTrue("initial password", m_mockUsersRepository.test("testPwdUser", "pwd1"));
-        
-         sendCommand("setpassword testPwdUser     ");
-        assertTrue("password changed to empty", m_mockUsersRepository.test("testPwdUser", "pwd1"));
-        readAnswer(); // ignore
-
-        // change pwd
-        sendCommand("setpassword testPwdUser pwd2");
-        assertTrue("password not changed to pwd2", m_mockUsersRepository.test("testPwdUser", "pwd2"));
-        readAnswer(); // ignore
-        
-        // assure case sensitivity
-        sendCommand("setpassword testPwdUser pWD2");
-        assertFalse("password not changed to pWD2", m_mockUsersRepository.test("testPwdUser", "pwd2"));
-        assertTrue("password not changed to pWD2", m_mockUsersRepository.test("testPwdUser", "pWD2"));
-        readAnswer(); // ignore
-        
-    }
-}
+/***********************************************************************
+ * Copyright (c) 2000-2005 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.remotemanager;
+
+import org.apache.avalon.cornerstone.services.sockets.SocketManager;
+import org.apache.avalon.cornerstone.services.threads.ThreadManager;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.commons.net.telnet.TelnetClient;
+import org.apache.james.services.JamesConnectionManager;
+import org.apache.james.services.MailServer;
+import org.apache.james.services.UsersRepository;
+import org.apache.james.services.UsersStore;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.james.test.mock.avalon.MockServiceManager;
+import org.apache.james.test.mock.avalon.MockSocketManager;
+import org.apache.james.test.mock.avalon.MockThreadManager;
+import org.apache.james.test.mock.james.MockMailServer;
+import org.apache.james.test.mock.james.MockUsersStore;
+import org.apache.james.test.util.Util;
+import org.apache.james.userrepository.MockUsersRepository;
+import org.apache.james.util.connection.SimpleConnectionManager;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the org.apache.james.remotemanager.RemoteManager
+ * TODO: impl missing command tests for: 
+ *       USER 
+ *       SHUTDOWN (hard to test, because it does shutdown the whole (testing) JVM 
+ */
+
+public class RemoteManagerTest extends TestCase {
+    
+    public static final String LINE_SEPARATOR = System.getProperties().getProperty("line.separator"); 
+
+    protected int m_remoteManagerListenerPort = Util.getNonPrivilegedPort();
+    protected RemoteManager m_remoteManager;
+    protected RemoteManagerTestConfiguration m_testConfiguration;
+    protected String m_host = "127.0.0.1";
+    protected BufferedReader m_reader;
+    protected OutputStreamWriter m_writer;
+    protected TelnetClient m_telnetClient;
+    private MockUsersRepository m_mockUsersRepository;
+
+    protected void setUp() throws Exception {
+        m_remoteManager = new RemoteManager();
+        ContainerUtil.enableLogging(m_remoteManager, new MockLogger());
+        ContainerUtil.service(m_remoteManager, setUpServiceManager());
+        m_testConfiguration = new RemoteManagerTestConfiguration(m_remoteManagerListenerPort);
+    }
+
+    protected void finishSetUp(RemoteManagerTestConfiguration testConfiguration) {
+        testConfiguration.init();
+        try {
+            ContainerUtil.configure(m_remoteManager, testConfiguration);
+            ContainerUtil.initialize(m_remoteManager);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected void login() throws IOException {
+        login(m_testConfiguration.getLoginName(), m_testConfiguration.getLoginPassword());
+    }
+
+    protected void login(String name, String password) throws IOException {
+        sendCommand(name);
+        sendCommand(password);
+
+        List answers = readAnswer();
+        String 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() {
+        try {
+            while (!m_reader.ready()) { ; }
+        } catch (IOException e) {
+            return null;
+        }
+
+        StringBuffer stringBuffer = new StringBuffer();
+        char[] charBuffer = new char[100];
+        List allAnswerLines = new ArrayList();
+        try {
+            int readCount;
+            while ((m_reader.ready() && (readCount = m_reader.read(charBuffer)) > 0)) {
+                stringBuffer.append(charBuffer, 0, readCount);
+            }
+        } catch (IOException e) {
+            fail("reading remote manager answer failed");
+        }
+
+        allAnswerLines.addAll(Arrays.asList(stringBuffer.toString().split(LINE_SEPARATOR)));
+        if ("".equals(getLastLine(allAnswerLines))) allAnswerLines.remove(allAnswerLines.size()-1);
+        return allAnswerLines;
+    }
+
+    protected void sendCommand(String command) throws IOException {
+        m_writer.write(command + LINE_SEPARATOR);
+        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(m_telnetClient.getInputStream()));
+        m_writer = new OutputStreamWriter(m_telnetClient.getOutputStream());
+    }
+
+    private MockServiceManager setUpServiceManager() {
+        MockServiceManager serviceManager = new MockServiceManager();
+        SimpleConnectionManager connectionManager = new SimpleConnectionManager();
+        ContainerUtil.enableLogging(connectionManager, new MockLogger());
+        serviceManager.put(JamesConnectionManager.ROLE, connectionManager);
+        MockMailServer mailServer = new MockMailServer();
+        serviceManager.put(MailServer.ROLE, mailServer);
+        m_mockUsersRepository = mailServer.getUsersRepository();
+        serviceManager.put(UsersRepository.ROLE, m_mockUsersRepository);
+        serviceManager.put(UsersStore.ROLE, new MockUsersStore(m_mockUsersRepository));
+        serviceManager.put(SocketManager.ROLE, new MockSocketManager(m_remoteManagerListenerPort));
+        serviceManager.put(ThreadManager.ROLE, new MockThreadManager());
+        return serviceManager;
+    }
+
+    public void testLogin() throws IOException {
+        finishSetUp(m_testConfiguration);
+        connect();
+
+        login();
+    }
+
+    public void testWrongLoginUser() throws IOException {
+        finishSetUp(m_testConfiguration);
+        connect();
+
+        sendCommand("sindbad");
+        sendCommand(m_testConfiguration.getLoginPassword());
+
+        List answers = readAnswer();
+        String last = getLastLine(answers);
+        assertTrue(last.startsWith("Login id:")); // login failed, getting new login prompt
+    }
+
+    public void testWrongLoginPassword() throws IOException {
+        finishSetUp(m_testConfiguration);
+        connect();
+
+        sendCommand(m_testConfiguration.getLoginName());
+        sendCommand("getmethru");
+
+        List answers = readAnswer();
+        String last = getLastLine(answers);
+        assertTrue(last.startsWith("Login id:")); // login failed, getting new login prompt
+    }
+
+    public void testUserCount() throws IOException {
+        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 IOException {
+        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 IOException {
+        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 IOException {
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("help");
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException e) {
+            ; // ignore
+        }
+        assertTrue("command line is effective", readAnswer().size() > 0);
+
+        sendCommand("quit");
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException e) {
+            ; // ignore
+        }
+        readAnswer();
+
+        sendCommand("help");
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException e) {
+            ; // ignore
+        }
+        assertNull("connection is closed", m_reader.readLine());
+    }   
+
+    public void testListUsers() throws IOException {
+        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");
+        }
+        
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException e) {
+            ; // ignore
+        }
+        readAnswer();
+
+        sendCommand("listusers");
+        List list = readAnswer();
+
+        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));
+        }
+    }
+
+    public void testCommandCaseInsensitive() throws IOException {
+        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 IOException {
+        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 testAlias() throws IOException {
+        m_mockUsersRepository.setForceUseJamesUser();
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+        
+        // do some tests when parameter users don't exist
+        sendCommand("setalias testNonExist1 testNonExist2");
+        assertTrue(getLastLine(readAnswer()).equals("No such user testNonExist1"));
+
+        sendCommand("adduser testAlias1 test");
+        assertTrue(getLastLine(readAnswer()).endsWith(" added"));
+
+        sendCommand("showalias testAlias1");
+        assertTrue(getLastLine(readAnswer()).equals("User testAlias1 does not currently have an alias"));
+
+        sendCommand("setalias testAlias1 testNonExist2");
+        assertTrue(getLastLine(readAnswer()).equals("Alias unknown to server - create that user first."));
+
+        sendCommand("setalias testNonExist1 testAlias");
+        assertTrue(getLastLine(readAnswer()).equals("No such user testNonExist1"));
+
+        sendCommand("adduser testAlias2 test");
+        assertTrue(getLastLine(readAnswer()).endsWith(" added"));
+
+        // regular alias
+        sendCommand("setalias testAlias1 testAlias2");
+        assertTrue(getLastLine(readAnswer()).equals("Alias for testAlias1 set to:testAlias2"));
+
+        //TODO: is this correct? even primitive circular aliasing allowed!
+        sendCommand("setalias testAlias2 testAlias1");
+        assertTrue(getLastLine(readAnswer()).equals("Alias for testAlias2 set to:testAlias1"));
+
+        // did first one persist?
+        sendCommand("showalias testAlias1");
+        assertTrue(getLastLine(readAnswer()).equals("Current alias for testAlias1 is: testAlias2"));
+
+        //TODO: is this correct? setting self as alias!
+        sendCommand("setalias testAlias1 testAlias1");
+        assertTrue(getLastLine(readAnswer()).equals("Alias for testAlias1 set to:testAlias1"));
+
+        sendCommand("adduser testAlias3 test");
+        assertTrue(getLastLine(readAnswer()).endsWith(" added"));
+
+        // re-set, simply overwrites
+        sendCommand("setalias testAlias1 testAlias3");
+        assertTrue(getLastLine(readAnswer()).equals("Alias for testAlias1 set to:testAlias3"));
+
+        // check overwrite
+        sendCommand("showalias testAlias1");
+        assertTrue(getLastLine(readAnswer()).equals("Current alias for testAlias1 is: testAlias3"));
+
+        // retreat
+        sendCommand("unsetalias testAlias1");
+        assertTrue(getLastLine(readAnswer()).equals("Alias for testAlias1 unset"));
+
+        // check removed alias
+        sendCommand("showalias testAlias1");
+        assertTrue(getLastLine(readAnswer()).equals("User testAlias1 does not currently have an alias"));
+
+    }
+
+    public void testForward() throws IOException {
+        m_mockUsersRepository.setForceUseJamesUser();
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        // do some tests when parameter users don't exist
+        sendCommand("setforwarding testNonExist1 testForward1@locahost");
+        assertTrue(getLastLine(readAnswer()).equals("No such user testNonExist1"));
+        
+        sendCommand("adduser testForwardUser test");
+        assertTrue(getLastLine(readAnswer()).endsWith(" added"));
+
+        sendCommand("showforwarding testForwardUser");
+        assertTrue(getLastLine(readAnswer()).equals("User testForwardUser is not currently being forwarded"));
+
+        sendCommand("setforwarding testForwardUser testForward1@locahost");
+        assertTrue(getLastLine(readAnswer()).equals("Forwarding destination for testForwardUser set to:testForward1@locahost"));
+        
+        // did it persist?
+        sendCommand("showforwarding testForwardUser");
+        assertTrue(getLastLine(readAnswer()).equals("Current forwarding destination for testForwardUser is: testForward1@locahost"));
+
+        // re-set, simply overwrites
+        sendCommand("setforwarding testForwardUser testForward2@locahost");
+        assertTrue(getLastLine(readAnswer()).equals("Forwarding destination for testForwardUser set to:testForward2@locahost"));
+
+        // check overwrite
+        sendCommand("showforwarding testForwardUser");
+        assertTrue(getLastLine(readAnswer()).equals("Current forwarding destination for testForwardUser is: testForward2@locahost"));
+
+        // retreat
+        sendCommand("unsetforwarding testForwardUser");
+        assertTrue(getLastLine(readAnswer()).equals("Forward for testForwardUser unset"));
+
+        // check removed forward
+        sendCommand("showforwarding testForwardUser");
+        assertTrue(getLastLine(readAnswer()).equals("User testForwardUser is not currently being forwarded"));
+
+    }
+
+    public void testSetPassword() throws IOException {
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("adduser testPwdUser pwd1");
+        assertTrue(getLastLine(readAnswer()).endsWith(" added"));
+
+        assertTrue("initial password", m_mockUsersRepository.test("testPwdUser", "pwd1"));
+        
+         sendCommand("setpassword testPwdUser     ");
+        assertTrue("password changed to empty", m_mockUsersRepository.test("testPwdUser", "pwd1"));
+        readAnswer(); // ignore
+
+        // change pwd
+        sendCommand("setpassword testPwdUser pwd2");
+        assertTrue("password not changed to pwd2", m_mockUsersRepository.test("testPwdUser", "pwd2"));
+        readAnswer(); // ignore
+        
+        // assure case sensitivity
+        sendCommand("setpassword testPwdUser pWD2");
+        assertFalse("password not changed to pWD2", m_mockUsersRepository.test("testPwdUser", "pwd2"));
+        assertTrue("password not changed to pWD2", m_mockUsersRepository.test("testPwdUser", "pWD2"));
+        readAnswer(); // ignore
+        
+    }
+}

Propchange: james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



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


Re: svn commit: r405795 [2/5] - in /james/server/trunk: ./ src/test/org/apache/james/ src/test/org/apache/james/core/ src/test/org/apache/james/mailrepository/ src/test/org/apache/james/pop3server/ src/test/org/apache/james/remotemanager/ src/test/org/apac...

Posted by Stefano Bagnara <ap...@bago.org>.
Bernd Fondermann wrote:
> Hi Stefano,
> 
> JDBCMailRepositoryTest is not quite finished, isn't it? At least, it 
> fails for my local copy ;-)

Ops JDBCMailRepository is a mistake. I should not have committed it.
Thank you for pointing this out!

Stefano


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


Re: svn commit: r405795 [2/5] - in /james/server/trunk: ./ src/test/org/apache/james/ src/test/org/apache/james/core/ src/test/org/apache/james/mailrepository/ src/test/org/apache/james/pop3server/ src/test/org/apache/james/remotemanager/ src/test/org/apac...

Posted by Bernd Fondermann <bf...@brainlounge.de>.
Hi Stefano,

JDBCMailRepositoryTest is not quite finished, isn't it? At least, it 
fails for my local copy ;-)

   Bernd

bago@apache.org wrote:
> Added: james/server/trunk/src/test/org/apache/james/mailrepository/JDBCMailRepositoryTest.java
> URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/mailrepository/JDBCMailRepositoryTest.java?rev=405795&view=auto
> ==============================================================================
> --- james/server/trunk/src/test/org/apache/james/mailrepository/JDBCMailRepositoryTest.java (added)
> +++ james/server/trunk/src/test/org/apache/james/mailrepository/JDBCMailRepositoryTest.java Wed May 10 09:46:54 2006
> @@ -0,0 +1,304 @@
> +package org.apache.james.mailrepository;
> +
> +import org.apache.avalon.cornerstone.blocks.datasources.DefaultDataSourceSelector;
> +import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
> +import org.apache.avalon.cornerstone.services.store.Store;
> +import org.apache.avalon.framework.configuration.DefaultConfiguration;
> +import org.apache.avalon.framework.context.ContextException;
> +import org.apache.james.context.AvalonContextConstants;
> +import org.apache.james.core.MailImpl;
> +import org.apache.james.mailrepository.filepair.File_Persistent_Stream_Repository;
> +import org.apache.james.remotemanager.RemoteManagerTestConfiguration;
> +import org.apache.james.test.mock.avalon.MockContext;
> +import org.apache.james.test.mock.avalon.MockLogger;
> +import org.apache.james.test.mock.avalon.MockServiceManager;
> +import org.apache.james.test.mock.avalon.MockStore;
> +import org.apache.james.util.io.IOUtil;
> +import org.apache.mailet.Mail;
> +import org.apache.mailet.MailAddress;
> +
> +import javax.mail.Session;
> +import javax.mail.internet.MimeMessage;
> +import javax.mail.util.SharedFileInputStream;
> +
> +import java.io.File;
> +import java.io.FileOutputStream;
> +//import java.lang.management.ManagementFactory;
> +//import java.lang.management.MemoryMXBean;
> +//import java.lang.management.MemoryUsage;
> +import java.util.Arrays;
> +import java.util.Properties;
> +
> +import junit.framework.TestCase;
> +
> +/**
> + * test for the JDBCMailRepository
> + */
> +public class JDBCMailRepositoryTest extends TestCase {
> +
> +    protected JDBCMailRepository mailRepository;
> +    protected JDBCMailRepository mailRepository2;
[snipped]

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