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.test.mock.mailet;
019:
020: import java.io.Serializable;
021: import java.util.ArrayList;
022: import java.util.Collection;
023: import java.util.Date;
024: import java.util.HashMap;
025: import java.util.Iterator;
026:
027: import javax.mail.MessagingException;
028: import javax.mail.internet.MimeMessage;
029:
030: import org.apache.mailet.Mail;
031: import org.apache.mailet.MailAddress;
032:
033: public class MockMail implements Mail {
034:
035: private MimeMessage msg = null;
036:
037: private Collection recipients = new ArrayList();
038:
039: private String name = null;
040:
041: private MailAddress sender = null;
042:
043: private String state = null;
044:
045: private String errorMessage;
046:
047: private Date lastUpdated;
048:
049: private HashMap attributes = new HashMap();
050:
051: private static final long serialVersionUID = 1L;
052:
053: public String getName() {
054: return name;
055: }
056:
057: public void setName(String newName) {
058: this .name = newName;
059: }
060:
061: public MimeMessage getMessage() throws MessagingException {
062: return msg;
063: }
064:
065: public Collection getRecipients() {
066: return recipients;
067: }
068:
069: public void setRecipients(Collection recipients) {
070: this .recipients = recipients;
071: }
072:
073: public MailAddress getSender() {
074: return sender;
075: }
076:
077: public String getState() {
078: return state;
079: }
080:
081: public String getRemoteHost() {
082: throw new UnsupportedOperationException(
083: "Unimplemented mock service");
084: }
085:
086: public String getRemoteAddr() {
087: throw new UnsupportedOperationException(
088: "Unimplemented mock service");
089: }
090:
091: public String getErrorMessage() {
092: return errorMessage;
093: }
094:
095: public void setErrorMessage(String msg) {
096: this .errorMessage = msg;
097: }
098:
099: public void setMessage(MimeMessage message) {
100: this .msg = message;
101: }
102:
103: public void setState(String state) {
104: this .state = state;
105: }
106:
107: public Serializable getAttribute(String name) {
108: return (Serializable) attributes.get(name);
109: }
110:
111: public Iterator getAttributeNames() {
112: return attributes.keySet().iterator();
113: }
114:
115: public boolean hasAttributes() {
116: return !attributes.isEmpty();
117: }
118:
119: public Serializable removeAttribute(String name) {
120: return (Serializable) attributes.remove(name);
121:
122: }
123:
124: public void removeAllAttributes() {
125: attributes.clear();
126: }
127:
128: public Serializable setAttribute(String name, Serializable object) {
129:
130: return (Serializable) attributes.put(name, object);
131: }
132:
133: public long getMessageSize() throws MessagingException {
134: throw new UnsupportedOperationException(
135: "Unimplemented mock service");
136: }
137:
138: public Date getLastUpdated() {
139: return lastUpdated;
140: }
141:
142: public void setLastUpdated(Date lastUpdated) {
143: this.lastUpdated = lastUpdated;
144: }
145:
146: }
|