Clover Coverage Report - kew-test 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
262   450   28   20.15
30   343   0.11   13
13     2.15  
1    
 
  DocumentSearchTest       Line # 44 262 0% 28 305 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10    *
11    * Unless required by applicable law or agreed to in writing, software
12    * distributed under the License is distributed on an "AS IS" BASIS,
13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    * See the License for the specific language governing permissions and
15    * limitations under the License.
16    */
17    package org.kuali.rice.kew.docsearch;
18   
19    import org.junit.Test;
20    import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils;
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.engine.node.RouteNode;
25    import org.kuali.rice.kew.service.KEWServiceLocator;
26    import org.kuali.rice.kew.service.WorkflowDocument;
27    import org.kuali.rice.kew.test.KEWTestCase;
28    import org.kuali.rice.kew.util.KEWConstants;
29    import org.kuali.rice.kew.web.KeyValueSort;
30    import org.kuali.rice.kim.bo.Person;
31    import org.kuali.rice.kim.service.KIMServiceLocator;
32    import org.kuali.rice.test.BaselineTestCase;
33    import org.kuali.rice.test.TestHarnessServiceLocator;
34    import org.springframework.jdbc.core.JdbcTemplate;
35   
36    import java.math.BigDecimal;
37    import java.util.Calendar;
38    import java.util.Iterator;
39    import java.util.List;
40   
41    import static org.junit.Assert.*;
42   
43    @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
 
