001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.gl.web.lookupable;
017:
018: import java.util.ArrayList;
019: import java.util.Date;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.kuali.kfs.KFSPropertyConstants;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.kfs.lookup.LookupableSpringContext;
026: import org.kuali.module.gl.bo.Entry;
027: import org.kuali.module.gl.bo.Transaction;
028: import org.kuali.module.gl.dao.EntryDao;
029: import org.kuali.test.ConfigureContext;
030:
031: /**
032: * This class contains the test cases that can be applied to the method in EntryLookupableImpl class.
033: */
034: @ConfigureContext
035: public class EntryLookupableHelperServiceTest extends
036: AbstractGLLookupableHelperServiceTestBase {
037:
038: private EntryDao entryDao;
039:
040: /**
041: * Initializes the services that this test needs to run
042: * @see junit.framework.TestCase#setUp()
043: */
044: @Override
045: protected void setUp() throws Exception {
046: super .setUp();
047:
048: entryDao = SpringContext.getBean(EntryDao.class);
049: lookupableHelperServiceImpl = LookupableSpringContext
050: .getLookupableHelperService("glEntryLookupableHelperService");
051: lookupableHelperServiceImpl.setBusinessObjectClass(Entry.class);
052: }
053:
054: /**
055: * Tests the search results returned by the EntryLookupableHelperService
056: * @see org.kuali.module.gl.web.lookupable.AbstractGLLookupableTestBase#testGetSearchResults()
057: */
058: public void testGetSearchResults() throws Exception {
059: testDataGenerator.generateTransactionData(pendingEntry);
060: Entry entry = new Entry(pendingEntry, date);
061:
062: // test the search results before the specified entry is inserted into the database
063: Map fieldValues = getLookupFieldValues(entry, true);
064: List searchResults = lookupableHelperServiceImpl
065: .getSearchResults(fieldValues);
066: assertTrue(testDataGenerator.getMessageValue("noSuchRecord"),
067: !contains(searchResults, entry));
068:
069: // add a new entry into database.
070: insertNewRecord(pendingEntry, date);
071:
072: // test the search results with only the required fields
073: fieldValues = getLookupFieldValues(entry, true);
074: searchResults = lookupableHelperServiceImpl
075: .getSearchResults(fieldValues);
076: int numOfFirstResult = searchResults.size();
077: assertTrue(
078: testDataGenerator.getMessageValue("wrongRecordSize"),
079: searchResults.size() >= 1);
080: assertTrue(testDataGenerator
081: .getMessageValue("failToFindRecord"), contains(
082: searchResults, entry));
083:
084: // test the search results with all specified fields
085: fieldValues = getLookupFieldValues(entry, false);
086: searchResults = lookupableHelperServiceImpl
087: .getSearchResults(fieldValues);
088: assertTrue(
089: testDataGenerator.getMessageValue("wrongRecordSize"),
090: searchResults.size() >= numOfFirstResult);
091: assertTrue(testDataGenerator
092: .getMessageValue("failToFindRecord"), contains(
093: searchResults, entry));
094: }
095:
096: /**
097: * Returns a List of lookup fields to include in the test
098: * @param isExtended true if extended fields should also be included, false otherwise
099: * @return a List of lookup fields
100: * @see org.kuali.module.gl.web.lookupable.AbstractGLLookupableTestBase#getLookupFields(boolean)
101: */
102: public List getLookupFields(boolean isExtended) {
103: List lookupFields = new ArrayList();
104:
105: lookupFields.add(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
106: lookupFields.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
107: lookupFields.add(KFSPropertyConstants.ACCOUNT_NUMBER);
108: lookupFields
109: .add(KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE);
110: lookupFields
111: .add(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE);
112:
113: // include the extended fields
114: if (isExtended) {
115: lookupFields.add(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
116: lookupFields
117: .add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
118: lookupFields
119: .add(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
120:
121: lookupFields
122: .add(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE);
123: lookupFields
124: .add(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE);
125: lookupFields
126: .add(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE);
127: lookupFields.add(KFSPropertyConstants.DOCUMENT_NUMBER);
128: lookupFields
129: .add(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER);
130: }
131: return lookupFields;
132: }
133:
134: /**
135: * This method inserts a new account balance record into database
136: *
137: * @param transaction the given transaction
138: * @param date the current date
139: */
140: private void insertNewRecord(Transaction transaction, Date date) {
141: try {
142: entryDao.addEntry(transaction, date);
143: } catch (Exception e) {
144: }
145: }
146: }
|