MailServerTestAllImplementations.javaAPI DocApache James 2.3.14509Fri Jan 12 12:56:36 GMT


public abstract class MailServerTestAllImplementations extends junit.framework.TestCase
tests all implementations for interface MailServer

Fields Summary
protected static final String
Constructors Summary
Methods Summary
public abstract booleanallowsPasswordlessUser()

public abstract booleancanTestUserExists()
while addUser() is part of MailServer interface, a user cannot be tested for afterwards at the same time, James allows to do exactly this via isLocalUser(), other implementations might vary.

public abstract MailServercreateMailServer()

public abstract booleanisUserExisting(MailServer mailServerImpl, java.lang.String username)

public voidtestAddUser()

        // addUser acts on field localUsers for class org.apache.james.James 
        // thus, it is unrelated to getUserInbox() for the only known implementation of MailServer
        // TODO clarify this 
        MailServer mailServer = createMailServer();

        String userName = "testUserName";

        if (canTestUserExists())
            assertFalse("this is a fresh user", isUserExisting(mailServer, userName));
        boolean allowsPasswordlessUser = allowsPasswordlessUser();
        try {
            boolean success = mailServer.addUser(userName, null);
            if (!allowsPasswordlessUser) fail("null pwd was accepted unexpectedly");
            if (!success) fail("null pwd was not accepted unexpectedly"); 
        } catch (Exception e) {
            if (allowsPasswordlessUser) fail("null pwd not accepted unexpectedly (with exception)");

        userName = userName + "_next"; 
        String password = "password";
        boolean success = mailServer.addUser(userName, password);
        if (!success) fail("user has not been added"); 
        if (canTestUserExists())
            assertTrue("user is present now", isUserExisting(mailServer, userName));
        boolean successAgain = mailServer.addUser(userName, password);
        if (successAgain) fail("user has been added two times"); 
public voidtestGetExisitingUserInbox()

        MailServer mailServer = createMailServer();

        MailRepository userInbox = mailServer.getUserInbox(EXISTING_USER_NAME);
        assertNotNull("existing user exists", userInbox);
public voidtestGetNonexistingUserInbox()

        MailServer mailServer = createMailServer();

        String userName = "testNonexisitingUserName";
        MailRepository userInbox = null;
        userInbox = mailServer.getUserInbox(userName);
        assertEquals("test user does not exist", null, userInbox);
public voidtestId()


        MailServer mailServer = createMailServer();
        String id = mailServer.getId();
        assertNotNull("mail id not null", id);
        assertFalse("mail id not empty", "".equals(id));
public voidtestIdIncrement()

        MailServer mailServer = createMailServer();
        String id1 = mailServer.getId();
        String id2 = mailServer.getId();
        assertFalse("next id is different", id1.equals(id2));