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;
017:
018: import java.util.ArrayList;
019: import java.util.HashMap;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.apache.commons.beanutils.PropertyUtils;
024: import org.kuali.kfs.KFSPropertyConstants;
025: import org.kuali.kfs.bo.GeneralLedgerPendingEntry;
026: import org.kuali.kfs.context.KualiTestBase;
027: import org.kuali.module.gl.bo.AccountBalance;
028:
029: /**
030: * A test of the TestDataGenerator fixtures.
031: */
032: public class TestDataGeneratorTest extends KualiTestBase {
033:
034: private TestDataGenerator testDataGenerator;
035: private GeneralLedgerPendingEntry pendingEntry;
036: private AccountBalance accountBalance;
037:
038: /**
039: * Sets up the test by creating a new TestDataGenerator as well as an account balance and pending entry
040: * @see junit.framework.TestCase#setUp()
041: */
042: @Override
043: public void setUp() throws Exception {
044: super .setUp();
045: testDataGenerator = new TestDataGenerator();
046: pendingEntry = new GeneralLedgerPendingEntry();
047: accountBalance = new AccountBalance();
048: }
049:
050: /**
051: * test case for generateTransactionDate method of TestDataGenerator class
052: * @throws Exception thrown if an exception is encountered for any reason
053: */
054: public void testGenerateTransactionData() throws Exception {
055: testDataGenerator.generateTransactionData(pendingEntry);
056: assertEquals(pendingEntry.getAccountNumber(), testDataGenerator
057: .getProperties().getProperty("accountNumber"));
058: assertNull(pendingEntry.getTransactionDate());
059: try {
060: Object property = PropertyUtils.getProperty(pendingEntry,
061: "objectCode");
062: assertTrue(false);
063: } catch (Exception e) {
064: assertTrue(true);
065: }
066: }
067:
068: /**
069: * test case for generateTransactionDate method of TestDataGenerator class
070: * @throws Exception thrown if an exception is encountered for any reason
071: */
072: public void testGenerateFieldValues() throws Exception {
073: Map fieldValues = new HashMap();
074:
075: // test business object implementing transaction
076: fieldValues = testDataGenerator
077: .generateLookupFieldValues(pendingEntry);
078: assertEquals(testDataGenerator.getProperties().getProperty(
079: "accountNumber"), fieldValues.get("accountNumber"));
080: assertNull(fieldValues.get("transactionDate"));
081: assertNull(fieldValues.get("objectCode"));
082:
083: // test business object not implementing transaction
084: fieldValues = testDataGenerator
085: .generateLookupFieldValues(accountBalance);
086: assertEquals(testDataGenerator.getProperties().getProperty(
087: "accountNumber"), fieldValues.get("accountNumber"));
088: assertEquals(testDataGenerator.getProperties().getProperty(
089: "dummyBusinessObject.consolidationOption"), fieldValues
090: .get("dummyBusinessObject.consolidationOption"));
091:
092: assertNull(fieldValues.get("timestamp"));
093: assertNull(fieldValues.get("finacialObjectCode"));
094: }
095:
096: /**
097: * test case for generateTransactionDate method of TestDataGenerator class
098: * @param test an unused parameter
099: * @throws Exception thrown if an exception is encountered for any reason
100: */
101: public void testGenerateFieldValues(String test) throws Exception {
102: Map fieldValues = new HashMap();
103:
104: List lookupFields = getLookupFields(true);
105:
106: // test business object implementing transaction
107: fieldValues = testDataGenerator.generateLookupFieldValues(
108: pendingEntry, lookupFields);
109: assertEquals(testDataGenerator.getProperties().getProperty(
110: "accountNumber"), fieldValues.get("accountNumber"));
111: assertEquals(testDataGenerator.getProperties().getProperty(
112: "dummyBusinessObject.consolidationOption"), fieldValues
113: .get("dummyBusinessObject.consolidationOption"));
114: assertNull(fieldValues.get("transactionDate"));
115: assertNull(fieldValues.get("objectCode"));
116:
117: // test business object not implementing transaction
118: fieldValues = testDataGenerator.generateLookupFieldValues(
119: accountBalance, lookupFields);
120: assertEquals(testDataGenerator.getProperties().getProperty(
121: "accountNumber"), fieldValues.get("accountNumber"));
122: assertEquals(testDataGenerator.getProperties().getProperty(
123: "dummyBusinessObject.consolidationOption"), fieldValues
124: .get("dummyBusinessObject.consolidationOption"));
125:
126: assertNull(fieldValues.get("timestamp"));
127: assertNull(fieldValues.get("finacialObjectCode"));
128: }
129:
130: /**
131: * Generates a list of lookup fields
132: *
133: * @param isExtended should the lookup fields include extended fields?
134: * @return a List of lookup field names
135: */
136: protected List getLookupFields(boolean isExtended) {
137: List lookupFields = new ArrayList();
138:
139: lookupFields.add(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
140: lookupFields.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
141: lookupFields.add(KFSPropertyConstants.ACCOUNT_NUMBER);
142: lookupFields
143: .add(KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE);
144: lookupFields
145: .add(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE);
146: lookupFields.add("dummyBusinessObject.consolidationOption");
147: lookupFields.add("dummyBusinessObject.pendingEntryOption");
148:
149: // include the extended fields
150: if (isExtended) {
151: lookupFields.add(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
152: lookupFields
153: .add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
154: lookupFields
155: .add(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
156:
157: lookupFields
158: .add(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE);
159: lookupFields
160: .add(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE);
161: lookupFields
162: .add(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE);
163: lookupFields.add(KFSPropertyConstants.DOCUMENT_NUMBER);
164: lookupFields
165: .add(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER);
166: }
167: return lookupFields;
168: }
169: }
|