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.HashMap;
020: import java.util.List;
021: import java.util.Map;
022: import java.util.Properties;
023:
024: import org.kuali.core.lookup.LookupableHelperService;
025: import org.kuali.core.service.BusinessObjectService;
026: import org.kuali.core.service.PersistenceService;
027: import org.kuali.kfs.KFSPropertyConstants;
028: import org.kuali.kfs.context.KualiTestBase;
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.kfs.lookup.LookupableSpringContext;
031: import org.kuali.module.gl.web.TestDataGenerator;
032: import org.kuali.module.labor.bo.LedgerBalance;
033: import org.kuali.module.labor.util.ObjectUtil;
034: import org.kuali.test.ConfigureContext;
035:
036: /**
037: * This class contains the test cases that can be applied to the method in LedgerBalanceLookupableImpl class.
038: */
039: @ConfigureContext
040: public class LedgerBalanceLookupableHelperServiceTest extends
041: KualiTestBase {
042: private BusinessObjectService businessObjectService;
043: private LookupableHelperService lookupableHelperService;
044: private PersistenceService persistenceService;
045:
046: private Properties properties;
047: private String fieldNames, documentFieldNames;
048: private String deliminator;
049: private int ledgerBalanceNumberOfTestData;
050: private int ledgerBalanceExpectedInsertion;
051:
052: @Override
053: protected void setUp() throws Exception {
054: super .setUp();
055:
056: businessObjectService = SpringContext
057: .getBean(BusinessObjectService.class);
058:
059: lookupableHelperService = LookupableSpringContext
060: .getLookupableHelperService("laborLedgerBalanceLookupableHelperService");
061: lookupableHelperService
062: .setBusinessObjectClass(LedgerBalance.class);
063:
064: // Clear up the database so that any existing data cannot affact your test result
065: HashMap keys = new HashMap();
066: keys.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, "2004");
067: keys.put(KFSPropertyConstants.EMPLID, "1000000005");
068: keys
069: .put(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE,
070: "AC");
071: keys.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, "BL");
072: businessObjectService.deleteMatching(LedgerBalance.class, keys);
073: }
074:
075: public void testGetSearchResults() throws Exception {
076: insertLedgerBalanceRecords();
077:
078: LedgerBalance ledgerBalance = new LedgerBalance();
079: ledgerBalance.setUniversityFiscalYear(2004);
080: ledgerBalance.setEmplid("0000001265");
081: ledgerBalance.setBalanceTypeCode("AC");
082: ledgerBalance.setChartOfAccountsCode("BL");
083:
084: // test the search results before the specified entry is inserted into the database
085: Map fieldValues = buildFieldValues(ledgerBalance, this
086: .getLookupFields(false));
087: List searchResults = lookupableHelperService
088: .getSearchResults(fieldValues);
089:
090: if (searchResults != null) {
091: System.out.println("Results Size:" + searchResults.size());
092: }
093:
094: // compare the search results with the expected and see if they match with each other
095: assertEquals(this .ledgerBalanceExpectedInsertion, searchResults
096: .size());
097: }
098:
099: private Map<String, String> buildFieldValues(
100: LedgerBalance ledgerBalance, List<String> lookupFields) {
101: Map<String, String> fieldValues = new HashMap<String, String>();
102:
103: Map<String, Object> tempFieldValues = ObjectUtil
104: .buildPropertyMap(ledgerBalance, lookupFields);
105: for (String key : tempFieldValues.keySet()) {
106: fieldValues.put(key, tempFieldValues.get(key).toString());
107: }
108: return fieldValues;
109: }
110:
111: private List<String> getLookupFields(boolean isExtended) {
112: List<String> lookupFields = new ArrayList<String>();
113:
114: lookupFields.add(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
115: lookupFields.add(KFSPropertyConstants.EMPLID);
116: lookupFields
117: .add(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE);
118: lookupFields.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
119:
120: return lookupFields;
121: }
122:
123: protected void insertLedgerBalanceRecords() {
124: String messageFileName = "test/src/org/kuali/module/labor/web/testdata/message.properties";
125: String propertiesFileName = "test/src/org/kuali/module/labor/web/testdata/ledgerBalance.properties";
126:
127: properties = (new TestDataGenerator(propertiesFileName,
128: messageFileName)).getProperties();
129: fieldNames = properties.getProperty("fieldNames");
130: documentFieldNames = properties.getProperty("fieldNames");
131: deliminator = properties.getProperty("deliminator");
132:
133: TestDataGenerator testDataGenerator = new TestDataGenerator(
134: propertiesFileName, messageFileName);
135:
136: businessObjectService = SpringContext
137: .getBean(BusinessObjectService.class);
138: persistenceService = SpringContext
139: .getBean(PersistenceService.class);
140:
141: int numberOfDocuments = Integer.valueOf(properties
142: .getProperty("getLedgerBalance.numOfData"));
143: List<LedgerBalance> inputDataList = new ArrayList<LedgerBalance>();
144: for (int i = 1; i <= numberOfDocuments; i++) {
145: String propertyKey = "getLedgerBalance.testData" + i;
146: LedgerBalance inputData = new LedgerBalance();
147: ObjectUtil.populateBusinessObject(inputData, properties,
148: propertyKey, documentFieldNames, deliminator);
149: inputDataList.add(inputData);
150: }
151:
152: String testTarget = "getLedgerBalance.";
153: this .ledgerBalanceNumberOfTestData = Integer.valueOf(properties
154: .getProperty(testTarget + "numOfData"));
155: this .ledgerBalanceExpectedInsertion = Integer
156: .valueOf(properties.getProperty(testTarget
157: + "expectedInsertion"));
158: businessObjectService.save(inputDataList);
159: }
160: }
|