KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > transport > matchers > AbstractSenderIsTest


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.transport.matchers;
22
23 import java.io.Serializable JavaDoc;
24 import java.io.UnsupportedEncodingException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.Date JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import javax.mail.MessagingException JavaDoc;
31 import javax.mail.internet.MimeMessage JavaDoc;
32 import javax.mail.internet.ParseException JavaDoc;
33
34 import junit.framework.TestCase;
35
36 import org.apache.james.test.mock.mailet.MockMailContext;
37 import org.apache.james.test.mock.mailet.MockMatcherConfig;
38 import org.apache.mailet.Mail;
39 import org.apache.mailet.MailAddress;
40 import org.apache.mailet.Matcher;
41
42 public abstract class AbstractSenderIsTest extends TestCase {
43
44     protected Mail mockedMail;
45
46     protected Matcher matcher;
47
48     private MailAddress sender;
49
50     public AbstractSenderIsTest(String JavaDoc arg0)
51             throws UnsupportedEncodingException JavaDoc {
52         super(arg0);
53     }
54
55     protected void setSender(MailAddress sender) {
56         this.sender = sender;
57     }
58
59     protected void setupMockedMail() {
60         mockedMail = new Mail() {
61
62             private static final long serialVersionUID = 1L;
63
64             public String JavaDoc getName() {
65                 throw new UnsupportedOperationException JavaDoc(
66                         "Unimplemented mock service");
67             }
68
69             public void setName(String JavaDoc newName) {
70                 throw new UnsupportedOperationException JavaDoc(
71                         "Unimplemented mock service");
72             }
73
74             public MimeMessage JavaDoc getMessage() throws MessagingException JavaDoc {
75                 throw new UnsupportedOperationException JavaDoc(
76                         "Unimplemented mock service");
77             }
78
79             public Collection JavaDoc getRecipients() {
80                 ArrayList JavaDoc r = new ArrayList JavaDoc();
81                 try {
82                     r.add(new MailAddress("test@localhost"));
83                 } catch (ParseException JavaDoc e) {
84                 }
85                 return r;
86             }
87
88             public void setRecipients(Collection JavaDoc recipients) {
89                 throw new UnsupportedOperationException JavaDoc(
90                         "Unimplemented mock service");
91             }
92
93             public MailAddress getSender() {
94                 return sender;
95             }
96
97             public String JavaDoc getState() {
98                 throw new UnsupportedOperationException JavaDoc(
99                         "Unimplemented mock service");
100             }
101
102             public String JavaDoc getRemoteHost() {
103                 throw new UnsupportedOperationException JavaDoc(
104                         "Unimplemented mock service");
105             }
106
107             public String JavaDoc getRemoteAddr() {
108                 throw new UnsupportedOperationException JavaDoc(
109                         "Unimplemented mock service");
110             }
111
112             public String JavaDoc getErrorMessage() {
113                 throw new UnsupportedOperationException JavaDoc(
114                         "Unimplemented mock service");
115             }
116
117             public void setErrorMessage(String JavaDoc msg) {
118                 throw new UnsupportedOperationException JavaDoc(
119                         "Unimplemented mock service");
120             }
121
122             public void setMessage(MimeMessage JavaDoc message) {
123                 throw new UnsupportedOperationException JavaDoc(
124                         "Unimplemented mock service");
125             }
126
127             public void setState(String JavaDoc state) {
128                 throw new UnsupportedOperationException JavaDoc(
129                         "Unimplemented mock service");
130             }
131
132             public Serializable JavaDoc getAttribute(String JavaDoc name) {
133                 throw new UnsupportedOperationException JavaDoc(
134                         "Unimplemented mock service");
135             }
136
137             public Iterator JavaDoc getAttributeNames() {
138                 throw new UnsupportedOperationException JavaDoc(
139                         "Unimplemented mock service");
140             }
141
142             public boolean hasAttributes() {
143                 throw new UnsupportedOperationException JavaDoc(
144                         "Unimplemented mock service");
145             }
146
147             public Serializable JavaDoc removeAttribute(String JavaDoc name) {
148                 throw new UnsupportedOperationException JavaDoc(
149                         "Unimplemented mock service");
150             }
151
152             public void removeAllAttributes() {
153                 throw new UnsupportedOperationException JavaDoc(
154                         "Unimplemented mock service");
155             }
156
157             public Serializable JavaDoc setAttribute(String JavaDoc name, Serializable JavaDoc object) {
158                 throw new UnsupportedOperationException JavaDoc(
159                         "Unimplemented mock service");
160             }
161
162             public long getMessageSize() throws MessagingException JavaDoc {
163                 throw new UnsupportedOperationException JavaDoc(
164                         "Unimplemented mock service");
165             }
166
167             public Date JavaDoc getLastUpdated() {
168                 throw new UnsupportedOperationException JavaDoc(
169                         "Unimplemented mock service");
170             }
171
172             public void setLastUpdated(Date JavaDoc lastUpdated) {
173                 throw new UnsupportedOperationException JavaDoc(
174                         "Unimplemented mock service");
175             }
176
177         };
178
179     }
180
181     protected void setupMatcher() throws MessagingException JavaDoc {
182         matcher = createMatcher();
183         MockMatcherConfig mci = new MockMatcherConfig(getConfigOption()
184                 + getConfigValue(), new MockMailContext());
185         matcher.init(mci);
186     }
187
188     protected void setupAll() throws MessagingException JavaDoc {
189         setupMockedMail();
190         setupMatcher();
191     }
192
193     protected abstract String JavaDoc getConfigOption();
194
195     protected abstract String JavaDoc getConfigValue();
196
197     protected abstract Matcher createMatcher();
198 }
199
Popular Tags