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.financial.rules;
017:
018: import static org.kuali.test.util.KualiTestAssertionUtils.assertGlobalErrorMapEmpty;
019:
020: import org.kuali.core.service.DateTimeService;
021: import org.kuali.kfs.KFSConstants;
022: import org.kuali.kfs.KFSPropertyConstants;
023: import org.kuali.kfs.context.KualiTestBase;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.kfs.rules.AccountingDocumentRuleUtil;
026: import org.kuali.module.chart.bo.AccountingPeriod;
027: import org.kuali.module.chart.bo.codes.BalanceTyp;
028: import org.kuali.module.chart.service.AccountingPeriodService;
029: import org.kuali.module.chart.service.BalanceTypService;
030: import org.kuali.module.financial.document.JournalVoucherDocument;
031: import org.kuali.test.ConfigureContext;
032:
033: /**
034: * Class for unit testing the functionality of <code>{@link TransactionalDocumentRuleUtil}</code>
035: */
036: @ConfigureContext
037: public class TransactionalDocumentRuleUtilTest extends KualiTestBase {
038:
039: private static final String DOES_NOT_MATTER = "doesNotMatter";
040:
041: private static long ONE_DAY_MILLIS = 24 * 60 * 60 * 1000L;
042:
043: private final String ANNUAL_BALANCE_PERIOD_CODE = "AB";
044: private final Integer CURRENT_FISCAL_YEAR = new Integer("2004");
045:
046: // /////////////////////////////////////////////////////////////////////////
047: // Fixture Methods Start Here //
048: // /////////////////////////////////////////////////////////////////////////
049: /**
050: * Accessor method to </code>errorPropertyName</code>
051: *
052: * @return String
053: */
054: protected String getErrorPropertyName() {
055: return KFSConstants.GLOBAL_ERRORS;
056: }
057:
058: /**
059: * Fixture accessor method to get <code>{@link String}</code> serialization instance of an active balance type.
060: *
061: * @return String
062: */
063: protected String getActiveBalanceType() {
064: return KFSConstants.BALANCE_TYPE_ACTUAL;
065: }
066:
067: /**
068: * Fixture accessor method to get <code>{@link String}</code> serialization instance of an inactive balance type.
069: *
070: * @return String
071: */
072: protected String getInactiveBalanceType() {
073: return KFSConstants.BALANCE_TYPE_ACTUAL;
074: }
075:
076: /**
077: * Fixture accessor method for the Annual Balance <code>{@link AccountingPeriod}</code>
078: *
079: * @return AccountingPeriod
080: */
081: public AccountingPeriod getAnnualBalanceAccountingPeriod() {
082: return SpringContext.getBean(AccountingPeriodService.class)
083: .getByPeriod(ANNUAL_BALANCE_PERIOD_CODE,
084: CURRENT_FISCAL_YEAR);
085: }
086:
087: /**
088: * Fixture accessor method for a closed <code>{@link AccountingPeriod}</code> instance.
089: *
090: * @return AccountingPeriod
091: */
092: protected AccountingPeriod getClosedAccountingPeriod() {
093: return null;
094: }
095:
096: /**
097: * Fixture accessor method for getting a <code>{@link java.sql.Date}</code> instance that is in the past.
098: *
099: * @return Timestamp
100: */
101: private java.sql.Date getSqlDateYesterday() {
102: return new java.sql.Date(SpringContext.getBean(
103: DateTimeService.class).getCurrentDate().getTime()
104: - ONE_DAY_MILLIS);
105: }
106:
107: /**
108: * Fixture accessor method for getting a <code>{@link java.sql.Date}</code> instance that is in the future.
109: */
110: private java.sql.Date getSqlDateTomorrow() {
111: return new java.sql.Date(SpringContext.getBean(
112: DateTimeService.class).getCurrentDate().getTime()
113: + ONE_DAY_MILLIS);
114: }
115:
116: /**
117: * @return today's java.sql.Date
118: */
119: private java.sql.Date getSqlDateToday() {
120: return new java.sql.Date(SpringContext.getBean(
121: DateTimeService.class).getCurrentDate().getTime());
122: }
123:
124: // /////////////////////////////////////////////////////////////////////////
125: // Fixture Methods End Here //
126: // /////////////////////////////////////////////////////////////////////////
127:
128: // /////////////////////////////////////////////////////////////////////////
129: // Test Methods Start Here //
130: // /////////////////////////////////////////////////////////////////////////
131: /**
132: * test the <code>isValidBalanceType()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
133: *
134: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidBalanceType
135: */
136: public void testIsValidBalanceType_Active() {
137: testIsValidBalanceType(getActiveBalanceType(), true);
138: }
139:
140: /**
141: * test the <code>isValidBalanceType()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
142: *
143: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidBalanceType
144: */
145: public void testIsValidBalanceType_Inactive() {
146: testIsValidBalanceType(getInactiveBalanceType(), true);
147: }
148:
149: /**
150: * test the <code>isValidBalanceType()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
151: *
152: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidBalanceType
153: */
154: public void testIsValidBalanceType_Null() {
155: testIsValidBalanceType(null, false);
156: }
157:
158: /**
159: * test the <code>isValidBalanceType()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
160: *
161: * @param btStr
162: * @param expected
163: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidBalanceType
164: */
165: protected void testIsValidBalanceType(String btStr, boolean expected) {
166: BalanceTyp balanceType = null;
167:
168: if (btStr != null) {
169: balanceType = SpringContext
170: .getBean(BalanceTypService.class)
171: .getBalanceTypByCode(btStr);
172: }
173: assertGlobalErrorMapEmpty();
174: boolean result = AccountingDocumentRuleUtil.isValidBalanceType(
175: balanceType, "code");
176: if (expected) {
177: assertGlobalErrorMapEmpty();
178: }
179: assertEquals("result", expected, result);
180: }
181:
182: /**
183: * test the <code>isValidOpenAccountingPeriod()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
184: *
185: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidOpenAccountingPeriod
186: */
187: // @RelatesTo(JiraIssue.KULRNE4926)
188: public void testIsValidOpenAccountingPeriod_Open() {
189: testIsValidOpenAccountingPeriod(
190: getAnnualBalanceAccountingPeriod(), true);
191: }
192:
193: /**
194: * test the <code>isValidOpenAccountingPeriod()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
195: *
196: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidOpenAccountingPeriod
197: */
198: public void pendingTestIsValidOpenAccountingPeriod_Closed() {
199: testIsValidOpenAccountingPeriod(getClosedAccountingPeriod(),
200: false);
201: }
202:
203: /**
204: * test the <code>isValidOpenAccountingPeriod()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
205: *
206: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidOpenAccountingPeriod
207: */
208: // @RelatesTo(JiraIssue.KULRNE4926)
209: public void testIsValidOpenAccountingPeriod_Null() {
210: testIsValidOpenAccountingPeriod(null, false);
211: }
212:
213: /**
214: * test the <code>isValidOpenAccountingPeriod()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
215: *
216: * @param period
217: * @param expected
218: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidOpenAccountingPeriod
219: */
220: protected void testIsValidOpenAccountingPeriod(
221: AccountingPeriod period, boolean expected) {
222: assertGlobalErrorMapEmpty();
223: boolean result = AccountingDocumentRuleUtil
224: .isValidOpenAccountingPeriod(period,
225: JournalVoucherDocument.class,
226: KFSPropertyConstants.ACCOUNTING_PERIOD,
227: DOES_NOT_MATTER);
228: if (expected) {
229: assertGlobalErrorMapEmpty();
230: }
231: assertEquals("result", expected, result);
232: }
233:
234: /**
235: * test the <code>isValidReversalDate()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
236: *
237: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidReversalDate
238: */
239: public void testIsValidReversalDate_Null() {
240: testIsValidReversalDate(null, true);
241: }
242:
243: /**
244: * test the <code>isValidReversalDate()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
245: *
246: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidReversalDate
247: */
248: public void testIsValidReversalDate_Past() {
249: testIsValidReversalDate(getSqlDateYesterday(), false);
250: }
251:
252: /**
253: * test the <code>isValidReversalDate()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
254: *
255: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidReversalDate
256: */
257: public void testIsValidReversalDate_Future() {
258: testIsValidReversalDate(getSqlDateTomorrow(), true);
259: }
260:
261: public void testIsValidReversalDate_Today() {
262: testIsValidReversalDate(getSqlDateToday(), true);
263: }
264:
265: /**
266: * test the <code>isValidReversalDate()</code> method of <code>{@link TransactionalDocumentRuleUtil}</code>
267: *
268: * @param reversalDate
269: * @param expected
270: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleUtil#isValidReversalDate
271: */
272: protected void testIsValidReversalDate(java.sql.Date reversalDate,
273: boolean expected) {
274: assertGlobalErrorMapEmpty();
275: boolean result = AccountingDocumentRuleUtil
276: .isValidReversalDate(reversalDate,
277: getErrorPropertyName());
278: if (expected) {
279: assertGlobalErrorMapEmpty();
280: }
281: assertEquals("result", expected, result);
282: }
283:
284: // /////////////////////////////////////////////////////////////////////////
285: // Test Methods End Here //
286: // /////////////////////////////////////////////////////////////////////////
287: }
|