1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.docsearch;
18
19 import org.junit.Test;
20 import org.kuali.rice.core.util.ClassLoaderUtils;
21 import org.kuali.rice.kew.docsearch.service.DocumentSearchService;
22 import org.kuali.rice.kew.doctype.bo.DocumentType;
23 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
24 import org.kuali.rice.kew.dto.NetworkIdDTO;
25 import org.kuali.rice.kew.dto.WorkflowAttributeDefinitionDTO;
26 import org.kuali.rice.kew.service.KEWServiceLocator;
27 import org.kuali.rice.kew.service.WorkflowDocument;
28 import org.kuali.rice.kew.util.KEWConstants;
29 import org.kuali.rice.kew.util.Utilities;
30 import org.kuali.rice.kim.bo.Person;
31 import org.kuali.rice.kim.service.KIMServiceLocator;
32 import org.kuali.rice.kns.bo.Parameter;
33 import org.kuali.rice.kns.service.KNSServiceLocator;
34 import org.kuali.rice.kns.util.KNSConstants;
35
36
37
38
39
40
41 public class CustomDocumentSearchGeneratorTest extends DocumentSearchTestBase {
42
43
44 protected void loadTestData() throws Exception {
45 loadXmlFile("SearchAttributeConfig.xml");
46 }
47
48 @Test public void testCustomDocumentSearchGeneratorUse() throws Exception {
49 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName("SearchDocType");
50 assertEquals("The document search Generator class is incorrect.",StandardDocumentSearchGenerator.class,(ClassLoaderUtils.unwrapFromProxy(docType.getDocumentSearchGenerator())).getClass());
51 docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName("SearchDocType_DefaultCustomProcessor");
52 assertEquals("The document search Generator class is incorrect.",CustomDocumentSearchGenerator.class,(ClassLoaderUtils.unwrapFromProxy(docType.getDocumentSearchGenerator())).getClass());
53 }
54
55 private DocumentType getValidDocumentType(String documentTypeFullName) {
56 if (Utilities.isEmpty(documentTypeFullName)) {
57 return null;
58 }
59 DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeFullName);
60 if (docType == null) {
61 throw new RuntimeException("No Valid Document Type Found for document type name '" + documentTypeFullName + "'");
62 } else {
63 return docType;
64 }
65 }
66
67 @Test public void testCustomDocSearchGeneratorResultSetLimit() throws Exception {
68 String documentTypeName = "SearchDocType_DefaultCustomProcessor";
69 String userNetworkId = "rkirkend";
70 Person user = KIMServiceLocator.getPersonService().getPersonByPrincipalName(userNetworkId);
71
72
73 DocSearchCriteriaDTO criteria = new DocSearchCriteriaDTO();
74 criteria.setDocTypeFullName(documentTypeName);
75 criteria.addSearchableAttribute(createSearchAttributeCriteriaComponent(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE, KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName)));
76
77
78 adjustResultSetCapApplicationConstantValue(CustomDocumentSearchGenerator.RESULT_SET_LIMIT + 1);
79 KEWServiceLocator.getDocumentSearchService().getList(user.getPrincipalId(), criteria);
80 assertEquals("Criteria threshold should equal custom generator class threshold", CustomDocumentSearchGenerator.RESULT_SET_LIMIT, criteria.getThreshold().intValue());
81
82
83 int newLimit = CustomDocumentSearchGenerator.RESULT_SET_LIMIT - 1;
84 adjustResultSetCapApplicationConstantValue(newLimit);
85 KEWServiceLocator.getDocumentSearchService().getList(user.getPrincipalId(), criteria);
86 assertEquals("Criteria threshold should equal system result set threshold", newLimit, criteria.getThreshold().intValue());
87
88
89 KNSServiceLocator.getBusinessObjectService().delete(KNSServiceLocator.getParameterService().retrieveParameter(KEWConstants.KEW_NAMESPACE, KNSConstants.DetailTypes.DOCUMENT_SEARCH_DETAIL_TYPE, KEWConstants.DOC_SEARCH_RESULT_CAP));
90
91
92 KNSServiceLocator.getParameterService().clearCache();
93
94 KEWServiceLocator.getDocumentSearchService().getList(user.getPrincipalId(), criteria);
95 assertEquals("Criteria threshold should equal custom generator class threshold", CustomDocumentSearchGenerator.RESULT_SET_LIMIT, criteria.getThreshold().intValue());
96 }
97
98 private void adjustResultSetCapApplicationConstantValue(Integer newValue) {
99 Parameter ps = KNSServiceLocator.getParameterService().retrieveParameter(KEWConstants.KEW_NAMESPACE, KNSConstants.DetailTypes.DOCUMENT_SEARCH_DETAIL_TYPE, KEWConstants.DOC_SEARCH_RESULT_CAP);
100 if (ps == null) {
101 ps = new Parameter( KEWConstants.DOC_SEARCH_RESULT_CAP, newValue.toString(), "A" );
102 }
103 ps.setParameterNamespaceCode(KEWConstants.KEW_NAMESPACE);
104 ps.setParameterName(KEWConstants.DOC_SEARCH_RESULT_CAP);
105 ps.setParameterValue(newValue.toString());
106 ps.setParameterTypeCode("CONFG");
107
108 ps.setParameterDetailTypeCode(KNSConstants.DetailTypes.DOCUMENT_SEARCH_DETAIL_TYPE);
109 KNSServiceLocator.getBusinessObjectService().save(ps);
110 }
111
112
113
114
115
116
117
118 @Test public void testSearchOnExtraDocType() throws Exception {
119 String userNetworkId = "rkirkend";
120 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
121 Person user = KIMServiceLocator.getPersonService().getPersonByPrincipalName(userNetworkId);
122
123 String documentTypeName1 = "SearchDocType_DefaultCustomProcessor";
124 WorkflowDocument workDoc_Matching1 = new WorkflowDocument(new NetworkIdDTO(userNetworkId), documentTypeName1);
125 DocumentType docType1 = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName1);
126 WorkflowAttributeDefinitionDTO stringXMLDef1 = new WorkflowAttributeDefinitionDTO("SearchableAttributeVisible");
127 stringXMLDef1.addProperty(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE);
128 workDoc_Matching1.addSearchableDefinition(stringXMLDef1);
129 workDoc_Matching1.routeDocument("");
130
131 String documentTypeName2 = "SearchDocType_DefaultCustomProcessor_2";
132 WorkflowDocument workDoc_Matching2 = new WorkflowDocument(new NetworkIdDTO(userNetworkId), documentTypeName2);
133 DocumentType docType2 = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName2);
134 WorkflowAttributeDefinitionDTO stringXMLDef2 = new WorkflowAttributeDefinitionDTO("SearchableAttributeVisible");
135 stringXMLDef2.addProperty(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE);
136 workDoc_Matching2.addSearchableDefinition(stringXMLDef2);
137 workDoc_Matching2.routeDocument("");
138
139
140 DocSearchCriteriaDTO criteria = new DocSearchCriteriaDTO();
141 criteria.setDocTypeFullName(documentTypeName1);
142 criteria.addSearchableAttribute(createSearchAttributeCriteriaComponent(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE, docType1));
143 DocumentSearchResultComponents result = docSearchService.getList(user.getPrincipalId(), criteria);
144 assertEquals("Search results should have one document.", 2, result.getSearchResults().size());
145
146
147 criteria = new DocSearchCriteriaDTO();
148 criteria.setDocTypeFullName(documentTypeName2);
149 criteria.addSearchableAttribute(createSearchAttributeCriteriaComponent(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE, docType2));
150 result = docSearchService.getList(user.getPrincipalId(), criteria);
151 assertEquals("Search results should have one document.", 2, result.getSearchResults().size());
152
153
154 criteria = new DocSearchCriteriaDTO();
155 criteria.setDocTypeFullName(documentTypeName1);
156 result = docSearchService.getList(user.getPrincipalId(), criteria);
157 assertEquals("Search results should have one document.", 2, result.getSearchResults().size());
158
159
160 criteria = new DocSearchCriteriaDTO();
161 criteria.setDocTypeFullName(documentTypeName2);
162 result = docSearchService.getList(user.getPrincipalId(), criteria);
163 assertEquals("Search results should have one document.", 2, result.getSearchResults().size());
164
165 String documentTypeName3 = "SearchDocType_DefaultCustomProcessor_3";
166 WorkflowDocument workDoc_Matching3 = new WorkflowDocument(new NetworkIdDTO(userNetworkId), documentTypeName3);
167 DocumentType docType3 = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName3);
168 WorkflowAttributeDefinitionDTO stringXMLDef3 = new WorkflowAttributeDefinitionDTO("SearchableAttributeVisible");
169 stringXMLDef3.addProperty(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE);
170 workDoc_Matching3.addSearchableDefinition(stringXMLDef3);
171 workDoc_Matching3.routeDocument("");
172
173
174 criteria = new DocSearchCriteriaDTO();
175 criteria.setDocTypeFullName(documentTypeName3);
176 criteria.addSearchableAttribute(createSearchAttributeCriteriaComponent(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE, docType3));
177 result = docSearchService.getList(user.getPrincipalId(), criteria);
178 assertEquals("Search results should have one document.", 1, result.getSearchResults().size());
179
180
181 criteria = new DocSearchCriteriaDTO();
182 criteria.setDocTypeFullName(documentTypeName3);
183 result = docSearchService.getList(user.getPrincipalId(), criteria);
184 assertEquals("Search results should have one document.", 1, result.getSearchResults().size());
185
186 WorkflowDocument workDoc_NonMatching2 = new WorkflowDocument(new NetworkIdDTO(userNetworkId), documentTypeName2);
187 WorkflowAttributeDefinitionDTO stringXMLDef1a = new WorkflowAttributeDefinitionDTO("SearchableAttributeVisible");
188
189 String searchAttributeValue = TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE + "nonMatching";
190 stringXMLDef1a.addProperty(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, searchAttributeValue);
191 workDoc_NonMatching2.addSearchableDefinition(stringXMLDef1a);
192 workDoc_NonMatching2.routeDocument("");
193
194
195 criteria = new DocSearchCriteriaDTO();
196 criteria.setDocTypeFullName(documentTypeName1);
197 criteria.addSearchableAttribute(createSearchAttributeCriteriaComponent(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, searchAttributeValue, docType1));
198 result = docSearchService.getList(user.getPrincipalId(), criteria);
199 assertEquals("Search results should have one document.", 1, result.getSearchResults().size());
200
201
202 criteria = new DocSearchCriteriaDTO();
203 criteria.setDocTypeFullName(documentTypeName1);
204 result = docSearchService.getList(user.getPrincipalId(), criteria);
205 assertEquals("Search results should have one document.", 3, result.getSearchResults().size());
206 }
207 }