001: /****************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one *
003: * or more contributor license agreements. See the NOTICE file *
004: * distributed with this work for additional information *
005: * regarding copyright ownership. The ASF licenses this file *
006: * to you under the Apache License, Version 2.0 (the *
007: * "License"); you may not use this file except in compliance *
008: * with the License. You may obtain a copy of the License at *
009: * *
010: * http://www.apache.org/licenses/LICENSE-2.0 *
011: * *
012: * Unless required by applicable law or agreed to in writing, *
013: * software distributed under the License is distributed on an *
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015: * KIND, either express or implied. See the License for the *
016: * specific language governing permissions and limitations *
017: * under the License. *
018: ****************************************************************/package org.apache.james.services;
019:
020: import junit.framework.TestCase;
021:
022: /**
023: * tests all implementations for interface MailServer
024: */
025: abstract public class MailServerTestAllImplementations extends TestCase {
026:
027: protected static final String EXISTING_USER_NAME = "testExistingUserName";
028:
029: abstract public MailServer createMailServer();
030:
031: abstract public boolean allowsPasswordlessUser();
032:
033: /**
034: * while addUser() is part of MailServer interface, a user cannot be tested for afterwards
035: * at the same time, James allows to do exactly this via isLocalUser(), other implementations
036: * might vary.
037: */
038: abstract public boolean canTestUserExists();
039:
040: abstract public boolean isUserExisting(MailServer mailServerImpl,
041: String username);
042:
043: public void testId() {
044: MailServer mailServer = createMailServer();
045:
046: String id = mailServer.getId();
047: assertNotNull("mail id not null", id);
048: assertFalse("mail id not empty", "".equals(id));
049: }
050:
051: public void testIdIncrement() {
052: MailServer mailServer = createMailServer();
053:
054: String id1 = mailServer.getId();
055: String id2 = mailServer.getId();
056: assertFalse("next id is different", id1.equals(id2));
057: }
058:
059: public void testAddUser() {
060:
061: // addUser acts on field localUsers for class org.apache.james.James
062: // thus, it is unrelated to getUserInbox() for the only known implementation of MailServer
063: // TODO clarify this
064:
065: MailServer mailServer = createMailServer();
066:
067: String userName = "testUserName";
068:
069: if (canTestUserExists()) {
070: assertFalse("this is a fresh user", isUserExisting(
071: mailServer, userName));
072: }
073:
074: boolean allowsPasswordlessUser = allowsPasswordlessUser();
075: try {
076: boolean success = mailServer.addUser(userName, null);
077: if (!allowsPasswordlessUser)
078: fail("null pwd was accepted unexpectedly");
079: if (!success)
080: fail("null pwd was not accepted unexpectedly");
081: } catch (Exception e) {
082: if (allowsPasswordlessUser)
083: fail("null pwd not accepted unexpectedly (with exception)");
084: }
085:
086: userName = userName + "_next";
087: String password = "password";
088:
089: boolean success = mailServer.addUser(userName, password);
090: if (!success)
091: fail("user has not been added");
092:
093: if (canTestUserExists()) {
094: assertTrue("user is present now", isUserExisting(
095: mailServer, userName));
096: }
097:
098: boolean successAgain = mailServer.addUser(userName, password);
099: if (successAgain)
100: fail("user has been added two times");
101:
102: }
103:
104: public void testGetNonexistingUserInbox() {
105:
106: MailServer mailServer = createMailServer();
107:
108: String userName = "testNonexisitingUserName";
109: MailRepository userInbox = null;
110:
111: userInbox = mailServer.getUserInbox(userName);
112: assertEquals("test user does not exist", null, userInbox);
113: }
114:
115: public void testGetExisitingUserInbox() {
116: MailServer mailServer = createMailServer();
117:
118: MailRepository userInbox = mailServer
119: .getUserInbox(EXISTING_USER_NAME);
120: assertNotNull("existing user exists", userInbox);
121: }
122: }
|