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.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.PersistableBusinessObject;
025: import org.kuali.core.service.DateTimeService;
026: import org.kuali.kfs.context.KualiTestBase;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.kfs.lookup.LookupableSpringContext;
029: import org.kuali.module.gl.web.TestDataGenerator;
030: import org.kuali.module.labor.bo.LaborLedgerPendingEntry;
031: import org.kuali.module.labor.service.LaborLedgerPendingEntryService;
032: import org.kuali.test.ConfigureContext;
033:
034: /**
035: * Unit tests for the Lookup Helper Service of the <code>{@link LaborLedgerPendingEntry}</code> business object
036: */
037: @ConfigureContext
038: public class LaborPendingEntryLookupableHelperServiceTest extends
039: KualiTestBase {
040: private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
041: .getLog(LaborPendingEntryLookupableHelperServiceTest.class);
042:
043: private String messageFileName;
044: private String propertiesFileName;
045: private Date date;
046: private LaborLedgerPendingEntry pendingEntry;
047: private TestDataGenerator testDataGenerator;
048: private LaborLedgerPendingEntryService pendingEntryService;
049: private LaborPendingEntryLookupableHelperServiceImpl lookupableHelperServiceImpl;
050:
051: /**
052: * @see org.kuali.module.gl.web.lookupable.AbstractGLLookupableTestBase#testGetSearchResults()
053: */
054: public void testGetSearchResults() throws Exception {
055: }
056:
057: /**
058: * @see org.kuali.module.gl.web.lookupable.AbstractGLLookupableTestBase#getLookupFields(boolean)
059: */
060: public List getLookupFields(boolean isExtended) {
061: return null;
062: }
063:
064: @Override
065: protected void setUp() throws Exception {
066: super .setUp();
067:
068: messageFileName = "test/src/org/kuali/module/labor/web/testdata/message.properties";
069: propertiesFileName = "test/src/org/kuali/module/labor/web/testdata/laborLedgerPendingEntry.properties";
070: date = SpringContext.getBean(DateTimeService.class)
071: .getCurrentDate();
072: pendingEntry = new LaborLedgerPendingEntry();
073: testDataGenerator = new TestDataGenerator(propertiesFileName,
074: messageFileName);
075: lookupableHelperServiceImpl = (LaborPendingEntryLookupableHelperServiceImpl) LookupableSpringContext
076: .getLookupableHelperService("laborPendingEntryLookupableHelperService");
077: setPendingEntryService(SpringContext
078: .getBean(LaborLedgerPendingEntryService.class));
079: }
080:
081: /**
082: * This method defines the primary key fields
083: *
084: * @return a list of primary key fields
085: */
086: public List getPrimaryKeyFields() {
087: return lookupableHelperServiceImpl.getReturnKeys();
088: }
089:
090: /**
091: * test cases for getInquiryUrl method of LookupableImpl class
092: */
093: public void testGetInquiryUrl() throws Exception {
094: }
095:
096: /**
097: * This method tests if the search results have the given entry
098: *
099: * @param searchResults the search results
100: * @param businessObject the given business object
101: * @return true if the given business object is in the search results
102: */
103: protected boolean contains(List searchResults,
104: PersistableBusinessObject businessObject) {
105: boolean isContains = false;
106: List priamryKeyFields = getPrimaryKeyFields();
107: int numberOfPrimaryKeyFields = priamryKeyFields.size();
108:
109: String propertyName, resultPropertyValue, propertyValue;
110:
111: Iterator searchResultsIterator = searchResults.iterator();
112: while (searchResultsIterator.hasNext() && !isContains) {
113: Object resultRecord = searchResultsIterator.next();
114:
115: isContains = true;
116: for (int i = 0; i < numberOfPrimaryKeyFields; i++) {
117: try {
118: propertyName = (String) (priamryKeyFields.get(i));
119: resultPropertyValue = PropertyUtils.getProperty(
120: resultRecord, propertyName).toString();
121: propertyValue = PropertyUtils.getProperty(
122: businessObject, propertyName).toString();
123:
124: if (!resultPropertyValue.equals(propertyValue)) {
125: isContains = false;
126: break;
127: }
128: } catch (Exception e) {
129: e.printStackTrace();
130: }
131: }
132: }
133: return isContains;
134: }
135:
136: /**
137: * This method creates the lookup form fields with the given business object and lookup fields
138: *
139: * @param businessObject the given business object
140: * @param isExtended determine if the extended lookup fields are used
141: * @return a lookup form fields
142: * @throws Exception
143: */
144: public Map getLookupFieldValues(
145: PersistableBusinessObject businessObject, boolean isExtended)
146: throws Exception {
147: List lookupFields = this .getLookupFields(isExtended);
148: // return testDataGenerator.generateLookupFieldValues(businessObject, lookupFields);
149: return null;
150: }
151:
152: /**
153: * Gets the pendingEntryService attribute.
154: *
155: * @return Returns the pendingEntryService.
156: */
157: public LaborLedgerPendingEntryService getPendingEntryService() {
158: return pendingEntryService;
159: }
160:
161: /**
162: * Sets the pendingEntryService attribute value.
163: *
164: * @param pendingEntryService The pendingEntryService to set.
165: */
166: public void setPendingEntryService(
167: LaborLedgerPendingEntryService pendingEntryService) {
168: this.pendingEntryService = pendingEntryService;
169: }
170: }
|