1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.jsieve.util;
20
21 import org.apache.jsieve.NumberArgument;
22 import org.apache.jsieve.TagArgument;
23 import org.apache.jsieve.parser.generated.ASTargument;
24 import org.apache.jsieve.parser.generated.ASTarguments;
25 import org.apache.jsieve.parser.generated.ASTblock;
26 import org.apache.jsieve.parser.generated.ASTcommand;
27 import org.apache.jsieve.parser.generated.ASTcommands;
28 import org.apache.jsieve.parser.generated.ASTstart;
29 import org.apache.jsieve.parser.generated.ASTstring;
30 import org.apache.jsieve.parser.generated.ASTstring_list;
31 import org.apache.jsieve.parser.generated.ASTtest;
32 import org.apache.jsieve.parser.generated.ASTtest_list;
33 import org.apache.jsieve.parser.generated.SieveParserTreeConstants;
34 import org.apache.jsieve.parser.generated.SimpleNode;
35 import org.apache.jsieve.parser.generated.Token;
36 import org.jmock.Mock;
37 import org.jmock.MockObjectTestCase;
38
39 public class NodeToSieveAdapterTest extends MockObjectTestCase {
40
41 Mock mock;
42 NodeToSieveAdapter subject;
43
44 protected void setUp() throws Exception {
45 super.setUp();
46 mock = mock(SieveHandler.class);
47 subject = new NodeToSieveAdapter((SieveHandler)mock.proxy());
48 }
49
50 protected void tearDown() throws Exception {
51 super.tearDown();
52 }
53
54 public void testStart() throws Exception {
55
56 subject.start();
57 }
58
59 public void testEnd() throws Exception {
60
61 subject.end();
62 }
63
64 public void testEndSimpleNode() throws Exception {
65
66 subject.end(new SimpleNode(SieveParserTreeConstants.JJTBLOCK));
67 }
68
69 public void testEndASTstart() throws Exception {
70 mock.expects(once()).method("endScript");
71 subject.end(new ASTstart(SieveParserTreeConstants.JJTSTART));
72 }
73
74 public void testEndASTcommands() throws Exception {
75 mock.expects(once()).method("endCommands");
76 subject.end(new ASTcommands(SieveParserTreeConstants.JJTCOMMANDS));
77 }
78
79 public void testEndASTcommand() throws Exception {
80 String name = "CommandName";
81 mock.expects(once()).method("endCommand").with(eq(name));
82 ASTcommand node = new ASTcommand(SieveParserTreeConstants.JJTCOMMAND);
83 node.setName(name);
84 subject.end(node);
85 }
86
87 public void testEndASTblock() throws Exception {
88 mock.expects(once()).method("endBlock");
89 subject.end(new ASTblock(SieveParserTreeConstants.JJTBLOCK));
90 }
91
92 public void testEndASTarguments() throws Exception {
93 mock.expects(once()).method("endArguments");
94 subject.end(new ASTarguments(SieveParserTreeConstants.JJTARGUMENTS));
95 }
96
97 public void testASTargumentTag() throws Exception {
98 String tag = "Hugo";
99 mock.expects(once()).method("argument").with(eq(tag));
100 ASTargument argument = new ASTargument(SieveParserTreeConstants.JJTARGUMENTS);
101 argument.setValue(new TagArgument(new Token(0, tag)));
102 subject.start(argument);
103 subject.end(argument);
104 }
105
106 public void testASTargumentNumber() throws Exception {
107 int number = 17;
108 mock.expects(once()).method("argument").with(eq(number));
109 ASTargument argument = new ASTargument(SieveParserTreeConstants.JJTARGUMENTS);
110 argument.setValue(new NumberArgument(new Token(0, "17")));
111 subject.start(argument);
112 subject.end(argument);
113 }
114
115 public void testEndASTtest() throws Exception {
116 String name = "ATestName";
117 mock.expects(once()).method("endTest").with(eq(name));
118 ASTtest node = new ASTtest(SieveParserTreeConstants.JJTTEST);
119 node.setName(name);
120 subject.end(node);
121 }
122
123 public void testEndASTtest_list() throws Exception {
124 mock.expects(once()).method("endTestList");
125 subject.end(new ASTtest_list(SieveParserTreeConstants.JJTTEST_LIST));
126 }
127
128 public void testEndASTstring_list() throws Exception {
129 mock.expects(once()).method("endStringListArgument");
130 subject.end(new ASTstring_list(SieveParserTreeConstants.JJTSTRING_LIST));
131 }
132
133 public void testStartSimpleNode() throws Exception {
134
135 subject.end(new SimpleNode(SieveParserTreeConstants.JJTBLOCK));
136 }
137
138 public void testStartASTstart() throws Exception {
139 mock.expects(once()).method("startScript");
140 subject.start(new ASTstart(SieveParserTreeConstants.JJTSTART));
141 }
142
143 public void testStartASTcommands() throws Exception {
144 mock.expects(once()).method("startCommands");
145 subject.start(new ASTcommands(SieveParserTreeConstants.JJTCOMMANDS));
146 }
147
148 public void testStartASTcommand() throws Exception {
149 String name = "CommandName";
150 mock.expects(once()).method("startCommand").with(eq(name));
151 ASTcommand node = new ASTcommand(SieveParserTreeConstants.JJTCOMMAND);
152 node.setName(name);
153 subject.start(node);
154 }
155
156 public void testStartASTblock() throws Exception {
157 mock.expects(once()).method("startBlock");
158 subject.start(new ASTblock(SieveParserTreeConstants.JJTBLOCK));
159 }
160
161 public void testStartASTarguments() throws Exception {
162 mock.expects(once()).method("startArguments");
163 subject.start(new ASTarguments(SieveParserTreeConstants.JJTARGUMENTS));
164 }
165
166 public void testStartASTtest() throws Exception {
167 String name = "ATestName";
168 mock.expects(once()).method("startTest").with(eq(name));
169 ASTtest node = new ASTtest(SieveParserTreeConstants.JJTTEST);
170 node.setName(name);
171 subject.start(node);
172 }
173
174 public void testStartASTtest_list() throws Exception {
175 mock.expects(once()).method("startTestList");
176 subject.start(new ASTtest_list(SieveParserTreeConstants.JJTTEST_LIST));
177 }
178
179 public void testASTstring() throws Exception {
180 String string = "A Value";
181 mock.expects(once()).method("listMember").with(eq(string));
182 ASTstring node = new ASTstring(SieveParserTreeConstants.JJTSTRING);
183 node.setValue(string);
184 subject.start(node);
185 subject.end(node);
186 }
187
188 public void testStartASTstring_list() throws Exception {
189 mock.expects(once()).method("startStringListArgument");
190 subject.start(new ASTstring_list(SieveParserTreeConstants.JJTSTRING_LIST));
191 }
192
193 }