View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sys.report;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.kuali.kfs.gl.businessobject.GlSummary;
26  import org.kuali.kfs.gl.businessobject.LedgerEntryForReporting;
27  import org.kuali.kfs.sys.ConfigureContext;
28  import org.kuali.kfs.sys.batch.service.WrappingBatchService;
29  import org.kuali.kfs.sys.context.KualiTestBase;
30  import org.kuali.kfs.sys.context.SpringContext;
31  import org.kuali.kfs.sys.service.ReportWriterService;
32  
33  @ConfigureContext
34  public class ReportWriterServiceTest extends KualiTestBase {
35      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ReportWriterServiceTest.class);
36      
37      protected ReportWriterService tableReportWriterService;
38      protected ReportWriterService colspanTableReportWriterService;
39      protected ReportWriterService ledgerReportWriterService;
40  
41      @Override
42      public void setUp() throws Exception {
43          super.setUp();
44  
45          Map<String, ReportWriterService> businessObjectReportHelperBeans = SpringContext.getBeansOfType(ReportWriterService.class);
46          tableReportWriterService = businessObjectReportHelperBeans.get("tableReportWriterService");
47          colspanTableReportWriterService = businessObjectReportHelperBeans.get("colspanTableReportWriterService");
48          ledgerReportWriterService = businessObjectReportHelperBeans.get("testLedgerReportWriterService");
49      }
50  
51      /**
52       * @see junit.framework.TestCase#tearDown()
53       */
54      @Override
55      protected void tearDown() throws Exception {
56          super.tearDown();
57          
58          ((WrappingBatchService) tableReportWriterService).destroy();
59          ((WrappingBatchService) colspanTableReportWriterService).destroy();
60          ((WrappingBatchService) ledgerReportWriterService).destroy();
61      }
62      
63      public void testWriteTable() throws Exception{             
64          ((WrappingBatchService) tableReportWriterService).initialize();
65          
66          List<GlSummary> summaryList = this.getTestData(40);
67          tableReportWriterService.writeTable(summaryList, true, false);
68      }
69      
70      public void testWriteRowWithColspan() throws Exception{
71          ((WrappingBatchService) colspanTableReportWriterService).initialize();
72          
73          List<GlSummary> summaryList = this.getTestData(20);
74          colspanTableReportWriterService.writeTableHeader(summaryList.get(0));
75          
76          int index = 1;
77          for(GlSummary summary : summaryList) {
78              colspanTableReportWriterService.writeTableRow(summary);
79              
80              if(index++ % 5 == 0) {
81                  GlSummary subTotal = new GlSummary();
82                  subTotal.setFundGroup("Sub Totals (AC):");
83                  
84                  colspanTableReportWriterService.writeTableRowWithColspan(subTotal);                
85                  colspanTableReportWriterService.writeTableRowSeparationLine(summary);
86              }
87          }
88          
89          GlSummary grandTotal = new GlSummary();
90          grandTotal.setFundGroup("Grand Totals (AC):");
91          colspanTableReportWriterService.writeTableRowWithColspan(grandTotal);
92      }
93      
94      public void testLedgerReport() throws Exception{             
95          ((WrappingBatchService) ledgerReportWriterService).initialize();
96          
97          List<LedgerEntryForReporting> ledgerEntries = this.getLedgerEntryTestData(40);
98          ledgerReportWriterService.writeTable(ledgerEntries, true, false);
99      }
100 
101     protected List<LedgerEntryForReporting> getLedgerEntryTestData(int countOfData) {
102         List<LedgerEntryForReporting> ledgerEntries = new ArrayList<LedgerEntryForReporting>();
103         for(int i = 0; i < countOfData; i++) {
104             LedgerEntryForReporting entry = new LedgerEntryForReporting();
105             entry.setBalanceType("Bal-" + i);
106             entry.setFiscalYear(2000 + i);
107             entry.setOriginCode("0" + i);
108             entry.setPeriod("P-" + i);
109             
110             ledgerEntries.add(entry);
111         }
112         
113         return ledgerEntries;
114     }
115 
116     protected List<GlSummary> getTestData(int countOfData) {
117         List<GlSummary> summaryList = new ArrayList<GlSummary>();
118         for(int i = 0; i < countOfData; i++) {
119             GlSummary summary = new GlSummary();
120             summary.setFundGroup("FG-" + i);
121             
122             summaryList.add(summary);
123         }
124         
125         return summaryList;
126     }
127 }