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.bo;
017:
018: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
019:
020: import java.io.ByteArrayInputStream;
021: import java.util.Arrays;
022: import java.util.List;
023:
024: import org.kuali.core.service.DocumentService;
025: import org.kuali.core.util.KualiDecimal;
026: import org.kuali.kfs.KFSKeyConstants;
027: import org.kuali.kfs.bo.AccountingLineParser;
028: import org.kuali.kfs.bo.SourceAccountingLine;
029: import org.kuali.kfs.bo.TargetAccountingLine;
030: import org.kuali.kfs.context.KualiTestBase;
031: import org.kuali.kfs.context.SpringContext;
032: import org.kuali.kfs.document.AccountingDocument;
033: import org.kuali.kfs.exceptions.AccountingLineParserException;
034: import org.kuali.module.financial.document.InternalBillingDocument;
035: import org.kuali.test.ConfigureContext;
036: import org.kuali.test.suite.AnnotationTestSuite;
037: import org.kuali.test.suite.CrossSectionSuite;
038:
039: /**
040: * Test class for testing <code>{@link AccountingLineParserBase}</code>
041: */
042: @AnnotationTestSuite(CrossSectionSuite.class)
043: @ConfigureContext(session=KHUNTLEY)
044: public class AccountingLineParserBaseTest extends KualiTestBase {
045:
046: private AccountingDocument accountingDocument;
047: private AccountingLineParser parser;
048:
049: @Override
050: protected void setUp() throws Exception {
051: super .setUp();
052: accountingDocument = (AccountingDocument) SpringContext
053: .getBean(DocumentService.class).getNewDocument(
054: InternalBillingDocument.class);
055: parser = accountingDocument.getAccountingLineParser();
056: }
057:
058: /**
059: */
060: public void testParseSourceAccountingLine_failure_notANumber() {
061: try {
062: parser.parseSourceAccountingLine(accountingDocument,
063: "BL,4631672, , ,KUL, , , a");
064: fail("didn't throw AccountingLineParserException");
065: } catch (AccountingLineParserException e) {
066: // good
067: assertInvalidPropertyValue(e, " a");
068: }
069: }
070:
071: private static void assertInvalidPropertyValue(
072: AccountingLineParserException e, String expectedErrorParam) {
073: assertEquals(
074: KFSKeyConstants.AccountingLineParser.ERROR_INVALID_PROPERTY_VALUE,
075: e.getErrorKey());
076: List<String> errorParams = Arrays
077: .asList(e.getErrorParameters());
078: assertTrue(errorParams + " contains '" + expectedErrorParam
079: + "'", errorParams.contains(expectedErrorParam));
080: }
081:
082: /**
083: */
084: public void testParseTargetAccountingLine_failure_notANumber() {
085: try {
086: parser.parseTargetAccountingLine(accountingDocument,
087: "BL,4631672, , ,KUL, , , b");
088: fail("didn't throw AccountingLineParserException");
089: } catch (AccountingLineParserException e) {
090: // good
091: assertInvalidPropertyValue(e, " b");
092: }
093: }
094:
095: /**
096: */
097: public void testParseSourceAccountingLine_pass_upperCase() {
098: String chartOfAccountsCode = "BL";
099: String accountNumber = "463172";
100: String projectCode = "KUL";
101: String amount = "12.31";
102:
103: StringBuffer sb = new StringBuffer();
104: sb.append(chartOfAccountsCode);
105: sb.append(",");
106: sb.append(accountNumber);
107: sb.append(",,,,");
108: sb.append(projectCode);
109: sb.append(",,");
110: sb.append(amount);
111: SourceAccountingLine result = parser.parseSourceAccountingLine(
112: accountingDocument, sb.toString());
113:
114: assertEquals(accountingDocument.getPostingYear(), result
115: .getPostingYear());
116: assertEquals(accountingDocument.getDocumentNumber(), result
117: .getDocumentNumber());
118: assertEquals(accountingDocument.getSourceAccountingLines()
119: .size() + 1, result.getSequenceNumber().intValue());
120: assertEquals(chartOfAccountsCode, result
121: .getChartOfAccountsCode());
122: assertEquals(accountNumber, result.getAccountNumber());
123: assertEquals(projectCode, result.getProjectCode());
124: assertEquals(new KualiDecimal(amount), result.getAmount());
125: }
126:
127: /**
128: */
129: public void testParseSourceAccountingLine_pass_lowerCase() {
130: String chartOfAccountsCode = "bl";
131: String accountNumber = "463172";
132: String projectCode = "kul";
133: String amount = "12.31";
134:
135: StringBuffer sb = new StringBuffer();
136: sb.append(chartOfAccountsCode);
137: sb.append(",");
138: sb.append(accountNumber);
139: sb.append(",,,,");
140: sb.append(projectCode);
141: sb.append(",,");
142: sb.append(amount);
143: SourceAccountingLine result = parser.parseSourceAccountingLine(
144: accountingDocument, sb.toString());
145:
146: assertEquals(accountingDocument.getPostingYear(), result
147: .getPostingYear());
148: assertEquals(accountingDocument.getDocumentNumber(), result
149: .getDocumentNumber());
150: assertEquals(accountingDocument.getSourceAccountingLines()
151: .size() + 1, result.getSequenceNumber().intValue());
152: assertEquals(chartOfAccountsCode.toUpperCase(), result
153: .getChartOfAccountsCode());
154: assertEquals(accountNumber, result.getAccountNumber());
155: assertEquals(projectCode.toUpperCase(), result.getProjectCode());
156: assertEquals(new KualiDecimal(amount), result.getAmount());
157: }
158:
159: /**
160: */
161: public void testParseTargetAccountingLine_pass_upperCase() {
162: String chartOfAccountsCode = "BL";
163: String accountNumber = "463172";
164: String projectCode = "KUL";
165: String amount = "12.31";
166:
167: StringBuffer sb = new StringBuffer();
168: sb.append(chartOfAccountsCode);
169: sb.append(",");
170: sb.append(accountNumber);
171: sb.append(",,,,");
172: sb.append(projectCode);
173: sb.append(",,");
174: sb.append(amount);
175: TargetAccountingLine result = parser.parseTargetAccountingLine(
176: accountingDocument, sb.toString());
177:
178: assertEquals(accountingDocument.getPostingYear(), result
179: .getPostingYear());
180: assertEquals(accountingDocument.getDocumentNumber(), result
181: .getDocumentNumber());
182: assertEquals(accountingDocument.getTargetAccountingLines()
183: .size() + 1, result.getSequenceNumber().intValue());
184: assertEquals(chartOfAccountsCode, result
185: .getChartOfAccountsCode());
186: assertEquals(accountNumber, result.getAccountNumber());
187: assertEquals(projectCode, result.getProjectCode());
188: assertEquals(new KualiDecimal(amount), result.getAmount());
189: }
190:
191: /**
192: */
193: public void testParseTargetAccountingLine_pass_lowerCase() {
194: String chartOfAccountsCode = "bl";
195: String accountNumber = "463172";
196: String projectCode = "kul";
197: String amount = "12.31";
198:
199: StringBuffer sb = new StringBuffer();
200: sb.append(chartOfAccountsCode);
201: sb.append(",");
202: sb.append(accountNumber);
203: sb.append(",,,,");
204: sb.append(projectCode);
205: sb.append(",,");
206: sb.append(amount);
207: TargetAccountingLine result = parser.parseTargetAccountingLine(
208: accountingDocument, sb.toString());
209:
210: assertEquals(accountingDocument.getPostingYear(), result
211: .getPostingYear());
212: assertEquals(accountingDocument.getDocumentNumber(), result
213: .getDocumentNumber());
214: assertEquals(accountingDocument.getTargetAccountingLines()
215: .size() + 1, result.getSequenceNumber().intValue());
216: assertEquals(chartOfAccountsCode.toUpperCase(), result
217: .getChartOfAccountsCode());
218: assertEquals(accountNumber, result.getAccountNumber());
219: assertEquals(projectCode.toUpperCase(), result.getProjectCode());
220: assertEquals(new KualiDecimal(amount), result.getAmount());
221: }
222:
223: /**
224: */
225: public void testImportSourceAccountingLine_pass() {
226: String chartOfAccountsCode = "bl";
227: String accountNumber = "463172";
228: String projectCode = "kul";
229: String amount = "12.31";
230:
231: StringBuffer sb = new StringBuffer();
232: sb.append(chartOfAccountsCode);
233: sb.append(",");
234: sb.append(accountNumber);
235: sb.append(",,,,");
236: sb.append(projectCode);
237: sb.append(",,");
238: sb.append(amount);
239: List<SourceAccountingLine> lineList = parser
240: .importSourceAccountingLines(null,
241: new ByteArrayInputStream(sb.toString()
242: .getBytes()), accountingDocument);
243: for (SourceAccountingLine result : lineList) {
244: assertEquals(accountingDocument.getPostingYear(), result
245: .getPostingYear());
246: assertEquals(accountingDocument.getDocumentNumber(), result
247: .getDocumentNumber());
248: assertEquals(accountingDocument.getSourceAccountingLines()
249: .size() + 1, result.getSequenceNumber().intValue());
250: assertEquals(chartOfAccountsCode.toUpperCase(), result
251: .getChartOfAccountsCode());
252: assertEquals(accountNumber, result.getAccountNumber());
253: assertEquals(projectCode.toUpperCase(), result
254: .getProjectCode());
255: assertEquals(new KualiDecimal(amount), result.getAmount());
256: }
257: }
258: //
259: // public void testImportSourceAccountingLines() throws Exception {
260: // List result = null;
261: // List expected = null;
262: // TransactionalDocument document = getDocument();
263: //
264: // expected = getImportSourceAccountingLinesExpected(document);
265: // result = getAccountingLineParser().importSourceAccountingLines(getImportSourceAccountingLinesFixture(), document);
266: // assertTrue((result != null));
267: // assertEquals(expected.toString(), result.toString());
268: // }
269: //
270: // public void testImportTargetAccountingLines() throws Exception {
271: // List result = null;
272: // List expected = null;
273: // TransactionalDocument document = getDocument();
274: //
275: // expected = getImportTargetAccountingLinesExpected(document);
276: // result = getAccountingLineParser().importTargetAccountingLines(getImportTargetAccountingLinesFixture(), document);
277: // assertTrue((result != null));
278: // assertEquals(expected.toString(), result.toString());
279: // }
280: //
281: // /**
282: // * KULEDOCS-1317
283: // *
284: // * @throws Exception
285: // */
286: // public void testImportSourceAccountingLines_lowerCase() throws Exception {
287: // StringBuffer buffer = new
288: // StringBuffer().append(StringUtils.lowerCase(getSerializedTargetAccountingLine())).append("\n").append(StringUtils.lowerCase(getSerializedTargetAccountingLine()));
289: // InputStream input = new ByteArrayInputStream(buffer.toString().getBytes());
290: // List result = null;
291: // List expected = null;
292: // TransactionalDocument document = getDocument();
293: // expected = getImportSourceAccountingLinesExpected(document);
294: // result = getAccountingLineParser().importSourceAccountingLines(input, document);
295: // assertTrue((result != null));
296: // assertEquals(expected.toString(), result.toString());
297: // }
298: }
|