1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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
50
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
61
62
63
64
65 Date date = Date.valueOf("2011-10-31");
66 AccountingPeriod currPeriod = SpringContext.getBean(AccountingPeriodService.class).getByDate(date);
67
68
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
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
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
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
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
177
178
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
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
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
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
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 }