KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.UnsupportedEncodingException JavaDoc;
32
33 public class SetMailAttributeTest extends TestCase {
34
35     private Mail mockedMail;
36
37     private Mailet mailet;
38
39     private final String JavaDoc ATTRIBUTE_NAME1 = "org.apache.james.junit1";
40
41     private final String JavaDoc ATTRIBUTE_NAME2 = "org.apache.james.junit2";
42
43     public SetMailAttributeTest(String JavaDoc arg0)
44             throws UnsupportedEncodingException JavaDoc {
45         super(arg0);
46     }
47
48     private void setupMailet() throws MessagingException JavaDoc {
49         mailet = new SetMailAttribute();
50         MockMailetConfig mci = new MockMailetConfig("Test",
51                 new MockMailContext());
52         mci.setProperty(ATTRIBUTE_NAME1, "true");
53         mci.setProperty(ATTRIBUTE_NAME2, "true");
54
55         mailet.init(mci);
56     }
57
58     // test if the Header was add
59
public void testMailAttributeAdded() throws MessagingException JavaDoc {
60         mockedMail = Util.createMockMail2Recipients(null);
61         setupMailet();
62
63         assertNull(mockedMail.getAttribute(ATTRIBUTE_NAME1));
64         assertNull(mockedMail.getAttribute(ATTRIBUTE_NAME2));
65         mailet.service(mockedMail);
66
67         assertEquals("true", mockedMail.getAttribute(ATTRIBUTE_NAME1));
68         assertEquals("true", mockedMail.getAttribute(ATTRIBUTE_NAME2));
69     }
70 }
71
Popular Tags