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.module.ar.businessobject.lookup;
20  
21  import static org.kuali.kfs.sys.fixture.UserNameFixture.khuntley;
22  
23  import java.text.DateFormat;
24  import java.text.SimpleDateFormat;
25  import java.util.ArrayList;
26  import java.util.Collection;
27  import java.util.Date;
28  import java.util.LinkedHashMap;
29  import java.util.Map;
30  
31  import org.kuali.kfs.module.ar.businessobject.CustomerAgingReportDetail;
32  import org.kuali.kfs.module.ar.web.struts.CustomerAgingReportForm;
33  import org.kuali.kfs.sys.ConfigureContext;
34  import org.kuali.kfs.sys.KFSPropertyConstants;
35  import org.kuali.kfs.sys.context.KualiTestBase;
36  import org.kuali.kfs.sys.context.SpringContext;
37  import org.kuali.rice.core.api.datetime.DateTimeService;
38  import org.kuali.rice.core.api.util.type.KualiDecimal;
39  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
40  import org.kuali.rice.krad.service.BusinessObjectService;
41  
42  /**
43   * This class tests the CustomerAgingReport lookup and totals calculations
44   */
45  @ConfigureContext(session = khuntley)
46  public class CustomerAgingReportLookupableHelperServiceImplTest extends KualiTestBase {
47  
48      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CustomerAgingReportLookupableHelperServiceImplTest.class);
49  
50      private CustomerAgingReportLookupableHelperServiceImpl customerAgingReportLookupableHelperServiceImpl;
51      private CustomerAgingReportForm customerAgingReportForm;
52      private Map fieldValues;
53  
54      /**
55       * @see junit.framework.TestCase#setUp()
56       */
57      @Override
58      protected void setUp() throws Exception {
59          super.setUp();
60          customerAgingReportLookupableHelperServiceImpl = new CustomerAgingReportLookupableHelperServiceImpl();
61          customerAgingReportLookupableHelperServiceImpl.setBusinessObjectService(SpringContext.getBean(BusinessObjectService.class));
62          customerAgingReportLookupableHelperServiceImpl.setParameterService(SpringContext.getBean(ParameterService.class));
63          customerAgingReportLookupableHelperServiceImpl.setDateTimeService(SpringContext.getBean(DateTimeService.class));
64          customerAgingReportLookupableHelperServiceImpl.afterPropertiesSet();
65          fieldValues = new LinkedHashMap();
66          DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
67          fieldValues.put("backLocation", null);
68          fieldValues.put(KFSPropertyConstants.ACCOUNT_NUMBER, "1111111");
69          fieldValues.put("reportRunDate", dateFormat.format(new Date()));
70          fieldValues.put("reportOption", "Account");
71          fieldValues.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, "");
72          fieldValues.put(KFSPropertyConstants.ORGANIZATION_CODE, "");
73          fieldValues.put("docFormKey", null);
74      }
75  
76      /**
77       * @see junit.framework.TestCase#tearDown()
78       */
79      @Override
80      protected void tearDown() throws Exception {
81          super.tearDown();
82      }
83  
84      /**
85       * Test method for
86       * {@link org.kuali.kfs.module.ar.businessobject.lookup.CustomerAgingReportLookupableHelperServiceImpl#getSearchResults(java.util.Map)}
87       * .
88       */
89      public void testGetSearchResultsMap() {
90          Collection<?> displayList;
91  
92          // run search
93          KualiDecimal test0to30total = new KualiDecimal("0.00");
94          KualiDecimal test31to60total = new KualiDecimal("0.00");
95          KualiDecimal test61to90total = new KualiDecimal("0.00");
96          KualiDecimal test91toSYSPRtotal = new KualiDecimal("0.00");
97          KualiDecimal testSYSPRplus1orMoretotal = new KualiDecimal("0.00");
98          assertNotNull("search results not null", displayList = customerAgingReportLookupableHelperServiceImpl.getSearchResults(fieldValues));
99  
100         // add all 0to30 totals
101         for (Object aDisplayList : displayList) {
102             CustomerAgingReportDetail detail = (CustomerAgingReportDetail) aDisplayList;
103             test0to30total = test0to30total.add(detail.getUnpaidBalance0to30());
104             test31to60total = test31to60total.add(detail.getUnpaidBalance31to60());
105             test61to90total = test61to90total.add(detail.getUnpaidBalance61to90());
106             test91toSYSPRtotal = test91toSYSPRtotal.add(detail.getUnpaidBalance91toSYSPR());
107             testSYSPRplus1orMoretotal = testSYSPRplus1orMoretotal.add(detail.getUnpaidBalanceSYSPRplus1orMore());
108         }
109         assertEquals(customerAgingReportLookupableHelperServiceImpl.getTotal0to30().toString(), test0to30total.toString());
110         assertEquals(customerAgingReportLookupableHelperServiceImpl.getTotal31to60().toString(), test31to60total.toString());
111         assertEquals(customerAgingReportLookupableHelperServiceImpl.getTotal61to90().toString(), test61to90total.toString());
112         LOG.info("\n\n\n\n***************************************************************************************\n" + "\n\t\t testtotal0to30 = " + customerAgingReportLookupableHelperServiceImpl.getTotal0to30().toString() + "\t\t\t\t\tactualtotal0to30 = " + test0to30total.toString() + "\n\t\t testtotal31to60 = " + customerAgingReportLookupableHelperServiceImpl.getTotal31to60().toString() + "\t\t\t\t\t\tactualtotal31to60 = " + test31to60total.toString() + "\n\t\t testtotal61to90 = " + customerAgingReportLookupableHelperServiceImpl.getTotal61to90().toString() + "\t\t\t\t\t\tactualtotal61to90 = " + test61to90total.toString() + "\n\t\t testtotal91toSYSPR = " + customerAgingReportLookupableHelperServiceImpl.getTotal91toSYSPR().toString() + "\t\t\t\t\tactualtotal91toSYSPR = " + test91toSYSPRtotal.toString() + "\n\t\t testtotalSYSPRplus1orMore = " + customerAgingReportLookupableHelperServiceImpl.getTotalSYSPRplus1orMore().toString() + "\t\t\tactualtotalSYSPRplus1orMore = "
113                 + testSYSPRplus1orMoretotal.toString() + "\n\n***************************************************************************************\n\n");
114     }
115 
116     /**
117      * Test method for
118      * {@link org.kuali.kfs.module.ar.businessobject.lookup.CustomerAgingReportLookupableHelperServiceImpl#performLookup(org.kuali.rice.kns.web.struts.form.LookupForm, java.util.Collection, boolean)}
119      * .
120      */
121     public void testPerformLookupLookupFormCollectionBoolean() {
122 
123         customerAgingReportForm = new CustomerAgingReportForm();
124         customerAgingReportForm.setFieldsForLookup(fieldValues);
125 
126         Collection resultTable = new ArrayList<String>();
127         assertNotNull("lookup list not null", customerAgingReportLookupableHelperServiceImpl.performLookup(customerAgingReportForm, resultTable, true));
128     }
129 
130 }