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