52
52
import org .apache .fineract .portfolio .savings .SavingsAccountTransactionType ;
53
53
import org .junit .jupiter .api .Assertions ;
54
54
import org .junit .jupiter .api .BeforeEach ;
55
- import org .junit .jupiter .api .Disabled ;
56
55
import org .junit .jupiter .api .Test ;
57
56
import org .slf4j .Logger ;
58
57
import org .slf4j .LoggerFactory ;
59
58
60
- @ Disabled ("Disabled till FINERACT-2378 fixed" )
61
59
public class SavingsInterestPostingTest {
62
60
63
61
private static final Logger LOG = LoggerFactory .getLogger (SavingsInterestPostingTest .class );
@@ -90,11 +88,6 @@ public void setup() {
90
88
@ Test
91
89
public void testPostInterestWithOverdraftProduct () {
92
90
try {
93
- final LocalDate startDate = LocalDate .of (LocalDate .now (Utils .getZoneIdOfTenant ()).getYear (), 2 , 1 );
94
- // Simulate time passing - update business date to February
95
- globalConfigurationHelper .updateGlobalConfiguration (GlobalConfigurationConstants .ENABLE_BUSINESS_DATE ,
96
- new PutGlobalConfigurationsRequest ().enabled (true ));
97
- BusinessDateHelper .updateBusinessDate (requestSpec , responseSpec , BusinessDateType .BUSINESS_DATE , startDate );
98
91
final String amount = "10000" ;
99
92
100
93
final Account assetAccount = accountHelper .createAssetAccount ();
@@ -110,7 +103,7 @@ public void testPostInterestWithOverdraftProduct() {
110
103
interestReceivableAccount .getAccountID ().toString (), assetAccount , incomeAccount , expenseAccount , liabilityAccount );
111
104
112
105
final Integer clientId = ClientHelper .createClient (requestSpec , responseSpec , "01 January 2025" );
113
-
106
+ final LocalDate startDate = LocalDate . of ( 2025 , 2 , 1 );
114
107
final String startDateString = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (startDate );
115
108
116
109
final Integer accountId = savingsAccountHelper .applyForSavingsApplicationOnDate (clientId , productId ,
@@ -120,21 +113,21 @@ public void testPostInterestWithOverdraftProduct() {
120
113
savingsAccountHelper .depositToSavingsAccount (accountId , amount , startDateString , CommonConstants .RESPONSE_RESOURCE_ID );
121
114
122
115
// Simulate time passing - update business date to March
123
- LocalDate marchDate = LocalDate .of (startDate .getYear (), 3 , 1 );
116
+ globalConfigurationHelper .updateGlobalConfiguration (GlobalConfigurationConstants .ENABLE_BUSINESS_DATE ,
117
+ new PutGlobalConfigurationsRequest ().enabled (true ));
118
+ LocalDate marchDate = LocalDate .of (2025 , 3 , 2 );
124
119
BusinessDateHelper .updateBusinessDate (requestSpec , responseSpec , BusinessDateType .BUSINESS_DATE , marchDate );
125
120
126
121
runAccrualsThenPost ();
127
122
128
- long days = ChronoUnit .DAYS .between (startDate , marchDate );
123
+ long days = ChronoUnit .DAYS .between (startDate , marchDate . minusDays ( 1 ) );
129
124
BigDecimal expected = calcInterestPosting (productHelper , amount , days );
130
125
131
126
List <HashMap > txs = getInterestTransactions (accountId );
132
- for (HashMap tx : txs ) {
133
- Assertions .assertEquals (expected , BigDecimal .valueOf (((Double ) tx .get ("amount" ))));
134
- }
127
+ Assertions .assertEquals (expected , BigDecimal .valueOf (((Double ) txs .get (0 ).get ("amount" ))), "ERROR in expected" );
135
128
136
- long interestCount = countInterestOnDate (accountId , marchDate );
137
- long overdraftCount = countOverdraftOnDate (accountId , marchDate );
129
+ long interestCount = countInterestOnDate (accountId , marchDate . minusDays ( 1 ) );
130
+ long overdraftCount = countOverdraftOnDate (accountId , marchDate . minusDays ( 1 ) );
138
131
Assertions .assertEquals (1L , interestCount , "Expected exactly one INTEREST posting on posting date" );
139
132
Assertions .assertEquals (0L , overdraftCount , "Expected NO OVERDRAFT posting on posting date" );
140
133
@@ -163,7 +156,7 @@ public void testOverdraftInterestWithOverdraftProduct() {
163
156
interestReceivableAccount .getAccountID ().toString (), assetAccount , incomeAccount , expenseAccount , liabilityAccount );
164
157
165
158
final Integer clientId = ClientHelper .createClient (requestSpec , responseSpec , "01 January 2025" );
166
- final LocalDate startDate = LocalDate .of (LocalDate . now ( Utils . getZoneIdOfTenant ()). getYear () , 2 , 1 );
159
+ final LocalDate startDate = LocalDate .of (2025 , 2 , 1 );
167
160
final String startDateString = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (startDate );
168
161
169
162
final Integer accountId = savingsAccountHelper .applyForSavingsApplicationOnDate (clientId , productId ,
@@ -175,12 +168,12 @@ public void testOverdraftInterestWithOverdraftProduct() {
175
168
// Simulate time passing - update business date to March
176
169
globalConfigurationHelper .updateGlobalConfiguration (GlobalConfigurationConstants .ENABLE_BUSINESS_DATE ,
177
170
new PutGlobalConfigurationsRequest ().enabled (true ));
178
- LocalDate marchDate = LocalDate .of (startDate . getYear () , 3 , 1 );
171
+ LocalDate marchDate = LocalDate .of (2025 , 3 , 2 );
179
172
BusinessDateHelper .updateBusinessDate (requestSpec , responseSpec , BusinessDateType .BUSINESS_DATE , marchDate );
180
173
181
174
runAccrualsThenPost ();
182
175
183
- long days = ChronoUnit .DAYS .between (startDate , marchDate );
176
+ long days = ChronoUnit .DAYS .between (startDate , marchDate . minusDays ( 1 ) );
184
177
BigDecimal expected = calcOverdraftPosting (productHelper , amount , days );
185
178
186
179
List <HashMap > txs = getInterestTransactions (accountId );
@@ -189,8 +182,8 @@ public void testOverdraftInterestWithOverdraftProduct() {
189
182
BigDecimal runningBalance = BigDecimal .valueOf (((Double ) txs .get (0 ).get ("runningBalance" )));
190
183
Assertions .assertTrue (MathUtil .isLessThanZero (runningBalance ), "Running balance is not less than zero" );
191
184
192
- long interestCount = countInterestOnDate (accountId , marchDate );
193
- long overdraftCount = countOverdraftOnDate (accountId , marchDate );
185
+ long interestCount = countInterestOnDate (accountId , marchDate . minusDays ( 1 ) );
186
+ long overdraftCount = countOverdraftOnDate (accountId , marchDate . minusDays ( 1 ) );
194
187
Assertions .assertEquals (0L , interestCount , "Expected NO INTEREST posting on posting date" );
195
188
Assertions .assertEquals (1L , overdraftCount , "Expected exactly one OVERDRAFT posting on posting date" );
196
189
@@ -220,7 +213,7 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceLess
220
213
interestReceivableAccount .getAccountID ().toString (), assetAccount , incomeAccount , expenseAccount , liabilityAccount );
221
214
222
215
final Integer clientId = ClientHelper .createClient (requestSpec , responseSpec , "01 January 2025" );
223
- final LocalDate startDate = LocalDate .of (LocalDate . now ( Utils . getZoneIdOfTenant ()). getYear () , 2 , 1 );
216
+ final LocalDate startDate = LocalDate .of (2025 , 2 , 1 );
224
217
final String startStr = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (startDate );
225
218
226
219
final Integer accountId = savingsAccountHelper .applyForSavingsApplicationOnDate (clientId , productId ,
@@ -229,14 +222,14 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceLess
229
222
savingsAccountHelper .activateSavings (accountId , startStr );
230
223
savingsAccountHelper .depositToSavingsAccount (accountId , amountDeposit , startStr , CommonConstants .RESPONSE_RESOURCE_ID );
231
224
232
- final LocalDate withdrawalDate = LocalDate .of (startDate . getYear () , 2 , 16 );
225
+ final LocalDate withdrawalDate = LocalDate .of (2025 , 2 , 16 );
233
226
final String withdrawalStr = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (withdrawalDate );
234
227
savingsAccountHelper .withdrawalFromSavingsAccount (accountId , amountWithdrawal , withdrawalStr ,
235
228
CommonConstants .RESPONSE_RESOURCE_ID );
236
229
237
230
globalConfigurationHelper .updateGlobalConfiguration (GlobalConfigurationConstants .ENABLE_BUSINESS_DATE ,
238
231
new PutGlobalConfigurationsRequest ().enabled (true ));
239
- LocalDate marchDate = LocalDate .of (startDate . getYear () , 3 , 1 );
232
+ LocalDate marchDate = LocalDate .of (2025 , 3 , 2 );
240
233
BusinessDateHelper .updateBusinessDate (requestSpec , responseSpec , BusinessDateType .BUSINESS_DATE , marchDate );
241
234
242
235
runAccrualsThenPost ();
@@ -253,15 +246,16 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceLess
253
246
BigDecimal expected = calcInterestPosting (productHelper , amountDeposit , days );
254
247
Assertions .assertEquals (expected , amt );
255
248
} else {
256
- long days = ChronoUnit .DAYS .between (withdrawalDate , marchDate );
249
+ long days = ChronoUnit .DAYS .between (withdrawalDate , marchDate . minusDays ( 1 ) );
257
250
BigDecimal overdraftBase = new BigDecimal (amountWithdrawal ).subtract (new BigDecimal (amountDeposit ));
258
251
BigDecimal expected = calcOverdraftPosting (productHelper , overdraftBase .toString (), days );
259
252
Assertions .assertEquals (expected , amt );
260
253
}
261
254
}
262
255
263
- Assertions .assertEquals (1L , countInterestOnDate (accountId , marchDate ), "Expected exactly one INTEREST posting on posting date" );
264
- Assertions .assertEquals (1L , countOverdraftOnDate (accountId , marchDate ),
256
+ Assertions .assertEquals (1L , countInterestOnDate (accountId , marchDate .minusDays (1 )),
257
+ "Expected exactly one INTEREST posting on posting date" );
258
+ Assertions .assertEquals (1L , countOverdraftOnDate (accountId , marchDate .minusDays (1 )),
265
259
"Expected exactly one OVERDRAFT posting on posting date" );
266
260
267
261
assertNoAccrualReversals (accountId );
@@ -290,7 +284,7 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceGrea
290
284
interestReceivableAccount .getAccountID ().toString (), assetAccount , incomeAccount , expenseAccount , liabilityAccount );
291
285
292
286
final Integer clientId = ClientHelper .createClient (requestSpec , responseSpec , "01 January 2025" );
293
- final LocalDate startDate = LocalDate .of (LocalDate . now ( Utils . getZoneIdOfTenant ()). getYear () , 2 , 1 );
287
+ final LocalDate startDate = LocalDate .of (2025 , 2 , 1 );
294
288
final String startStr = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (startDate );
295
289
296
290
final Integer accountId = savingsAccountHelper .applyForSavingsApplicationOnDate (clientId , productId ,
@@ -299,13 +293,13 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceGrea
299
293
savingsAccountHelper .activateSavings (accountId , startStr );
300
294
savingsAccountHelper .withdrawalFromSavingsAccount (accountId , amountWithdrawal , startStr , CommonConstants .RESPONSE_RESOURCE_ID );
301
295
302
- final LocalDate depositDate = LocalDate .of (startDate . getYear () , 2 , 16 );
296
+ final LocalDate depositDate = LocalDate .of (2025 , 2 , 16 );
303
297
final String depositStr = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (depositDate );
304
298
savingsAccountHelper .depositToSavingsAccount (accountId , amountDeposit , depositStr , CommonConstants .RESPONSE_RESOURCE_ID );
305
299
306
300
globalConfigurationHelper .updateGlobalConfiguration (GlobalConfigurationConstants .ENABLE_BUSINESS_DATE ,
307
301
new PutGlobalConfigurationsRequest ().enabled (true ));
308
- LocalDate marchDate = LocalDate .of (startDate . getYear () , 3 , 1 );
302
+ LocalDate marchDate = LocalDate .of (2025 , 3 , 2 );
309
303
BusinessDateHelper .updateBusinessDate (requestSpec , responseSpec , BusinessDateType .BUSINESS_DATE , marchDate );
310
304
311
305
runAccrualsThenPost ();
@@ -322,16 +316,17 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceGrea
322
316
BigDecimal expected = calcOverdraftPosting (productHelper , amountWithdrawal , days );
323
317
Assertions .assertEquals (expected , amt );
324
318
} else {
325
- long days = ChronoUnit .DAYS .between (depositDate , marchDate );
319
+ long days = ChronoUnit .DAYS .between (depositDate , marchDate . minusDays ( 1 ) );
326
320
BigDecimal positiveBase = new BigDecimal (amountDeposit ).subtract (new BigDecimal (amountWithdrawal ));
327
321
BigDecimal expected = calcInterestPosting (productHelper , positiveBase .toString (), days );
328
322
Assertions .assertEquals (expected , amt );
329
323
}
330
324
}
331
325
332
- Assertions .assertEquals (1L , countOverdraftOnDate (accountId , marchDate ),
326
+ Assertions .assertEquals (1L , countOverdraftOnDate (accountId , marchDate . minusDays ( 1 ) ),
333
327
"Expected exactly one OVERDRAFT posting on posting date" );
334
- Assertions .assertEquals (1L , countInterestOnDate (accountId , marchDate ), "Expected exactly one INTEREST posting on posting date" );
328
+ Assertions .assertEquals (1L , countInterestOnDate (accountId , marchDate .minusDays (1 )),
329
+ "Expected exactly one INTEREST posting on posting date" );
335
330
336
331
assertNoAccrualReversals (accountId );
337
332
} finally {
@@ -442,7 +437,6 @@ private List<HashMap> getInterestTransactions(Integer savingsAccountId) {
442
437
443
438
public Integer createSavingsProductWithAccrualAccountingWithOutOverdraftAllowed (final String interestPayableAccount ,
444
439
final String savingsControlAccount , final String interestReceivableAccount , final Account ... accounts ) {
445
-
446
440
LOG .info ("------------------------------CREATING NEW SAVINGS PRODUCT WITHOUT OVERDRAFT ---------------------------------------" );
447
441
this .productHelper = new SavingsProductHelper ().withOverDraftRate ("100000" , "21" )
448
442
.withAccountInterestReceivables (interestReceivableAccount ).withSavingsControlAccountId (savingsControlAccount )
0 commit comments