FINERACT-2378: Failing integration test: org.apache.fineract.integrationtests.SchedulerJobsTestResults#testInterestTransferForSavings

This commit is contained in:
JohnAlva
2025-10-01 15:32:13 +02:00
committed by Adam Saghy
parent d782e65fc2
commit 963f8550b8
3 changed files with 27 additions and 41 deletions
@@ -47,14 +47,9 @@ public class CompoundInterestHelper {
// total interest earned in previous periods but not yet recognised
BigDecimal compoundedInterest = BigDecimal.ZERO;
BigDecimal unCompoundedInterest = BigDecimal.ZERO;
LocalDate endDay = DateUtils.getBusinessLocalDate();
final CompoundInterestValues compoundInterestValues = new CompoundInterestValues(compoundedInterest, unCompoundedInterest);
for (final PostingPeriod postingPeriod : allPeriods) {
if (postingPeriod.dateOfPostingTransaction().getMonth() != endDay.getMonth()) {
compoundInterestValues.setCompoundedInterest(interestEarned.getAmount());
}
final BigDecimal interestEarnedThisPeriod = postingPeriod.calculateInterest(compoundInterestValues);
final Money moneyToBePostedForPeriod = Money.of(currency, interestEarnedThisPeriod);
@@ -68,7 +63,6 @@ public class CompoundInterestHelper {
|| (lockUntil != null && !DateUtils.isAfter(postingPeriod.dateOfPostingTransaction(), lockUntil)))) {
compoundInterestValues.setCompoundedInterest(BigDecimal.ZERO);
}
endDay = postingPeriod.dateOfPostingTransaction();
}
return interestEarned;
@@ -52,12 +52,10 @@ import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
import org.apache.fineract.portfolio.savings.SavingsAccountTransactionType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Disabled("Disabled till FINERACT-2378 fixed")
public class SavingsInterestPostingTest {
private static final Logger LOG = LoggerFactory.getLogger(SavingsInterestPostingTest.class);
@@ -90,11 +88,6 @@ public class SavingsInterestPostingTest {
@Test
public void testPostInterestWithOverdraftProduct() {
try {
final LocalDate startDate = LocalDate.of(LocalDate.now(Utils.getZoneIdOfTenant()).getYear(), 2, 1);
// Simulate time passing - update business date to February
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE,
new PutGlobalConfigurationsRequest().enabled(true));
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, startDate);
final String amount = "10000";
final Account assetAccount = accountHelper.createAssetAccount();
@@ -110,7 +103,7 @@ public class SavingsInterestPostingTest {
interestReceivableAccount.getAccountID().toString(), assetAccount, incomeAccount, expenseAccount, liabilityAccount);
final Integer clientId = ClientHelper.createClient(requestSpec, responseSpec, "01 January 2025");
final LocalDate startDate = LocalDate.of(2025, 2, 1);
final String startDateString = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(startDate);
final Integer accountId = savingsAccountHelper.applyForSavingsApplicationOnDate(clientId, productId,
@@ -120,21 +113,21 @@ public class SavingsInterestPostingTest {
savingsAccountHelper.depositToSavingsAccount(accountId, amount, startDateString, CommonConstants.RESPONSE_RESOURCE_ID);
// Simulate time passing - update business date to March
LocalDate marchDate = LocalDate.of(startDate.getYear(), 3, 1);
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE,
new PutGlobalConfigurationsRequest().enabled(true));
LocalDate marchDate = LocalDate.of(2025, 3, 2);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, marchDate);
runAccrualsThenPost();
long days = ChronoUnit.DAYS.between(startDate, marchDate);
long days = ChronoUnit.DAYS.between(startDate, marchDate.minusDays(1));
BigDecimal expected = calcInterestPosting(productHelper, amount, days);
List<HashMap> txs = getInterestTransactions(accountId);
for (HashMap tx : txs) {
Assertions.assertEquals(expected, BigDecimal.valueOf(((Double) tx.get("amount"))));
}
Assertions.assertEquals(expected, BigDecimal.valueOf(((Double) txs.get(0).get("amount"))), "ERROR in expected");
long interestCount = countInterestOnDate(accountId, marchDate);
long overdraftCount = countOverdraftOnDate(accountId, marchDate);
long interestCount = countInterestOnDate(accountId, marchDate.minusDays(1));
long overdraftCount = countOverdraftOnDate(accountId, marchDate.minusDays(1));
Assertions.assertEquals(1L, interestCount, "Expected exactly one INTEREST posting on posting date");
Assertions.assertEquals(0L, overdraftCount, "Expected NO OVERDRAFT posting on posting date");
@@ -163,7 +156,7 @@ public class SavingsInterestPostingTest {
interestReceivableAccount.getAccountID().toString(), assetAccount, incomeAccount, expenseAccount, liabilityAccount);
final Integer clientId = ClientHelper.createClient(requestSpec, responseSpec, "01 January 2025");
final LocalDate startDate = LocalDate.of(LocalDate.now(Utils.getZoneIdOfTenant()).getYear(), 2, 1);
final LocalDate startDate = LocalDate.of(2025, 2, 1);
final String startDateString = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(startDate);
final Integer accountId = savingsAccountHelper.applyForSavingsApplicationOnDate(clientId, productId,
@@ -175,12 +168,12 @@ public class SavingsInterestPostingTest {
// Simulate time passing - update business date to March
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE,
new PutGlobalConfigurationsRequest().enabled(true));
LocalDate marchDate = LocalDate.of(startDate.getYear(), 3, 1);
LocalDate marchDate = LocalDate.of(2025, 3, 2);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, marchDate);
runAccrualsThenPost();
long days = ChronoUnit.DAYS.between(startDate, marchDate);
long days = ChronoUnit.DAYS.between(startDate, marchDate.minusDays(1));
BigDecimal expected = calcOverdraftPosting(productHelper, amount, days);
List<HashMap> txs = getInterestTransactions(accountId);
@@ -189,8 +182,8 @@ public class SavingsInterestPostingTest {
BigDecimal runningBalance = BigDecimal.valueOf(((Double) txs.get(0).get("runningBalance")));
Assertions.assertTrue(MathUtil.isLessThanZero(runningBalance), "Running balance is not less than zero");
long interestCount = countInterestOnDate(accountId, marchDate);
long overdraftCount = countOverdraftOnDate(accountId, marchDate);
long interestCount = countInterestOnDate(accountId, marchDate.minusDays(1));
long overdraftCount = countOverdraftOnDate(accountId, marchDate.minusDays(1));
Assertions.assertEquals(0L, interestCount, "Expected NO INTEREST posting on posting date");
Assertions.assertEquals(1L, overdraftCount, "Expected exactly one OVERDRAFT posting on posting date");
@@ -220,7 +213,7 @@ public class SavingsInterestPostingTest {
interestReceivableAccount.getAccountID().toString(), assetAccount, incomeAccount, expenseAccount, liabilityAccount);
final Integer clientId = ClientHelper.createClient(requestSpec, responseSpec, "01 January 2025");
final LocalDate startDate = LocalDate.of(LocalDate.now(Utils.getZoneIdOfTenant()).getYear(), 2, 1);
final LocalDate startDate = LocalDate.of(2025, 2, 1);
final String startStr = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(startDate);
final Integer accountId = savingsAccountHelper.applyForSavingsApplicationOnDate(clientId, productId,
@@ -229,14 +222,14 @@ public class SavingsInterestPostingTest {
savingsAccountHelper.activateSavings(accountId, startStr);
savingsAccountHelper.depositToSavingsAccount(accountId, amountDeposit, startStr, CommonConstants.RESPONSE_RESOURCE_ID);
final LocalDate withdrawalDate = LocalDate.of(startDate.getYear(), 2, 16);
final LocalDate withdrawalDate = LocalDate.of(2025, 2, 16);
final String withdrawalStr = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(withdrawalDate);
savingsAccountHelper.withdrawalFromSavingsAccount(accountId, amountWithdrawal, withdrawalStr,
CommonConstants.RESPONSE_RESOURCE_ID);
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE,
new PutGlobalConfigurationsRequest().enabled(true));
LocalDate marchDate = LocalDate.of(startDate.getYear(), 3, 1);
LocalDate marchDate = LocalDate.of(2025, 3, 2);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, marchDate);
runAccrualsThenPost();
@@ -253,15 +246,16 @@ public class SavingsInterestPostingTest {
BigDecimal expected = calcInterestPosting(productHelper, amountDeposit, days);
Assertions.assertEquals(expected, amt);
} else {
long days = ChronoUnit.DAYS.between(withdrawalDate, marchDate);
long days = ChronoUnit.DAYS.between(withdrawalDate, marchDate.minusDays(1));
BigDecimal overdraftBase = new BigDecimal(amountWithdrawal).subtract(new BigDecimal(amountDeposit));
BigDecimal expected = calcOverdraftPosting(productHelper, overdraftBase.toString(), days);
Assertions.assertEquals(expected, amt);
}
}
Assertions.assertEquals(1L, countInterestOnDate(accountId, marchDate), "Expected exactly one INTEREST posting on posting date");
Assertions.assertEquals(1L, countOverdraftOnDate(accountId, marchDate),
Assertions.assertEquals(1L, countInterestOnDate(accountId, marchDate.minusDays(1)),
"Expected exactly one INTEREST posting on posting date");
Assertions.assertEquals(1L, countOverdraftOnDate(accountId, marchDate.minusDays(1)),
"Expected exactly one OVERDRAFT posting on posting date");
assertNoAccrualReversals(accountId);
@@ -290,7 +284,7 @@ public class SavingsInterestPostingTest {
interestReceivableAccount.getAccountID().toString(), assetAccount, incomeAccount, expenseAccount, liabilityAccount);
final Integer clientId = ClientHelper.createClient(requestSpec, responseSpec, "01 January 2025");
final LocalDate startDate = LocalDate.of(LocalDate.now(Utils.getZoneIdOfTenant()).getYear(), 2, 1);
final LocalDate startDate = LocalDate.of(2025, 2, 1);
final String startStr = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(startDate);
final Integer accountId = savingsAccountHelper.applyForSavingsApplicationOnDate(clientId, productId,
@@ -299,13 +293,13 @@ public class SavingsInterestPostingTest {
savingsAccountHelper.activateSavings(accountId, startStr);
savingsAccountHelper.withdrawalFromSavingsAccount(accountId, amountWithdrawal, startStr, CommonConstants.RESPONSE_RESOURCE_ID);
final LocalDate depositDate = LocalDate.of(startDate.getYear(), 2, 16);
final LocalDate depositDate = LocalDate.of(2025, 2, 16);
final String depositStr = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(depositDate);
savingsAccountHelper.depositToSavingsAccount(accountId, amountDeposit, depositStr, CommonConstants.RESPONSE_RESOURCE_ID);
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE,
new PutGlobalConfigurationsRequest().enabled(true));
LocalDate marchDate = LocalDate.of(startDate.getYear(), 3, 1);
LocalDate marchDate = LocalDate.of(2025, 3, 2);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, marchDate);
runAccrualsThenPost();
@@ -322,16 +316,17 @@ public class SavingsInterestPostingTest {
BigDecimal expected = calcOverdraftPosting(productHelper, amountWithdrawal, days);
Assertions.assertEquals(expected, amt);
} else {
long days = ChronoUnit.DAYS.between(depositDate, marchDate);
long days = ChronoUnit.DAYS.between(depositDate, marchDate.minusDays(1));
BigDecimal positiveBase = new BigDecimal(amountDeposit).subtract(new BigDecimal(amountWithdrawal));
BigDecimal expected = calcInterestPosting(productHelper, positiveBase.toString(), days);
Assertions.assertEquals(expected, amt);
}
}
Assertions.assertEquals(1L, countOverdraftOnDate(accountId, marchDate),
Assertions.assertEquals(1L, countOverdraftOnDate(accountId, marchDate.minusDays(1)),
"Expected exactly one OVERDRAFT posting on posting date");
Assertions.assertEquals(1L, countInterestOnDate(accountId, marchDate), "Expected exactly one INTEREST posting on posting date");
Assertions.assertEquals(1L, countInterestOnDate(accountId, marchDate.minusDays(1)),
"Expected exactly one INTEREST posting on posting date");
assertNoAccrualReversals(accountId);
} finally {
@@ -442,7 +437,6 @@ public class SavingsInterestPostingTest {
public Integer createSavingsProductWithAccrualAccountingWithOutOverdraftAllowed(final String interestPayableAccount,
final String savingsControlAccount, final String interestReceivableAccount, final Account... accounts) {
LOG.info("------------------------------CREATING NEW SAVINGS PRODUCT WITHOUT OVERDRAFT ---------------------------------------");
this.productHelper = new SavingsProductHelper().withOverDraftRate("100000", "21")
.withAccountInterestReceivables(interestReceivableAccount).withSavingsControlAccountId(savingsControlAccount)
@@ -91,7 +91,6 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer.MethodName;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@@ -1266,7 +1265,6 @@ public class SchedulerJobsTestResults extends IntegrationTest {
}
@Test
@Disabled("Disabled due to FINERACT-2378")
public void testInterestTransferForSavings() throws InterruptedException {
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
FixedDepositAccountHelper fixedDepositAccountHelper = new FixedDepositAccountHelper(requestSpec, responseSpec);