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


001:        /*
002:         * Copyright 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.kfs.service;
017:
018:        import java.io.InputStream;
019:        import java.util.ArrayList;
020:        import java.util.List;
021:
022:        import org.apache.commons.io.IOUtils;
023:        import org.kuali.kfs.batch.BatchInputFileType;
024:        import org.kuali.kfs.context.KualiTestBase;
025:        import org.kuali.kfs.context.SpringContext;
026:        import org.kuali.kfs.exceptions.XMLParseException;
027:        import org.kuali.module.financial.batch.pcard.ProcurementCardInputFileType;
028:        import org.kuali.module.financial.bo.ProcurementCardTransaction;
029:        import org.kuali.module.gl.batch.collector.CollectorBatch;
030:        import org.kuali.module.gl.batch.collector.CollectorInputFileType;
031:        import org.kuali.module.gl.bo.CollectorDetail;
032:        import org.kuali.module.gl.bo.OriginEntryFull;
033:        import org.kuali.test.ConfigureContext;
034:
035:        /**
036:         * Tests for the service parse method.
037:         */
038:        @ConfigureContext
039:        public class BatchInputServiceParseTest extends KualiTestBase {
040:            private static final String TEST_BATCH_XML_DIRECTORY = "org/kuali/kfs/batch/xml/";
041:
042:            private BatchInputFileService batchInputFileService;
043:
044:            private byte[] validPCDOFileContents;
045:            private byte[] validCollectorFileContents;
046:
047:            private BatchInputFileType pcdoBatchInputFileType;
048:            private BatchInputFileType collectorBatchInputFileType;
049:
050:            /**
051:             * @see junit.framework.TestCase#setUp()
052:             */
053:            @Override
054:            protected void setUp() throws Exception {
055:                super .setUp();
056:
057:                batchInputFileService = SpringContext
058:                        .getBean(BatchInputFileService.class);
059:                pcdoBatchInputFileType = SpringContext
060:                        .getBean(ProcurementCardInputFileType.class);
061:                collectorBatchInputFileType = SpringContext
062:                        .getBean(CollectorInputFileType.class);
063:
064:                InputStream pcdoValidFileStream = ClassLoader
065:                        .getSystemResourceAsStream(TEST_BATCH_XML_DIRECTORY
066:                                + "BatchInputValidPCDO.xml");
067:                validPCDOFileContents = IOUtils
068:                        .toByteArray(pcdoValidFileStream);
069:                InputStream collectorValidFileStream = ClassLoader
070:                        .getSystemResourceAsStream(TEST_BATCH_XML_DIRECTORY
071:                                + "BatchInputValidCollector.xml");
072:                validCollectorFileContents = IOUtils
073:                        .toByteArray(collectorValidFileStream);
074:            }
075:
076:            /**
077:             * Verifies the correct object graph is being built from the pcdo file contents in the service parse method. The PCDO
078:             * unmarshalling rules specify the result should be a ArrayList of ProcurementCardTransaction objects.
079:             * 
080:             * @see org.kuali.module.financial.bo.ProcurementCardTransaction
081:             */
082:            public final void testParse_pcdoValidContents() throws Exception {
083:                Object parsedObject = batchInputFileService.parse(
084:                        pcdoBatchInputFileType, validPCDOFileContents);
085:
086:                assertNotNull("parsed object was null", parsedObject);
087:                assertEquals("incorrect object type constructured from parse",
088:                        java.util.ArrayList.class, parsedObject.getClass());
089:
090:                List parsedList = (ArrayList) parsedObject;
091:                assertEquals("parsed object size was incorrect", 3, parsedList
092:                        .size());
093:
094:                for (int i = 0; i < parsedList.size(); i++) {
095:                    Object parsedElement = parsedList.get(i);
096:                    assertEquals(
097:                            "list object type was incorrect on index " + i,
098:                            ProcurementCardTransaction.class, parsedElement
099:                                    .getClass());
100:                }
101:            }
102:
103:            /**
104:             * Verifies the correct object graph is being built from the collector file contents in the service parse method. The Collector
105:             * unmarshalling rules specify the result should be a populated CollectorBatch object.
106:             * 
107:             * @see org.kuali.module.gl.collector.xml.CollectorBatch
108:             */
109:            public final void testParse_collectorValidContents()
110:                    throws Exception {
111:                Object parsedObject = batchInputFileService
112:                        .parse(collectorBatchInputFileType,
113:                                validCollectorFileContents);
114:
115:                assertNotNull("parsed object was null", parsedObject);
116:                assertEquals("incorrect object type constructured from parse",
117:                        CollectorBatch.class, parsedObject.getClass());
118:
119:                CollectorBatch collectorBatch = (CollectorBatch) parsedObject;
120:
121:                // verify origin entries were populated
122:                assertEquals(
123:                        "parsed object has incorrect number of origin entries",
124:                        2, collectorBatch.getOriginEntries().size());
125:
126:                for (int i = 0; i < collectorBatch.getOriginEntries().size(); i++) {
127:                    Object originEntry = collectorBatch.getOriginEntries().get(
128:                            i);
129:
130:                    assertNotNull("orgin entry record is null on index " + i,
131:                            originEntry);
132:                    assertEquals("object type was incorrect on index " + i,
133:                            OriginEntryFull.class, originEntry.getClass());
134:                }
135:
136:                // verify id billing entries were populated
137:                assertEquals(
138:                        "parsed object has incorrect number of id billing entries",
139:                        2, collectorBatch.getCollectorDetails().size());
140:
141:                for (int i = 0; i < collectorBatch.getCollectorDetails().size(); i++) {
142:                    Object idBilling = collectorBatch.getCollectorDetails()
143:                            .get(i);
144:
145:                    assertNotNull("ID Billing record is null on index " + i,
146:                            idBilling);
147:                    assertEquals("object type was incorrect on index " + i,
148:                            CollectorDetail.class, idBilling.getClass());
149:                }
150:
151:                assertEquals(
152:                        "number of batch records does not match header count",
153:                        collectorBatch.getTotalRecords().intValue(),
154:                        collectorBatch.getOriginEntries().size()
155:                                + collectorBatch.getCollectorDetails().size());
156:            }
157:
158:            /**
159:             * Verifies exception is thrown on parse method if file contents are empty.
160:             */
161:            public final void testParse_emptyFileContents() throws Exception {
162:                byte[] emptyContents = null;
163:
164:                boolean failedAsExpected = false;
165:                try {
166:                    batchInputFileService.parse(pcdoBatchInputFileType,
167:                            emptyContents);
168:                } catch (IllegalArgumentException e) {
169:                    failedAsExpected = true;
170:                }
171:                assertTrue(
172:                        "exception not thrown for null empty pcdo file contents",
173:                        failedAsExpected);
174:
175:                failedAsExpected = false;
176:                try {
177:                    batchInputFileService.parse(collectorBatchInputFileType,
178:                            emptyContents);
179:                } catch (IllegalArgumentException e) {
180:                    failedAsExpected = true;
181:                }
182:                assertTrue(
183:                        "exception not thrown for null empty collector file contents",
184:                        failedAsExpected);
185:            }
186:
187:            /**
188:             * Verifies error message occurs on parse when an invalid xml format is given.
189:             */
190:            public final void testParse_invalidTagOrder() throws Exception {
191:                InputStream fileContents = ClassLoader
192:                        .getSystemResourceAsStream(TEST_BATCH_XML_DIRECTORY
193:                                + "BatchInputInvalidTagOrderPCDO.xml");
194:                byte[] invalidTagOrderPCDOFileContents = IOUtils
195:                        .toByteArray(fileContents);
196:
197:                boolean failedAsExpected = false;
198:                try {
199:                    batchInputFileService.parse(pcdoBatchInputFileType,
200:                            invalidTagOrderPCDOFileContents);
201:                } catch (XMLParseException e) {
202:                    failedAsExpected = true;
203:                }
204:
205:                assertTrue(
206:                        "parse exception not thrown for xml with invalid tag order",
207:                        failedAsExpected);
208:            }
209:
210:            /**
211:             * Verifies error message occurs on parse when an invalid xml format is given.
212:             */
213:            public final void testParse_missingRequiredField() throws Exception {
214:                InputStream fileContents = ClassLoader
215:                        .getSystemResourceAsStream(TEST_BATCH_XML_DIRECTORY
216:                                + "BatchInputMissingTagPCDO.xml");
217:                byte[] missingTagPCDOFileContents = IOUtils
218:                        .toByteArray(fileContents);
219:
220:                boolean failedAsExpected = false;
221:                try {
222:                    batchInputFileService.parse(pcdoBatchInputFileType,
223:                            missingTagPCDOFileContents);
224:                } catch (XMLParseException e) {
225:                    failedAsExpected = true;
226:                }
227:
228:                assertTrue(
229:                        "parse exception not thrown for xml missing a required field",
230:                        failedAsExpected);
231:            }
232:
233:            /**
234:             * Verifies error occurs when an invalid tag is given.
235:             */
236:            public final void testParse_invalidTag() throws Exception {
237:                InputStream fileContents = ClassLoader
238:                        .getSystemResourceAsStream(TEST_BATCH_XML_DIRECTORY
239:                                + "BatchInputInvalidTagCollector.xml");
240:                byte[] invalidTagCollectorContents = IOUtils
241:                        .toByteArray(fileContents);
242:
243:                boolean failedAsExpected = false;
244:                try {
245:                    batchInputFileService.parse(collectorBatchInputFileType,
246:                            invalidTagCollectorContents);
247:                } catch (XMLParseException e) {
248:                    failedAsExpected = true;
249:                }
250:
251:                assertTrue("parse exception not thrown for invalid tag",
252:                        failedAsExpected);
253:            }
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.