Source Code Cross Referenced for AuxiliaryVoucherDocumentRuleTest.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » financial » rules » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » org.kuali.module.financial.rules 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.kfs.KFSConstants.GL_CREDIT_CODE;
019:        import static org.kuali.kfs.KFSConstants.GL_DEBIT_CODE;
020:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLineRule_IsObjectCodeAllowed;
021:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLineRule_IsObjectTypeAllowed;
022:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLineRule_ProcessAddAccountingLineBusinessRules;
023:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLine_IsObjectSubTypeAllowed;
024:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testGenerateGeneralLedgerPendingEntriesRule_ProcessGenerateGeneralLedgerPendingEntries;
025:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testRouteDocumentRule_processRouteDocument;
026:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testSaveDocumentRule_ProcessSaveDocument;
027:        import static org.kuali.test.fixtures.AccountingLineFixture.ACCRUED_INCOME_LINE;
028:        import static org.kuali.test.fixtures.AccountingLineFixture.ACCRUED_SICK_PAY_LINE;
029:        import static org.kuali.test.fixtures.AccountingLineFixture.EXPENSE_GEC_LINE;
030:        import static org.kuali.test.fixtures.AccountingLineFixture.EXPENSE_LINE;
031:        import static org.kuali.test.fixtures.AccountingLineFixture.FUND_BALANCE_LINE;
032:        import static org.kuali.test.fixtures.AccountingLineFixture.LINE15;
033:        import static org.kuali.test.fixtures.AccountingLineFixture.LINE8;
034:        import static org.kuali.test.fixtures.GeneralLedgerPendingEntryFixture.EXPECTED_AV_EXPLICIT_SOURCE_PENDING_ENTRY;
035:        import static org.kuali.test.fixtures.GeneralLedgerPendingEntryFixture.EXPECTED_AV_EXPLICIT_SOURCE_PENDING_ENTRY_FOR_EXPENSE;
036:        import static org.kuali.test.fixtures.GeneralLedgerPendingEntryFixture.EXPECTED_AV_EXPLICIT_TARGET_PENDING_ENTRY;
037:        import static org.kuali.test.fixtures.GeneralLedgerPendingEntryFixture.EXPECTED_AV_EXPLICIT_TARGET_PENDING_ENTRY_FOR_EXPENSE;
038:        import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
039:
040:        import java.util.ArrayList;
041:        import java.util.List;
042:
043:        import org.kuali.core.service.DataDictionaryService;
044:        import org.kuali.core.service.DocumentService;
045:        import org.kuali.core.service.DocumentTypeService;
046:        import org.kuali.kfs.KFSConstants;
047:        import org.kuali.kfs.bo.AccountingLine;
048:        import org.kuali.kfs.bo.SourceAccountingLine;
049:        import org.kuali.kfs.bo.TargetAccountingLine;
050:        import org.kuali.kfs.context.KualiTestBase;
051:        import org.kuali.kfs.context.SpringContext;
052:        import org.kuali.kfs.document.AccountingDocument;
053:        import org.kuali.module.chart.bo.AccountingPeriod;
054:        import org.kuali.module.chart.service.AccountingPeriodService;
055:        import org.kuali.module.financial.document.AuxiliaryVoucherDocument;
056:        import org.kuali.test.ConfigureContext;
057:        import org.kuali.test.DocumentTestUtils;
058:        import org.kuali.test.fixtures.AccountingLineFixture;
059:
060:        @ConfigureContext(session=KHUNTLEY)
061:        public class AuxiliaryVoucherDocumentRuleTest extends KualiTestBase {
062:
063:            public static final Class<AuxiliaryVoucherDocument> DOCUMENT_CLASS = AuxiliaryVoucherDocument.class;
064:
065:            public void testIsDebit_debitCode() throws Exception {
066:                AccountingDocument accountingDocument = IsDebitTestUtils
067:                        .getDocument(SpringContext
068:                                .getBean(DocumentService.class),
069:                                AuxiliaryVoucherDocument.class);
070:                AccountingLine accountingLine = (AccountingLine) accountingDocument
071:                        .getSourceAccountingLineClass().newInstance();
072:                accountingLine.setDebitCreditCode(GL_DEBIT_CODE);
073:
074:                assertTrue(IsDebitTestUtils.isDebit(SpringContext
075:                        .getBean(DocumentTypeService.class), SpringContext
076:                        .getBean(DataDictionaryService.class),
077:                        accountingDocument, accountingLine));
078:            }
079:
080:            public void testIsDebit_creditCode() throws Exception {
081:                AccountingDocument accountingDocument = IsDebitTestUtils
082:                        .getDocument(SpringContext
083:                                .getBean(DocumentService.class),
084:                                AuxiliaryVoucherDocument.class);
085:                AccountingLine accountingLine = (AccountingLine) accountingDocument
086:                        .getSourceAccountingLineClass().newInstance();
087:                accountingLine.setDebitCreditCode(GL_CREDIT_CODE);
088:
089:                assertFalse(IsDebitTestUtils.isDebit(SpringContext
090:                        .getBean(DocumentTypeService.class), SpringContext
091:                        .getBean(DataDictionaryService.class),
092:                        accountingDocument, accountingLine));
093:            }
094:
095:            public void testIsDebit_blankValue() throws Exception {
096:                AccountingDocument accountingDocument = IsDebitTestUtils
097:                        .getDocument(SpringContext
098:                                .getBean(DocumentService.class),
099:                                AuxiliaryVoucherDocument.class);
100:                AccountingLine accountingLine = (AccountingLine) accountingDocument
101:                        .getSourceAccountingLineClass().newInstance();
102:                accountingLine.setDebitCreditCode(" ");
103:
104:                assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
105:                        SpringContext.getBean(DocumentTypeService.class),
106:                        SpringContext.getBean(DataDictionaryService.class),
107:                        accountingDocument, accountingLine));
108:            }
109:
110:            public void testIsDebit_errorCorrection_debitCode()
111:                    throws Exception {
112:                AccountingDocument accountingDocument = IsDebitTestUtils
113:                        .getErrorCorrectionDocument(SpringContext
114:                                .getBean(DocumentService.class),
115:                                AuxiliaryVoucherDocument.class);
116:                AccountingLine accountingLine = (AccountingLine) accountingDocument
117:                        .getSourceAccountingLineClass().newInstance();
118:                accountingLine.setDebitCreditCode(GL_DEBIT_CODE);
119:
120:                assertTrue(IsDebitTestUtils.isDebit(SpringContext
121:                        .getBean(DocumentTypeService.class), SpringContext
122:                        .getBean(DataDictionaryService.class),
123:                        accountingDocument, accountingLine));
124:            }
125:
126:            public void testIsDebit_errorCorrection_creditCode()
127:                    throws Exception {
128:                AccountingDocument accountingDocument = IsDebitTestUtils
129:                        .getErrorCorrectionDocument(SpringContext
130:                                .getBean(DocumentService.class),
131:                                AuxiliaryVoucherDocument.class);
132:                AccountingLine accountingLine = (AccountingLine) accountingDocument
133:                        .getSourceAccountingLineClass().newInstance();
134:                accountingLine.setDebitCreditCode(GL_CREDIT_CODE);
135:
136:                assertFalse(IsDebitTestUtils.isDebit(SpringContext
137:                        .getBean(DocumentTypeService.class), SpringContext
138:                        .getBean(DataDictionaryService.class),
139:                        accountingDocument, accountingLine));
140:            }
141:
142:            public void testIsDebit_errorCorrection_blankValue()
143:                    throws Exception {
144:                AccountingDocument accountingDocument = IsDebitTestUtils
145:                        .getErrorCorrectionDocument(SpringContext
146:                                .getBean(DocumentService.class),
147:                                AuxiliaryVoucherDocument.class);
148:                AccountingLine accountingLine = (AccountingLine) accountingDocument
149:                        .getSourceAccountingLineClass().newInstance();
150:                accountingLine.setDebitCreditCode(" ");
151:
152:                assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
153:                        SpringContext.getBean(DocumentTypeService.class),
154:                        SpringContext.getBean(DataDictionaryService.class),
155:                        accountingDocument, accountingLine));
156:            }
157:
158:            public void testIsObjectTypeAllowed_InvalidObjectType()
159:                    throws Exception {
160:                testAddAccountingLineRule_IsObjectTypeAllowed(DOCUMENT_CLASS,
161:                        getInvalidObjectTypeSourceLine(), false);
162:            }
163:
164:            public void testIsObjectTypeAllowed_Valid() throws Exception {
165:                testAddAccountingLineRule_IsObjectTypeAllowed(DOCUMENT_CLASS,
166:                        getValidObjectTypeSourceLine(), true);
167:            }
168:
169:            public void testIsObjectCodeAllowed_Valid() throws Exception {
170:                testAddAccountingLineRule_IsObjectCodeAllowed(DOCUMENT_CLASS,
171:                        getValidObjectCodeSourceLine(), true);
172:            }
173:
174:            public void testAddAccountingLine_InvalidObjectSubType()
175:                    throws Exception {
176:                AccountingDocument doc = createDocumentWithInvalidObjectSubType();
177:                testAddAccountingLineRule_ProcessAddAccountingLineBusinessRules(
178:                        doc, false);
179:            }
180:
181:            public void testAddAccountingLine_Valid() throws Exception {
182:                AccountingDocument doc = createDocumentWithValidObjectSubType();
183:                testAddAccountingLineRule_ProcessAddAccountingLineBusinessRules(
184:                        doc, true);
185:            }
186:
187:            public void testIsObjectSubTypeAllowed_InvalidSubType()
188:                    throws Exception {
189:                testAddAccountingLine_IsObjectSubTypeAllowed(DOCUMENT_CLASS,
190:                        AccountingLineFixture.LINE17
191:                                .createSourceAccountingLine(), false);
192:            }
193:
194:            public void testIsObjectSubTypeAllowed_ValidSubType()
195:                    throws Exception {
196:                testAddAccountingLine_IsObjectSubTypeAllowed(DOCUMENT_CLASS,
197:                        getValidObjectSubTypeTargetLine(), true);
198:            }
199:
200:            public void testProcessSaveDocument_Valid() throws Exception {
201:                testSaveDocumentRule_ProcessSaveDocument(createDocument(), true);
202:            }
203:
204:            public void testProcessSaveDocument_Invalid() throws Exception {
205:                testSaveDocumentRule_ProcessSaveDocument(
206:                        createDocumentInvalidForSave(), false);
207:            }
208:
209:            public void testProcessSaveDocument_Invalid1() throws Exception {
210:                try {
211:                    testSaveDocumentRule_ProcessSaveDocument(null, false);
212:                    fail("validated null doc");
213:                } catch (Exception e) {
214:                    assertTrue(true);
215:                }
216:            }
217:
218:            public void testProcessRouteDocument_Valid() throws Exception {
219:                testRouteDocumentRule_processRouteDocument(
220:                        createDocumentValidForRouting(), true);
221:            }
222:
223:            public void testProcessRouteDocument_Invalid() throws Exception {
224:                testRouteDocumentRule_processRouteDocument(createDocument(),
225:                        false);
226:            }
227:
228:            public void testProcessRouteDocument_NoAccountingLines()
229:                    throws Exception {
230:                testRouteDocumentRule_processRouteDocument(createDocument(),
231:                        false);
232:            }
233:
234:            public void testProcessRouteDocument_Unbalanced() throws Exception {
235:                testRouteDocumentRule_processRouteDocument(
236:                        createDocumentUnbalanced(), false);
237:            }
238:
239:            public void testProcessGenerateGeneralLedgerPendingEntries_validTargetExpense()
240:                    throws Exception {
241:                testGenerateGeneralLedgerPendingEntriesRule_ProcessGenerateGeneralLedgerPendingEntries(
242:                        createDocument(), getExpenseTargetLine(),
243:                        EXPECTED_AV_EXPLICIT_TARGET_PENDING_ENTRY_FOR_EXPENSE,
244:                        null);
245:            }
246:
247:            public void testProcessGenerateGeneralLedgerPendingEntries_validSourceExpense()
248:                    throws Exception {
249:
250:                testGenerateGeneralLedgerPendingEntriesRule_ProcessGenerateGeneralLedgerPendingEntries(
251:                        createDocument(), getExpenseSourceLine(),
252:                        EXPECTED_AV_EXPLICIT_SOURCE_PENDING_ENTRY_FOR_EXPENSE,
253:                        null);
254:            }
255:
256:            public void testProcessGenerateGeneralLedgerPendingEntries_validSourceAsset()
257:                    throws Exception {
258:                testGenerateGeneralLedgerPendingEntriesRule_ProcessGenerateGeneralLedgerPendingEntries(
259:                        createDocument(), getAssetSourceLine(),
260:                        EXPECTED_AV_EXPLICIT_SOURCE_PENDING_ENTRY, null);
261:            }
262:
263:            public void testProcessGenerateGeneralLedgerPendingEntries_validTargetAsset()
264:                    throws Exception {
265:                testGenerateGeneralLedgerPendingEntriesRule_ProcessGenerateGeneralLedgerPendingEntries(
266:                        createDocument(), getAssetTargetLine(),
267:                        EXPECTED_AV_EXPLICIT_TARGET_PENDING_ENTRY, null);
268:            }
269:
270:            private AuxiliaryVoucherDocument createDocument() throws Exception {
271:                // AV document has a restriction on accounting period cannot be more than 2 periods behind current
272:                return DocumentTestUtils.createDocument(SpringContext
273:                        .getBean(DocumentService.class),
274:                        AuxiliaryVoucherDocument.class);
275:            }
276:
277:            private AuxiliaryVoucherDocument createDocumentValidForRouting()
278:                    throws Exception {
279:                return createDocumentWithValidObjectSubType();
280:            }
281:
282:            private AuxiliaryVoucherDocument createDocumentInvalidForSave()
283:                    throws Exception {
284:                return createDocumentInvalidDescription();
285:            }
286:
287:            private AuxiliaryVoucherDocument createDocumentInvalidDescription()
288:                    throws Exception {
289:                AuxiliaryVoucherDocument document = DocumentTestUtils
290:                        .createDocument(SpringContext
291:                                .getBean(DocumentService.class),
292:                                AuxiliaryVoucherDocument.class);
293:
294:                document.getDocumentHeader().setFinancialDocumentDescription(
295:                        null);
296:                return document;
297:            }
298:
299:            private AuxiliaryVoucherDocument createDocumentWithValidObjectSubType()
300:                    throws Exception {
301:                AuxiliaryVoucherDocument retval = createDocument();
302:                retval
303:                        .setSourceAccountingLines(getValidObjectSubTypeSourceLines());
304:                return retval;
305:            }
306:
307:            private SourceAccountingLine getExpenseSourceLine()
308:                    throws Exception {
309:                return EXPENSE_GEC_LINE.createAccountingLine(
310:                        SourceAccountingLine.class, KFSConstants.GL_DEBIT_CODE);
311:            }
312:
313:            private TargetAccountingLine getExpenseTargetLine()
314:                    throws Exception {
315:                return EXPENSE_LINE.createTargetAccountingLine();
316:            }
317:
318:            private TargetAccountingLine getAssetTargetLine() throws Exception {
319:                return ACCRUED_INCOME_LINE.createAccountingLine(
320:                        TargetAccountingLine.class, KFSConstants.GL_DEBIT_CODE);
321:            }
322:
323:            private TargetAccountingLine getValidObjectSubTypeTargetLine()
324:                    throws Exception {
325:                return new TargetAccountingLine();
326:            }
327:
328:            private List<SourceAccountingLine> getValidObjectSubTypeSourceLines()
329:                    throws Exception {
330:                List<SourceAccountingLine> retval = new ArrayList<SourceAccountingLine>();
331:                retval.add(LINE15
332:                        .createAccountingLine(SourceAccountingLine.class,
333:                                KFSConstants.GL_CREDIT_CODE));
334:                retval
335:                        .add(LINE15.createAccountingLine(
336:                                SourceAccountingLine.class,
337:                                KFSConstants.GL_DEBIT_CODE));
338:                return retval;
339:            }
340:
341:            private List<SourceAccountingLine> getInvalidObjectSubTypeSourceLines()
342:                    throws Exception {
343:                List<SourceAccountingLine> retval = new ArrayList<SourceAccountingLine>();
344:                retval.add(getAccruedSickPaySourceLineParameter());
345:                retval.add(getAccruedSickPaySourceLineParameter());
346:                return retval;
347:            }
348:
349:            private SourceAccountingLine getValidObjectTypeSourceLine()
350:                    throws Exception {
351:                return LINE8.createSourceAccountingLine();
352:            }
353:
354:            private SourceAccountingLine getInvalidObjectTypeSourceLine()
355:                    throws Exception {
356:                return FUND_BALANCE_LINE.createSourceAccountingLine();
357:            }
358:
359:            private SourceAccountingLine getValidObjectCodeSourceLine()
360:                    throws Exception {
361:                return getAccruedIncomeSourceLineParameter();
362:            }
363:
364:            private SourceAccountingLine getAssetSourceLine() throws Exception {
365:                return getAccruedIncomeSourceLineParameter();
366:            }
367:
368:            private AuxiliaryVoucherDocument createDocumentWithInvalidObjectSubType()
369:                    throws Exception {
370:                AuxiliaryVoucherDocument retval = createDocument();
371:                retval
372:                        .setSourceAccountingLines(getInvalidObjectSubTypeSourceLines());
373:                return retval;
374:            }
375:
376:            private AuxiliaryVoucherDocument createDocumentUnbalanced()
377:                    throws Exception {
378:                AuxiliaryVoucherDocument retval = createDocument();
379:                retval
380:                        .setSourceAccountingLines(getInvalidObjectSubTypeSourceLines());
381:                return retval;
382:            }
383:
384:            private SourceAccountingLine getAccruedIncomeSourceLineParameter()
385:                    throws Exception {
386:                return ACCRUED_INCOME_LINE.createAccountingLine(
387:                        SourceAccountingLine.class, KFSConstants.GL_DEBIT_CODE);
388:            }
389:
390:            private SourceAccountingLine getAccruedSickPaySourceLineParameter()
391:                    throws Exception {
392:                return ACCRUED_SICK_PAY_LINE.createAccountingLine(
393:                        SourceAccountingLine.class, KFSConstants.GL_DEBIT_CODE);
394:            }
395:
396:            /**
397:             * This tests that the rules are calculating if dates are within accounting period grace periods correctly.
398:             */
399:            public void testWithinGracePeriod() {
400:                AccountingPeriod firstPeriod = SpringContext.getBean(
401:                        AccountingPeriodService.class).getByPeriod("10",
402:                        new Integer(2007));
403:                java.util.Calendar firstPeriodInside = new java.util.GregorianCalendar(
404:                        2007, java.util.Calendar.MAY, 8);
405:                java.util.Calendar firstPeriodOutside = new java.util.GregorianCalendar(
406:                        2007, java.util.Calendar.MAY, 23);
407:                assertTrue(AuxiliaryVoucherDocumentRule
408:                        .calculateIfWithinGracePeriod(new java.sql.Date(
409:                                firstPeriodInside.getTimeInMillis()),
410:                                firstPeriod));
411:                assertFalse(AuxiliaryVoucherDocumentRule
412:                        .calculateIfWithinGracePeriod(new java.sql.Date(
413:                                firstPeriodOutside.getTimeInMillis()),
414:                                firstPeriod));
415:
416:                AccountingPeriod secondPeriod = SpringContext.getBean(
417:                        AccountingPeriodService.class).getByPeriod("13",
418:                        new Integer(2006));
419:                java.util.Calendar secondPeriodInside = new java.util.GregorianCalendar(
420:                        2006, java.util.Calendar.JULY, 20);
421:                java.util.Calendar secondPeriodOutside = new java.util.GregorianCalendar(
422:                        2007, java.util.Calendar.JULY, 21);
423:                assertTrue(AuxiliaryVoucherDocumentRule
424:                        .calculateIfWithinGracePeriod(new java.sql.Date(
425:                                secondPeriodInside.getTimeInMillis()),
426:                                secondPeriod));
427:                assertFalse(AuxiliaryVoucherDocumentRule
428:                        .calculateIfWithinGracePeriod(new java.sql.Date(
429:                                secondPeriodOutside.getTimeInMillis()),
430:                                secondPeriod));
431:
432:            }
433:
434:            /**
435:             * This tests that comparable dates are being calculated correctly.
436:             */
437:            public void testComparableDateForm() {
438:                java.util.Calendar firstDate = new java.util.GregorianCalendar(
439:                        2007, java.util.Calendar.MAY, 8);
440:                assertEquals(new Integer(AuxiliaryVoucherDocumentRule
441:                        .comparableDateForm(new java.sql.Date(firstDate
442:                                .getTimeInMillis()))), new Integer(732683));
443:
444:                java.util.Calendar secondDate = new java.util.GregorianCalendar(
445:                        1776, java.util.Calendar.JULY, 4);
446:                assertEquals(new Integer(AuxiliaryVoucherDocumentRule
447:                        .comparableDateForm(new java.sql.Date(secondDate
448:                                .getTimeInMillis()))), new Integer(648426));
449:
450:                java.util.Calendar thirdDate = new java.util.GregorianCalendar(
451:                        2007, java.util.Calendar.MAY, 7);
452:                assertEquals(new Integer(AuxiliaryVoucherDocumentRule
453:                        .comparableDateForm(new java.sql.Date(thirdDate
454:                                .getTimeInMillis()))), new Integer(732682));
455:            }
456:
457:            /**
458:             * This tests that the first day of months are being correctly calculated.
459:             */
460:            public void testCalculateFirstDayOfMonth() {
461:                java.util.Calendar cal = new java.util.GregorianCalendar();
462:
463:                cal.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
464:                cal.set(java.util.Calendar.DAY_OF_MONTH, 15);
465:                doFirstDayOfMonthTest(cal);
466:
467:                cal.set(java.util.Calendar.DAY_OF_MONTH, 30);
468:                doFirstDayOfMonthTest(cal);
469:
470:                cal.set(java.util.Calendar.DAY_OF_MONTH, 1);
471:                doFirstDayOfMonthTest(cal);
472:
473:                cal.set(java.util.Calendar.MONTH, java.util.Calendar.MARCH);
474:                cal.set(java.util.Calendar.DAY_OF_MONTH, 31);
475:                doFirstDayOfMonthTest(cal);
476:            }
477:
478:            /**
479:             * This method tests if the given calendar date is the first day of the month, after the rule converts it.
480:             * 
481:             * @param cal the calendar to check
482:             */
483:            private void doFirstDayOfMonthTest(java.util.Calendar cal) {
484:                java.sql.Date firstOfMonth = AuxiliaryVoucherDocumentRule
485:                        .calculateFirstDayOfMonth(new java.sql.Date(cal
486:                                .getTimeInMillis()));
487:                java.util.Calendar testCal = new java.util.GregorianCalendar();
488:                testCal.setTime(firstOfMonth);
489:                assertEquals(new Integer(1), new Integer(testCal
490:                        .get(java.util.Calendar.DAY_OF_MONTH)));
491:            }
492:
493:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.