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.core;
019:
020: import org.apache.james.test.mock.james.MockMailServer;
021: import org.apache.james.test.mock.javaxmail.MockMimeMessage;
022: import org.apache.mailet.MailAddress;
023: import org.apache.mailet.Mail;
024:
025: import javax.mail.MessagingException;
026: import java.util.ArrayList;
027:
028: public class MailImplTest extends MailTestAllImplementations {
029:
030: protected Mail createMailImplementation() {
031: return new MailImpl();
032: }
033:
034: public void testConstr1() throws MessagingException {
035: MailImpl mail = new MailImpl();
036:
037: helperTestInitialState(mail);
038: helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
039: assertNull("no initial message", mail.getMessage());
040: assertNull("no initial sender", mail.getSender());
041: assertNull("no initial name", mail.getName());
042: }
043:
044: public void testConstr2() throws MessagingException {
045: ArrayList recepients = new ArrayList();
046: String name = new MockMailServer().getId();
047: String sender = "sender@localhost";
048: MailAddress senderMailAddress = new MailAddress(sender);
049: MailImpl mail = new MailImpl(name, senderMailAddress,
050: recepients);
051:
052: helperTestInitialState(mail); // MimeMessageWrapper default is 0
053: helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
054: assertNull("no initial message", mail.getMessage());
055: assertEquals("sender", sender, mail.getSender().toString());
056: assertEquals("name", name, mail.getName());
057:
058: mail.setMessage(new MockMimeMessage());
059: assertNotNull("message", mail.getMessage());
060: }
061:
062: public void testConstr3() throws MessagingException {
063: ArrayList recepients = new ArrayList();
064: String name = new MockMailServer().getId();
065: String sender = "sender@localhost";
066: MailAddress senderMailAddress = new MailAddress(sender);
067: MockMimeMessage mimeMessage = new MockMimeMessage();
068: MailImpl mail = new MailImpl(name, senderMailAddress,
069: recepients, mimeMessage);
070:
071: helperTestInitialState(mail);
072: helperTestMessageSize(mail, 0);
073: assertEquals("initial message", mimeMessage.getMessageID(),
074: mail.getMessage().getMessageID());
075: assertEquals("sender", sender, mail.getSender().toString());
076: assertEquals("name", name, mail.getName());
077: mail.dispose();
078: }
079:
080: public void testDuplicate() throws MessagingException {
081: MailImpl mail = new MailImpl();
082: MailImpl duplicate = (MailImpl) mail.duplicate();
083: assertNotSame("is real duplicate", mail, duplicate);
084: helperTestInitialState(duplicate);
085: helperTestMessageSize(duplicate, 0);
086: }
087:
088: public void testDuplicateNewName() throws MessagingException {
089: String newName = "aNewName";
090:
091: MailImpl mail = new MailImpl();
092: assertFalse("before + after names differ", newName.equals(mail
093: .getName()));
094:
095: MailImpl duplicate = (MailImpl) mail.duplicate(newName);
096: assertEquals("new name set", newName, duplicate.getName());
097: helperTestInitialState(duplicate);
098: helperTestMessageSize(duplicate, 0);
099: }
100: }
|