Source Code Cross Referenced for StandardGenericXMLRuleAttributeTest.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » routetemplate » xmlrouting » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » edu.iu.uis.eden.routetemplate.xmlrouting 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 The Kuali Foundation.
003:         * 
004:         * 
005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         * 
009:         * http://www.opensource.org/licenses/ecl1.php
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package edu.iu.uis.eden.routetemplate.xmlrouting;
018:
019:        import java.io.BufferedReader;
020:        import java.io.StringReader;
021:        import java.util.ArrayList;
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.Map;
026:
027:        import javax.xml.parsers.DocumentBuilderFactory;
028:        import javax.xml.xpath.XPath;
029:        import javax.xml.xpath.XPathConstants;
030:        import javax.xml.xpath.XPathFactory;
031:
032:        import org.junit.Test;
033:        import org.kuali.workflow.test.WorkflowTestCase;
034:        import org.w3c.dom.Element;
035:        import org.xml.sax.InputSource;
036:
037:        import edu.iu.uis.eden.clientapp.WorkflowDocument;
038:        import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
039:        import edu.iu.uis.eden.clientapp.vo.WorkflowAttributeDefinitionVO;
040:        import edu.iu.uis.eden.exception.WorkflowException;
041:        import edu.iu.uis.eden.lookupable.Field;
042:        import edu.iu.uis.eden.lookupable.Row;
043:        import edu.iu.uis.eden.routeheader.DocumentContent;
044:        import edu.iu.uis.eden.routeheader.StandardDocumentContent;
045:        import edu.iu.uis.eden.routetemplate.RuleAttribute;
046:        import edu.iu.uis.eden.routetemplate.RuleExtension;
047:        import edu.iu.uis.eden.routetemplate.RuleExtensionValue;
048:        import edu.iu.uis.eden.routetemplate.RuleTemplateAttribute;
049:
050:        public class StandardGenericXMLRuleAttributeTest extends
051:                WorkflowTestCase {
052:
053:            private DocumentContent docContent;
054:            private StandardGenericXMLRuleAttribute attribute;
055:            private List extensions;
056:
057:            public void setUp() throws Exception {
058:                super .setUp();
059:                attribute = new StandardGenericXMLRuleAttribute();
060:                String documentcontent = "<documentContent>"
061:                        + "<attributeContent>" + "<xmlContent>"
062:                        + "<fieldDef name=\"givenname\">"
063:                        + "<value>Dave</value>" + "</fieldDef>"
064:                        + "<fieldDef name=\"gender\">"
065:                        + "<value>female</value>" + "</fieldDef>"
066:                        + "<fieldDef name=\"color\">" + "<value>green</value>"
067:                        + "</fieldDef>" + "<fieldDef name=\"totalDollar\">"
068:                        + "<value>500</value>" + "</fieldDef>"
069:                        + "</xmlContent>" + "<xmlContent>"
070:                        + "<fieldDef name=\"givenname\">"
071:                        + "<value>Jane</value>" + "</fieldDef>"
072:                        + "<fieldDef name=\"gender\">"
073:                        + "<value>female</value>" + "</fieldDef>"
074:                        + "<fieldDef name=\"color\">" + "<value>blue</value>"
075:                        + "</fieldDef>" + "<fieldDef name=\"totalDollar\">"
076:                        + "<value>400</value>" + "</fieldDef>"
077:                        + "</xmlContent>" + "</attributeContent>"
078:                        + "</documentContent>";
079:
080:                String routingConfig = "<routingConfig>"
081:                        + "<globalEvaluations>"
082:                        + "<xpathexpression>//fieldDef/value != 'Nothing'</xpathexpression>"
083:                        + "</globalEvaluations>"
084:                        +
085:
086:                        "<fieldDef name=\"givenname\" title=\"First name\" workflowType=\"ALL\">"
087:                        + "<value>Joe</value>"
088:                        + "<display>"
089:                        + "<type>text</type>"
090:                        + "<meta><name>size</name><value>20</value></meta>"
091:                        + "</display>"
092:                        + "<validation required=\"true\">"
093:                        + "<regex>^[a-zA-Z ]+$</regex>"
094:                        + "<message>Invalid first name</message>"
095:                        + "</validation>"
096:                        + "<fieldEvaluation><xpathexpression>//xmlContent/fieldDef[@name='givenname']/value = wf:ruledata('givenname')</xpathexpression></fieldEvaluation>"
097:                        + "</fieldDef>"
098:                        + "<fieldDef name=\"gender\" title=\"Gender\" workflowType=\"ALL\">"
099:                        + "<value>male</value>"
100:                        + "<display>"
101:                        + "<type>radio</type>"
102:                        + "<values title=\"Male\">male</values>"
103:                        + "<values title=\"Female\">female</values>"
104:                        + "</display>"
105:                        + "<validation required=\"true\">"
106:                        + "<regex>(male|female)</regex>"
107:                        + "<message>Invalid gender</message>"
108:                        + "</validation>"
109:                        + "<fieldEvaluation><xpathexpression>//xmlContent/fieldDef[@name='gender']/value = wf:ruledata('gender')</xpathexpression></fieldEvaluation>"
110:                        + "</fieldDef>"
111:                        + "<fieldDef name=\"color\" title=\"Color\" workflowType=\"ALL\">"
112:                        + "<value>blue</value>"
113:                        + "<display>"
114:                        + "<type>select</type>"
115:                        + "<values title=\"Red\">red</values>"
116:                        + "<values title=\"Green\">green</values>"
117:                        + "<values title=\"Blue\" selected=\"true\">blue</values>"
118:                        + "</display>"
119:                        + "<validation required=\"true\">"
120:                        + "<regex>(red|green|blue|)</regex>"
121:                        + "<message>Invalid color</message>"
122:                        + "</validation>"
123:                        + "<fieldEvaluation><xpathexpression>//xmlContent/fieldDef[@name='color']/value = wf:ruledata('color')</xpathexpression></fieldEvaluation>"
124:                        + "</fieldDef>"
125:                        + "<fieldDef name=\"maxDollar\" title=\"Max dollar\" workflowType=\"RULE\">"
126:                        + "<display>"
127:                        + "<type>text</type>"
128:                        + "</display>"
129:                        + "<fieldEvaluation><xpathexpression>//xmlContent/fieldDef[@name='totalDollar']/value &lt;= wf:ruledata('maxDollar')</xpathexpression></fieldEvaluation>"
130:                        + "</fieldDef>"
131:                        + "<fieldDef name=\"minDollar\" title=\"Min dollar\" workflowType=\"RULE\">"
132:                        + "<display>"
133:                        + "<type>text</type>"
134:                        + "</display>"
135:                        + "<fieldEvaluation><xpathexpression>//xmlContent/fieldDef[@name='totalDollar']/value &gt;= wf:ruledata('minDollar')</xpathexpression></fieldEvaluation>"
136:                        + "</fieldDef>"
137:                        + "<fieldDef name=\"totalDollar\" title=\"Total dollar\" workflowType=\"REPORT\">"
138:                        + "<display>" + "<type>text</type>" + "</display>"
139:                        + "</fieldDef>" + "</routingConfig>";
140:
141:                docContent = new StandardDocumentContent(documentcontent);
142:                RuleAttribute ruleAttribute = new RuleAttribute();
143:                ruleAttribute.setXmlConfigData(routingConfig);
144:                ruleAttribute.setName("MyUniqueRuleAttribute1");
145:                attribute.setRuleAttribute(ruleAttribute);
146:            }
147:
148:            @Test
149:            public void testValidateRoutingData() {
150:                Map paramMap = new HashMap();
151:                paramMap.put("givenname", "Dave");
152:                paramMap.put("gender", "female");
153:                paramMap.put("color", "green");
154:                paramMap.put("totalDollar", "500");
155:
156:                assertTrue("Errors found", attribute.validateRoutingData(
157:                        paramMap).isEmpty());
158:            }
159:
160:            @Test
161:            public void testValidateRuleData() {
162:                Map paramMap = new HashMap();
163:                paramMap.put("givenname", "Dave");
164:                paramMap.put("gender", "female");
165:                paramMap.put("color", "green");
166:                paramMap.put("totalDollar", "500");
167:
168:                assertTrue("Errors found", attribute.validateRuleData(paramMap)
169:                        .isEmpty());
170:
171:                paramMap = new HashMap();
172:                paramMap.put("givenname", "4444");
173:                paramMap.put("gender", "crap");
174:                paramMap.put("color", "green");
175:                paramMap.put("totalDollar", "500");
176:
177:                assertFalse("Error list should contain at least one error.",
178:                        attribute.validateRuleData(paramMap).isEmpty());
179:
180:                paramMap = new HashMap();
181:                paramMap.put("givenname", "");
182:                paramMap.put("gender", "female");
183:                paramMap.put("color", "green");
184:                paramMap.put("totalDollar", "500");
185:
186:                assertFalse("givenname should be required.", attribute
187:                        .validateRuleData(paramMap).isEmpty());
188:            }
189:
190:            /**
191:             * Tests SGXA attribute matching behavior with extension value keys that do not necessarily match
192:             * a field defined in the attribute
193:             */
194:            @Test
195:            public void testNonMatchingExtensionKey() throws WorkflowException {
196:                loadXmlFile("TestExtensionValueMatching.xml");
197:                WorkflowDocument doc = new WorkflowDocument(new NetworkIdVO(
198:                        "arh14"), "TestDocument");
199:
200:                WorkflowAttributeDefinitionVO attr = new WorkflowAttributeDefinitionVO(
201:                        StandardGenericXMLRuleAttribute.class.getName());
202:                attr.setAttributeName("Attr1");
203:                // expected to match RuleTemplate with extension value: value='1' with xpath expression /xmlRouting/field[@name=attr1] = wf:ruledata('value')
204:                attr.addProperty("attr1", "2");
205:                doc.addAttributeDefinition(attr);
206:
207:                doc.routeDocument("");
208:
209:                Long id = doc.getRouteHeaderId();
210:
211:                doc = new WorkflowDocument(new NetworkIdVO("user1"), id);
212:                assertFalse("Unexpected approval request to user1", doc
213:                        .isApprovalRequested());
214:
215:                doc = new WorkflowDocument(new NetworkIdVO("user2"), id);
216:                assertTrue("Expected approval request to user2", doc
217:                        .isApprovalRequested());
218:            }
219:
220:            /*
221:             * Test method for 'edu.iu.uis.eden.routetemplate.xmlrouting.StandardGenericXMLRuleAttribute.isMatch(DocumentContent, List)'
222:             */
223:            @Test
224:            public void testIsMatch() {
225:                RuleExtension extension = new RuleExtension();
226:
227:                List values = new ArrayList();
228:                RuleExtensionValue value = new RuleExtensionValue();
229:                value.setKey("givenname");
230:                value.setValue("Dave");
231:                values.add(value);
232:
233:                RuleExtensionValue value2 = new RuleExtensionValue();
234:                value2.setKey("gender");
235:                value2.setValue("female");
236:                values.add(value2);
237:
238:                RuleExtensionValue value3 = new RuleExtensionValue();
239:                value3.setKey("color");
240:                value3.setValue("green");
241:                values.add(value3);
242:
243:                extension.setExtensionValues(values);
244:                RuleTemplateAttribute ruleTemplateAttribute = new RuleTemplateAttribute();
245:
246:                RuleAttribute ruleAttribute = new RuleAttribute();
247:                ruleAttribute.setName("MyUniqueRuleAttribute1");
248:
249:                ruleTemplateAttribute.setRuleAttribute(ruleAttribute);
250:                extension.setRuleTemplateAttribute(ruleTemplateAttribute);
251:                RuleExtension extension2 = new RuleExtension();
252:
253:                List values2 = new ArrayList();
254:                RuleExtensionValue valueNew = new RuleExtensionValue();
255:                valueNew.setKey("givenname");
256:                valueNew.setValue("Jack");
257:
258:                values2.add(valueNew);
259:                extension2.setExtensionValues(values2);
260:                RuleTemplateAttribute ruleTemplateAttribute2 = new RuleTemplateAttribute();
261:
262:                RuleAttribute ruleAttribute2 = new RuleAttribute();
263:                ruleAttribute2.setName("MyUniqueRuleAttribute2");
264:
265:                ruleTemplateAttribute2.setRuleAttribute(ruleAttribute2);
266:                extension2.setRuleTemplateAttribute(ruleTemplateAttribute2);
267:
268:                extensions = new ArrayList();
269:                extensions.add(extension);
270:                extensions.add(extension2);
271:
272:                assertTrue(
273:                        "Givenname did not match Dave, gender did not match female, or color did not match green",
274:                        attribute.isMatch(docContent, extensions));
275:
276:                extension = new RuleExtension();
277:                values = new ArrayList();
278:                RuleExtensionValue value4 = new RuleExtensionValue();
279:                value4.setKey("givenname");
280:                value4.setValue("Dave");
281:                values.add(value4);
282:
283:                RuleExtensionValue value5 = new RuleExtensionValue();
284:                value5.setKey("gender");
285:                value5.setValue("male");
286:                values.add(value5);
287:
288:                RuleExtensionValue value6 = new RuleExtensionValue();
289:                value6.setKey("color");
290:                value6.setValue("green");
291:                values.add(value6);
292:
293:                extension.setExtensionValues(values);
294:                ruleTemplateAttribute = new RuleTemplateAttribute();
295:
296:                ruleAttribute = new RuleAttribute();
297:                ruleAttribute.setName("MyUniqueRuleAttribute1");
298:
299:                ruleTemplateAttribute.setRuleAttribute(ruleAttribute);
300:                extension.setRuleTemplateAttribute(ruleTemplateAttribute);
301:
302:                values2 = new ArrayList();
303:                valueNew = new RuleExtensionValue();
304:                valueNew.setKey("givenname");
305:                valueNew.setValue("Jack");
306:
307:                values2.add(valueNew);
308:                extension2.setExtensionValues(values2);
309:                ruleTemplateAttribute2 = new RuleTemplateAttribute();
310:
311:                ruleAttribute2 = new RuleAttribute();
312:                ruleAttribute2.setName("MyUniqueRuleAttribute2");
313:
314:                ruleTemplateAttribute2.setRuleAttribute(ruleAttribute2);
315:                extension2.setRuleTemplateAttribute(ruleTemplateAttribute2);
316:
317:                extensions = new ArrayList();
318:                extensions.add(extension);
319:                extensions.add(extension2);
320:                assertFalse("Gender female != male.", attribute.isMatch(
321:                        docContent, extensions));
322:
323:                extension = new RuleExtension();
324:                values = new ArrayList();
325:                RuleExtensionValue value7 = new RuleExtensionValue();
326:                value7.setKey("maxDollar");
327:                value7.setValue("500");
328:                values.add(value7);
329:
330:                RuleExtensionValue value8 = new RuleExtensionValue();
331:                value8.setKey("minDollar");
332:                value8.setValue("100");
333:                values.add(value8);
334:
335:                extension.setExtensionValues(values);
336:                ruleTemplateAttribute = new RuleTemplateAttribute();
337:
338:                ruleAttribute = new RuleAttribute();
339:                ruleAttribute.setName("MyUniqueRuleAttribute1");
340:
341:                ruleTemplateAttribute.setRuleAttribute(ruleAttribute);
342:                extension.setRuleTemplateAttribute(ruleTemplateAttribute);
343:
344:                values2 = new ArrayList();
345:                valueNew = new RuleExtensionValue();
346:                valueNew.setKey("givenname");
347:                valueNew.setValue("Jack");
348:
349:                values2.add(valueNew);
350:                extension2.setExtensionValues(values2);
351:                ruleTemplateAttribute2 = new RuleTemplateAttribute();
352:
353:                ruleAttribute2 = new RuleAttribute();
354:                ruleAttribute2.setName("MyUniqueRuleAttribute2");
355:
356:                ruleTemplateAttribute2.setRuleAttribute(ruleAttribute2);
357:                extension2.setRuleTemplateAttribute(ruleTemplateAttribute2);
358:
359:                extensions = new ArrayList();
360:                extensions.add(extension);
361:                extensions.add(extension2);
362:                assertTrue(
363:                        "Total dollar is greater than the max or less than the min.",
364:                        attribute.isMatch(docContent, extensions));
365:            }
366:
367:            /*
368:             * Test method for 'edu.iu.uis.eden.routetemplate.xmlrouting.StandardGenericXMLRuleAttribute.getRuleRows()'
369:             */
370:            @Test
371:            public void testGetRuleRows() {
372:                assertTrue("Invalid number of rule rows", attribute
373:                        .getRuleRows().size() == 5);
374:
375:                String routingConfigWithQuickfinders = "<routingConfig>"
376:                        + "<globalEvaluations>"
377:                        + "<xpathexpression>//field/value != 'Nothing'</xpathexpression>"
378:                        + "</globalEvaluations>"
379:                        +
380:
381:                        "<fieldDef name=\"chart\" title=\"Chart\" workflowType=\"ALL\">"
382:                        + "<value>BL</value>"
383:                        + "<display>"
384:                        + "<type>text</type>"
385:                        + "<meta><name>size</name><value>20</value></meta>"
386:                        + "</display>"
387:                        + "<quickfinder service=\"ChartOrgLookupableImplService\" appliesTo=\"fin_coa_cd\" draw=\"false\"/>"
388:                        + "<fieldEvaluation><xpathexpression>//xmlContent/field[@name='chart']/value = wf:ruledata('chart')</xpathexpression></fieldEvaluation>"
389:                        + "</fieldDef>"
390:                        + "<fieldDef name=\"org\" title=\"Org\" workflowType=\"ALL\">"
391:                        + "<display>"
392:                        + "<type>text</type>"
393:                        + "</display>"
394:                        + "<quickfinder service=\"ChartOrgLookupableImplService\" appliesTo=\"org_cd\" draw=\"true\" />"
395:                        + "<fieldEvaluation><xpathexpression>//xmlContent/field[@name='gender']/value = wf:ruledata('gender')</xpathexpression></fieldEvaluation>"
396:                        + "</fieldDef>" + "</routingConfig>";
397:
398:                RuleAttribute ruleAttribute = new RuleAttribute();
399:                ruleAttribute.setXmlConfigData(routingConfigWithQuickfinders);
400:                ruleAttribute.setName("MyUniqueRuleAttribute3");
401:                StandardGenericXMLRuleAttribute myAttribute = new StandardGenericXMLRuleAttribute();
402:                myAttribute.setRuleAttribute(ruleAttribute);
403:
404:                for (Iterator iter = myAttribute.getRuleRows().iterator(); iter
405:                        .hasNext();) {
406:                    Row row = (Row) iter.next();
407:                    for (Iterator iterator = row.getFields().iterator(); iterator
408:                            .hasNext();) {
409:                        Field field = (Field) iterator.next();
410:                        if (field.getFieldType().equals(Field.QUICKFINDER)) {
411:                            assertTrue("Did not find quickfinder.", true);
412:                        }
413:                    }
414:                }
415:                assertTrue(
416:                        "Should have 2 rows and 3 fields: chart, org, and quickfinder.",
417:                        myAttribute.getRuleRows().size() == 2);
418:            }
419:
420:            @Test
421:            public void testGetRoutingDataRows() {
422:                assertTrue("Invalid number of routing data rows", attribute
423:                        .getRoutingDataRows().size() == 4);
424:            }
425:
426:            @Test
427:            public void testGetDocContent() {
428:                //test the standard doc content...
429:                Map paramMap = new HashMap();
430:                paramMap.put("givenname", "Dave");
431:                paramMap.put("gender", "female");
432:                paramMap.put("color", "green");
433:                paramMap.put("totalDollar", "500");
434:
435:                attribute.setParamMap(paramMap);
436:                try {
437:                    XPath xpath = XPathFactory.newInstance().newXPath();
438:                    Element element = DocumentBuilderFactory.newInstance()
439:                            .newDocumentBuilder().parse(
440:                                    new InputSource(new BufferedReader(
441:                                            new StringReader(attribute
442:                                                    .getDocContent()))))
443:                            .getDocumentElement();
444:
445:                    String findStuff = "//xmlRouting/field[@name='givenname']/value";
446:                    assertTrue(
447:                            "Document content does not contain field givenname with value of Dave.",
448:                            "Dave".equals(xpath.evaluate(findStuff, element,
449:                                    XPathConstants.STRING)));
450:
451:                    findStuff = "//xmlRouting/field[@name='gender']/value";
452:                    assertTrue(
453:                            "Document content does not contain field gender with value of female.",
454:                            "female".equals(xpath.evaluate(findStuff, element,
455:                                    XPathConstants.STRING)));
456:
457:                    findStuff = "//xmlRouting/field[@name='color']/value";
458:                    assertTrue(
459:                            "Document content does not contain field color with value of green.",
460:                            "green".equals(xpath.evaluate(findStuff, element,
461:                                    XPathConstants.STRING)));
462:
463:                    findStuff = "//xmlRouting/field[@name='totalDollar']/value";
464:                    assertTrue(
465:                            "Document content does not contain field totalDollar with value of 500.",
466:                            "500".equals(xpath.evaluate(findStuff, element,
467:                                    XPathConstants.STRING)));
468:                } catch (Exception e) {
469:                    e.printStackTrace();
470:                }
471:
472:                // Now test the custom doc content...
473:                String routingConfig = "<routingConfig>"
474:                        + "<fieldDef name=\"myname\" title=\"First name\" workflowType=\"ALL\">"
475:                        + "<value>Joe</value>"
476:                        + "<display>"
477:                        + "<type>text</type>"
478:                        + "<meta><name>size</name><value>20</value></meta>"
479:                        + "</display>"
480:                        + "<fieldEvaluation><xpathexpression>//putWhateverWordsIwantInsideThisTag/myname/value = wf:ruledata('myname')</xpathexpression></fieldEvaluation>"
481:                        + "</fieldDef>"
482:                        + "<fieldDef name=\"theGender\" title=\"Gender\" workflowType=\"ALL\">"
483:                        + "<value>male</value>"
484:                        + "<display>"
485:                        + "<type>radio</type>"
486:                        + "<values title=\"Male\">male</values>"
487:                        + "<values title=\"Female\">female</values>"
488:                        + "</display>"
489:                        + "<fieldEvaluation><xpathexpression>//putWhateverWordsIwantInsideThisTag/theGender/value = wf:ruledata('theGender')</xpathexpression></fieldEvaluation>"
490:                        + "</fieldDef>"
491:                        + "<fieldDef name=\"myFavoriteColor\" title=\"Color\" workflowType=\"ALL\">"
492:                        + "<value>blue</value>"
493:                        + "<display>"
494:                        + "<type>select</type>"
495:                        + "<values title=\"Red\">red</values>"
496:                        + "<values title=\"Green\">green</values>"
497:                        + "<values title=\"Blue\" selected=\"true\">blue</values>"
498:                        + "</display>"
499:                        + "<fieldEvaluation><xpathexpression>//putWhateverWordsIwantInsideThisTag/myFavoriteColor/value = wf:ruledata('myFavoriteColor')</xpathexpression></fieldEvaluation>"
500:                        + "</fieldDef>"
501:                        + "<fieldDef name=\"maxDollar\" title=\"Max dollar\" workflowType=\"RULE\">"
502:                        + "<display>"
503:                        + "<type>text</type>"
504:                        + "</display>"
505:                        + "<fieldEvaluation><xpathexpression>//putWhateverWordsIwantInsideThisTag/myMoney/value &lt;= wf:ruledata('maxDollar')</xpathexpression></fieldEvaluation>"
506:                        + "</fieldDef>"
507:                        + "<fieldDef name=\"minDollar\" title=\"Min dollar\" workflowType=\"RULE\">"
508:                        + "<display>"
509:                        + "<type>text</type>"
510:                        + "</display>"
511:                        + "<fieldEvaluation><xpathexpression>//putWhateverWordsIwantInsideThisTag/myMoney/value &gt;= wf:ruledata('minDollar')</xpathexpression></fieldEvaluation>"
512:                        + "</fieldDef>"
513:                        + "<fieldDef name=\"myMoney\" title=\"Total dollar\" workflowType=\"REPORT\">"
514:                        + "<display>" + "<type>text</type>" + "</display>"
515:                        + "</fieldDef>" +
516:
517:                        "<xmlDocumentContent>"
518:                        + "<putWhateverWordsIwantInsideThisTag>" + "<myname>"
519:                        + "<value>%myname%</value>" + "</myname>"
520:                        + "<theGender>" + "<value>%theGender%</value>"
521:                        + "</theGender>" + "<myFavoriteColor>"
522:                        + "<value>%myFavoriteColor%</value>"
523:                        + "</myFavoriteColor>" + "<myMoney>"
524:                        + "<value>%myMoney%</value>" + "</myMoney>"
525:                        + "</putWhateverWordsIwantInsideThisTag>"
526:                        + "</xmlDocumentContent>" + "</routingConfig>";
527:                try {
528:                    paramMap = new HashMap();
529:                    paramMap.put("myname", "jack");
530:                    paramMap.put("theGender", "male");
531:                    paramMap.put("myFavoriteColor", "blue");
532:                    paramMap.put("myMoney", "10");
533:
534:                    attribute.setParamMap(paramMap);
535:
536:                    RuleAttribute ruleAttribute = new RuleAttribute();
537:                    ruleAttribute.setXmlConfigData(routingConfig);
538:                    ruleAttribute.setName("MyUniqueRuleAttribute2");
539:                    attribute.setRuleAttribute(ruleAttribute);
540:
541:                    String docContent = attribute.getDocContent();
542:                    assertTrue("DocContent was not found.", docContent != null
543:                            && docContent.length() > 0);
544:
545:                    XPath xpath = XPathFactory.newInstance().newXPath();
546:                    Element foundDocContent = DocumentBuilderFactory
547:                            .newInstance().newDocumentBuilder().parse(
548:                                    new InputSource(new BufferedReader(
549:                                            new StringReader(docContent))))
550:                            .getDocumentElement();
551:
552:                    String findStuff = "//putWhateverWordsIwantInsideThisTag/myMoney/value";
553:                    assertTrue(
554:                            "Document content does not contain field myMoney with a value of 10.",
555:                            "10".equals(xpath.evaluate(findStuff,
556:                                    foundDocContent, XPathConstants.STRING)));
557:
558:                    findStuff = "//putWhateverWordsIwantInsideThisTag/myFavoriteColor/value";
559:                    assertTrue(
560:                            "Document content does not contain field myFavoriteColor with value of blue.",
561:                            "blue".equals(xpath.evaluate(findStuff,
562:                                    foundDocContent, XPathConstants.STRING)));
563:
564:                    findStuff = "//putWhateverWordsIwantInsideThisTag/theGender/value";
565:                    assertTrue(
566:                            "Document content does not contain field theGender with value of male.",
567:                            "male".equals(xpath.evaluate(findStuff,
568:                                    foundDocContent, XPathConstants.STRING)));
569:
570:                    findStuff = "//putWhateverWordsIwantInsideThisTag/myname/value";
571:                    assertTrue(
572:                            "Document content does not contain field myname with value of jack.",
573:                            "jack".equals(xpath.evaluate(findStuff,
574:                                    foundDocContent, XPathConstants.STRING)));
575:
576:                } catch (Exception e) {
577:                    e.printStackTrace();
578:                }
579:            }
580:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.