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.api.util.ClassLoaderUtils;
21 import org.kuali.rice.kew.docsearch.service.DocumentSearchService;
22 import org.kuali.rice.kew.docsearch.xml.DocumentSearchXMLResultProcessor;
23 import org.kuali.rice.kew.docsearch.xml.DocumentSearchXMLResultProcessorImpl;
24 import org.kuali.rice.kew.doctype.bo.DocumentType;
25 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
26 import org.kuali.rice.kew.rule.bo.RuleAttribute;
27 import org.kuali.rice.kew.service.KEWServiceLocator;
28 import org.kuali.rice.kew.util.KEWPropertyConstants;
29 import org.kuali.rice.kim.api.identity.Person;
30 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
31 import org.kuali.rice.kns.web.ui.Column;
32
33 import java.util.Arrays;
34 import java.util.Iterator;
35 import java.util.List;
36
37 import static org.junit.Assert.assertEquals;
38 import static org.junit.Assert.fail;
39
40
41
42
43
44 public class CustomDocumentSearchResultProcessorTest extends DocumentSearchTestBase {
45
46
47 protected void loadTestData() throws Exception {
48 loadXmlFile("SearchAttributeConfig.xml");
49 }
50
51 @Test public void testCustomDocumentSearchResultProcessorOverrideUse() throws Exception {
52 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName("SearchDocType");
53 assertEquals("The document search Processor class is incorrect.",StandardDocumentSearchResultProcessor.class,(ClassLoaderUtils.unwrapFromProxy(docType.getDocumentSearchResultProcessor())).getClass());
54
55 docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName("SearchDocType_DefaultCustomProcessor");
56 assertEquals("The document search Processor class is incorrect.",DocumentSearchXMLResultProcessorImpl.class,(ClassLoaderUtils.unwrapFromProxy(docType.getDocumentSearchResultProcessor())).getClass());
57
58 docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName("SearchDocType2");
59 assertEquals("The document search Processor class is incorrect.",CustomSearchResultProcessor.class,(ClassLoaderUtils.unwrapFromProxy(docType.getDocumentSearchResultProcessor())).getClass());
60 }
61
62 @Test public void testSearchXMLResultProcessorFunction() throws Exception {
63 RuleAttribute ruleAttribute = KEWServiceLocator.getRuleAttributeService().findByName("XMLResultProcessorDetails");
64 DocumentSearchXMLResultProcessorImpl docSearchResult = new DocumentSearchXMLResultProcessorImpl();
65 docSearchResult.setRuleAttribute(ruleAttribute);
66
67 List<Column> columns = docSearchResult.getCustomDisplayColumns();
68 for (Iterator iter = columns.iterator(); iter.hasNext();) {
69 Column column = (Column) iter.next();
70 if (KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOC_TYPE_LABEL.equals(column.getPropertyName())) {
71 assertEquals("Attribute xml is not populating column 'sortable' value correctly", "true", column.getSortable());
72 assertEquals("Attribute xml is not populating column 'title' value correctly", "", column.getColumnTitle());
73 } else if (KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_TITLE.equals(column.getPropertyName())) {
74 assertEquals("Attribute xml is not populating column 'sortable' value correctly", "false", column.getSortable());
75 assertEquals("Attribute xml is not populating column 'title' value correctly", null, column.getColumnTitle());
76 } else if (KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_INITIATOR.equals(column.getPropertyName())) {
77 assertEquals("Attribute xml is not populating column 'sortable' value correctly", null, column.getSortable());
78 assertEquals("Attribute xml is not populating column 'title' value correctly", "Initiator Dude", column.getColumnTitle());
79 } else if (KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_STATUS_DESC.equals(column.getPropertyName())) {
80 assertEquals("Attribute xml is not populating column 'sortable' value correctly", null, column.getSortable());
81 assertEquals("Attribute xml is not populating column 'title' value correctly", null, column.getColumnTitle());
82 } else if (TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY.equals(column.getPropertyName())) {
83 assertEquals("Attribute xml is not populating column 'sortable' value correctly", "false", column.getSortable());
84 assertEquals("Attribute xml is not populating column 'title' value correctly", null, column.getColumnTitle());
85 } else {
86 fail("Key value of custom column should never be anything except already checked values but is '" + column.getPropertyName() + "'");
87 }
88 }
89
90 assertEquals("Value of 'show all standard fields' should be default",DocumentSearchXMLResultProcessor.DEFAULT_SHOW_ALL_STANDARD_FIELDS_VALUE,docSearchResult.getShowAllStandardFields());
91 assertEquals("Value of 'override searchable attributes' should be default",DocumentSearchXMLResultProcessor.DEFAULT_OVERRIDE_SEARCHABLE_ATTRIBUTES_VALUE,docSearchResult.getOverrideSearchableAttributes());
92 }
93
94 private DocumentSearchResultComponents performSearch(String documentTypeName,String userNetworkId) {
95 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
96 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
97 Person person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(userNetworkId);
98
99 DocSearchCriteriaDTO criteria = new DocSearchCriteriaDTO();
100 criteria.setDocTypeFullName(documentTypeName);
101 criteria.addSearchableAttribute(createSearchAttributeCriteriaComponent(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE, docType));
102 return docSearchService.getList(person.getPrincipalId(), criteria);
103 }
104
105 private void parseList(List<Column> columns, List<String> columnsRequired, List<String> columnsNotAllowed) {
106
107 for (Iterator iterator = columnsNotAllowed.iterator(); iterator.hasNext();) {
108 String disallowedColumnKey = (String) iterator.next();
109 for (Iterator iter = columns.iterator(); iter.hasNext();) {
110 Column currentColumn = (Column) iter.next();
111 if (disallowedColumnKey.equals(currentColumn.getPropertyName())) {
112 fail("The column with key '" + currentColumn.getPropertyName() + "' should not be in the list of columns to be displayed but was");
113 }
114 }
115 }
116
117
118 for (int i = 0; i < columnsRequired.size(); i++) {
119 String requiredColumnKey = columnsRequired.get(i);
120 Column testColumn = columns.get(i);
121 if (!(requiredColumnKey.equals(testColumn.getPropertyName()))) {
122 fail("The column with key '" + requiredColumnKey + "' should be in the list of columns to be displayed (at location " + i + ") but was not");
123 }
124 }
125 }
126
127 @Test public void testCustomDocumentSearchXMLResultProcessor() throws Exception {
128 String searchableAttributeKey_Shown = "givenname";
129 String searchableAttributeKey_Hidden = "givenname_hidden";
130
131
132
133
134
135 String documentTypeName = "SearchDocType_DefaultCustomProcessor";
136 String userNetworkId = "rkirkend";
137 DocumentSearchResultComponents result = performSearch(documentTypeName, userNetworkId);
138
139
140
141
142
143
144
145
146
147
148
149
150
151 parseList(result.getColumns(), Arrays.asList(new String[]{
152 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_ID,
153 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOC_TYPE_LABEL,
154 searchableAttributeKey_Hidden,
155 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_TITLE,
156 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_INITIATOR,
157 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_STATUS_DESC,
158 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_LOG
159 }), Arrays.asList(new String[]{
160 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DATE_CREATED,
161 searchableAttributeKey_Shown
162 }));
163
164
165
166
167
168
169 documentTypeName = "SearchDocType_AllCustomProcessor";
170 result = performSearch(documentTypeName, userNetworkId);
171
172
173
174
175
176
177
178
179
180
181
182
183
184 parseList(result.getColumns(), Arrays.asList(new String[]{
185 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_ID,
186 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOC_TYPE_LABEL,
187 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_TITLE,
188 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_INITIATOR,
189 searchableAttributeKey_Hidden,
190 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_STATUS_DESC,
191 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_LOG
192 }), Arrays.asList(new String[]{
193 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DATE_CREATED,
194 searchableAttributeKey_Shown
195 }));
196
197
198
199
200
201
202
203 documentTypeName = "SearchDocType_SearchAttCustomProcessor";
204 result = performSearch(documentTypeName, userNetworkId);
205
206
207
208
209
210
211
212
213
214
215
216
217
218 parseList(result.getColumns(), Arrays.asList(new String[]{
219 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_ID,
220 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOC_TYPE_LABEL,
221 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_TITLE,
222 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_STATUS_DESC,
223 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_INITIATOR,
224 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DATE_CREATED,
225 searchableAttributeKey_Hidden,
226 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_LOG
227 }), Arrays.asList(new String[]{
228 searchableAttributeKey_Shown
229 }));
230
231
232
233
234
235
236
237 documentTypeName = "SearchDocType_StandardCustomProcessor";
238 result = performSearch(documentTypeName, userNetworkId);
239
240
241
242
243
244
245
246
247
248
249
250
251
252 parseList(result.getColumns(), Arrays.asList(new String[]{
253 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_ID,
254 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_TITLE,
255 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOC_TYPE_LABEL,
256 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_STATUS_DESC,
257 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_INITIATOR,
258 searchableAttributeKey_Shown,
259 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_LOG
260 }), Arrays.asList(new String[]{
261 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DATE_CREATED,
262 searchableAttributeKey_Hidden
263 }));
264
265
266
267
268
269
270
271 documentTypeName = "SearchDocType_NormalCustomProcessor";
272 result = performSearch(documentTypeName, userNetworkId);
273
274
275
276
277
278
279
280
281
282
283
284
285
286 parseList(result.getColumns(), Arrays.asList(new String[]{
287 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_ID,
288 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOC_TYPE_LABEL,
289 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_TITLE,
290 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_STATUS_DESC,
291 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_INITIATOR,
292 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DATE_CREATED,
293 searchableAttributeKey_Shown,
294 KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_LOG
295 }), Arrays.asList(new String[]{
296 searchableAttributeKey_Hidden
297 }));
298 }
299 }