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.wklykins;
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.List;
30  import java.util.Map;
31  
32  import org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward;
33  import org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount;
34  import org.kuali.kfs.module.ar.businessobject.ContractsAndGrantsAgingReport;
35  import org.kuali.kfs.module.ar.businessobject.InvoiceAddressDetail;
36  import org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument;
37  import org.kuali.kfs.module.ar.document.service.CustomerCreditMemoDocumentService;
38  import org.kuali.kfs.module.ar.fixture.ARAwardAccountFixture;
39  import org.kuali.kfs.module.ar.fixture.ARAwardFixture;
40  import org.kuali.kfs.module.ar.report.service.ContractsGrantsAgingReportService;
41  import org.kuali.kfs.module.ar.report.service.CustomerAgingReportService;
42  import org.kuali.kfs.module.ar.service.ContractsGrantsInvoiceCreateDocumentService;
43  import org.kuali.kfs.module.ar.web.struts.ContractsGrantsAgingReportForm;
44  import org.kuali.kfs.module.cg.businessobject.Award;
45  import org.kuali.kfs.sys.ConfigureContext;
46  import org.kuali.kfs.sys.KFSConstants;
47  import org.kuali.kfs.sys.context.KualiTestBase;
48  import org.kuali.kfs.sys.context.SpringContext;
49  import org.kuali.rice.core.api.datetime.DateTimeService;
50  import org.kuali.rice.core.api.util.type.KualiDecimal;
51  import org.kuali.rice.krad.service.BusinessObjectService;
52  import org.kuali.rice.krad.service.DocumentService;
53  import org.kuali.rice.krad.service.KualiModuleService;
54  import org.kuali.rice.krad.util.ErrorMessage;
55  
56  /**
57   * This class tests the ContractsGrantsAgingReport lookup
58   */
59  @ConfigureContext(session = wklykins)
60  public class ContractsGrantsAgingReportLookupableHelperServiceImplTest extends KualiTestBase {
61  
62      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ContractsGrantsAgingReportLookupableHelperServiceImplTest.class);
63  
64      private ContractsGrantsAgingReportLookupableHelperServiceImpl contractsGrantsAgingReportLookupableHelperServiceImpl;
65      private ContractsGrantsAgingReportForm contractsGrantsAgingReportForm;
66      private Map fieldValues;
67  
68      /**
69       * @see junit.framework.TestCase#setUp()
70       */
71      @Override
72      protected void setUp() throws Exception {
73          super.setUp();
74  
75          // setting up document
76          String chartCode = "BL";
77          String orgCode = "UGCS";
78          String customerNumber = "ABB2";
79          String customerName = "WOODS CORPORATION";
80  
81          // To create a basic invoice with test data
82          DocumentService documentService = SpringContext.getBean(DocumentService.class);
83          ContractsAndGrantsBillingAward award = ARAwardFixture.CG_AWARD_MONTHLY_BILLED_DATE_NULL.createAward();
84          ContractsAndGrantsBillingAwardAccount awardAccount_1 = ARAwardAccountFixture.AWD_ACCT_1.createAwardAccount();
85          List<ContractsAndGrantsBillingAwardAccount> awardAccounts = new ArrayList<ContractsAndGrantsBillingAwardAccount>();
86          awardAccounts.add(awardAccount_1);
87          award.getActiveAwardAccounts().clear();
88  
89          award.getActiveAwardAccounts().add(awardAccount_1);
90          award = ARAwardFixture.CG_AWARD_MONTHLY_BILLED_DATE_NULL.setAgencyFromFixture((Award) award);
91  
92          List<ErrorMessage> errorMessages = new ArrayList<ErrorMessage>();
93          ContractsGrantsInvoiceDocument cgInvoice = SpringContext.getBean(ContractsGrantsInvoiceCreateDocumentService.class).createCGInvoiceDocumentByAwardInfo(award, awardAccounts, chartCode, orgCode, errorMessages, null, null);
94          cgInvoice.getFinancialSystemDocumentHeader().setFinancialDocumentStatusCode(KFSConstants.DocumentStatusCodes.APPROVED);
95          cgInvoice.getAccountsReceivableDocumentHeader().setCustomerNumber(customerNumber);
96          cgInvoice.getAccountsReceivableDocumentHeader().setDocumentHeader(cgInvoice.getDocumentHeader());
97  
98          cgInvoice.setBillingDate(new java.sql.Date(new Date().getTime()));
99          cgInvoice.getInvoiceGeneralDetail().setAward(award);
100         cgInvoice.setOpenInvoiceIndicator(true);
101         cgInvoice.setCustomerName(customerName);
102         for (InvoiceAddressDetail invoiceAddressDetail : cgInvoice.getInvoiceAddressDetails()) {
103             invoiceAddressDetail.setCustomerInvoiceTemplateCode("STD");
104             invoiceAddressDetail.setInvoiceTransmissionMethodCode("MAIL");
105         }
106 
107         documentService.saveDocument(cgInvoice);
108 
109         contractsGrantsAgingReportLookupableHelperServiceImpl = new ContractsGrantsAgingReportLookupableHelperServiceImpl();
110         contractsGrantsAgingReportLookupableHelperServiceImpl.setBusinessObjectService(SpringContext.getBean(BusinessObjectService.class));
111         contractsGrantsAgingReportLookupableHelperServiceImpl.setBusinessObjectClass(ContractsAndGrantsAgingReport.class);
112         contractsGrantsAgingReportLookupableHelperServiceImpl.setDateTimeService(SpringContext.getBean(DateTimeService.class));
113         contractsGrantsAgingReportLookupableHelperServiceImpl.setContractsGrantsAgingReportService(SpringContext.getBean(ContractsGrantsAgingReportService.class));
114         contractsGrantsAgingReportLookupableHelperServiceImpl.setCustomerAgingReportService(SpringContext.getBean(CustomerAgingReportService.class));
115         contractsGrantsAgingReportLookupableHelperServiceImpl.setCustomerCreditMemoDocumentService(SpringContext.getBean(CustomerCreditMemoDocumentService.class));
116         contractsGrantsAgingReportLookupableHelperServiceImpl.setModuleService(SpringContext.getBean(KualiModuleService.class));
117         contractsGrantsAgingReportLookupableHelperServiceImpl.afterPropertiesSet();
118         fieldValues = new LinkedHashMap();
119 
120         DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
121         fieldValues.put("backLocation", null);
122         fieldValues.put("reportRunDate", dateFormat.format(new Date()));
123         fieldValues.put("docFormKey", null);
124         fieldValues.put("businessObjectClassName", ContractsAndGrantsAgingReport.class.getName());
125 
126     }
127 
128     /**
129      * @see junit.framework.TestCase#tearDown()
130      */
131     @Override
132     protected void tearDown() throws Exception {
133         super.tearDown();
134     }
135 
136     /**
137      * Test method for
138      * {@link org.kuali.kfs.module.ar.businessobject.lookup.ContractsGrantsAgingReportLookupableHelperServiceImplTest#getSearchResults(java.util.Map)}
139      * .
140      */
141     public void testGetSearchResultsMap() {
142         Collection<?> displayList;
143         // run search
144         KualiDecimal test0to30total = new KualiDecimal("0.00");
145         KualiDecimal test31to60total = new KualiDecimal("0.00");
146         KualiDecimal test61to90total = new KualiDecimal("0.00");
147         KualiDecimal test91toSYSPRtotal = new KualiDecimal("0.00");
148         KualiDecimal testSYSPRplus1orMoretotal = new KualiDecimal("0.00");
149         assertNotNull("search results not null", displayList = contractsGrantsAgingReportLookupableHelperServiceImpl.getSearchResults(fieldValues));
150 
151 
152         // add all 0to30 totals
153         for (Object aDisplayList : displayList) {
154             ContractsAndGrantsAgingReport detail = (ContractsAndGrantsAgingReport) aDisplayList;
155             test0to30total = test0to30total.add(detail.getUnpaidBalance0to30());
156             test31to60total = test31to60total.add(detail.getUnpaidBalance31to60());
157             test61to90total = test61to90total.add(detail.getUnpaidBalance61to90());
158             test91toSYSPRtotal = test91toSYSPRtotal.add(detail.getUnpaidBalance91toSYSPR());
159             testSYSPRplus1orMoretotal = testSYSPRplus1orMoretotal.add(detail.getUnpaidBalanceSYSPRplus1orMore());
160         }
161         assertEquals(contractsGrantsAgingReportLookupableHelperServiceImpl.getTotal0to30().toString(), test0to30total.toString());
162         assertEquals(contractsGrantsAgingReportLookupableHelperServiceImpl.getTotal31to60().toString(), test31to60total.toString());
163         assertEquals(contractsGrantsAgingReportLookupableHelperServiceImpl.getTotal61to90().toString(), test61to90total.toString());
164         LOG.info("\n\n\n\n***************************************************************************************\n" + "\n\t\t testtotal0to30 = " + contractsGrantsAgingReportLookupableHelperServiceImpl.getTotal0to30().toString() + "\t\t\t\t\tactualtotal0to30 = " + test0to30total.toString() + "\n\t\t testtotal31to60 = " + contractsGrantsAgingReportLookupableHelperServiceImpl.getTotal31to60().toString() + "\t\t\t\t\t\tactualtotal31to60 = " + test31to60total.toString() + "\n\t\t testtotal61to90 = " + contractsGrantsAgingReportLookupableHelperServiceImpl.getTotal61to90().toString() + "\t\t\t\t\t\tactualtotal61to90 = " + test61to90total.toString() + "\n\t\t testtotal91toSYSPR = " + contractsGrantsAgingReportLookupableHelperServiceImpl.getTotal91toSYSPR().toString() + "\t\t\t\t\tactualtotal91toSYSPR = " + test91toSYSPRtotal.toString() + "\n\t\t testtotalSYSPRplus1orMore = " + contractsGrantsAgingReportLookupableHelperServiceImpl.getTotalSYSPRplus1orMore().toString()
165                 + "\t\t\tactualtotalSYSPRplus1orMore = " + testSYSPRplus1orMoretotal.toString() + "\n\n***************************************************************************************\n\n");
166 
167 
168     }
169 
170     /**
171      * Test method for
172      * {@link org.kuali.kfs.module.ar.businessobject.lookup.ContractsGrantsAgingReportLookupableHelperServiceImplTest#performLookup(org.kuali.rice.kns.web.struts.form.LookupForm, java.util.Collection, boolean)}
173      * .
174      */
175     public void testPerformLookupLookupFormCollectionBoolean() {
176 
177         contractsGrantsAgingReportForm = new ContractsGrantsAgingReportForm();
178         contractsGrantsAgingReportForm.setFieldsForLookup(fieldValues);
179 
180         Collection resultTable = new ArrayList<String>();
181         assertNotNull("lookup list not null", contractsGrantsAgingReportLookupableHelperServiceImpl.performLookup(contractsGrantsAgingReportForm, resultTable, false));
182     }
183 
184 }