5252import org .apache .fineract .portfolio .savings .SavingsAccountTransactionType ;
5353import org .junit .jupiter .api .Assertions ;
5454import org .junit .jupiter .api .BeforeEach ;
55- import org .junit .jupiter .api .Disabled ;
5655import org .junit .jupiter .api .Test ;
5756import org .slf4j .Logger ;
5857import org .slf4j .LoggerFactory ;
5958
60- @ Disabled ("Disabled till FINERACT-2378 fixed" )
6159public class SavingsInterestPostingTest {
6260
6361 private static final Logger LOG = LoggerFactory .getLogger (SavingsInterestPostingTest .class );
@@ -90,11 +88,6 @@ public void setup() {
9088 @ Test
9189 public void testPostInterestWithOverdraftProduct () {
9290 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 );
9891 final String amount = "10000" ;
9992
10093 final Account assetAccount = accountHelper .createAssetAccount ();
@@ -110,7 +103,7 @@ public void testPostInterestWithOverdraftProduct() {
110103 interestReceivableAccount .getAccountID ().toString (), assetAccount , incomeAccount , expenseAccount , liabilityAccount );
111104
112105 final Integer clientId = ClientHelper .createClient (requestSpec , responseSpec , "01 January 2025" );
113-
106+ final LocalDate startDate = LocalDate . of ( 2025 , 2 , 1 );
114107 final String startDateString = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (startDate );
115108
116109 final Integer accountId = savingsAccountHelper .applyForSavingsApplicationOnDate (clientId , productId ,
@@ -120,21 +113,21 @@ public void testPostInterestWithOverdraftProduct() {
120113 savingsAccountHelper .depositToSavingsAccount (accountId , amount , startDateString , CommonConstants .RESPONSE_RESOURCE_ID );
121114
122115 // 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 );
124119 BusinessDateHelper .updateBusinessDate (requestSpec , responseSpec , BusinessDateType .BUSINESS_DATE , marchDate );
125120
126121 runAccrualsThenPost ();
127122
128- long days = ChronoUnit .DAYS .between (startDate , marchDate );
123+ long days = ChronoUnit .DAYS .between (startDate , marchDate . minusDays ( 1 ) );
129124 BigDecimal expected = calcInterestPosting (productHelper , amount , days );
130125
131126 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" );
135128
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 ) );
138131 Assertions .assertEquals (1L , interestCount , "Expected exactly one INTEREST posting on posting date" );
139132 Assertions .assertEquals (0L , overdraftCount , "Expected NO OVERDRAFT posting on posting date" );
140133
@@ -163,7 +156,7 @@ public void testOverdraftInterestWithOverdraftProduct() {
163156 interestReceivableAccount .getAccountID ().toString (), assetAccount , incomeAccount , expenseAccount , liabilityAccount );
164157
165158 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 );
167160 final String startDateString = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (startDate );
168161
169162 final Integer accountId = savingsAccountHelper .applyForSavingsApplicationOnDate (clientId , productId ,
@@ -175,12 +168,12 @@ public void testOverdraftInterestWithOverdraftProduct() {
175168 // Simulate time passing - update business date to March
176169 globalConfigurationHelper .updateGlobalConfiguration (GlobalConfigurationConstants .ENABLE_BUSINESS_DATE ,
177170 new PutGlobalConfigurationsRequest ().enabled (true ));
178- LocalDate marchDate = LocalDate .of (startDate . getYear () , 3 , 1 );
171+ LocalDate marchDate = LocalDate .of (2025 , 3 , 2 );
179172 BusinessDateHelper .updateBusinessDate (requestSpec , responseSpec , BusinessDateType .BUSINESS_DATE , marchDate );
180173
181174 runAccrualsThenPost ();
182175
183- long days = ChronoUnit .DAYS .between (startDate , marchDate );
176+ long days = ChronoUnit .DAYS .between (startDate , marchDate . minusDays ( 1 ) );
184177 BigDecimal expected = calcOverdraftPosting (productHelper , amount , days );
185178
186179 List <HashMap > txs = getInterestTransactions (accountId );
@@ -189,8 +182,8 @@ public void testOverdraftInterestWithOverdraftProduct() {
189182 BigDecimal runningBalance = BigDecimal .valueOf (((Double ) txs .get (0 ).get ("runningBalance" )));
190183 Assertions .assertTrue (MathUtil .isLessThanZero (runningBalance ), "Running balance is not less than zero" );
191184
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 ) );
194187 Assertions .assertEquals (0L , interestCount , "Expected NO INTEREST posting on posting date" );
195188 Assertions .assertEquals (1L , overdraftCount , "Expected exactly one OVERDRAFT posting on posting date" );
196189
@@ -220,7 +213,7 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceLess
220213 interestReceivableAccount .getAccountID ().toString (), assetAccount , incomeAccount , expenseAccount , liabilityAccount );
221214
222215 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 );
224217 final String startStr = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (startDate );
225218
226219 final Integer accountId = savingsAccountHelper .applyForSavingsApplicationOnDate (clientId , productId ,
@@ -229,14 +222,14 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceLess
229222 savingsAccountHelper .activateSavings (accountId , startStr );
230223 savingsAccountHelper .depositToSavingsAccount (accountId , amountDeposit , startStr , CommonConstants .RESPONSE_RESOURCE_ID );
231224
232- final LocalDate withdrawalDate = LocalDate .of (startDate . getYear () , 2 , 16 );
225+ final LocalDate withdrawalDate = LocalDate .of (2025 , 2 , 16 );
233226 final String withdrawalStr = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (withdrawalDate );
234227 savingsAccountHelper .withdrawalFromSavingsAccount (accountId , amountWithdrawal , withdrawalStr ,
235228 CommonConstants .RESPONSE_RESOURCE_ID );
236229
237230 globalConfigurationHelper .updateGlobalConfiguration (GlobalConfigurationConstants .ENABLE_BUSINESS_DATE ,
238231 new PutGlobalConfigurationsRequest ().enabled (true ));
239- LocalDate marchDate = LocalDate .of (startDate . getYear () , 3 , 1 );
232+ LocalDate marchDate = LocalDate .of (2025 , 3 , 2 );
240233 BusinessDateHelper .updateBusinessDate (requestSpec , responseSpec , BusinessDateType .BUSINESS_DATE , marchDate );
241234
242235 runAccrualsThenPost ();
@@ -253,15 +246,16 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceLess
253246 BigDecimal expected = calcInterestPosting (productHelper , amountDeposit , days );
254247 Assertions .assertEquals (expected , amt );
255248 } else {
256- long days = ChronoUnit .DAYS .between (withdrawalDate , marchDate );
249+ long days = ChronoUnit .DAYS .between (withdrawalDate , marchDate . minusDays ( 1 ) );
257250 BigDecimal overdraftBase = new BigDecimal (amountWithdrawal ).subtract (new BigDecimal (amountDeposit ));
258251 BigDecimal expected = calcOverdraftPosting (productHelper , overdraftBase .toString (), days );
259252 Assertions .assertEquals (expected , amt );
260253 }
261254 }
262255
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 )),
265259 "Expected exactly one OVERDRAFT posting on posting date" );
266260
267261 assertNoAccrualReversals (accountId );
@@ -290,7 +284,7 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceGrea
290284 interestReceivableAccount .getAccountID ().toString (), assetAccount , incomeAccount , expenseAccount , liabilityAccount );
291285
292286 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 );
294288 final String startStr = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (startDate );
295289
296290 final Integer accountId = savingsAccountHelper .applyForSavingsApplicationOnDate (clientId , productId ,
@@ -299,13 +293,13 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceGrea
299293 savingsAccountHelper .activateSavings (accountId , startStr );
300294 savingsAccountHelper .withdrawalFromSavingsAccount (accountId , amountWithdrawal , startStr , CommonConstants .RESPONSE_RESOURCE_ID );
301295
302- final LocalDate depositDate = LocalDate .of (startDate . getYear () , 2 , 16 );
296+ final LocalDate depositDate = LocalDate .of (2025 , 2 , 16 );
303297 final String depositStr = DateTimeFormatter .ofPattern ("dd MMMM yyyy" , Locale .US ).format (depositDate );
304298 savingsAccountHelper .depositToSavingsAccount (accountId , amountDeposit , depositStr , CommonConstants .RESPONSE_RESOURCE_ID );
305299
306300 globalConfigurationHelper .updateGlobalConfiguration (GlobalConfigurationConstants .ENABLE_BUSINESS_DATE ,
307301 new PutGlobalConfigurationsRequest ().enabled (true ));
308- LocalDate marchDate = LocalDate .of (startDate . getYear () , 3 , 1 );
302+ LocalDate marchDate = LocalDate .of (2025 , 3 , 2 );
309303 BusinessDateHelper .updateBusinessDate (requestSpec , responseSpec , BusinessDateType .BUSINESS_DATE , marchDate );
310304
311305 runAccrualsThenPost ();
@@ -322,16 +316,17 @@ public void testOverdraftAndInterestPosting_WithOverdraftProduct_WhitBalanceGrea
322316 BigDecimal expected = calcOverdraftPosting (productHelper , amountWithdrawal , days );
323317 Assertions .assertEquals (expected , amt );
324318 } else {
325- long days = ChronoUnit .DAYS .between (depositDate , marchDate );
319+ long days = ChronoUnit .DAYS .between (depositDate , marchDate . minusDays ( 1 ) );
326320 BigDecimal positiveBase = new BigDecimal (amountDeposit ).subtract (new BigDecimal (amountWithdrawal ));
327321 BigDecimal expected = calcInterestPosting (productHelper , positiveBase .toString (), days );
328322 Assertions .assertEquals (expected , amt );
329323 }
330324 }
331325
332- Assertions .assertEquals (1L , countOverdraftOnDate (accountId , marchDate ),
326+ Assertions .assertEquals (1L , countOverdraftOnDate (accountId , marchDate . minusDays ( 1 ) ),
333327 "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" );
335330
336331 assertNoAccrualReversals (accountId );
337332 } finally {
@@ -442,7 +437,6 @@ private List<HashMap> getInterestTransactions(Integer savingsAccountId) {
442437
443438 public Integer createSavingsProductWithAccrualAccountingWithOutOverdraftAllowed (final String interestPayableAccount ,
444439 final String savingsControlAccount , final String interestReceivableAccount , final Account ... accounts ) {
445-
446440 LOG .info ("------------------------------CREATING NEW SAVINGS PRODUCT WITHOUT OVERDRAFT ---------------------------------------" );
447441 this .productHelper = new SavingsProductHelper ().withOverDraftRate ("100000" , "21" )
448442 .withAccountInterestReceivables (interestReceivableAccount ).withSavingsControlAccountId (savingsControlAccount )
0 commit comments