KickJava   Java API By Example, From Geeks To Geeks.

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


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.mailet.MockMail;
25 import org.apache.james.test.mock.mailet.MockMailContext;
26 import org.apache.james.test.mock.mailet.MockMatcherConfig;
27 import org.apache.james.test.util.Util;
28 import org.apache.mailet.Matcher;
29 import org.apache.mailet.RFC2822Headers;
30
31 import javax.mail.MessagingException JavaDoc;
32 import javax.mail.internet.MimeMessage JavaDoc;
33 import java.io.UnsupportedEncodingException JavaDoc;
34 import java.util.Collection JavaDoc;
35
36 public class NESSpamCheckTest extends TestCase {
37
38     private MimeMessage JavaDoc mockedMimeMessage;
39
40     private MockMail mockedMail;
41
42     private Matcher matcher;
43
44     private String JavaDoc headerName = "defaultHeaderName";
45
46     private String JavaDoc headerValue = "defaultHeaderValue";
47
48     public NESSpamCheckTest(String JavaDoc arg0) throws UnsupportedEncodingException JavaDoc {
49         super(arg0);
50     }
51
52     private void setHeaderName(String JavaDoc headerName) {
53         this.headerName = headerName;
54     }
55
56     private void setHeaderValue(String JavaDoc headerValue) {
57         this.headerValue = headerValue;
58     }
59
60     private void setupMockedMimeMessage() throws MessagingException JavaDoc {
61         mockedMimeMessage = Util.createMimeMessage(headerName, headerValue);
62     }
63
64     private void setupMatcher() throws MessagingException JavaDoc {
65         setupMockedMimeMessage();
66         matcher = new NESSpamCheck();
67         MockMatcherConfig mci = new MockMatcherConfig("NESSpamCheck", new MockMailContext());
68         matcher.init(mci);
69     }
70
71     public void testNESSpamCheckMatched() throws MessagingException JavaDoc {
72         setHeaderName(RFC2822Headers.RECEIVED);
73         setHeaderValue("xxxxxxxxxxxxxxxxxxxxx");
74
75         setupMockedMimeMessage();
76         mockedMail = Util.createMockMail2Recipients(mockedMimeMessage);
77         setupMatcher();
78
79         Collection JavaDoc matchedRecipients = matcher.match(mockedMail);
80
81         assertNotNull(matchedRecipients);
82         assertEquals(matchedRecipients.size(), mockedMail.getRecipients().size());
83     }
84
85     public void testNESSpamCheckNotMatched() throws MessagingException JavaDoc {
86         setupMockedMimeMessage();
87         mockedMail = Util.createMockMail2Recipients(mockedMimeMessage);
88         setupMatcher();
89
90         Collection JavaDoc matchedRecipients = matcher.match(mockedMail);
91
92         assertNull(matchedRecipients);
93     }
94 }
95
Popular Tags