KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.TestCase;
24 import org.apache.james.test.mock.javaxmail.MockMimeMessage;
25 import org.apache.james.test.mock.mailet.MockMail;
26 import org.apache.james.test.mock.mailet.MockMailContext;
27 import org.apache.james.test.mock.mailet.MockMatcherConfig;
28 import org.apache.james.test.util.Util;
29 import org.apache.mailet.Matcher;
30
31 import javax.mail.MessagingException JavaDoc;
32 import javax.mail.internet.MimeMessage JavaDoc;
33 import java.io.UnsupportedEncodingException JavaDoc;
34
35 public abstract class AbstractSubjectIsTest extends TestCase {
36
37     protected MockMail mockedMail;
38
39     protected Matcher matcher;
40
41     private String JavaDoc subject = null;
42
43     private MockMimeMessage mockedMimeMessage;
44
45     public AbstractSubjectIsTest(String JavaDoc arg0)
46             throws UnsupportedEncodingException JavaDoc {
47         super(arg0);
48     }
49
50     protected void setSubject(String JavaDoc subject) {
51         this.subject = subject;
52     }
53
54     protected void setupMockedMail(MimeMessage m) {
55         mockedMail = new MockMail();
56         mockedMail.setMessage(m);
57
58     }
59
60     protected void setupMockedMimeMessage() throws MessagingException JavaDoc {
61         mockedMimeMessage = Util.createMimeMessage("test", "test");
62         mockedMimeMessage.setSubject(subject);
63     }
64
65     protected void setupMatcher() throws MessagingException JavaDoc {
66         matcher = createMatcher();
67         MockMatcherConfig mci = new MockMatcherConfig(getConfigOption()
68                 + getSubjectName(), new MockMailContext());
69         matcher.init(mci);
70     }
71
72     protected void setupAll() throws MessagingException JavaDoc {
73         setupMockedMimeMessage();
74         setupMockedMail(mockedMimeMessage);
75         setupMatcher();
76     }
77
78     protected abstract String JavaDoc getConfigOption();
79
80     protected abstract String JavaDoc getSubjectName();
81
82     protected abstract Matcher createMatcher();
83 }
84
Popular Tags