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.mailet.base.test.FakeMailContext;
25 import org.apache.mailet.base.test.FakeMailetConfig;
26 import org.apache.mailet.base.test.MailUtil;
27 import org.apache.mailet.Mail;
28 import org.apache.mailet.Mailet;
29
30 import javax.mail.MessagingException;
31 import javax.mail.internet.MimeMessage;
32 import javax.mail.internet.ParseException;
33 import java.io.UnsupportedEncodingException;
34
35 public class RemoveAllMailAttributesTest extends TestCase {
36
37 private Mail mockedMail;
38
39 private Mailet mailet;
40
41 public RemoveAllMailAttributesTest(String arg0)
42 throws UnsupportedEncodingException {
43 super(arg0);
44 }
45
46 private void setupMockedMail(MimeMessage m) throws ParseException {
47 mockedMail = MailUtil.createMockMail2Recipients(m);
48 mockedMail.setAttribute("org.apache.james.test.junit", "true");
49
50 }
51
52 private void setupMailet() throws MessagingException {
53 mailet = new RemoveAllMailAttributes();
54 FakeMailetConfig mci = new FakeMailetConfig("Test",
55 new FakeMailContext());
56 mailet.init(mci);
57 }
58
59 // test if ToProcessor works
60 public void testRemoveAllMailAttributes() throws MessagingException {
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 }