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.gl.batch;
017:
018: import java.util.Calendar;
019: import java.util.GregorianCalendar;
020:
021: import org.kuali.core.util.KualiDecimal;
022: import org.kuali.kfs.KFSConstants;
023: import org.kuali.kfs.context.SpringContext;
024: import org.kuali.module.chart.service.A21SubAccountService;
025: import org.kuali.module.chart.service.PriorYearAccountService;
026: import org.kuali.module.chart.service.SubFundGroupService;
027: import org.kuali.module.financial.service.UniversityDateService;
028: import org.kuali.module.gl.OriginEntryTestBase;
029: import org.kuali.module.gl.batch.closing.year.service.impl.helper.EncumbranceClosingRuleHelper;
030: import org.kuali.module.gl.batch.closing.year.util.EncumbranceClosingOriginEntryFactory;
031: import org.kuali.module.gl.bo.Encumbrance;
032: import org.kuali.module.gl.util.OriginEntryOffsetPair;
033: import org.kuali.test.ConfigureContext;
034:
035: /**
036: * Tests that the forward encumbrance process is generating cost share encumbrance forwarding origin entries correctly
037: */
038: @ConfigureContext
039: public class ForwardEncumbranceTest extends OriginEntryTestBase {
040: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
041: .getLogger(ForwardEncumbranceTest.class);
042:
043: /**
044: * An enum with a set of encumbrances to test; here, we've only got one encumbrance, an encumbrance
045: * that should force forward encumbrances to generate a cost share forwarding entry/offset pair
046: */
047: enum ENCUMBRANCE_FIXTURE {
048: COST_SHARE_ENCUMBRANCE("BL", "4531413", "CS001", "7100", "EX",
049: "EE");
050:
051: // to find account: select ca_prior_yr_acct_t.fin_coa_cd, ca_prior_yr_acct_t.ACCOUNT_NBR, CA_A21_SUB_ACCT_T.sub_acct_nbr
052: // from (ca_prior_yr_acct_t join ca_sub_fund_grp_t on ca_prior_yr_acct_t.SUB_FUND_GRP_CD =
053: // ca_sub_fund_grp_t.SUB_FUND_GRP_CD) join CA_A21_SUB_ACCT_T on CA_PRIOR_YR_ACCT_T.fin_coa_cd = CA_A21_SUB_ACCT_T.fin_coa_cd
054: // and CA_PRIOR_YR_ACCT_T.account_nbr = CA_A21_SUB_ACCT_T.account_nbr where ca_sub_fund_grp_t.FUND_GRP_CD = 'CG' and
055: // CA_A21_SUB_ACCT_T.sub_acct_typ_cd = 'CS'
056: // this was a rough one, it needed a cost share sub account and a CG sub fund group fund group type
057:
058: private String chart;
059: private String accountNumber;
060: private String subAccountNumber;
061: private String objectCode;
062: private String balanceType;
063: private String objectTypeCode;
064:
065: /**
066: * Constructs a ForwardEncumbranceTest.ENCUMBRANCE_FIXTURE
067: * @param chart the chart of the encumbrance
068: * @param accountNumber the account of the encumbrance
069: * @param subAccountNumber the sub account of the encumbrance
070: * @param objectCode the object code of the encumbrance
071: * @param balanceType the balance type code of the encumbrance
072: * @param objectTypeCode the object type code of the encumbrance
073: */
074: private ENCUMBRANCE_FIXTURE(String chart, String accountNumber,
075: String subAccountNumber, String objectCode,
076: String balanceType, String objectTypeCode) {
077: this .chart = chart;
078: this .accountNumber = accountNumber;
079: this .subAccountNumber = subAccountNumber;
080: this .objectCode = objectCode;
081: this .balanceType = balanceType;
082: this .objectTypeCode = objectTypeCode;
083: }
084:
085: /**
086: * Converts one of the members of this enum to an actual Encumbrance
087: *
088: * @return a real encumbrance!
089: */
090: public Encumbrance convertToEncumbrance() {
091: Encumbrance e = new Encumbrance();
092: Integer fy = new Integer(SpringContext.getBean(
093: UniversityDateService.class).getCurrentFiscalYear()
094: .intValue() - 1);
095: e.setUniversityFiscalYear(fy);
096: e.setChartOfAccountsCode(chart);
097: e.setAccountNumber(accountNumber);
098: e.setSubAccountNumber(subAccountNumber);
099: e.setObjectCode(objectCode);
100: e.setSubObjectCode(KFSConstants
101: .getDashFinancialSubObjectCode());
102: e.setBalanceTypeCode(balanceType);
103: e.setDocumentTypeCode("EXEN"); // we don't need this field
104: e.setOriginCode("EP");
105: e.setDocumentNumber("000001"); // we don't need this field
106: GregorianCalendar lastYear = new GregorianCalendar();
107: lastYear.add(Calendar.YEAR, -1);
108: e.setTransactionEncumbranceDate(new java.sql.Date(lastYear
109: .getTimeInMillis()));
110: e
111: .setTransactionEncumbranceDescription("MONKEYS-R-US IS THE NEWEST AND GREATEST STORE IN THE ENTIRE TRI-STATE AREA");
112: e.setAccountLineEncumbranceAmount(new KualiDecimal(1000));
113: e.setAccountLineEncumbranceClosedAmount(KualiDecimal.ZERO);
114: return e;
115: }
116:
117: /**
118: * Returns the object type code of this enum
119: *
120: * @return this enum's object type code
121: */
122: public String getObjectType() {
123: return this .objectTypeCode;
124: }
125: }
126:
127: /**
128: * Tests that the expected encumbrance fixtures would be selected by the forward encumbrance process
129: */
130: public void testEncumbranceSelection() {
131: EncumbranceClosingRuleHelper helper = new EncumbranceClosingRuleHelper();
132: helper.setA21SubAccountService(SpringContext
133: .getBean(A21SubAccountService.class));
134: helper.setKualiConfigurationService(kualiConfigurationService);
135: helper.setPriorYearAccountService(SpringContext
136: .getBean(PriorYearAccountService.class));
137: helper.setSubFundGroupService(SpringContext
138: .getBean(SubFundGroupService.class));
139:
140: assertTrue(helper
141: .anEntryShouldBeCreatedForThisEncumbrance(ENCUMBRANCE_FIXTURE.COST_SHARE_ENCUMBRANCE
142: .convertToEncumbrance()));
143: }
144:
145: /**
146: * Tests that the expted fixtures would be selected for cost share entry/offset generation by the forward encumbrance process
147: *
148: * @throws Exception thrown if something goes wrong
149: */
150: public void testCostShareSelection() throws Exception {
151: EncumbranceClosingRuleHelper helper = new EncumbranceClosingRuleHelper();
152: helper.setA21SubAccountService(SpringContext
153: .getBean(A21SubAccountService.class));
154: helper.setKualiConfigurationService(kualiConfigurationService);
155: helper.setPriorYearAccountService(SpringContext
156: .getBean(PriorYearAccountService.class));
157: helper.setSubFundGroupService(SpringContext
158: .getBean(SubFundGroupService.class));
159:
160: Encumbrance encumbrance = ENCUMBRANCE_FIXTURE.COST_SHARE_ENCUMBRANCE
161: .convertToEncumbrance();
162: OriginEntryOffsetPair entryPair = EncumbranceClosingOriginEntryFactory
163: .createBeginningBalanceEntryOffsetPair(encumbrance,
164: SpringContext.getBean(
165: UniversityDateService.class)
166: .getCurrentFiscalYear(),
167: new java.sql.Date(new GregorianCalendar()
168: .getTimeInMillis()));
169:
170: assertTrue(helper.isEncumbranceEligibleForCostShare(entryPair
171: .getEntry(), entryPair.getOffset(), encumbrance,
172: ENCUMBRANCE_FIXTURE.COST_SHARE_ENCUMBRANCE
173: .getObjectType()));
174:
175: OriginEntryOffsetPair costShareEntryPair = EncumbranceClosingOriginEntryFactory
176: .createCostShareBeginningBalanceEntryOffsetPair(
177: encumbrance, new java.sql.Date(
178: new GregorianCalendar()
179: .getTimeInMillis()));
180: LOG.info(costShareEntryPair.getEntry().getLine());
181: LOG.info(costShareEntryPair.getOffset().getLine());
182:
183: assertTrue(costShareEntryPair.getOffset().getLine().indexOf(
184: "GENERATED") >= 0);
185: }
186: }
|