001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.docsearch;
018:
019: import java.io.FileInputStream;
020: import java.util.Calendar;
021: import java.util.Collection;
022: import java.util.HashMap;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.junit.Test;
027: import org.kuali.workflow.test.WorkflowTestCase;
028:
029: import edu.iu.uis.eden.EdenConstants;
030: import edu.iu.uis.eden.KEWServiceLocator;
031: import edu.iu.uis.eden.doctype.DocumentType;
032: import edu.iu.uis.eden.lookupable.DocumentTypeLookupableImpl;
033: import edu.iu.uis.eden.user.AuthenticationUserId;
034: import edu.iu.uis.eden.user.UserService;
035: import edu.iu.uis.eden.user.WorkflowUser;
036:
037: public class DocumentSearchTest extends WorkflowTestCase {
038:
039: DocumentSearchService docSearchService;
040: UserService userService;
041:
042: protected void setUpTransaction() throws Exception {
043: docSearchService = (DocumentSearchService) KEWServiceLocator
044: .getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
045: userService = (UserService) KEWServiceLocator
046: .getService(KEWServiceLocator.USER_SERVICE);
047: }
048:
049: @Test
050: public void testDocSearch() throws Exception {
051: WorkflowUser user = userService
052: .getWorkflowUser(new AuthenticationUserId("bmcgough"));
053: DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
054: List searchResults = null;
055: DocumentSearchResultComponents result = null;
056: criteria.setDocTitle("*IN");
057: criteria.setNamedSearch("bytitle");
058: result = docSearchService.getList(user, criteria);
059: criteria = new DocSearchCriteriaVO();
060: criteria.setDocTitle("*IN-CFSG");
061: criteria.setNamedSearch("for in accounts");
062: result = docSearchService.getList(user, criteria);
063: criteria = new DocSearchCriteriaVO();
064: criteria.setFromDateApproved("09/16/2004");
065: result = docSearchService.getList(user, criteria);
066: criteria = new DocSearchCriteriaVO();
067: criteria.setDocRouteNodeId("3");
068: criteria.setDocRouteNodeLogic("equal");
069: result = docSearchService.getList(user, criteria);
070: user = userService.getWorkflowUser(new AuthenticationUserId(
071: "bmcgough"));
072: SavedSearchResult savedSearchResults = docSearchService
073: .getSavedSearchResults(user,
074: "DocSearch.NamedSearch.bytitle");
075: assertNotNull(savedSearchResults);
076: savedSearchResults = docSearchService.getSavedSearchResults(
077: user, "DocSearch.NamedSearch.for in accounts");
078: assertNotNull(savedSearchResults);
079: }
080:
081: @Test
082: public void testGetNamedDocSearches() throws Exception {
083: WorkflowUser user = userService
084: .getWorkflowUser(new AuthenticationUserId("bmcgough"));
085: List namedSearches = docSearchService.getNamedSearches(user);
086: assertNotNull(namedSearches);
087: }
088:
089: /**
090: * Test for https://test.kuali.org/jira/browse/KULWF-703
091: */
092: @Test
093: public void testSearchEDENSERVICE_DOCS() throws Exception {
094: loadXmlStream(new FileInputStream(
095: "conf/bootstrap/BootstrapData.xml"));
096: // loadXmlStream(new FileInputStream("conf/bootstrap/BootstrapRuleTemplateContent.xml"));
097: // loadXmlStream(new FileInputStream("conf/bootstrap/BootstrapDocumentTypesContent.xml"));
098: // loadXmlStream(new FileInputStream("conf/bootstrap/BootstrapRuleContent.xml"));
099:
100: Collection c = KEWServiceLocator.getDocumentTypeService().find(
101: new DocumentType(), "EDENSERVICE-DOCS", true);
102: assertNotNull(c);
103: assertTrue(c.size() > 0);
104:
105: DocumentTypeLookupableImpl lookupable = new DocumentTypeLookupableImpl();
106: Map fieldValues = new HashMap();
107: fieldValues.put(
108: DocumentTypeLookupableImpl.ACTIVE_IND_PROPERTY_NAME,
109: "ALL");
110: fieldValues.put(
111: DocumentTypeLookupableImpl.DOC_TYP_PROPERTY_NAME, "");
112: fieldValues.put(DocumentTypeLookupableImpl.DOC_TYP_FULL_NAME,
113: "");
114: fieldValues
115: .put(
116: DocumentTypeLookupableImpl.DOCUMENT_TYPE_ID_PROPERTY_NAME,
117: "");
118: fieldValues.put(
119: DocumentTypeLookupableImpl.DOC_TYP_NAME_PROPERTY_NAME,
120: "EDENSERVICE-DOCS");
121: fieldValues.put(
122: DocumentTypeLookupableImpl.BACK_LOCATION_KEY_NAME,
123: "http://localhost:8080/en-dev/DocumentSearch.do");
124:
125: fieldValues.put(DocumentTypeLookupableImpl.DOC_FORM_KEY_NAME,
126: "0");
127:
128: //String docTypReturn = (String) fieldConversions.get(DOC_TYP_FULL_NAME);
129:
130: List list = lookupable.getSearchResults(fieldValues,
131: new HashMap());
132: assertNotNull(list);
133: assertTrue(list.size() > 0);
134: }
135:
136: @Test
137: public void testDefaultCreateDateSearchCriteria() throws Exception {
138: WorkflowUser user = userService
139: .getWorkflowUser(new AuthenticationUserId("bmcgough"));
140: DocSearchCriteriaVO criteria = new DocSearchCriteriaVO();
141: DocumentSearchResultComponents result = docSearchService
142: .getList(user, criteria);
143: assertNotNull("Should have a date created value", criteria
144: .getFromDateCreated());
145: Calendar today = Calendar.getInstance();
146: Calendar criteriaDate = Calendar.getInstance();
147: criteriaDate.setTime(DocSearchUtils
148: .convertStringDateToTimestamp(criteria
149: .getFromDateCreated()));
150: assertEquals(
151: "Criteria date minus today's date should equal the constant value",
152: EdenConstants.DOCUMENT_SEARCH_NO_CRITERIA_CREATE_DATE_DAYS_AGO
153: .doubleValue(), getDifferenceInDays(today,
154: criteriaDate));
155:
156: criteria = new DocSearchCriteriaVO();
157: criteria.setDocTitle("testing");
158: result = docSearchService.getList(user, criteria);
159: assertNotNull("Should have a date created value", criteria
160: .getFromDateCreated());
161: today = Calendar.getInstance();
162: criteriaDate = Calendar.getInstance();
163: criteriaDate.setTime(DocSearchUtils
164: .convertStringDateToTimestamp(criteria
165: .getFromDateCreated()));
166: assertEquals(
167: "Criteria date minus today's date should equal the constant value",
168: EdenConstants.DOCUMENT_SEARCH_DOC_TITLE_CREATE_DATE_DAYS_AGO
169: .doubleValue(), getDifferenceInDays(today,
170: criteriaDate));
171: }
172:
173: private static double getDifferenceInDays(Calendar startCalendar,
174: Calendar endCalendar) {
175: // First, get difference in whole days
176: startCalendar.set(Calendar.HOUR_OF_DAY, 0);
177: startCalendar.set(Calendar.MINUTE, 0);
178: startCalendar.set(Calendar.SECOND, 0);
179: startCalendar.set(Calendar.MILLISECOND, 0);
180:
181: endCalendar.set(Calendar.HOUR_OF_DAY, 0);
182: endCalendar.set(Calendar.MINUTE, 0);
183: endCalendar.set(Calendar.SECOND, 0);
184: endCalendar.set(Calendar.MILLISECOND, 0);
185:
186: return (endCalendar.getTimeInMillis() - startCalendar
187: .getTimeInMillis())
188: / (24 * 60 * 60 * 1000);
189: }
190:
191: }
|