Source Code Cross Referenced for StandardGenericXMLSearchableAttributeRangesTest.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.math.BigDecimal;
0020:        import java.util.Calendar;
0021:        import java.util.HashMap;
0022:        import java.util.Iterator;
0023:        import java.util.List;
0024:        import java.util.Map;
0025:
0026:        import org.junit.Test;
0027:        import org.kuali.workflow.test.WorkflowTestCase;
0028:
0029:        import edu.iu.uis.eden.KEWServiceLocator;
0030:        import edu.iu.uis.eden.WorkflowServiceErrorException;
0031:        import edu.iu.uis.eden.clientapp.WorkflowDocument;
0032:        import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
0033:        import edu.iu.uis.eden.clientapp.vo.WorkflowAttributeDefinitionVO;
0034:        import edu.iu.uis.eden.docsearch.DocSearchCriteriaVO;
0035:        import edu.iu.uis.eden.docsearch.DocSearchUtils;
0036:        import edu.iu.uis.eden.docsearch.DocumentSearchResultComponents;
0037:        import edu.iu.uis.eden.docsearch.DocumentSearchService;
0038:        import edu.iu.uis.eden.docsearch.SearchAttributeCriteriaComponent;
0039:        import edu.iu.uis.eden.docsearch.SearchableAttribute;
0040:        import edu.iu.uis.eden.docsearch.SearchableAttributeDateTimeValue;
0041:        import edu.iu.uis.eden.docsearch.SearchableAttributeFloatValue;
0042:        import edu.iu.uis.eden.docsearch.SearchableAttributeLongValue;
0043:        import edu.iu.uis.eden.docsearch.SearchableAttributeStringValue;
0044:        import edu.iu.uis.eden.docsearch.SearchableAttributeValue;
0045:        import edu.iu.uis.eden.docsearch.TestXMLSearchableAttributeDateTime;
0046:        import edu.iu.uis.eden.docsearch.TestXMLSearchableAttributeFloat;
0047:        import edu.iu.uis.eden.docsearch.TestXMLSearchableAttributeLong;
0048:        import edu.iu.uis.eden.docsearch.TestXMLSearchableAttributeString;
0049:        import edu.iu.uis.eden.doctype.DocumentType;
0050:        import edu.iu.uis.eden.doctype.DocumentTypeService;
0051:        import edu.iu.uis.eden.lookupable.Field;
0052:        import edu.iu.uis.eden.lookupable.Row;
0053:        import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
0054:        import edu.iu.uis.eden.routetemplate.RuleAttribute;
0055:        import edu.iu.uis.eden.routetemplate.WorkflowAttributeValidationError;
0056:        import edu.iu.uis.eden.user.AuthenticationUserId;
0057:        import edu.iu.uis.eden.user.UserService;
0058:        import edu.iu.uis.eden.user.WorkflowUser;
0059:        import edu.iu.uis.eden.util.Utilities;
0060:
0061:        /**
0062:         * Tests the StandardGenericXMLSearchableAttribute.
0063:         * 
0064:         * KULWF-654: Tests the resolution to this issue by configuring a CustomActionListAttribute as well as a
0065:         * searchable attribute.
0066:         */
0067:        public class StandardGenericXMLSearchableAttributeRangesTest extends
0068:                WorkflowTestCase {
0069:
0070:            protected void loadTestData() throws Exception {
0071:                loadXmlFile("XmlConfig.xml");
0072:            }
0073:
0074:            private StandardGenericXMLSearchableAttribute getAttribute(
0075:                    String name) {
0076:                String attName = name;
0077:                if (attName == null) {
0078:                    attName = "XMLSearchableAttribute";
0079:                }
0080:                RuleAttribute ruleAttribute = KEWServiceLocator
0081:                        .getRuleAttributeService().findByName(attName);
0082:                StandardGenericXMLSearchableAttribute attribute = new StandardGenericXMLSearchableAttribute();
0083:                attribute.setRuleAttribute(ruleAttribute);
0084:                return attribute;
0085:            }
0086:
0087:            private SearchAttributeCriteriaComponent createSearchAttributeCriteriaComponent(
0088:                    String key, String value, Boolean isLowerBoundValue,
0089:                    DocumentType docType) {
0090:                String formKey = (isLowerBoundValue == null) ? key
0091:                        : ((isLowerBoundValue != null && isLowerBoundValue
0092:                                .booleanValue()) ? SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX
0093:                                + key
0094:                                : SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX
0095:                                        + key);
0096:                String savedKey = key;
0097:                SearchAttributeCriteriaComponent sacc = new SearchAttributeCriteriaComponent(
0098:                        formKey, value, savedKey);
0099:                Field field = getFieldByFormKey(docType, formKey);
0100:                if (field != null) {
0101:                    sacc.setSearchableAttributeValue(DocSearchUtils
0102:                            .getSearchableAttributeValueByDataTypeString(field
0103:                                    .getFieldDataType()));
0104:                    sacc.setRangeSearch(field.isMemberOfRange());
0105:                    sacc.setAllowWildcards(field.isAllowingWildcards());
0106:                    sacc.setAutoWildcardBeginning(field
0107:                            .isAutoWildcardAtBeginning());
0108:                    sacc.setAutoWildcardEnd(field.isAutoWildcardAtEnding());
0109:                    sacc.setCaseSensitive(field.isCaseSensitive());
0110:                    sacc.setSearchInclusive(field.isInclusive());
0111:                    sacc.setSearchable(field.isSearchable());
0112:                    sacc.setCanHoldMultipleValues(Field.MULTI_VALUE_FIELD_TYPES
0113:                            .contains(field.getFieldType()));
0114:                }
0115:                return sacc;
0116:            }
0117:
0118:            private Field getFieldByFormKey(DocumentType docType, String formKey) {
0119:                if (docType == null) {
0120:                    return null;
0121:                }
0122:                for (SearchableAttribute searchableAttribute : docType
0123:                        .getSearchableAttributes()) {
0124:                    for (Row row : searchableAttribute.getSearchingRows()) {
0125:                        for (Field field : row.getFields()) {
0126:                            if (field.getPropertyName().equals(formKey)) {
0127:                                return field;
0128:                            }
0129:                        }
0130:                    }
0131:                }
0132:                return null;
0133:            }
0134:
0135:            /*
0136:             * Test method for 'edu.iu.uis.eden.docsearch.xml.StandardGenericXMLSearchableAttribute.getSearchingRows()'
0137:             */
0138:            @Test
0139:            public void testGetSearchingRowsUsingRangeSearches() {
0140:                StandardGenericXMLSearchableAttribute searchAttribute = getAttribute("XMLSearchableAttributeStringRange");
0141:                List searchRows = searchAttribute.getSearchingRows();
0142:                if ((new SearchableAttributeStringValue())
0143:                        .allowsRangeSearches()) {
0144:                    fail("Cannot perform range search on string field at database level");
0145:                    //            assertEquals("Invalid number of search rows", 2, searchRows.size());
0146:                    //            for (int i = 1; i <= searchRows.size(); i++) {
0147:                    //				Row row = (Row)searchRows.get(i - 1);
0148:                    //	            assertEquals("Invalid number of fields for search row " + i, 1, row.getFields().size());
0149:                    //	            assertTrue("Field is not the member of a range",row.getField(0).isMemberOfRange());
0150:                    //			}
0151:                } else {
0152:                    assertEquals("Invalid number of search rows", 1, searchRows
0153:                            .size());
0154:                    Row row = (Row) searchRows.get(0);
0155:                    assertEquals("Invalid number of fields for search row", 1,
0156:                            row.getFields().size());
0157:                    assertFalse(
0158:                            "Field is the member of a range when ranges are not allowed",
0159:                            row.getField(0).isMemberOfRange());
0160:                }
0161:
0162:                searchAttribute = getAttribute("XMLSearchableAttributeStdLongRange");
0163:                // search def :  rangeSearch=true
0164:                // range def  :  
0165:                // upper def  :  
0166:                // lower def  :  
0167:                searchRows = searchAttribute.getSearchingRows();
0168:                if ((new SearchableAttributeLongValue()).allowsRangeSearches()) {
0169:                    assertEquals("Invalid number of search rows", 2, searchRows
0170:                            .size());
0171:                    for (int i = 1; i <= searchRows.size(); i++) {
0172:                        Row row = (Row) searchRows.get(i - 1);
0173:                        assertEquals("Invalid number of fields for search row "
0174:                                + i, 1, row.getFields().size());
0175:                        Field field = row.getField(0);
0176:                        assertTrue("Field should be the member of a range",
0177:                                field.isMemberOfRange());
0178:                        assertTrue("Field should not be inclusive", field
0179:                                .isInclusive());
0180:                        assertFalse("Field should not be using datepicker",
0181:                                field.isUsingDatePicker());
0182:                    }
0183:                } else {
0184:                    assertEquals("Invalid number of search rows", 1, searchRows
0185:                            .size());
0186:                    Row row = (Row) searchRows.get(0);
0187:                    assertEquals("Invalid number of fields for search row", 1,
0188:                            row.getFields().size());
0189:                    Field field = row.getField(0);
0190:                    assertFalse(
0191:                            "Field is the member of a range when ranges are not allowed",
0192:                            field.isMemberOfRange());
0193:                    assertFalse(
0194:                            "Field is inclusive when ranges are not allowed",
0195:                            field.isInclusive());
0196:                    assertFalse("Field should not be using datepicker", field
0197:                            .isUsingDatePicker());
0198:                }
0199:
0200:                searchAttribute = getAttribute("XMLSearchableAttributeStdFloatRange");
0201:                // search def :  
0202:                // range def  :  inclusive=false
0203:                // upper def  :  label=ending
0204:                // lower def  :  label=starting
0205:                searchRows = searchAttribute.getSearchingRows();
0206:                if ((new SearchableAttributeFloatValue()).allowsRangeSearches()) {
0207:                    assertEquals("Invalid number of search rows", 2, searchRows
0208:                            .size());
0209:                    for (int i = 1; i <= searchRows.size(); i++) {
0210:                        Row row = (Row) searchRows.get(i - 1);
0211:                        assertEquals("Invalid number of fields for search row "
0212:                                + i, 1, row.getFields().size());
0213:                        Field field = row.getField(0);
0214:                        assertTrue(
0215:                                "Upper and Lower Fields should be members of a range",
0216:                                field.isMemberOfRange());
0217:                        assertFalse(
0218:                                "Upper and Lower Fields should not be inclusive",
0219:                                field.isInclusive());
0220:                        String labelValue = null;
0221:                        if (field
0222:                                .getPropertyName()
0223:                                .startsWith(
0224:                                        SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX)) {
0225:                            labelValue = "starting";
0226:                        } else if (field
0227:                                .getPropertyName()
0228:                                .startsWith(
0229:                                        SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX)) {
0230:                            labelValue = "ending";
0231:                        } else {
0232:                            fail("Field should have prefix consistent with upper or lower bound of a range");
0233:                        }
0234:                        assertEquals("Field label is incorrect.", labelValue,
0235:                                field.getFieldLabel());
0236:                        assertFalse("Field should not be using datepicker",
0237:                                field.isUsingDatePicker());
0238:                    }
0239:                } else {
0240:                    assertEquals("Invalid number of search rows", 1, searchRows
0241:                            .size());
0242:                    Row row = (Row) searchRows.get(0);
0243:                    assertEquals("Invalid number of fields for search row", 1,
0244:                            row.getFields().size());
0245:                    Field field = row.getField(0);
0246:                    assertFalse(
0247:                            "Field is the member of a range when ranges are not allowed",
0248:                            field.isMemberOfRange());
0249:                    assertFalse("Field should not be using datepicker", field
0250:                            .isUsingDatePicker());
0251:                }
0252:
0253:                searchAttribute = getAttribute("XMLSearchableAttributeStdDateTimeRange");
0254:                // search def :  datePicker=false
0255:                // range def  :  inclusive=false
0256:                // upper def  :  inclusvie=true - datePicker=true
0257:                // lower def  :  
0258:                searchRows = searchAttribute.getSearchingRows();
0259:                if ((new SearchableAttributeDateTimeValue())
0260:                        .allowsRangeSearches()) {
0261:                    assertEquals("Invalid number of search rows", 2, searchRows
0262:                            .size());
0263:                    for (int i = 0; i < searchRows.size(); i++) {
0264:                        Row row = (Row) searchRows.get(i);
0265:                        assertTrue("Invalid number of fields for search row",
0266:                                row.getFields().size() > 0);
0267:                        Field field = row.getField(0);
0268:                        assertTrue(
0269:                                "Field should be the member of a range search",
0270:                                field.isMemberOfRange());
0271:                        if (field
0272:                                .getPropertyName()
0273:                                .startsWith(
0274:                                        SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX)) {
0275:                            // this is the lower bound row
0276:                            assertFalse(
0277:                                    "Upper Field should not be using datepicker field",
0278:                                    field.isUsingDatePicker());
0279:                            assertFalse("Upper Field should not be inclusive",
0280:                                    field.isInclusive());
0281:                        } else if (field
0282:                                .getPropertyName()
0283:                                .startsWith(
0284:                                        SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX)) {
0285:                            // this is the upper bound row
0286:                            assertTrue(
0287:                                    "Upper Field should be using datepicker field",
0288:                                    field.isUsingDatePicker());
0289:                            assertTrue("Upper Field should not be inclusive",
0290:                                    field.isInclusive());
0291:                            assertEquals(
0292:                                    "Row should have two fields (including the datepicker field)",
0293:                                    2, row.getFields().size());
0294:                            assertEquals(
0295:                                    "Second field in row  should be of type datepicker",
0296:                                    Field.DATEPICKER, row.getField(1)
0297:                                            .getFieldType());
0298:                        } else {
0299:                            fail("Field should have prefix consistent with upper or lower bound of a range");
0300:                        }
0301:                    }
0302:                } else {
0303:                    assertEquals("Invalid number of search rows", 1, searchRows
0304:                            .size());
0305:                    Row row = (Row) searchRows.get(0);
0306:                    // check to make sure our datepicker field didn't make it to the search rows
0307:                    assertEquals("Invalid number of fields", 1, row.getFields()
0308:                            .size());
0309:                    assertFalse(
0310:                            "Field is the member of a range when ranges are not allowed",
0311:                            row.getField(0).isMemberOfRange());
0312:                }
0313:            }
0314:
0315:            /*
0316:             * Test method for 'edu.iu.uis.eden.docsearch.xml.StandardGenericXMLSearchableAttribute.validateUserSearchInputs(Map)'
0317:             */
0318:            @Test
0319:            public void testValidateUserSearchRangeInputs() {
0320:                // upper bound and lower bound fields should be using same validation... we just altername which formKey we use here
0321:                StandardGenericXMLSearchableAttribute searchAttribute = getAttribute("XMLSearchableAttributeStringRange");
0322:                Map paramMap = new HashMap();
0323:                paramMap
0324:                        .put(
0325:                                SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX
0326:                                        + TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
0327:                                "jack");
0328:                List validationErrors = searchAttribute
0329:                        .validateUserSearchInputs(paramMap);
0330:                assertEquals("Validation should not have returned an error.",
0331:                        0, validationErrors.size());
0332:                paramMap.clear();
0333:                paramMap
0334:                        .put(
0335:                                SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX
0336:                                        + TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
0337:                                "jack.jack");
0338:                validationErrors = searchAttribute
0339:                        .validateUserSearchInputs(paramMap);
0340:                assertEquals(
0341:                        "Validation should return a single error message.", 1,
0342:                        validationErrors.size());
0343:                WorkflowAttributeValidationError error = (WorkflowAttributeValidationError) validationErrors
0344:                        .get(0);
0345:                assertEquals(
0346:                        "Validation error should match xml attribute message",
0347:                        "Invalid first name", error.getMessage());
0348:                paramMap.clear();
0349:                paramMap
0350:                        .put(
0351:                                SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX
0352:                                        + TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
0353:                                "jack*jack");
0354:                validationErrors = searchAttribute
0355:                        .validateUserSearchInputs(paramMap);
0356:                assertEquals(
0357:                        "Validation should return a single error message.", 0,
0358:                        validationErrors.size());
0359:
0360:                searchAttribute = getAttribute("XMLSearchableAttributeStdLongRange");
0361:                paramMap = new HashMap();
0362:                paramMap
0363:                        .put(
0364:                                SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX
0365:                                        + TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0366:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE
0367:                                        .toString());
0368:                validationErrors = searchAttribute
0369:                        .validateUserSearchInputs(paramMap);
0370:                assertEquals("Validation should not have returned an error.",
0371:                        0, validationErrors.size());
0372:                paramMap.clear();
0373:                paramMap
0374:                        .put(
0375:                                SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX
0376:                                        + TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0377:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE
0378:                                        .toString()
0379:                                        + ".33");
0380:                validationErrors = searchAttribute
0381:                        .validateUserSearchInputs(paramMap);
0382:                assertEquals(
0383:                        "Validation should return a single error message.", 1,
0384:                        validationErrors.size());
0385:                error = (WorkflowAttributeValidationError) validationErrors
0386:                        .get(0);
0387:                assertTrue(
0388:                        "Validation error is incorrect",
0389:                        error
0390:                                .getMessage()
0391:                                .endsWith(
0392:                                        "does not conform to standard validation for field type."));
0393:                paramMap.clear();
0394:                paramMap
0395:                        .put(
0396:                                SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX
0397:                                        + TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0398:                                "jack*jack");
0399:                validationErrors = searchAttribute
0400:                        .validateUserSearchInputs(paramMap);
0401:                assertEquals(
0402:                        "Validation should return a single error message.", 1,
0403:                        validationErrors.size());
0404:                error = (WorkflowAttributeValidationError) validationErrors
0405:                        .get(0);
0406:                assertTrue(
0407:                        "Validation error is incorrect",
0408:                        error
0409:                                .getMessage()
0410:                                .endsWith(
0411:                                        "does not conform to standard validation for field type."));
0412:
0413:                searchAttribute = getAttribute("XMLSearchableAttributeStdFloatRange");
0414:                paramMap = new HashMap();
0415:                paramMap
0416:                        .put(
0417:                                SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX
0418:                                        + TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
0419:                                TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE
0420:                                        .toString());
0421:                validationErrors = searchAttribute
0422:                        .validateUserSearchInputs(paramMap);
0423:                assertEquals("Validation should not have returned an error.",
0424:                        0, validationErrors.size());
0425:                paramMap.clear();
0426:                paramMap
0427:                        .put(
0428:                                SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX
0429:                                        + TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
0430:                                TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE
0431:                                        .toString()
0432:                                        + "a");
0433:                validationErrors = searchAttribute
0434:                        .validateUserSearchInputs(paramMap);
0435:                assertEquals(
0436:                        "Validation should return a single error message.", 1,
0437:                        validationErrors.size());
0438:                error = (WorkflowAttributeValidationError) validationErrors
0439:                        .get(0);
0440:                assertTrue(
0441:                        "Validation error is incorrect",
0442:                        error
0443:                                .getMessage()
0444:                                .endsWith(
0445:                                        "does not conform to standard validation for field type."));
0446:                paramMap.clear();
0447:                paramMap
0448:                        .put(
0449:                                SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX
0450:                                        + TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
0451:                                TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE
0452:                                        .toString()
0453:                                        + "*");
0454:                validationErrors = searchAttribute
0455:                        .validateUserSearchInputs(paramMap);
0456:                assertEquals(
0457:                        "Validation should return a single error message.", 1,
0458:                        validationErrors.size());
0459:                error = (WorkflowAttributeValidationError) validationErrors
0460:                        .get(0);
0461:                assertTrue(
0462:                        "Validation error is incorrect",
0463:                        error
0464:                                .getMessage()
0465:                                .endsWith(
0466:                                        "does not conform to standard validation for field type."));
0467:
0468:                searchAttribute = getAttribute("XMLSearchableAttributeStdDateTimeRange");
0469:                paramMap = new HashMap();
0470:                paramMap
0471:                        .put(
0472:                                SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX
0473:                                        + TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
0474:                                DocSearchUtils
0475:                                        .getDisplayValueWithDateOnly(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE));
0476:                validationErrors = searchAttribute
0477:                        .validateUserSearchInputs(paramMap);
0478:                assertEquals("Validation should not have returned an error.",
0479:                        0, validationErrors.size());
0480:                paramMap.clear();
0481:                paramMap
0482:                        .put(
0483:                                SearchableAttribute.RANGE_LOWER_BOUND_PROPERTY_PREFIX
0484:                                        + TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
0485:                                "001/5/08");
0486:                validationErrors = searchAttribute
0487:                        .validateUserSearchInputs(paramMap);
0488:                assertEquals(
0489:                        "Validation should return a single error message.", 1,
0490:                        validationErrors.size());
0491:                error = (WorkflowAttributeValidationError) validationErrors
0492:                        .get(0);
0493:                assertTrue(
0494:                        "Validation error is incorrect",
0495:                        error
0496:                                .getMessage()
0497:                                .endsWith(
0498:                                        "does not conform to standard validation for field type."));
0499:                paramMap.clear();
0500:                paramMap
0501:                        .put(
0502:                                SearchableAttribute.RANGE_UPPER_BOUND_PROPERTY_PREFIX
0503:                                        + TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
0504:                                "01/02/20*");
0505:                validationErrors = searchAttribute
0506:                        .validateUserSearchInputs(paramMap);
0507:                assertEquals(
0508:                        "Validation should return a single error message.", 1,
0509:                        validationErrors.size());
0510:                error = (WorkflowAttributeValidationError) validationErrors
0511:                        .get(0);
0512:                assertTrue(
0513:                        "Validation error is incorrect",
0514:                        error
0515:                                .getMessage()
0516:                                .endsWith(
0517:                                        "does not conform to standard validation for field type."));
0518:            }
0519:
0520:            /**
0521:             * Test searching by searchable attributes that use ranges
0522:             */
0523:            @Test
0524:            public void testSearchableAttributeRanges() throws Exception {
0525:                String documentTypeName = "SearchDocTypeRangeSearchDataType";
0526:                DocumentType docType = ((DocumentTypeService) KEWServiceLocator
0527:                        .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
0528:                        .findByName(documentTypeName);
0529:                String userNetworkId = "rkirkend";
0530:                WorkflowDocument workflowDocument = new WorkflowDocument(
0531:                        new NetworkIdVO(userNetworkId), documentTypeName);
0532:
0533:                /*
0534:                 *   Below we are using the keys and values from the custom searchable attribute classes' static constants but 
0535:                 *   this is only for convenience as those should always be valid values to test for.
0536:                 */
0537:                // adding string searchable attribute
0538:                WorkflowAttributeDefinitionVO stringXMLDef = new WorkflowAttributeDefinitionVO(
0539:                        "XMLSearchableAttributeStringRange");
0540:                stringXMLDef.addProperty(
0541:                        TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
0542:                        TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE);
0543:                workflowDocument.addSearchableDefinition(stringXMLDef);
0544:                // adding long searchable attribute
0545:                WorkflowAttributeDefinitionVO longXMLDef = new WorkflowAttributeDefinitionVO(
0546:                        "XMLSearchableAttributeStdLongRange");
0547:                longXMLDef.addProperty(
0548:                        TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0549:                        TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE
0550:                                .toString());
0551:                workflowDocument.addSearchableDefinition(longXMLDef);
0552:                // adding float searchable attribute
0553:                WorkflowAttributeDefinitionVO floatXMLDef = new WorkflowAttributeDefinitionVO(
0554:                        "XMLSearchableAttributeStdFloatRange");
0555:                floatXMLDef.addProperty(
0556:                        TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
0557:                        TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE
0558:                                .toString());
0559:                workflowDocument.addSearchableDefinition(floatXMLDef);
0560:                // adding string searchable attribute
0561:                WorkflowAttributeDefinitionVO dateXMLDef = new WorkflowAttributeDefinitionVO(
0562:                        "XMLSearchableAttributeStdDateTimeRange");
0563:                dateXMLDef
0564:                        .addProperty(
0565:                                TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
0566:                                DocSearchUtils
0567:                                        .getDisplayValueWithDateOnly(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE));
0568:                workflowDocument.addSearchableDefinition(dateXMLDef);
0569:
0570:                workflowDocument.setTitle("Routing style");
0571:                workflowDocument.routeDocument("routing this document.");
0572:
0573:                workflowDocument = new WorkflowDocument(new NetworkIdVO(
0574:                        userNetworkId), workflowDocument.getRouteHeaderId());
0575:                DocumentRouteHeaderValue doc = KEWServiceLocator
0576:                        .getRouteHeaderService().getRouteHeader(
0577:                                workflowDocument.getRouteHeaderId());
0578:                assertEquals("Wrong number of searchable attributes", 4, doc
0579:                        .getSearchableAttributeValues().size());
0580:                for (Iterator iter = doc.getSearchableAttributeValues()
0581:                        .iterator(); iter.hasNext();) {
0582:                    SearchableAttributeValue attributeValue = (SearchableAttributeValue) iter
0583:                            .next();
0584:                    if (attributeValue instanceof  SearchableAttributeStringValue) {
0585:                        SearchableAttributeStringValue realValue = (SearchableAttributeStringValue) attributeValue;
0586:                        assertEquals(
0587:                                "The only String attribute that should have been added has key '"
0588:                                        + TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY
0589:                                        + "'",
0590:                                TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
0591:                                realValue.getSearchableAttributeKey());
0592:                        assertEquals(
0593:                                "The only String attribute that should have been added has value '"
0594:                                        + TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE
0595:                                        + "'",
0596:                                TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE,
0597:                                realValue.getSearchableAttributeValue());
0598:                    } else if (attributeValue instanceof  SearchableAttributeLongValue) {
0599:                        SearchableAttributeLongValue realValue = (SearchableAttributeLongValue) attributeValue;
0600:                        assertEquals(
0601:                                "The only Long attribute that should have been added has key '"
0602:                                        + TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY
0603:                                        + "'",
0604:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
0605:                                realValue.getSearchableAttributeKey());
0606:                        assertEquals(
0607:                                "The only Long attribute that should have been added has value '"
0608:                                        + TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE
0609:                                        + "'",
0610:                                TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE,
0611:                                realValue.getSearchableAttributeValue());
0612:                    } else if (attributeValue instanceof  SearchableAttributeFloatValue) {
0613:                        SearchableAttributeFloatValue realValue = (SearchableAttributeFloatValue) attributeValue;
0614:                        assertEquals(
0615:                                "The only Float attribute that should have been added has key '"
0616:                                        + TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY
0617:                                        + "'",
0618:                                TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
0619:                                realValue.getSearchableAttributeKey());
0620:                        assertEquals(
0621:                                "The only Float attribute that should have been added has value '"
0622:                                        + TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE
0623:                                        + "'",
0624:                                TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE,
0625:                                realValue.getSearchableAttributeValue());
0626:                    } else if (attributeValue instanceof  SearchableAttributeDateTimeValue) {
0627:                        SearchableAttributeDateTimeValue realValue = (SearchableAttributeDateTimeValue) attributeValue;
0628:                        assertEquals(
0629:                                "The only DateTime attribute that should have been added has key '"
0630:                                        + TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY
0631:                                        + "'",
0632:                                TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
0633:                                realValue.getSearchableAttributeKey());
0634:                        Calendar testDate = Calendar.getInstance();
0635:                        testDate
0636:                                .setTimeInMillis(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE_IN_MILLS);
0637:                        testDate.set(Calendar.SECOND, 0);
0638:                        testDate.set(Calendar.MILLISECOND, 0);
0639:                        Calendar attributeDate = Calendar.getInstance();
0640:                        attributeDate.setTimeInMillis(realValue
0641:                                .getSearchableAttributeValue().getTime());
0642:                        attributeDate.set(Calendar.SECOND, 0);
0643:                        attributeDate.set(Calendar.MILLISECOND, 0);
0644:                        assertEquals(
0645:                                "The month value for the searchable attribute is wrong",
0646:                                testDate.get(Calendar.MONTH), attributeDate
0647:                                        .get(Calendar.MONTH));
0648:                        assertEquals(
0649:                                "The date value for the searchable attribute is wrong",
0650:                                testDate.get(Calendar.DATE), attributeDate
0651:                                        .get(Calendar.DATE));
0652:                        assertEquals(
0653:                                "The year value for the searchable attribute is wrong",
0654:                                testDate.get(Calendar.YEAR), attributeDate
0655:                                        .get(Calendar.YEAR));
0656:                    } else {
0657:                        fail("Searchable Attribute Value base class should be one of the four checked always");
0658:                    }
0659:                }
0660:
0661:                DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator
0662:                        .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
0663:                UserService userService = (UserService) KEWServiceLocator
0664:                        .getService(KEWServiceLocator.USER_SERVICE);
0665:                WorkflowUser user = userService
0666:                        .getWorkflowUser(new AuthenticationUserId(userNetworkId));
0667:
0668:                // begin string attribute value testing
0669:                DocSearchCriteriaVO criteria = null;
0670:                List searchResults = null;
0671:                DocumentSearchResultComponents result = null;
0672:
0673:                criteria = new DocSearchCriteriaVO();
0674:                criteria.setDocTypeFullName(documentTypeName);
0675:                criteria
0676:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0677:                                TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
0678:                                TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE,
0679:                                Boolean.TRUE, docType));
0680:                if ((new SearchableAttributeStringValue())
0681:                        .allowsRangeSearches()) {
0682:                    fail("Cannot search by range on a String field at the database level");
0683:                } else {
0684:                    try {
0685:                        result = docSearchService.getList(user, criteria);
0686:                        fail("Searching by range for field using key '"
0687:                                + TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY
0688:                                + "' should throw exception");
0689:                    } catch (Exception e) {
0690:                    }
0691:                }
0692:
0693:                // begin long attribute value testing
0694:                // inclusive = true
0695:                String searchAttributeLongKey = TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY;
0696:                Long searchAttributeLongValue = TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE;
0697:
0698:                Long longValueToUse = null;
0699:                // test lower bound only
0700:                criteria = new DocSearchCriteriaVO();
0701:                criteria.setDocTypeFullName(documentTypeName);
0702:                longValueToUse = searchAttributeLongValue;
0703:                criteria
0704:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0705:                                searchAttributeLongKey, longValueToUse
0706:                                        .toString(), Boolean.TRUE, docType));
0707:                criteria
0708:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0709:                                searchAttributeLongKey, "", Boolean.FALSE,
0710:                                docType));
0711:                result = docSearchService.getList(user, criteria);
0712:                searchResults = result.getSearchResults();
0713:                assertEquals("Search results should have one document.", 1,
0714:                        searchResults.size());
0715:                criteria = new DocSearchCriteriaVO();
0716:                criteria.setDocTypeFullName(documentTypeName);
0717:                longValueToUse = Long.valueOf(searchAttributeLongValue
0718:                        .longValue() - 1);
0719:                criteria
0720:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0721:                                searchAttributeLongKey, longValueToUse
0722:                                        .toString(), Boolean.TRUE, docType));
0723:                criteria
0724:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0725:                                searchAttributeLongKey, "", Boolean.FALSE,
0726:                                docType));
0727:                result = docSearchService.getList(user, criteria);
0728:                searchResults = result.getSearchResults();
0729:                assertEquals("Search results should have one document.", 1,
0730:                        searchResults.size());
0731:                criteria = new DocSearchCriteriaVO();
0732:                criteria.setDocTypeFullName(documentTypeName);
0733:                longValueToUse = Long.valueOf(searchAttributeLongValue
0734:                        .longValue() + 1);
0735:                criteria
0736:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0737:                                searchAttributeLongKey, longValueToUse
0738:                                        .toString(), Boolean.TRUE, docType));
0739:                criteria
0740:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0741:                                searchAttributeLongKey, "", Boolean.FALSE,
0742:                                docType));
0743:                result = docSearchService.getList(user, criteria);
0744:                searchResults = result.getSearchResults();
0745:                assertEquals("Search results should have one document.", 0,
0746:                        searchResults.size());
0747:
0748:                // test upper bound only
0749:                criteria = new DocSearchCriteriaVO();
0750:                criteria.setDocTypeFullName(documentTypeName);
0751:                longValueToUse = searchAttributeLongValue;
0752:                criteria
0753:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0754:                                searchAttributeLongKey, "", Boolean.TRUE,
0755:                                docType));
0756:                criteria
0757:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0758:                                searchAttributeLongKey, longValueToUse
0759:                                        .toString(), Boolean.FALSE, docType));
0760:                result = docSearchService.getList(user, criteria);
0761:                searchResults = result.getSearchResults();
0762:                assertEquals("Search results should have one document.", 1,
0763:                        searchResults.size());
0764:                criteria = new DocSearchCriteriaVO();
0765:                criteria.setDocTypeFullName(documentTypeName);
0766:                longValueToUse = Long.valueOf(searchAttributeLongValue
0767:                        .longValue() - 1);
0768:                criteria
0769:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0770:                                searchAttributeLongKey, "", Boolean.TRUE,
0771:                                docType));
0772:                criteria
0773:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0774:                                searchAttributeLongKey, longValueToUse
0775:                                        .toString(), Boolean.FALSE, docType));
0776:                result = docSearchService.getList(user, criteria);
0777:                searchResults = result.getSearchResults();
0778:                assertEquals("Search results should have one document.", 0,
0779:                        searchResults.size());
0780:                criteria = new DocSearchCriteriaVO();
0781:                criteria.setDocTypeFullName(documentTypeName);
0782:                longValueToUse = Long.valueOf(searchAttributeLongValue
0783:                        .longValue() + 1);
0784:                criteria
0785:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0786:                                searchAttributeLongKey, "", Boolean.TRUE,
0787:                                docType));
0788:                criteria
0789:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0790:                                searchAttributeLongKey, longValueToUse
0791:                                        .toString(), Boolean.FALSE, docType));
0792:                result = docSearchService.getList(user, criteria);
0793:                searchResults = result.getSearchResults();
0794:                assertEquals("Search results should have one document.", 1,
0795:                        searchResults.size());
0796:
0797:                // test both bounds
0798:                criteria = new DocSearchCriteriaVO();
0799:                criteria.setDocTypeFullName(documentTypeName);
0800:                criteria
0801:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0802:                                searchAttributeLongKey, Long.valueOf(
0803:                                        searchAttributeLongValue.longValue())
0804:                                        .toString(), Boolean.TRUE, docType));
0805:                criteria
0806:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0807:                                searchAttributeLongKey, Long.valueOf(
0808:                                        searchAttributeLongValue.longValue())
0809:                                        .toString(), Boolean.FALSE, docType));
0810:                result = docSearchService.getList(user, criteria);
0811:                searchResults = result.getSearchResults();
0812:                assertEquals("Search results should have one document.", 1,
0813:                        searchResults.size());
0814:                criteria = new DocSearchCriteriaVO();
0815:                criteria.setDocTypeFullName(documentTypeName);
0816:                criteria
0817:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0818:                                searchAttributeLongKey, Long
0819:                                        .valueOf(
0820:                                                searchAttributeLongValue
0821:                                                        .longValue() + 2)
0822:                                        .toString(), Boolean.TRUE, docType));
0823:                criteria
0824:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0825:                                searchAttributeLongKey, Long
0826:                                        .valueOf(
0827:                                                searchAttributeLongValue
0828:                                                        .longValue() + 4)
0829:                                        .toString(), Boolean.FALSE, docType));
0830:                result = docSearchService.getList(user, criteria);
0831:                searchResults = result.getSearchResults();
0832:                assertEquals("Search results should have one document.", 0,
0833:                        searchResults.size());
0834:                criteria = new DocSearchCriteriaVO();
0835:                criteria.setDocTypeFullName(documentTypeName);
0836:                criteria
0837:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0838:                                searchAttributeLongKey, Long
0839:                                        .valueOf(
0840:                                                searchAttributeLongValue
0841:                                                        .longValue() - 4)
0842:                                        .toString(), Boolean.TRUE, docType));
0843:                criteria
0844:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0845:                                searchAttributeLongKey, Long
0846:                                        .valueOf(
0847:                                                searchAttributeLongValue
0848:                                                        .longValue() - 2)
0849:                                        .toString(), Boolean.FALSE, docType));
0850:                result = docSearchService.getList(user, criteria);
0851:                searchResults = result.getSearchResults();
0852:                assertEquals("Search results should have one document.", 0,
0853:                        searchResults.size());
0854:                criteria = new DocSearchCriteriaVO();
0855:                criteria.setDocTypeFullName(documentTypeName);
0856:                criteria
0857:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0858:                                searchAttributeLongKey, Long
0859:                                        .valueOf(
0860:                                                searchAttributeLongValue
0861:                                                        .longValue() - 2)
0862:                                        .toString(), Boolean.TRUE, docType));
0863:                criteria
0864:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0865:                                searchAttributeLongKey, Long
0866:                                        .valueOf(
0867:                                                searchAttributeLongValue
0868:                                                        .longValue() + 2)
0869:                                        .toString(), Boolean.FALSE, docType));
0870:                result = docSearchService.getList(user, criteria);
0871:                searchResults = result.getSearchResults();
0872:                assertEquals("Search results should have one document.", 1,
0873:                        searchResults.size());
0874:                criteria = new DocSearchCriteriaVO();
0875:                criteria.setDocTypeFullName(documentTypeName);
0876:                criteria
0877:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0878:                                searchAttributeLongKey, Long
0879:                                        .valueOf(
0880:                                                searchAttributeLongValue
0881:                                                        .longValue() + 2)
0882:                                        .toString(), Boolean.TRUE, docType));
0883:                criteria
0884:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0885:                                searchAttributeLongKey, Long
0886:                                        .valueOf(
0887:                                                searchAttributeLongValue
0888:                                                        .longValue() - 2)
0889:                                        .toString(), Boolean.FALSE, docType));
0890:                try {
0891:                    result = docSearchService.getList(user, criteria);
0892:                    fail("Error should have been thrown for invalid range");
0893:                } catch (WorkflowServiceErrorException e) {
0894:                }
0895:
0896:                // begin float attribute value testing
0897:                // inclusive = false
0898:                String searchAttributeFloatKey = TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY;
0899:                BigDecimal searchAttributeFloatValue = TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE;
0900:
0901:                BigDecimal floatValueToUse = null;
0902:                // test lower bound only
0903:                criteria = new DocSearchCriteriaVO();
0904:                criteria.setDocTypeFullName(documentTypeName);
0905:                floatValueToUse = searchAttributeFloatValue;
0906:                criteria
0907:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0908:                                searchAttributeFloatKey, floatValueToUse
0909:                                        .toString(), Boolean.TRUE, docType));
0910:                criteria
0911:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0912:                                searchAttributeFloatKey, "", Boolean.FALSE,
0913:                                docType));
0914:                result = docSearchService.getList(user, criteria);
0915:                searchResults = result.getSearchResults();
0916:                assertEquals("Search results should have one document.", 0,
0917:                        searchResults.size());
0918:                criteria = new DocSearchCriteriaVO();
0919:                criteria.setDocTypeFullName(documentTypeName);
0920:                floatValueToUse = searchAttributeFloatValue
0921:                        .subtract(BigDecimal.ONE);
0922:                criteria
0923:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0924:                                searchAttributeFloatKey, floatValueToUse
0925:                                        .toString(), Boolean.TRUE, docType));
0926:                criteria
0927:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0928:                                searchAttributeFloatKey, "", Boolean.FALSE,
0929:                                docType));
0930:                result = docSearchService.getList(user, criteria);
0931:                searchResults = result.getSearchResults();
0932:                assertEquals("Search results should have one document.", 1,
0933:                        searchResults.size());
0934:                criteria = new DocSearchCriteriaVO();
0935:                criteria.setDocTypeFullName(documentTypeName);
0936:                floatValueToUse = searchAttributeFloatValue.add(BigDecimal.ONE);
0937:                criteria
0938:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0939:                                searchAttributeFloatKey, floatValueToUse
0940:                                        .toString(), Boolean.TRUE, docType));
0941:                criteria
0942:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0943:                                searchAttributeFloatKey, "", Boolean.FALSE,
0944:                                docType));
0945:                result = docSearchService.getList(user, criteria);
0946:                searchResults = result.getSearchResults();
0947:                assertEquals("Search results should have one document.", 0,
0948:                        searchResults.size());
0949:
0950:                // test upper bound only
0951:                criteria = new DocSearchCriteriaVO();
0952:                criteria.setDocTypeFullName(documentTypeName);
0953:                floatValueToUse = searchAttributeFloatValue;
0954:                criteria
0955:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0956:                                searchAttributeFloatKey, "", Boolean.TRUE,
0957:                                docType));
0958:                criteria
0959:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0960:                                searchAttributeFloatKey, floatValueToUse
0961:                                        .toString(), Boolean.FALSE, docType));
0962:                result = docSearchService.getList(user, criteria);
0963:                searchResults = result.getSearchResults();
0964:                assertEquals("Search results should have one document.", 0,
0965:                        searchResults.size());
0966:                criteria = new DocSearchCriteriaVO();
0967:                criteria.setDocTypeFullName(documentTypeName);
0968:                floatValueToUse = searchAttributeFloatValue
0969:                        .subtract(BigDecimal.ONE);
0970:                criteria
0971:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0972:                                searchAttributeFloatKey, "", Boolean.TRUE,
0973:                                docType));
0974:                criteria
0975:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0976:                                searchAttributeFloatKey, floatValueToUse
0977:                                        .toString(), Boolean.FALSE, docType));
0978:                result = docSearchService.getList(user, criteria);
0979:                searchResults = result.getSearchResults();
0980:                assertEquals("Search results should have one document.", 0,
0981:                        searchResults.size());
0982:                criteria = new DocSearchCriteriaVO();
0983:                criteria.setDocTypeFullName(documentTypeName);
0984:                floatValueToUse = searchAttributeFloatValue.add(BigDecimal.ONE);
0985:                criteria
0986:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0987:                                searchAttributeFloatKey, "", Boolean.TRUE,
0988:                                docType));
0989:                criteria
0990:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
0991:                                searchAttributeFloatKey, floatValueToUse
0992:                                        .toString(), Boolean.FALSE, docType));
0993:                result = docSearchService.getList(user, criteria);
0994:                searchResults = result.getSearchResults();
0995:                assertEquals("Search results should have one document.", 1,
0996:                        searchResults.size());
0997:
0998:                // test both bounds
0999:                criteria = new DocSearchCriteriaVO();
1000:                criteria.setDocTypeFullName(documentTypeName);
1001:                criteria
1002:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1003:                                searchAttributeFloatKey,
1004:                                searchAttributeFloatValue.toString(),
1005:                                Boolean.TRUE, docType));
1006:                criteria
1007:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1008:                                searchAttributeFloatKey,
1009:                                searchAttributeFloatValue.toString(),
1010:                                Boolean.FALSE, docType));
1011:                result = docSearchService.getList(user, criteria);
1012:                searchResults = result.getSearchResults();
1013:                assertEquals("Search results should have one document.", 0,
1014:                        searchResults.size());
1015:                criteria = new DocSearchCriteriaVO();
1016:                criteria.setDocTypeFullName(documentTypeName);
1017:                criteria
1018:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1019:                                searchAttributeFloatKey,
1020:                                (searchAttributeFloatValue
1021:                                        .add(new BigDecimal(2))).toString(),
1022:                                Boolean.TRUE, docType));
1023:                criteria
1024:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1025:                                searchAttributeFloatKey,
1026:                                (searchAttributeFloatValue
1027:                                        .add(new BigDecimal(4))).toString(),
1028:                                Boolean.FALSE, docType));
1029:                result = docSearchService.getList(user, criteria);
1030:                searchResults = result.getSearchResults();
1031:                assertEquals("Search results should have one document.", 0,
1032:                        searchResults.size());
1033:                criteria = new DocSearchCriteriaVO();
1034:                criteria.setDocTypeFullName(documentTypeName);
1035:                criteria
1036:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1037:                                searchAttributeFloatKey,
1038:                                (searchAttributeFloatValue
1039:                                        .subtract(new BigDecimal(4)))
1040:                                        .toString(), Boolean.TRUE, docType));
1041:                criteria
1042:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1043:                                searchAttributeFloatKey,
1044:                                (searchAttributeFloatValue
1045:                                        .subtract(new BigDecimal(2)))
1046:                                        .toString(), Boolean.FALSE, docType));
1047:                result = docSearchService.getList(user, criteria);
1048:                searchResults = result.getSearchResults();
1049:                assertEquals("Search results should have one document.", 0,
1050:                        searchResults.size());
1051:                criteria = new DocSearchCriteriaVO();
1052:                criteria.setDocTypeFullName(documentTypeName);
1053:                criteria
1054:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1055:                                searchAttributeFloatKey,
1056:                                (searchAttributeFloatValue
1057:                                        .subtract(new BigDecimal(2)))
1058:                                        .toString(), Boolean.TRUE, docType));
1059:                criteria
1060:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1061:                                searchAttributeFloatKey,
1062:                                (searchAttributeFloatValue
1063:                                        .add(new BigDecimal(2))).toString(),
1064:                                Boolean.FALSE, docType));
1065:                result = docSearchService.getList(user, criteria);
1066:                searchResults = result.getSearchResults();
1067:                assertEquals("Search results should have one document.", 1,
1068:                        searchResults.size());
1069:                criteria = new DocSearchCriteriaVO();
1070:                criteria.setDocTypeFullName(documentTypeName);
1071:                criteria
1072:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1073:                                searchAttributeFloatKey,
1074:                                (searchAttributeFloatValue
1075:                                        .add(new BigDecimal(2))).toString(),
1076:                                Boolean.TRUE, docType));
1077:                criteria
1078:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1079:                                searchAttributeFloatKey,
1080:                                (searchAttributeFloatValue
1081:                                        .subtract(new BigDecimal(2)))
1082:                                        .toString(), Boolean.FALSE, docType));
1083:                try {
1084:                    result = docSearchService.getList(user, criteria);
1085:                    fail("Error should have been thrown for invalid range");
1086:                } catch (WorkflowServiceErrorException e) {
1087:                }
1088:
1089:                // begin datetime attribute value testing
1090:                // inclusive = ?
1091:                String searchAttributeDateTimeKey = TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY;
1092:                Calendar searchAttributeDateTimeValue = Utilities
1093:                        .convertTimestamp(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE);
1094:
1095:                Calendar calendarValueToUse = null;
1096:                // test lower bound only
1097:                criteria = new DocSearchCriteriaVO();
1098:                criteria.setDocTypeFullName(documentTypeName);
1099:                calendarValueToUse = (Calendar) searchAttributeDateTimeValue
1100:                        .clone();
1101:                String valueToSearch = DocSearchUtils
1102:                        .getDisplayValueWithDateOnly(Utilities
1103:                                .convertCalendar(calendarValueToUse));
1104:                criteria
1105:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1106:                                searchAttributeDateTimeKey, valueToSearch,
1107:                                Boolean.TRUE, docType));
1108:                criteria
1109:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1110:                                searchAttributeDateTimeKey, "", Boolean.FALSE,
1111:                                docType));
1112:                result = docSearchService.getList(user, criteria);
1113:                searchResults = result.getSearchResults();
1114:                assertEquals("Search results should have one document.", 0,
1115:                        searchResults.size());
1116:                criteria = new DocSearchCriteriaVO();
1117:                criteria.setDocTypeFullName(documentTypeName);
1118:                calendarValueToUse = (Calendar) searchAttributeDateTimeValue
1119:                        .clone();
1120:                calendarValueToUse.add(Calendar.DATE, -1);
1121:                valueToSearch = DocSearchUtils
1122:                        .getDisplayValueWithDateOnly(Utilities
1123:                                .convertCalendar(calendarValueToUse));
1124:                criteria
1125:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1126:                                searchAttributeDateTimeKey, valueToSearch,
1127:                                Boolean.TRUE, docType));
1128:                criteria
1129:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1130:                                searchAttributeDateTimeKey, "", Boolean.FALSE,
1131:                                docType));
1132:                result = docSearchService.getList(user, criteria);
1133:                searchResults = result.getSearchResults();
1134:                assertEquals("Search results should have one document.", 1,
1135:                        searchResults.size());
1136:                criteria = new DocSearchCriteriaVO();
1137:                criteria.setDocTypeFullName(documentTypeName);
1138:                calendarValueToUse = (Calendar) searchAttributeDateTimeValue
1139:                        .clone();
1140:                calendarValueToUse.add(Calendar.DATE, 1);
1141:                valueToSearch = DocSearchUtils
1142:                        .getDisplayValueWithDateOnly(Utilities
1143:                                .convertCalendar(calendarValueToUse));
1144:                criteria
1145:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1146:                                searchAttributeDateTimeKey, valueToSearch,
1147:                                Boolean.TRUE, docType));
1148:                criteria
1149:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1150:                                searchAttributeDateTimeKey, "", Boolean.FALSE,
1151:                                docType));
1152:                result = docSearchService.getList(user, criteria);
1153:                searchResults = result.getSearchResults();
1154:                assertEquals("Search results should have one document.", 0,
1155:                        searchResults.size());
1156:
1157:                // test upper bound only
1158:                criteria = new DocSearchCriteriaVO();
1159:                criteria.setDocTypeFullName(documentTypeName);
1160:                calendarValueToUse = (Calendar) searchAttributeDateTimeValue
1161:                        .clone();
1162:                criteria
1163:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1164:                                searchAttributeDateTimeKey, "", Boolean.TRUE,
1165:                                docType));
1166:                criteria
1167:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1168:                                searchAttributeDateTimeKey,
1169:                                DocSearchUtils
1170:                                        .getDisplayValueWithDateOnly(Utilities
1171:                                                .convertCalendar(calendarValueToUse)),
1172:                                Boolean.FALSE, docType));
1173:                result = docSearchService.getList(user, criteria);
1174:                searchResults = result.getSearchResults();
1175:                assertEquals("Search results should have one document.", 1,
1176:                        searchResults.size());
1177:                criteria = new DocSearchCriteriaVO();
1178:                criteria.setDocTypeFullName(documentTypeName);
1179:                calendarValueToUse = (Calendar) searchAttributeDateTimeValue
1180:                        .clone();
1181:                calendarValueToUse.add(Calendar.DATE, -1);
1182:                criteria
1183:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1184:                                searchAttributeDateTimeKey, "", Boolean.TRUE,
1185:                                docType));
1186:                criteria
1187:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1188:                                searchAttributeDateTimeKey,
1189:                                DocSearchUtils
1190:                                        .getDisplayValueWithDateOnly(Utilities
1191:                                                .convertCalendar(calendarValueToUse)),
1192:                                Boolean.FALSE, docType));
1193:                result = docSearchService.getList(user, criteria);
1194:                searchResults = result.getSearchResults();
1195:                assertEquals("Search results should have one document.", 0,
1196:                        searchResults.size());
1197:                criteria = new DocSearchCriteriaVO();
1198:                criteria.setDocTypeFullName(documentTypeName);
1199:                calendarValueToUse = (Calendar) searchAttributeDateTimeValue
1200:                        .clone();
1201:                calendarValueToUse.add(Calendar.DATE, 1);
1202:                criteria
1203:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1204:                                searchAttributeDateTimeKey, "", Boolean.TRUE,
1205:                                docType));
1206:                criteria
1207:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1208:                                searchAttributeDateTimeKey,
1209:                                DocSearchUtils
1210:                                        .getDisplayValueWithDateOnly(Utilities
1211:                                                .convertCalendar(calendarValueToUse)),
1212:                                Boolean.FALSE, docType));
1213:                result = docSearchService.getList(user, criteria);
1214:                searchResults = result.getSearchResults();
1215:                assertEquals("Search results should have one document.", 1,
1216:                        searchResults.size());
1217:
1218:                // test both bounds
1219:                criteria = new DocSearchCriteriaVO();
1220:                criteria.setDocTypeFullName(documentTypeName);
1221:                Calendar lowerBoundValue = (Calendar) searchAttributeDateTimeValue
1222:                        .clone();
1223:                criteria
1224:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1225:                                searchAttributeDateTimeKey,
1226:                                DocSearchUtils
1227:                                        .getDisplayValueWithDateOnly(Utilities
1228:                                                .convertCalendar(lowerBoundValue)),
1229:                                Boolean.TRUE, docType));
1230:                Calendar upperBoundValue = (Calendar) searchAttributeDateTimeValue
1231:                        .clone();
1232:                criteria
1233:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1234:                                searchAttributeDateTimeKey,
1235:                                DocSearchUtils
1236:                                        .getDisplayValueWithDateOnly(Utilities
1237:                                                .convertCalendar(upperBoundValue)),
1238:                                Boolean.FALSE, docType));
1239:                result = docSearchService.getList(user, criteria);
1240:                searchResults = result.getSearchResults();
1241:                assertEquals("Search results should have one document.", 0,
1242:                        searchResults.size());
1243:                criteria = new DocSearchCriteriaVO();
1244:                criteria.setDocTypeFullName(documentTypeName);
1245:                lowerBoundValue = (Calendar) searchAttributeDateTimeValue
1246:                        .clone();
1247:                lowerBoundValue.add(Calendar.DATE, 2);
1248:                criteria
1249:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1250:                                searchAttributeDateTimeKey,
1251:                                DocSearchUtils
1252:                                        .getDisplayValueWithDateOnly(Utilities
1253:                                                .convertCalendar(lowerBoundValue)),
1254:                                Boolean.TRUE, docType));
1255:                upperBoundValue = (Calendar) searchAttributeDateTimeValue
1256:                        .clone();
1257:                upperBoundValue.add(Calendar.DATE, 4);
1258:                criteria
1259:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1260:                                searchAttributeDateTimeKey,
1261:                                DocSearchUtils
1262:                                        .getDisplayValueWithDateOnly(Utilities
1263:                                                .convertCalendar(upperBoundValue)),
1264:                                Boolean.FALSE, docType));
1265:                result = docSearchService.getList(user, criteria);
1266:                searchResults = result.getSearchResults();
1267:                assertEquals("Search results should have one document.", 0,
1268:                        searchResults.size());
1269:                criteria = new DocSearchCriteriaVO();
1270:                criteria.setDocTypeFullName(documentTypeName);
1271:                lowerBoundValue = (Calendar) searchAttributeDateTimeValue
1272:                        .clone();
1273:                lowerBoundValue.add(Calendar.DATE, -4);
1274:                criteria
1275:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1276:                                searchAttributeDateTimeKey,
1277:                                DocSearchUtils
1278:                                        .getDisplayValueWithDateOnly(Utilities
1279:                                                .convertCalendar(lowerBoundValue)),
1280:                                Boolean.TRUE, docType));
1281:                upperBoundValue = (Calendar) searchAttributeDateTimeValue
1282:                        .clone();
1283:                upperBoundValue.add(Calendar.DATE, -2);
1284:                criteria
1285:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1286:                                searchAttributeDateTimeKey,
1287:                                DocSearchUtils
1288:                                        .getDisplayValueWithDateOnly(Utilities
1289:                                                .convertCalendar(upperBoundValue)),
1290:                                Boolean.FALSE, docType));
1291:                result = docSearchService.getList(user, criteria);
1292:                searchResults = result.getSearchResults();
1293:                assertEquals("Search results should have one document.", 0,
1294:                        searchResults.size());
1295:                criteria = new DocSearchCriteriaVO();
1296:                criteria.setDocTypeFullName(documentTypeName);
1297:                lowerBoundValue = (Calendar) searchAttributeDateTimeValue
1298:                        .clone();
1299:                lowerBoundValue.add(Calendar.DATE, -2);
1300:                criteria
1301:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1302:                                searchAttributeDateTimeKey,
1303:                                DocSearchUtils
1304:                                        .getDisplayValueWithDateOnly(Utilities
1305:                                                .convertCalendar(lowerBoundValue)),
1306:                                Boolean.TRUE, docType));
1307:                upperBoundValue = (Calendar) searchAttributeDateTimeValue
1308:                        .clone();
1309:                upperBoundValue.add(Calendar.DATE, 2);
1310:                criteria
1311:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1312:                                searchAttributeDateTimeKey,
1313:                                DocSearchUtils
1314:                                        .getDisplayValueWithDateOnly(Utilities
1315:                                                .convertCalendar(upperBoundValue)),
1316:                                Boolean.FALSE, docType));
1317:                result = docSearchService.getList(user, criteria);
1318:                searchResults = result.getSearchResults();
1319:                assertEquals("Search results should have one document.", 1,
1320:                        searchResults.size());
1321:                criteria = new DocSearchCriteriaVO();
1322:                criteria.setDocTypeFullName(documentTypeName);
1323:                lowerBoundValue = (Calendar) searchAttributeDateTimeValue
1324:                        .clone();
1325:                lowerBoundValue.add(Calendar.DATE, 2);
1326:                criteria
1327:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1328:                                searchAttributeDateTimeKey,
1329:                                DocSearchUtils
1330:                                        .getDisplayValueWithDateOnly(Utilities
1331:                                                .convertCalendar(lowerBoundValue)),
1332:                                Boolean.TRUE, docType));
1333:                upperBoundValue = (Calendar) searchAttributeDateTimeValue
1334:                        .clone();
1335:                upperBoundValue.add(Calendar.DATE, -2);
1336:                criteria
1337:                        .addSearchableAttribute(createSearchAttributeCriteriaComponent(
1338:                                searchAttributeDateTimeKey,
1339:                                DocSearchUtils
1340:                                        .getDisplayValueWithDateOnly(Utilities
1341:                                                .convertCalendar(upperBoundValue)),
1342:                                Boolean.FALSE, docType));
1343:                try {
1344:                    result = docSearchService.getList(user, criteria);
1345:                    fail("Error should have been thrown for invalid range");
1346:                } catch (WorkflowServiceErrorException e) {
1347:                }
1348:            }
1349:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.