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