44    public class DocumentSearchTest extends KEWTestCase {
45    private static final String KREW_DOC_HDR_T = "KREW_DOC_HDR_T";
46    private static final String INITIATOR_COL = "INITR_PRNCPL_ID";
47   
48    DocumentSearchService docSearchService;
49   
 
50  0 toggle @Override
51    protected void loadTestData() throws Exception {
52  0 loadXmlFile("SearchAttributeConfig.xml");
53   
54    }
55   
 
56  0 toggle @Override
57    protected void setUpAfterDataLoad() throws Exception {
58  0 docSearchService = (DocumentSearchService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
59    }
60   
 
61  0 toggle @Test public void testDocSearch() throws Exception {
62  0 Person user = KIMServiceLocator.getPersonService().getPersonByPrincipalName("bmcgough");
63  0 DocSearchCriteriaDTO criteria = new DocSearchCriteriaDTO();
64  0 List searchResults = null;
65  0 DocumentSearchResultComponents result = null;
66  0 criteria.setDocTitle("*IN");
67  0 criteria.setNamedSearch("bytitle");
68  0 result = docSearchService.getList(user.getPrincipalId(), criteria);
69  0 criteria = new DocSearchCriteriaDTO();
70  0 criteria.setDocTitle("*IN-CFSG");
71  0 criteria.setNamedSearch("for in accounts");
72  0 result = docSearchService.getList(user.getPrincipalId(), criteria);
73  0 criteria = new DocSearchCriteriaDTO();
74  0 criteria.setFromDateApproved("09/16/2004");
75  0 result = docSearchService.getList(user.getPrincipalId(), criteria);
76  0 criteria = new DocSearchCriteriaDTO();
77  0 criteria.setDocRouteNodeId("3");
78  0 criteria.setDocRouteNodeLogic("equal");
79  0 result = docSearchService.getList(user.getPrincipalId(), criteria);
80  0 user = KIMServiceLocator.getPersonService().getPersonByPrincipalName("bmcgough");
81  0 SavedSearchResult savedSearchResults = docSearchService.getSavedSearchResults(user.getPrincipalId(), "DocSearch.NamedSearch.bytitle");
82  0 assertNotNull(savedSearchResults);
83  0 assertNotNull(savedSearchResults.getSearchResult());
84  0 savedSearchResults = docSearchService.getSavedSearchResults(user.getPrincipalId(), "DocSearch.NamedSearch.for in accounts");
85  0 assertNotNull(savedSearchResults);
86  0 assertNotNull(savedSearchResults.getSearchResult());
87    }
88   
89    /**
90    * Test for https://test.kuali.org/jira/browse/KULRICE-1968 - Document search fails when users are missing
91    * Tests that we can safely search on docs whose initiator no longer exists in the identity management system
92    * This test searches by doc type name criteria.
93    * @throws Exception
94    */
 
95  0 toggle @Test public void testDocSearch_MissingInitiator() throws Exception {
96  0 String documentTypeName = "SearchDocType";
97  0 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
98  0 String userNetworkId = "arh14";
99    // route a document to enroute and route one to final
100  0 WorkflowDocument workflowDocument = new WorkflowDocument(getPrincipalId(userNetworkId), documentTypeName);
101  0 workflowDocument.setTitle("testDocSearch_MissingInitiator");
102  0 workflowDocument.routeDocument("routing this document.");
103   
104    // verify the document is enroute for jhopf
105  0 workflowDocument = new WorkflowDocument(getPrincipalId("jhopf"),workflowDocument.getRouteHeaderId());
106  0 assertTrue(workflowDocument.stateIsEnroute());
107  0 assertTrue(workflowDocument.isApprovalRequested());
108   
109    // now nuke the initiator...
110  0 new JdbcTemplate(TestHarnessServiceLocator.getDataSource()).execute("update " + KREW_DOC_HDR_T + " set " + INITIATOR_COL + " = 'bogus user' where DOC_HDR_ID = " + workflowDocument.getRouteHeaderId());
111   
112   
113  0 Person user = KIMServiceLocator.getPersonService().getPersonByPrincipalName("jhopf");
114  0 DocSearchCriteriaDTO criteria = new DocSearchCriteriaDTO();
115  0 criteria.setDocTypeFullName(documentTypeName);
116  0 DocumentSearchResultComponents result = docSearchService.getList(user.getPrincipalId(), criteria);
117  0 assertNotNull(result);
118  0 assertNotNull(result.getSearchResults());
119  0 assertEquals("Search returned invalid number of documents", 1, result.getSearchResults().size());
120    }
121   
122    /**
123    * Test for https://test.kuali.org/jira/browse/KULRICE-1968 - Tests that we get an error if we try and search on an initiator that doesn't exist in the IDM system
124    * @throws Exception
125    */
 
126  0 toggle @Test public void testDocSearch_SearchOnMissingInitiator() throws Exception {
127  0 String documentTypeName = "SearchDocType";
128  0 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
129  0 String userNetworkId = "arh14";
130    // route a document to enroute and route one to final
131  0 WorkflowDocument workflowDocument = new WorkflowDocument(getPrincipalId(userNetworkId), documentTypeName);
132  0 workflowDocument.setTitle("testDocSearch_MissingInitiator");
133  0 workflowDocument.routeDocument("routing this document.");
134   
135    // verify the document is enroute for jhopf
136  0 workflowDocument = new WorkflowDocument(getPrincipalId("jhopf"),workflowDocument.getRouteHeaderId());
137  0 assertTrue(workflowDocument.stateIsEnroute());
138  0 assertTrue(workflowDocument.isApprovalRequested());
139   
140    // now nuke the initiator...
141  0 new JdbcTemplate(TestHarnessServiceLocator.getDataSource()).execute("update " + KREW_DOC_HDR_T + " set " + INITIATOR_COL + " = 'bogus user' where DOC_HDR_ID = " + workflowDocument.getRouteHeaderId());
142   
143   
144  0 Person user = KIMServiceLocator.getPersonService().getPersonByPrincipalName("jhopf");
145  0 DocSearchCriteriaDTO criteria = new DocSearchCriteriaDTO();
146  0 criteria.setInitiator("bogus user");
147   
148  0 DocumentSearchResultComponents result = docSearchService.getList(user.getPrincipalId(), criteria);
149  0 int size = result.getSearchResults().size();
150  0 assertTrue("Searching by an invalid initiator should return nothing", size == 0);
151   
152    }
153   
 
154  0 toggle @Test public void testDocSearch_RouteNodeName() throws Exception {
155  0 loadXmlFile("DocSearchTest_RouteNode.xml");
156  0 String documentTypeName = "SearchDocType_RouteNodeTest";
157  0 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
158  0 String userNetworkId = "rkirkend";
159   
160    // route a document to enroute and route one to final
161  0 WorkflowDocument workflowDocument = new WorkflowDocument(getPrincipalId(userNetworkId), documentTypeName);
162  0 workflowDocument.setTitle("Routing style");
163  0 workflowDocument.routeDocument("routing this document.");
164    // verify the document is enroute for jhopf
165  0 workflowDocument = new WorkflowDocument(getPrincipalId("jhopf"),workflowDocument.getRouteHeaderId());
166  0 assertTrue(workflowDocument.stateIsEnroute());
167  0 assertTrue(workflowDocument.isApprovalRequested());
168  0 workflowDocument.approve("");
169  0 workflowDocument = new WorkflowDocument(getPrincipalId("jhopf"),workflowDocument.getRouteHeaderId());
170  0 assertTrue(workflowDocument.stateIsFinal());
171  0 workflowDocument = new WorkflowDocument(getPrincipalId(userNetworkId), documentTypeName);
172  0 workflowDocument.setTitle("Routing style");
173  0 workflowDocument.routeDocument("routing this document.");
174    // verify the document is enroute for jhopf
175  0 workflowDocument = new WorkflowDocument(getPrincipalId("jhopf"),workflowDocument.getRouteHeaderId());
176  0 assertTrue(workflowDocument.stateIsEnroute());
177  0 assertTrue(workflowDocument.isApprovalRequested());
178   
179   
180  0 Person user = KIMServiceLocator.getPersonService().getPersonByPrincipalName(userNetworkId);
181  0 DocSearchCriteriaDTO criteria = new DocSearchCriteriaDTO();
182  0 criteria.setDocTypeFullName(documentTypeName);
183  0 DocumentSearchResultComponents result = docSearchService.getList(user.getPrincipalId(), criteria);
184  0 assertNotNull(result);
185  0 assertNotNull(result.getSearchResults());
186  0 assertEquals("Search returned invalid number of documents", 2, result.getSearchResults().size());
187   
188  0 criteria.setDocRouteNodeId(getRouteNodeForSearch(documentTypeName,workflowDocument.getNodeNames()));
189  0 criteria.setDocRouteNodeLogic("equal");
190  0 result = docSearchService.getList(user.getPrincipalId(), criteria);
191  0 assertNotNull(result);
192  0 assertNotNull(result.getSearchResults());
193  0 assertEquals("Search returned invalid number of documents", 1, result.getSearchResults().size());
194   
195    // load the document type again to change the route node ids
196  0 loadXmlFile("DocSearchTest_RouteNode.xml");
197   
198  0 workflowDocument = new WorkflowDocument(getPrincipalId("jhopf"),workflowDocument.getRouteHeaderId());
199  0 assertTrue(workflowDocument.stateIsEnroute());
200  0 assertTrue(workflowDocument.isApprovalRequested());
201  0 criteria.setDocRouteNodeId(getRouteNodeForSearch(documentTypeName,workflowDocument.getNodeNames()));
202  0 result = docSearchService.getList(user.getPrincipalId(), criteria);
203  0 assertNotNull(result);
204  0 assertNotNull(result.getSearchResults());
205  0 assertEquals("Search returned invalid number of documents", 1, result.getSearchResults().size());
206   
207    }
208   
 
209  0 toggle private String getRouteNodeForSearch(String documentTypeName, String[] nodeNames) {
210  0 assertEquals(1, nodeNames.length);
211  0 String expectedNodeName = nodeNames[0];
212  0 List routeNodes = KEWServiceLocator.getRouteNodeService().getFlattenedNodes(KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName), true);
213  0 for (Iterator iterator = routeNodes.iterator(); iterator.hasNext();) {
214  0 RouteNode node = (RouteNode) iterator.next();
215  0 if (expectedNodeName.equals(node.getRouteNodeName())) {
216  0 return node.getRouteNodeName();
217    }
218    }
219  0 return null;
220    }
221   
 
222  0 toggle @Test public void testGetNamedDocSearches() throws Exception {
223  0 Person user = KIMServiceLocator.getPersonService().getPersonByPrincipalName("bmcgough");
224  0 List namedSearches = docSearchService.getNamedSearches(user.getPrincipalId());
225  0 assertNotNull(namedSearches);
226    }
227   
 
228  0 toggle @Test public void testDefaultCreateDateSearchCriteria() throws Exception {
229  0 Person user = KIMServiceLocator.getPersonService().getPersonByPrincipalName("bmcgough");
230  0 DocSearchCriteriaDTO criteria = new DocSearchCriteriaDTO();
231  0 DocumentSearchResultComponents result = docSearchService.getList(user.getPrincipalId(), criteria);
232  0 assertNotNull("Should have a date created value",criteria.getFromDateCreated());
233  0 Calendar criteriaDate = Calendar.getInstance();
234  0 criteriaDate.setTime(SQLUtils.convertStringDateToTimestamp(criteria.getFromDateCreated()));
235  0 assertEquals("Criteria date minus today's date should equal the constant value", KEWConstants.DOCUMENT_SEARCH_NO_CRITERIA_CREATE_DATE_DAYS_AGO.doubleValue(), getDifferenceInDays(criteriaDate), 0);
236   
237  0 criteria = new DocSearchCriteriaDTO();
238  0 criteria.setDocTitle("testing");
239  0 result = docSearchService.getList(user.getPrincipalId(), criteria);
240  0 assertNotNull("Should have a date created value",criteria.getFromDateCreated());
241  0 criteriaDate = Calendar.getInstance();
242  0 criteriaDate.setTime(SQLUtils.convertStringDateToTimestamp(criteria.getFromDateCreated()));
243  0 assertEquals("Criteria date minus today's date should equal the constant value", KEWConstants.DOCUMENT_SEARCH_DOC_TITLE_CREATE_DATE_DAYS_AGO.doubleValue(), getDifferenceInDays(criteriaDate), 0);
244    }
245   
 
246  0 toggle private static double getDifferenceInDays(Calendar compareDate) {
247  0 Calendar today = Calendar.getInstance();
248    // First, get difference in whole days
249  0 today.set(Calendar.HOUR_OF_DAY, 0);
250  0 today.set(Calendar.MINUTE, 0);
251  0 today.set(Calendar.SECOND, 0);
252  0 today.set(Calendar.MILLISECOND, 0);
253   
254  0 compareDate.set(Calendar.HOUR_OF_DAY, 0);
255  0 compareDate.set(Calendar.MINUTE, 0);
256  0 compareDate.set(Calendar.SECOND, 0);
257  0 compareDate.set(Calendar.MILLISECOND, 0);
258   
259  0 return (BigDecimal.valueOf(compareDate.getTimeInMillis()).subtract(BigDecimal.valueOf(today.getTimeInMillis()))).divide(BigDecimal.valueOf(24 * 60 * 60 * 1000.00), BigDecimal.ROUND_HALF_UP).doubleValue();
260    }
261   
 
262  0 toggle @Test public void testUseWorkflowSuperUserDocHandlerPolicy() throws Exception {
263  0 String customDocHandlerDocumentType = "SearchDocType";
264  0 String standardDocHandlerDocumentType = "SearchDocType2";
265  0 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(customDocHandlerDocumentType);
266  0 String userNetworkId = "rkirkend";
267   
268    // route a document to enroute and route one to final
269  0 WorkflowDocument workflowDocument = new WorkflowDocument(getPrincipalId(userNetworkId), standardDocHandlerDocumentType);
270  0 workflowDocument.setTitle("Routing style");
271  0 workflowDocument.routeDocument("routing this document.");
272    // verify the document is enroute for jhopf
273  0 workflowDocument = new WorkflowDocument(getPrincipalId("jhopf"),workflowDocument.getRouteHeaderId());
274  0 assertTrue(workflowDocument.stateIsEnroute());
275   
276    // route a document to enroute and route one to final
277  0 workflowDocument = new WorkflowDocument(getPrincipalId(userNetworkId), customDocHandlerDocumentType);
278  0 workflowDocument.setTitle("Routing style");
279  0 workflowDocument.routeDocument("routing this document.");
280    // verify the document is enroute for jhopf
281  0 workflowDocument = new WorkflowDocument(getPrincipalId("jhopf"),workflowDocument.getRouteHeaderId());
282  0 assertTrue(workflowDocument.stateIsEnroute());
283  0 assertTrue(workflowDocument.isApprovalRequested());
284  0 workflowDocument.approve("");
285  0 workflowDocument = new WorkflowDocument(getPrincipalId("jhopf"),workflowDocument.getRouteHeaderId());
286  0 assertTrue(workflowDocument.stateIsFinal());
287   
288  0 workflowDocument = new WorkflowDocument(getPrincipalId(userNetworkId), customDocHandlerDocumentType);
289  0 workflowDocument.setTitle("Routing style");
290  0 workflowDocument.routeDocument("routing this document.");
291    // verify the document is enroute for jhopf
292  0 workflowDocument = new WorkflowDocument(getPrincipalId("jhopf"),workflowDocument.getRouteHeaderId());
293  0 assertTrue(workflowDocument.stateIsEnroute());
294  0 assertTrue(workflowDocument.isApprovalRequested());
295   
296  0 Person user = KIMServiceLocator.getPersonService().getPersonByPrincipalName(userNetworkId);
297  0 DocSearchCriteriaDTO criteria = new DocSearchCriteriaDTO();
298  0 criteria.setSuperUserSearch("YES");
299  0 criteria.setDocTypeFullName(customDocHandlerDocumentType);
300  0 DocumentSearchResultComponents result = docSearchService.getList(user.getPrincipalId(), criteria);
301  0 assertNotNull(result);
302  0 assertNotNull(result.getSearchResults());
303  0 assertEquals("Search returned invalid number of documents", 2, result.getSearchResults().size());
304  0 for (DocumentSearchResult resultElement : result.getSearchResults()) {
305  0 KeyValueSort kvs = resultElement.getResultContainer(DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID);
306  0 assertNotNull("A valid column field value should be returned for key " + DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID, kvs);
307  0 assertTrue("The document handler redirect for the client should be included in the route header id url", kvs.getValue().contains(KEWConstants.DOC_HANDLER_REDIRECT_PAGE));
308  0 assertTrue("The document handler redirect for the client should include the command value for super user search", kvs.getValue().contains(KEWConstants.SUPERUSER_COMMAND));
309    }
310   
311  0 user = KIMServiceLocator.getPersonService().getPersonByPrincipalName(userNetworkId);
312  0 criteria = new DocSearchCriteriaDTO();
313  0 criteria.setSuperUserSearch("YES");
314  0 result = docSearchService.getList(user.getPrincipalId(), criteria);
315  0 assertNotNull(result);
316  0 assertNotNull(result.getSearchResults());
317  0 assertEquals("Search returned invalid number of documents", 3, result.getSearchResults().size());
318  0 for (DocumentSearchResult resultElement : result.getSearchResults()) {
319  0 KeyValueSort routeHeaderIdValue = resultElement.getResultContainer(DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID);
320  0 assertNotNull("A valid column field value should be returned for key " + DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID, routeHeaderIdValue);
321  0 KeyValueSort documentTypeValue = resultElement.getResultContainer(DocumentSearchResult.PROPERTY_NAME_DOC_TYPE_LABEL);
322  0 assertNotNull("A valid column field value should be returned for key " + DocumentSearchResult.PROPERTY_NAME_DOC_TYPE_LABEL, documentTypeValue);
323  0 if (customDocHandlerDocumentType.equals(documentTypeValue.getValue())) {
324  0 assertTrue("The document handler redirect for the client should be included in the route header id url", routeHeaderIdValue.getValue().contains(KEWConstants.DOC_HANDLER_REDIRECT_PAGE));
325  0 assertTrue("The document handler redirect for the client should include the command value for super user search", routeHeaderIdValue.getValue().contains(KEWConstants.SUPERUSER_COMMAND));
326  0 } else if (standardDocHandlerDocumentType.equals(documentTypeValue.getValue())) {
327  0 assertTrue("The document handler redirect for the client should be included in the route header id url", !routeHeaderIdValue.getValue().contains(KEWConstants.DOC_HANDLER_REDIRECT_PAGE));
328    } else {
329  0 fail("Found document search result row with document type '" + documentTypeValue.getValue() + "' that should not have existed");
330    }
331    }
332    }
333   
334    /**
335    * Tests the usage of wildcards on the regular document search attributes.
336    * @throws Exception
337    */
 
338  0 toggle @Test public void testDocSearch_WildcardsOnRegularAttributes() throws Exception {
339    // TODO: Add some wildcard testing for the document type attribute once wildcards are usable with it.
340   
341    // Route some test documents.
342  0 String docTypeName = "SearchDocType";
343  0 String[] principalNames = {"bmcgough", "quickstart", "rkirkend"};
344  0 String[] titles = {"The New Doc", "Document Number 2", "Some New Document"};
345  0 String[] docIds = new String[titles.length];
346  0 String[] appDocIds = {"6543", "5432", "4321"};
347  0 String[] approverNames = {null, "jhopf", null};
348  0 for (int i = 0; i < titles.length; i++) {
349  0 WorkflowDocument workflowDocument = new WorkflowDocument(
350    KIMServiceLocator.getPersonService().getPersonByPrincipalName(principalNames[i]).getPrincipalId(), docTypeName);
351  0 workflowDocument.setTitle(titles[i]);
352  0 workflowDocument.setAppDocId(appDocIds[i]);
353  0 workflowDocument.routeDocument("routing this document.");
354  0 docIds[i] = workflowDocument.getRouteHeaderId().toString();
355  0 if (approverNames[i] != null) {
356  0 workflowDocument.setPrincipalId(KIMServiceLocator.getPersonService().getPersonByPrincipalName(approverNames[i]).getPrincipalId());
357  0 workflowDocument.approve("approving this document.");
358    }
359    }
360  0 String principalId = KIMServiceLocator.getPersonService().getPersonByPrincipalName("bmcgough").getPrincipalId();
361  0 DocSearchCriteriaDTO criteria = null;
362  0 List<DocumentSearchResult> searchResults = null;
363  0 DocumentSearchResultComponents result = null;
364   
365    // Test the wildcards on the initiator attribute.
366  0 String[] searchStrings = {"!quickstart", "!rkirkend!bmcgough", "!quickstart&&!rkirkend", "!admin", "user1", "quickstart|bmcgough",
367    "admin|rkirkend", ">bmcgough", ">=rkirkend", "<bmcgough", "<=quickstart", ">bmcgough&&<=rkirkend", "<rkirkend&&!bmcgough",
368    "?mc?oug?", "*t", "*i?k*", "*", "!quick*", "!b???????!?kirk???", "!*g*&&!*k*", ">bmc?ough", "<=quick*", "quickstart..rkirkend"};
369  0 int[] expectedResults = {2, 1, 1, 3, 0, 2, 1, 2, 1, 0, 2, 2, 1, 1, 1, 2, 3, 2, 1, 0, 2, 1, 2/*1*/};
370  0 for (int i = 0; i < searchStrings.length; i++) {
371  0 criteria = new DocSearchCriteriaDTO();
372  0 criteria.setInitiator(searchStrings[i]);
373  0 result = docSearchService.getList(principalId, criteria);
374  0 searchResults = result.getSearchResults();
375  0 assertEquals("Initiator search at index " + i + " retrieved the wrong number of documents.", expectedResults[i], searchResults.size());
376    }
377   
378    // Test the wildcards on the approver attribute.
379  0 searchStrings = new String[] {"jhopf","!jhopf", ">jhopf", "<jjopf", ">=quickstart", "<=jhopf", "jhope..jhopg", "?hopf", "*i*", "!*f", "j*"};
380  0 expectedResults = new int[] {1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1};
381  0 for (int i = 0; i < searchStrings.length; i++) {
382  0 criteria = new DocSearchCriteriaDTO();
383  0 criteria.setApprover(searchStrings[i]);
384  0 result = docSearchService.getList(principalId, criteria);
385  0 searchResults = result.getSearchResults();
386  0 assertEquals("Approver search at index " + i + " retrieved the wrong number of documents.", expectedResults[i], searchResults.size());
387    }
388   
389    // Test the wildcards on the document/notification ID attribute. The string wildcards should get ignored, since the doc ID is not a string.
390  0 searchStrings = new String[] {"!"+docIds[0], docIds[1]+"|"+docIds[2], "<="+docIds[1], ">="+docIds[2], "<"+docIds[0]+"&&>"+docIds[2],
391    ">"+docIds[1], "<"+docIds[2]+"&&!"+docIds[0], docIds[0]+".."+docIds[2], "?"+docIds[1]+"*", "?9*7"};
392  0 expectedResults = new int[] {1, 2, 2, 1, 0, 1, 1, 3/*2*/, 1, 0};
393  0 for (int i = 0; i < searchStrings.length; i++) {
394  0 criteria = new DocSearchCriteriaDTO();
395  0 criteria.setRouteHeaderId(searchStrings[i]);
396  0 result = docSearchService.getList(principalId, criteria);
397  0 searchResults = result.getSearchResults();
398  0 assertEquals("Doc ID search at index " + i + " retrieved the wrong number of documents.", expectedResults[i], searchResults.size());
399    }
400   
401    // Test the wildcards on the application document/notification ID attribute. The string wildcards should work, since the app doc ID is a string.
402  0 searchStrings = new String[] {"6543", "5432|4321", ">4321", "<=5432", ">=6543", "<3210", "!3210", "!5432", "!4321!5432", ">4321&&!6543",
403    "*5?3*", "*", "?3?1", "!*43*", "!???2", ">43*1", "<=5432&&!?32?", "5432..6543"};
404  0 expectedResults = new int[] {1, 2, 2, 2, 1, 0, 3, 2, 1, 1, 2, 3, 1, 0, 2, 3, 1, 2/*1*/};
405  0 for (int i = 0; i < searchStrings.length; i++) {
406  0 criteria = new DocSearchCriteriaDTO();
407  0 criteria.setAppDocId(searchStrings[i]);
408  0 result = docSearchService.getList(principalId, criteria);
409  0 searchResults = result.getSearchResults();
410  0 if(expectedResults[i] != searchResults.size()){
411  0 assertEquals("App doc ID search at index " + i + " retrieved the wrong number of documents.", expectedResults[i], searchResults.size());
412    }
413    }
414   
415    // Test the wildcards on the viewer attribute.
416  0 searchStrings = new String[] {"jhopf","!jhopf", ">jhopf", "<jjopf", ">=quickstart", "<=jhopf", "jhope..jhopg", "?hopf", "*i*", "!*f", "j*"};
417  0 expectedResults = new int[] {3, 0, 0, 3, 0, 3, 3, 3, 0, 0, 3};
418  0 for (int i = 0; i < searchStrings.length; i++) {
419  0 criteria = new DocSearchCriteriaDTO();
420  0 criteria.setViewer(searchStrings[i]);
421  0 result = docSearchService.getList(principalId, criteria);
422  0 searchResults = result.getSearchResults();
423  0 if(expectedResults[i] != searchResults.size()){
424  0 assertEquals("Viewer search at index " + i + " retrieved the wrong number of documents.", expectedResults[i], searchResults.size());
425    }
426    }
427   
428    // Test the wildcards on the title attribute.
429  0 searchStrings = new String[] {"Some New Document", "Document Number 2|The New Doc", "!The New Doc", "!Some New Document!Document Number 2",
430    "!The New Doc&&!Some New Document", ">Document Number 2", "<=Some New Document", ">=The New Doc&&<Some New Document", ">A New Doc",
431    "<Some New Document|The New Doc", ">=Document Number 2&&!Some New Document", "*Docu??nt*", "*New*", "The ??? Doc", "*Doc*", "*Number*",
432    "Some New Document..The New Doc", "Document..The", "*New*&&!*Some*", "!The ??? Doc|!*New*"};
433  0 expectedResults = new int[] {1, 2, 2, 1, 1, 2, 2, 0, 3, 2, 2, 2, 2, 1, 3, 1, 2/*1*/, 2, 1, 2};
434  0 for (int i = 0; i < searchStrings.length; i++) {
435  0 criteria = new DocSearchCriteriaDTO();
436  0 criteria.setDocTitle(searchStrings[i]);
437  0 result = docSearchService.getList(principalId, criteria);
438  0 searchResults = result.getSearchResults();
439  0 if(expectedResults[i] != searchResults.size()){
440  0 assertEquals("Doc title search at index " + i + " retrieved the wrong number of documents.", expectedResults[i], searchResults.size());
441    }
442    }
443   
444   
445    }
446   
 
447  0 toggle private String getPrincipalId(String principalName) {
448  0 return KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(principalName).getPrincipalId();
449    }
450    }