FileDocCategorySizeDatePackage
POP3ClientTest.javaAPI DocApache Commons NET 1.4.1 API4748Sat Dec 03 10:05:48 GMT 2005org.apache.commons.net.pop3

POP3ClientTest

public class POP3ClientTest extends junit.framework.TestCase
author
[Net]
version
$Id: POP3ClientTest.java 165675 2005-05-02 20:09:55Z rwinston $ The POP3* tests all presume the existence of the following parameters: mailserver: localhost (running on the default port 110) account: username=test; password=password account: username=alwaysempty; password=password. mail: At least four emails in the test account and zero emails in the alwaysempty account If this won't work for you, you can change these parameters in the TestSetupParameters class. The tests were originally run on a default installation of James. Your mileage may vary based on the POP3 server you run the tests against. Some servers are more standards-compliant than others.

Fields Summary
POP3Client
p
String
user
String
emptyUser
String
password
String
mailhost
Constructors Summary
public POP3ClientTest(String name)


         
      
    
        super(name);
    
Methods Summary
private voidconnect()

        p.connect(InetAddress.getByName(mailhost));
        assertTrue(p.isConnected());
        assertEquals(POP3.AUTHORIZATION_STATE, p.getState());
    
private voidlogin()

        assertTrue(p.login(user, password));
        assertEquals(POP3.TRANSACTION_STATE, p.getState());
    
private voidreset()

        //Case where this is the first time reset is called
        if (p == null)
        {
            //Do nothing
        }
        else if (p.isConnected())
        {
            p.disconnect();
        }
        p = null;
        p = new POP3Client();
    
public static junit.framework.TestSuitesuite()
Method suite.

return
TestSuite

        return (new TestSuite(POP3ClientTest.class));
    
public voidtestInvalidLoginWithBadName()

        reset();
        connect();

        //Try with an invalid user that doesn't exist
        assertFalse(p.login("badusername", password));
    
public voidtestInvalidLoginWithBadPassword()

        reset();
        connect();

        //Try with a bad password
        assertFalse(p.login(user, "badpassword"));
    
public voidtestLoginFromWrongState()
Test to try to run the login method from the disconnected, transaction and update states

        reset();

        //Not currently connected, not in authorization state
        //Try to login with good name/password
        assertFalse(p.login(user, password));

        //Now connect and set the state to 'transaction' and try again
        connect();
        p.setState(POP3.TRANSACTION_STATE);
        assertFalse(p.login(user, password));
        p.disconnect();

        //Now connect and set the state to 'update' and try again
        connect();
        p.setState(POP3.UPDATE_STATE);
        assertFalse(p.login(user, password));
        p.disconnect();
    
public voidtestLogoutFromAllStates()

        //From 'transaction' state
        reset();
        connect();
        login();
        assertTrue(p.logout());
        assertEquals(POP3.UPDATE_STATE, p.getState());

        //From 'update' state
        reset();
        connect();
        login();
        p.setState(POP3.UPDATE_STATE);
        assertTrue(p.logout());
    
public voidtestValidLoginWithNameAndPassword()
Simple test to logon to a valid server using a valid user name and password.

        reset();
        connect();

        //Try with a valid user
        login();