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 package org.apache.jsieve;
21
22 import junit.framework.TestCase;
23
24 import org.apache.jsieve.exception.SieveException;
25 import org.apache.jsieve.exception.SyntaxException;
26 import org.apache.jsieve.mail.ActionKeep;
27 import org.apache.jsieve.mail.MailAdapter;
28 import org.apache.jsieve.parser.generated.ParseException;
29 import org.apache.jsieve.utils.JUnitUtils;
30
31 /**
32 * Class KeepTest
33 */
34 public class KeepTest extends TestCase {
35
36 /**
37 * Test for Command 'keep' with invalid arguments
38 */
39 public void testInvalidArguments() {
40 boolean isTestPassed = false;
41 String script = "keep 1 ;";
42
43 try {
44 JUnitUtils.interpret(JUnitUtils.createMail(), script);
45 } catch (SyntaxException e) {
46 isTestPassed = true;
47 } catch (ParseException e) {
48 } catch (SieveException e) {
49 }
50 assertTrue(isTestPassed);
51 }
52
53 /**
54 * Test for Command 'keep' with an invalid block
55 */
56 public void testInvalidBlock() {
57 boolean isTestPassed = false;
58 String script = "keep 1 {throwTestException;}";
59
60 try {
61 JUnitUtils.interpret(JUnitUtils.createMail(), script);
62 } catch (SyntaxException e) {
63 isTestPassed = true;
64 } catch (ParseException e) {
65 } catch (SieveException e) {
66 }
67 assertTrue(isTestPassed);
68 }
69
70 /**
71 * Test for Command 'keep'
72 */
73 public void testKeep() {
74 boolean isTestPassed = false;
75 String script = "keep;";
76
77 try {
78 MailAdapter mail = JUnitUtils.createMail();
79 JUnitUtils.interpret(mail, script);
80 assertTrue(mail.getActions().size() == 1);
81 assertTrue(mail.getActions().get(0) instanceof ActionKeep);
82 isTestPassed = true;
83 } catch (ParseException e) {
84 } catch (SieveException e) {
85 }
86 assertTrue(isTestPassed);
87 }
88
89 }