1 |
|
package org.kuali.student.common.messagebuilder.impl; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
|
import java.util.List; |
5 |
|
|
6 |
|
import org.antlr.runtime.Token; |
7 |
|
import org.antlr.runtime.tree.CommonTreeAdaptor; |
8 |
|
import org.junit.Assert; |
9 |
|
import org.junit.Before; |
10 |
|
import org.junit.Test; |
11 |
|
import org.kuali.student.common.messagebuilder.booleanmessage.ast.BooleanNode; |
12 |
|
import org.kuali.student.common.messagebuilder.booleanmessage.ast.parsers.BooleanFunctionParser; |
13 |
|
import org.kuali.student.common.messagebuilder.impl.BooleanOperators; |
14 |
|
import org.kuali.student.common.messagebuilder.impl.FailureMessageBuilder; |
15 |
|
import org.kuali.student.common.messagebuilder.impl.exceptions.MessageBuilderException; |
16 |
|
|
|
|
| 99.4% |
Uncovered Elements: 1 (154) |
Complexity: 8 |
Complexity Density: 0.05 |
|
17 |
|
public class FailureMessageBuilderTest { |
18 |
|
private final static CommonTreeAdaptor adapter = new CommonTreeAdaptor(); |
19 |
|
private FailureMessageBuilder failureMessageBuilder; |
20 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
21 |
6
|
@Before... |
22 |
|
public void setUp() throws Exception { |
23 |
6
|
BooleanOperators bo = new BooleanOperators(); |
24 |
6
|
failureMessageBuilder = new FailureMessageBuilder(bo); |
25 |
|
} |
26 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1
PASS
|
|
27 |
1
|
@Test... |
28 |
|
public void testBuildFailureMessageForSingleOrNode() throws Exception { |
29 |
|
|
30 |
1
|
Token or = adapter.createToken(BooleanFunctionParser.OR, "+"); |
31 |
1
|
Token a = adapter.createToken(BooleanFunctionParser.ALPHA, "A"); |
32 |
1
|
Token b = adapter.createToken(BooleanFunctionParser.ALPHA, "B"); |
33 |
|
|
34 |
|
|
35 |
1
|
BooleanNode orNode = new BooleanNode(or); |
36 |
|
|
37 |
1
|
BooleanNode aNode = new BooleanNode(a); |
38 |
1
|
aNode.setParent(orNode); |
39 |
1
|
aNode.setValue(Boolean.FALSE); |
40 |
1
|
aNode.setNodeMessage("MATH101"); |
41 |
|
|
42 |
1
|
BooleanNode bNode = new BooleanNode(b); |
43 |
1
|
bNode.setParent(orNode); |
44 |
1
|
bNode.setValue(Boolean.FALSE); |
45 |
1
|
bNode.setNodeMessage("MATH201"); |
46 |
|
|
47 |
1
|
orNode.addChild(aNode); |
48 |
1
|
orNode.addChild(bNode); |
49 |
|
|
50 |
1
|
String failureMsg = failureMessageBuilder.buildFailureMessage(orNode); |
51 |
|
|
52 |
1
|
Assert.assertEquals(failureMsg, orNode.getNodeMessage()); |
53 |
1
|
Assert.assertEquals("MATH101 OR MATH201", failureMsg); |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1
PASS
|
|
56 |
1
|
@Test... |
57 |
|
public void testBuildFailureMessageForSingleAnd1Node() throws Exception { |
58 |
|
|
59 |
1
|
Token and = adapter.createToken(BooleanFunctionParser.AND, "*"); |
60 |
1
|
Token a = adapter.createToken(BooleanFunctionParser.ALPHA, "A"); |
61 |
1
|
Token b = adapter.createToken(BooleanFunctionParser.ALPHA, "B"); |
62 |
|
|
63 |
|
|
64 |
1
|
BooleanNode andNode = new BooleanNode(and); |
65 |
|
|
66 |
1
|
BooleanNode aNode = new BooleanNode(a); |
67 |
1
|
aNode.setParent(andNode); |
68 |
1
|
aNode.setValue(Boolean.TRUE); |
69 |
1
|
aNode.setNodeMessage("MATH101"); |
70 |
|
|
71 |
1
|
BooleanNode bNode = new BooleanNode(b); |
72 |
1
|
bNode.setParent(andNode); |
73 |
1
|
bNode.setValue(Boolean.FALSE); |
74 |
1
|
bNode.setNodeMessage("MATH201"); |
75 |
|
|
76 |
1
|
andNode.addChild(aNode); |
77 |
1
|
andNode.addChild(bNode); |
78 |
|
|
79 |
1
|
String failureMsg = failureMessageBuilder.buildFailureMessage(andNode); |
80 |
|
|
81 |
1
|
Assert.assertEquals(failureMsg, andNode.getNodeMessage()); |
82 |
1
|
Assert.assertEquals("MATH201", failureMsg); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1
PASS
|
|
85 |
1
|
@Test... |
86 |
|
public void testBuildFailureMessageForSingleAnd2Node() throws Exception { |
87 |
|
|
88 |
1
|
Token and = adapter.createToken(BooleanFunctionParser.AND, "*"); |
89 |
1
|
Token a = adapter.createToken(BooleanFunctionParser.ALPHA, "A"); |
90 |
1
|
Token b = adapter.createToken(BooleanFunctionParser.ALPHA, "B"); |
91 |
|
|
92 |
|
|
93 |
1
|
BooleanNode andNode = new BooleanNode(and); |
94 |
|
|
95 |
1
|
BooleanNode aNode = new BooleanNode(a); |
96 |
1
|
aNode.setParent(andNode); |
97 |
1
|
aNode.setValue(Boolean.FALSE); |
98 |
1
|
aNode.setNodeMessage("MATH101"); |
99 |
|
|
100 |
1
|
BooleanNode bNode = new BooleanNode(b); |
101 |
1
|
bNode.setParent(andNode); |
102 |
1
|
bNode.setValue(Boolean.FALSE); |
103 |
1
|
bNode.setNodeMessage("MATH201"); |
104 |
|
|
105 |
1
|
andNode.addChild(aNode); |
106 |
1
|
andNode.addChild(bNode); |
107 |
|
|
108 |
1
|
String failureMsg = failureMessageBuilder.buildFailureMessage(andNode); |
109 |
|
|
110 |
1
|
Assert.assertEquals(failureMsg, andNode.getNodeMessage()); |
111 |
1
|
Assert.assertEquals("MATH101 AND MATH201", failureMsg); |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 1 |
Complexity Density: 0.03 |
1
PASS
|
|
114 |
1
|
@Test... |
115 |
|
public void testBuildFailureMessageForListOfNodes_Simple() throws Exception { |
116 |
|
|
117 |
1
|
Token and = adapter.createToken(BooleanFunctionParser.AND, "*"); |
118 |
1
|
Token or = adapter.createToken(BooleanFunctionParser.OR, "+"); |
119 |
1
|
Token a = adapter.createToken(BooleanFunctionParser.ALPHA, "A"); |
120 |
1
|
Token b = adapter.createToken(BooleanFunctionParser.ALPHA, "B"); |
121 |
1
|
Token c = adapter.createToken(BooleanFunctionParser.ALPHA, "C"); |
122 |
|
|
123 |
|
|
124 |
1
|
BooleanNode andNode = new BooleanNode(and); |
125 |
1
|
BooleanNode orNode = new BooleanNode(or); |
126 |
1
|
orNode.setParent(andNode); |
127 |
1
|
orNode.setValue(Boolean.FALSE); |
128 |
|
|
129 |
1
|
BooleanNode aNode = new BooleanNode(a); |
130 |
1
|
aNode.setParent(andNode); |
131 |
1
|
aNode.setValue(Boolean.FALSE); |
132 |
1
|
aNode.setNodeMessage("MATH101"); |
133 |
|
|
134 |
1
|
BooleanNode bNode = new BooleanNode(b); |
135 |
1
|
bNode.setParent(orNode); |
136 |
1
|
bNode.setValue(Boolean.FALSE); |
137 |
1
|
bNode.setNodeMessage("MATH201"); |
138 |
|
|
139 |
1
|
BooleanNode cNode = new BooleanNode(c); |
140 |
1
|
cNode.setParent(orNode); |
141 |
1
|
cNode.setValue(Boolean.FALSE); |
142 |
1
|
cNode.setNodeMessage("MATH301"); |
143 |
|
|
144 |
1
|
orNode.addChild(bNode); |
145 |
1
|
orNode.addChild(cNode); |
146 |
1
|
andNode.addChild(aNode); |
147 |
1
|
andNode.addChild(orNode); |
148 |
|
|
149 |
|
|
150 |
1
|
List<BooleanNode> list = new ArrayList<BooleanNode>(); |
151 |
1
|
list.add(cNode); |
152 |
1
|
list.add(bNode); |
153 |
1
|
list.add(orNode); |
154 |
1
|
list.add(aNode); |
155 |
1
|
list.add(andNode); |
156 |
|
|
157 |
1
|
String failureMsg = failureMessageBuilder.buildFailureMessage(list); |
158 |
|
|
159 |
1
|
Assert.assertEquals(failureMsg, andNode.getNodeMessage()); |
160 |
1
|
Assert.assertEquals("MATH101 AND (MATH201 OR MATH301)", failureMsg); |
161 |
|
} |
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 1 |
Complexity Density: 0.02 |
1
PASS
|
|
163 |
1
|
@Test... |
164 |
|
public void testBuildFailureMessageForListOfNodes_Complex() throws Exception { |
165 |
|
|
166 |
1
|
Token and = adapter.createToken(BooleanFunctionParser.AND, "*"); |
167 |
1
|
Token or1 = adapter.createToken(BooleanFunctionParser.OR, "+"); |
168 |
1
|
Token or2 = adapter.createToken(BooleanFunctionParser.OR, "+"); |
169 |
1
|
Token a = adapter.createToken(BooleanFunctionParser.ALPHA, "A"); |
170 |
1
|
Token b = adapter.createToken(BooleanFunctionParser.ALPHA, "B"); |
171 |
1
|
Token c = adapter.createToken(BooleanFunctionParser.ALPHA, "C"); |
172 |
1
|
Token d = adapter.createToken(BooleanFunctionParser.ALPHA, "D"); |
173 |
|
|
174 |
|
|
175 |
1
|
BooleanNode andNode = new BooleanNode(and); |
176 |
|
|
177 |
1
|
BooleanNode orNode1 = new BooleanNode(or1); |
178 |
1
|
orNode1.setParent(andNode); |
179 |
1
|
orNode1.setValue(Boolean.TRUE); |
180 |
|
|
181 |
1
|
BooleanNode orNode2 = new BooleanNode(or2); |
182 |
1
|
orNode2.setParent(andNode); |
183 |
1
|
orNode2.setValue(Boolean.FALSE); |
184 |
|
|
185 |
1
|
BooleanNode aNode = new BooleanNode(a); |
186 |
1
|
aNode.setParent(orNode1); |
187 |
1
|
aNode.setValue(Boolean.TRUE); |
188 |
1
|
aNode.setNodeMessage("MATH101"); |
189 |
|
|
190 |
1
|
BooleanNode bNode = new BooleanNode(b); |
191 |
1
|
bNode.setParent(orNode1); |
192 |
1
|
bNode.setValue(Boolean.TRUE); |
193 |
1
|
bNode.setNodeMessage("MATH201"); |
194 |
|
|
195 |
1
|
BooleanNode cNode = new BooleanNode(c); |
196 |
1
|
cNode.setParent(orNode2); |
197 |
1
|
cNode.setValue(Boolean.FALSE); |
198 |
1
|
cNode.setNodeMessage("MATH301"); |
199 |
|
|
200 |
1
|
BooleanNode dNode = new BooleanNode(d); |
201 |
1
|
dNode.setParent(orNode2); |
202 |
1
|
dNode.setValue(Boolean.FALSE); |
203 |
1
|
dNode.setNodeMessage("MATH401"); |
204 |
|
|
205 |
1
|
orNode1.addChild(aNode); |
206 |
1
|
orNode1.addChild(bNode); |
207 |
1
|
orNode2.addChild(cNode); |
208 |
1
|
orNode2.addChild(dNode); |
209 |
1
|
andNode.addChild(orNode1); |
210 |
1
|
andNode.addChild(orNode2); |
211 |
|
|
212 |
|
|
213 |
1
|
List<BooleanNode> list = new ArrayList<BooleanNode>(); |
214 |
1
|
list.add(aNode); |
215 |
1
|
list.add(bNode); |
216 |
1
|
list.add(cNode); |
217 |
1
|
list.add(dNode); |
218 |
1
|
list.add(orNode1); |
219 |
1
|
list.add(orNode2); |
220 |
1
|
list.add(andNode); |
221 |
|
|
222 |
1
|
String failureMsg = failureMessageBuilder.buildFailureMessage(list); |
223 |
|
|
224 |
1
|
Assert.assertEquals(failureMsg, andNode.getNodeMessage()); |
225 |
1
|
Assert.assertEquals("(MATH301 OR MATH401)", failureMsg); |
226 |
|
} |
227 |
|
|
|
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 2 |
Complexity Density: 0.15 |
1
PASS
|
|
228 |
1
|
@Test... |
229 |
|
public void testBuildFailureMessageForListOfNodes_MultipleRootNodes() throws Exception { |
230 |
1
|
Token or = adapter.createToken(BooleanFunctionParser.OR, "+"); |
231 |
1
|
Token and = adapter.createToken(BooleanFunctionParser.AND, "*"); |
232 |
|
|
233 |
|
|
234 |
1
|
BooleanNode orNode = new BooleanNode(or); |
235 |
|
|
236 |
1
|
BooleanNode andNode = new BooleanNode(and); |
237 |
|
|
238 |
1
|
List<BooleanNode> list = new ArrayList<BooleanNode>(); |
239 |
1
|
list.add(orNode); |
240 |
1
|
list.add(andNode); |
241 |
|
|
242 |
1
|
try { |
243 |
1
|
failureMessageBuilder.buildFailureMessage(list); |
244 |
0
|
Assert.fail("buildFailureMessage should have failed since list has 2 root nodes"); |
245 |
|
} catch (MessageBuilderException e) { |
246 |
1
|
Assert.assertTrue(e.getMessage() != null); |
247 |
1
|
Assert.assertTrue(e.getMessage().contains("label=+")); |
248 |
1
|
Assert.assertTrue(e.getMessage().contains("label=*")); |
249 |
|
} |
250 |
|
} |
251 |
|
} |