1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.kuali.rice.kew.rule.xmlrouting; |
18 |
|
|
19 |
|
import org.junit.Test; |
20 |
|
|
21 |
|
import org.kuali.rice.kew.dto.WorkflowAttributeDefinitionDTO; |
22 |
|
import org.kuali.rice.kew.exception.WorkflowException; |
23 |
|
import org.kuali.rice.kew.routeheader.DocumentContent; |
24 |
|
import org.kuali.rice.kew.routeheader.StandardDocumentContent; |
25 |
|
import org.kuali.rice.kew.rule.RuleExtension; |
26 |
|
import org.kuali.rice.kew.rule.RuleExtensionValue; |
27 |
|
import org.kuali.rice.kew.rule.bo.RuleAttribute; |
28 |
|
import org.kuali.rice.kew.rule.bo.RuleTemplateAttribute; |
29 |
|
import org.kuali.rice.kew.service.WorkflowDocument; |
30 |
|
import org.kuali.rice.kew.test.KEWTestCase; |
31 |
|
import org.kuali.rice.kns.web.ui.Field; |
32 |
|
import org.kuali.rice.kns.web.ui.Row; |
33 |
|
import org.w3c.dom.Element; |
34 |
|
import org.xml.sax.InputSource; |
35 |
|
|
36 |
|
import javax.xml.parsers.DocumentBuilderFactory; |
37 |
|
import javax.xml.xpath.XPath; |
38 |
|
import javax.xml.xpath.XPathConstants; |
39 |
|
import javax.xml.xpath.XPathFactory; |
40 |
|
import java.io.BufferedReader; |
41 |
|
import java.io.StringReader; |
42 |
|
import java.util.*; |
43 |
|
|
44 |
|
import static org.junit.Assert.assertFalse; |
45 |
|
import static org.junit.Assert.assertTrue; |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 227 (227) |
Complexity: 13 |
Complexity Density: 0.06 |
|
47 |
|
public class StandardGenericXMLRuleAttributeTest extends KEWTestCase { |
48 |
|
|
49 |
|
private DocumentContent docContent; |
50 |
|
private StandardGenericXMLRuleAttribute attribute; |
51 |
|
private List extensions; |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
53 |
0
|
public void setUp() throws Exception {... |
54 |
0
|
super.setUp(); |
55 |
0
|
attribute = new StandardGenericXMLRuleAttribute(); |
56 |
0
|
String documentcontent = |
57 |
|
"<documentContent>" + |
58 |
|
"<attributeContent>"+ |
59 |
|
"<xmlContent>"+ |
60 |
|
"<fieldDef name=\"givenname\">"+ |
61 |
|
"<value>Dave</value>"+ |
62 |
|
"</fieldDef>"+ |
63 |
|
"<fieldDef name=\"gender\">"+ |
64 |
|
"<value>female</value>"+ |
65 |
|
"</fieldDef>"+ |
66 |
|
"<fieldDef name=\"color\">"+ |
67 |
|
"<value>green</value>"+ |
68 |
|
"</fieldDef>"+ |
69 |
|
"<fieldDef name=\"totalDollar\">"+ |
70 |
|
"<value>500</value>"+ |
71 |
|
"</fieldDef>"+ |
72 |
|
"</xmlContent>"+ |
73 |
|
"<xmlContent>"+ |
74 |
|
"<fieldDef name=\"givenname\">"+ |
75 |
|
"<value>Jane</value>"+ |
76 |
|
"</fieldDef>"+ |
77 |
|
"<fieldDef name=\"gender\">"+ |
78 |
|
"<value>female</value>"+ |
79 |
|
"</fieldDef>"+ |
80 |
|
"<fieldDef name=\"color\">"+ |
81 |
|
"<value>blue</value>"+ |
82 |
|
"</fieldDef>"+ |
83 |
|
"<fieldDef name=\"totalDollar\">"+ |
84 |
|
"<value>400</value>"+ |
85 |
|
"</fieldDef>"+ |
86 |
|
"</xmlContent>"+ |
87 |
|
"</attributeContent>"+ |
88 |
|
"</documentContent>"; |
89 |
|
|
90 |
0
|
String routingConfig = |
91 |
|
"<routingConfig>"+ |
92 |
|
"<globalEvaluations>" + |
93 |
|
"<xpathexpression>//fieldDef/value != 'Nothing'</xpathexpression>" + |
94 |
|
"</globalEvaluations>"+ |
95 |
|
|
96 |
|
"<fieldDef name=\"givenname\" title=\"First name\" workflowType=\"ALL\">"+ |
97 |
|
"<value>Joe</value>"+ |
98 |
|
"<display>"+ |
99 |
|
"<type>text</type>"+ |
100 |
|
"<meta><name>size</name><value>20</value></meta>"+ |
101 |
|
"</display>" + |
102 |
|
"<validation required=\"true\">"+ |
103 |
|
"<regex>^[a-zA-Z ]+$</regex>"+ |
104 |
|
"<message>Invalid first name</message>"+ |
105 |
|
"</validation>"+ |
106 |
|
"<fieldEvaluation><xpathexpression>//xmlContent/fieldDef[@name='givenname']/value = wf:ruledata('givenname')</xpathexpression></fieldEvaluation>"+ |
107 |
|
"</fieldDef>"+ |
108 |
|
"<fieldDef name=\"gender\" title=\"Gender\" workflowType=\"ALL\">"+ |
109 |
|
"<value>male</value>"+ |
110 |
|
"<display>"+ |
111 |
|
"<type>radio</type>"+ |
112 |
|
"<values title=\"Male\">male</values>"+ |
113 |
|
"<values title=\"Female\">female</values>"+ |
114 |
|
"</display>"+ |
115 |
|
"<validation required=\"true\">" + |
116 |
|
"<regex>(male|female)</regex>"+ |
117 |
|
"<message>Invalid gender</message>"+ |
118 |
|
"</validation>"+ |
119 |
|
"<fieldEvaluation><xpathexpression>//xmlContent/fieldDef[@name='gender']/value = wf:ruledata('gender')</xpathexpression></fieldEvaluation>"+ |
120 |
|
"</fieldDef>"+ |
121 |
|
"<fieldDef name=\"color\" title=\"Color\" workflowType=\"ALL\">" + |
122 |
|
"<value>blue</value>" + |
123 |
|
"<display>" + |
124 |
|
"<type>select</type>" + |
125 |
|
"<values title=\"Red\">red</values>" + |
126 |
|
"<values title=\"Green\">green</values>" + |
127 |
|
"<values title=\"Blue\" selected=\"true\">blue</values>" + |
128 |
|
"</display>" + |
129 |
|
"<validation required=\"true\">"+ |
130 |
|
"<regex>(red|green|blue|)</regex>"+ |
131 |
|
"<message>Invalid color</message>"+ |
132 |
|
"</validation>"+ |
133 |
|
"<fieldEvaluation><xpathexpression>//xmlContent/fieldDef[@name='color']/value = wf:ruledata('color')</xpathexpression></fieldEvaluation>"+ |
134 |
|
"</fieldDef>"+ |
135 |
|
"<fieldDef name=\"maxDollar\" title=\"Max dollar\" workflowType=\"RULE\">" + |
136 |
|
"<display>" + |
137 |
|
"<type>text</type>" + |
138 |
|
"</display>" + |
139 |
|
"<fieldEvaluation><xpathexpression>//xmlContent/fieldDef[@name='totalDollar']/value <= wf:ruledata('maxDollar')</xpathexpression></fieldEvaluation>"+ |
140 |
|
"</fieldDef>"+ |
141 |
|
"<fieldDef name=\"minDollar\" title=\"Min dollar\" workflowType=\"RULE\">" + |
142 |
|
"<display>" + |
143 |
|
"<type>text</type>" + |
144 |
|
"</display>" + |
145 |
|
"<fieldEvaluation><xpathexpression>//xmlContent/fieldDef[@name='totalDollar']/value >= wf:ruledata('minDollar')</xpathexpression></fieldEvaluation>"+ |
146 |
|
"</fieldDef>"+ |
147 |
|
"<fieldDef name=\"totalDollar\" title=\"Total dollar\" workflowType=\"REPORT\">" + |
148 |
|
"<display>" + |
149 |
|
"<type>text</type>" + |
150 |
|
"</display>" + |
151 |
|
"</fieldDef>" + |
152 |
|
"</routingConfig>"; |
153 |
|
|
154 |
0
|
docContent = new StandardDocumentContent(documentcontent); |
155 |
0
|
RuleAttribute ruleAttribute = new RuleAttribute(); |
156 |
0
|
ruleAttribute.setXmlConfigData(routingConfig); |
157 |
0
|
ruleAttribute.setName("MyUniqueRuleAttribute1"); |
158 |
0
|
attribute.setRuleAttribute(ruleAttribute); |
159 |
|
} |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
4
-
|
|
161 |
0
|
@Test public void testValidateRoutingData(){... |
162 |
0
|
Map paramMap = new HashMap(); |
163 |
0
|
paramMap.put("givenname", "Dave"); |
164 |
0
|
paramMap.put("gender", "female"); |
165 |
0
|
paramMap.put("color", "green"); |
166 |
0
|
paramMap.put("totalDollar", "500"); |
167 |
|
|
168 |
0
|
assertTrue("Errors found", attribute.validateRoutingData(paramMap).isEmpty()); |
169 |
|
} |
170 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
4
-
|
|
171 |
0
|
@Test public void testValidateRuleData(){... |
172 |
0
|
Map paramMap = new HashMap(); |
173 |
0
|
paramMap.put("givenname", "Dave"); |
174 |
0
|
paramMap.put("gender", "female"); |
175 |
0
|
paramMap.put("color", "green"); |
176 |
0
|
paramMap.put("totalDollar", "500"); |
177 |
|
|
178 |
0
|
assertTrue("Errors found", attribute.validateRuleData(paramMap).isEmpty()); |
179 |
|
|
180 |
0
|
paramMap = new HashMap(); |
181 |
0
|
paramMap.put("givenname", "4444"); |
182 |
0
|
paramMap.put("gender", "crap"); |
183 |
0
|
paramMap.put("color", "green"); |
184 |
0
|
paramMap.put("totalDollar", "500"); |
185 |
|
|
186 |
0
|
assertFalse("Error list should contain at least one error.", attribute.validateRuleData(paramMap).isEmpty()); |
187 |
|
|
188 |
0
|
paramMap = new HashMap(); |
189 |
0
|
paramMap.put("givenname", ""); |
190 |
0
|
paramMap.put("gender", "female"); |
191 |
0
|
paramMap.put("color", "green"); |
192 |
0
|
paramMap.put("totalDollar", "500"); |
193 |
|
|
194 |
0
|
assertFalse("givenname should be required.", attribute.validateRuleData(paramMap).isEmpty()); |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
4
-
|
|
201 |
0
|
@Test public void testNonMatchingExtensionKey() throws WorkflowException {... |
202 |
0
|
loadXmlFile("TestExtensionValueMatching.xml"); |
203 |
0
|
WorkflowDocument doc = new WorkflowDocument(getPrincipalIdForName("arh14"), "TestDocument"); |
204 |
|
|
205 |
0
|
WorkflowAttributeDefinitionDTO attr = new WorkflowAttributeDefinitionDTO(StandardGenericXMLRuleAttribute.class.getName()); |
206 |
0
|
attr.setAttributeName("Attr1"); |
207 |
|
|
208 |
0
|
attr.addProperty("attr1", "2"); |
209 |
0
|
doc.addAttributeDefinition(attr); |
210 |
|
|
211 |
0
|
doc.routeDocument(""); |
212 |
|
|
213 |
0
|
Long id = doc.getRouteHeaderId(); |
214 |
|
|
215 |
0
|
doc = new WorkflowDocument(getPrincipalIdForName("user1"), id); |
216 |
0
|
assertTrue("Request should have been generated to user1", doc.isApprovalRequested()); |
217 |
|
|
218 |
0
|
doc = new WorkflowDocument(getPrincipalIdForName("user2"), id); |
219 |
0
|
assertTrue("Expected approval request to user2", doc.isApprovalRequested()); |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
|
|
| 0% |
Uncovered Elements: 110 (110) |
Complexity: 1 |
Complexity Density: 0.01 |
4
-
|
|
225 |
0
|
@Test public void testIsMatch() {... |
226 |
0
|
RuleExtension extension = new RuleExtension(); |
227 |
|
|
228 |
0
|
List values = new ArrayList(); |
229 |
0
|
RuleExtensionValue value = new RuleExtensionValue(); |
230 |
0
|
value.setKey("givenname"); |
231 |
0
|
value.setValue("Dave"); |
232 |
0
|
values.add(value); |
233 |
|
|
234 |
0
|
RuleExtensionValue value2 = new RuleExtensionValue(); |
235 |
0
|
value2.setKey("gender"); |
236 |
0
|
value2.setValue("female"); |
237 |
0
|
values.add(value2); |
238 |
|
|
239 |
0
|
RuleExtensionValue value3 = new RuleExtensionValue(); |
240 |
0
|
value3.setKey("color"); |
241 |
0
|
value3.setValue("green"); |
242 |
0
|
values.add(value3); |
243 |
|
|
244 |
0
|
extension.setExtensionValues(values); |
245 |
0
|
RuleTemplateAttribute ruleTemplateAttribute = new RuleTemplateAttribute(); |
246 |
|
|
247 |
0
|
RuleAttribute ruleAttribute = new RuleAttribute(); |
248 |
0
|
ruleAttribute.setName("MyUniqueRuleAttribute1"); |
249 |
|
|
250 |
0
|
ruleTemplateAttribute.setRuleAttribute(ruleAttribute); |
251 |
0
|
extension.setRuleTemplateAttribute(ruleTemplateAttribute); |
252 |
0
|
RuleExtension extension2 = new RuleExtension(); |
253 |
|
|
254 |
0
|
List values2 = new ArrayList(); |
255 |
0
|
RuleExtensionValue valueNew = new RuleExtensionValue(); |
256 |
0
|
valueNew.setKey("givenname"); |
257 |
0
|
valueNew.setValue("Jack"); |
258 |
|
|
259 |
0
|
RuleExtensionValue minDollar = new RuleExtensionValue(); |
260 |
0
|
minDollar.setKey("minDollar"); |
261 |
0
|
minDollar.setValue("300"); |
262 |
0
|
RuleExtensionValue maxDollar = new RuleExtensionValue(); |
263 |
0
|
maxDollar.setKey("maxDollar"); |
264 |
0
|
maxDollar.setValue("600"); |
265 |
|
|
266 |
|
|
267 |
0
|
values2.add(valueNew); |
268 |
0
|
values2.add(minDollar); |
269 |
0
|
values2.add(maxDollar); |
270 |
0
|
extension2.setExtensionValues(values2); |
271 |
0
|
RuleTemplateAttribute ruleTemplateAttribute2 = new RuleTemplateAttribute(); |
272 |
|
|
273 |
0
|
RuleAttribute ruleAttribute2 = new RuleAttribute(); |
274 |
0
|
ruleAttribute2.setName("MyUniqueRuleAttribute2"); |
275 |
|
|
276 |
0
|
ruleTemplateAttribute2.setRuleAttribute(ruleAttribute2); |
277 |
0
|
extension2.setRuleTemplateAttribute(ruleTemplateAttribute2); |
278 |
|
|
279 |
0
|
extensions = new ArrayList(); |
280 |
0
|
extensions.add(extension); |
281 |
0
|
extensions.add(extension2); |
282 |
|
|
283 |
0
|
assertTrue("Givenname did not match Dave, gender did not match female, or color did not match green", attribute.isMatch(docContent, extensions)); |
284 |
|
|
285 |
0
|
extension = new RuleExtension(); |
286 |
0
|
values = new ArrayList(); |
287 |
0
|
RuleExtensionValue value4 = new RuleExtensionValue(); |
288 |
0
|
value4.setKey("givenname"); |
289 |
0
|
value4.setValue("Dave"); |
290 |
0
|
values.add(value4); |
291 |
|
|
292 |
0
|
RuleExtensionValue value5 = new RuleExtensionValue(); |
293 |
0
|
value5.setKey("gender"); |
294 |
0
|
value5.setValue("male"); |
295 |
0
|
values.add(value5); |
296 |
|
|
297 |
0
|
RuleExtensionValue value6 = new RuleExtensionValue(); |
298 |
0
|
value6.setKey("color"); |
299 |
0
|
value6.setValue("green"); |
300 |
0
|
values.add(value6); |
301 |
|
|
302 |
0
|
extension.setExtensionValues(values); |
303 |
0
|
ruleTemplateAttribute = new RuleTemplateAttribute(); |
304 |
|
|
305 |
0
|
ruleAttribute = new RuleAttribute(); |
306 |
0
|
ruleAttribute.setName("MyUniqueRuleAttribute1"); |
307 |
|
|
308 |
0
|
ruleTemplateAttribute.setRuleAttribute(ruleAttribute); |
309 |
0
|
extension.setRuleTemplateAttribute(ruleTemplateAttribute); |
310 |
|
|
311 |
|
|
312 |
0
|
values2 = new ArrayList(); |
313 |
0
|
valueNew = new RuleExtensionValue(); |
314 |
0
|
valueNew.setKey("givenname"); |
315 |
0
|
valueNew.setValue("Jack"); |
316 |
|
|
317 |
0
|
values2.add(valueNew); |
318 |
0
|
extension2.setExtensionValues(values2); |
319 |
0
|
ruleTemplateAttribute2 = new RuleTemplateAttribute(); |
320 |
|
|
321 |
0
|
ruleAttribute2 = new RuleAttribute(); |
322 |
0
|
ruleAttribute2.setName("MyUniqueRuleAttribute2"); |
323 |
|
|
324 |
0
|
ruleTemplateAttribute2.setRuleAttribute(ruleAttribute2); |
325 |
0
|
extension2.setRuleTemplateAttribute(ruleTemplateAttribute2); |
326 |
|
|
327 |
0
|
extensions = new ArrayList(); |
328 |
0
|
extensions.add(extension); |
329 |
0
|
extensions.add(extension2); |
330 |
0
|
assertFalse("Gender female != male.", attribute.isMatch(docContent, extensions)); |
331 |
|
|
332 |
|
|
333 |
|
|
334 |
0
|
extension = new RuleExtension(); |
335 |
0
|
values = new ArrayList(); |
336 |
|
|
337 |
0
|
RuleExtensionValue value7 = new RuleExtensionValue(); |
338 |
0
|
value7.setKey("maxDollar"); |
339 |
0
|
value7.setValue("500"); |
340 |
|
|
341 |
|
|
342 |
0
|
RuleExtensionValue value8 = new RuleExtensionValue(); |
343 |
0
|
value8.setKey("minDollar"); |
344 |
0
|
value8.setValue("100"); |
345 |
|
|
346 |
0
|
values.add(value7); |
347 |
0
|
values.add(value8); |
348 |
0
|
extension.setExtensionValues(values); |
349 |
0
|
ruleTemplateAttribute = new RuleTemplateAttribute(); |
350 |
0
|
ruleAttribute = new RuleAttribute(); |
351 |
0
|
ruleAttribute.setName("MyUniqueRuleAttribute1"); |
352 |
0
|
ruleTemplateAttribute.setRuleAttribute(ruleAttribute); |
353 |
0
|
extension.setRuleTemplateAttribute(ruleTemplateAttribute); |
354 |
|
|
355 |
0
|
values2 = new ArrayList(); |
356 |
|
|
357 |
0
|
valueNew = new RuleExtensionValue(); |
358 |
0
|
valueNew.setKey("givenname"); |
359 |
0
|
valueNew.setValue("Jack"); |
360 |
0
|
values2.add(valueNew); |
361 |
|
|
362 |
0
|
extension2.setExtensionValues(values2); |
363 |
0
|
ruleTemplateAttribute2 = new RuleTemplateAttribute(); |
364 |
|
|
365 |
0
|
ruleAttribute2 = new RuleAttribute(); |
366 |
0
|
ruleAttribute2.setName("MyUniqueRuleAttribute2"); |
367 |
|
|
368 |
0
|
ruleTemplateAttribute2.setRuleAttribute(ruleAttribute2); |
369 |
0
|
extension2.setRuleTemplateAttribute(ruleTemplateAttribute2); |
370 |
|
|
371 |
0
|
extensions = new ArrayList(); |
372 |
0
|
extensions.add(extension); |
373 |
0
|
extensions.add(extension2); |
374 |
0
|
assertTrue("Total dollar is greater than the max or less than the min.", attribute.isMatch(docContent, extensions)); |
375 |
|
} |
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
4
-
|
|
380 |
0
|
@Test public void testGetRuleRows() {... |
381 |
0
|
assertTrue("Invalid number of rule rows", attribute.getRuleRows().size() == 5); |
382 |
|
|
383 |
0
|
String routingConfigWithQuickfinders = |
384 |
|
"<routingConfig>"+ |
385 |
|
"<globalEvaluations>" + |
386 |
|
"<xpathexpression>//field/value != 'Nothing'</xpathexpression>" + |
387 |
|
"</globalEvaluations>"+ |
388 |
|
|
389 |
|
"<fieldDef name=\"chart\" title=\"Chart\" workflowType=\"ALL\">"+ |
390 |
|
"<value>BL</value>"+ |
391 |
|
"<display>"+ |
392 |
|
"<type>text</type>"+ |
393 |
|
"<meta><name>size</name><value>20</value></meta>"+ |
394 |
|
"</display>" + |
395 |
|
"<fieldEvaluation><xpathexpression>//xmlContent/field[@name='chart']/value = wf:ruledata('chart')</xpathexpression></fieldEvaluation>"+ |
396 |
|
"</fieldDef>"+ |
397 |
|
"<fieldDef name=\"org\" title=\"Org\" workflowType=\"ALL\">"+ |
398 |
|
"<display>"+ |
399 |
|
"<type>text</type>"+ |
400 |
|
"</display>" + |
401 |
|
"<lookup businessObjectClass=\"ChartOrgLookupableImplService\">" + |
402 |
|
"<fieldConversions>" + |
403 |
|
"<fieldConversion lookupFieldName=\"fin_coa_cd\" localFieldName=\"chart\"/>" + |
404 |
|
"<fieldConversion lookupFieldName=\"org_cd\" localFieldName=\"org\"/>" + |
405 |
|
"</fieldConversions>" + |
406 |
|
"</lookup>" + |
407 |
|
"<fieldEvaluation><xpathexpression>//xmlContent/field[@name='gender']/value = wf:ruledata('gender')</xpathexpression></fieldEvaluation>"+ |
408 |
|
"</fieldDef>" + |
409 |
|
"</routingConfig>"; |
410 |
|
|
411 |
0
|
RuleAttribute ruleAttribute = new RuleAttribute(); |
412 |
0
|
ruleAttribute.setXmlConfigData(routingConfigWithQuickfinders); |
413 |
0
|
ruleAttribute.setName("MyUniqueRuleAttribute3"); |
414 |
0
|
StandardGenericXMLRuleAttribute myAttribute = new StandardGenericXMLRuleAttribute(); |
415 |
0
|
myAttribute.setRuleAttribute(ruleAttribute); |
416 |
|
|
417 |
0
|
for (Iterator iter = myAttribute.getRuleRows().iterator(); iter.hasNext();) { |
418 |
0
|
Row row = (Row) iter.next(); |
419 |
0
|
for (Iterator iterator = row.getFields().iterator(); iterator.hasNext();) { |
420 |
0
|
Field field = (Field) iterator.next(); |
421 |
0
|
if(field.getFieldType().equals(Field.QUICKFINDER)){ |
422 |
0
|
assertTrue("Did not find quickfinder.", true); |
423 |
|
} |
424 |
|
} |
425 |
|
} |
426 |
0
|
assertTrue("Should have 2 rows and 3 fields: chart, org, and quickfinder.", myAttribute.getRuleRows().size() == 2); |
427 |
|
} |
428 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
4
-
|
|
429 |
0
|
@Test public void testGetRoutingDataRows() {... |
430 |
0
|
assertTrue("Invalid number of routing data rows",attribute.getRoutingDataRows().size() == 4); |
431 |
|
} |
432 |
|
|
|
|
| 0% |
Uncovered Elements: 43 (43) |
Complexity: 3 |
Complexity Density: 0.07 |
4
-
|
|
433 |
0
|
@Test public void testGetDocContent() {... |
434 |
|
|
435 |
0
|
Map paramMap = new HashMap(); |
436 |
0
|
paramMap.put("givenname", "Dave"); |
437 |
0
|
paramMap.put("gender", "female"); |
438 |
0
|
paramMap.put("color", "green"); |
439 |
0
|
paramMap.put("totalDollar", "500"); |
440 |
|
|
441 |
0
|
attribute.setParamMap(paramMap); |
442 |
0
|
try{ |
443 |
0
|
XPath xpath = XPathFactory.newInstance().newXPath(); |
444 |
0
|
Element element = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new BufferedReader(new StringReader(attribute.getDocContent())))).getDocumentElement(); |
445 |
|
|
446 |
0
|
String findStuff = "//xmlRouting/field[@name='givenname']/value"; |
447 |
0
|
assertTrue("Document content does not contain field givenname with value of Dave.", "Dave".equals(xpath.evaluate(findStuff, element, XPathConstants.STRING))); |
448 |
|
|
449 |
0
|
findStuff = "//xmlRouting/field[@name='gender']/value"; |
450 |
0
|
assertTrue("Document content does not contain field gender with value of female.", "female".equals(xpath.evaluate(findStuff, element, XPathConstants.STRING))); |
451 |
|
|
452 |
0
|
findStuff = "//xmlRouting/field[@name='color']/value"; |
453 |
0
|
assertTrue("Document content does not contain field color with value of green.", "green".equals(xpath.evaluate(findStuff, element, XPathConstants.STRING))); |
454 |
|
|
455 |
0
|
findStuff = "//xmlRouting/field[@name='totalDollar']/value"; |
456 |
0
|
assertTrue("Document content does not contain field totalDollar with value of 500.", "500".equals(xpath.evaluate(findStuff, element, XPathConstants.STRING))); |
457 |
|
} catch (Exception e){ |
458 |
0
|
e.printStackTrace(); |
459 |
|
} |
460 |
|
|
461 |
|
|
462 |
0
|
String routingConfig = |
463 |
|
"<routingConfig>" + |
464 |
|
"<fieldDef name=\"myname\" title=\"First name\" workflowType=\"ALL\">"+ |
465 |
|
"<value>Joe</value>"+ |
466 |
|
"<display>"+ |
467 |
|
"<type>text</type>"+ |
468 |
|
"<meta><name>size</name><value>20</value></meta>"+ |
469 |
|
"</display>"+ |
470 |
|
"<fieldEvaluation><xpathexpression>//putWhateverWordsIwantInsideThisTag/myname/value = wf:ruledata('myname')</xpathexpression></fieldEvaluation>"+ |
471 |
|
"</fieldDef>"+ |
472 |
|
"<fieldDef name=\"theGender\" title=\"Gender\" workflowType=\"ALL\">"+ |
473 |
|
"<value>male</value>"+ |
474 |
|
"<display>"+ |
475 |
|
"<type>radio</type>"+ |
476 |
|
"<values title=\"Male\">male</values>"+ |
477 |
|
"<values title=\"Female\">female</values>"+ |
478 |
|
"</display>"+ |
479 |
|
"<fieldEvaluation><xpathexpression>//putWhateverWordsIwantInsideThisTag/theGender/value = wf:ruledata('theGender')</xpathexpression></fieldEvaluation>"+ |
480 |
|
"</fieldDef>"+ |
481 |
|
"<fieldDef name=\"myFavoriteColor\" title=\"Color\" workflowType=\"ALL\">" + |
482 |
|
"<value>blue</value>" + |
483 |
|
"<display>" + |
484 |
|
"<type>select</type>" + |
485 |
|
"<values title=\"Red\">red</values>" + |
486 |
|
"<values title=\"Green\">green</values>" + |
487 |
|
"<values title=\"Blue\" selected=\"true\">blue</values>" + |
488 |
|
"</display>" + |
489 |
|
"<fieldEvaluation><xpathexpression>//putWhateverWordsIwantInsideThisTag/myFavoriteColor/value = wf:ruledata('myFavoriteColor')</xpathexpression></fieldEvaluation>"+ |
490 |
|
"</fieldDef>"+ |
491 |
|
"<fieldDef name=\"maxDollar\" title=\"Max dollar\" workflowType=\"RULE\">" + |
492 |
|
"<display>" + |
493 |
|
"<type>text</type>" + |
494 |
|
"</display>" + |
495 |
|
"<fieldEvaluation><xpathexpression>//putWhateverWordsIwantInsideThisTag/myMoney/value <= wf:ruledata('maxDollar')</xpathexpression></fieldEvaluation>"+ |
496 |
|
"</fieldDef>"+ |
497 |
|
"<fieldDef name=\"minDollar\" title=\"Min dollar\" workflowType=\"RULE\">" + |
498 |
|
"<display>" + |
499 |
|
"<type>text</type>" + |
500 |
|
"</display>" + |
501 |
|
"<fieldEvaluation><xpathexpression>//putWhateverWordsIwantInsideThisTag/myMoney/value >= wf:ruledata('minDollar')</xpathexpression></fieldEvaluation>"+ |
502 |
|
"</fieldDef>"+ |
503 |
|
"<fieldDef name=\"myMoney\" title=\"Total dollar\" workflowType=\"REPORT\">" + |
504 |
|
"<display>" + |
505 |
|
"<type>text</type>" + |
506 |
|
"</display>" + |
507 |
|
"</fieldDef>"+ |
508 |
|
|
509 |
|
"<xmlDocumentContent>"+ |
510 |
|
"<putWhateverWordsIwantInsideThisTag>"+ |
511 |
|
"<myname>"+ |
512 |
|
"<value>%myname%</value>"+ |
513 |
|
"</myname>"+ |
514 |
|
"<theGender>"+ |
515 |
|
"<value>%theGender%</value>"+ |
516 |
|
"</theGender>"+ |
517 |
|
"<myFavoriteColor>"+ |
518 |
|
"<value>%myFavoriteColor%</value>"+ |
519 |
|
"</myFavoriteColor>"+ |
520 |
|
"<myMoney>"+ |
521 |
|
"<value>%myMoney%</value>"+ |
522 |
|
"</myMoney>"+ |
523 |
|
"</putWhateverWordsIwantInsideThisTag>"+ |
524 |
|
"</xmlDocumentContent>"+ |
525 |
|
"</routingConfig>"; |
526 |
0
|
try { |
527 |
0
|
paramMap = new HashMap(); |
528 |
0
|
paramMap.put("myname", "jack"); |
529 |
0
|
paramMap.put("theGender", "male"); |
530 |
0
|
paramMap.put("myFavoriteColor", "blue"); |
531 |
0
|
paramMap.put("myMoney", "10"); |
532 |
|
|
533 |
0
|
attribute.setParamMap(paramMap); |
534 |
|
|
535 |
0
|
RuleAttribute ruleAttribute = new RuleAttribute(); |
536 |
0
|
ruleAttribute.setXmlConfigData(routingConfig); |
537 |
0
|
ruleAttribute.setName("MyUniqueRuleAttribute2"); |
538 |
0
|
attribute.setRuleAttribute(ruleAttribute); |
539 |
|
|
540 |
0
|
String docContent = attribute.getDocContent(); |
541 |
0
|
assertTrue("DocContent was not found.", docContent != null && docContent.length() > 0); |
542 |
|
|
543 |
|
|
544 |
0
|
XPath xpath = XPathFactory.newInstance().newXPath(); |
545 |
0
|
Element foundDocContent = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new BufferedReader(new StringReader(docContent)))).getDocumentElement(); |
546 |
|
|
547 |
0
|
String findStuff = "//putWhateverWordsIwantInsideThisTag/myMoney/value"; |
548 |
0
|
assertTrue("Document content does not contain field myMoney with a value of 10.", "10".equals(xpath.evaluate(findStuff, foundDocContent, XPathConstants.STRING))); |
549 |
|
|
550 |
0
|
findStuff = "//putWhateverWordsIwantInsideThisTag/myFavoriteColor/value"; |
551 |
0
|
assertTrue("Document content does not contain field myFavoriteColor with value of blue.", "blue".equals(xpath.evaluate(findStuff, foundDocContent, XPathConstants.STRING))); |
552 |
|
|
553 |
0
|
findStuff = "//putWhateverWordsIwantInsideThisTag/theGender/value"; |
554 |
0
|
assertTrue("Document content does not contain field theGender with value of male.", "male".equals(xpath.evaluate(findStuff, foundDocContent, XPathConstants.STRING))); |
555 |
|
|
556 |
0
|
findStuff = "//putWhateverWordsIwantInsideThisTag/myname/value"; |
557 |
0
|
assertTrue("Document content does not contain field myname with value of jack.", "jack".equals(xpath.evaluate(findStuff, foundDocContent, XPathConstants.STRING))); |
558 |
|
|
559 |
|
} catch(Exception e){ |
560 |
0
|
e.printStackTrace(); |
561 |
|
} |
562 |
|
} |
563 |
|
} |