KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > transport > mailets > RemoveAllMailAttributesTest


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.mailets;
22
23 import junit.framework.TestCase;
24 import org.apache.james.test.mock.mailet.MockMailContext;
25 import org.apache.james.test.mock.mailet.MockMailetConfig;
26 import org.apache.james.test.util.Util;
27 import org.apache.mailet.Mail;
28 import org.apache.mailet.Mailet;
29
30 import javax.mail.MessagingException JavaDoc;
31 import javax.mail.internet.MimeMessage JavaDoc;
32 import javax.mail.internet.ParseException JavaDoc;
33 import java.io.UnsupportedEncodingException JavaDoc;
34
35 public class RemoveAllMailAttributesTest extends TestCase {
36
37     private Mail mockedMail;
38
39     private Mailet mailet;
40
41     public RemoveAllMailAttributesTest(String JavaDoc arg0)
42             throws UnsupportedEncodingException JavaDoc {
43         super(arg0);
44     }
45
46     private void setupMockedMail(MimeMessage JavaDoc m) throws ParseException JavaDoc {
47         mockedMail = Util.createMockMail2Recipients(m);
48         mockedMail.setAttribute("org.apache.james.test.junit", "true");
49
50     }
51
52     private void setupMailet() throws MessagingException JavaDoc {
53         mailet = new RemoveAllMailAttributes();
54         MockMailetConfig mci = new MockMailetConfig("Test",
55                 new MockMailContext());
56         mailet.init(mci);
57     }
58
59     // test if ToProcessor works
60
public void testRemoveAllMailAttributes() throws MessagingException JavaDoc {
61         setupMockedMail(null);
62         setupMailet();
63
64         // check if the mail has a attribute
65
assertTrue(mockedMail.getAttributeNames().hasNext());
66
67         mailet.service(mockedMail);
68
69         // check if all was removed
70
assertFalse(mockedMail.getAttributeNames().hasNext());
71     }
72
73 }
74
Popular Tags