Source Code Cross Referenced for DocumentServiceTest.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » core » service » 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.core.service 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2005-2007 The Kuali Foundation.
0003:         * 
0004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
0005:         * you may not use this file except in compliance with the License.
0006:         * You may obtain a copy of the License at
0007:         * 
0008:         * http://www.opensource.org/licenses/ecl1.php
0009:         * 
0010:         * Unless required by applicable law or agreed to in writing, software
0011:         * distributed under the License is distributed on an "AS IS" BASIS,
0012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013:         * See the License for the specific language governing permissions and
0014:         * limitations under the License.
0015:         */
0016:        package org.kuali.core.service;
0017:
0018:        import static org.kuali.test.fixtures.AccountingLineFixture.DOCUMENT_SERVICE_TEST_LINE;
0019:        import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
0020:
0021:        import java.util.ArrayList;
0022:        import java.util.Iterator;
0023:        import java.util.LinkedHashMap;
0024:
0025:        import org.kuali.core.bo.DocumentHeader;
0026:        import org.kuali.core.bo.DocumentType;
0027:        import org.kuali.core.bo.KualiCode;
0028:        import org.kuali.core.document.Document;
0029:        import org.kuali.core.document.DocumentBase;
0030:        import org.kuali.core.exceptions.InactiveDocumentTypeAuthorizationException;
0031:        import org.kuali.core.exceptions.UnknownDocumentIdException;
0032:        import org.kuali.core.exceptions.UnknownDocumentTypeException;
0033:        import org.kuali.core.rule.event.SaveDocumentEvent;
0034:        import org.kuali.core.service.impl.DocumentServiceImpl;
0035:        import org.kuali.core.util.KualiDecimal;
0036:        import org.kuali.core.util.ObjectUtils;
0037:        import org.kuali.kfs.KFSConstants;
0038:        import org.kuali.kfs.bo.SourceAccountingLine;
0039:        import org.kuali.kfs.bo.TargetAccountingLine;
0040:        import org.kuali.kfs.context.KualiTestBase;
0041:        import org.kuali.kfs.context.SpringContext;
0042:        import org.kuali.kfs.service.KualiCodeService;
0043:        import org.kuali.module.chart.bo.Account;
0044:        import org.kuali.module.chart.bo.ObjLevel;
0045:        import org.kuali.module.chart.bo.ObjSubTyp;
0046:        import org.kuali.module.chart.bo.ObjectType;
0047:        import org.kuali.module.chart.bo.codes.BalanceTyp;
0048:        import org.kuali.module.chart.bo.codes.BudgetAggregationCode;
0049:        import org.kuali.module.chart.bo.codes.FederalFundedCode;
0050:        import org.kuali.module.chart.bo.codes.MandatoryTransferEliminationCode;
0051:        import org.kuali.module.chart.service.ObjectLevelService;
0052:        import org.kuali.module.financial.bo.InternalBillingItem;
0053:        import org.kuali.module.financial.document.CashReceiptDocument;
0054:        import org.kuali.module.financial.document.InternalBillingDocument;
0055:        import org.kuali.test.ConfigureContext;
0056:
0057:        /**
0058:         * This class tests the Document service.
0059:         */
0060:        @ConfigureContext(session=KHUNTLEY)
0061:        public class DocumentServiceTest extends KualiTestBase {
0062:
0063:            private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
0064:                    .getLogger(DocumentService.class);
0065:
0066:            private static final String UNKNOWN_DOCUMENT_TYPENAME = "bar";
0067:            private static final String KNOWN_DOCUMENT_TYPENAME = "InternalBillingDocument";
0068:            private static final String INTERNAL_BILLING_DOCUMENT_TYPE_NAME = "InternalBillingDocument";
0069:            private static final Class INTERNAL_BILLING_DOCUMENT_CLASS = InternalBillingDocument.class;
0070:            private static final String UNKNOWN_DOCHEADERID = "-1";
0071:            private static final String UNKNOWN_DOCHEADERID_2 = "-2";
0072:            private static final String MOCK_INACTIVE_DOCUMENT_TYPE_NAME = "mockInactiveTypeName";
0073:            private static final String MAINTENANCE_DOCUMENT_TYPENAME = "AccountMaintenanceDocument";
0074:
0075:            private static BalanceTyp BAL_TYP = new BalanceTyp();
0076:            private static final int YEAR = 2004;
0077:
0078:            public final void testGetNewDocument_byTypeName_nullDocumentType()
0079:                    throws Exception {
0080:                boolean failedAsExpected = false;
0081:
0082:                try {
0083:                    SpringContext.getBean(DocumentService.class)
0084:                            .getNewDocument((String) null);
0085:                } catch (IllegalArgumentException e) {
0086:                    failedAsExpected = true;
0087:                }
0088:
0089:                assertTrue(failedAsExpected);
0090:            }
0091:
0092:            public final void testGetNewDocument_byTypeName_unknownDocumentType()
0093:                    throws Exception {
0094:                boolean failedAsExpected = false;
0095:
0096:                try {
0097:                    SpringContext.getBean(DocumentService.class)
0098:                            .getNewDocument(UNKNOWN_DOCUMENT_TYPENAME);
0099:                } catch (UnknownDocumentTypeException e) {
0100:                    failedAsExpected = true;
0101:                }
0102:
0103:                assertTrue(failedAsExpected);
0104:            }
0105:
0106:            public final void testGetNewDocument_byTypeName_knownDocumentType()
0107:                    throws Exception {
0108:                testGetNewDocument_byTypeName_known(KNOWN_DOCUMENT_TYPENAME);
0109:            }
0110:
0111:            public final void testGetNewDocument_byTypeName_maintenanceDocumentType()
0112:                    throws Exception {
0113:                testGetNewDocument_byTypeName_known(MAINTENANCE_DOCUMENT_TYPENAME);
0114:            }
0115:
0116:            private void testGetNewDocument_byTypeName_known(
0117:                    String documentTypeName) throws Exception {
0118:                Document document = SpringContext
0119:                        .getBean(DocumentService.class).getNewDocument(
0120:                                documentTypeName);
0121:                assertNotNull(document);
0122:                assertNotNull(document.getDocumentHeader());
0123:                assertNotNull(document.getDocumentHeader().getDocumentNumber());
0124:            }
0125:
0126:            public final void testGetNewDocument_byTypeName_inactiveDocumentType()
0127:                    throws Exception {
0128:                assertSame(
0129:                        "only one instance from Spring so can't insert mocks without affecting other tests",
0130:                        SpringContext.getBean(DocumentService.class),
0131:                        SpringContext.getBean(DocumentService.class));
0132:                DocumentServiceImpl serviceImpl = new DocumentServiceImpl();
0133:                serviceImpl
0134:                        .setDocumentTypeService(new MockInactiveDocumentTypeService());
0135:                try {
0136:                    serviceImpl
0137:                            .getNewDocument(MOCK_INACTIVE_DOCUMENT_TYPE_NAME);
0138:                    // Actually it wouldn't get this far anyway; the mock service would cause other exceptions.
0139:                    fail("created a new document of an inactive type");
0140:                } catch (InactiveDocumentTypeAuthorizationException e) {
0141:                    // good
0142:                }
0143:            }
0144:
0145:            public final void testGetNewDocument_byClass_nullDocumentClass()
0146:                    throws Exception {
0147:                boolean failedAsExpected = false;
0148:
0149:                try {
0150:                    SpringContext.getBean(DocumentService.class)
0151:                            .getNewDocument((Class) null);
0152:                } catch (IllegalArgumentException e) {
0153:                    failedAsExpected = true;
0154:                }
0155:
0156:                assertTrue(failedAsExpected);
0157:            }
0158:
0159:            public final void testGetNewDocument_byClass_nonDocumentClass()
0160:                    throws Exception {
0161:                boolean failedAsExpected = false;
0162:
0163:                try {
0164:                    SpringContext.getBean(DocumentService.class)
0165:                            .getNewDocument(Integer.class);
0166:                } catch (IllegalArgumentException e) {
0167:                    failedAsExpected = true;
0168:                }
0169:
0170:                assertTrue(failedAsExpected);
0171:            }
0172:
0173:            public final void testGetNewDocument_byClass_unknownDocumentClass()
0174:                    throws Exception {
0175:                boolean failedAsExpected = false;
0176:
0177:                try {
0178:                    SpringContext.getBean(DocumentService.class)
0179:                            .getNewDocument(MockDocument.class);
0180:                } catch (UnknownDocumentTypeException e) {
0181:                    failedAsExpected = true;
0182:                }
0183:
0184:                assertTrue(failedAsExpected);
0185:            }
0186:
0187:            public final void testGetNewDocument_byClass_knownDocumentClass()
0188:                    throws Exception {
0189:                Document document = SpringContext
0190:                        .getBean(DocumentService.class).getNewDocument(
0191:                                InternalBillingDocument.class);
0192:
0193:                assertNotNull(document);
0194:                assertNotNull(document.getDocumentHeader());
0195:                assertNotNull(document.getDocumentHeader().getDocumentNumber());
0196:            }
0197:
0198:            @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
0199:            public void testPartiallyLoadedDoc() throws Exception {
0200:
0201:                InternalBillingDocument ib;
0202:                SourceAccountingLine incomeLine;
0203:                TargetAccountingLine expenseLine;
0204:                InternalBillingItem item;
0205:                String documentHeaderId;
0206:                KualiCode kualiCode;
0207:                String code;
0208:                String name;
0209:                Iterator iter;
0210:                ObjLevel objectLevel;
0211:                Integer lineNumber;
0212:
0213:                // get a new object, unpopulated
0214:                ib = (InternalBillingDocument) SpringContext.getBean(
0215:                        DocumentService.class).getNewDocument(
0216:                        KNOWN_DOCUMENT_TYPENAME);
0217:                documentHeaderId = ib.getDocumentHeader().getDocumentNumber();
0218:                LOG.debug("documentHeaderId = " + documentHeaderId);
0219:
0220:                // set attributes on the document itself
0221:                ib.setPostingYear(new Integer(YEAR));
0222:                ib.getDocumentHeader().setExplanation(
0223:                        "This is a test document.");
0224:                ib.getDocumentHeader().setFinancialDocumentDescription("test");
0225:
0226:                // setup income lines
0227:                incomeLine = createSourceLine(documentHeaderId, 1);
0228:                ib.addSourceAccountingLine(incomeLine);
0229:
0230:                // setup expense lines
0231:                expenseLine = createTargetLine(documentHeaderId, 1);
0232:                ib.addTargetAccountingLine(expenseLine);
0233:
0234:                // save the document
0235:                SpringContext.getBean(DocumentService.class).saveDocument(ib);
0236:
0237:                // load the document from the DB
0238:                ib = (InternalBillingDocument) SpringContext.getBean(
0239:                        DocumentService.class).getByDocumentHeaderId(
0240:                        documentHeaderId);
0241:
0242:                // test to make sure all the values are as expected
0243:                assertNotNull(ib);
0244:
0245:                LOG.debug("pre getTargetAccountingLines call and iteration");
0246:                // make sure the expense lines are there
0247:                assertTrue(ib.getTargetAccountingLines().size() == 1);
0248:                iter = ib.getTargetAccountingLines().iterator();
0249:                while (iter.hasNext()) {
0250:
0251:                    // grab the line
0252:                    expenseLine = (TargetAccountingLine) iter.next();
0253:                    assertNotNull(expenseLine);
0254:
0255:                    LOG.debug("next expenseLine()");
0256:                    LOG.debug("expenseLine.getAmount() == "
0257:                            + expenseLine.getAmount());
0258:
0259:                    // chart
0260:                    assertNotNull(expenseLine.getChart());
0261:                    assertEquals(
0262:                            DOCUMENT_SERVICE_TEST_LINE.chartOfAccountsCode,
0263:                            expenseLine.getChart().getChartOfAccountsCode());
0264:
0265:                    // account
0266:                    assertNotNull(expenseLine.getAccount());
0267:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.accountNumber,
0268:                            expenseLine.getAccount().getAccountNumber());
0269:
0270:                    // sub-account
0271:                    assertNotNull(expenseLine.getSubAccount());
0272:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.subAccountNumber,
0273:                            expenseLine.getSubAccount().getSubAccountNumber());
0274:
0275:                    // object code
0276:                    assertNotNull(expenseLine.getObjectCode());
0277:                    assertEquals(
0278:                            DOCUMENT_SERVICE_TEST_LINE.financialObjectCode,
0279:                            expenseLine.getObjectCode()
0280:                                    .getFinancialObjectCode());
0281:
0282:                    // object type code
0283:                    assertNotNull(expenseLine.getObjectCode()
0284:                            .getFinancialObjectType());
0285:                    kualiCode = (ObjectType) SpringContext.getBean(
0286:                            KualiCodeService.class).getByCode(
0287:                            ObjectType.class,
0288:                            expenseLine.getObjectCode()
0289:                                    .getFinancialObjectType().getCode());
0290:                    assertEquals(kualiCode.getName(), expenseLine
0291:                            .getObjectCode().getFinancialObjectType().getName());
0292:
0293:                    // object level code
0294:                    assertNotNull(expenseLine.getObjectCode()
0295:                            .getFinancialObjectLevel());
0296:                    objectLevel = SpringContext.getBean(
0297:                            ObjectLevelService.class).getByPrimaryId(
0298:                            expenseLine.getObjectCode()
0299:                                    .getFinancialObjectLevel()
0300:                                    .getChartOfAccounts()
0301:                                    .getChartOfAccountsCode(),
0302:                            expenseLine.getObjectCode()
0303:                                    .getFinancialObjectLevel()
0304:                                    .getFinancialObjectLevelCode());
0305:                    assertNotNull(objectLevel);
0306:                    assertEquals(objectLevel.getFinancialObjectLevelName(),
0307:                            expenseLine.getObjectCode()
0308:                                    .getFinancialObjectLevel()
0309:                                    .getFinancialObjectLevelName());
0310:
0311:                    // object sub type code
0312:                    assertNotNull(expenseLine.getObjectCode()
0313:                            .getFinancialObjectSubType());
0314:                    kualiCode = (ObjSubTyp) SpringContext.getBean(
0315:                            KualiCodeService.class).getByCode(
0316:                            ObjSubTyp.class,
0317:                            expenseLine.getObjectCode()
0318:                                    .getFinancialObjectSubType().getCode());
0319:                    assertEquals(kualiCode.getName(), expenseLine
0320:                            .getObjectCode().getFinancialObjectSubType()
0321:                            .getName());
0322:
0323:                    // budget aggregation code
0324:                    assertNotNull(expenseLine.getObjectCode()
0325:                            .getFinancialBudgetAggregation());
0326:                    kualiCode = (BudgetAggregationCode) SpringContext.getBean(
0327:                            KualiCodeService.class).getByCode(
0328:                            BudgetAggregationCode.class,
0329:                            expenseLine.getObjectCode()
0330:                                    .getFinancialBudgetAggregation().getCode());
0331:                    assertEquals(kualiCode.getName(), expenseLine
0332:                            .getObjectCode().getFinancialBudgetAggregation()
0333:                            .getName());
0334:
0335:                    // MandatoryTransferEliminationCode
0336:                    assertNotNull(expenseLine.getObjectCode()
0337:                            .getFinObjMandatoryTrnfrelim());
0338:                    kualiCode = (MandatoryTransferEliminationCode) SpringContext
0339:                            .getBean(KualiCodeService.class).getByCode(
0340:                                    MandatoryTransferEliminationCode.class,
0341:                                    expenseLine.getObjectCode()
0342:                                            .getFinObjMandatoryTrnfrelim()
0343:                                            .getCode());
0344:                    assertEquals(kualiCode.getName(), expenseLine
0345:                            .getObjectCode().getFinObjMandatoryTrnfrelim()
0346:                            .getName());
0347:
0348:                    // FederalFundedCode
0349:                    assertNotNull(expenseLine.getObjectCode()
0350:                            .getFinancialFederalFunded());
0351:                    kualiCode = (FederalFundedCode) SpringContext.getBean(
0352:                            KualiCodeService.class).getByCode(
0353:                            FederalFundedCode.class,
0354:                            expenseLine.getObjectCode()
0355:                                    .getFinancialFederalFunded().getCode());
0356:                    assertEquals(kualiCode.getName(), expenseLine
0357:                            .getObjectCode().getFinancialFederalFunded()
0358:                            .getName());
0359:
0360:                    // sub-object-code
0361:                    assertNotNull(expenseLine.getSubObjectCode());
0362:                    assertEquals(
0363:                            DOCUMENT_SERVICE_TEST_LINE.financialSubObjectCode,
0364:                            expenseLine.getSubObjectCode()
0365:                                    .getFinancialSubObjectCode());
0366:
0367:                    // project
0368:                    assertNotNull(expenseLine.getProjectCode());
0369:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.projectCode,
0370:                            expenseLine.getProject().getCode());
0371:                }
0372:                LOG.debug("post getTargetAccountingLines call and iteration");
0373:
0374:                // make sure the income lines are there
0375:                LOG.debug("pre getSourceAccountingLines call and iteration");
0376:                assertTrue(ib.getSourceAccountingLines().size() == 1);
0377:                iter = ib.getSourceAccountingLines().iterator();
0378:                while (iter.hasNext()) {
0379:
0380:                    // grab the line
0381:                    incomeLine = (SourceAccountingLine) iter.next();
0382:                    assertNotNull(incomeLine);
0383:
0384:                    LOG.debug("next incomeLine()");
0385:
0386:                    // chart
0387:                    assertNotNull(incomeLine.getChart());
0388:                    assertEquals(
0389:                            DOCUMENT_SERVICE_TEST_LINE.chartOfAccountsCode,
0390:                            incomeLine.getChart().getChartOfAccountsCode());
0391:
0392:                    // account
0393:                    assertNotNull(incomeLine.getAccount());
0394:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.accountNumber,
0395:                            incomeLine.getAccount().getAccountNumber());
0396:
0397:                    // sub-account
0398:                    assertNotNull(incomeLine.getSubAccount());
0399:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.subAccountNumber,
0400:                            incomeLine.getSubAccount().getSubAccountNumber());
0401:
0402:                    // object code
0403:                    assertNotNull(incomeLine.getObjectCode());
0404:                    assertEquals(
0405:                            DOCUMENT_SERVICE_TEST_LINE.financialObjectCode,
0406:                            incomeLine.getObjectCode().getFinancialObjectCode());
0407:
0408:                    // object level code
0409:                    assertNotNull(incomeLine.getObjectCode()
0410:                            .getFinancialObjectLevel());
0411:                    objectLevel = SpringContext.getBean(
0412:                            ObjectLevelService.class).getByPrimaryId(
0413:                            incomeLine.getObjectCode()
0414:                                    .getFinancialObjectLevel()
0415:                                    .getChartOfAccounts()
0416:                                    .getChartOfAccountsCode(),
0417:                            incomeLine.getObjectCode()
0418:                                    .getFinancialObjectLevel()
0419:                                    .getFinancialObjectLevelCode());
0420:                    assertNotNull(objectLevel);
0421:                    assertEquals(objectLevel.getFinancialObjectLevelName(),
0422:                            incomeLine.getObjectCode()
0423:                                    .getFinancialObjectLevel()
0424:                                    .getFinancialObjectLevelName());
0425:
0426:                    // object type code
0427:                    assertNotNull(incomeLine.getObjectCode()
0428:                            .getFinancialObjectType());
0429:                    kualiCode = (ObjectType) SpringContext.getBean(
0430:                            KualiCodeService.class).getByCode(
0431:                            ObjectType.class,
0432:                            incomeLine.getObjectCode().getFinancialObjectType()
0433:                                    .getCode());
0434:                    assertEquals(kualiCode.getName(), incomeLine
0435:                            .getObjectCode().getFinancialObjectType().getName());
0436:
0437:                    // object sub type code
0438:                    assertNotNull(incomeLine.getObjectCode()
0439:                            .getFinancialObjectSubType());
0440:                    kualiCode = (ObjSubTyp) SpringContext.getBean(
0441:                            KualiCodeService.class).getByCode(
0442:                            ObjSubTyp.class,
0443:                            incomeLine.getObjectCode()
0444:                                    .getFinancialObjectSubType().getCode());
0445:                    assertEquals(kualiCode.getName(), incomeLine
0446:                            .getObjectCode().getFinancialObjectSubType()
0447:                            .getName());
0448:
0449:                    // budget aggregation code
0450:                    assertNotNull(incomeLine.getObjectCode()
0451:                            .getFinancialBudgetAggregation());
0452:                    kualiCode = (BudgetAggregationCode) SpringContext.getBean(
0453:                            KualiCodeService.class).getByCode(
0454:                            BudgetAggregationCode.class,
0455:                            incomeLine.getObjectCode()
0456:                                    .getFinancialBudgetAggregation().getCode());
0457:                    assertEquals(kualiCode.getName(), incomeLine
0458:                            .getObjectCode().getFinancialBudgetAggregation()
0459:                            .getName());
0460:
0461:                    // MandatoryTransferEliminationCode
0462:                    assertNotNull(incomeLine.getObjectCode()
0463:                            .getFinObjMandatoryTrnfrelim());
0464:                    kualiCode = (MandatoryTransferEliminationCode) SpringContext
0465:                            .getBean(KualiCodeService.class).getByCode(
0466:                                    MandatoryTransferEliminationCode.class,
0467:                                    incomeLine.getObjectCode()
0468:                                            .getFinObjMandatoryTrnfrelim()
0469:                                            .getCode());
0470:                    assertEquals(kualiCode.getName(), incomeLine
0471:                            .getObjectCode().getFinObjMandatoryTrnfrelim()
0472:                            .getName());
0473:
0474:                    // FederalFundedCode
0475:                    assertNotNull(incomeLine.getObjectCode()
0476:                            .getFinancialFederalFunded());
0477:                    kualiCode = (FederalFundedCode) SpringContext.getBean(
0478:                            KualiCodeService.class).getByCode(
0479:                            FederalFundedCode.class,
0480:                            incomeLine.getObjectCode()
0481:                                    .getFinancialFederalFunded().getCode());
0482:                    assertEquals(kualiCode.getName(), incomeLine
0483:                            .getObjectCode().getFinancialFederalFunded()
0484:                            .getName());
0485:
0486:                    // sub-object-code
0487:                    assertNotNull(incomeLine.getSubObjectCode());
0488:                    assertEquals(
0489:                            DOCUMENT_SERVICE_TEST_LINE.financialSubObjectCode,
0490:                            incomeLine.getSubObjectCode()
0491:                                    .getFinancialSubObjectCode());
0492:
0493:                    // project
0494:                    assertNotNull(incomeLine.getProjectCode());
0495:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.projectCode,
0496:                            incomeLine.getProject().getCode());
0497:                }
0498:                LOG.debug("post getSourceAccountingLines call and iteration");
0499:            }
0500:
0501:            public final void testSave_assumedEventClass_nullDocument()
0502:                    throws Exception {
0503:                boolean failedAsExpected = false;
0504:
0505:                try {
0506:                    SpringContext.getBean(DocumentService.class).saveDocument(
0507:                            null);
0508:                } catch (IllegalArgumentException e) {
0509:                    failedAsExpected = true;
0510:                }
0511:
0512:                assertTrue(failedAsExpected);
0513:            }
0514:
0515:            public final void testSave_useEventClass_nullDocument()
0516:                    throws Exception {
0517:                boolean failedAsExpected = false;
0518:
0519:                try {
0520:                    SpringContext.getBean(DocumentService.class).saveDocument(
0521:                            null, SaveDocumentEvent.class);
0522:                } catch (IllegalArgumentException e) {
0523:                    failedAsExpected = true;
0524:                }
0525:
0526:                assertTrue(failedAsExpected);
0527:            }
0528:
0529:            public final void testSave_assumedEventClass_invalidDocument()
0530:                    throws Exception {
0531:
0532:                boolean failedAsExpected = false;
0533:
0534:                try {
0535:                    SpringContext.getBean(DocumentService.class).saveDocument(
0536:                            new InternalBillingDocument());
0537:                } catch (IllegalStateException e) {
0538:                    failedAsExpected = true;
0539:                }
0540:
0541:                assertTrue(failedAsExpected);
0542:            }
0543:
0544:            public final void testSave_useEventClass_invalidDocument()
0545:                    throws Exception {
0546:
0547:                boolean failedAsExpected = false;
0548:
0549:                try {
0550:                    SpringContext.getBean(DocumentService.class).saveDocument(
0551:                            new InternalBillingDocument(),
0552:                            SaveDocumentEvent.class);
0553:                } catch (IllegalStateException e) {
0554:                    failedAsExpected = true;
0555:                }
0556:
0557:                assertTrue(failedAsExpected);
0558:            }
0559:
0560:            @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
0561:            public final void testSave_assumedEventClass_validDocument()
0562:                    throws Exception {
0563:                Document document = SpringContext
0564:                        .getBean(DocumentService.class).getNewDocument(
0565:                                KNOWN_DOCUMENT_TYPENAME);
0566:
0567:                // fill in a few required fields before saving
0568:                DocumentHeader documentHeader = document.getDocumentHeader();
0569:                documentHeader.setFinancialDocumentDescription("test document");
0570:
0571:                SpringContext.getBean(DocumentService.class).saveDocument(
0572:                        document);
0573:            }
0574:
0575:            @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
0576:            public final void testSave_useEventClass_validDocument()
0577:                    throws Exception {
0578:                Document document = SpringContext
0579:                        .getBean(DocumentService.class).getNewDocument(
0580:                                KNOWN_DOCUMENT_TYPENAME);
0581:
0582:                // fill in a few required fields before saving
0583:                DocumentHeader documentHeader = document.getDocumentHeader();
0584:                documentHeader.setFinancialDocumentDescription("test document");
0585:
0586:                SpringContext.getBean(DocumentService.class).saveDocument(
0587:                        document, SaveDocumentEvent.class);
0588:            }
0589:
0590:            @ConfigureContext(session=KHUNTLEY)
0591:            public final void testSave_nullEventClass() throws Exception {
0592:                Document document = SpringContext
0593:                        .getBean(DocumentService.class).getNewDocument(
0594:                                KNOWN_DOCUMENT_TYPENAME);
0595:                // fill in a few required fields before saving
0596:                DocumentHeader documentHeader = document.getDocumentHeader();
0597:                documentHeader.setFinancialDocumentDescription("test document");
0598:                try {
0599:                    SpringContext.getBean(DocumentService.class).saveDocument(
0600:                            document, null);
0601:                    fail();
0602:                } catch (IllegalArgumentException e) {
0603:                }
0604:            }
0605:
0606:            // TODO: have workflow return something better than a NullPointerException when
0607:            // handed an unknown document type id
0608:            public final void testGetByDocumentHeaderId_unknownDocumentId()
0609:                    throws Exception {
0610:                boolean failedAsExpected = false;
0611:
0612:                try {
0613:                    SpringContext.getBean(DocumentService.class)
0614:                            .getByDocumentHeaderId(UNKNOWN_DOCHEADERID);
0615:                } catch (UnknownDocumentIdException e) {
0616:                    failedAsExpected = true;
0617:                }
0618:
0619:                assertTrue(failedAsExpected);
0620:            }
0621:
0622:            @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
0623:            public final void testGetByDocumentHeaderId_knownUser_knownDocumentId()
0624:                    throws Exception {
0625:                // create and save a new document
0626:                Document newDocument = SpringContext.getBean(
0627:                        DocumentService.class).getNewDocument(
0628:                        KNOWN_DOCUMENT_TYPENAME);
0629:                newDocument.getDocumentHeader()
0630:                        .setFinancialDocumentDescription("test");
0631:
0632:                SpringContext.getBean(DocumentService.class).saveDocument(
0633:                        newDocument);
0634:
0635:                // re-retrieve it
0636:                Document retrievedDocument = SpringContext.getBean(
0637:                        DocumentService.class).getByDocumentHeaderId(
0638:                        newDocument.getDocumentHeader().getDocumentNumber());
0639:                assertNotNull(retrievedDocument);
0640:                assertEquals(newDocument.getDocumentHeader()
0641:                        .getDocumentNumber(), retrievedDocument
0642:                        .getDocumentHeader().getDocumentNumber());
0643:            }
0644:
0645:            public final void testGetDocumentsByListOfDocumentHeaderIds_nullDocumentIds()
0646:                    throws Exception {
0647:                boolean failedAsExpected = false;
0648:
0649:                try {
0650:                    SpringContext.getBean(DocumentService.class)
0651:                            .getDocumentsByListOfDocumentHeaderIds(
0652:                                    Document.class, null);
0653:                } catch (IllegalArgumentException e) {
0654:                    failedAsExpected = true;
0655:                }
0656:
0657:                assertTrue(failedAsExpected);
0658:            }
0659:
0660:            public final void testGetDocumentsByListOfDocumentHeaderIds_blankDocumentIds()
0661:                    throws Exception {
0662:                boolean failedAsExpected = false;
0663:
0664:                ArrayList blankDocHeaderIds = new ArrayList();
0665:                blankDocHeaderIds.add(UNKNOWN_DOCHEADERID);
0666:                blankDocHeaderIds.add(KFSConstants.EMPTY_STRING);
0667:
0668:                try {
0669:                    SpringContext.getBean(DocumentService.class)
0670:                            .getDocumentsByListOfDocumentHeaderIds(
0671:                                    Document.class, blankDocHeaderIds);
0672:                } catch (IllegalArgumentException e) {
0673:                    failedAsExpected = true;
0674:                }
0675:
0676:                assertTrue(failedAsExpected);
0677:            }
0678:
0679:            public final void testGetDocumentsByListOfDocumentHeaderIds_invalidClass()
0680:                    throws Exception {
0681:                boolean failedAsExpected = false;
0682:
0683:                ArrayList blankDocHeaderIds = new ArrayList();
0684:                blankDocHeaderIds.add(UNKNOWN_DOCHEADERID);
0685:                blankDocHeaderIds.add(UNKNOWN_DOCHEADERID);
0686:
0687:                try {
0688:                    SpringContext.getBean(DocumentService.class)
0689:                            .getDocumentsByListOfDocumentHeaderIds(
0690:                                    Account.class, blankDocHeaderIds);
0691:                } catch (IllegalArgumentException e) {
0692:                    failedAsExpected = true;
0693:                }
0694:
0695:                assertTrue(failedAsExpected);
0696:            }
0697:
0698:            public final void testGetDocumentsByListOfDocumentHeaderIds_unknownDocumentIds()
0699:                    throws Exception {
0700:                boolean failedAsExpected = false;
0701:
0702:                ArrayList unknownDocumentHeaderIds = new ArrayList();
0703:                unknownDocumentHeaderIds.add(UNKNOWN_DOCHEADERID);
0704:                unknownDocumentHeaderIds.add(UNKNOWN_DOCHEADERID_2);
0705:
0706:                assertTrue(SpringContext.getBean(DocumentService.class)
0707:                        .getDocumentsByListOfDocumentHeaderIds(
0708:                                CashReceiptDocument.class,
0709:                                unknownDocumentHeaderIds).isEmpty());
0710:            }
0711:
0712:            @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
0713:            public final void testGetDocumentsByListOfDocumentHeaderIds_knownDocumentIds()
0714:                    throws Exception {
0715:                // create and save two new documents
0716:                Document newDocument1 = SpringContext.getBean(
0717:                        DocumentService.class).getNewDocument(
0718:                        INTERNAL_BILLING_DOCUMENT_TYPE_NAME);
0719:                newDocument1.getDocumentHeader()
0720:                        .setFinancialDocumentDescription("test");
0721:
0722:                SpringContext.getBean(DocumentService.class).saveDocument(
0723:                        newDocument1);
0724:
0725:                Document newDocument2 = SpringContext.getBean(
0726:                        DocumentService.class).getNewDocument(
0727:                        INTERNAL_BILLING_DOCUMENT_TYPE_NAME);
0728:                newDocument2.getDocumentHeader()
0729:                        .setFinancialDocumentDescription("test");
0730:
0731:                SpringContext.getBean(DocumentService.class).saveDocument(
0732:                        newDocument2);
0733:
0734:                ArrayList docHeaderIds = new ArrayList();
0735:                docHeaderIds.add(newDocument1.getDocumentNumber());
0736:                docHeaderIds.add(newDocument2.getDocumentNumber());
0737:
0738:                assertEquals(docHeaderIds.size(), SpringContext.getBean(
0739:                        DocumentService.class)
0740:                        .getDocumentsByListOfDocumentHeaderIds(
0741:                                INTERNAL_BILLING_DOCUMENT_CLASS, docHeaderIds)
0742:                        .size());
0743:            }
0744:
0745:            private static SourceAccountingLine protoSourceLine;
0746:
0747:            private SourceAccountingLine createSourceLine(
0748:                    String documentHeaderId, int sequenceNumber)
0749:                    throws Exception {
0750:                if (protoSourceLine == null) {
0751:                    protoSourceLine = DOCUMENT_SERVICE_TEST_LINE
0752:                            .createAccountingLine(SourceAccountingLine.class,
0753:                                    documentHeaderId, YEAR, sequenceNumber);
0754:                }
0755:
0756:                SourceAccountingLine sourceLine = (SourceAccountingLine) ObjectUtils
0757:                        .deepCopy(protoSourceLine);
0758:
0759:                return sourceLine;
0760:            }
0761:
0762:            private static TargetAccountingLine protoTargetLine;
0763:
0764:            private TargetAccountingLine createTargetLine(
0765:                    String documentHeaderId, int sequenceNumber)
0766:                    throws Exception {
0767:                if (protoTargetLine == null) {
0768:                    protoTargetLine = DOCUMENT_SERVICE_TEST_LINE
0769:                            .createAccountingLine(TargetAccountingLine.class,
0770:                                    documentHeaderId, YEAR, sequenceNumber);
0771:                }
0772:                TargetAccountingLine targetLine = (TargetAccountingLine) ObjectUtils
0773:                        .deepCopy(protoTargetLine);
0774:
0775:                return targetLine;
0776:            }
0777:
0778:            @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
0779:            public void testOJBLoading() throws Exception {
0780:
0781:                InternalBillingDocument ib;
0782:                SourceAccountingLine incomeLine;
0783:                TargetAccountingLine expenseLine;
0784:                InternalBillingItem item;
0785:                String documentHeaderId;
0786:                KualiCode kualiCode;
0787:                String code;
0788:                String name;
0789:                Iterator iter;
0790:                ObjLevel objectLevel;
0791:                Integer lineNumber;
0792:                // TODO: is this still needed revisit
0793:                // DocumentNote documentNote;
0794:
0795:                // get a new object, unpopulated
0796:                ib = (InternalBillingDocument) SpringContext.getBean(
0797:                        DocumentService.class).getNewDocument(
0798:                        KNOWN_DOCUMENT_TYPENAME);
0799:                documentHeaderId = ib.getDocumentNumber();
0800:                LOG.debug("documentHeaderId = " + documentHeaderId);
0801:
0802:                // set attributes on the document itself
0803:                ib.setPostingYear(new Integer(YEAR));
0804:                ib.getDocumentHeader().setExplanation(
0805:                        "This is a test document, testing anonymous keys.");
0806:                ib.getDocumentHeader().setFinancialDocumentDescription("test");
0807:
0808:                // setup income lines
0809:                incomeLine = createSourceLine(documentHeaderId, 1);
0810:                ib.addSourceAccountingLine(incomeLine);
0811:                incomeLine = createSourceLine(documentHeaderId, 2);
0812:                ib.addSourceAccountingLine(incomeLine);
0813:
0814:                // setup expense lines
0815:                expenseLine = createTargetLine(documentHeaderId, 1);
0816:                ib.addTargetAccountingLine(expenseLine);
0817:                expenseLine = createTargetLine(documentHeaderId, 2);
0818:                ib.addTargetAccountingLine(expenseLine);
0819:
0820:                // setup items line 1
0821:                item = new InternalBillingItem();
0822:                item.setItemQuantity(new Integer(1));
0823:                item.setItemServiceDate(null);
0824:                item.setItemStockDescription("X");
0825:                item.setItemStockNumber("1234");
0826:                item.setItemUnitAmount(new KualiDecimal("3000.00"));
0827:                item.setUnitOfMeasureCode("X");
0828:                ib.addItem(item);
0829:
0830:                // setup items line 2
0831:                item = new InternalBillingItem();
0832:                item.setItemQuantity(new Integer(1));
0833:                item.setItemServiceDate(null);
0834:                item.setItemStockDescription("X");
0835:                item.setItemStockNumber("1234");
0836:                item.setItemUnitAmount(new KualiDecimal("3000.00"));
0837:                item.setUnitOfMeasureCode("X");
0838:                ib.addItem(item);
0839:
0840:                // setup items line 3
0841:                item = new InternalBillingItem();
0842:                item.setItemQuantity(new Integer(1));
0843:                item.setItemServiceDate(null);
0844:                item.setItemStockDescription("X");
0845:                item.setItemStockNumber("1234");
0846:                item.setItemUnitAmount(new KualiDecimal("3000.00"));
0847:                item.setUnitOfMeasureCode("X");
0848:                ib.addItem(item);
0849:
0850:                // TODO: revisit this it is commented out for now, is it really needed
0851:                // Add the document note
0852:                // UniversalUser author = GlobalVariables.getUserSession().getUniversalUser();
0853:                // documentNote = DocumentTestUtils.createDocumentNote(documentHeaderId, author, "This is a test note");
0854:                // ib.getDocumentHeader().addNote(documentNote);
0855:
0856:                // save the document
0857:                SpringContext.getBean(DocumentService.class).saveDocument(ib);
0858:
0859:                // load the document from the DB
0860:                ib = (InternalBillingDocument) SpringContext.getBean(
0861:                        DocumentService.class).getByDocumentHeaderId(
0862:                        documentHeaderId);
0863:
0864:                // test to make sure all the values are as expected
0865:                assertNotNull(ib);
0866:
0867:                // test to make sure notes are there
0868:                // assertTrue(ib.getDocumentHeader().getNotes().size() == 1);
0869:
0870:                LOG.debug("pre getItems call and iteration");
0871:                // make sure the Items lines are there
0872:                assertTrue(ib.getItems().size() == 3);
0873:                iter = ib.getItems().iterator();
0874:                while (iter.hasNext()) {
0875:
0876:                    LOG.debug("next itemLine()");
0877:
0878:                    item = (InternalBillingItem) iter.next();
0879:                    assertNotNull(item);
0880:                    assertEquals(new Integer(1), item.getItemQuantity());
0881:                    assertNull(item.getItemServiceDate());
0882:                    assertEquals("X", item.getItemStockDescription());
0883:                    assertEquals("1234", item.getItemStockNumber());
0884:                    assertEquals(new KualiDecimal("3000.00"), item
0885:                            .getItemUnitAmount().setScale(2));
0886:                    assertEquals("X", item.getUnitOfMeasureCode());
0887:                }
0888:                LOG.debug("post getItems call and iteration");
0889:
0890:                // make sure the expense lines are there
0891:                LOG.debug("pre getTargetAccountingLines call and iteration");
0892:                assertTrue(ib.getTargetAccountingLines().size() == 2);
0893:                iter = ib.getTargetAccountingLines().iterator();
0894:                while (iter.hasNext()) {
0895:
0896:                    // grab the line
0897:                    expenseLine = (TargetAccountingLine) iter.next();
0898:                    assertNotNull(expenseLine);
0899:
0900:                    LOG.debug("next expenseLine()");
0901:                    LOG.debug("expenseLine.getExpenseLineAmount() == "
0902:                            + expenseLine.getAmount());
0903:
0904:                    // chart
0905:                    assertNotNull(expenseLine.getChart());
0906:                    assertEquals(
0907:                            DOCUMENT_SERVICE_TEST_LINE.chartOfAccountsCode,
0908:                            expenseLine.getChart().getChartOfAccountsCode());
0909:
0910:                    // account
0911:                    assertNotNull(expenseLine.getAccount());
0912:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.accountNumber,
0913:                            expenseLine.getAccount().getAccountNumber());
0914:
0915:                    // sub-account
0916:                    assertNotNull(expenseLine.getSubAccount());
0917:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.subAccountNumber,
0918:                            expenseLine.getSubAccount().getSubAccountNumber());
0919:
0920:                    // object code
0921:                    assertNotNull(expenseLine.getObjectCode());
0922:                    assertEquals(
0923:                            DOCUMENT_SERVICE_TEST_LINE.financialObjectCode,
0924:                            expenseLine.getObjectCode()
0925:                                    .getFinancialObjectCode());
0926:
0927:                    // object type code
0928:                    assertNotNull(expenseLine.getObjectCode()
0929:                            .getFinancialObjectType());
0930:                    kualiCode = (ObjectType) SpringContext.getBean(
0931:                            KualiCodeService.class).getByCode(
0932:                            ObjectType.class,
0933:                            expenseLine.getObjectCode()
0934:                                    .getFinancialObjectType().getCode());
0935:                    assertEquals(kualiCode.getName(), expenseLine
0936:                            .getObjectCode().getFinancialObjectType().getName());
0937:
0938:                    // object level code
0939:                    assertNotNull(expenseLine.getObjectCode()
0940:                            .getFinancialObjectLevel());
0941:                    objectLevel = SpringContext.getBean(
0942:                            ObjectLevelService.class).getByPrimaryId(
0943:                            expenseLine.getObjectCode()
0944:                                    .getFinancialObjectLevel()
0945:                                    .getChartOfAccounts()
0946:                                    .getChartOfAccountsCode(),
0947:                            expenseLine.getObjectCode()
0948:                                    .getFinancialObjectLevel()
0949:                                    .getFinancialObjectLevelCode());
0950:                    assertNotNull(objectLevel);
0951:                    assertEquals(objectLevel.getFinancialObjectLevelName(),
0952:                            expenseLine.getObjectCode()
0953:                                    .getFinancialObjectLevel()
0954:                                    .getFinancialObjectLevelName());
0955:
0956:                    // object sub type code
0957:                    assertNotNull(expenseLine.getObjectCode()
0958:                            .getFinancialObjectSubType());
0959:                    kualiCode = (ObjSubTyp) SpringContext.getBean(
0960:                            KualiCodeService.class).getByCode(
0961:                            ObjSubTyp.class,
0962:                            expenseLine.getObjectCode()
0963:                                    .getFinancialObjectSubType().getCode());
0964:                    assertEquals(kualiCode.getName(), expenseLine
0965:                            .getObjectCode().getFinancialObjectSubType()
0966:                            .getName());
0967:
0968:                    // budget aggregation code
0969:                    assertNotNull(expenseLine.getObjectCode()
0970:                            .getFinancialBudgetAggregation());
0971:                    kualiCode = (BudgetAggregationCode) SpringContext.getBean(
0972:                            KualiCodeService.class).getByCode(
0973:                            BudgetAggregationCode.class,
0974:                            expenseLine.getObjectCode()
0975:                                    .getFinancialBudgetAggregation().getCode());
0976:                    assertEquals(kualiCode.getName(), expenseLine
0977:                            .getObjectCode().getFinancialBudgetAggregation()
0978:                            .getName());
0979:
0980:                    // MandatoryTransferEliminationCode
0981:                    assertNotNull(expenseLine.getObjectCode()
0982:                            .getFinObjMandatoryTrnfrelim());
0983:                    kualiCode = (MandatoryTransferEliminationCode) SpringContext
0984:                            .getBean(KualiCodeService.class).getByCode(
0985:                                    MandatoryTransferEliminationCode.class,
0986:                                    expenseLine.getObjectCode()
0987:                                            .getFinObjMandatoryTrnfrelim()
0988:                                            .getCode());
0989:                    assertEquals(kualiCode.getName(), expenseLine
0990:                            .getObjectCode().getFinObjMandatoryTrnfrelim()
0991:                            .getName());
0992:
0993:                    // FederalFundedCode
0994:                    assertNotNull(expenseLine.getObjectCode()
0995:                            .getFinancialFederalFunded());
0996:                    kualiCode = (FederalFundedCode) SpringContext.getBean(
0997:                            KualiCodeService.class).getByCode(
0998:                            FederalFundedCode.class,
0999:                            expenseLine.getObjectCode()
1000:                                    .getFinancialFederalFunded().getCode());
1001:                    assertEquals(kualiCode.getName(), expenseLine
1002:                            .getObjectCode().getFinancialFederalFunded()
1003:                            .getName());
1004:
1005:                    // sub-object-code
1006:                    assertNotNull(expenseLine.getSubObjectCode());
1007:                    assertEquals(
1008:                            DOCUMENT_SERVICE_TEST_LINE.financialSubObjectCode,
1009:                            expenseLine.getSubObjectCode()
1010:                                    .getFinancialSubObjectCode());
1011:
1012:                    // project
1013:                    assertNotNull(expenseLine.getProjectCode());
1014:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.projectCode,
1015:                            expenseLine.getProject().getCode());
1016:
1017:                }
1018:                LOG.debug("post getTargetAccountingLines call and iteration");
1019:
1020:                // make sure the income lines are there
1021:                LOG.debug("pre getSourceAccountingLines call and iteration");
1022:                assertTrue(ib.getSourceAccountingLines().size() == 2);
1023:                iter = ib.getSourceAccountingLines().iterator();
1024:                while (iter.hasNext()) {
1025:
1026:                    // grab the line
1027:                    incomeLine = (SourceAccountingLine) iter.next();
1028:                    assertNotNull(incomeLine);
1029:
1030:                    LOG.debug("next incomeLine()");
1031:
1032:                    // chart
1033:                    assertNotNull(incomeLine.getChart());
1034:                    assertEquals(
1035:                            DOCUMENT_SERVICE_TEST_LINE.chartOfAccountsCode,
1036:                            incomeLine.getChart().getChartOfAccountsCode());
1037:
1038:                    // account
1039:                    assertNotNull(incomeLine.getAccount());
1040:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.accountNumber,
1041:                            incomeLine.getAccount().getAccountNumber());
1042:
1043:                    // sub-account
1044:                    assertNotNull(incomeLine.getSubAccount());
1045:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.subAccountNumber,
1046:                            incomeLine.getSubAccount().getSubAccountNumber());
1047:
1048:                    // object code
1049:                    assertNotNull(incomeLine.getObjectCode());
1050:                    assertEquals(
1051:                            DOCUMENT_SERVICE_TEST_LINE.financialObjectCode,
1052:                            incomeLine.getObjectCode().getFinancialObjectCode());
1053:
1054:                    // object level code
1055:                    assertNotNull(incomeLine.getObjectCode()
1056:                            .getFinancialObjectLevel());
1057:                    objectLevel = SpringContext.getBean(
1058:                            ObjectLevelService.class).getByPrimaryId(
1059:                            incomeLine.getObjectCode()
1060:                                    .getFinancialObjectLevel()
1061:                                    .getChartOfAccounts()
1062:                                    .getChartOfAccountsCode(),
1063:                            incomeLine.getObjectCode()
1064:                                    .getFinancialObjectLevel()
1065:                                    .getFinancialObjectLevelCode());
1066:                    assertNotNull(objectLevel);
1067:                    assertEquals(objectLevel.getFinancialObjectLevelName(),
1068:                            incomeLine.getObjectCode()
1069:                                    .getFinancialObjectLevel()
1070:                                    .getFinancialObjectLevelName());
1071:
1072:                    // object type code
1073:                    assertNotNull(incomeLine.getObjectCode()
1074:                            .getFinancialObjectType());
1075:                    kualiCode = (ObjectType) SpringContext.getBean(
1076:                            KualiCodeService.class).getByCode(
1077:                            ObjectType.class,
1078:                            incomeLine.getObjectCode().getFinancialObjectType()
1079:                                    .getCode());
1080:                    assertEquals(kualiCode.getName(), incomeLine
1081:                            .getObjectCode().getFinancialObjectType().getName());
1082:
1083:                    // object sub type code
1084:                    assertNotNull(incomeLine.getObjectCode()
1085:                            .getFinancialObjectSubType());
1086:                    kualiCode = (ObjSubTyp) SpringContext.getBean(
1087:                            KualiCodeService.class).getByCode(
1088:                            ObjSubTyp.class,
1089:                            incomeLine.getObjectCode()
1090:                                    .getFinancialObjectSubType().getCode());
1091:                    assertEquals(kualiCode.getName(), incomeLine
1092:                            .getObjectCode().getFinancialObjectSubType()
1093:                            .getName());
1094:
1095:                    // budget aggregation code
1096:                    assertNotNull(incomeLine.getObjectCode()
1097:                            .getFinancialBudgetAggregation());
1098:                    kualiCode = (BudgetAggregationCode) SpringContext.getBean(
1099:                            KualiCodeService.class).getByCode(
1100:                            BudgetAggregationCode.class,
1101:                            incomeLine.getObjectCode()
1102:                                    .getFinancialBudgetAggregation().getCode());
1103:                    assertEquals(kualiCode.getName(), incomeLine
1104:                            .getObjectCode().getFinancialBudgetAggregation()
1105:                            .getName());
1106:
1107:                    // MandatoryTransferEliminationCode
1108:                    assertNotNull(incomeLine.getObjectCode()
1109:                            .getFinObjMandatoryTrnfrelim());
1110:                    kualiCode = (MandatoryTransferEliminationCode) SpringContext
1111:                            .getBean(KualiCodeService.class).getByCode(
1112:                                    MandatoryTransferEliminationCode.class,
1113:                                    incomeLine.getObjectCode()
1114:                                            .getFinObjMandatoryTrnfrelim()
1115:                                            .getCode());
1116:                    assertEquals(kualiCode.getName(), incomeLine
1117:                            .getObjectCode().getFinObjMandatoryTrnfrelim()
1118:                            .getName());
1119:
1120:                    // FederalFundedCode
1121:                    assertNotNull(incomeLine.getObjectCode()
1122:                            .getFinancialFederalFunded());
1123:                    kualiCode = (FederalFundedCode) SpringContext.getBean(
1124:                            KualiCodeService.class).getByCode(
1125:                            FederalFundedCode.class,
1126:                            incomeLine.getObjectCode()
1127:                                    .getFinancialFederalFunded().getCode());
1128:                    assertEquals(kualiCode.getName(), incomeLine
1129:                            .getObjectCode().getFinancialFederalFunded()
1130:                            .getName());
1131:
1132:                    // sub-object-code
1133:                    assertNotNull(incomeLine.getSubObjectCode());
1134:                    assertEquals(
1135:                            DOCUMENT_SERVICE_TEST_LINE.financialSubObjectCode,
1136:                            incomeLine.getSubObjectCode()
1137:                                    .getFinancialSubObjectCode());
1138:
1139:                    // project
1140:                    assertNotNull(incomeLine.getProjectCode());
1141:                    assertEquals(DOCUMENT_SERVICE_TEST_LINE.projectCode,
1142:                            incomeLine.getProject().getCode());
1143:
1144:                }
1145:                LOG.debug("post getSourceAccountingLines call and iteration");
1146:
1147:                ib.getDocumentHeader().setExplanation("test 1");
1148:
1149:                // save the document
1150:                SpringContext.getBean(DocumentService.class).saveDocument(ib);
1151:
1152:                // load the document from the DB
1153:                ib = (InternalBillingDocument) SpringContext.getBean(
1154:                        DocumentService.class).getByDocumentHeaderId(
1155:                        documentHeaderId);
1156:
1157:                // confirm that the second change was saved
1158:                assertEquals(ib.getDocumentHeader().getExplanation(), "test 1");
1159:
1160:            }
1161:
1162:            public void testDocumentExists_blankDocumentId() throws Exception {
1163:                try {
1164:                    SpringContext.getBean(DocumentService.class)
1165:                            .documentExists("  ");
1166:                    fail("blank document id did not cause an exception");
1167:                } catch (IllegalArgumentException e) {
1168:                    // good
1169:                }
1170:                assertEquals("because a service threw an exception", true,
1171:                        testTransactionIsRollbackOnly());
1172:            }
1173:
1174:            public void testDocumentExists_documentDoesNotExist()
1175:                    throws Exception {
1176:                assertFalse(SpringContext.getBean(DocumentService.class)
1177:                        .documentExists("0"));
1178:                assertFalse(testTransactionIsRollbackOnly());
1179:            }
1180:
1181:            @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
1182:            public void testDocumentExists_documentExists() throws Exception {
1183:                Document document = SpringContext
1184:                        .getBean(DocumentService.class).getNewDocument(
1185:                                InternalBillingDocument.class);
1186:
1187:                assertNotNull(document);
1188:                assertNotNull(document.getDocumentHeader());
1189:                assertNotNull(document.getDocumentHeader().getDocumentNumber());
1190:
1191:                document.getDocumentHeader().setFinancialDocumentDescription(
1192:                        "foo");
1193:                SpringContext.getBean(DocumentService.class).saveDocument(
1194:                        document);
1195:
1196:                assertTrue(SpringContext.getBean(DocumentService.class)
1197:                        .documentExists(document.getDocumentNumber()));
1198:                assertFalse(testTransactionIsRollbackOnly());
1199:            }
1200:
1201:            private static class MockDocument extends DocumentBase {
1202:                @Override
1203:                public final void populateDocumentForRouting() {
1204:                    throw new UnsupportedOperationException();
1205:                }
1206:
1207:                @Override
1208:                protected LinkedHashMap toStringMapper() {
1209:                    return new LinkedHashMap();
1210:                }
1211:
1212:                public boolean getAllowsCopy() {
1213:                    return false;
1214:                }
1215:            }
1216:
1217:            // there's no need to generalize this yet
1218:            private static class MockInactiveDocumentTypeService implements 
1219:                    DocumentTypeService {
1220:
1221:                public Class getClassByName(String documentTypeName) {
1222:                    assertEquals(MOCK_INACTIVE_DOCUMENT_TYPE_NAME,
1223:                            documentTypeName);
1224:                    return getClass(); // A Document subclass isn't necessary; anything not null will do for this test.
1225:                }
1226:
1227:                public DocumentType getDocumentTypeByName(
1228:                        String documentTypeName) {
1229:                    assertEquals(MOCK_INACTIVE_DOCUMENT_TYPE_NAME,
1230:                            documentTypeName);
1231:                    DocumentType documentType = new DocumentType();
1232:                    documentType.setFinDocumentTypeActiveIndicator(false);
1233:                    return documentType;
1234:                }
1235:
1236:                public String getDocumentTypeNameByClass(Class documentClass) {
1237:                    throw new NoSuchMethodError(
1238:                            "the test does not use this method");
1239:                }
1240:
1241:                public String getDocumentTypeCodeByClass(Class documentClass) {
1242:                    throw new NoSuchMethodError(
1243:                            "the test does not use this method");
1244:                }
1245:
1246:                public DocumentType getDocumentTypeByCode(
1247:                        String documentTypeCode) {
1248:                    throw new NoSuchMethodError(
1249:                            "the test does not use this method");
1250:                }
1251:            }
1252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.