Source Code Cross Referenced for StandardGenericXMLSearchableAttributeTest.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » docsearch » xml » 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.docsearch.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2005-2007 The Kuali Foundation.
0003:         * 
0004:         * 
0005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
0006:         * you may not use this file except in compliance with the License.
0007:         * You may obtain a copy of the License at
0008:         * 
0009:         * http://www.opensource.org/licenses/ecl1.php
0010:         * 
0011:         * Unless required by applicable law or agreed to in writing, software
0012:         * distributed under the License is distributed on an "AS IS" BASIS,
0013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         * See the License for the specific language governing permissions and
0015:         * limitations under the License.
0016:         */
0017:        package edu.iu.uis.eden.docsearch.xml;
0018:
0019:        import java.io.BufferedReader;
0020:        import java.io.StringReader;
0021:        import java.sql.Timestamp;
0022:        import java.util.Calendar;
0023:        import java.util.HashMap;
0024:        import java.util.Iterator;
0025:        import java.util.List;
0026:        import java.util.Map;
0027:
0028:        import javax.xml.parsers.DocumentBuilderFactory;
0029:        import javax.xml.xpath.XPath;
0030:        import javax.xml.xpath.XPathConstants;
0031:        import javax.xml.xpath.XPathFactory;
0032:
0033:        import org.junit.Ignore;
0034:        import org.junit.Test;
0035:        import org.kuali.workflow.test.WorkflowTestCase;
0036:        import org.w3c.dom.Element;
0037:        import org.xml.sax.InputSource;
0038:
0039:        import edu.iu.uis.eden.KEWServiceLocator;
0040:        import edu.iu.uis.eden.WorkflowServiceErrorException;
0041:        import edu.iu.uis.eden.clientapp.WorkflowDocument;
0042:        import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
0043:        import edu.iu.uis.eden.clientapp.vo.WorkflowAttributeDefinitionVO;
0044:        import edu.iu.uis.eden.docsearch.DocSearchCriteriaVO;
0045:        import edu.iu.uis.eden.docsearch.DocSearchUtils;
0046:        import edu.iu.uis.eden.docsearch.DocumentSearchResult;
0047:        import edu.iu.uis.eden.docsearch.DocumentSearchResultComponents;
0048:        import edu.iu.uis.eden.docsearch.DocumentSearchService;
0049:        import edu.iu.uis.eden.docsearch.SearchAttributeCriteriaComponent;
0050:        import edu.iu.uis.eden.docsearch.SearchableAttribute;
0051:        import edu.iu.uis.eden.docsearch.SearchableAttributeDateTimeValue;
0052:        import edu.iu.uis.eden.docsearch.SearchableAttributeFloatValue;
0053:        import edu.iu.uis.eden.docsearch.SearchableAttributeLongValue;
0054:        import edu.iu.uis.eden.docsearch.SearchableAttributeStringValue;
0055:        import edu.iu.uis.eden.docsearch.SearchableAttributeValue;
0056:        import edu.iu.uis.eden.docsearch.TestXMLSearchableAttributeDateTime;
0057:        import edu.iu.uis.eden.docsearch.TestXMLSearchableAttributeFloat;
0058:        import edu.iu.uis.eden.docsearch.TestXMLSearchableAttributeLong;
0059:        import edu.iu.uis.eden.docsearch.TestXMLSearchableAttributeString;
0060:        import edu.iu.uis.eden.doctype.DocumentType;
0061:        import edu.iu.uis.eden.doctype.DocumentTypeService;
0062:        import edu.iu.uis.eden.exception.WorkflowException;
0063:        import edu.iu.uis.eden.lookupable.Field;
0064:        import edu.iu.uis.eden.lookupable.Row;
0065:        import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
0066:        import edu.iu.uis.eden.routeheader.RouteHeaderService;
0067:        import edu.iu.uis.eden.routetemplate.RuleAttribute;
0068:        import edu.iu.uis.eden.routetemplate.WorkflowAttributeValidationError;
0069:        import edu.iu.uis.eden.user.AuthenticationUserId;
0070:        import edu.iu.uis.eden.user.UserService;
0071:        import edu.iu.uis.eden.user.WorkflowUser;
0072:        import edu.iu.uis.eden.web.KeyValueSort;
0073:
0074:        /**
0075:         * Tests the StandardGenericXMLSearchableAttribute.
0076:         * 
0077:         * KULWF-654: Tests the resolution to this issue by configuring a CustomActionListAttribute as well as a
0078:         * searchable attribute.
0079:         */
0080:        public class StandardGenericXMLSearchableAttributeTest extends
0081:                WorkflowTestCase {
0082:
0083:            protected void loadTestData() throws Exception {
0084:                loadXmlFile("XmlConfig.xml");
0085:            }
0086:
0087:            private StandardGenericXMLSearchableAttribute getAttribute(
0088:                    String name) {
0089:                String attName = name;
0090:                if (attName == null) {
0091:                    attName = "XMLSearchableAttribute";
0092:                }
0093:                RuleAttribute ruleAttribute = KEWServiceLocator
0094:                        .getRuleAttributeService().findByName(attName);
0095:                StandardGenericXMLSearchableAttribute attribute = new StandardGenericXMLSearchableAttribute();
0096:                attribute.setRuleAttribute(ruleAttribute);
0097:                return attribute;
0098:            }
0099:
0100:            private SearchAttributeCriteriaComponent createSearchAttributeCriteriaComponent(
0101:                    String key, String value, DocumentType docType) {
0102:                String formKey = key;
0103:                String savedKey = key;
0104:                SearchAttributeCriteriaComponent sacc = new SearchAttributeCriteriaComponent(
0105:                        formKey, value, savedKey);
0106:                Field field = getFieldByFormKey(docType, formKey);
0107:                if (field != null) {
0108:                    sacc.setSearchableAttributeValue(DocSearchUtils
0109:                            .getSearchableAttributeValueByDataTypeString(field
0110:                                    .getFieldDataType()));
0111:                    sacc.setRangeSearch(field.isMemberOfRange());
0112:                    sacc.setAllowWildcards(field.isAllowingWildcards());
0113:                    sacc.setAutoWildcardBeginning(field
0114:                            .isAutoWildcardAtBeginning());
0115:                    sacc.setAutoWildcardEnd(field.isAutoWildcardAtEnding());
0116:                    sacc.setCaseSensitive(field.isCaseSensitive());
0117:                    sacc.setSearchInclusive(field.isInclusive());
0118:                    sacc.setSearchable(field.isSearchable());
0119:                    sacc.setCanHoldMultipleValues(Field.MULTI_VALUE_FIELD_TYPES
0120:                            .contains(field.getFieldType()));
0121:                }
0122:                return sacc;
0123:            }
0124:
0125:            private Field getFieldByFormKey(DocumentType docType, String formKey) {
0126:                if (docType == null) {
0127:                    return null;
0128:                }
0129:                for (SearchableAttribute searchableAttribute : docType
0130:                        .getSearchableAttributes()) {
0131:                    for (Row row : searchableAttribute.getSearchingRows()) {
0132:                        for (Field field : row.getFields()) {
0133:                            if (field.getPropertyName().equals(formKey)) {
0134:                                return field;
0135:                            }
0136:                        }
0137:                    }
0138:                }
0139:                return null;
0140:            }
0141:
0142:            @Test
0143:            public void testXMLStandardSearchableAttributeWithInvalidValue()
0144:                    throws Exception {
0145:                String documentTypeName = "SearchDocTypeStandardSearchDataType";
0146:                //        DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
0147:                String userNetworkId = "rkirkend";
0148:                WorkflowDocument workflowDocument = new WorkflowDocument(
0149:                        new NetworkIdVO(userNetworkId), documentTypeName);
0150:
0151:                /*
0152:                 *   Below we are using the keys and values from the custom searchable attribute classes' static constants but 
0153:                 *   this is only for convenience as those should always be valid values to test for.
0154:                 */
0155:                // adding string value in what should be a long searchable attribute
0156:                WorkflowAttributeDefinitionVO longXMLDef = new WorkflowAttributeDefinitionVO(
0157:                        "XMLSearchableAttributeStdLong");
0158:                longXMLDef.addProperty(
0159:                        TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0160:                        "123x23");
0161:                workflowDocument.addSearchableDefinition(longXMLDef);
0162:
0163:                workflowDocument.setTitle("Routing style");
0164:                try {
0165:                    workflowDocument.routeDocument("routing this document.");
0166:                    fail("Document should be unroutable with invalid searchable attribute value");
0167:                } catch (Exception e) {
0168:                    e.printStackTrace();
0169:                }
0170:            }
0171:
0172:            @Test
0173:            public void testXMLStandardSearchableAttributesWithDataType()
0174:                    throws Exception {
0175:                String documentTypeName = "SearchDocTypeStandardSearchDataType";
0176:                DocumentType docType = ((DocumentTypeService) KEWServiceLocator
0177:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
0178:                        .findByName(documentTypeName);
0179:                String userNetworkId = "rkirkend";
0180:                WorkflowDocument workflowDocument = new WorkflowDocument(
0181:                        new NetworkIdVO(userNetworkId), documentTypeName);
0182:
0183:                /*
0184:                 *   Below we are using the keys and values from the custom searchable attribute classes' static constants but 
0185:                 *   this is only for convenience as those should always be valid values to test for.
0186:                 */
0187:                int i = 0;
0188:                // adding string searchable attribute
0189:                i++;
0190:                WorkflowAttributeDefinitionVO stringXMLDef = new WorkflowAttributeDefinitionVO(
0191:                        "XMLSearchableAttribute");
0192:                stringXMLDef.addProperty(
0193:                        TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
0194:                        TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE);
0195:                workflowDocument.addSearchableDefinition(stringXMLDef);
0196:                // adding long searchable attribute
0197:                i++;
0198:                WorkflowAttributeDefinitionVO longXMLDef = new WorkflowAttributeDefinitionVO(
0199:                        "XMLSearchableAttributeStdLong");
0200:                longXMLDef.addProperty(
0201:                        TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0202:                        TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE
0203:                                .toString());
0204:                workflowDocument.addSearchableDefinition(longXMLDef);
0205:                // adding float searchable attribute
0206:                i++;
0207:                WorkflowAttributeDefinitionVO floatXMLDef = new WorkflowAttributeDefinitionVO(
0208:                        "XMLSearchableAttributeStdFloat");
0209:                floatXMLDef.addProperty(
0210:                        TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
0211:                        TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE
0212:                                .toString());
0213:                workflowDocument.addSearchableDefinition(floatXMLDef);
0214:                // adding string searchable attribute
0215:                i++;
0216:                WorkflowAttributeDefinitionVO dateXMLDef = new WorkflowAttributeDefinitionVO(
0217:                        "XMLSearchableAttributeStdDateTime");
0218:                dateXMLDef
0219:                        .addProperty(
0220:                                TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
0221:                                DocSearchUtils
0222:                                        .getDisplayValueWithDateOnly(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE));
0223:                workflowDocument.addSearchableDefinition(dateXMLDef);
0224:
0225:                workflowDocument.setTitle("Routing style");
0226:                workflowDocument.routeDocument("routing this document.");
0227:
0228:                workflowDocument = new WorkflowDocument(new NetworkIdVO(
0229:                        userNetworkId), workflowDocument.getRouteHeaderId());
0230:                DocumentRouteHeaderValue doc = KEWServiceLocator
0231:                        .getRouteHeaderService().getRouteHeader(
0232:                                workflowDocument.getRouteHeaderId());
0233:                assertEquals("Wrong number of searchable attributes", i, doc
0234:                        .getSearchableAttributeValues().size());
0235:                for (Iterator iter = doc.getSearchableAttributeValues()
0236:                        .iterator(); iter.hasNext();) {
0237:                    SearchableAttributeValue attributeValue = (SearchableAttributeValue) iter
0238:                            .next();
0239:                    if (attributeValue instanceof  SearchableAttributeStringValue) {
0240:                        SearchableAttributeStringValue realValue = (SearchableAttributeStringValue) attributeValue;
0241:                        assertEquals(
0242:                                "The only String attribute that should have been added has key '"
0243:                                        + TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY
0244:                                        + "'",
0245:                                TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
0246:                                realValue.getSearchableAttributeKey());
0247:                        assertEquals(
0248:                                "The only String attribute that should have been added has value '"
0249:                                        + TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE
0250:                                        + "'",
0251:                                TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE,
0252:                                realValue.getSearchableAttributeValue());
0253:                    } else if (attributeValue instanceof  SearchableAttributeLongValue) {
0254:                        SearchableAttributeLongValue realValue = (SearchableAttributeLongValue) attributeValue;
0255:                        assertEquals(
0256:                                "The only Long attribute that should have been added has key '"
0257:                                        + TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY
0258:                                        + "'",
0259:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0260:                                realValue.getSearchableAttributeKey());
0261:                        assertEquals(
0262:                                "The only Long attribute that should have been added has value '"
0263:                                        + TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE
0264:                                        + "'",
0265:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE,
0266:                                realValue.getSearchableAttributeValue());
0267:                    } else if (attributeValue instanceof  SearchableAttributeFloatValue) {
0268:                        SearchableAttributeFloatValue realValue = (SearchableAttributeFloatValue) attributeValue;
0269:                        assertEquals(
0270:                                "The only Float attribute that should have been added has key '"
0271:                                        + TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY
0272:                                        + "'",
0273:                                TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
0274:                                realValue.getSearchableAttributeKey());
0275:                        assertEquals(
0276:                                "The only Float attribute that should have been added has value '"
0277:                                        + TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY
0278:                                        + "'",
0279:                                TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE,
0280:                                realValue.getSearchableAttributeValue());
0281:                    } else if (attributeValue instanceof  SearchableAttributeDateTimeValue) {
0282:                        SearchableAttributeDateTimeValue realValue = (SearchableAttributeDateTimeValue) attributeValue;
0283:                        assertEquals(
0284:                                "The only DateTime attribute that should have been added has key '"
0285:                                        + TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY
0286:                                        + "'",
0287:                                TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
0288:                                realValue.getSearchableAttributeKey());
0289:                        Calendar testDate = Calendar.getInstance();
0290:                        testDate
0291:                                .setTimeInMillis(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE_IN_MILLS);
0292:                        testDate.set(Calendar.SECOND, 0);
0293:                        testDate.set(Calendar.MILLISECOND, 0);
0294:                        Calendar attributeDate = Calendar.getInstance();
0295:                        attributeDate.setTimeInMillis(realValue
0296:                                .getSearchableAttributeValue().getTime());
0297:                        attributeDate.set(Calendar.SECOND, 0);
0298:                        attributeDate.set(Calendar.MILLISECOND, 0);
0299:                        assertEquals(
0300:                                "The month value for the searchable attribute is wrong",
0301:                                testDate.get(Calendar.MONTH), attributeDate
0302:                                        .get(Calendar.MONTH));
0303:                        assertEquals(
0304:                                "The date value for the searchable attribute is wrong",
0305:                                testDate.get(Calendar.DATE), attributeDate
0306:                                        .get(Calendar.DATE));
0307:                        assertEquals(
0308:                                "The year value for the searchable attribute is wrong",
0309:                                testDate.get(Calendar.YEAR), attributeDate
0310:                                        .get(Calendar.YEAR));
0311:                    } else {
0312:                        fail("Searchable Attribute Value base class should be one of the four checked always");
0313:                    }
0314:                }
0315:
0316:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
0317:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
0318:                UserService userService = (UserService) KEWServiceLocator
0319:                        .getService(KEWServiceLocator.USER_SERVICE);
0320:                WorkflowUser user = userService
0321:                        .getWorkflowUser(new AuthenticationUserId(userNetworkId));
0322:
0323:                DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
0324:                criteria.setDocTypeFullName(documentTypeName);
0325:                criteria
0326:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0327:                                TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
0328:                                TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE,
0329:                                docType));
0330:                DocumentSearchResultComponents result = docSearchService
0331:                        .getList(user, criteria);
0332:                List searchResults = result.getSearchResults();
0333:
0334:                assertEquals("Search results should have one document.", 1,
0335:                        searchResults.size());
0336:
0337:                DocSearchCriteriaVO criteria2 = new DocSearchCriteriaVO();
0338:                criteria2.setDocTypeFullName(documentTypeName);
0339:                criteria2
0340:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0341:                                TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
0342:                                "fred", docType));
0343:                DocumentSearchResultComponents result2 = docSearchService
0344:                        .getList(user, criteria2);
0345:                List searchResults2 = result2.getSearchResults();
0346:
0347:                assertEquals("Search results should be empty.", 0,
0348:                        searchResults2.size());
0349:
0350:                DocSearchCriteriaVO criteria3 = new DocSearchCriteriaVO();
0351:                criteria3.setDocTypeFullName(documentTypeName);
0352:                criteria3
0353:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0354:                                "fakeproperty", "doesntexist", docType));
0355:                DocumentSearchResultComponents result3 = null;
0356:                try {
0357:                    result3 = docSearchService.getList(user, criteria3);
0358:                    fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
0359:                } catch (WorkflowServiceErrorException e) {
0360:                }
0361:
0362:                criteria = null;
0363:                searchResults = null;
0364:                criteria = new DocSearchCriteriaVO();
0365:                criteria.setDocTypeFullName(documentTypeName);
0366:                criteria
0367:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0368:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0369:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE
0370:                                        .toString(), docType));
0371:                result = docSearchService.getList(user, criteria);
0372:                searchResults = result.getSearchResults();
0373:                assertEquals("Search results should have one document.", 1,
0374:                        searchResults.size());
0375:
0376:                criteria2 = null;
0377:                searchResults2 = null;
0378:                criteria2 = new DocSearchCriteriaVO();
0379:                criteria2.setDocTypeFullName(documentTypeName);
0380:                criteria2
0381:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0382:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0383:                                "1111111", docType));
0384:                result2 = docSearchService.getList(user, criteria2);
0385:                searchResults2 = result2.getSearchResults();
0386:                assertEquals("Search results should be empty.", 0,
0387:                        searchResults2.size());
0388:
0389:                criteria3 = null;
0390:                result3 = null;
0391:                criteria3 = new DocSearchCriteriaVO();
0392:                criteria3.setDocTypeFullName(documentTypeName);
0393:                criteria3
0394:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0395:                                "fakeymcfakefake", "99999999", docType));
0396:                try {
0397:                    result3 = docSearchService.getList(user, criteria3);
0398:                    fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
0399:                } catch (WorkflowServiceErrorException e) {
0400:                }
0401:
0402:                criteria = null;
0403:                searchResults = null;
0404:                criteria = new DocSearchCriteriaVO();
0405:                criteria.setDocTypeFullName(documentTypeName);
0406:                criteria
0407:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0408:                                TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
0409:                                TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE
0410:                                        .toString(), docType));
0411:                result = docSearchService.getList(user, criteria);
0412:                searchResults = result.getSearchResults();
0413:                assertEquals("Search results should have one document.", 1,
0414:                        searchResults.size());
0415:
0416:                criteria2 = null;
0417:                searchResults2 = null;
0418:                criteria2 = new DocSearchCriteriaVO();
0419:                criteria2.setDocTypeFullName(documentTypeName);
0420:                criteria2
0421:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0422:                                TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
0423:                                "215.3548", docType));
0424:                result2 = docSearchService.getList(user, criteria2);
0425:                searchResults2 = result2.getSearchResults();
0426:                assertEquals("Search results should be empty.", 0,
0427:                        searchResults2.size());
0428:
0429:                criteria3 = null;
0430:                result3 = null;
0431:                criteria3 = new DocSearchCriteriaVO();
0432:                criteria3.setDocTypeFullName(documentTypeName);
0433:                criteria3
0434:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0435:                                "fakeylostington", "9999.9999", docType));
0436:                try {
0437:                    result3 = docSearchService.getList(user, criteria3);
0438:                    fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
0439:                } catch (WorkflowServiceErrorException e) {
0440:                }
0441:
0442:                criteria = null;
0443:                searchResults = null;
0444:                criteria = new DocSearchCriteriaVO();
0445:                criteria.setDocTypeFullName(documentTypeName);
0446:                criteria
0447:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0448:                                TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
0449:                                DocSearchUtils
0450:                                        .getDisplayValueWithDateOnly(new Timestamp(
0451:                                                TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE_IN_MILLS)),
0452:                                docType));
0453:                result = docSearchService.getList(user, criteria);
0454:                searchResults = result.getSearchResults();
0455:                assertEquals("Search results should have one document.", 1,
0456:                        searchResults.size());
0457:
0458:                criteria2 = null;
0459:                searchResults2 = null;
0460:                criteria2 = new DocSearchCriteriaVO();
0461:                criteria2.setDocTypeFullName(documentTypeName);
0462:                criteria2
0463:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0464:                                TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
0465:                                "07/06/1979", docType));
0466:                result2 = docSearchService.getList(user, criteria2);
0467:                searchResults2 = result2.getSearchResults();
0468:                assertEquals("Search results should be empty.", 0,
0469:                        searchResults2.size());
0470:
0471:                criteria3 = null;
0472:                result3 = null;
0473:                criteria3 = new DocSearchCriteriaVO();
0474:                criteria3.setDocTypeFullName(documentTypeName);
0475:                criteria3
0476:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0477:                                "lastingsfakerson", "07/06/2007", docType));
0478:                try {
0479:                    result3 = docSearchService.getList(user, criteria3);
0480:                    fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
0481:                } catch (WorkflowServiceErrorException e) {
0482:                }
0483:            }
0484:
0485:            @Test
0486:            public void testRouteDocumentWithSearchableAttribute()
0487:                    throws Exception {
0488:                String documentTypeName = "SearchDocType";
0489:                String key = "givenname";
0490:                DocumentType docType = ((DocumentTypeService) KEWServiceLocator
0491:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
0492:                        .findByName(documentTypeName);
0493:                WorkflowDocument workflowDocument = new WorkflowDocument(
0494:                        new NetworkIdVO("rkirkend"), documentTypeName);
0495:                WorkflowAttributeDefinitionVO givennameXMLDef = new WorkflowAttributeDefinitionVO(
0496:                        "XMLSearchableAttribute");
0497:
0498:                workflowDocument.setApplicationContent("<test></test>");
0499:
0500:                givennameXMLDef.addProperty(key, "jack");
0501:                workflowDocument.addSearchableDefinition(givennameXMLDef);
0502:
0503:                workflowDocument.setTitle("Routing style");
0504:                workflowDocument.routeDocument("routing this document.");
0505:
0506:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
0507:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
0508:                UserService userService = (UserService) KEWServiceLocator
0509:                        .getService(KEWServiceLocator.USER_SERVICE);
0510:
0511:                WorkflowUser user = userService
0512:                        .getWorkflowUser(new AuthenticationUserId("rkirkend"));
0513:                DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
0514:                criteria.setDocTypeFullName(documentTypeName);
0515:                criteria
0516:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0517:                                key, "jack", docType));
0518:                DocumentSearchResultComponents result = docSearchService
0519:                        .getList(user, criteria);
0520:                List searchResults = result.getSearchResults();
0521:
0522:                assertEquals("Search results should have one document.", 1,
0523:                        searchResults.size());
0524:
0525:                criteria = null;
0526:                searchResults = null;
0527:                criteria = new DocSearchCriteriaVO();
0528:                criteria.setDocTypeFullName(documentTypeName);
0529:                criteria
0530:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0531:                                key, "fred", docType));
0532:                result = docSearchService.getList(user, criteria);
0533:                searchResults = result.getSearchResults();
0534:
0535:                assertEquals("Search results should be empty.", 0,
0536:                        searchResults.size());
0537:
0538:                criteria = null;
0539:                searchResults = null;
0540:                criteria = new DocSearchCriteriaVO();
0541:                criteria.setDocTypeFullName(documentTypeName);
0542:                criteria
0543:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0544:                                "fakeproperty", "doesntexist", docType));
0545:                try {
0546:                    result = docSearchService.getList(user, criteria);
0547:                    fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
0548:                } catch (WorkflowServiceErrorException wsee) {
0549:                }
0550:            }
0551:
0552:            @Test
0553:            public void testDocumentSearchAttributeWildcarding()
0554:                    throws Exception {
0555:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
0556:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
0557:                UserService userService = (UserService) KEWServiceLocator
0558:                        .getService(KEWServiceLocator.USER_SERVICE);
0559:
0560:                String documentTypeName = "SearchDocType";
0561:                String key = "givenname";
0562:                DocumentType docType = ((DocumentTypeService) KEWServiceLocator
0563:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
0564:                        .findByName(documentTypeName);
0565:                WorkflowDocument workflowDocument = new WorkflowDocument(
0566:                        new NetworkIdVO("rkirkend"), documentTypeName);
0567:                WorkflowAttributeDefinitionVO givennameXMLDef = new WorkflowAttributeDefinitionVO(
0568:                        "XMLSearchableAttribute");
0569:
0570:                workflowDocument.setApplicationContent("<test></test>");
0571:
0572:                givennameXMLDef.addProperty(key, "jack");
0573:                workflowDocument.addSearchableDefinition(givennameXMLDef);
0574:
0575:                workflowDocument.setTitle("Routing style");
0576:                workflowDocument.routeDocument("routing this document.");
0577:
0578:                WorkflowUser user = userService
0579:                        .getWorkflowUser(new AuthenticationUserId("rkirkend"));
0580:                DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
0581:                criteria.setDocTypeFullName(documentTypeName);
0582:                criteria
0583:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0584:                                key, "jack", docType));
0585:                DocumentSearchResultComponents result = docSearchService
0586:                        .getList(user, criteria);
0587:                List searchResults = result.getSearchResults();
0588:
0589:                assertEquals("Search results should have one document.", 1,
0590:                        searchResults.size());
0591:
0592:                criteria = new DocSearchCriteriaVO();
0593:                criteria.setDocTypeFullName(documentTypeName);
0594:                criteria
0595:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0596:                                key, "ja*", docType));
0597:                result = docSearchService.getList(user, criteria);
0598:                searchResults = result.getSearchResults();
0599:
0600:                assertEquals("Search results should have one document.", 1,
0601:                        searchResults.size());
0602:
0603:                criteria = new DocSearchCriteriaVO();
0604:                criteria.setDocTypeFullName(documentTypeName);
0605:                criteria
0606:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0607:                                key, "ja", docType));
0608:                result = docSearchService.getList(user, criteria);
0609:                searchResults = result.getSearchResults();
0610:
0611:                assertEquals("Search results should have one document.", 0,
0612:                        searchResults.size());
0613:
0614:                criteria = new DocSearchCriteriaVO();
0615:                criteria.setDocTypeFullName(documentTypeName);
0616:                criteria
0617:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0618:                                key, "ack", docType));
0619:                result = docSearchService.getList(user, criteria);
0620:                searchResults = result.getSearchResults();
0621:
0622:                assertEquals("Search results should have one document.", 1,
0623:                        searchResults.size());
0624:            }
0625:
0626:            @Test
0627:            public void testDocumentSearchAttributeWildcardingDisallow()
0628:                    throws Exception {
0629:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
0630:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
0631:                UserService userService = (UserService) KEWServiceLocator
0632:                        .getService(KEWServiceLocator.USER_SERVICE);
0633:
0634:                String documentTypeName = "SearchDocTypeStandardSearchDataType";
0635:                DocumentType docType = ((DocumentTypeService) KEWServiceLocator
0636:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
0637:                        .findByName(documentTypeName);
0638:                String userNetworkId = "rkirkend";
0639:                WorkflowDocument workflowDocument = new WorkflowDocument(
0640:                        new NetworkIdVO(userNetworkId), documentTypeName);
0641:
0642:                /*
0643:                 *   Below we are using the keys and values from the custom searchable attribute classes' static constants but 
0644:                 *   this is only for convenience as those should always be valid values to test for.
0645:                 */
0646:                WorkflowAttributeDefinitionVO longXMLDef = new WorkflowAttributeDefinitionVO(
0647:                        "XMLSearchableAttributeStdLong");
0648:                longXMLDef.addProperty(
0649:                        TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0650:                        TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE
0651:                                .toString());
0652:                workflowDocument.addSearchableDefinition(longXMLDef);
0653:                workflowDocument.setTitle("Routing style");
0654:                workflowDocument.routeDocument("routing this document.");
0655:
0656:                WorkflowUser user = userService
0657:                        .getWorkflowUser(new AuthenticationUserId(userNetworkId));
0658:
0659:                String validSearchValue = TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE
0660:                        .toString();
0661:                DocSearchCriteriaVO criteria = null;
0662:                List searchResults = null;
0663:                DocumentSearchResultComponents result = null;
0664:                criteria = new DocSearchCriteriaVO();
0665:                criteria.setDocTypeFullName(documentTypeName);
0666:                criteria
0667:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0668:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0669:                                validSearchValue, docType));
0670:                result = docSearchService.getList(user, criteria);
0671:                searchResults = result.getSearchResults();
0672:                assertEquals("Search results should have one document.", 1,
0673:                        searchResults.size());
0674:
0675:                criteria = null;
0676:                searchResults = null;
0677:                criteria = new DocSearchCriteriaVO();
0678:                criteria.setDocTypeFullName(documentTypeName);
0679:                criteria
0680:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0681:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0682:                                "*" + validSearchValue.substring(2), docType));
0683:
0684:                if ((new SearchableAttributeLongValue()).allowsWildcards()) {
0685:                    result = docSearchService.getList(user, criteria);
0686:                    searchResults = result.getSearchResults();
0687:                    assertEquals(
0688:                            "Search results should be empty using wildcard '*' value.",
0689:                            0, searchResults.size());
0690:                } else {
0691:                    try {
0692:                        result = docSearchService.getList(user, criteria);
0693:                        searchResults = result.getSearchResults();
0694:                        fail("Search results should be throwing a validation exception for use of the character '*' without allowing wildcards");
0695:                    } catch (WorkflowServiceErrorException wsee) {
0696:                    }
0697:                }
0698:
0699:                criteria = null;
0700:                searchResults = null;
0701:                criteria = new DocSearchCriteriaVO();
0702:                criteria.setDocTypeFullName(documentTypeName);
0703:                criteria
0704:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0705:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0706:                                validSearchValue.substring(0, (validSearchValue
0707:                                        .length() - 2)), docType));
0708:                result = docSearchService.getList(user, criteria);
0709:                searchResults = result.getSearchResults();
0710:                assertEquals(
0711:                        "Search results should be empty trying to use assumed ending wildcard.",
0712:                        0, searchResults.size());
0713:            }
0714:
0715:            @Test
0716:            public void testDocumentSearchAttributeCaseSensitivity()
0717:                    throws Exception {
0718:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
0719:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
0720:                UserService userService = (UserService) KEWServiceLocator
0721:                        .getService(KEWServiceLocator.USER_SERVICE);
0722:                String documentTypeName = "SearchDocTypeCaseSensitivity";
0723:                String networkId = "rkirkend";
0724:                DocumentType docType = ((DocumentTypeService) KEWServiceLocator
0725:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
0726:                        .findByName(documentTypeName);
0727:
0728:                String key = "givenname";
0729:                WorkflowDocument workflowDocument = new WorkflowDocument(
0730:                        new NetworkIdVO(networkId), documentTypeName);
0731:                WorkflowAttributeDefinitionVO givennameXMLDef = new WorkflowAttributeDefinitionVO(
0732:                        "XMLSearchableAttribute");
0733:                givennameXMLDef.addProperty(key, "jack");
0734:                workflowDocument.addSearchableDefinition(givennameXMLDef);
0735:                workflowDocument.setTitle("Routing style");
0736:                workflowDocument.routeDocument("routing this document.");
0737:
0738:                WorkflowUser user = userService
0739:                        .getWorkflowUser(new AuthenticationUserId(networkId));
0740:                DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
0741:                criteria.setDocTypeFullName(documentTypeName);
0742:                criteria
0743:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0744:                                key, "jack", docType));
0745:                DocumentSearchResultComponents result = docSearchService
0746:                        .getList(user, criteria);
0747:                assertEquals("Search results should have one document.", 1,
0748:                        result.getSearchResults().size());
0749:
0750:                criteria = new DocSearchCriteriaVO();
0751:                criteria.setDocTypeFullName(documentTypeName);
0752:                criteria
0753:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0754:                                key, "JACK", docType));
0755:                result = docSearchService.getList(user, criteria);
0756:                assertEquals("Search results should have one document.", 0,
0757:                        result.getSearchResults().size());
0758:
0759:                criteria = new DocSearchCriteriaVO();
0760:                criteria.setDocTypeFullName(documentTypeName);
0761:                criteria
0762:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0763:                                key, "jAck", docType));
0764:                result = docSearchService.getList(user, criteria);
0765:                assertEquals("Search results should have one document.", 0,
0766:                        result.getSearchResults().size());
0767:
0768:                criteria = new DocSearchCriteriaVO();
0769:                criteria.setDocTypeFullName(documentTypeName);
0770:                criteria
0771:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0772:                                key, "jacK", docType));
0773:                result = docSearchService.getList(user, criteria);
0774:                assertEquals("Search results should have one document.", 0,
0775:                        result.getSearchResults().size());
0776:
0777:                key = "givenname_nocase";
0778:                workflowDocument = new WorkflowDocument(new NetworkIdVO(
0779:                        networkId), documentTypeName);
0780:                WorkflowAttributeDefinitionVO givenname_nocaseXMLDef = new WorkflowAttributeDefinitionVO(
0781:                        "XMLSearchableAttribute_CaseInsensitive");
0782:                givenname_nocaseXMLDef.addProperty(key, "jaCk");
0783:                workflowDocument
0784:                        .addSearchableDefinition(givenname_nocaseXMLDef);
0785:                workflowDocument.setTitle("Routing style");
0786:                workflowDocument.routeDocument("routing this document.");
0787:
0788:                criteria = new DocSearchCriteriaVO();
0789:                criteria.setDocTypeFullName(documentTypeName);
0790:                criteria
0791:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0792:                                key, "jack", docType));
0793:                result = docSearchService.getList(user, criteria);
0794:                assertEquals("Search results should have one document.", 1,
0795:                        result.getSearchResults().size());
0796:
0797:                criteria = new DocSearchCriteriaVO();
0798:                criteria.setDocTypeFullName(documentTypeName);
0799:                criteria
0800:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0801:                                key, "JACK", docType));
0802:                result = docSearchService.getList(user, criteria);
0803:                assertEquals("Search results should have one document.", 1,
0804:                        result.getSearchResults().size());
0805:
0806:                criteria = new DocSearchCriteriaVO();
0807:                criteria.setDocTypeFullName(documentTypeName);
0808:                criteria
0809:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0810:                                key, "jaCk", docType));
0811:                result = docSearchService.getList(user, criteria);
0812:                assertEquals("Search results should have one document.", 1,
0813:                        result.getSearchResults().size());
0814:
0815:                criteria = new DocSearchCriteriaVO();
0816:                criteria.setDocTypeFullName(documentTypeName);
0817:                criteria
0818:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0819:                                key, "jacK", docType));
0820:                result = docSearchService.getList(user, criteria);
0821:                assertEquals("Search results should have one document.", 1,
0822:                        result.getSearchResults().size());
0823:
0824:                criteria = new DocSearchCriteriaVO();
0825:                criteria.setDocTypeFullName(documentTypeName);
0826:                criteria
0827:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0828:                                key, "jAc", docType));
0829:                result = docSearchService.getList(user, criteria);
0830:                assertEquals("Search results should have one document.", 0,
0831:                        result.getSearchResults().size());
0832:
0833:                criteria = new DocSearchCriteriaVO();
0834:                criteria.setDocTypeFullName(documentTypeName);
0835:                criteria
0836:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0837:                                key, "jA*", docType));
0838:                result = docSearchService.getList(user, criteria);
0839:                assertEquals("Search results should have one document.", 1,
0840:                        result.getSearchResults().size());
0841:
0842:                criteria = new DocSearchCriteriaVO();
0843:                criteria.setDocTypeFullName(documentTypeName);
0844:                criteria
0845:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0846:                                key, "aCk", docType));
0847:                result = docSearchService.getList(user, criteria);
0848:                assertEquals("Search results should have one document.", 1,
0849:                        result.getSearchResults().size());
0850:            }
0851:
0852:            /**
0853:             * Tests searching with client-generated documentContent which is just malformed XML.
0854:             * @throws WorkflowException
0855:             */
0856:            @Test
0857:            public void testRouteDocumentWithMalformedSearchableAttributeContent()
0858:                    throws WorkflowException {
0859:                WorkflowDocument workflowDocument = new WorkflowDocument(
0860:                        new NetworkIdVO("rkirkend"), "SearchDocType");
0861:
0862:                workflowDocument
0863:                        .setApplicationContent("hey, <I'm Not ] Even & XML");
0864:
0865:                workflowDocument.setTitle("Routing style");
0866:                try {
0867:                    workflowDocument.routeDocument("routing this document.");
0868:                    fail("routeDocument succeeded with malformed XML");
0869:                } catch (WorkflowException we) {
0870:                    // An exception is thrown in BeanConverter/XmlUtils.appendXml at the time of this writing
0871:                    // so I will just assume that is the expected behavior
0872:                }
0873:            }
0874:
0875:            /**
0876:             * Tests searching with client-generated documentContent which will not match what the SearchableAttribute
0877:             * is configured to look for.  This should pass with zero search results, but should not throw an exception.
0878:             * @throws Exception
0879:             */
0880:            @Test
0881:            public void testRouteDocumentWithInvalidSearchableAttributeContent()
0882:                    throws Exception {
0883:                String documentTypeName = "SearchDocType";
0884:                String key = "givenname";
0885:                DocumentType docType = ((DocumentTypeService) KEWServiceLocator
0886:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
0887:                        .findByName(documentTypeName);
0888:                WorkflowDocument workflowDocument = new WorkflowDocument(
0889:                        new NetworkIdVO("rkirkend"), documentTypeName);
0890:
0891:                workflowDocument
0892:                        .setApplicationContent("<documentContent><searchableContent><garbage>"
0893:                                + "<blah>not going to match anything</blah>"
0894:                                + "</garbage></searchableContent></documentContent>");
0895:
0896:                workflowDocument.setTitle("Routing style");
0897:                workflowDocument.routeDocument("routing this document.");
0898:
0899:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
0900:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
0901:                UserService userService = (UserService) KEWServiceLocator
0902:                        .getService(KEWServiceLocator.USER_SERVICE);
0903:
0904:                WorkflowUser user = userService
0905:                        .getWorkflowUser(new AuthenticationUserId("rkirkend"));
0906:                DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
0907:                criteria.setDocTypeFullName(documentTypeName);
0908:                criteria
0909:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0910:                                key, "jack", docType));
0911:                DocumentSearchResultComponents result = docSearchService
0912:                        .getList(user, criteria);
0913:                List searchResults = result.getSearchResults();
0914:
0915:                assertEquals("Search results should be empty.", 0,
0916:                        searchResults.size());
0917:
0918:                criteria = new DocSearchCriteriaVO();
0919:                criteria.setDocTypeFullName(documentTypeName);
0920:                criteria
0921:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0922:                                key, "fred", docType));
0923:                result = docSearchService.getList(user, criteria);
0924:                searchResults = result.getSearchResults();
0925:
0926:                assertEquals("Search results should be empty.", 0,
0927:                        searchResults.size());
0928:
0929:                criteria = new DocSearchCriteriaVO();
0930:                criteria.setDocTypeFullName(documentTypeName);
0931:                criteria
0932:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0933:                                "fakeproperty", "doesntexist", docType));
0934:                try {
0935:                    result = docSearchService.getList(user, criteria);
0936:                    fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
0937:                } catch (WorkflowServiceErrorException wsee) {
0938:                }
0939:            }
0940:
0941:            /**
0942:             * Tests searching with client-generated documentContent which will not match what the SearchableAttribute
0943:             * is configured to look for.  This should pass with zero search results, but should not throw an exception.
0944:             * @throws Exception
0945:             */
0946:            @Test
0947:            public void testRouteDocumentWithMoreInvalidSearchableAttributeContent()
0948:                    throws Exception {
0949:                String documentTypeName = "SearchDocType";
0950:                String key = "givenname";
0951:                DocumentType docType = ((DocumentTypeService) KEWServiceLocator
0952:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
0953:                        .findByName(documentTypeName);
0954:                WorkflowDocument workflowDocument = new WorkflowDocument(
0955:                        new NetworkIdVO("rkirkend"), documentTypeName);
0956:
0957:                workflowDocument
0958:                        .setApplicationContent("<documentContent><NOTsearchableContent><garbage>"
0959:                                + "<blah>not going to match anything</blah>"
0960:                                + "</garbage></NOTsearchableContent></documentContent>");
0961:
0962:                workflowDocument.setTitle("Routing style");
0963:                workflowDocument.routeDocument("routing this document.");
0964:
0965:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
0966:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
0967:                UserService userService = (UserService) KEWServiceLocator
0968:                        .getService(KEWServiceLocator.USER_SERVICE);
0969:
0970:                WorkflowUser user = userService
0971:                        .getWorkflowUser(new AuthenticationUserId("rkirkend"));
0972:                DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
0973:                criteria.setDocTypeFullName(documentTypeName);
0974:                criteria
0975:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0976:                                key, "jack", docType));
0977:                DocumentSearchResultComponents result = docSearchService
0978:                        .getList(user, criteria);
0979:                List searchResults = result.getSearchResults();
0980:
0981:                assertEquals("Search results should be empty.", 0,
0982:                        searchResults.size());
0983:
0984:                criteria = new DocSearchCriteriaVO();
0985:                criteria.setDocTypeFullName(documentTypeName);
0986:                criteria
0987:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0988:                                key, "fred", docType));
0989:                result = docSearchService.getList(user, criteria);
0990:                searchResults = result.getSearchResults();
0991:
0992:                assertEquals("Search results should be empty.", 0,
0993:                        searchResults.size());
0994:
0995:                criteria = new DocSearchCriteriaVO();
0996:                criteria.setDocTypeFullName(documentTypeName);
0997:                criteria
0998:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0999:                                "fakeproperty", "doesntexist", docType));
1000:                try {
1001:                    result = docSearchService.getList(user, criteria);
1002:                    fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
1003:                } catch (WorkflowServiceErrorException wsee) {
1004:                }
1005:            }
1006:
1007:            @Test
1008:            public void testAppendingSeachContentWithSearchableAttribute()
1009:                    throws Exception {
1010:                WorkflowDocument workflowDocument = new WorkflowDocument(
1011:                        new NetworkIdVO("rkirkend"), "SearchDocType");
1012:                WorkflowAttributeDefinitionVO givennameXMLDef = new WorkflowAttributeDefinitionVO(
1013:                        "XMLSearchableAttribute");
1014:
1015:                givennameXMLDef.addProperty("givenname", "jack");
1016:                workflowDocument.addSearchableDefinition(givennameXMLDef);
1017:
1018:                workflowDocument.setTitle("Routing Rowdy Piper");
1019:                workflowDocument.routeDocument("routing this document.");
1020:
1021:                // look up document and verify the search valu is there
1022:                DocumentRouteHeaderValue doc = KEWServiceLocator
1023:                        .getRouteHeaderService().getRouteHeader(
1024:                                workflowDocument.getRouteHeaderId());
1025:                assertEquals("Wrong number of searchable attributes", 1, doc
1026:                        .getSearchableAttributeValues().size());
1027:
1028:                workflowDocument = new WorkflowDocument(
1029:                        new NetworkIdVO("jhopf"), workflowDocument
1030:                                .getRouteHeaderId());
1031:                givennameXMLDef = new WorkflowAttributeDefinitionVO(
1032:                        "XMLSearchableAttribute");
1033:
1034:                givennameXMLDef.addProperty("givenname", "jill");
1035:                workflowDocument.addSearchableDefinition(givennameXMLDef);
1036:                workflowDocument.approve("");
1037:
1038:                doc = KEWServiceLocator.getRouteHeaderService().getRouteHeader(
1039:                        workflowDocument.getRouteHeaderId());
1040:                assertEquals("Wrong number of searchable attributes", 2, doc
1041:                        .getSearchableAttributeValues().size());
1042:
1043:                // check for jack and jill
1044:                boolean foundJack = false;
1045:                boolean foundJill = false;
1046:                for (Iterator iter = doc.getSearchableAttributeValues()
1047:                        .iterator(); iter.hasNext();) {
1048:                    SearchableAttributeValue searchableValue = (SearchableAttributeValue) iter
1049:                            .next();
1050:                    if (searchableValue.getSearchableAttributeDisplayValue()
1051:                            .equals("jack")) {
1052:                        foundJack = true;
1053:                    } else if (searchableValue
1054:                            .getSearchableAttributeDisplayValue()
1055:                            .equals("jill")) {
1056:                        foundJill = true;
1057:                    }
1058:                }
1059:
1060:                assertTrue("Didn't find searchable attribute value 'jack'",
1061:                        foundJack);
1062:                assertTrue("Didn't find searchable attribute value 'jill'",
1063:                        foundJill);
1064:            }
1065:
1066:            @Test
1067:            public void testNoSearchableContentAction() throws Exception {
1068:                RouteHeaderService routeHeaderService = KEWServiceLocator
1069:                        .getRouteHeaderService();
1070:                WorkflowDocument workflowDocument = new WorkflowDocument(
1071:                        new NetworkIdVO("rkirkend"), "SearchDocType");
1072:                workflowDocument.saveDocument("");
1073:
1074:                //verify that a searchable attribute exists even though 
1075:                DocumentRouteHeaderValue document = routeHeaderService
1076:                        .getRouteHeader(workflowDocument.getRouteHeaderId());
1077:                assertEquals("Should have a searchable attribute key", 1,
1078:                        document.getSearchableAttributeValues().size());
1079:                assertEquals("Searchable attribute key should be givenname",
1080:                        "givenname", ((SearchableAttributeValue) document
1081:                                .getSearchableAttributeValues().get(0))
1082:                                .getSearchableAttributeKey());
1083:
1084:                WorkflowDocument workflowDocument2 = new WorkflowDocument(
1085:                        new NetworkIdVO("rkirkend"), "SearchDocType2");
1086:                workflowDocument2.saveDocument("");
1087:
1088:                DocumentRouteHeaderValue document2 = routeHeaderService
1089:                        .getRouteHeader(workflowDocument2.getRouteHeaderId());
1090:                assertEquals("Should have a searchable attribute key", 1,
1091:                        document2.getSearchableAttributeValues().size());
1092:                assertEquals("Searchable attribute key should be givenname",
1093:                        "givenname", ((SearchableAttributeValue) document2
1094:                                .getSearchableAttributeValues().get(0))
1095:                                .getSearchableAttributeKey());
1096:            }
1097:
1098:            //    protected String getAltAppContextFile() {
1099:            //    	if (this.getName().equals("testIndexingRequeue")) {
1100:            //    		return "edu/iu/uis/eden/docsearch/xml/SearchableAttributeProcessorSpring.xml";
1101:            //    	} else {
1102:            //    		return null;
1103:            //    	}
1104:            //        
1105:            //    }
1106:
1107:            //this is testing that the code being called in the event of an OptimisticLockException happening in the 
1108:            //SearchableAttributeProcessor is working.  An actual OptimisticLockException is not being created because it's 
1109:            //too much of a pain in this single threaded testing env.
1110:            //    public void testIndexingRequeue() throws Exception {
1111:            //    	Long routeHeaderId = new Long(1);
1112:            //    	
1113:            //        PersistedMessage searchIndexingWork = new PersistedMessage();
1114:            //        searchIndexingWork.setProcessorClassName(SearchableAttributeProcessor.class.getName());
1115:            //        searchIndexingWork.setRouteHeaderId(routeHeaderId);
1116:            //        searchIndexingWork.setQueuePriority(new Integer(6));
1117:            //        searchIndexingWork.setQueueStatus("Q");
1118:            //        searchIndexingWork.setQueueDate(new Timestamp(System.currentTimeMillis()));
1119:            //        SpringServiceLocator.getRouteQueueService().save(searchIndexingWork);
1120:            //        
1121:            //        new SearchableAttributeProcessor().requeueIndexing(searchIndexingWork);
1122:            //        
1123:            //        Collection queueEntries = SpringServiceLocator.getRouteQueueService().findAll();
1124:            //        assertEquals("should have 2 queue entries", 2, queueEntries.size());
1125:            //        for (Iterator iter = queueEntries.iterator(); iter.hasNext();) {
1126:            //			PersistedMessage queueEntry = (PersistedMessage) iter.next();
1127:            //			//all entries should have certain similarities
1128:            //			assertEquals("Wrong routeHeaderid", searchIndexingWork.getRouteHeaderId(), queueEntry.getRouteHeaderId());
1129:            //			assertEquals("Wrong queue status", searchIndexingWork.getQueueStatus(), queueEntry.getQueueStatus());
1130:            //			assertEquals("Wrong queue priority", searchIndexingWork.getQueuePriority(), queueEntry.getQueuePriority());
1131:            //		}
1132:            //    }
1133:
1134:            @Test
1135:            public void testClearingSearchContentWithSearchableAttribute()
1136:                    throws Exception {
1137:                RouteHeaderService routeHeaderService = KEWServiceLocator
1138:                        .getRouteHeaderService();
1139:
1140:                WorkflowDocument workflowDocument = new WorkflowDocument(
1141:                        new NetworkIdVO("rkirkend"), "SearchDocType");
1142:                WorkflowAttributeDefinitionVO givennameXMLDef = new WorkflowAttributeDefinitionVO(
1143:                        "XMLSearchableAttribute");
1144:
1145:                givennameXMLDef.addProperty("givenname", "jack");
1146:                workflowDocument.addSearchableDefinition(givennameXMLDef);
1147:
1148:                workflowDocument.setTitle("Routing Rowdy Piper");
1149:                workflowDocument.routeDocument("routing this document.");
1150:
1151:                // look up document and verify the search valu is there
1152:                DocumentRouteHeaderValue doc = routeHeaderService
1153:                        .getRouteHeader(workflowDocument.getRouteHeaderId());
1154:                assertEquals("Wrong number of searchable attributes", 1, doc
1155:                        .getSearchableAttributeValues().size());
1156:
1157:                workflowDocument = new WorkflowDocument(
1158:                        new NetworkIdVO("jhopf"), workflowDocument
1159:                                .getRouteHeaderId());
1160:                workflowDocument.clearSearchableContent();
1161:
1162:                givennameXMLDef = new WorkflowAttributeDefinitionVO(
1163:                        "XMLSearchableAttribute");
1164:                givennameXMLDef.addProperty("givenname", "dukeboys");
1165:                workflowDocument.addSearchableDefinition(givennameXMLDef);
1166:
1167:                givennameXMLDef = new WorkflowAttributeDefinitionVO(
1168:                        "XMLSearchableAttribute");
1169:                givennameXMLDef.addProperty("givenname", "luke duke");
1170:                workflowDocument.addSearchableDefinition(givennameXMLDef);
1171:
1172:                givennameXMLDef = new WorkflowAttributeDefinitionVO(
1173:                        "XMLSearchableAttribute");
1174:                givennameXMLDef.addProperty("givenname", "bo duke");
1175:                workflowDocument.addSearchableDefinition(givennameXMLDef);
1176:
1177:                workflowDocument.approve("");
1178:
1179:                doc = routeHeaderService.getRouteHeader(workflowDocument
1180:                        .getRouteHeaderId());
1181:                assertEquals("Wrong number of searchable attributes", 3, doc
1182:                        .getSearchableAttributeValues().size());
1183:
1184:                // check for jack and jill
1185:                boolean foundLuke = false;
1186:                boolean foundBo = false;
1187:                boolean foundDukeBoys = false;
1188:                for (Iterator iter = doc.getSearchableAttributeValues()
1189:                        .iterator(); iter.hasNext();) {
1190:                    SearchableAttributeValue searchableValue = (SearchableAttributeValue) iter
1191:                            .next();
1192:                    if (searchableValue.getSearchableAttributeDisplayValue()
1193:                            .equals("dukeboys")) {
1194:                        foundDukeBoys = true;
1195:                    } else if (searchableValue
1196:                            .getSearchableAttributeDisplayValue().equals(
1197:                                    "luke duke")) {
1198:                        foundLuke = true;
1199:                    } else if (searchableValue
1200:                            .getSearchableAttributeDisplayValue().equals(
1201:                                    "bo duke")) {
1202:                        foundBo = true;
1203:                    }
1204:                }
1205:
1206:                assertTrue(
1207:                        "Didn't find searchable attribute value 'luke duke'",
1208:                        foundLuke);
1209:                assertTrue("Didn't find searchable attribute value 'bo duke'",
1210:                        foundBo);
1211:                assertTrue("Didn't find searchable attribute value 'dukeboys'",
1212:                        foundDukeBoys);
1213:            }
1214:
1215:            /*
1216:             * Test method for 'edu.iu.uis.eden.docsearch.xml.StandardGenericXMLSearchableAttribute.getSearchContent()'
1217:             */
1218:            @Test
1219:            public void testGetSearchContent() throws Exception {
1220:                StandardGenericXMLSearchableAttribute attribute = getAttribute("XMLSearchableAttribute");
1221:                String keyName = "givenname";
1222:                String value = "jack";
1223:                Map paramMap = new HashMap();
1224:                paramMap.put(keyName, value);
1225:                attribute.setParamMap(paramMap);
1226:                String searchContent = attribute.getSearchContent();
1227:                assertTrue("searchContent was not found.",
1228:                        searchContent != null && searchContent.length() > 0);
1229:                XPath xpath = XPathFactory.newInstance().newXPath();
1230:                Element foundDocContent = DocumentBuilderFactory.newInstance()
1231:                        .newDocumentBuilder().parse(
1232:                                new InputSource(new BufferedReader(
1233:                                        new StringReader(searchContent))))
1234:                        .getDocumentElement();
1235:                String findStuff = "//putWhateverWordsIwantInsideThisTag/"
1236:                        + keyName + "/value";
1237:                assertTrue(
1238:                        "Search content does not contain correct value for field '"
1239:                                + keyName + "'.", value.equals(xpath.evaluate(
1240:                                findStuff, foundDocContent,
1241:                                XPathConstants.STRING)));
1242:
1243:                attribute = getAttribute("XMLSearchableAttributeStdLong");
1244:                keyName = "testLongKey";
1245:                value = "123458";
1246:                paramMap = new HashMap();
1247:                paramMap.put(keyName, value);
1248:                attribute.setParamMap(paramMap);
1249:                searchContent = attribute.getSearchContent();
1250:                assertTrue("searchContent was not found.",
1251:                        searchContent != null && searchContent.length() > 0);
1252:                xpath = XPathFactory.newInstance().newXPath();
1253:                foundDocContent = DocumentBuilderFactory.newInstance()
1254:                        .newDocumentBuilder().parse(
1255:                                new InputSource(new BufferedReader(
1256:                                        new StringReader(searchContent))))
1257:                        .getDocumentElement();
1258:                findStuff = "//putWhateverWordsIwantInsideThisTag/" + keyName
1259:                        + "/value";
1260:                assertTrue(
1261:                        "Search content does not contain correct value for field '"
1262:                                + keyName + "'.", value.equals(xpath.evaluate(
1263:                                findStuff, foundDocContent,
1264:                                XPathConstants.STRING)));
1265:
1266:                attribute = getAttribute("XMLSearchableAttributeStdFloat");
1267:                keyName = "testFloatKey";
1268:                value = "2568.204";
1269:                paramMap = new HashMap();
1270:                paramMap.put(keyName, value);
1271:                attribute.setParamMap(paramMap);
1272:                searchContent = attribute.getSearchContent();
1273:                assertTrue("searchContent was not found.",
1274:                        searchContent != null && searchContent.length() > 0);
1275:                xpath = XPathFactory.newInstance().newXPath();
1276:                foundDocContent = DocumentBuilderFactory.newInstance()
1277:                        .newDocumentBuilder().parse(
1278:                                new InputSource(new BufferedReader(
1279:                                        new StringReader(searchContent))))
1280:                        .getDocumentElement();
1281:                findStuff = "//putWhateverWordsIwantInsideThisTag/" + keyName
1282:                        + "/value";
1283:                assertTrue(
1284:                        "Search content does not contain correct value for field '"
1285:                                + keyName + "'.", value.equals(xpath.evaluate(
1286:                                findStuff, foundDocContent,
1287:                                XPathConstants.STRING)));
1288:
1289:                attribute = getAttribute("XMLSearchableAttributeStdCurrency");
1290:                keyName = "testCurrencyKey";
1291:                value = "2248.20";
1292:                paramMap = new HashMap();
1293:                paramMap.put(keyName, value);
1294:                attribute.setParamMap(paramMap);
1295:                searchContent = attribute.getSearchContent();
1296:                assertTrue("searchContent was not found.",
1297:                        searchContent != null && searchContent.length() > 0);
1298:                xpath = XPathFactory.newInstance().newXPath();
1299:                foundDocContent = DocumentBuilderFactory.newInstance()
1300:                        .newDocumentBuilder().parse(
1301:                                new InputSource(new BufferedReader(
1302:                                        new StringReader(searchContent))))
1303:                        .getDocumentElement();
1304:                findStuff = "//putWhateverWordsIwantInsideThisTag/" + keyName
1305:                        + "/value";
1306:                assertTrue(
1307:                        "Search content does not contain correct value for field '"
1308:                                + keyName + "'.", value.equals(xpath.evaluate(
1309:                                findStuff, foundDocContent,
1310:                                XPathConstants.STRING)));
1311:
1312:                attribute = getAttribute("XMLSearchableAttributeStdDateTime");
1313:                keyName = "testDateTimeKey";
1314:                value = DocSearchUtils
1315:                        .getDisplayValueWithDateOnly(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE);
1316:                paramMap = new HashMap();
1317:                paramMap.put(keyName, value);
1318:                attribute.setParamMap(paramMap);
1319:                searchContent = attribute.getSearchContent();
1320:                assertTrue("searchContent was not found.",
1321:                        searchContent != null && searchContent.length() > 0);
1322:                xpath = XPathFactory.newInstance().newXPath();
1323:                foundDocContent = DocumentBuilderFactory.newInstance()
1324:                        .newDocumentBuilder().parse(
1325:                                new InputSource(new BufferedReader(
1326:                                        new StringReader(searchContent))))
1327:                        .getDocumentElement();
1328:                findStuff = "//putWhateverWordsIwantInsideThisTag/" + keyName
1329:                        + "/value";
1330:                assertTrue(
1331:                        "Search content does not contain correct value for field '"
1332:                                + keyName + "'.", value.equals(xpath.evaluate(
1333:                                findStuff, foundDocContent,
1334:                                XPathConstants.STRING)));
1335:            }
1336:
1337:            /*
1338:             * Test method for 'edu.iu.uis.eden.docsearch.xml.StandardGenericXMLSearchableAttribute.getSearchStorageValues(String)'
1339:             */
1340:            @Test
1341:            public void testGetSearchStorageValues() {
1342:                String attributeName = "XMLSearchableAttribute";
1343:                String keyName = "givenname";
1344:                String value = "jack";
1345:                String documentcontent = "<documentContent>"
1346:                        + "<searchableContent>"
1347:                        + "<putWhateverWordsIwantInsideThisTag>" + "<"
1348:                        + keyName + ">" + "<value>" + value + "</value>" + "</"
1349:                        + keyName + ">"
1350:                        + "</putWhateverWordsIwantInsideThisTag>"
1351:                        + "</searchableContent>" + "</documentContent>";
1352:                StandardGenericXMLSearchableAttribute attribute = getAttribute(attributeName);
1353:                List values = attribute.getSearchStorageValues(documentcontent);
1354:                assertEquals("Number of search attribute values is wrong", 1,
1355:                        values.size());
1356:                for (Iterator iter = values.iterator(); iter.hasNext();) {
1357:                    SearchableAttributeValue searchAttValue = (SearchableAttributeValue) iter
1358:                            .next();
1359:                    assertEquals("Key of attribute is wrong", keyName,
1360:                            searchAttValue.getSearchableAttributeKey());
1361:                    assertEquals("Value of attribute is wrong", value,
1362:                            searchAttValue.getSearchableAttributeDisplayValue());
1363:                }
1364:
1365:                attributeName = "XMLSearchableAttributeStdLong";
1366:                keyName = "testLongKey";
1367:                value = "123458";
1368:                documentcontent = "<documentContent>" + "<searchableContent>"
1369:                        + "<putWhateverWordsIwantInsideThisTag>" + "<"
1370:                        + keyName + ">" + "<value>" + value + "</value>" + "</"
1371:                        + keyName + ">"
1372:                        + "</putWhateverWordsIwantInsideThisTag>"
1373:                        + "</searchableContent>" + "</documentContent>";
1374:                attribute = getAttribute(attributeName);
1375:                values = attribute.getSearchStorageValues(documentcontent);
1376:                assertEquals("Number of search attribute values is wrong", 1,
1377:                        values.size());
1378:                for (Iterator iter = values.iterator(); iter.hasNext();) {
1379:                    SearchableAttributeValue searchAttValue = (SearchableAttributeValue) iter
1380:                            .next();
1381:                    assertEquals("Key of attribute is wrong", keyName,
1382:                            searchAttValue.getSearchableAttributeKey());
1383:                    assertEquals("Value of attribute is wrong", value,
1384:                            searchAttValue.getSearchableAttributeDisplayValue());
1385:                }
1386:
1387:                attributeName = "XMLSearchableAttributeStdFloat";
1388:                keyName = "testFloatKey";
1389:                value = "2568.204154796";
1390:                documentcontent = "<documentContent>" + "<searchableContent>"
1391:                        + "<putWhateverWordsIwantInsideThisTag>" + "<"
1392:                        + keyName + ">" + "<value>" + value + "</value>" + "</"
1393:                        + keyName + ">"
1394:                        + "</putWhateverWordsIwantInsideThisTag>"
1395:                        + "</searchableContent>" + "</documentContent>";
1396:                attribute = getAttribute(attributeName);
1397:                values = attribute.getSearchStorageValues(documentcontent);
1398:                assertEquals("Number of search attribute values is wrong", 1,
1399:                        values.size());
1400:                for (Iterator iter = values.iterator(); iter.hasNext();) {
1401:                    SearchableAttributeValue searchAttValue = (SearchableAttributeValue) iter
1402:                            .next();
1403:                    assertEquals("Key of attribute is wrong", keyName,
1404:                            searchAttValue.getSearchableAttributeKey());
1405:                    assertEquals("Value of attribute is wrong",
1406:                            insertCommasIfNeeded(value, 3), searchAttValue
1407:                                    .getSearchableAttributeDisplayValue());
1408:                }
1409:
1410:                Map<String, String> currencyParameterMap = new HashMap<String, String>();
1411:                currencyParameterMap.put("displayFormatPattern", "#,###.00");
1412:                attributeName = "XMLSearchableAttributeStdCurrency";
1413:                keyName = "testCurrencyKey";
1414:                value = "2238.2";
1415:                documentcontent = "<documentContent>" + "<searchableContent>"
1416:                        + "<putWhateverWordsIwantInsideThisTag>" + "<"
1417:                        + keyName + ">" + "<value>" + value + "</value>" + "</"
1418:                        + keyName + ">"
1419:                        + "</putWhateverWordsIwantInsideThisTag>"
1420:                        + "</searchableContent>" + "</documentContent>";
1421:                attribute = getAttribute(attributeName);
1422:                values = attribute.getSearchStorageValues(documentcontent);
1423:                assertEquals("Number of search attribute values is wrong", 1,
1424:                        values.size());
1425:                for (Iterator iter = values.iterator(); iter.hasNext();) {
1426:                    SearchableAttributeValue searchAttValue = (SearchableAttributeValue) iter
1427:                            .next();
1428:                    assertEquals("Key of attribute is wrong", keyName,
1429:                            searchAttValue.getSearchableAttributeKey());
1430:                    assertEquals(
1431:                            "Value of attribute is wrong",
1432:                            insertCommasIfNeeded(value + "0", 3),
1433:                            searchAttValue
1434:                                    .getSearchableAttributeDisplayValue(currencyParameterMap));
1435:                }
1436:
1437:                attributeName = "XMLSearchableAttributeStdCurrency";
1438:                keyName = "testCurrencyKey";
1439:                value = "2157238.2";
1440:                documentcontent = "<documentContent>" + "<searchableContent>"
1441:                        + "<putWhateverWordsIwantInsideThisTag>" + "<"
1442:                        + keyName + ">" + "<value>" + value + "</value>" + "</"
1443:                        + keyName + ">"
1444:                        + "</putWhateverWordsIwantInsideThisTag>"
1445:                        + "</searchableContent>" + "</documentContent>";
1446:                attribute = getAttribute(attributeName);
1447:                values = attribute.getSearchStorageValues(documentcontent);
1448:                assertEquals("Number of search attribute values is wrong", 1,
1449:                        values.size());
1450:                for (Iterator iter = values.iterator(); iter.hasNext();) {
1451:                    SearchableAttributeValue searchAttValue = (SearchableAttributeValue) iter
1452:                            .next();
1453:                    assertEquals("Key of attribute is wrong", keyName,
1454:                            searchAttValue.getSearchableAttributeKey());
1455:                    assertEquals(
1456:                            "Value of attribute is wrong",
1457:                            insertCommasIfNeeded(value + "0", 3),
1458:                            searchAttValue
1459:                                    .getSearchableAttributeDisplayValue(currencyParameterMap));
1460:                }
1461:
1462:                attributeName = "XMLSearchableAttributeStdDateTime";
1463:                keyName = "testDateTimeKey";
1464:                value = DocSearchUtils
1465:                        .getDisplayValueWithDateOnly(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE);
1466:                documentcontent = "<documentContent>" + "<searchableContent>"
1467:                        + "<putWhateverWordsIwantInsideThisTag>" + "<"
1468:                        + keyName + ">" + "<value>" + value + "</value>" + "</"
1469:                        + keyName + ">"
1470:                        + "</putWhateverWordsIwantInsideThisTag>"
1471:                        + "</searchableContent>" + "</documentContent>";
1472:                attribute = getAttribute(attributeName);
1473:                values = attribute.getSearchStorageValues(documentcontent);
1474:                assertEquals("Number of search attribute values is wrong", 1,
1475:                        values.size());
1476:                for (Iterator iter = values.iterator(); iter.hasNext();) {
1477:                    SearchableAttributeValue searchAttValue = (SearchableAttributeValue) iter
1478:                            .next();
1479:                    assertEquals("Key of attribute is wrong", keyName,
1480:                            searchAttValue.getSearchableAttributeKey());
1481:                    assertEquals("Value of attribute is wrong", value,
1482:                            searchAttValue.getSearchableAttributeDisplayValue());
1483:                }
1484:
1485:                // test for kuali xstream formatted dates
1486:                value = "2007-02-20";
1487:                String returnValue = "02/20/2007";
1488:                documentcontent = "<documentContent>" + "<searchableContent>"
1489:                        + "<putWhateverWordsIwantInsideThisTag>" + "<"
1490:                        + keyName + ">" + "<value>" + value + "</value>" + "</"
1491:                        + keyName + ">"
1492:                        + "</putWhateverWordsIwantInsideThisTag>"
1493:                        + "</searchableContent>" + "</documentContent>";
1494:                attribute = getAttribute(attributeName);
1495:                values = attribute.getSearchStorageValues(documentcontent);
1496:                assertEquals("Number of search attribute values is wrong", 1,
1497:                        values.size());
1498:                for (Iterator iter = values.iterator(); iter.hasNext();) {
1499:                    SearchableAttributeValue searchAttValue = (SearchableAttributeValue) iter
1500:                            .next();
1501:                    assertEquals("Key of attribute is wrong", keyName,
1502:                            searchAttValue.getSearchableAttributeKey());
1503:                    assertEquals("Value of attribute is wrong", returnValue,
1504:                            searchAttValue.getSearchableAttributeDisplayValue());
1505:                }
1506:            }
1507:
1508:            private String insertCommasIfNeeded(String value, int interval) {
1509:                int indexOfDecimal = value.indexOf(".");
1510:                String decimalPointOn = value.substring(indexOfDecimal);
1511:                String temp = value.substring(0, indexOfDecimal);
1512:                StringBuffer builtValue = new StringBuffer();
1513:                if (temp.length() <= interval) {
1514:                    builtValue.append(temp);
1515:                } else {
1516:                    int counter = 0;
1517:                    for (int i = temp.length() - 1; (i >= 0); i--) {
1518:                        if (counter == interval) {
1519:                            builtValue.insert(0, ",");
1520:                            counter = 0;
1521:                        }
1522:                        counter++;
1523:                        builtValue.insert(0, temp.substring(i, i + 1));
1524:                    }
1525:                }
1526:                return (builtValue.append(decimalPointOn)).toString();
1527:            }
1528:
1529:            /*
1530:             * Test method for 'edu.iu.uis.eden.docsearch.xml.StandardGenericXMLSearchableAttribute.getSearchingRows()'
1531:             */
1532:            @Test
1533:            public void testGetSearchingRows() {
1534:                StandardGenericXMLSearchableAttribute searchAttribute = getAttribute(null);
1535:                assertTrue("Invalid number of search rows", searchAttribute
1536:                        .getSearchingRows().size() == 1);
1537:
1538:                //we really just want this to load without exploding
1539:                List searchRows = getAttribute("BlankDropDownSearchAttribute")
1540:                        .getSearchingRows();
1541:                assertEquals("Invalid number of search rows", 1, searchRows
1542:                        .size());
1543:                Row row = (Row) searchRows.get(0);
1544:                Field field = row.getField(0);
1545:                assertEquals("Should be 5 valid values", 5, field
1546:                        .getFieldValidValues().size());
1547:
1548:                assertEquals("Default value is not correct", "AMST", field
1549:                        .getPropertyValue());
1550:            }
1551:
1552:            /*
1553:             * Test method for 'edu.iu.uis.eden.docsearch.xml.StandardGenericXMLSearchableAttribute.validateUserSearchInputs(Map)'
1554:             */
1555:            @Test
1556:            public void testValidateUserSearchInputs() {
1557:                StandardGenericXMLSearchableAttribute searchAttribute = getAttribute("XMLSearchableAttribute");
1558:                Map paramMap = new HashMap();
1559:                paramMap.put(
1560:                        TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
1561:                        "jack");
1562:                List validationErrors = searchAttribute
1563:                        .validateUserSearchInputs(paramMap);
1564:                assertEquals("Validation should not have returned an error.",
1565:                        0, validationErrors.size());
1566:                paramMap.clear();
1567:                paramMap.put(
1568:                        TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
1569:                        "jack.jack");
1570:                validationErrors = searchAttribute
1571:                        .validateUserSearchInputs(paramMap);
1572:                assertEquals(
1573:                        "Validation should return a single error message.", 1,
1574:                        validationErrors.size());
1575:                WorkflowAttributeValidationError error = (WorkflowAttributeValidationError) validationErrors
1576:                        .get(0);
1577:                assertEquals(
1578:                        "Validation error should match xml attribute message",
1579:                        "Invalid first name", error.getMessage());
1580:                paramMap.clear();
1581:                paramMap.put(
1582:                        TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
1583:                        "jack*jack");
1584:                validationErrors = searchAttribute
1585:                        .validateUserSearchInputs(paramMap);
1586:                assertEquals(
1587:                        "Validation should return a single error message.", 0,
1588:                        validationErrors.size());
1589:
1590:                searchAttribute = getAttribute("XMLSearchableAttributeStdLong");
1591:                paramMap = new HashMap();
1592:                paramMap.put(TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
1593:                        TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE
1594:                                .toString());
1595:                validationErrors = searchAttribute
1596:                        .validateUserSearchInputs(paramMap);
1597:                assertEquals("Validation should not have returned an error.",
1598:                        0, validationErrors.size());
1599:                paramMap.clear();
1600:                paramMap.put(TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
1601:                        TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE
1602:                                .toString()
1603:                                + ".33");
1604:                validationErrors = searchAttribute
1605:                        .validateUserSearchInputs(paramMap);
1606:                assertEquals(
1607:                        "Validation should return a single error message.", 1,
1608:                        validationErrors.size());
1609:                error = (WorkflowAttributeValidationError) validationErrors
1610:                        .get(0);
1611:                assertTrue(
1612:                        "Validation error is incorrect",
1613:                        error
1614:                                .getMessage()
1615:                                .endsWith(
1616:                                        "does not conform to standard validation for field type."));
1617:                paramMap.clear();
1618:                paramMap.put(TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
1619:                        "jack*jack");
1620:                validationErrors = searchAttribute
1621:                        .validateUserSearchInputs(paramMap);
1622:                assertEquals(
1623:                        "Validation should return a single error message.", 1,
1624:                        validationErrors.size());
1625:                error = (WorkflowAttributeValidationError) validationErrors
1626:                        .get(0);
1627:                assertTrue(
1628:                        "Validation error is incorrect",
1629:                        error
1630:                                .getMessage()
1631:                                .endsWith(
1632:                                        "does not conform to standard validation for field type."));
1633:
1634:                searchAttribute = getAttribute("XMLSearchableAttributeStdFloat");
1635:                paramMap = new HashMap();
1636:                paramMap.put(
1637:                        TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
1638:                        TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE
1639:                                .toString());
1640:                validationErrors = searchAttribute
1641:                        .validateUserSearchInputs(paramMap);
1642:                assertEquals("Validation should not have returned an error.",
1643:                        0, validationErrors.size());
1644:                paramMap.clear();
1645:                paramMap.put(
1646:                        TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
1647:                        TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE
1648:                                .toString()
1649:                                + "a");
1650:                validationErrors = searchAttribute
1651:                        .validateUserSearchInputs(paramMap);
1652:                assertEquals(
1653:                        "Validation should return a single error message.", 1,
1654:                        validationErrors.size());
1655:                error = (WorkflowAttributeValidationError) validationErrors
1656:                        .get(0);
1657:                assertTrue(
1658:                        "Validation error is incorrect",
1659:                        error
1660:                                .getMessage()
1661:                                .endsWith(
1662:                                        "does not conform to standard validation for field type."));
1663:                paramMap.clear();
1664:                paramMap.put(
1665:                        TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
1666:                        TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE
1667:                                .toString()
1668:                                + "*");
1669:                validationErrors = searchAttribute
1670:                        .validateUserSearchInputs(paramMap);
1671:                assertEquals(
1672:                        "Validation should return a single error message.", 1,
1673:                        validationErrors.size());
1674:                error = (WorkflowAttributeValidationError) validationErrors
1675:                        .get(0);
1676:                assertTrue(
1677:                        "Validation error is incorrect",
1678:                        error
1679:                                .getMessage()
1680:                                .endsWith(
1681:                                        "does not conform to standard validation for field type."));
1682:
1683:                searchAttribute = getAttribute("XMLSearchableAttributeStdCurrency");
1684:                String key = "testCurrencyKey";
1685:                Float value = Float.valueOf("5486.25");
1686:                paramMap = new HashMap();
1687:                paramMap.put(key, value.toString());
1688:                validationErrors = searchAttribute
1689:                        .validateUserSearchInputs(paramMap);
1690:                assertEquals("Validation should not have returned an error.",
1691:                        0, validationErrors.size());
1692:                paramMap.clear();
1693:                paramMap.put(key, value.toString() + "a");
1694:                validationErrors = searchAttribute
1695:                        .validateUserSearchInputs(paramMap);
1696:                assertEquals(
1697:                        "Validation should return a single error message.", 1,
1698:                        validationErrors.size());
1699:                error = (WorkflowAttributeValidationError) validationErrors
1700:                        .get(0);
1701:                assertTrue(
1702:                        "Validation error is incorrect",
1703:                        error
1704:                                .getMessage()
1705:                                .endsWith(
1706:                                        "does not conform to standard validation for field type."));
1707:                paramMap.clear();
1708:                paramMap.put(key, value.toString() + "*");
1709:                validationErrors = searchAttribute
1710:                        .validateUserSearchInputs(paramMap);
1711:                assertEquals(
1712:                        "Validation should return a single error message.", 1,
1713:                        validationErrors.size());
1714:                error = (WorkflowAttributeValidationError) validationErrors
1715:                        .get(0);
1716:                assertTrue(
1717:                        "Validation error is incorrect",
1718:                        error
1719:                                .getMessage()
1720:                                .endsWith(
1721:                                        "does not conform to standard validation for field type."));
1722:
1723:                searchAttribute = getAttribute("XMLSearchableAttributeStdDateTime");
1724:                paramMap = new HashMap();
1725:                paramMap
1726:                        .put(
1727:                                TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
1728:                                DocSearchUtils
1729:                                        .getDisplayValueWithDateOnly(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE));
1730:                validationErrors = searchAttribute
1731:                        .validateUserSearchInputs(paramMap);
1732:                assertEquals("Validation should not have returned an error.",
1733:                        0, validationErrors.size());
1734:                paramMap.clear();
1735:                paramMap.put(
1736:                        TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
1737:                        "001/5/08");
1738:                validationErrors = searchAttribute
1739:                        .validateUserSearchInputs(paramMap);
1740:                assertEquals(
1741:                        "Validation should return a single error message.", 1,
1742:                        validationErrors.size());
1743:                error = (WorkflowAttributeValidationError) validationErrors
1744:                        .get(0);
1745:                assertTrue(
1746:                        "Validation error is incorrect",
1747:                        error
1748:                                .getMessage()
1749:                                .endsWith(
1750:                                        "does not conform to standard validation for field type."));
1751:                paramMap.clear();
1752:                paramMap.put(
1753:                        TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
1754:                        "01/02/20*");
1755:                validationErrors = searchAttribute
1756:                        .validateUserSearchInputs(paramMap);
1757:                assertEquals(
1758:                        "Validation should return a single error message.", 1,
1759:                        validationErrors.size());
1760:                error = (WorkflowAttributeValidationError) validationErrors
1761:                        .get(0);
1762:                assertTrue(
1763:                        "Validation error is incorrect",
1764:                        error
1765:                                .getMessage()
1766:                                .endsWith(
1767:                                        "does not conform to standard validation for field type."));
1768:            }
1769:
1770:            /**
1771:             * Tests the XStreamSafeEvaluator against searchable attributes to resolve EN-63 and KULWF-723.
1772:             * 
1773:             * This test is pretty much just a copy of testRouteDocumentWithSearchableAttribute using a 
1774:             * different document type which defines the same xpath expression, only with embedded
1775:             * XStream "reference" attributes in the XML.
1776:             */
1777:            @Test
1778:            public void testRouteDocumentWithXStreamSearchableAttribute()
1779:                    throws Exception {
1780:                String documentTypeName = "SearchDocType";
1781:                String key = "givenname";
1782:                DocumentType docType = ((DocumentTypeService) KEWServiceLocator
1783:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
1784:                        .findByName(documentTypeName);
1785:
1786:                WorkflowDocument workflowDocument = new WorkflowDocument(
1787:                        new NetworkIdVO("rkirkend"), "SearchDocTypeXStream");
1788:                WorkflowAttributeDefinitionVO givennameXMLDef = new WorkflowAttributeDefinitionVO(
1789:                        "XMLXStreamSearchableAttribute");
1790:
1791:                workflowDocument.setApplicationContent("<test></test>");
1792:
1793:                givennameXMLDef.addProperty("givenname", "jack");
1794:                workflowDocument.addSearchableDefinition(givennameXMLDef);
1795:
1796:                workflowDocument.setTitle("Routing style");
1797:                workflowDocument.routeDocument("routing this document.");
1798:
1799:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
1800:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
1801:                UserService userService = (UserService) KEWServiceLocator
1802:                        .getService(KEWServiceLocator.USER_SERVICE);
1803:
1804:                WorkflowUser user = userService
1805:                        .getWorkflowUser(new AuthenticationUserId("rkirkend"));
1806:                DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
1807:                criteria.setDocTypeFullName(documentTypeName);
1808:                criteria
1809:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1810:                                key, "jack", docType));
1811:                DocumentSearchResultComponents result = docSearchService
1812:                        .getList(user, criteria);
1813:                List searchResults = result.getSearchResults();
1814:
1815:                assertEquals("Search results should be empty.", 0,
1816:                        searchResults.size());
1817:
1818:                criteria = new DocSearchCriteriaVO();
1819:                criteria.setDocTypeFullName(documentTypeName);
1820:                criteria
1821:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1822:                                key, "fred", docType));
1823:                result = docSearchService.getList(user, criteria);
1824:                searchResults = result.getSearchResults();
1825:
1826:                assertEquals("Search results should be empty.", 0,
1827:                        searchResults.size());
1828:
1829:                criteria = new DocSearchCriteriaVO();
1830:                criteria.setDocTypeFullName(documentTypeName);
1831:                criteria
1832:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1833:                                "fakeproperty", "doesntexist", docType));
1834:                try {
1835:                    result = docSearchService.getList(user, criteria);
1836:                    fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
1837:                } catch (WorkflowServiceErrorException wsee) {
1838:                }
1839:            }
1840:
1841:            /**
1842:             * Tests the resolution to issues EN-95, KULWF-757, KULOWF-52 whereby the use of a quickfinder is causing
1843:             * NullPointers when searching for documents.
1844:             */
1845:            @Test
1846:            public void testSearchableAttributeWithQuickfinder()
1847:                    throws Exception {
1848:                String documentTypeName = "AttributeWithQuickfinderDocType";
1849:                String key = "chart";
1850:                DocumentType docType = ((DocumentTypeService) KEWServiceLocator
1851:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
1852:                        .findByName(documentTypeName);
1853:                WorkflowDocument document = new WorkflowDocument(
1854:                        new NetworkIdVO("rkirkend"), documentTypeName);
1855:
1856:                // define the chart for the searchable attribute
1857:                WorkflowAttributeDefinitionVO chartDef = new WorkflowAttributeDefinitionVO(
1858:                        "SearchableAttributeWithQuickfinder");
1859:                chartDef.addProperty(key, "BL");
1860:                document.addSearchableDefinition(chartDef);
1861:
1862:                // save the document
1863:                document.setTitle("Routin' with style");
1864:                document.saveDocument("Savin' this document.");
1865:
1866:                // prepare to search
1867:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
1868:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
1869:                UserService userService = (UserService) KEWServiceLocator
1870:                        .getService(KEWServiceLocator.USER_SERVICE);
1871:                WorkflowUser user = userService
1872:                        .getWorkflowUser(new AuthenticationUserId("rkirkend"));
1873:
1874:                // execute the search by our chart, we should see one result
1875:                DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
1876:                criteria.setDocTypeFullName(documentTypeName);
1877:                criteria
1878:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1879:                                key, "BL", docType));
1880:                DocumentSearchResultComponents results = docSearchService
1881:                        .getList(user, criteria);
1882:                List searchResults = results.getSearchResults();
1883:                assertEquals("Search results should have one document.", 1,
1884:                        searchResults.size());
1885:                DocumentSearchResult result = (DocumentSearchResult) searchResults
1886:                        .get(0);
1887:                KeyValueSort kvs = result
1888:                        .getResultContainer(DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID);
1889:                assertEquals("Wrong document in search results.", document
1890:                        .getRouteHeaderId(), kvs.getSortValue());
1891:
1892:                // search with no searchable attribute criteria, should return our document as well
1893:                criteria = new DocSearchCriteriaVO();
1894:                criteria.setDocTypeFullName(documentTypeName);
1895:                results = docSearchService.getList(user, criteria);
1896:                searchResults = results.getSearchResults();
1897:                assertEquals("Search results should have one document.", 1,
1898:                        searchResults.size());
1899:                result = (DocumentSearchResult) searchResults.get(0);
1900:                kvs = result
1901:                        .getResultContainer(DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID);
1902:                assertEquals("Wrong document in search results.", document
1903:                        .getRouteHeaderId(), kvs.getSortValue());
1904:
1905:            }
1906:
1907:            /**
1908:             * Tests that the hidding of fields and columns works properly to resolve EN-53.
1909:             * 
1910:             * TODO this is currently commented out because we can't test this properly through the unit
1911:             * test since the filtering of the column actually happens in the web-tier.  Shoudl this be
1912:             * the case?  Maybe we need to re-examine when we refactor document search.
1913:             */
1914:            @Test
1915:            public void testSearchableAttributeWithHiddens() throws Exception {
1916:                // for the following document, the chart field should not show up in the result set and the org field
1917:                // should not show up in the criteriaw
1918:                String docType = "AttributeWithHiddensDocType";
1919:                DocumentType documentType = ((DocumentTypeService) KEWServiceLocator
1920:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
1921:                        .findByName(docType);
1922:
1923:                String attributeName = "SearchableAttributeWithHiddens";
1924:                WorkflowDocument document = new WorkflowDocument(
1925:                        new NetworkIdVO("rkirkend"), docType);
1926:
1927:                // define the chart for the searchable attribute
1928:                WorkflowAttributeDefinitionVO chartDef = new WorkflowAttributeDefinitionVO(
1929:                        attributeName);
1930:                chartDef.addProperty("chart", "BL");
1931:                chartDef.addProperty("org", "ARSC");
1932:                chartDef.addProperty("dollar", "24");
1933:                document.addSearchableDefinition(chartDef);
1934:
1935:                // save the document
1936:                document.setTitle("Routin' with style");
1937:                document.saveDocument("Savin' this document.");
1938:
1939:                // prepare to search
1940:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
1941:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
1942:                UserService userService = (UserService) KEWServiceLocator
1943:                        .getService(KEWServiceLocator.USER_SERVICE);
1944:                WorkflowUser user = userService
1945:                        .getWorkflowUser(new AuthenticationUserId("rkirkend"));
1946:
1947:                // execute the search by our chart, we should see one result
1948:                DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
1949:                criteria.setDocTypeFullName(docType);
1950:                criteria
1951:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1952:                                "chart", "BL", documentType));
1953:                DocumentSearchResultComponents results = docSearchService
1954:                        .getList(user, criteria);
1955:                List searchResults = results.getSearchResults();
1956:                assertEquals("Search results should have one document.", 1,
1957:                        searchResults.size());
1958:                DocumentSearchResult result = (DocumentSearchResult) searchResults
1959:                        .get(0);
1960:                KeyValueSort kvs = result
1961:                        .getResultContainer(DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID);
1962:                assertEquals("Wrong document in search results.", document
1963:                        .getRouteHeaderId(), kvs.getSortValue());
1964:                // also check that the chart field is not in the result set and the org field is
1965:                kvs = null;
1966:                kvs = result.getResultContainer("chart");
1967:                assertNull("The chart column should not be in the result set!",
1968:                        kvs.getValue());
1969:                kvs = null;
1970:                kvs = result.getResultContainer("org");
1971:                assertNotNull("The org column should be in the result set", kvs);
1972:                assertEquals("Wrong org code.", "ARSC", kvs.getValue());
1973:                kvs = null;
1974:                kvs = result.getResultContainer("dollar");
1975:                assertNotNull("The dollar column should be in the result set",
1976:                        kvs);
1977:                assertEquals("Wrong dollar code.", "24", kvs.getValue());
1978:            }
1979:
1980:            @Test
1981:            public void testSetApplicationContentXMLRoutedDocument()
1982:                    throws Exception {
1983:                String documentTypeName = "SearchDocType";
1984:                String key = "givenname";
1985:                DocumentType docType = ((DocumentTypeService) KEWServiceLocator
1986:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
1987:                        .findByName(documentTypeName);
1988:                WorkflowDocument workflowDocument = new WorkflowDocument(
1989:                        new NetworkIdVO("rkirkend"), documentTypeName);
1990:                workflowDocument
1991:                        .setApplicationContent("<documentContent><searchableContent><putWhateverWordsIwantInsideThisTag>"
1992:                                + "<givenname><value>jack</value></givenname>"
1993:                                + "</putWhateverWordsIwantInsideThisTag></searchableContent></documentContent>");
1994:
1995:                workflowDocument.setTitle("Routing style");
1996:                workflowDocument.routeDocument("routing this document.");
1997:
1998:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
1999:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
2000:                UserService userService = (UserService) KEWServiceLocator
2001:                        .getService(KEWServiceLocator.USER_SERVICE);
2002:
2003:                WorkflowUser user = userService
2004:                        .getWorkflowUser(new AuthenticationUserId("rkirkend"));
2005:                DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
2006:                criteria.setDocTypeFullName(documentTypeName);
2007:                criteria
2008:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
2009:                                key, "jack", docType));
2010:                DocumentSearchResultComponents result = docSearchService
2011:                        .getList(user, criteria);
2012:                List searchResults = result.getSearchResults();
2013:
2014:                assertEquals("Search results should be empty.", 1,
2015:                        searchResults.size());
2016:
2017:                criteria = new DocSearchCriteriaVO();
2018:                criteria.setDocTypeFullName(documentTypeName);
2019:                criteria
2020:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
2021:                                key, "fred", docType));
2022:                result = docSearchService.getList(user, criteria);
2023:                searchResults = result.getSearchResults();
2024:
2025:                assertEquals("Search results should be empty.", 0,
2026:                        searchResults.size());
2027:
2028:                criteria = new DocSearchCriteriaVO();
2029:                criteria.setDocTypeFullName(documentTypeName);
2030:                criteria
2031:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
2032:                                "fakeproperty", "doesntexist", docType));
2033:                try {
2034:                    result = docSearchService.getList(user, criteria);
2035:                    fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
2036:                } catch (WorkflowServiceErrorException wsee) {
2037:                }
2038:            }
2039:
2040:            @Ignore("Implement Me")
2041:            @Test
2042:            public void testDisplayTypeMultiboxSearch() throws Exception {
2043:
2044:            }
2045:
2046:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.