01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
10: * http://www.apache.org/licenses/LICENSE-2.0 *
11: * *
12: * Unless required by applicable law or agreed to in writing, *
13: * software distributed under the License is distributed on an *
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15: * KIND, either express or implied. See the License for the *
16: * specific language governing permissions and limitations *
17: * under the License. *
18: ****************************************************************/package org.apache.james.core;
19:
20: import junit.framework.TestCase;
21:
22: import javax.mail.MessagingException;
23:
24: import org.apache.mailet.Mail;
25:
26: /**
27: * testing common behavior of Mail implementors. subclasses automatically get their Mail-behavior tested.
28: */
29: public abstract class MailTestAllImplementations extends TestCase {
30:
31: /** provide the concrete implementation to test */
32: protected abstract Mail createMailImplementation();
33:
34: protected void helperTestInitialState(Mail mail)
35: throws MessagingException {
36: assertFalse("no initial attributes", mail.hasAttributes());
37: assertNull("no initial error", mail.getErrorMessage());
38: assertNotNull("initial last update set", mail.getLastUpdated());
39: try {
40: assertTrue("no initial recipient", mail.getRecipients()
41: .isEmpty());
42: } catch (NullPointerException e) {
43: // current behavior. *BUT*, shouldn't this method better return with an empty list?!
44: }
45: assertEquals("initial remote address is localhost ip",
46: "127.0.0.1", mail.getRemoteAddr());
47: assertEquals("initial remote host is localhost", "localhost",
48: mail.getRemoteHost());
49: assertEquals("default initial state", Mail.DEFAULT, mail
50: .getState());
51: }
52:
53: protected void helperTestMessageSize(Mail mail, int expectedMsgSize)
54: throws MessagingException {
55: try {
56: assertEquals("initial message size == " + expectedMsgSize,
57: expectedMsgSize, mail.getMessageSize());
58: } catch (NullPointerException e) {
59: // current behavior. *BUT*, shouldn't this method return more gracefully?!
60: }
61: }
62:
63: public void testAttributes() {
64: Mail mail = createMailImplementation();
65: assertFalse("no initial attributes", mail.hasAttributes());
66: assertFalse("attributes initially empty", mail
67: .getAttributeNames().hasNext());
68: assertNull("not found on emtpy list", mail.getAttribute("test"));
69: assertNull("no previous item with key", mail.setAttribute(
70: "testKey", "testValue"));
71: assertEquals("item found", "testValue", mail
72: .getAttribute("testKey"));
73: assertTrue("has attribute", mail.hasAttributes());
74: assertEquals("item removed", "testValue", mail
75: .removeAttribute("testKey"));
76: assertNull("item no longer found", mail.getAttribute("testKey"));
77: }
78:
79: }
|