Source Code Cross Referenced for DelegateRuleTest.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » chart » 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.chart.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.chart.rules;
017:
018:        import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
019:        import static org.kuali.test.util.KualiTestAssertionUtils.assertGlobalErrorMapContains;
020:        import static org.kuali.test.util.KualiTestAssertionUtils.assertGlobalErrorMapEmpty;
021:
022:        import java.sql.Timestamp;
023:        import java.util.Calendar;
024:
025:        import org.apache.commons.lang.time.DateUtils;
026:        import org.kuali.core.document.MaintenanceDocument;
027:        import org.kuali.core.service.DateTimeService;
028:        import org.kuali.core.util.KualiDecimal;
029:        import org.kuali.kfs.KFSKeyConstants;
030:        import org.kuali.kfs.context.SpringContext;
031:        import org.kuali.module.chart.bo.Delegate;
032:        import org.kuali.test.ConfigureContext;
033:
034:        /**
035:         * This class...
036:         */
037:        @ConfigureContext(session=KHUNTLEY)
038:        public class DelegateRuleTest extends ChartRuleTestBase {
039:
040:            protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
041:                    .getLogger(DelegateRuleTest.class);
042:            private static final String ERROR_PREFIX = "document.newMaintainableObject.";
043:            private static final String CHART_GOOD_1 = "UA";
044:            private static final String ACCOUNT_GOOD_1 = "1912201";
045:            private static final String DOCTYPE_GOOD_1 = "ALL";
046:            private static final int BAD_FROM_AMT = -25;
047:            private static final int BAD_TO_AMT = -40;
048:            private static final int GOOD_FROM_AMT = 25;
049:            private static final int GOOD_TO_AMT = 25;
050:            private static final int BAD_TO_AMT_LESS_THAN = 5;
051:
052:            // delegate user's - need four
053:            // one that is good - has both A for status and P for type
054:            private static final String USERID_GOOD_1 = "1545104915";// ABARRING = BARRINGER,ALONZO E
055:
056:            // one that has something else for status and P for type
057:            private static final String USERID_BAD_1 = "2419205388"; // SROOD=ROOD,SAM N : status=D
058:
059:            // one that has A for status and something else for type
060:            private static final String USERID_BAD_2 = "1659102154"; // AAVILES=AVILES,ANTON F
061:
062:            // one that has neither A nor P for status and type
063:            private static final String USERID_BAD_3 = "4533105209"; // AIAUCOIN=AUCOIN,AMELIA I
064:
065:            // values for testing primary routing
066:            // has doctype "all" for chart BL and account 223146
067:            private static final String DOCTYPE_ALL_CHART = "BL";
068:            private static final String DOCTYPE_ALL_ACCT = "2231466";
069:
070:            // has doctype CREQ for chart BL and account 1031400
071:            private static final String DOCTYPE_SPECIFIC_CHART = "BL";
072:            private static final String DOCTYPE_SPECIFIC_ACCT = "1031400";
073:            private static final String DOCTYPE_SPECIFIC_DT_VALUE = "CREQ";
074:
075:            // this one is an available chart/account combo that should succeed for specific
076:            // choose anything but CREQ or AV for doctype
077:            private static final String DOCTYPE_OPEN_SPECIFIC_CHART = "BA";
078:            private static final String DOCTYPE_OPEN_SPECIFIC_ACCT = "9020174";
079:            private static final String DOCTYPE_OPEN_SPECFIC_DT_VALUE = "A21";
080:
081:            // this one is an available chart/account combo for doctype "all"
082:            private static final String DOCTYPE_OPEN_ALL_CHART = "UA";
083:            private static final String DOCTYPE_OPEN_ALL_ACCT = "1912201";
084:            private static final String DOCTYPE_OPEN_ALL_DT_VALUE = "ALL";
085:
086:            private static final String DOCTYPE_ALL = "ALL";
087:
088:            private Delegate newDelegate;
089:            private Delegate oldDelegate;
090:            private MaintenanceDocument maintDoc;
091:
092:            /**
093:             * This method creates a delegate with a minimal set of known-good values.
094:             * 
095:             * @return
096:             */
097:            private Delegate goodDelegate1() {
098:                Delegate delegate = new Delegate();
099:                delegate.setChartOfAccountsCode(CHART_GOOD_1);
100:                delegate.setAccountNumber(ACCOUNT_GOOD_1);
101:                delegate.setFinancialDocumentTypeCode(DOCTYPE_GOOD_1);
102:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
103:                delegate.refresh();
104:                return delegate;
105:            }
106:
107:            private Delegate goodDelegate2() {
108:                Delegate delegate = new Delegate();
109:                delegate.setChartOfAccountsCode(CHART_GOOD_1);
110:                delegate.setAccountNumber(ACCOUNT_GOOD_1);
111:                delegate.setFinancialDocumentTypeCode(DOCTYPE_GOOD_1);
112:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
113:
114:                Timestamp today = SpringContext.getBean(DateTimeService.class)
115:                        .getCurrentTimestamp();
116:                delegate.setAccountDelegateStartDate(today);
117:
118:                delegate.refresh();
119:                return delegate;
120:            }
121:
122:            private Delegate badDelegate1() {
123:                Delegate delegate = new Delegate();
124:                delegate.setChartOfAccountsCode(CHART_GOOD_1);
125:                delegate.setAccountNumber(ACCOUNT_GOOD_1);
126:                delegate.setFinancialDocumentTypeCode(DOCTYPE_GOOD_1);
127:                delegate.setAccountDelegateSystemId(USERID_BAD_1);
128:                delegate.refresh();
129:                return delegate;
130:            }
131:
132:            private Delegate badDelegate2() {
133:                Delegate delegate = new Delegate();
134:                delegate.setChartOfAccountsCode(CHART_GOOD_1);
135:                delegate.setAccountNumber(ACCOUNT_GOOD_1);
136:                delegate.setFinancialDocumentTypeCode(DOCTYPE_GOOD_1);
137:                delegate.setAccountDelegateSystemId(USERID_BAD_2);
138:                delegate.refresh();
139:                return delegate;
140:            }
141:
142:            private Delegate badDelegate3() {
143:                Delegate delegate = new Delegate();
144:                delegate.setChartOfAccountsCode(CHART_GOOD_1);
145:                delegate.setAccountNumber(ACCOUNT_GOOD_1);
146:                delegate.setFinancialDocumentTypeCode(DOCTYPE_GOOD_1);
147:                delegate.setAccountDelegateSystemId(USERID_BAD_3);
148:                delegate.refresh();
149:                return delegate;
150:            }
151:
152:            private Delegate badDelegate4() {
153:                Delegate delegate = new Delegate();
154:                delegate.setChartOfAccountsCode(CHART_GOOD_1);
155:                delegate.setAccountNumber(ACCOUNT_GOOD_1);
156:                delegate.setFinancialDocumentTypeCode(DOCTYPE_GOOD_1);
157:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
158:                delegate.setFinDocApprovalFromThisAmt(new KualiDecimal(
159:                        BAD_FROM_AMT));
160:                delegate.refresh();
161:                return delegate;
162:            }
163:
164:            private Delegate badDelegate5() {
165:                Delegate delegate = new Delegate();
166:                delegate.setChartOfAccountsCode(CHART_GOOD_1);
167:                delegate.setAccountNumber(ACCOUNT_GOOD_1);
168:                delegate.setFinancialDocumentTypeCode(DOCTYPE_GOOD_1);
169:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
170:                delegate.setFinDocApprovalToThisAmount(new KualiDecimal(
171:                        BAD_TO_AMT));
172:                delegate.refresh();
173:                return delegate;
174:            }
175:
176:            private Delegate badDelegate6() {
177:                Delegate delegate = new Delegate();
178:                delegate.setChartOfAccountsCode(CHART_GOOD_1);
179:                delegate.setAccountNumber(ACCOUNT_GOOD_1);
180:                delegate.setFinancialDocumentTypeCode(DOCTYPE_GOOD_1);
181:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
182:                delegate.setFinDocApprovalToThisAmount(new KualiDecimal(
183:                        GOOD_FROM_AMT));
184:                delegate.setFinDocApprovalToThisAmount(null);
185:                delegate.refresh();
186:                return delegate;
187:            }
188:
189:            private Delegate badDelegate7() {
190:                Delegate delegate = new Delegate();
191:                delegate.setChartOfAccountsCode(CHART_GOOD_1);
192:                delegate.setAccountNumber(ACCOUNT_GOOD_1);
193:                delegate.setFinancialDocumentTypeCode(DOCTYPE_GOOD_1);
194:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
195:                delegate.setFinDocApprovalFromThisAmt(null);
196:                delegate.setFinDocApprovalToThisAmount(new KualiDecimal(
197:                        GOOD_TO_AMT));
198:                delegate.refresh();
199:                return delegate;
200:            }
201:
202:            private Delegate badDelegate8() {
203:                Delegate delegate = new Delegate();
204:                delegate.setChartOfAccountsCode(CHART_GOOD_1);
205:                delegate.setAccountNumber(ACCOUNT_GOOD_1);
206:                delegate.setFinancialDocumentTypeCode(DOCTYPE_GOOD_1);
207:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
208:                delegate.setFinDocApprovalFromThisAmt(new KualiDecimal(
209:                        GOOD_FROM_AMT));
210:                delegate.setFinDocApprovalToThisAmount(new KualiDecimal(
211:                        BAD_TO_AMT_LESS_THAN));
212:                delegate.refresh();
213:                return delegate;
214:            }
215:
216:            @SuppressWarnings("deprecation")
217:            private Delegate delegateWithDocTypeAll() {
218:                Delegate delegate = new Delegate();
219:                delegate.setChartOfAccountsCode(DOCTYPE_ALL_CHART);
220:                delegate.setAccountNumber(DOCTYPE_ALL_ACCT);
221:                delegate.setFinancialDocumentTypeCode(DOCTYPE_ALL);
222:                delegate.setAccountsDelegatePrmrtIndicator(true);
223:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
224:                delegate.refresh();
225:                return delegate;
226:            }
227:
228:            @SuppressWarnings("deprecation")
229:            private Delegate delegateWithSpecificTypeClosedAllSpecified() {
230:                Delegate delegate = new Delegate();
231:                delegate.setChartOfAccountsCode(DOCTYPE_SPECIFIC_CHART);
232:                delegate.setAccountNumber(DOCTYPE_SPECIFIC_ACCT);
233:                delegate.setFinancialDocumentTypeCode(DOCTYPE_ALL);
234:                delegate.setAccountsDelegatePrmrtIndicator(true);
235:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
236:                delegate.refresh();
237:                return delegate;
238:            }
239:
240:            @SuppressWarnings("deprecation")
241:            private Delegate delegateWithSpecificTypeClosed() {
242:                Delegate delegate = new Delegate();
243:                delegate.setChartOfAccountsCode(DOCTYPE_SPECIFIC_CHART);
244:                delegate.setAccountNumber(DOCTYPE_SPECIFIC_ACCT);
245:                delegate
246:                        .setFinancialDocumentTypeCode(DOCTYPE_SPECIFIC_DT_VALUE);
247:                delegate.setAccountsDelegatePrmrtIndicator(true);
248:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
249:                delegate.refresh();
250:                return delegate;
251:            }
252:
253:            @SuppressWarnings("deprecation")
254:            private Delegate delegateWithAllDocTypeOpen() {
255:                Delegate delegate = new Delegate();
256:                delegate.setChartOfAccountsCode(DOCTYPE_OPEN_ALL_CHART);
257:                delegate.setAccountNumber(DOCTYPE_OPEN_ALL_ACCT);
258:                delegate
259:                        .setFinancialDocumentTypeCode(DOCTYPE_OPEN_ALL_DT_VALUE);
260:                delegate.setAccountsDelegatePrmrtIndicator(true);
261:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
262:                delegate.refresh();
263:                return delegate;
264:            }
265:
266:            @SuppressWarnings("deprecation")
267:            private Delegate delegateWithSpecificDocTypeOpen() {
268:                Delegate delegate = new Delegate();
269:                delegate.setChartOfAccountsCode(DOCTYPE_OPEN_SPECIFIC_CHART);
270:                delegate.setAccountNumber(DOCTYPE_OPEN_SPECIFIC_ACCT);
271:                delegate
272:                        .setFinancialDocumentTypeCode(DOCTYPE_OPEN_SPECFIC_DT_VALUE);
273:                delegate.setAccountsDelegatePrmrtIndicator(true);
274:                delegate.setAccountDelegateSystemId(USERID_GOOD_1);
275:                delegate.refresh();
276:                return delegate;
277:            }
278:
279:            private Timestamp newTimestamp(int year, int month, int day) {
280:
281:                Calendar calendar = Calendar.getInstance();
282:                calendar.clear();
283:                calendar.set(year, month, day);
284:                calendar = DateUtils.truncate(calendar, Calendar.DAY_OF_MONTH);
285:
286:                return new Timestamp(calendar.getTimeInMillis());
287:            }
288:
289:            /**
290:             * This method tests a Delegate that we have setup with all known good values for the required fields, and nothing or the
291:             * default for the other fields. This test should always pass, if it does not, then none of the following tests are meaningful,
292:             * as the baseline is broken.
293:             */
294:            public void testCheckSimpleRules_validDelegate() {
295:                DelegateRule rule = new DelegateRule();
296:                newDelegate = goodDelegate1();
297:                maintDoc = newMaintDoc(newDelegate);
298:
299:                rule = (DelegateRule) setupMaintDocRule(maintDoc, rule
300:                        .getClass());
301:                // now we need to setup the convenience objects so that the rule has the right
302:                // delegate values
303:                rule.setupConvenienceObjects(maintDoc);
304:
305:                // confirm that there are no errors to begin with
306:                assertGlobalErrorMapEmpty();
307:
308:                // run the business rules
309:                rule.checkSimpleRules();
310:                assertGlobalErrorMapEmpty();
311:
312:            }
313:
314:            public void testCheckSimpleRulesStartDateRule_startDateToday() {
315:                DelegateRule rule = new DelegateRule();
316:                newDelegate = goodDelegate2();
317:
318:                // new delegate with start-date same as today
319:                maintDoc = newMaintDoc(newDelegate);
320:                rule = (DelegateRule) setupMaintDocRule(maintDoc, rule
321:                        .getClass());
322:
323:                // now we need to setup the convenience objects so that the rule has the right
324:                // delegate values
325:                rule.setupConvenienceObjects(maintDoc);
326:
327:                // confirm that there are no errors to begin with
328:                assertGlobalErrorMapEmpty();
329:
330:                // run the business rules
331:                rule.checkSimpleRules();
332:                assertGlobalErrorMapEmpty();
333:
334:            }
335:
336:            public void testCheckSimpleRulesStartDateRule_startDateTomorrow() {
337:                DelegateRule rule = new DelegateRule();
338:                Calendar cal = SpringContext.getBean(DateTimeService.class)
339:                        .getCurrentCalendar();
340:                cal.add(Calendar.DATE, 1);
341:                Timestamp ts = newTimestamp(cal.get(Calendar.YEAR), cal
342:                        .get(Calendar.MONTH), cal.get(Calendar.DATE));
343:
344:                newDelegate = goodDelegate2();
345:                newDelegate.setAccountDelegateStartDate(ts);
346:
347:                // new delegate with start-date same as today
348:                maintDoc = newMaintDoc(newDelegate);
349:                rule = (DelegateRule) setupMaintDocRule(maintDoc, rule
350:                        .getClass());
351:
352:                // now we need to setup the convenience objects so that the rule has the right
353:                // delegate values
354:                rule.setupConvenienceObjects(maintDoc);
355:
356:                // confirm that there are no errors to begin with
357:                assertGlobalErrorMapEmpty();
358:
359:                // run the business rules
360:                rule.checkSimpleRules();
361:                assertGlobalErrorMapEmpty();
362:            }
363:
364:            public void testCheckSimpleRulesStartDateRule_startDateYesterday() {
365:                DelegateRule rule = new DelegateRule();
366:                Calendar cal = SpringContext.getBean(DateTimeService.class)
367:                        .getCurrentCalendar();
368:                cal.add(Calendar.DATE, -1);
369:                Timestamp ts = newTimestamp(cal.get(Calendar.YEAR), cal
370:                        .get(Calendar.MONTH), cal.get(Calendar.DATE));
371:
372:                newDelegate = goodDelegate2();
373:                newDelegate.setAccountDelegateStartDate(ts);
374:
375:                // new delegate with start-date same as today
376:                maintDoc = newMaintDoc(newDelegate);
377:                rule = (DelegateRule) setupMaintDocRule(maintDoc, rule
378:                        .getClass());
379:
380:                // now we need to setup the convenience objects so that the rule has the right
381:                // delegate values
382:                rule.setupConvenienceObjects(maintDoc);
383:
384:                // confirm that there are no errors to begin with
385:                assertGlobalErrorMapEmpty();
386:
387:                // run the business rules
388:                rule.checkSimpleRules();
389:                assertGlobalErrorMapEmpty();
390:            }
391:
392:            public void testCheckSimpleRulesStartDateRule_invalidFromAmt() {
393:                DelegateRule rule = new DelegateRule();
394:                newDelegate = badDelegate4();
395:
396:                // new delegate with start-date same as today
397:                maintDoc = newMaintDoc(newDelegate);
398:                rule = (DelegateRule) setupMaintDocRule(maintDoc, rule
399:                        .getClass());
400:
401:                // now we need to setup the convenience objects so that the rule has the right
402:                // delegate values
403:                rule.setupConvenienceObjects(maintDoc);
404:
405:                // confirm that there are no errors to begin with
406:                assertGlobalErrorMapEmpty();
407:
408:                // run the business rules
409:                rule.checkSimpleRules();
410:                assertGlobalErrorMapContains(
411:                        ERROR_PREFIX + "finDocApprovalFromThisAmt",
412:                        KFSKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_FROM_AMOUNT_NONNEGATIVE);
413:            }
414:
415:            public void testCheckSimpleRulesStartDateRule_invalidToAmt() {
416:                DelegateRule rule = new DelegateRule();
417:                newDelegate = badDelegate5();
418:
419:                // new delegate with start-date same as today
420:                maintDoc = newMaintDoc(newDelegate);
421:                rule = (DelegateRule) setupMaintDocRule(maintDoc, rule
422:                        .getClass());
423:
424:                // now we need to setup the convenience objects so that the rule has the right
425:                // delegate values
426:                rule.setupConvenienceObjects(maintDoc);
427:
428:                // confirm that there are no errors to begin with
429:                assertGlobalErrorMapEmpty();
430:
431:                // run the business rules
432:                rule.checkSimpleRules();
433:                assertGlobalErrorMapContains(
434:                        ERROR_PREFIX + "finDocApprovalToThisAmount",
435:                        KFSKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_TO_AMOUNT_MORE_THAN_FROM_OR_ZERO);
436:            }
437:
438:            public void testCheckSimpleRulesStartDateRule_validFromAmtNullToAmt() {
439:                DelegateRule rule = new DelegateRule();
440:                newDelegate = badDelegate6();
441:
442:                // new delegate with start-date same as today
443:                maintDoc = newMaintDoc(newDelegate);
444:                rule = (DelegateRule) setupMaintDocRule(maintDoc, rule
445:                        .getClass());
446:
447:                // now we need to setup the convenience objects so that the rule has the right
448:                // delegate values
449:                rule.setupConvenienceObjects(maintDoc);
450:
451:                // confirm that there are no errors to begin with
452:                assertGlobalErrorMapEmpty();
453:
454:                // run the business rules
455:                rule.checkSimpleRules();
456:                assertGlobalErrorMapContains(
457:                        ERROR_PREFIX + "finDocApprovalToThisAmount",
458:                        KFSKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_TO_AMOUNT_MORE_THAN_FROM_OR_ZERO);
459:            }
460:
461:            public void testCheckSimpleRulesStartDateRule_nullFromAmtZeroPlusToAmt() {
462:                DelegateRule rule = new DelegateRule();
463:                newDelegate = badDelegate7();
464:
465:                // new delegate with start-date same as today
466:                maintDoc = newMaintDoc(newDelegate);
467:                rule = (DelegateRule) setupMaintDocRule(maintDoc, rule
468:                        .getClass());
469:
470:                // now we need to setup the convenience objects so that the rule has the right
471:                // delegate values
472:                rule.setupConvenienceObjects(maintDoc);
473:
474:                // confirm that there are no errors to begin with
475:                assertGlobalErrorMapEmpty();
476:
477:                // run the business rules
478:                rule.checkSimpleRules();
479:                assertGlobalErrorMapContains(
480:                        ERROR_PREFIX + "finDocApprovalToThisAmount",
481:                        KFSKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_TO_AMOUNT_MORE_THAN_FROM_OR_ZERO);
482:            }
483:
484:            public void testCheckSimpleRulesStartDateRule_validFromAmtLessThanToAmt() {
485:                DelegateRule rule = new DelegateRule();
486:                newDelegate = badDelegate8();
487:
488:                // new delegate with start-date same as today
489:                maintDoc = newMaintDoc(newDelegate);
490:                rule = (DelegateRule) setupMaintDocRule(maintDoc, rule
491:                        .getClass());
492:
493:                // now we need to setup the convenience objects so that the rule has the right
494:                // delegate values
495:                rule.setupConvenienceObjects(maintDoc);
496:
497:                // confirm that there are no errors to begin with
498:                assertGlobalErrorMapEmpty();
499:
500:                // run the business rules
501:                rule.checkSimpleRules();
502:                assertGlobalErrorMapContains(
503:                        ERROR_PREFIX + "finDocApprovalToThisAmount",
504:                        KFSKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_TO_AMOUNT_MORE_THAN_FROM_OR_ZERO);
505:            }
506:
507:            /**
508:             * This test makes sure that a good user delegate passes the Delegate User Rules
509:             */
510:            public void testcheckDelegateUserRules_goodDelegate() {
511:                DelegateRule rule = new DelegateRule();
512:                newDelegate = goodDelegate1();
513:                maintDoc = newMaintDoc(newDelegate);
514:
515:                rule = (DelegateRule) setupMaintDocRule(newDelegate, rule
516:                        .getClass());
517:                // now we need to setup the convenience objects so that the rule has the right
518:                // delegate values
519:                rule.setupConvenienceObjects(maintDoc);
520:
521:                // confirm that there are no errors to begin with
522:                assertGlobalErrorMapEmpty();
523:                rule.checkDelegateUserRules(maintDoc);
524:                assertGlobalErrorMapEmpty();
525:
526:            }
527:
528:            public void testcheckDelegateUserRules_badDelegate1() {
529:                DelegateRule rule = new DelegateRule();
530:                newDelegate = badDelegate1();
531:                maintDoc = newMaintDoc(newDelegate);
532:
533:                rule = (DelegateRule) setupMaintDocRule(newDelegate, rule
534:                        .getClass());
535:                // now we need to setup the convenience objects so that the rule has the right
536:                // delegate values
537:                rule.setupConvenienceObjects(maintDoc);
538:
539:                // confirm that there are no errors to begin with
540:                assertGlobalErrorMapEmpty();
541:                rule.checkDelegateUserRules(maintDoc);
542:                assertGlobalErrorMapContains(
543:                        ERROR_PREFIX + "accountDelegate.personUserIdentifier",
544:                        KFSKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_USER_NOT_ACTIVE);
545:            }
546:
547:            public void testcheckDelegateUserRules_badDelegate2() {
548:                DelegateRule rule = new DelegateRule();
549:                newDelegate = badDelegate2();
550:                maintDoc = newMaintDoc(newDelegate);
551:
552:                rule = (DelegateRule) setupMaintDocRule(newDelegate, rule
553:                        .getClass());
554:                // now we need to setup the convenience objects so that the rule has the right
555:                // delegate values
556:                rule.setupConvenienceObjects(maintDoc);
557:
558:                // confirm that there are no errors to begin with
559:                assertGlobalErrorMapEmpty();
560:                rule.checkDelegateUserRules(maintDoc);
561:                assertGlobalErrorMapEmpty();
562:
563:            }
564:
565:            public void testcheckDelegateUserRules_badDelegate3() {
566:                DelegateRule rule = new DelegateRule();
567:                newDelegate = badDelegate3();
568:                maintDoc = newMaintDoc(newDelegate);
569:
570:                rule = (DelegateRule) setupMaintDocRule(newDelegate, rule
571:                        .getClass());
572:                // now we need to setup the convenience objects so that the rule has the right
573:                // delegate values
574:                rule.setupConvenienceObjects(maintDoc);
575:
576:                // confirm that there are no errors to begin with
577:                assertGlobalErrorMapEmpty();
578:                rule.checkDelegateUserRules(maintDoc);
579:                assertGlobalErrorMapContains(
580:                        ERROR_PREFIX + "accountDelegate.personUserIdentifier",
581:                        KFSKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_USER_NOT_ACTIVE);
582:            }
583:
584:            /**
585:             * This method simulates a user trying to create a delegate marked as primary when there is already an account with All
586:             * Documents for the doctype for the chart/account combo
587:             */
588:            public void testCheckOnlyOnePrimaryRoute_allPrimaryAlreadyExists() {
589:                DelegateRule rule = new DelegateRule();
590:                newDelegate = delegateWithDocTypeAll();
591:                maintDoc = newMaintDoc(newDelegate);
592:
593:                rule = (DelegateRule) setupMaintDocRule(newDelegate, rule
594:                        .getClass());
595:                // now we need to setup the convenience objects so that the rule has the right
596:                // delegate values
597:                rule.setupConvenienceObjects(maintDoc);
598:
599:                // confirm that there are no errors to begin with
600:                assertGlobalErrorMapEmpty();
601:                rule.checkOnlyOnePrimaryRoute(maintDoc);
602:                assertGlobalErrorMapEmpty();
603:            }
604:
605:            /**
606:             * This method will simulate a user is trying to create a delegate that routes with DocumentType of ALL, but a chart/account
607:             * combo that has a primary route for a specific doctype already exists
608:             */
609:
610:            public void testCheckOnlyOnePrimaryRoute_specificPrimaryAlreadyExistsAllFails() {
611:                DelegateRule rule = new DelegateRule();
612:                newDelegate = delegateWithSpecificTypeClosedAllSpecified();
613:                maintDoc = newMaintDoc(newDelegate);
614:
615:                rule = (DelegateRule) setupMaintDocRule(newDelegate, rule
616:                        .getClass());
617:                // now we need to setup the convenience objects so that the rule has the right
618:                // delegate values
619:                rule.setupConvenienceObjects(maintDoc);
620:
621:                // confirm that there are no errors to begin with
622:                assertGlobalErrorMapEmpty();
623:                rule.checkOnlyOnePrimaryRoute(maintDoc);
624:                assertGlobalErrorMapEmpty();
625:            }
626:
627:            /**
628:             * This method will simulate a user who is trying to create a delegate that routes with a specific doctype that is already taken
629:             * in the db
630:             */
631:
632:            public void testCheckOnlyOnePrimaryRoute_specificPrimaryAlreadyExistsSpecificFails() {
633:                DelegateRule rule = new DelegateRule();
634:                newDelegate = delegateWithSpecificTypeClosed();
635:                maintDoc = newMaintDoc(newDelegate);
636:
637:                rule = (DelegateRule) setupMaintDocRule(newDelegate, rule
638:                        .getClass());
639:                // now we need to setup the convenience objects so that the rule has the right
640:                // delegate values
641:                rule.setupConvenienceObjects(maintDoc);
642:
643:                // confirm that there are no errors to begin with
644:                assertGlobalErrorMapEmpty();
645:                rule.checkOnlyOnePrimaryRoute(maintDoc);
646:                assertGlobalErrorMapEmpty();
647:            }
648:
649:            /**
650:             * This method will simulate a user who is trying to create a delegate that routes with a doctype of all and should succeed
651:             */
652:
653:            public void testCheckOnlyOnePrimaryRoute_allPrimaryDoesNotExist() {
654:                DelegateRule rule = new DelegateRule();
655:                newDelegate = delegateWithAllDocTypeOpen();
656:                maintDoc = newMaintDoc(newDelegate);
657:
658:                rule = (DelegateRule) setupMaintDocRule(newDelegate, rule
659:                        .getClass());
660:                // now we need to setup the convenience objects so that the rule has the right
661:                // delegate values
662:                rule.setupConvenienceObjects(maintDoc);
663:
664:                // confirm that there are no errors to begin with
665:                assertGlobalErrorMapEmpty();
666:                rule.checkOnlyOnePrimaryRoute(maintDoc);
667:                assertGlobalErrorMapEmpty();
668:            }
669:
670:            /**
671:             * This method will simulate a user who is trying to create a delegate that routes with a doctype of a21 should succeed
672:             */
673:
674:            public void testCheckOnlyOnePrimaryRoute_specificPrimaryDoesNotExist() {
675:                DelegateRule rule = new DelegateRule();
676:                newDelegate = delegateWithSpecificDocTypeOpen();
677:                maintDoc = newMaintDoc(newDelegate);
678:
679:                rule = (DelegateRule) setupMaintDocRule(newDelegate, rule
680:                        .getClass());
681:                // now we need to setup the convenience objects so that the rule has the right
682:                // delegate values
683:                rule.setupConvenienceObjects(maintDoc);
684:
685:                // confirm that there are no errors to begin with
686:                assertGlobalErrorMapEmpty();
687:                rule.checkOnlyOnePrimaryRoute(maintDoc);
688:                assertGlobalErrorMapEmpty();
689:            }
690:
691:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.