1 19 20 21 22 package org.apache.james.services; 23 24 import org.apache.avalon.framework.service.ServiceException; 25 26 import junit.framework.TestCase; 27 28 31 abstract public class MailServerTestAllImplementations extends TestCase { 32 33 protected static final String EXISTING_USER_NAME = "testExistingUserName"; 34 35 abstract public MailServer createMailServer() throws ServiceException; 36 abstract public boolean allowsPasswordlessUser(); 37 38 43 abstract public boolean canTestUserExists(); 44 abstract public boolean isUserExisting(MailServer mailServerImpl, String username); 45 46 public void testId() throws ServiceException { 47 MailServer mailServer = createMailServer(); 48 49 String id = mailServer.getId(); 50 assertNotNull("mail id not null", id); 51 assertFalse("mail id not empty", "".equals(id)); 52 } 53 54 public void testIdIncrement() throws ServiceException { 55 MailServer mailServer = createMailServer(); 56 57 String id1 = mailServer.getId(); 58 String id2 = mailServer.getId(); 59 assertFalse("next id is different", id1.equals(id2)); 60 } 61 62 public void testAddUser() throws ServiceException { 63 64 68 MailServer mailServer = createMailServer(); 69 70 String userName = "testUserName"; 71 72 if (canTestUserExists()) 73 { 74 assertFalse("this is a fresh user", isUserExisting(mailServer, userName+"@localhost")); 75 } 76 77 boolean allowsPasswordlessUser = allowsPasswordlessUser(); 78 try { 79 boolean success = mailServer.addUser(userName, null); 80 if (!allowsPasswordlessUser) fail("null pwd was accepted unexpectedly"); 81 if (!success) fail("null pwd was not accepted unexpectedly"); 82 } catch (Exception e) { 83 if (allowsPasswordlessUser) fail("null pwd not accepted unexpectedly (with exception)"); 84 } 85 86 userName = userName + "_next"; 87 String password = "password"; 88 89 boolean success = mailServer.addUser(userName, password); 90 if (!success) fail("user has not been added"); 91 92 if (canTestUserExists()) 93 { 94 assertTrue("user is present now", isUserExisting(mailServer, userName)); 95 } 96 97 boolean successAgain = mailServer.addUser(userName, password); 98 if (successAgain) fail("user has been added two times"); 99 100 } 101 102 public void testGetNonexistingUserInbox() throws ServiceException { 103 104 MailServer mailServer = createMailServer(); 105 106 String userName = "testNonexisitingUserName"; 107 MailRepository userInbox = null; 108 109 userInbox = mailServer.getUserInbox(userName); 110 assertEquals("test user does not exist", null, userInbox); 111 } 112 113 public void testGetExisitingUserInbox() throws ServiceException { 114 MailServer mailServer = createMailServer(); 115 116 MailRepository userInbox = mailServer.getUserInbox(EXISTING_USER_NAME); 117 assertNotNull("existing user exists", userInbox); 118 } 119 } 120 | Popular Tags |