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.Date;
019: import java.util.Iterator;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.apache.commons.beanutils.PropertyUtils;
024: import org.kuali.core.bo.PersistableBusinessObjectBase;
025: import org.kuali.core.lookup.LookupableHelperService;
026: import org.kuali.core.service.DateTimeService;
027: import org.kuali.kfs.bo.GeneralLedgerPendingEntry;
028: import org.kuali.kfs.context.KualiTestBase;
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.kfs.service.GeneralLedgerPendingEntryService;
031: import org.kuali.module.gl.web.TestDataGenerator;
032:
033: /**
034: * This class is a template being used by the test case classes of GL lookupable implementation.
035: */
036: public abstract class AbstractGLLookupableHelperServiceTestBase extends
037: KualiTestBase {
038:
039: protected Date date;
040: protected GeneralLedgerPendingEntry pendingEntry;
041: protected TestDataGenerator testDataGenerator;
042: protected LookupableHelperService lookupableHelperServiceImpl;
043: protected GeneralLedgerPendingEntryService pendingEntryService;
044:
045: /**
046: * Sets up the test by initializing several properties
047: * @see junit.framework.TestCase#setUp()
048: */
049: @Override
050: protected void setUp() throws Exception {
051: super .setUp();
052:
053: date = SpringContext.getBean(DateTimeService.class)
054: .getCurrentDate();
055: pendingEntry = new GeneralLedgerPendingEntry();
056: testDataGenerator = new TestDataGenerator();
057:
058: setPendingEntryService(SpringContext
059: .getBean(GeneralLedgerPendingEntryService.class));
060: }
061:
062: /**
063: * test cases for getSearchResults method of LookupableImpl class
064: */
065: public abstract void testGetSearchResults() throws Exception;
066:
067: /**
068: * This method defines the lookup fields
069: *
070: * @param isExtended flag if the non required fields are included
071: * @return a list of lookup fields
072: */
073: public abstract List getLookupFields(boolean isExtended);
074:
075: /**
076: * This method defines the primary key fields
077: *
078: * @return a list of primary key fields
079: */
080: public List getPrimaryKeyFields() {
081: return lookupableHelperServiceImpl.getReturnKeys();
082: }
083:
084: /**
085: * test cases for getInquiryUrl method of LookupableImpl class
086: */
087: public void testGetInquiryUrl() throws Exception {
088: }
089:
090: /**
091: * This method tests if the search results have the given entry
092: *
093: * @param searchResults the search results
094: * @param businessObject the given business object
095: * @return true if the given business object is in the search results
096: */
097: protected boolean contains(List searchResults,
098: PersistableBusinessObjectBase businessObject) {
099: boolean isContains = false;
100: List priamryKeyFields = getPrimaryKeyFields();
101: int numberOfPrimaryKeyFields = priamryKeyFields.size();
102:
103: String propertyName, resultPropertyValue, propertyValue;
104:
105: Iterator searchResultsIterator = searchResults.iterator();
106: while (searchResultsIterator.hasNext() && !isContains) {
107: Object resultRecord = searchResultsIterator.next();
108:
109: isContains = true;
110: for (int i = 0; i < numberOfPrimaryKeyFields; i++) {
111: try {
112: propertyName = (String) (priamryKeyFields.get(i));
113: resultPropertyValue = PropertyUtils.getProperty(
114: resultRecord, propertyName).toString();
115: propertyValue = PropertyUtils.getProperty(
116: businessObject, propertyName).toString();
117:
118: if (!resultPropertyValue.equals(propertyValue)) {
119: isContains = false;
120: break;
121: }
122: } catch (Exception e) {
123: e.printStackTrace();
124: }
125: }
126: }
127: return isContains;
128: }
129:
130: /**
131: * This method creates the lookup form fields with the given business object and lookup fields
132: *
133: * @param businessObject the given business object
134: * @param isExtended determine if the extended lookup fields are used
135: * @return a lookup form fields
136: * @throws Exception thrown if any exception is encountered for any reason
137: */
138: public Map getLookupFieldValues(
139: PersistableBusinessObjectBase businessObject,
140: boolean isExtended) throws Exception {
141: List lookupFields = this .getLookupFields(isExtended);
142: return testDataGenerator.generateLookupFieldValues(
143: businessObject, lookupFields);
144: }
145:
146: /**
147: * This method inserts a new pending ledger Entry record into database
148: *
149: * @param pendingEntry the given pending ledger Entry
150: */
151: protected void insertNewPendingEntry(
152: GeneralLedgerPendingEntry pendingEntry) {
153: try {
154: getPendingEntryService().save(pendingEntry);
155: } catch (Exception e) {
156: e.printStackTrace();
157: }
158: }
159:
160: /**
161: * Gets the pendingEntryService attribute.
162: *
163: * @return Returns the pendingEntryService.
164: */
165: public GeneralLedgerPendingEntryService getPendingEntryService() {
166: return pendingEntryService;
167: }
168:
169: /**
170: * Sets the pendingEntryService attribute value.
171: *
172: * @param pendingEntryService The pendingEntryService to set.
173: */
174: public void setPendingEntryService(
175: GeneralLedgerPendingEntryService pendingEntryService) {
176: this.pendingEntryService = pendingEntryService;
177: }
178: }
|