KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > test > mock > mailet > MockMail


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
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  ****************************************************************/

19
20
21 package org.apache.james.test.mock.mailet;
22
23 import java.io.Serializable JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.Date JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import javax.mail.MessagingException JavaDoc;
31 import javax.mail.internet.MimeMessage JavaDoc;
32
33 import org.apache.mailet.Mail;
34 import org.apache.mailet.MailAddress;
35
36 public class MockMail implements Mail {
37
38     private MimeMessage JavaDoc msg = null;
39
40     private Collection JavaDoc recipients = new ArrayList JavaDoc();
41
42     private String JavaDoc name = null;
43
44     private MailAddress sender = null;
45
46     private String JavaDoc state = null;
47
48     private String JavaDoc errorMessage;
49
50     private Date JavaDoc lastUpdated;
51
52     private HashMap JavaDoc attributes = new HashMap JavaDoc();
53
54     private static final long serialVersionUID = 1L;
55
56     private long size = 0;
57     
58     private String JavaDoc remoteAddr ="127.0.0.1";
59     
60     public String JavaDoc getName() {
61         return name;
62     }
63
64     public void setName(String JavaDoc newName) {
65         this.name = newName;
66     }
67
68     public MimeMessage JavaDoc getMessage() throws MessagingException JavaDoc {
69         return msg;
70     }
71
72     public Collection JavaDoc getRecipients() {
73         return recipients;
74     }
75
76     public void setRecipients(Collection JavaDoc recipients) {
77         this.recipients = recipients;
78     }
79
80     public MailAddress getSender() {
81         return sender;
82     }
83
84     public String JavaDoc getState() {
85         return state;
86     }
87
88     public String JavaDoc getRemoteHost() {
89         return "111.222.333.444";
90     }
91
92     public String JavaDoc getRemoteAddr() {
93         return remoteAddr;
94     }
95
96     public String JavaDoc getErrorMessage() {
97         return errorMessage;
98     }
99
100     public void setErrorMessage(String JavaDoc msg) {
101         this.errorMessage = msg;
102     }
103
104     public void setMessage(MimeMessage JavaDoc message) {
105         this.msg = message;
106     }
107
108     public void setState(String JavaDoc state) {
109         this.state = state;
110     }
111
112     public Serializable JavaDoc getAttribute(String JavaDoc name) {
113         return (Serializable JavaDoc) attributes.get(name);
114     }
115
116     public Iterator JavaDoc getAttributeNames() {
117         return attributes.keySet().iterator();
118     }
119
120     public boolean hasAttributes() {
121         return !attributes.isEmpty();
122     }
123
124     public Serializable JavaDoc removeAttribute(String JavaDoc name) {
125         return (Serializable JavaDoc) attributes.remove(name);
126
127     }
128
129     public void removeAllAttributes() {
130         attributes.clear();
131     }
132
133     public Serializable JavaDoc setAttribute(String JavaDoc name, Serializable JavaDoc object) {
134
135         return (Serializable JavaDoc) attributes.put(name, object);
136     }
137
138     public long getMessageSize() throws MessagingException JavaDoc {
139         return size;
140     }
141
142     public Date JavaDoc getLastUpdated() {
143         return lastUpdated;
144     }
145
146     public void setLastUpdated(Date JavaDoc lastUpdated) {
147         this.lastUpdated = lastUpdated;
148     }
149     
150     public void setMessageSize(long size) {
151         this.size = size;
152     }
153
154     public void setRemoteAddr(String JavaDoc remoteAddr) {
155         this.remoteAddr = remoteAddr;
156     }
157 }
158
Popular Tags