Source Code Cross Referenced for JournalVoucherDocumentRuleTest.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.getBusinessRule;
021:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLineRule_IsObjectCodeAllowed;
022:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLineRule_IsObjectTypeAllowed;
023:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLineRule_ProcessAddAccountingLineBusinessRules;
024:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLine_IsObjectSubTypeAllowed;
025:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testGenerateGeneralLedgerPendingEntriesRule_ProcessGenerateGeneralLedgerPendingEntries;
026:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testRouteDocumentRule_processRouteDocument;
027:        import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testSaveDocumentRule_ProcessSaveDocument;
028:        import static org.kuali.test.fixtures.AccountingLineFixture.EXPENSE_LINE;
029:        import static org.kuali.test.fixtures.AccountingLineFixture.EXPENSE_LINE2;
030:        import static org.kuali.test.fixtures.AccountingLineFixture.EXTERNAL_ENCUMBRANCE_LINE;
031:        import static org.kuali.test.fixtures.AccountingLineFixture.LINE11;
032:        import static org.kuali.test.fixtures.AccountingLineFixture.LINE8;
033:        import static org.kuali.test.fixtures.AccountingLineFixture.LINE9;
034:        import static org.kuali.test.fixtures.AccountingLineFixture.SOURCE_LINE;
035:        import static org.kuali.test.fixtures.GeneralLedgerPendingEntryFixture.EXPECTED_JV_EXPLICIT_SOURCE_PENDING_ENTRY;
036:        import static org.kuali.test.fixtures.GeneralLedgerPendingEntryFixture.EXPECTED_JV_EXPLICIT_SOURCE_PENDING_ENTRY_FOR_EXPENSE;
037:        import static org.kuali.test.fixtures.UserNameFixture.DFOGLE;
038:        import static org.kuali.test.util.KualiTestAssertionUtils.assertGlobalErrorMapContains;
039:        import static org.kuali.test.util.KualiTestAssertionUtils.assertGlobalErrorMapEmpty;
040:        import static org.kuali.test.util.KualiTestAssertionUtils.assertGlobalErrorMapNotContains;
041:        import static org.kuali.test.util.KualiTestAssertionUtils.assertGlobalErrorMapSize;
042:
043:        import java.util.ArrayList;
044:        import java.util.List;
045:
046:        import org.kuali.core.service.DataDictionaryService;
047:        import org.kuali.core.service.DocumentService;
048:        import org.kuali.core.service.DocumentTypeService;
049:        import org.kuali.kfs.KFSConstants;
050:        import org.kuali.kfs.KFSKeyConstants;
051:        import org.kuali.kfs.KFSPropertyConstants;
052:        import org.kuali.kfs.bo.AccountingLine;
053:        import org.kuali.kfs.bo.SourceAccountingLine;
054:        import org.kuali.kfs.bo.TargetAccountingLine;
055:        import org.kuali.kfs.context.KualiTestBase;
056:        import org.kuali.kfs.context.SpringContext;
057:        import org.kuali.kfs.document.AccountingDocument;
058:        import org.kuali.kfs.rule.AddAccountingLineRule;
059:        import org.kuali.module.financial.document.JournalVoucherDocument;
060:        import org.kuali.test.ConfigureContext;
061:        import org.kuali.test.DocumentTestUtils;
062:
063:        @ConfigureContext(session=DFOGLE)
064:        public class JournalVoucherDocumentRuleTest extends KualiTestBase {
065:
066:            public static final Class<JournalVoucherDocument> DOCUMENT_CLASS = JournalVoucherDocument.class;
067:
068:            public void testProcessAddAccountingLineBusinessRules_irrelevantReferenceOriginCode()
069:                    throws Exception {
070:                testProcessAddAccountingLineBusinessRules(EXPENSE_LINE2
071:                        .createSourceAccountingLine(), null, null);
072:            }
073:
074:            public void testProcessAddAccountingLineBusinessRules_emptyReferenceOriginCode()
075:                    throws Exception {
076:                AccountingLine line = EXTERNAL_ENCUMBRANCE_LINE
077:                        .createSourceAccountingLine();
078:                line.setReferenceOriginCode("");
079:                testProcessAddAccountingLineBusinessRules(line,
080:                        KFSPropertyConstants.REFERENCE_ORIGIN_CODE,
081:                        KFSKeyConstants.ERROR_REQUIRED);
082:            }
083:
084:            public void testProcessAddAccountingLineBusinessRules_emptyReferences()
085:                    throws Exception {
086:                AccountingLine line = EXTERNAL_ENCUMBRANCE_LINE
087:                        .createSourceAccountingLine();
088:                line.setReferenceOriginCode("");
089:                line.setReferenceNumber("");
090:                line.setReferenceTypeCode("");
091:                testProcessAddAccountingLineBusinessRules(line,
092:                        KFSPropertyConstants.REFERENCE_ORIGIN_CODE,
093:                        KFSKeyConstants.ERROR_REQUIRED);
094:                assertGlobalErrorMapContains(
095:                        KFSPropertyConstants.REFERENCE_NUMBER,
096:                        KFSKeyConstants.ERROR_REQUIRED);
097:                assertGlobalErrorMapContains(
098:                        KFSPropertyConstants.REFERENCE_TYPE_CODE,
099:                        KFSKeyConstants.ERROR_REQUIRED);
100:            }
101:
102:            public void testProcessAddAccountingLineBusinessRules_validReferences()
103:                    throws Exception {
104:                testProcessAddAccountingLineBusinessRules(
105:                        EXTERNAL_ENCUMBRANCE_LINE.createSourceAccountingLine(),
106:                        null, null);
107:            }
108:
109:            public void testProcessAddAccountingLineBusinessRules_invalidReferenceOriginCode()
110:                    throws Exception {
111:                AccountingLine line = EXTERNAL_ENCUMBRANCE_LINE
112:                        .createSourceAccountingLine();
113:                line.setReferenceOriginCode("42");
114:                testProcessAddAccountingLineBusinessRules(line,
115:                        KFSPropertyConstants.REFERENCE_ORIGIN_CODE,
116:                        KFSKeyConstants.ERROR_EXISTENCE);
117:            }
118:
119:            public void testProcessAddAccountingLineBusinessRules_invalidReferenceTypeCode()
120:                    throws Exception {
121:                AccountingLine line = EXTERNAL_ENCUMBRANCE_LINE
122:                        .createSourceAccountingLine();
123:                line.setReferenceTypeCode("42");
124:                testProcessAddAccountingLineBusinessRules(line,
125:                        KFSPropertyConstants.REFERENCE_TYPE_CODE,
126:                        KFSKeyConstants.ERROR_EXISTENCE);
127:                assertGlobalErrorMapNotContains(line.toString(),
128:                        KFSPropertyConstants.REFERENCE_TYPE_CODE,
129:                        KFSKeyConstants.ERROR_REQUIRED);
130:                assertGlobalErrorMapSize(line.toString(), 1);
131:            }
132:
133:            private void testProcessAddAccountingLineBusinessRules(
134:                    AccountingLine line, String expectedErrorFieldName,
135:                    String expectedErrorKey) throws Exception {
136:                line.refresh();
137:                assertGlobalErrorMapEmpty();
138:                boolean wasValid = getBusinessRule(DOCUMENT_CLASS,
139:                        AddAccountingLineRule.class)
140:                        .processAddAccountingLineBusinessRules(
141:                                createDocumentUnbalanced(), line);
142:                if (expectedErrorFieldName == null) {
143:                    assertGlobalErrorMapEmpty(line.toString()); // fail printing error map for debugging before failing on simple result
144:                    assertEquals("wasValid " + line, true, wasValid);
145:                } else {
146:                    assertGlobalErrorMapContains(line.toString(),
147:                            expectedErrorFieldName, expectedErrorKey);
148:                    assertEquals("wasValid " + line, false, wasValid);
149:                }
150:            }
151:
152:            public void testIsDebit_debitCode() throws Exception {
153:                AccountingDocument accountingDocument = IsDebitTestUtils
154:                        .getDocument(SpringContext
155:                                .getBean(DocumentService.class),
156:                                JournalVoucherDocument.class);
157:                AccountingLine accountingLine = (AccountingLine) accountingDocument
158:                        .getSourceAccountingLineClass().newInstance();
159:                accountingLine.setDebitCreditCode(GL_DEBIT_CODE);
160:
161:                assertTrue(IsDebitTestUtils.isDebit(SpringContext
162:                        .getBean(DocumentTypeService.class), SpringContext
163:                        .getBean(DataDictionaryService.class),
164:                        accountingDocument, accountingLine));
165:            }
166:
167:            public void testIsDebit_creditCode() throws Exception {
168:                AccountingDocument accountingDocument = IsDebitTestUtils
169:                        .getDocument(SpringContext
170:                                .getBean(DocumentService.class),
171:                                JournalVoucherDocument.class);
172:                AccountingLine accountingLine = (AccountingLine) accountingDocument
173:                        .getSourceAccountingLineClass().newInstance();
174:                accountingLine.setDebitCreditCode(GL_CREDIT_CODE);
175:
176:                assertFalse(IsDebitTestUtils.isDebit(SpringContext
177:                        .getBean(DocumentTypeService.class), SpringContext
178:                        .getBean(DataDictionaryService.class),
179:                        accountingDocument, accountingLine));
180:            }
181:
182:            public void testIsDebit_blankValue() throws Exception {
183:                AccountingDocument accountingDocument = IsDebitTestUtils
184:                        .getDocument(SpringContext
185:                                .getBean(DocumentService.class),
186:                                JournalVoucherDocument.class);
187:                AccountingLine accountingLine = (AccountingLine) accountingDocument
188:                        .getSourceAccountingLineClass().newInstance();
189:                accountingLine.setDebitCreditCode(" ");
190:
191:                assertTrue(IsDebitTestUtils.isDebit(SpringContext
192:                        .getBean(DocumentTypeService.class), SpringContext
193:                        .getBean(DataDictionaryService.class),
194:                        accountingDocument, accountingLine));
195:
196:            }
197:
198:            public void testIsDebit_errorCorrection_crediCode()
199:                    throws Exception {
200:                AccountingDocument accountingDocument = IsDebitTestUtils
201:                        .getErrorCorrectionDocument(SpringContext
202:                                .getBean(DocumentService.class),
203:                                JournalVoucherDocument.class);
204:                AccountingLine accountingLine = (AccountingLine) accountingDocument
205:                        .getSourceAccountingLineClass().newInstance();
206:                accountingLine.setDebitCreditCode(GL_CREDIT_CODE);
207:
208:                assertFalse(IsDebitTestUtils.isDebit(SpringContext
209:                        .getBean(DocumentTypeService.class), SpringContext
210:                        .getBean(DataDictionaryService.class),
211:                        accountingDocument, accountingLine));
212:            }
213:
214:            public void testIsDebit_errorCorrection_debitCode()
215:                    throws Exception {
216:                AccountingDocument accountingDocument = IsDebitTestUtils
217:                        .getErrorCorrectionDocument(SpringContext
218:                                .getBean(DocumentService.class),
219:                                JournalVoucherDocument.class);
220:                AccountingLine accountingLine = (AccountingLine) accountingDocument
221:                        .getSourceAccountingLineClass().newInstance();
222:                accountingLine.setDebitCreditCode(GL_DEBIT_CODE);
223:
224:                assertTrue(IsDebitTestUtils.isDebit(SpringContext
225:                        .getBean(DocumentTypeService.class), SpringContext
226:                        .getBean(DataDictionaryService.class),
227:                        accountingDocument, accountingLine));
228:            }
229:
230:            public void testIsDebit_errorCorrection_blankValue()
231:                    throws Exception {
232:                AccountingDocument accountingDocument = IsDebitTestUtils
233:                        .getErrorCorrectionDocument(SpringContext
234:                                .getBean(DocumentService.class),
235:                                JournalVoucherDocument.class);
236:                AccountingLine accountingLine = (AccountingLine) accountingDocument
237:                        .getSourceAccountingLineClass().newInstance();
238:                accountingLine.setDebitCreditCode(" ");
239:
240:                assertTrue(IsDebitTestUtils.isDebit(SpringContext
241:                        .getBean(DocumentTypeService.class), SpringContext
242:                        .getBean(DataDictionaryService.class),
243:                        accountingDocument, accountingLine));
244:
245:            }
246:
247:            public void testIsObjectTypeAllowed_InvalidObjectType()
248:                    throws Exception {
249:                testAddAccountingLineRule_IsObjectTypeAllowed(DOCUMENT_CLASS,
250:                        getInvalidObjectTypeSourceLine(), false);
251:            }
252:
253:            public void testIsObjectTypeAllowed_Valid() throws Exception {
254:                testAddAccountingLineRule_IsObjectTypeAllowed(DOCUMENT_CLASS,
255:                        getValidObjectTypeSourceLine(), true);
256:            }
257:
258:            public void testIsObjectCodeAllowed_Valid() throws Exception {
259:                testAddAccountingLineRule_IsObjectCodeAllowed(DOCUMENT_CLASS,
260:                        getValidObjectCodeSourceLine(), true);
261:            }
262:
263:            public void testAddAccountingLine_Valid() throws Exception {
264:                AccountingDocument doc = createDocumentWithValidObjectSubType();
265:                testAddAccountingLineRule_ProcessAddAccountingLineBusinessRules(
266:                        doc, true);
267:            }
268:
269:            public void testIsObjectSubTypeAllowed_ValidSubType()
270:                    throws Exception {
271:                testAddAccountingLine_IsObjectSubTypeAllowed(DOCUMENT_CLASS,
272:                        getValidObjectSubTypeTargetLine(), true);
273:            }
274:
275:            // @RelatesTo(JiraIssue.KULRNE4926)
276:            public void testProcessSaveDocument_Valid() throws Exception {
277:                testSaveDocumentRule_ProcessSaveDocument(buildDocument(), true);
278:            }
279:
280:            public void testProcessSaveDocument_Invalid() throws Exception {
281:                testSaveDocumentRule_ProcessSaveDocument(
282:                        createDocumentInvalidForSave(), false);
283:            }
284:
285:            public void testProcessSaveDocument_Invalid1() throws Exception {
286:                try {
287:                    testSaveDocumentRule_ProcessSaveDocument(null, false);
288:                    fail("validated null doc");
289:                } catch (Exception e) {
290:                    assertTrue(true);
291:                }
292:            }
293:
294:            public void testProcessRouteDocument_Valid() throws Exception {
295:                testRouteDocumentRule_processRouteDocument(
296:                        createDocumentValidForRouting(), true);
297:            }
298:
299:            public void testProcessRouteDocument_Invalid() throws Exception {
300:                testRouteDocumentRule_processRouteDocument(buildDocument(),
301:                        false);
302:            }
303:
304:            public void testProcessRouteDocument_NoAccountingLines()
305:                    throws Exception {
306:                testRouteDocumentRule_processRouteDocument(buildDocument(),
307:                        false);
308:            }
309:
310:            public void testProcessRouteDocument_Unbalanced() throws Exception {
311:                testRouteDocumentRule_processRouteDocument(
312:                        createDocumentUnbalanced(), false);
313:            }
314:
315:            public void testProcessGenerateGeneralLedgerPendingEntries_validSourceExpense()
316:                    throws Exception {
317:                testGenerateGeneralLedgerPendingEntriesRule_ProcessGenerateGeneralLedgerPendingEntries(
318:                        buildDocument(), EXPENSE_LINE
319:                                .createSourceAccountingLine(),
320:                        EXPECTED_JV_EXPLICIT_SOURCE_PENDING_ENTRY_FOR_EXPENSE,
321:                        null);
322:            }
323:
324:            public void testProcessGenerateGeneralLedgerPendingEntries_validSourceAsset()
325:                    throws Exception {
326:                testGenerateGeneralLedgerPendingEntriesRule_ProcessGenerateGeneralLedgerPendingEntries(
327:                        buildDocument(), getAssetSourceLine(),
328:                        EXPECTED_JV_EXPLICIT_SOURCE_PENDING_ENTRY, null);
329:            }
330:
331:            private JournalVoucherDocument createDocumentValidForRouting()
332:                    throws Exception {
333:                return createDocumentWithValidObjectSubType();
334:            }
335:
336:            private JournalVoucherDocument createDocumentInvalidForSave()
337:                    throws Exception {
338:                return createDocumentInvalidDescription();
339:            }
340:
341:            private JournalVoucherDocument buildDocument() throws Exception {
342:                JournalVoucherDocument retval = DocumentTestUtils
343:                        .createDocument(SpringContext
344:                                .getBean(DocumentService.class),
345:                                JournalVoucherDocument.class);
346:                retval.setBalanceTypeCode(KFSConstants.BALANCE_TYPE_ACTUAL);
347:                return retval;
348:            }
349:
350:            private JournalVoucherDocument createDocumentWithValidObjectSubType()
351:                    throws Exception {
352:                JournalVoucherDocument retval = buildDocument();
353:                retval
354:                        .setSourceAccountingLines(getValidObjectSubTypeSourceLines());
355:                retval
356:                        .setTargetAccountingLines(getValidObjectSubTypeTargetLines());
357:                return retval;
358:            }
359:
360:            private JournalVoucherDocument createDocumentInvalidDescription()
361:                    throws Exception {
362:                JournalVoucherDocument retval = DocumentTestUtils
363:                        .createDocument(SpringContext
364:                                .getBean(DocumentService.class),
365:                                JournalVoucherDocument.class);
366:
367:                retval.getDocumentHeader().setFinancialDocumentDescription(
368:                        new String());
369:                return retval;
370:            }
371:
372:            private TargetAccountingLine getValidObjectSubTypeTargetLine()
373:                    throws Exception {
374:                return LINE11.createTargetAccountingLine();
375:            }
376:
377:            private List<SourceAccountingLine> getValidObjectSubTypeSourceLines()
378:                    throws Exception {
379:                List<SourceAccountingLine> retval = new ArrayList<SourceAccountingLine>();
380:                retval.add(LINE11.createSourceAccountingLine());
381:                return retval;
382:            }
383:
384:            private List<TargetAccountingLine> getValidObjectSubTypeTargetLines()
385:                    throws Exception {
386:                List<TargetAccountingLine> retval = new ArrayList<TargetAccountingLine>();
387:                retval.add(LINE11.createTargetAccountingLine());
388:                retval.add(LINE11.createTargetAccountingLine());
389:                return retval;
390:            }
391:
392:            private SourceAccountingLine getValidObjectTypeSourceLine()
393:                    throws Exception {
394:                return LINE8.createSourceAccountingLine();
395:            }
396:
397:            private SourceAccountingLine getInvalidObjectTypeSourceLine()
398:                    throws Exception {
399:                SourceAccountingLine retval = LINE9
400:                        .createSourceAccountingLine();
401:                retval.setObjectTypeCode(new String());
402:                return retval;
403:            }
404:
405:            private SourceAccountingLine getValidObjectCodeSourceLine()
406:                    throws Exception {
407:                return LINE11.createSourceAccountingLine();
408:            }
409:
410:            private SourceAccountingLine getAssetSourceLine() throws Exception {
411:                return SOURCE_LINE.createSourceAccountingLine();
412:            }
413:
414:            private JournalVoucherDocument createDocumentUnbalanced()
415:                    throws Exception {
416:                return buildDocument();
417:            }
418:
419:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.