001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.gl.service;
017:
018: import java.util.List;
019:
020: import org.kuali.core.service.DateTimeService;
021: import org.kuali.core.util.Guid;
022: import org.kuali.core.util.UnitTestSqlDao;
023: import org.kuali.kfs.context.KualiTestBase;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.test.ConfigureContext;
026:
027: /**
028: * Tests the NighlyOutService
029: */
030: @ConfigureContext
031: public class NightlyOutServiceTest extends KualiTestBase {
032:
033: private NightlyOutService nightlyOutService;
034: private UnitTestSqlDao unitTestSqlDao;
035: private DateTimeService dateTimeService;
036:
037: /**
038: * Initializes the services needed for this test
039: * @see junit.framework.TestCase#setUp()
040: */
041: @Override
042: protected void setUp() throws Exception {
043: super .setUp();
044:
045: nightlyOutService = SpringContext
046: .getBean(NightlyOutService.class);
047: unitTestSqlDao = SpringContext.getBean(UnitTestSqlDao.class);
048: dateTimeService = SpringContext.getBean(DateTimeService.class);
049: }
050:
051: /**
052: * This test validates that the correct data is copied into origin_entry
053: *
054: * @throws Exception thrown if any exception is encountered for any reason
055: */
056: public void testCopyPendingLedgerEntry() throws Exception {
057: // Empty out the origin entry group & origin entry tables
058: unitTestSqlDao.sqlCommand("delete from gl_origin_entry_t");
059: unitTestSqlDao.sqlCommand("delete from gl_origin_entry_grp_t");
060:
061: // Empty out the pending entry table & doc header table
062: unitTestSqlDao
063: .sqlCommand("delete from fp_doc_header_t where fdoc_nbr in ('1','2','3')");
064: unitTestSqlDao.sqlCommand("delete from gl_pending_entry_t");
065:
066: // Add a few documents
067: unitTestSqlDao
068: .sqlCommand("insert into fp_doc_header_t (fdoc_nbr,obj_id,ver_nbr,fdoc_status_cd,fdoc_desc,fdoc_total_amt,org_doc_nbr,"
069: + "fdoc_in_err_nbr,fdoc_tmpl_nbr) values ('1','"
070: + new Guid().toString()
071: + "',1,'A','a',100,'OA',null,null)");
072: unitTestSqlDao
073: .sqlCommand("insert into fp_doc_header_t (fdoc_nbr,obj_id,ver_nbr,fdoc_status_cd,fdoc_desc,fdoc_total_amt,org_doc_nbr,"
074: + "fdoc_in_err_nbr,fdoc_tmpl_nbr) values ('2','"
075: + new Guid().toString()
076: + "',1,'D','b',100,'OB',null,null)");
077: unitTestSqlDao
078: .sqlCommand("insert into fp_doc_header_t (fdoc_nbr,obj_id,ver_nbr,fdoc_status_cd,fdoc_desc,fdoc_total_amt,org_doc_nbr,"
079: + "fdoc_in_err_nbr,fdoc_tmpl_nbr) values ('3','"
080: + new Guid().toString()
081: + "',1,'A','c',100,'OC',null,null)");
082:
083: unitTestSqlDao
084: .sqlCommand("insert into gl_pending_entry_t (fs_origin_cd,fdoc_nbr,trn_entr_seq_nbr,obj_id,ver_nbr,fin_coa_cd,account_nbr,"
085: + "sub_acct_nbr,fin_object_cd,fin_sub_obj_cd,fin_balance_typ_cd,fin_obj_typ_cd,univ_fiscal_yr,univ_fiscal_prd_cd,"
086: + "trn_ldgr_entr_desc,trn_ldgr_entr_amt,trn_debit_crdt_cd,transaction_dt,fdoc_typ_cd,org_doc_nbr,project_cd,"
087: + "org_reference_id,fdoc_ref_typ_cd,fs_ref_origin_cd,fdoc_ref_nbr,fdoc_reversal_dt,trn_encum_updt_cd,fdoc_approved_cd,"
088: + "acct_sf_finobj_cd,trn_entr_ofst_cd,trnentr_process_tm) values ('01','1',1,'"
089: + new Guid().toString()
090: + "',1,'BA','123456',"
091: + "null,'4166',null,'AC','EX',2004,'01',"
092: + "'Description',100,'D',"
093: + unitTestSqlDao.getDbPlatform()
094: .getCurTimeFunction()
095: + ",'JV',null,null,"
096: + "null,null,null,null,null,' ','A',"
097: + "'4166',null,null)");
098: unitTestSqlDao
099: .sqlCommand("insert into gl_pending_entry_t (fs_origin_cd,fdoc_nbr,trn_entr_seq_nbr,obj_id,ver_nbr,fin_coa_cd,account_nbr,"
100: + "sub_acct_nbr,fin_object_cd,fin_sub_obj_cd,fin_balance_typ_cd,fin_obj_typ_cd,univ_fiscal_yr,univ_fiscal_prd_cd,"
101: + "trn_ldgr_entr_desc,trn_ldgr_entr_amt,trn_debit_crdt_cd,transaction_dt,fdoc_typ_cd,org_doc_nbr,project_cd,"
102: + "org_reference_id,fdoc_ref_typ_cd,fs_ref_origin_cd,fdoc_ref_nbr,fdoc_reversal_dt,trn_encum_updt_cd,fdoc_approved_cd,"
103: + "acct_sf_finobj_cd,trn_entr_ofst_cd,trnentr_process_tm) values ('01','1',2,'"
104: + new Guid().toString()
105: + "',1,'BA','123456',"
106: + "null,'4166',null,'AC','EX',2004,'01',"
107: + "'Description',100,'C',"
108: + unitTestSqlDao.getDbPlatform()
109: .getCurTimeFunction()
110: + ",'JV',null,null,"
111: + "null,null,null,null,null,' ',null,"
112: + "'4166',null,null)");
113: unitTestSqlDao
114: .sqlCommand("insert into gl_pending_entry_t (fs_origin_cd,fdoc_nbr,trn_entr_seq_nbr,obj_id,ver_nbr,fin_coa_cd,account_nbr,"
115: + "sub_acct_nbr,fin_object_cd,fin_sub_obj_cd,fin_balance_typ_cd,fin_obj_typ_cd,univ_fiscal_yr,univ_fiscal_prd_cd,"
116: + "trn_ldgr_entr_desc,trn_ldgr_entr_amt,trn_debit_crdt_cd,transaction_dt,fdoc_typ_cd,org_doc_nbr,project_cd,"
117: + "org_reference_id,fdoc_ref_typ_cd,fs_ref_origin_cd,fdoc_ref_nbr,fdoc_reversal_dt,trn_encum_updt_cd,fdoc_approved_cd,"
118: + "acct_sf_finobj_cd,trn_entr_ofst_cd,trnentr_process_tm) values ('01','2',3,'"
119: + new Guid().toString()
120: + "',1,'BA','123456',"
121: + "null,'4166',null,'AC','EX',2004,'01',"
122: + "'Description',100,'D',"
123: + unitTestSqlDao.getDbPlatform()
124: .getCurTimeFunction()
125: + ",'JV',null,null,"
126: + "null,null,null,null,null,' ','A',"
127: + "'4166',null,null)");
128: unitTestSqlDao
129: .sqlCommand("insert into gl_pending_entry_t (fs_origin_cd,fdoc_nbr,trn_entr_seq_nbr,obj_id,ver_nbr,fin_coa_cd,account_nbr,"
130: + "sub_acct_nbr,fin_object_cd,fin_sub_obj_cd,fin_balance_typ_cd,fin_obj_typ_cd,univ_fiscal_yr,univ_fiscal_prd_cd,"
131: + "trn_ldgr_entr_desc,trn_ldgr_entr_amt,trn_debit_crdt_cd,transaction_dt,fdoc_typ_cd,org_doc_nbr,project_cd,"
132: + "org_reference_id,fdoc_ref_typ_cd,fs_ref_origin_cd,fdoc_ref_nbr,fdoc_reversal_dt,trn_encum_updt_cd,fdoc_approved_cd,"
133: + "acct_sf_finobj_cd,trn_entr_ofst_cd,trnentr_process_tm) values ('01','2',4,'"
134: + new Guid().toString()
135: + "',1,'BA','123456',"
136: + "null,'4166',null,'AC','EX',2004,'01',"
137: + "'Description',100,'C',"
138: + unitTestSqlDao.getDbPlatform()
139: .getCurTimeFunction()
140: + ",'JV',null,null,"
141: + "null,null,null,null,null,' ',null,"
142: + "'4166',null,null)");
143: unitTestSqlDao
144: .sqlCommand("insert into gl_pending_entry_t (fs_origin_cd,fdoc_nbr,trn_entr_seq_nbr,obj_id,ver_nbr,fin_coa_cd,account_nbr,"
145: + "sub_acct_nbr,fin_object_cd,fin_sub_obj_cd,fin_balance_typ_cd,fin_obj_typ_cd,univ_fiscal_yr,univ_fiscal_prd_cd,"
146: + "trn_ldgr_entr_desc,trn_ldgr_entr_amt,trn_debit_crdt_cd,transaction_dt,fdoc_typ_cd,org_doc_nbr,project_cd,"
147: + "org_reference_id,fdoc_ref_typ_cd,fs_ref_origin_cd,fdoc_ref_nbr,fdoc_reversal_dt,trn_encum_updt_cd,fdoc_approved_cd,"
148: + "acct_sf_finobj_cd,trn_entr_ofst_cd,trnentr_process_tm) values ('01','3',5,'"
149: + new Guid().toString()
150: + "',1,'BA','123456',"
151: + "null,'4166',null,'AC','EX',2004,'01',"
152: + "'Description',100,'D',"
153: + unitTestSqlDao.getDbPlatform()
154: .getCurTimeFunction()
155: + ",'JV',null,null,"
156: + "null,null,null,null,null,' ','X',"
157: + "'4166',null,null)");
158: unitTestSqlDao
159: .sqlCommand("insert into gl_pending_entry_t (fs_origin_cd,fdoc_nbr,trn_entr_seq_nbr,obj_id,ver_nbr,fin_coa_cd,account_nbr,"
160: + "sub_acct_nbr,fin_object_cd,fin_sub_obj_cd,fin_balance_typ_cd,fin_obj_typ_cd,univ_fiscal_yr,univ_fiscal_prd_cd,"
161: + "trn_ldgr_entr_desc,trn_ldgr_entr_amt,trn_debit_crdt_cd,transaction_dt,fdoc_typ_cd,org_doc_nbr,project_cd,"
162: + "org_reference_id,fdoc_ref_typ_cd,fs_ref_origin_cd,fdoc_ref_nbr,fdoc_reversal_dt,trn_encum_updt_cd,fdoc_approved_cd,"
163: + "acct_sf_finobj_cd,trn_entr_ofst_cd,trnentr_process_tm) values ('01','3',6,'"
164: + new Guid().toString()
165: + "',1,'BA','123456',"
166: + "null,'4166',null,'AC','EX',2004,'01',"
167: + "'Description',100,'C',"
168: + unitTestSqlDao.getDbPlatform()
169: .getCurTimeFunction()
170: + ",'JV',null,null,"
171: + "null,null,null,null,null,' ','X',"
172: + "'4166',null,null)");
173:
174: nightlyOutService.copyApprovedPendingLedgerEntries();
175:
176: List groups = unitTestSqlDao
177: .sqlSelect("select * from gl_origin_entry_grp_t");
178: assertEquals("Should have 1 group", 1, groups.size());
179:
180: List entries = unitTestSqlDao
181: .sqlSelect("select * from gl_origin_entry_t");
182: assertEquals("Should have 2 entries", 2, entries.size());
183:
184: // 2 transactions were set to X to start with, 2 were marked as X when copyApprovedPendingLedgerEntries was run
185: List pendingEntries = unitTestSqlDao
186: .sqlSelect("select * from gl_pending_entry_t where fdoc_approved_cd = 'X'");
187: assertEquals("Should have 4 copied entries", 4, pendingEntries
188: .size());
189:
190: nightlyOutService.deleteCopiedPendingLedgerEntries();
191: List remainderEntries = unitTestSqlDao
192: .sqlSelect("select * from gl_pending_entry_t");
193: assertEquals("Should have 2 remaining entries", 2,
194: remainderEntries.size());
195: }
196: }
|