1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.module.ld.document.validation.impl;
20
21 import org.kuali.kfs.coa.businessobject.Account;
22 import org.kuali.kfs.coa.businessobject.SubFundGroup;
23 import org.kuali.kfs.module.ld.LaborKeyConstants;
24 import org.kuali.kfs.module.ld.businessobject.ErrorCertification;
25 import org.kuali.kfs.module.ld.businessobject.ExpenseTransferSourceAccountingLine;
26 import org.kuali.kfs.module.ld.businessobject.ExpenseTransferTargetAccountingLine;
27 import org.kuali.kfs.module.ld.document.SalaryExpenseTransferDocument;
28 import org.kuali.kfs.module.ld.document.service.impl.SalaryExpenseTransferTransactionAgeServiceImpl;
29 import org.kuali.kfs.sys.ConfigureContext;
30 import org.kuali.kfs.sys.businessobject.UniversityDate;
31 import org.kuali.kfs.sys.context.KualiTestBase;
32 import org.kuali.kfs.sys.context.SpringContext;
33 import org.kuali.kfs.sys.context.TestUtils;
34 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEventBase;
35 import org.kuali.kfs.sys.service.UniversityDateService;
36 import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
37 import org.kuali.kfs.sys.service.impl.UniversityDateServiceImpl;
38 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
39 import org.kuali.rice.krad.util.GlobalVariables;
40
41
42
43
44
45
46
47
48 @ConfigureContext
49 public class SalaryExpenseTransferErrorCertificationValidationTest extends KualiTestBase {
50 private static final String DEFAULT_PARM_FISCAL_PERIODS = "3";
51 private static final String DEFAULT_PARM_SUBFUND = "FEDERA=2";
52 private static final String YOUNGER_FISCAL_PER = "11";
53 private static final String OLDER_FISCAL_PER = "7";
54 private static final String FISCAL_PERIOD_FOR_REGULAR_TEST = "13";
55 private static final String YOUNGER_FISCAL_PER_FOR_FY_TEST = "13";
56 private static final String OLDER_FISCAL_PER_FOR_FY_TEST = "12";
57 private static final String FISCAL_PERIOD_FOR_FY_TEST = "3";
58 private static final String NON_PARM_SUBFUND = "AG";
59 private static final String PARM_SUBFUND = "FEDERA";
60
61 private SalaryExpenseTransferErrorCertificationValidation validation;
62 private SalaryExpenseTransferTransactionAgeServiceImpl salaryExpenseTransferTransactionAgeService;
63 private MyUniversityDateService universityDateService;
64 private UniversityDateService oldDateService;
65 private SalaryExpenseTransferDocument stDoc;
66 private MyAttributedDocumentEvent event;
67 private ErrorCertification errorCertification;
68
69 private enum TabState {
70 FULL, PARTIAL, EMPTY
71 };
72
73 private enum CrossFY {
74 YES, NO
75 }
76
77 @Override
78 public void setUp() throws Exception {
79 super.setUp();
80 validation = new SalaryExpenseTransferErrorCertificationValidation();
81 salaryExpenseTransferTransactionAgeService = new SalaryExpenseTransferTransactionAgeServiceImpl();
82 universityDateService = new MyUniversityDateService();
83 oldDateService = salaryExpenseTransferTransactionAgeService.getUniversityDateService();
84
85 salaryExpenseTransferTransactionAgeService.setUniversityDateService(universityDateService);
86 validation.setParameterService(SpringContext.getBean(ParameterService.class));
87 validation.setSalaryExpenseTransferTransactionAgeService(salaryExpenseTransferTransactionAgeService);
88 stDoc = new SalaryExpenseTransferDocument();
89 event = new MyAttributedDocumentEvent(stDoc);
90 errorCertification = new ErrorCertification();
91 errorCertification.setDocumentNumber("1");
92 stDoc.setErrorCertification(errorCertification);
93 TestUtils.setSystemParameter(KfsParameterConstants.LABOR_DOCUMENT.class, SalaryExpenseTransferDocumentRuleConstants.DEFAULT_NUMBER_OF_FISCAL_PERIODS_ERROR_CERTIFICATION_TAB_REQUIRED, DEFAULT_PARM_FISCAL_PERIODS);
94 TestUtils.setSystemParameter(KfsParameterConstants.LABOR_DOCUMENT.class, SalaryExpenseTransferDocumentRuleConstants.ERROR_CERTIFICATION_DEFAULT_OVERRIDE_BY_SUB_FUND, DEFAULT_PARM_SUBFUND);
95 }
96
97 @Override
98 public void tearDown() throws Exception {
99 super.tearDown();
100 this.salaryExpenseTransferTransactionAgeService.setUniversityDateService(oldDateService);
101 }
102
103
104
105
106
107
108 public void setUpErrorCertificationObject(TabState tabState) {
109 switch (tabState) {
110 case FULL:
111 errorCertification.setErrorCorrectionReason("test reason");
112 errorCertification.setErrorDescription("test desc");
113 errorCertification.setExpenditureDescription("test description");
114 errorCertification.setExpenditureProjectBenefit("test benefit");
115 break;
116 case PARTIAL:
117 errorCertification.setErrorCorrectionReason("test reason");
118 errorCertification.setErrorDescription("test desc");
119 errorCertification.setExpenditureDescription("");
120 errorCertification.setExpenditureProjectBenefit("");
121 break;
122 case EMPTY:
123 errorCertification.setErrorCorrectionReason("");
124 errorCertification.setErrorDescription("");
125 errorCertification.setExpenditureDescription("");
126 errorCertification.setExpenditureProjectBenefit("");
127 break;
128 }
129 }
130
131
132
133
134
135
136
137 public void setCustomUniversityDateFiscalPeriod(CrossFY crossFiscalYear) {
138 switch (crossFiscalYear) {
139 case YES:
140 salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().setUniversityFiscalAccountingPeriod(FISCAL_PERIOD_FOR_FY_TEST);
141 break;
142 case NO:
143 salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().setUniversityFiscalAccountingPeriod(FISCAL_PERIOD_FOR_REGULAR_TEST);
144 break;
145 }
146 }
147
148
149
150
151
152
153
154 public void testSourceAccountingLine() {
155
156 ExpenseTransferSourceAccountingLine sourceAccountingLine = new ExpenseTransferSourceAccountingLine();
157 sourceAccountingLine.setPayrollEndDateFiscalYear(salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().getUniversityFiscalYear());
158 sourceAccountingLine.setPayrollEndDateFiscalPeriodCode(YOUNGER_FISCAL_PER);
159
160 stDoc.addSourceAccountingLine(sourceAccountingLine);
161
162 setCustomUniversityDateFiscalPeriod(CrossFY.NO);
163
164
165 setUpErrorCertificationObject(TabState.EMPTY);
166
167 validation.validate(event);
168
169 boolean hasError = GlobalVariables.getMessageMap().doesPropertyHaveError(LaborKeyConstants.ErrorCertification.ERROR_ERROR_CERT_KEY);
170 assertFalse("Unexpected requirement of Error Certification Tab.", hasError);
171 }
172
173
174
175
176
177
178
179 public void testOlderSourceAccountingLine() {
180
181 ExpenseTransferSourceAccountingLine sourceAccountingLine = new ExpenseTransferSourceAccountingLine();
182 sourceAccountingLine.setPayrollEndDateFiscalYear(salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().getUniversityFiscalYear());
183 sourceAccountingLine.setPayrollEndDateFiscalPeriodCode(OLDER_FISCAL_PER);
184
185 stDoc.addSourceAccountingLine(sourceAccountingLine);
186
187 setCustomUniversityDateFiscalPeriod(CrossFY.NO);
188
189
190 setUpErrorCertificationObject(TabState.EMPTY);
191
192 validation.validate(event);
193
194 boolean hasError = GlobalVariables.getMessageMap().doesPropertyHaveError(LaborKeyConstants.ErrorCertification.ERROR_ERROR_CERT_KEY);
195 assertTrue("Error Certification Tab isn't required, but should be.", hasError);
196 }
197
198
199
200
201
202
203
204 public void testPriorYearOlderSourceAccountingLine() {
205
206 ExpenseTransferSourceAccountingLine sourceAccountingLine = new ExpenseTransferSourceAccountingLine();
207 sourceAccountingLine.setPayrollEndDateFiscalYear(salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().getUniversityFiscalYear() - 1);
208 sourceAccountingLine.setPayrollEndDateFiscalPeriodCode(OLDER_FISCAL_PER_FOR_FY_TEST);
209
210 stDoc.addSourceAccountingLine(sourceAccountingLine);
211
212 setCustomUniversityDateFiscalPeriod(CrossFY.YES);
213
214
215 setUpErrorCertificationObject(TabState.EMPTY);
216
217 validation.validate(event);
218
219 boolean hasError = GlobalVariables.getMessageMap().doesPropertyHaveError(LaborKeyConstants.ErrorCertification.ERROR_ERROR_CERT_KEY);
220 assertTrue("Error Certification Tab isn't required, but should be.", hasError);
221 }
222
223
224
225
226
227
228
229 public void testPriorYearYoungerSourceAccountingLine() {
230
231 ExpenseTransferSourceAccountingLine sourceAccountingLine = new ExpenseTransferSourceAccountingLine();
232 sourceAccountingLine.setPayrollEndDateFiscalYear(salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().getUniversityFiscalYear() - 1);
233 sourceAccountingLine.setPayrollEndDateFiscalPeriodCode(YOUNGER_FISCAL_PER_FOR_FY_TEST);
234
235 stDoc.addSourceAccountingLine(sourceAccountingLine);
236
237 setCustomUniversityDateFiscalPeriod(CrossFY.YES);
238
239
240 setUpErrorCertificationObject(TabState.EMPTY);
241
242 validation.validate(event);
243
244 boolean hasError = GlobalVariables.getMessageMap().doesPropertyHaveError(LaborKeyConstants.ErrorCertification.ERROR_ERROR_CERT_KEY);
245 assertFalse("Error Certification Tab is required, but shouldn't be.", hasError);
246 }
247
248
249
250
251
252
253
254
255 public void testTargetAccountingLine() {
256 Account account = new Account();
257 SubFundGroup subFundGroup = new SubFundGroup();
258 subFundGroup.setSubFundGroupCode(NON_PARM_SUBFUND);
259 account.setSubFundGroup(subFundGroup);
260
261
262 ExpenseTransferTargetAccountingLine targetAccountingLine = new ExpenseTransferTargetAccountingLine();
263 targetAccountingLine.setPayrollEndDateFiscalYear(salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().getUniversityFiscalYear());
264 targetAccountingLine.setPayrollEndDateFiscalPeriodCode(YOUNGER_FISCAL_PER);
265 targetAccountingLine.setAccount(account);
266
267 stDoc.addTargetAccountingLine(targetAccountingLine);
268
269 setCustomUniversityDateFiscalPeriod(CrossFY.NO);
270
271
272 setUpErrorCertificationObject(TabState.EMPTY);
273
274 validation.validate(event);
275
276 boolean hasError = GlobalVariables.getMessageMap().doesPropertyHaveError(LaborKeyConstants.ErrorCertification.ERROR_ERROR_CERT_KEY);
277 assertFalse("Unexpected requirement of Error Certification Tab.", hasError);
278 }
279
280
281
282
283
284
285
286
287 public void testOlderTargetAccountingLine() {
288 Account account = new Account();
289 SubFundGroup subFundGroup = new SubFundGroup();
290 subFundGroup.setSubFundGroupCode(NON_PARM_SUBFUND);
291 account.setSubFundGroup(subFundGroup);
292
293
294 ExpenseTransferTargetAccountingLine targetAccountingLine = new ExpenseTransferTargetAccountingLine();
295 targetAccountingLine.setPayrollEndDateFiscalYear(salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().getUniversityFiscalYear());
296 targetAccountingLine.setPayrollEndDateFiscalPeriodCode(OLDER_FISCAL_PER);
297 targetAccountingLine.setAccount(account);
298
299 stDoc.addTargetAccountingLine(targetAccountingLine);
300
301 setCustomUniversityDateFiscalPeriod(CrossFY.NO);
302
303
304 setUpErrorCertificationObject(TabState.EMPTY);
305
306 validation.validate(event);
307
308 boolean hasError = GlobalVariables.getMessageMap().doesPropertyHaveError(LaborKeyConstants.ErrorCertification.ERROR_ERROR_CERT_KEY);
309 assertTrue("Error Certification Tab isn't required, but should be.", hasError);
310 }
311
312
313
314
315
316
317
318
319 public void testPriorYearOlderTargetAccountingLine() {
320 Account account = new Account();
321 SubFundGroup subFundGroup = new SubFundGroup();
322 subFundGroup.setSubFundGroupCode(NON_PARM_SUBFUND);
323 account.setSubFundGroup(subFundGroup);
324
325
326 ExpenseTransferTargetAccountingLine targetAccountingLine = new ExpenseTransferTargetAccountingLine();
327 targetAccountingLine.setPayrollEndDateFiscalYear(salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().getUniversityFiscalYear() - 1);
328 targetAccountingLine.setPayrollEndDateFiscalPeriodCode(OLDER_FISCAL_PER_FOR_FY_TEST);
329 targetAccountingLine.setAccount(account);
330
331 stDoc.addTargetAccountingLine(targetAccountingLine);
332
333 setCustomUniversityDateFiscalPeriod(CrossFY.YES);
334
335
336 setUpErrorCertificationObject(TabState.EMPTY);
337
338 validation.validate(event);
339
340 boolean hasError = GlobalVariables.getMessageMap().doesPropertyHaveError(LaborKeyConstants.ErrorCertification.ERROR_ERROR_CERT_KEY);
341 assertTrue("Error Certification Tab isn't required, but should be.", hasError);
342 }
343
344
345
346
347
348
349
350
351 public void testPriorYearYoungerTargetAccountingLine() {
352 Account account = new Account();
353 SubFundGroup subFundGroup = new SubFundGroup();
354 subFundGroup.setSubFundGroupCode(NON_PARM_SUBFUND);
355 account.setSubFundGroup(subFundGroup);
356
357
358 ExpenseTransferTargetAccountingLine targetAccountingLine = new ExpenseTransferTargetAccountingLine();
359 targetAccountingLine.setPayrollEndDateFiscalYear(salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().getUniversityFiscalYear() - 1);
360 targetAccountingLine.setPayrollEndDateFiscalPeriodCode(YOUNGER_FISCAL_PER_FOR_FY_TEST);
361 targetAccountingLine.setAccount(account);
362
363 stDoc.addTargetAccountingLine(targetAccountingLine);
364
365 setCustomUniversityDateFiscalPeriod(CrossFY.YES);
366
367
368 setUpErrorCertificationObject(TabState.EMPTY);
369
370 validation.validate(event);
371
372 boolean hasError = GlobalVariables.getMessageMap().doesPropertyHaveError(LaborKeyConstants.ErrorCertification.ERROR_ERROR_CERT_KEY);
373 assertFalse("Unexpected requirement of Error Certification Tab.", hasError);
374 }
375
376
377
378
379
380
381
382
383
384 public void testOlderSubFundTargetAccountingLine() {
385 Account account = new Account();
386 SubFundGroup subFundGroup = new SubFundGroup();
387 subFundGroup.setSubFundGroupCode(PARM_SUBFUND);
388 account.setSubFundGroup(subFundGroup);
389
390
391 ExpenseTransferTargetAccountingLine targetAccountingLine = new ExpenseTransferTargetAccountingLine();
392 targetAccountingLine.setPayrollEndDateFiscalYear(salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().getUniversityFiscalYear());
393 targetAccountingLine.setPayrollEndDateFiscalPeriodCode(OLDER_FISCAL_PER);
394 targetAccountingLine.setAccount(account);
395
396 stDoc.addTargetAccountingLine(targetAccountingLine);
397
398 setCustomUniversityDateFiscalPeriod(CrossFY.NO);
399
400
401 setUpErrorCertificationObject(TabState.EMPTY);
402
403 validation.validate(event);
404
405 boolean hasError = GlobalVariables.getMessageMap().doesPropertyHaveError(LaborKeyConstants.ErrorCertification.ERROR_ERROR_CERT_KEY);
406 assertTrue("Error Certification Tab isn't required, but should be.", hasError);
407 }
408
409
410
411
412
413
414
415
416
417 public void testPriorYearSubFundTargetAccountingLine() {
418 Account account = new Account();
419 SubFundGroup subFundGroup = new SubFundGroup();
420 subFundGroup.setSubFundGroupCode(PARM_SUBFUND);
421 account.setSubFundGroup(subFundGroup);
422
423
424 ExpenseTransferTargetAccountingLine targetAccountingLine = new ExpenseTransferTargetAccountingLine();
425 targetAccountingLine.setPayrollEndDateFiscalYear(salaryExpenseTransferTransactionAgeService.getUniversityDateService().getCurrentUniversityDate().getUniversityFiscalYear() - 1);
426 targetAccountingLine.setPayrollEndDateFiscalPeriodCode(OLDER_FISCAL_PER_FOR_FY_TEST);
427 targetAccountingLine.setAccount(account);
428
429 stDoc.addTargetAccountingLine(targetAccountingLine);
430
431 setCustomUniversityDateFiscalPeriod(CrossFY.YES);
432
433
434 setUpErrorCertificationObject(TabState.EMPTY);
435
436 validation.validate(event);
437
438 boolean hasError = GlobalVariables.getMessageMap().doesPropertyHaveError(LaborKeyConstants.ErrorCertification.ERROR_ERROR_CERT_KEY);
439 assertTrue("Error Certification Tab isn't required, but should be.", hasError);
440 }
441
442
443
444
445 static class MyUniversityDateService extends UniversityDateServiceImpl {
446 @Override
447 public UniversityDate getCurrentUniversityDate() {
448 UniversityDate universityDate = SpringContext.getBean(UniversityDateService.class).getCurrentUniversityDate();
449 return universityDate;
450 }
451 }
452
453 static class MyAttributedDocumentEvent extends AttributedDocumentEventBase {
454 public MyAttributedDocumentEvent(SalaryExpenseTransferDocument d) {
455 super("", "", d);
456 }
457 }
458 }