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.core.lookup;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import org.kuali.core.bo.Campus;
022: import org.kuali.core.bo.user.UniversalUser;
023: import org.kuali.core.service.BusinessObjectMetaDataService;
024: import org.kuali.core.util.FieldUtils;
025: import org.kuali.core.web.ui.Field;
026: import org.kuali.kfs.bo.Options;
027: import org.kuali.kfs.context.KualiTestBase;
028: import org.kuali.kfs.context.SpringContext;
029: import org.kuali.module.chart.bo.Account;
030: import org.kuali.module.chart.bo.Chart;
031: import org.kuali.module.chart.bo.Org;
032: import org.kuali.module.chart.bo.SubAccount;
033: import org.kuali.module.chart.bo.SubFundGroup;
034: import org.kuali.module.gl.bo.AccountBalancePendingEntry;
035: import org.kuali.module.vendor.bo.VendorAddress;
036: import org.kuali.module.vendor.bo.VendorDefaultAddress;
037: import org.kuali.module.vendor.bo.VendorDetail;
038: import org.kuali.test.ConfigureContext;
039: import org.kuali.test.suite.AnnotationTestSuite;
040: import org.kuali.test.suite.LookupRefactoringSuite;
041:
042: /**
043: * This class tests the LookupUtils to make sure that it works properly
044: */
045: @ConfigureContext
046: @AnnotationTestSuite(LookupRefactoringSuite.class)
047: public class LookupUtilsTest extends KualiTestBase {
048:
049: public void testSetFieldQuickfinder_nonNestedAttributesValid() {
050: // testing chartOfAccountsCode lookup
051: Account acct = new Account();
052: Field field = FieldUtils.getPropertyField(acct.getClass(),
053: "chartOfAccountsCode", true);
054: List<String> lookupFieldAttributeList = SpringContext.getBean(
055: BusinessObjectMetaDataService.class)
056: .getLookupableFieldNames(acct.getClass());
057: LookupUtils.setFieldQuickfinder(acct, "chartOfAccountsCode",
058: field, lookupFieldAttributeList);
059: assertEquals(Chart.class.getName(), field
060: .getQuickFinderClassNameImpl());
061:
062: // subFundGroupCode
063: field = FieldUtils.getPropertyField(acct.getClass(),
064: "subFundGroupCode", true);
065: lookupFieldAttributeList = SpringContext.getBean(
066: BusinessObjectMetaDataService.class)
067: .getLookupableFieldNames(acct.getClass());
068: LookupUtils.setFieldQuickfinder(acct, "subFundGroupCode",
069: field, lookupFieldAttributeList);
070: assertEquals(SubFundGroup.class.getName(), field
071: .getQuickFinderClassNameImpl());
072:
073: // organizationCode
074: field = FieldUtils.getPropertyField(acct.getClass(),
075: "organizationCode", true);
076: lookupFieldAttributeList = SpringContext.getBean(
077: BusinessObjectMetaDataService.class)
078: .getLookupableFieldNames(acct.getClass());
079: LookupUtils.setFieldQuickfinder(acct, "organizationCode",
080: field, lookupFieldAttributeList);
081: assertEquals(Org.class.getName(), field
082: .getQuickFinderClassNameImpl());
083: }
084:
085: public void testSetFieldQuickfinder_nonNestedAttributesInvalid() {
086: // testing chartOfAccountsCode lookup
087: Account acct = new Account();
088:
089: Field field = FieldUtils.getPropertyField(acct.getClass(),
090: "accountNumber", true);
091: List<String> lookupFieldAttributeList = SpringContext.getBean(
092: BusinessObjectMetaDataService.class)
093: .getLookupableFieldNames(acct.getClass());
094: LookupUtils.setFieldQuickfinder(acct, "accountNumber", field,
095: lookupFieldAttributeList);
096: assertEquals(null, field.getQuickFinderClassNameImpl());
097:
098: // universityFiscalYearName on Options
099: Options options = new Options();
100: field = FieldUtils.getPropertyField(options.getClass(),
101: "universityFiscalYearName", true);
102: lookupFieldAttributeList = SpringContext.getBean(
103: BusinessObjectMetaDataService.class)
104: .getLookupableFieldNames(options.getClass());
105: LookupUtils.setFieldQuickfinder(options,
106: "universityFiscalYearName", field,
107: lookupFieldAttributeList);
108: assertEquals(null, field.getQuickFinderClassNameImpl());
109:
110: // organizationCode on Org
111: Org org = new Org();
112: field = FieldUtils.getPropertyField(org.getClass(),
113: "organizationCode", true);
114: lookupFieldAttributeList = SpringContext.getBean(
115: BusinessObjectMetaDataService.class)
116: .getLookupableFieldNames(org.getClass());
117: LookupUtils.setFieldQuickfinder(org, "organizationCode", field,
118: lookupFieldAttributeList);
119: assertEquals(null, field.getQuickFinderClassNameImpl());
120:
121: // add one in here for Universal User?
122: }
123:
124: public void testSetFieldQuickfinder_nonNestedAttributesNoLookupTrue() {
125: // testing chartOfAccountsCode lookup
126: Account acct = new Account();
127: Field field = FieldUtils.getPropertyField(acct.getClass(),
128: "accountNumber", true);
129: List<String> lookupFieldAttributeList = SpringContext.getBean(
130: BusinessObjectMetaDataService.class)
131: .getLookupableFieldNames(acct.getClass());
132: LookupUtils.setFieldQuickfinder(acct, "accountNumber", field,
133: lookupFieldAttributeList);
134: assertEquals(null, field.getQuickFinderClassNameImpl());
135:
136: AccountBalancePendingEntry pending = new AccountBalancePendingEntry();
137: // universityFiscalYear on the AccountBalancePendingEntry
138: field = FieldUtils.getPropertyField(pending.getClass(),
139: "universityFiscalYear", true);
140: lookupFieldAttributeList = SpringContext.getBean(
141: BusinessObjectMetaDataService.class)
142: .getLookupableFieldNames(pending.getClass());
143: LookupUtils.setFieldQuickfinder(acct, "universityFiscalYear",
144: field, lookupFieldAttributeList);
145: assertEquals(null, field.getQuickFinderClassNameImpl());
146: }
147:
148: public void testSetFieldQuickfinder_reportsToAccount() {
149: // testing reportsToAccountNumber lookup
150: Account acct = new Account();
151: Field field = FieldUtils.getPropertyField(acct.getClass(),
152: "reportsToAccountNumber", true);
153: List<String> lookupFieldAttributeList = SpringContext.getBean(
154: BusinessObjectMetaDataService.class)
155: .getLookupableFieldNames(acct.getClass());
156: LookupUtils.setFieldQuickfinder(acct, "reportsToAccountNumber",
157: field, lookupFieldAttributeList);
158: // should be account object
159: assertEquals(Account.class.getName(), field
160: .getQuickFinderClassNameImpl());
161: assertTrue("fieldConversions incorrect - was: "
162: + field.getFieldConversions(), field
163: .getFieldConversions().contains(
164: "accountNumber:reportsToAccountNumber"));
165: assertTrue("lookupParameters incorrect - was: "
166: + field.getLookupParameters(), field
167: .getLookupParameters().contains(
168: "reportsToAccountNumber:accountNumber"));
169:
170: }
171:
172: public void testSetFieldQuickfinder_nestedAttributesValid() {
173: // testing chartOfAccountsCode lookup
174: SubAccount subAcct = new SubAccount();
175: Field field = FieldUtils.getPropertyField(subAcct.getClass(),
176: "a21SubAccount.costShareChartOfAccountCode", true);
177: List<String> lookupFieldAttributeList = SpringContext.getBean(
178: BusinessObjectMetaDataService.class)
179: .getLookupableFieldNames(subAcct.getClass());
180: LookupUtils.setFieldQuickfinder(subAcct,
181: "a21SubAccount.costShareChartOfAccount", field,
182: lookupFieldAttributeList);
183: // should be chart object
184: assertEquals(Chart.class.getName(), field
185: .getQuickFinderClassNameImpl());
186: assertEquals(
187: "chartOfAccountsCode:a21SubAccount.costShareChartOfAccountCode",
188: field.getFieldConversions());
189: assertEquals(
190: "a21SubAccount.costShareChartOfAccountCode:chartOfAccountsCode",
191: field.getLookupParameters());
192:
193: }
194:
195: public void testSetFieldQuickfinder_nestedAttributesInvalid() {
196: // testing chartOfAccountsCode lookup
197: Account acct = new Account();
198: Field field = FieldUtils.getPropertyField(acct.getClass(),
199: "chartOfAccounts.codeAndDescription", true);
200: List<String> lookupFieldAttributeList = SpringContext.getBean(
201: BusinessObjectMetaDataService.class)
202: .getLookupableFieldNames(acct.getClass());
203: LookupUtils.setFieldQuickfinder(acct,
204: "chartOfAccounts.codeAndDescription", field,
205: lookupFieldAttributeList);
206: // should be chart object
207: assertEquals(Chart.class.getName(), field
208: .getQuickFinderClassNameImpl());
209: System.out
210: .println("chartOfAccounts.codeAndDescription lookupParams: "
211: + field.getLookupParameters());
212: System.out
213: .println("chartOfAccounts.codeAndDescription fieldConvs : "
214: + field.getFieldConversions());
215: }
216:
217: /**
218: * testing accountFiscalOfficerUser.personUserIdentifier lookup
219: */
220: public void testSetFieldQuickfinder_specialCases() {
221: Account acct = new Account();
222: Field field = FieldUtils.getPropertyField(acct.getClass(),
223: "accountFiscalOfficerUser.personUserIdentifier", true);
224: List<String> lookupFieldAttributeList = SpringContext.getBean(
225: BusinessObjectMetaDataService.class)
226: .getLookupableFieldNames(acct.getClass());
227: LookupUtils.setFieldQuickfinder(acct,
228: "accountFiscalOfficerUser.personUserIdentifier", field,
229: lookupFieldAttributeList);
230: assertEquals(UniversalUser.class.getName(), field
231: .getQuickFinderClassNameImpl());
232: assertTrue(
233: "fieldConversions incorrect - was: "
234: + field.getFieldConversions(),
235: field
236: .getFieldConversions()
237: .contains(
238: "personUniversalIdentifier:accountFiscalOfficerSystemIdentifier"));
239: assertTrue(
240: "fieldConversions incorrect - was: "
241: + field.getFieldConversions(),
242: field
243: .getFieldConversions()
244: .contains(
245: "personUserIdentifier:accountFiscalOfficerUser.personUserIdentifier"));
246: assertTrue(
247: "fieldConversions incorrect - was: "
248: + field.getFieldConversions(),
249: field
250: .getFieldConversions()
251: .contains(
252: "personName:accountFiscalOfficerUser.personName"));
253: assertTrue(
254: "lookupParameters incorrect - was: "
255: + field.getLookupParameters(),
256: field
257: .getLookupParameters()
258: .contains(
259: "accountFiscalOfficerUser.personUserIdentifier:personUserIdentifier"));
260: }
261:
262: public void testSetFieldQuickfinder_vendor() {
263: VendorDetail vd = new VendorDetail();
264: List<VendorAddress> vas = new ArrayList<VendorAddress>();
265: vd.setVendorAddresses(vas);
266: VendorAddress va = new VendorAddress();
267: vas.add(va);
268: VendorDefaultAddress vda = new VendorDefaultAddress();
269: List<VendorDefaultAddress> vdas = new ArrayList<VendorDefaultAddress>();
270: vdas.add(vda);
271: va.setVendorDefaultAddresses(vdas);
272:
273: String vendorDefaultAddressCampusCodePropertyName = "vendorCampusCode";
274: Field field = FieldUtils.getPropertyField(vda.getClass(),
275: vendorDefaultAddressCampusCodePropertyName, true);
276:
277: List<String> lookupFieldAttributeList = SpringContext.getBean(
278: BusinessObjectMetaDataService.class)
279: .getLookupableFieldNames(Campus.class);
280: LookupUtils.setFieldQuickfinder(vda,
281: "vendorAddresses[0].vendorDefaultAddresses", true, 0,
282: vendorDefaultAddressCampusCodePropertyName, field,
283: lookupFieldAttributeList);
284:
285: assertNotNull("quickfinder class was null", field
286: .getQuickFinderClassNameImpl());
287: assertEquals(Campus.class.getName(), field
288: .getQuickFinderClassNameImpl());
289: assertEquals("campusCode:"
290: + "add.vendorAddresses[0].vendorDefaultAddresses."
291: + vendorDefaultAddressCampusCodePropertyName, field
292: .getFieldConversions());
293: assertEquals("add.vendorAddresses[0].vendorDefaultAddresses."
294: + vendorDefaultAddressCampusCodePropertyName
295: + ":campusCode", field.getLookupParameters());
296:
297: LookupUtils.setFieldQuickfinder(vda,
298: "vendorAddresses[0].vendorDefaultAddresses", false, 0,
299: vendorDefaultAddressCampusCodePropertyName, field,
300: lookupFieldAttributeList);
301:
302: assertNotNull("quickfinder class was null", field
303: .getQuickFinderClassNameImpl());
304: assertEquals(Campus.class.getName(), field
305: .getQuickFinderClassNameImpl());
306: assertEquals("campusCode:"
307: + "vendorAddresses[0].vendorDefaultAddresses[0]."
308: + vendorDefaultAddressCampusCodePropertyName, field
309: .getFieldConversions());
310: assertEquals("vendorAddresses[0].vendorDefaultAddresses[0]."
311: + vendorDefaultAddressCampusCodePropertyName
312: + ":campusCode", field.getLookupParameters());
313:
314: }
315: }
|