1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.jsieve;
21
22 import junit.framework.TestCase;
23
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.jsieve.BaseSieveContext;
26 import org.apache.jsieve.ConfigurationManager;
27 import org.apache.jsieve.utils.JUnitUtils;
28 import org.apache.jsieve.utils.SieveMailAdapter;
29
30 public class AddressParseTest extends TestCase {
31
32 private static final String MULTIPLE_ADDRESS_VALUES = "coyote@desert.example.org, bugs@example.org, elmer@hunters.example.org";
33
34 private static final String SOLO_ADDRESS_VALUES = "coyote@desert.example.org";
35
36 BaseSieveContext context;
37
38 SieveMailAdapter mail;
39
40 OpenedAddress address;
41
42 protected void setUp() throws Exception {
43 super.setUp();
44 ConfigurationManager configurationManager = new ConfigurationManager();
45 context = new BaseSieveContext(
46 configurationManager.getCommandManager(), configurationManager
47 .getComparatorManager(), configurationManager
48 .getTestManager(), LogFactory
49 .getLog(AddressParseTest.class));
50 mail = (SieveMailAdapter) JUnitUtils.createMail();
51 address = new OpenedAddress();
52 }
53
54 public void testSingleAddress() throws Exception {
55 mail.getMessage().addHeader("From", SOLO_ADDRESS_VALUES);
56 assertTrue(address.match(mail, ":all", "i;ascii-casemap", ":is",
57 "from", "coyote@desert.example.org", context));
58 assertFalse(address.match(mail, ":all", "i;ascii-casemap", ":is",
59 "from", "elmer@hunters.example.org", context));
60 assertFalse(address.match(mail, ":all", "i;ascii-casemap", ":is",
61 "from", "bugs@example.org", context));
62 assertFalse(address.match(mail, ":all", "i;ascii-casemap", ":is",
63 "from", "roadrunner@example.org", context));
64 }
65
66 public void testMultipleAddresses() throws Exception {
67 mail.getMessage().addHeader("From", MULTIPLE_ADDRESS_VALUES);
68 assertTrue(address.match(mail, ":all", "i;ascii-casemap", ":is",
69 "from", "coyote@desert.example.org", context));
70 assertTrue(address.match(mail, ":all", "i;ascii-casemap", ":is",
71 "from", "elmer@hunters.example.org", context));
72 assertTrue(address.match(mail, ":all", "i;ascii-casemap", ":is",
73 "from", "bugs@example.org", context));
74 assertFalse(address.match(mail, ":all", "i;ascii-casemap", ":is",
75 "from", "roadrunner@example.org", context));
76 }
77 }