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.List;
020: import java.util.Map;
021:
022: import org.kuali.kfs.KFSPropertyConstants;
023: import org.kuali.kfs.context.SpringContext;
024: import org.kuali.kfs.lookup.LookupableSpringContext;
025: import org.kuali.module.gl.bo.AccountBalance;
026: import org.kuali.module.gl.bo.AccountBalanceByConsolidation;
027: import org.kuali.module.gl.service.AccountBalanceService;
028: import org.kuali.module.gl.web.Constant;
029: import org.kuali.test.ConfigureContext;
030:
031: /**
032: * This class contains the test cases that can be applied to the method in AccountBalanceLookupableImpl class.
033: */
034: @ConfigureContext
035: public class AccountBalanceLookupableHelperServiceTest extends
036: AbstractGLLookupableHelperServiceTestBase {
037:
038: private AccountBalanceService accountBalanceService;
039:
040: /**
041: * Initializes the services needed for this test
042: * @see org.kuali.module.gl.web.lookupable.AbstractGLLookupableHelperServiceTestBase#setUp()
043: */
044: @Override
045: protected void setUp() throws Exception {
046: super .setUp();
047:
048: setAccountBalanceService(SpringContext
049: .getBean(AccountBalanceService.class));
050: lookupableHelperServiceImpl = LookupableSpringContext
051: .getLookupableHelperService("glAccountBalanceLookupableHelperService");
052: lookupableHelperServiceImpl
053: .setBusinessObjectClass(AccountBalanceByConsolidation.class);
054: }
055:
056: /**
057: * Covers the search results returned by AccountBalanceLookupableService
058: * @throws Exception thrown if any exception is encountered for any reason
059: * @see org.kuali.module.gl.web.lookupable.AbstractGLLookupableTestBase#testGetSearchResults()
060: */
061: public void testGetSearchResults() throws Exception {
062: testDataGenerator.generateTransactionData(pendingEntry);
063: AccountBalance accountBalance = new AccountBalance(pendingEntry);
064:
065: // test the search results before the specified entry is inserted into the database
066: Map fieldValues = getLookupFieldValues(accountBalance, true);
067: List searchResults = lookupableHelperServiceImpl
068: .getSearchResults(fieldValues);
069: assertTrue(!contains(searchResults, accountBalance));
070:
071: // add a new entry into database. If complete this step, such entry should not in the database
072: insertNewRecord(accountBalance);
073:
074: // test the search results with only the required fields
075: fieldValues = getLookupFieldValues(accountBalance, true);
076: searchResults = lookupableHelperServiceImpl
077: .getSearchResults(fieldValues);
078: assertTrue(searchResults.size() == 1);
079: assertTrue(contains(searchResults, accountBalance));
080:
081: // add a new entry into database. If complete this step, such entry should not in the database
082: // Here, we can reuse encumbrance declared above
083: fieldValues = getLookupFieldValues(accountBalance, true);
084: AccountBalance accountBalance1 = new AccountBalance(
085: pendingEntry);
086: accountBalance1.setSubAccountNumber(testDataGenerator
087: .getPropertyValue("genericSubAccountNumber"));
088:
089: insertNewRecord(accountBalance1);
090:
091: // test the search results with all specified fields. The new record cannot meet the search criteria.
092: fieldValues = getLookupFieldValues(accountBalance, true);
093: searchResults = lookupableHelperServiceImpl
094: .getSearchResults(fieldValues);
095: assertTrue(searchResults.size() == 1);
096: assertTrue(!contains(searchResults, accountBalance1));
097:
098: // test the search results with all specified fields. The new record cannot meet the search criteria.
099: fieldValues = getLookupFieldValues(accountBalance, false);
100: searchResults = lookupableHelperServiceImpl
101: .getSearchResults(fieldValues);
102: assertTrue(searchResults.size() >= 2);
103: assertTrue(contains(searchResults, accountBalance));
104: assertTrue(contains(searchResults, accountBalance1));
105: }
106:
107: /**
108: * This method includes the test cases applied to the consolidation option: Consolidate and Detail
109: *
110: * @throws Exception thrown if any exception is encountered for any reason
111: */
112: public void testConsolidationOption() throws Exception {
113: // ensure the transaction data does not exist in enty table. Otherwise, execption may be raised
114: testDataGenerator.generateTransactionData(pendingEntry);
115: AccountBalance accountBalanceOne = new AccountBalance(
116: pendingEntry);
117:
118: insertNewRecord(accountBalanceOne);
119:
120: // get the number of the search results before adding the second record into database
121: Map fieldValues = getLookupFieldValues(accountBalanceOne, true);
122: fieldValues.put(Constant.CONSOLIDATION_OPTION,
123: Constant.CONSOLIDATION);
124:
125: List searchResults = lookupableHelperServiceImpl
126: .getSearchResults(fieldValues);
127: int numOfFirstResults = searchResults.size();
128:
129: String subAccountNumber = testDataGenerator
130: .getPropertyValue("genericSubAccountNumber");
131: pendingEntry.setSubAccountNumber(subAccountNumber);
132: AccountBalance accountBalanceTwo = new AccountBalance(
133: pendingEntry);
134:
135: insertNewRecord(accountBalanceTwo);
136:
137: // test if the second record is consolidated with others
138: fieldValues = getLookupFieldValues(accountBalanceOne, true);
139: fieldValues.put(Constant.CONSOLIDATION_OPTION,
140: Constant.CONSOLIDATION);
141:
142: searchResults = lookupableHelperServiceImpl
143: .getSearchResults(fieldValues);
144: int numOfSecondResults = searchResults.size();
145: assertTrue(numOfSecondResults == numOfFirstResults);
146:
147: // test if the search results appear in details
148: fieldValues = getLookupFieldValues(accountBalanceOne, false);
149: fieldValues.put(Constant.CONSOLIDATION_OPTION, Constant.DETAIL);
150:
151: searchResults = lookupableHelperServiceImpl
152: .getSearchResults(fieldValues);
153: int numOfThirdResults = searchResults.size();
154: assertTrue(numOfSecondResults < numOfThirdResults);
155: }
156:
157: /**
158: * This method includes the test cases applied to the consolidation option: Consolidate and Detail
159: *
160: * @throws Exception thrown if any exception is encountered for any reason
161: */
162: public void testPerformance() throws Exception {
163: long threshlod = 60000;
164:
165: // get the number of the search results before adding the second record into database
166: AccountBalance accountBalance = new AccountBalance();
167: accountBalance.setAccountNumber("1031400");
168: accountBalance.setUniversityFiscalYear(2004);
169: accountBalance.setChartOfAccountsCode("BL");
170:
171: Map fieldValues = getLookupFieldValues(accountBalance, true);
172: fieldValues.put(Constant.CONSOLIDATION_OPTION,
173: Constant.CONSOLIDATION);
174:
175: long startTime = System.currentTimeMillis();
176: List searchResults = lookupableHelperServiceImpl
177: .getSearchResults(fieldValues);
178: long endTime = System.currentTimeMillis();
179: long duration = endTime - startTime;
180:
181: System.out.println(duration + "ms");
182: assertTrue("Too slow", duration < threshlod);
183:
184: // test if the search results appear in details
185: fieldValues = getLookupFieldValues(accountBalance, false);
186: fieldValues.put(Constant.CONSOLIDATION_OPTION, Constant.DETAIL);
187:
188: startTime = System.currentTimeMillis();
189: searchResults = lookupableHelperServiceImpl
190: .getSearchResults(fieldValues);
191: endTime = System.currentTimeMillis();
192: duration = endTime - startTime;
193:
194: System.out.println(duration + "ms");
195: assertTrue("Too slow", duration < threshlod);
196: }
197:
198: /**
199: * Returns a List of field names to check in the search results
200: * @param isExtended true if extended attributes should be included for checking, false otherwise
201: * @return a List of field names to check
202: * @see org.kuali.module.gl.web.lookupable.AbstractGLLookupableTestBase#getLookupFields(boolean)
203: */
204: public List getLookupFields(boolean isExtended) {
205: List lookupFields = new ArrayList();
206:
207: lookupFields.add(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
208: lookupFields.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
209: lookupFields.add(KFSPropertyConstants.ACCOUNT_NUMBER);
210: lookupFields.add(Constant.CONSOLIDATION_OPTION);
211:
212: // include the extended fields
213: if (isExtended) {
214: lookupFields.add(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
215: lookupFields.add(KFSPropertyConstants.OBJECT_CODE);
216: lookupFields.add(KFSPropertyConstants.SUB_OBJECT_CODE);
217: }
218: return lookupFields;
219: }
220:
221: /**
222: * This method inserts a new account balance record into database
223: *
224: * @param accounBalance the given account balance
225: */
226: protected void insertNewRecord(AccountBalance accounBalance) {
227: try {
228: getAccountBalanceService().save(accounBalance);
229: } catch (Exception e) {
230: }
231: }
232:
233: /**
234: * Gets the accountBalanceService attribute.
235: *
236: * @return Returns the accountBalanceService.
237: */
238: public AccountBalanceService getAccountBalanceService() {
239: return accountBalanceService;
240: }
241:
242: /**
243: * Sets the accountBalanceService attribute value.
244: *
245: * @param accountBalanceService The accountBalanceService to set.
246: */
247: public void setAccountBalanceService(
248: AccountBalanceService accountBalanceService) {
249: this.accountBalanceService = accountBalanceService;
250: }
251: }
|