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 javax.mail.MessagingException;
23 import javax.mail.internet.MimeMultipart;
24
25 import junit.framework.TestCase;
26
27 import org.apache.jsieve.commands.ThrowTestException;
28 import org.apache.jsieve.exception.SieveException;
29 import org.apache.jsieve.parser.generated.ParseException;
30 import org.apache.jsieve.utils.JUnitUtils;
31 import org.apache.jsieve.utils.SieveMailAdapter;
32
33
34
35
36 public class BodyTest extends TestCase {
37
38 protected SieveMailAdapter textMail() throws MessagingException {
39 SieveMailAdapter mail = (SieveMailAdapter) JUnitUtils.createMail();
40 mail.getMessage().setContent("Wibble\n\n" + "Wibble\n", "text/plain");
41 return mail;
42 }
43
44 protected SieveMailAdapter nonTextMail() throws MessagingException,
45 SieveException {
46 SieveMailAdapter mail = (SieveMailAdapter) JUnitUtils.createMail();
47
48 mail.getMessage().setContent(new MimeMultipart("image/png"));
49 return mail;
50 }
51
52
53
54
55 public void testBasic() {
56 boolean isTestPassed = false;
57 String script = "if body :contains [\"Wibble\"] {throwTestException;}";
58 try {
59 JUnitUtils.interpret(textMail(), script);
60 } catch (MessagingException e) {
61 } catch (ThrowTestException.TestException e) {
62 isTestPassed = true;
63 } catch (ParseException e) {
64 } catch (SieveException e) {
65 }
66 assertTrue(isTestPassed);
67 }
68
69
70
71
72 public void testBodyCaseInsensitivity() {
73 boolean isTestPassed = false;
74 String script = "if body :contains [\"wibble\"] {throwTestException;}";
75 try {
76 JUnitUtils.interpret(textMail(), script);
77 } catch (MessagingException e) {
78 } catch (ThrowTestException.TestException e) {
79 isTestPassed = true;
80 } catch (ParseException e) {
81 } catch (SieveException e) {
82 }
83 assertTrue(isTestPassed);
84 }
85
86
87
88
89 public void testBodyNoContains() {
90 boolean isTestPassed = false;
91 String script = "if body [\"wibble\"] {throwTestException;}";
92 try {
93 JUnitUtils.interpret(textMail(), script);
94 } catch (MessagingException e) {
95 } catch (ThrowTestException.TestException e) {
96 } catch (ParseException e) {
97 } catch (SieveException e) {
98 isTestPassed = true;
99 }
100 assertTrue(isTestPassed);
101 }
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 }