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:
017: package org.kuali.module.gl.batch;
018:
019: import java.sql.Date;
020: import java.text.DateFormat;
021: import java.text.SimpleDateFormat;
022: import java.util.ArrayList;
023: import java.util.Collection;
024: import java.util.HashMap;
025: import java.util.Iterator;
026: import java.util.List;
027: import java.util.Map;
028:
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.kfs.context.TestUtils;
031: import org.kuali.kfs.service.ParameterService;
032: import org.kuali.kfs.service.impl.ParameterConstants;
033: import org.kuali.module.gl.GLConstants;
034: import org.kuali.module.gl.OriginEntryTestBase;
035: import org.kuali.module.gl.bo.OriginEntryFull;
036: import org.kuali.module.gl.bo.OriginEntryGroup;
037: import org.kuali.module.gl.service.OriginEntryGroupService;
038: import org.kuali.module.gl.service.OriginEntryService;
039: import org.kuali.module.gl.util.GeneralLedgerTestHelper;
040: import org.kuali.test.ConfigureContext;
041:
042: /**
043: * A test to see if the balance forward year end process produces the expected origin entries
044: */
045: @ConfigureContext
046: // @RelatesTo(RelatesTo.JiraIssue.KULRNE5916)
047: public class BalanceForwardStepTest extends OriginEntryTestBase {
048: // IF THIS TEST FAILS, READ KULRNE-34 regarding reference numbers
049: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
050: .getLogger(BalanceForwardStepTest.class);
051:
052: /**
053: * Constructs a BalanceForwardStepTest instance
054: */
055: public BalanceForwardStepTest() {
056: super ();
057: }
058:
059: /**
060: * Sets up the test by getting the date parameter
061: * @see org.kuali.module.gl.OriginEntryTestBase#setUp()
062: */
063: @Override
064: protected void setUp() throws Exception {
065:
066: super .setUp();
067:
068: DateFormat transactionDateFormat = new SimpleDateFormat(
069: "yyyy-MM-dd");
070: dateTimeService
071: .setCurrentDate(new Date(
072: transactionDateFormat
073: .parse(
074: SpringContext
075: .getBean(
076: ParameterService.class)
077: .getParameterValue(
078: ParameterConstants.GENERAL_LEDGER_BATCH.class,
079: GLConstants.ANNUAL_CLOSING_TRANSACTION_DATE_PARM))
080: .getTime()));
081: }
082:
083: /**
084: * Test the encumbrance forwarding process in one fell swoop. IF THIS TEST FAILS, READ
085: * KULRNE-34 regarding reference numbers and the year end dates
086: *
087: * @throws Exception ## WARNING: DO NOT run this test or rename this method. WARNING ## ## WARNING: This one test takes just
088: * under 3 hours to run WARNING ## ## WARNING: over the vpn. WARNING ##
089: */
090: public void testAll() throws Exception {
091:
092: clearOriginEntryTables();
093: BalanceTestHelper.populateBalanceTable();
094:
095: // Execute the step ...
096: BalanceForwardStep step = SpringContext
097: .getBean(BalanceForwardStep.class);
098: step.execute(getClass().getName());
099:
100: // load our services.
101: OriginEntryService entryService = SpringContext
102: .getBean(OriginEntryService.class);
103: OriginEntryGroupService groupService = SpringContext
104: .getBean(OriginEntryGroupService.class);
105:
106: // and verify the output.
107: List fisGeneratedRaw = GeneralLedgerTestHelper
108: .loadOutputOriginEntriesFromClasspath(
109: "org/kuali/module/gl/batch/gl_gleacbfb.data.txt",
110: dateTimeService.getCurrentDate());
111: List fisGenerated = new ArrayList();
112: for (Object o : fisGeneratedRaw) {
113: fisGenerated.add(filterOriginEntryLine((String) o));
114: }
115:
116: // load our groups.
117: Map criteria = new HashMap();
118:
119: criteria.put("sourceCode", "YEBB");
120: Collection kualiGeneratedNonClosedPriorYearAccountGroups = groupService
121: .getMatchingGroups(criteria);
122:
123: criteria.put("sourceCode", "YEBC");
124: Collection kualiGeneratedClosedPriorYearAccountGroups = groupService
125: .getMatchingGroups(criteria);
126:
127: // compute the difference between what should be output and what was output.
128: List kualiGeneratedEntriesNotGeneratedByFis = new ArrayList();
129:
130: Iterator kualiGeneratedNonClosedPriorYearAccountGroupIterator = kualiGeneratedNonClosedPriorYearAccountGroups
131: .iterator();
132: while (kualiGeneratedNonClosedPriorYearAccountGroupIterator
133: .hasNext()) {
134:
135: OriginEntryGroup kualiGroup = (OriginEntryGroup) kualiGeneratedNonClosedPriorYearAccountGroupIterator
136: .next();
137:
138: Iterator kualiGeneratedNonClosedPriorYearAccountEntryIterator = entryService
139: .getEntriesByGroup(kualiGroup);
140:
141: while (kualiGeneratedNonClosedPriorYearAccountEntryIterator
142: .hasNext()) {
143:
144: OriginEntryFull entry = (OriginEntryFull) kualiGeneratedNonClosedPriorYearAccountEntryIterator
145: .next();
146: String kualiEntryLine = entry.getLine();
147:
148: kualiEntryLine = filterOriginEntryLine(kualiEntryLine
149: .substring(0, 173));
150:
151: if (!fisGenerated.remove(kualiEntryLine)) {
152:
153: kualiGeneratedEntriesNotGeneratedByFis
154: .add(kualiEntryLine);
155:
156: }
157:
158: }
159:
160: }
161:
162: Iterator closedPriorYearAccountGroupsIterator = kualiGeneratedClosedPriorYearAccountGroups
163: .iterator();
164: while (closedPriorYearAccountGroupsIterator.hasNext()) {
165:
166: OriginEntryGroup group = (OriginEntryGroup) closedPriorYearAccountGroupsIterator
167: .next();
168:
169: Iterator entryIterator = entryService
170: .getEntriesByGroup(group);
171: while (entryIterator.hasNext()) {
172:
173: OriginEntryFull entry = (OriginEntryFull) entryIterator
174: .next();
175: String line = filterOriginEntryLine(entry.getLine()
176: .substring(0, 173));
177:
178: if (!fisGenerated.remove(line)) {
179:
180: kualiGeneratedEntriesNotGeneratedByFis.add(line);
181:
182: }
183:
184: }
185:
186: }
187:
188: traceList(kualiGeneratedEntriesNotGeneratedByFis,
189: "kuali not fis");
190: traceList(fisGenerated, "fis not kuali");
191:
192: // At this point extraEntriesGenerated and shouldBe should both be empty.
193: // If they're not then something went wrong.
194: assertTrue(
195: "Kuali generated entries that FIS did not generate (see KULRNE-34 for possible cause):",
196: kualiGeneratedEntriesNotGeneratedByFis.isEmpty());
197: assertTrue(
198: "FIS generated entries that Kuali did not generate (see KULRNE-34 for possible cause):",
199: fisGenerated.isEmpty());
200:
201: }
202:
203: /**
204: * This method resets the application params to values that are appropriate for year end dates
205: *
206: * @see org.kuali.module.gl.OriginEntryTestBase#setApplicationConfigurationFlag(java.lang.String, boolean)
207: */
208: @Override
209: protected void setApplicationConfigurationFlag(
210: Class componentClass, String name, boolean value)
211: throws Exception {
212: super .setApplicationConfigurationFlag(componentClass, name,
213: value);
214: TestUtils.setSystemParameter(
215: ParameterConstants.GENERAL_LEDGER_BATCH.class,
216: GLConstants.ANNUAL_CLOSING_TRANSACTION_DATE_PARM,
217: "2004-01-01");
218: TestUtils.setSystemParameter(
219: ParameterConstants.GENERAL_LEDGER_BATCH.class,
220: GLConstants.ANNUAL_CLOSING_FISCAL_YEAR_PARM, "2004");
221: }
222:
223: /**
224: * Removes the sequence number from the origin entry line
225: *
226: * @param line the original origin entry line
227: * @return the filtered origin entry line
228: */
229: private String filterOriginEntryLine(String line) {
230: // right now, remove the sequence number from this test
231: return line.substring(0, 51) + line.substring(57);
232: }
233: }
|