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.document.service;
20  
21  import static org.kuali.kfs.sys.fixture.UserNameFixture.khuntley;
22  
23  import java.sql.Date;
24  
25  import org.kuali.kfs.coa.businessobject.AccountingPeriod;
26  import org.kuali.kfs.coa.service.AccountingPeriodService;
27  import org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward;
28  import org.kuali.kfs.integration.cg.ContractsAndGrantsModuleBillingService;
29  import org.kuali.kfs.module.ar.batch.service.VerifyBillingFrequencyService;
30  import org.kuali.kfs.module.ar.fixture.ARAwardFixture;
31  import org.kuali.kfs.sys.ConfigureContext;
32  import org.kuali.kfs.sys.context.KualiTestBase;
33  import org.kuali.kfs.sys.context.SpringContext;
34  
35  /**
36   * This class tests the VerifyBillingFrequencyService
37   */
38  @ConfigureContext(session = khuntley)
39  public class VerifyBillingFrequencyServiceTest extends KualiTestBase {
40  
41  
42      @Override
43      protected void setUp() throws Exception {
44  
45          super.setUp();
46      }
47  
48      /**
49       * This method test the validateBillingFrequency functionality. To make it flexible to test all the billing frequencies with
50       * various billing periods, this test method call the internal methods and tests it rather testing it as a whole.
51       */
52      public void testValidateBillingFrequency() {
53          ContractsAndGrantsModuleBillingService ModuleBillingService = SpringContext.getBean(ContractsAndGrantsModuleBillingService.class);
54  
55  
56          VerifyBillingFrequencyService verifyBillingFrequencyService = SpringContext.getBean(VerifyBillingFrequencyService.class);
57          boolean valid = false;
58          Date testEndDay = null;
59          Date testStartDay = null;
60          // To test all billing frequencies with award last billed date null
61  
62          // CASE 1 - award last billed Date is null.
63  
64  
65          Date date = Date.valueOf("2011-10-31");
66          AccountingPeriod currPeriod = SpringContext.getBean(AccountingPeriodService.class).getByDate(date);
67          // Now to set currentPeriod based on the billing frequency we would want to test.
68          // 1. MONTHLY / Milestone/Predetermined.
69          ContractsAndGrantsBillingAward award = ARAwardFixture.CG_AWARD_MONTHLY_BILLED_DATE_NULL.createAward();
70  
71  
72          testEndDay = Date.valueOf("2011-09-30");
73          testStartDay = Date.valueOf("2011-01-01");
74  
75          Date[] pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
76  
77          valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
78  
79  
80          assertEquals(pair[0], testStartDay);
81          assertEquals(pair[1], testEndDay);
82          assertTrue(valid);
83  
84          award = ARAwardFixture.CG_AWARD_MILESTONE_BILLED_DATE_NULL.createAward();
85          testEndDay = Date.valueOf("2011-09-30");
86          testStartDay = Date.valueOf("2011-01-01");
87  
88          pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
89  
90          valid = false;
91          valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
92  
93  
94          assertEquals(pair[0], testStartDay);
95          assertEquals(pair[1], testEndDay);
96          assertTrue(valid);
97  
98  
99          award = ARAwardFixture.CG_AWARD_PREDETERMINED_BILLED_DATE_NULL.createAward();
100 
101         testEndDay = Date.valueOf("2011-09-30");
102         testStartDay = Date.valueOf("2011-01-01");
103 
104         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
105 
106         valid = false;
107         valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
108 
109 
110         assertEquals(pair[0], testStartDay);
111         assertEquals(pair[1], testEndDay);
112         assertTrue(valid);
113 
114         // 2. QUARTERLY
115 
116 
117         award = ARAwardFixture.CG_AWARD_QUAR_BILLED_DATE_NULL.createAward();
118 
119         testEndDay = Date.valueOf("2011-09-30");
120         testStartDay = Date.valueOf("2011-01-01");
121 
122         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
123 
124         valid = false;
125         valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
126 
127 
128         assertEquals(pair[0], testStartDay);
129         assertEquals(pair[1], testEndDay);
130         assertTrue(valid);
131 
132         // 3. SEMI-ANNUAL
133 
134         award = ARAwardFixture.CG_AWARD_SEMI_ANN_BILLED_DATE_NULL.createAward();
135         testEndDay = Date.valueOf("2011-06-30");
136         testStartDay = Date.valueOf("2011-01-01");
137 
138         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
139 
140         valid = false;
141         valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
142 
143 
144         assertEquals(pair[0], testStartDay);
145         assertEquals(pair[1], testEndDay);
146         assertTrue(valid);
147 
148         // 4. ANNUALLY
149 
150 
151         award = ARAwardFixture.CG_AWARD_ANNUAL_BILLED_DATE_NULL.createAward();
152         testEndDay = Date.valueOf("2011-06-30");
153         testStartDay = Date.valueOf("2011-01-01");
154 
155         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
156 
157         valid = false;
158         valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
159 
160 
161         assertEquals(pair[0], testStartDay);
162         assertEquals(pair[1], testEndDay);
163         assertTrue(valid);
164 
165         // 5. LOC Billing
166 
167         award = ARAwardFixture.CG_AWARD_LOCB_BILLED_DATE_NULL.createAward();
168 
169         testStartDay = Date.valueOf("2011-01-01");
170 
171         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
172 
173         assertEquals(pair[0], testStartDay);
174 
175 
176         // CASE 2 - award last billed Date is set to appropriate period, current period will also be set to appropriate values.
177 
178         // 1. MONTHLY / Milestone/Predetermined.
179         date = Date.valueOf("2011-11-01");
180         currPeriod = SpringContext.getBean(AccountingPeriodService.class).getByDate(date);
181 
182 
183         award = ARAwardFixture.CG_AWARD_MONTHLY_BILLED_DATE_VALID.createAward();
184 
185         testEndDay = Date.valueOf("2011-10-31");
186         testStartDay = Date.valueOf("2011-10-01");
187 
188         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
189 
190         valid = false;
191         valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
192 
193 
194         assertEquals(pair[0], testStartDay);
195         assertEquals(pair[1], testEndDay);
196         assertTrue(valid);
197 
198 
199         award = ARAwardFixture.CG_AWARD_MILESTONE_BILLED_DATE_VALID.createAward();
200         testEndDay = Date.valueOf("2011-10-31");
201         testStartDay = Date.valueOf("2011-10-01");
202 
203         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
204 
205         valid = false;
206         valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
207 
208 
209         assertEquals(pair[0], testStartDay);
210         assertEquals(pair[1], testEndDay);
211         assertTrue(valid);
212 
213 
214         award = ARAwardFixture.CG_AWARD_PREDETERMINED_BILLED_DATE_VALID.createAward();
215 
216         testEndDay = Date.valueOf("2011-10-31");
217         testStartDay = Date.valueOf("2011-10-01");
218 
219         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
220 
221         valid = false;
222         valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
223 
224 
225         assertEquals(pair[0], testStartDay);
226         assertEquals(pair[1], testEndDay);
227         assertTrue(valid);
228 
229         // 2. QUARTERLY
230 
231         award = ARAwardFixture.CG_AWARD_QUAR_BILLED_DATE_VALID.createAward();
232 
233         testEndDay = Date.valueOf("2011-09-30");
234         testStartDay = Date.valueOf("2011-07-01");
235 
236         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
237 
238         valid = false;
239         valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
240 
241 
242         assertEquals(pair[0], testStartDay);
243         assertEquals(pair[1], testEndDay);
244         assertTrue(valid);
245 
246         // 3. SEMI-ANNUAL
247         date = Date.valueOf("2012-01-01");
248         currPeriod = SpringContext.getBean(AccountingPeriodService.class).getByDate(date);
249 
250         award = ARAwardFixture.CG_AWARD_SEMI_ANN_BILLED_DATE_VALID.createAward();
251         testEndDay = Date.valueOf("2011-12-31");
252         testStartDay = Date.valueOf("2011-07-01");
253 
254         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
255 
256         valid = false;
257         valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
258 
259 
260         assertEquals(pair[0], testStartDay);
261         assertEquals(pair[1], testEndDay);
262         assertTrue(valid);
263 
264         // 4. ANNUALLY
265 
266 
267         date = Date.valueOf("2011-07-01");
268         currPeriod = SpringContext.getBean(AccountingPeriodService.class).getByDate(date);
269 
270         award = ARAwardFixture.CG_AWARD_ANNUAL_BILLED_DATE_VALID.createAward();
271         testEndDay = Date.valueOf("2011-06-30");
272         testStartDay = Date.valueOf("2010-07-01");
273 
274         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
275 
276         valid = false;
277         valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
278 
279 
280         assertEquals(pair[0], testStartDay);
281         assertEquals(pair[1], testEndDay);
282         assertTrue(valid);
283 
284         // 5. LOC Billing - No grace period validation involved here.
285 
286 
287         date = Date.valueOf("2011-12-15");
288         currPeriod = SpringContext.getBean(AccountingPeriodService.class).getByDate(date);
289         award = ARAwardFixture.CG_AWARD_LOCB_BILLED_DATE_VALID.createAward();
290 
291         testStartDay = Date.valueOf("2010-12-14");
292 
293         pair = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
294 
295         valid = verifyBillingFrequencyService.calculateIfWithinGracePeriod(date, pair[1], pair[0], award.getLastBilledDate(), new Integer(0));
296         assertEquals(pair[0], testStartDay);
297 
298 
299     }
300 
301 }