001: /*
002: * Copyright 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.labor.web.lookupable;
017:
018: import java.util.ArrayList;
019: import java.util.Arrays;
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.Map;
023: import java.util.Properties;
024:
025: import org.apache.commons.lang.StringUtils;
026: import org.kuali.core.lookup.LookupableHelperService;
027: import org.kuali.core.service.BusinessObjectService;
028: import org.kuali.core.service.PersistenceService;
029: import org.kuali.kfs.KFSPropertyConstants;
030: import org.kuali.kfs.context.KualiTestBase;
031: import org.kuali.kfs.context.SpringContext;
032: import org.kuali.kfs.lookup.LookupableSpringContext;
033: import org.kuali.module.gl.web.TestDataGenerator;
034: import org.kuali.module.labor.LaborConstants;
035: import org.kuali.module.labor.bo.AccountStatusBaseFunds;
036: import org.kuali.module.labor.bo.CalculatedSalaryFoundationTracker;
037: import org.kuali.module.labor.bo.LedgerBalance;
038: import org.kuali.module.labor.service.LaborInquiryOptionsService;
039: import org.kuali.module.labor.util.ObjectUtil;
040: import org.kuali.test.ConfigureContext;
041:
042: /**
043: * This class contains test cases that can be applied to methods in Account Status Base Funds class.
044: */
045: @ConfigureContext
046: public class BaseFundsLookupableHelperServiceTest extends KualiTestBase {
047: private BusinessObjectService businessObjectService;
048: private LookupableHelperService lookupableHelperService;
049: private PersistenceService persistenceService;
050:
051: private Properties properties;
052: private String fieldNames, documentFieldNames;
053: private String deliminator;
054: private int csfNumberOfTestData;
055: private int csfExpectedInsertion;
056: private int baseFundsNumberOfTestData;
057: private int baseFundsExpectedInsertion;
058:
059: @Override
060: /**
061: * Get things ready for the test
062: */
063: protected void setUp() throws Exception {
064: super .setUp();
065:
066: businessObjectService = SpringContext
067: .getBean(BusinessObjectService.class);
068:
069: lookupableHelperService = LookupableSpringContext
070: .getLookupableHelperService(LaborConstants.BASE_FUNDS_LOOKUP_HELPER_SRVICE_NAME);
071: lookupableHelperService
072: .setBusinessObjectClass(AccountStatusBaseFunds.class);
073:
074: // Clear up the database so that any existing data cannot affact your test result
075: Map keys = new HashMap();
076: keys.put(KFSPropertyConstants.ACCOUNT_NUMBER, "1031400");
077: keys.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, "2007");
078: keys.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, "BL");
079: businessObjectService.deleteMatching(LedgerBalance.class, keys);
080: businessObjectService.deleteMatching(
081: CalculatedSalaryFoundationTracker.class, keys);
082: }
083:
084: /**
085: * This method will run the base funds balance inquiry to test that the BaseFundsLookupableHelperService is returning data
086: * correctly.
087: *
088: * @throws Exception
089: */
090: public void testGetSearchResults() throws Exception {
091: /*
092: * insertBaseFundsRecords(); insertCSFRecords(); AccountStatusBaseFunds accountStatusBaseFunds = new
093: * AccountStatusBaseFunds(); accountStatusBaseFunds.setAccountNumber("1031400");
094: * accountStatusBaseFunds.setUniversityFiscalYear(2007); accountStatusBaseFunds.setChartOfAccountsCode("BL"); // test the
095: * search results before the specified entry is inserted into the database Map fieldValues =
096: * buildFieldValues(accountStatusBaseFunds, this.getLookupFields(false)); // Tells the lookupable I want detailed results
097: * getInquiryOptionsService().getConsolidationField(lookupableHelperService.getRows()).setPropertyValue(Constant.DETAIL);
098: * fieldValues.put(Constant.CONSOLIDATION_OPTION, Constant.DETAIL); List<String> groupByList = new ArrayList<String>();
099: * List<AccountStatusBaseFunds> searchResults = lookupableHelperService.getSearchResults(fieldValues); // Make sure the
100: * basic search parameters are returned from the inquiry for (AccountStatusBaseFunds accountStatusBaseFundsReturn :
101: * searchResults) {
102: * assertFalse(!(accountStatusBaseFundsReturn.getAccountNumber().equals(accountStatusBaseFunds.getAccountNumber()) &&
103: * accountStatusBaseFundsReturn.getUniversityFiscalYear().equals(accountStatusBaseFunds.getUniversityFiscalYear()) &&
104: * accountStatusBaseFundsReturn.getChartOfAccountsCode().equals(accountStatusBaseFunds.getChartOfAccountsCode()))); } if
105: * (searchResults != null) { System.out.println("Results Size:" + searchResults.size()); } // compare the search results
106: * with the expected and see if they match with each other
107: * assertEquals(this.baseFundsExpectedInsertion,searchResults.size());
108: */
109: }
110:
111: /**
112: * This method will run the base funds balance inquiry to test that the BaseFundsLookupableHelperService is returning data
113: * correctly.
114: *
115: * @throws Exception
116: */
117: public void testGetSearchResultsConsolidated() throws Exception {
118: /*
119: * insertBaseFundsRecords(); insertCSFRecords(); AccountStatusBaseFunds accountStatusBaseFunds = new
120: * AccountStatusBaseFunds(); accountStatusBaseFunds.setAccountNumber("1031400");
121: * accountStatusBaseFunds.setUniversityFiscalYear(2007); accountStatusBaseFunds.setChartOfAccountsCode("BL"); // test the
122: * search results before the specified entry is inserted into the database Map fieldValues =
123: * buildFieldValues(accountStatusBaseFunds, this.getLookupFields(false)); // Tells the lookupable I want consolidated
124: * results
125: * getInquiryOptionsService().getConsolidationField(lookupableHelperService.getRows()).setPropertyValue(Constant.CONSOLIDATION);
126: * fieldValues.put(Constant.CONSOLIDATION_OPTION, Constant.CONSOLIDATION); List<String> groupByList = new ArrayList<String>();
127: * List<AccountStatusBaseFunds> searchResults = lookupableHelperService.getSearchResults(fieldValues); // Make sure the
128: * basic search parameters are returned from the inquiry for (AccountStatusBaseFunds accountStatusBaseFundsReturn :
129: * searchResults) {
130: * assertFalse(!(accountStatusBaseFundsReturn.getAccountNumber().equals(accountStatusBaseFunds.getAccountNumber()) &&
131: * accountStatusBaseFundsReturn.getUniversityFiscalYear().equals(accountStatusBaseFunds.getUniversityFiscalYear()) &&
132: * accountStatusBaseFundsReturn.getChartOfAccountsCode().equals(accountStatusBaseFunds.getChartOfAccountsCode()))); } if
133: * (searchResults != null) { System.out.println("Results Size:" + searchResults.size()); } // compare the search results
134: * with the expected and see if they match with each other
135: * assertEquals(this.baseFundsExpectedInsertion,searchResults.size());
136: */
137: }
138:
139: /**
140: * This method uses property file parameters to create insert database records for this test
141: *
142: * @param accountStatusBaseFunds
143: * @param lookupFields
144: * @return
145: */
146: private Map<String, String> buildFieldValues(
147: AccountStatusBaseFunds accountStatusBaseFunds,
148: List<String> lookupFields) {
149: Map<String, String> fieldValues = new HashMap<String, String>();
150:
151: Map<String, Object> tempFieldValues = ObjectUtil
152: .buildPropertyMap(accountStatusBaseFunds, lookupFields);
153: for (String key : tempFieldValues.keySet()) {
154: fieldValues.put(key, tempFieldValues.get(key).toString());
155: }
156: return fieldValues;
157: }
158:
159: /**
160: * This method adds property constatants for future lookups
161: *
162: * @param isExtended
163: * @return
164: */
165: private List<String> getLookupFields(boolean isExtended) {
166: List<String> lookupFields = new ArrayList<String>();
167:
168: lookupFields.add(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
169: lookupFields.add(KFSPropertyConstants.ACCOUNT_NUMBER);
170: lookupFields.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
171:
172: return lookupFields;
173: }
174:
175: /**
176: * This method will add temporary test data to the CSF Tracker table
177: */
178: protected void insertCSFRecords() {
179: String messageFileName = "test/src/org/kuali/module/labor/web/testdata/message.properties";
180: String propertiesFileName = "test/src/org/kuali/module/labor/web/testdata/csfTracker.properties";
181:
182: properties = (new TestDataGenerator(propertiesFileName,
183: messageFileName)).getProperties();
184: fieldNames = properties.getProperty("fieldNames");
185: documentFieldNames = properties.getProperty("fieldNames");
186: deliminator = properties.getProperty("deliminator");
187:
188: CalculatedSalaryFoundationTracker cleanup = new CalculatedSalaryFoundationTracker();
189: ObjectUtil.populateBusinessObject(cleanup, properties,
190: "dataCleanup", fieldNames, deliminator);
191: Map fieldValues = ObjectUtil.buildPropertyMap(cleanup, Arrays
192: .asList(StringUtils.split(fieldNames, deliminator)));
193: businessObjectService.deleteMatching(
194: CalculatedSalaryFoundationTracker.class, fieldValues);
195:
196: TestDataGenerator testDataGenerator = new TestDataGenerator(
197: propertiesFileName, messageFileName);
198:
199: businessObjectService = SpringContext
200: .getBean(BusinessObjectService.class);
201: persistenceService = SpringContext
202: .getBean(PersistenceService.class);
203:
204: int numberOfDocuments = Integer.valueOf(properties
205: .getProperty("getCSFTracker.numberOfDocuments"));
206: List<CalculatedSalaryFoundationTracker> inputDataList = new ArrayList<CalculatedSalaryFoundationTracker>();
207: for (int i = 1; i <= numberOfDocuments; i++) {
208: String propertyKey = "getCSFTracker.testData" + i;
209: CalculatedSalaryFoundationTracker inputData = new CalculatedSalaryFoundationTracker();
210: ObjectUtil.populateBusinessObject(inputData, properties,
211: propertyKey, documentFieldNames, deliminator);
212: inputDataList.add(inputData);
213: // System.out.println(ObjectUtil.buildPropertyMap(inputData, ObjectUtil.split(fieldNames, deliminator)));
214: }
215:
216: String testTarget = "getCSFTracker.";
217: this .csfNumberOfTestData = Integer.valueOf(properties
218: .getProperty(testTarget + "numberOfDocuments"));
219: this .csfExpectedInsertion = Integer.valueOf(properties
220: .getProperty(testTarget + "expectedInsertion"));
221: businessObjectService.save(inputDataList);
222: }
223:
224: /**
225: * This method will add temporary test data to the Ledger Balance table
226: */
227: protected void insertBaseFundsRecords() {
228: String messageFileName = "test/src/org/kuali/module/labor/web/testdata/message.properties";
229: String propertiesFileName = "test/src/org/kuali/module/labor/web/testdata/accountStatusBaseFunds.properties";
230:
231: properties = (new TestDataGenerator(propertiesFileName,
232: messageFileName)).getProperties();
233: fieldNames = properties.getProperty("fieldNames");
234: documentFieldNames = properties.getProperty("fieldNames");
235: deliminator = properties.getProperty("deliminator");
236:
237: TestDataGenerator testDataGenerator = new TestDataGenerator(
238: propertiesFileName, messageFileName);
239:
240: businessObjectService = SpringContext
241: .getBean(BusinessObjectService.class);
242: persistenceService = SpringContext
243: .getBean(PersistenceService.class);
244:
245: int numberOfDocuments = Integer.valueOf(properties
246: .getProperty("getAccountStatusBaseFunds.numOfData"));
247: List<LedgerBalance> inputDataList = new ArrayList<LedgerBalance>();
248: for (int i = 1; i <= numberOfDocuments; i++) {
249: String propertyKey = "getAccountStatusBaseFunds.testData"
250: + i;
251: LedgerBalance inputData = new LedgerBalance();
252: ObjectUtil.populateBusinessObject(inputData, properties,
253: propertyKey, documentFieldNames, deliminator);
254: inputDataList.add(inputData);
255: }
256: String testTarget = "getAccountStatusBaseFunds.";
257: this .baseFundsNumberOfTestData = Integer.valueOf(properties
258: .getProperty(testTarget + "numOfData"));
259: this .baseFundsExpectedInsertion = Integer.valueOf(properties
260: .getProperty(testTarget + "expectedInsertion"));
261: businessObjectService.save(inputDataList);
262: }
263:
264: private LaborInquiryOptionsService getInquiryOptionsService() {
265: return SpringContext.getBean(LaborInquiryOptionsService.class);
266: }
267: }
|