001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.gl.service;
017:
018: import java.util.Iterator;
019:
020: import org.kuali.core.service.DateTimeService;
021: import org.kuali.core.util.KualiDecimal;
022: import org.kuali.kfs.KFSConstants;
023: import org.kuali.kfs.bo.GeneralLedgerPendingEntry;
024: import org.kuali.kfs.context.KualiTestBase;
025: import org.kuali.kfs.context.SpringContext;
026: import org.kuali.kfs.service.GeneralLedgerPendingEntryService;
027: import org.kuali.test.ConfigureContext;
028:
029: /**
030: * This class tests the GeneralLedgerPending service.
031: */
032: @ConfigureContext
033: public class GeneralLedgerPendingEntryServiceTest extends KualiTestBase {
034: private GeneralLedgerPendingEntryService generalLedgerPendingEntryService;
035: private final String docHeaderId = "1003";
036:
037: /**
038: * Initalizes the services needef or this test; also, since this test creates a fake document, deletes
039: * any entries from the real version of that document if they exist
040: * @see junit.framework.TestCase#setUp()
041: */
042: @Override
043: protected void setUp() throws Exception {
044: super .setUp();
045:
046: if (generalLedgerPendingEntryService == null) {
047: generalLedgerPendingEntryService = SpringContext
048: .getBean(GeneralLedgerPendingEntryService.class);
049: }
050: // Make sure the document doesn't exist before each test
051: generalLedgerPendingEntryService.delete(docHeaderId);
052: }
053:
054: /**
055: * Tests that pending entries are saved and retrieved properly
056: *
057: * @throws Exception thrown if any exception is encountered for any reason
058: */
059: public void testSave() throws Exception {
060: GeneralLedgerPendingEntry testEntry = this
061: .createGeneralLedgerPendingEntry();
062: generalLedgerPendingEntryService.save(testEntry);
063: GeneralLedgerPendingEntry generalLedgerPendingEntry = generalLedgerPendingEntryService
064: .getByPrimaryId(testEntry
065: .getTransactionLedgerEntrySequenceNumber(),
066: docHeaderId);
067: assertNotNull("Save didn't save this entry",
068: generalLedgerPendingEntry);
069: generalLedgerPendingEntryService.delete(docHeaderId);
070: }
071:
072: /**
073: * Covers GeneralPendingLedgerEntryService.getByPrimaryId (though, yeah, testSave does too, technically)
074: *
075: * @throws Exception thrown if any exception is encountered for any reason
076: */
077: public void testGetByPrimaryId() throws Exception {
078: GeneralLedgerPendingEntry testEntry = this
079: .createGeneralLedgerPendingEntry();
080: generalLedgerPendingEntryService.save(testEntry);
081: GeneralLedgerPendingEntry generalLedgerPendingEntry = generalLedgerPendingEntryService
082: .getByPrimaryId(testEntry
083: .getTransactionLedgerEntrySequenceNumber(),
084: docHeaderId);
085: assertNotNull("getByPrimaryId didn't get this entry",
086: generalLedgerPendingEntry);
087: generalLedgerPendingEntryService.delete(docHeaderId);
088: }
089:
090: /**
091: * Covers GeneralLedgerPendingEntryService.delete
092: *
093: * @throws Exception thrown if any exception is encountered for any reason
094: */
095: public void testDelete() throws Exception {
096: GeneralLedgerPendingEntry generalLedgerPendingEntry = this
097: .createGeneralLedgerPendingEntry();
098: generalLedgerPendingEntryService
099: .save(generalLedgerPendingEntry);
100: generalLedgerPendingEntryService.delete(docHeaderId);
101: generalLedgerPendingEntry = generalLedgerPendingEntryService
102: .getByPrimaryId(generalLedgerPendingEntry
103: .getTransactionLedgerEntrySequenceNumber(),
104: docHeaderId);
105: assertNull("Delete didn't delete this entry",
106: generalLedgerPendingEntry);
107: }
108:
109: /**
110: * Covers GeneralLedgerPendingEntryService.findApprovedPendingLedgerEntries
111: */
112: public void testFindApprovedPendingLedgerEntries() {
113: try {
114: GeneralLedgerPendingEntry generalLedgerPendingEntry = this
115: .createGeneralLedgerPendingEntry();
116: generalLedgerPendingEntryService
117: .save(generalLedgerPendingEntry);
118:
119: Iterator entries = generalLedgerPendingEntryService
120: .findApprovedPendingLedgerEntries();
121:
122: int counter = 0;
123: while (entries.hasNext()) {
124: generalLedgerPendingEntry = (GeneralLedgerPendingEntry) (entries
125: .next());
126: ++counter;
127:
128: System.out
129: .println(counter
130: + ":"
131: + generalLedgerPendingEntry
132: .getDocumentNumber());
133: }
134: } catch (Exception e) {
135: assertTrue("Failed to fetch all entries", true);
136: } finally {
137: generalLedgerPendingEntryService.delete(docHeaderId);
138: }
139: }
140:
141: /**
142: * Creates a pending entry fixture
143: *
144: * @return a pending entry to test against
145: */
146: private GeneralLedgerPendingEntry createGeneralLedgerPendingEntry() {
147: GeneralLedgerPendingEntry generalLedgerPendingEntry = new GeneralLedgerPendingEntry();
148:
149: generalLedgerPendingEntry
150: .setFinancialSystemOriginationCode("01");
151: generalLedgerPendingEntry.setDocumentNumber(docHeaderId);
152: generalLedgerPendingEntry.setChartOfAccountsCode("BA");
153: generalLedgerPendingEntry.setFinancialObjectCode("1130");
154: generalLedgerPendingEntry.setFinancialBalanceTypeCode("AX");
155: generalLedgerPendingEntry.setFinancialObjectTypeCode("AS");
156: generalLedgerPendingEntry.setUniversityFiscalYear(new Integer(
157: 2005));
158: generalLedgerPendingEntry.setUniversityFiscalPeriodCode("7");
159: generalLedgerPendingEntry
160: .setTransactionLedgerEntryAmount(new KualiDecimal("8.8"));
161: generalLedgerPendingEntry
162: .setTransactionLedgerEntryDescription("9");
163: generalLedgerPendingEntry.setTransactionDebitCreditCode("D");
164: generalLedgerPendingEntry.setTransactionDate(new java.sql.Date(
165: SpringContext.getBean(DateTimeService.class)
166: .getCurrentDate().getTime()));
167: generalLedgerPendingEntry.setFinancialDocumentTypeCode("12");
168: generalLedgerPendingEntry
169: .setTransactionLedgerEntrySequenceNumber(new Integer(1));
170: generalLedgerPendingEntry
171: .setFinancialDocumentApprovedCode(KFSConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.APPROVED);
172: return generalLedgerPendingEntry;
173: }
174: }
|