FINERACT-2326: Use exact business date during savings account accrual tests
This commit is contained in:
committed by
Arnold Gálovics
parent
9ef79f86a0
commit
5d71ffd4ea
+133
-124
@@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.integrationtests;
|
package org.apache.fineract.integrationtests;
|
||||||
|
|
||||||
|
import static org.apache.fineract.integrationtests.common.BusinessDateHelper.runAt;
|
||||||
|
|
||||||
import io.restassured.builder.RequestSpecBuilder;
|
import io.restassured.builder.RequestSpecBuilder;
|
||||||
import io.restassured.builder.ResponseSpecBuilder;
|
import io.restassured.builder.ResponseSpecBuilder;
|
||||||
import io.restassured.http.ContentType;
|
import io.restassured.http.ContentType;
|
||||||
@@ -72,155 +74,162 @@ public class SavingsAccrualAccountingIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPositiveAccrualPostsCorrectJournalEntries() {
|
public void testPositiveAccrualPostsCorrectJournalEntries() {
|
||||||
// --- ARRANGE ---
|
runAt("12 August 2021", () -> {
|
||||||
LOG.info("------------------------- INITIATING POSITIVE ACCRUAL ACCOUNTING TEST -------------------------");
|
// --- ARRANGE ---
|
||||||
final int daysToSubtract = 10;
|
LOG.info("------------------------- INITIATING POSITIVE ACCRUAL ACCOUNTING TEST -------------------------");
|
||||||
final String amount = "10000";
|
final int daysToSubtract = 10;
|
||||||
|
final String amount = "10000";
|
||||||
|
|
||||||
final Account savingsReferenceAccount = this.accountHelper.createAssetAccount("Savings Reference");
|
final Account savingsReferenceAccount = this.accountHelper.createAssetAccount("Savings Reference");
|
||||||
final Account interestOnSavingsAccount = this.accountHelper.createExpenseAccount("Interest on Savings (Expense)");
|
final Account interestOnSavingsAccount = this.accountHelper.createExpenseAccount("Interest on Savings (Expense)");
|
||||||
final Account savingsControlAccount = this.accountHelper.createLiabilityAccount("Savings Control");
|
final Account savingsControlAccount = this.accountHelper.createLiabilityAccount("Savings Control");
|
||||||
final Account interestPayableAccount = this.accountHelper.createLiabilityAccount("Interest Payable (Liability)");
|
final Account interestPayableAccount = this.accountHelper.createLiabilityAccount("Interest Payable (Liability)");
|
||||||
final Account incomeFromFeesAccount = this.accountHelper.createIncomeAccount("Income from Fees");
|
final Account incomeFromFeesAccount = this.accountHelper.createIncomeAccount("Income from Fees");
|
||||||
final Account[] accountList = { savingsReferenceAccount, savingsControlAccount, interestOnSavingsAccount, interestPayableAccount,
|
final Account[] accountList = { savingsReferenceAccount, savingsControlAccount, interestOnSavingsAccount,
|
||||||
incomeFromFeesAccount };
|
interestPayableAccount, incomeFromFeesAccount };
|
||||||
|
|
||||||
final SavingsProductHelper productHelper = new SavingsProductHelper().withNominalAnnualInterestRate(new BigDecimal("10.0"))
|
final SavingsProductHelper productHelper = new SavingsProductHelper().withNominalAnnualInterestRate(new BigDecimal("10.0"))
|
||||||
.withAccountingRuleAsAccrualBased(accountList)
|
.withAccountingRuleAsAccrualBased(accountList)
|
||||||
.withSavingsReferenceAccountId(savingsReferenceAccount.getAccountID().toString())
|
.withSavingsReferenceAccountId(savingsReferenceAccount.getAccountID().toString())
|
||||||
.withSavingsControlAccountId(savingsControlAccount.getAccountID().toString())
|
.withSavingsControlAccountId(savingsControlAccount.getAccountID().toString())
|
||||||
.withInterestOnSavingsAccountId(interestOnSavingsAccount.getAccountID().toString())
|
.withInterestOnSavingsAccountId(interestOnSavingsAccount.getAccountID().toString())
|
||||||
.withInterestPayableAccountId(interestPayableAccount.getAccountID().toString())
|
.withInterestPayableAccountId(interestPayableAccount.getAccountID().toString())
|
||||||
.withIncomeFromFeeAccountId(incomeFromFeesAccount.getAccountID().toString());
|
.withIncomeFromFeeAccountId(incomeFromFeesAccount.getAccountID().toString());
|
||||||
|
|
||||||
final Integer savingsProductId = SavingsProductHelper.createSavingsProduct(productHelper.build(), this.requestSpec,
|
final Integer savingsProductId = SavingsProductHelper.createSavingsProduct(productHelper.build(), this.requestSpec,
|
||||||
this.responseSpec);
|
this.responseSpec);
|
||||||
Assertions.assertNotNull(savingsProductId, "Failed to create savings product.");
|
Assertions.assertNotNull(savingsProductId, "Failed to create savings product.");
|
||||||
|
|
||||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2020");
|
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2020");
|
||||||
final LocalDate startDate = LocalDate.now(Utils.getZoneIdOfTenant()).minusDays(daysToSubtract);
|
final LocalDate startDate = LocalDate.of(2021, 8, 12).minusDays(daysToSubtract);
|
||||||
final String startDateString = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(startDate);
|
final String startDateString = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(startDate);
|
||||||
final Integer savingsAccountId = this.savingsAccountHelper.applyForSavingsApplicationOnDate(clientId, savingsProductId,
|
final Integer savingsAccountId = this.savingsAccountHelper.applyForSavingsApplicationOnDate(clientId, savingsProductId,
|
||||||
SavingsAccountHelper.ACCOUNT_TYPE_INDIVIDUAL, startDateString);
|
SavingsAccountHelper.ACCOUNT_TYPE_INDIVIDUAL, startDateString);
|
||||||
this.savingsAccountHelper.approveSavingsOnDate(savingsAccountId, startDateString);
|
this.savingsAccountHelper.approveSavingsOnDate(savingsAccountId, startDateString);
|
||||||
this.savingsAccountHelper.activateSavings(savingsAccountId, startDateString);
|
this.savingsAccountHelper.activateSavings(savingsAccountId, startDateString);
|
||||||
this.savingsAccountHelper.depositToSavingsAccount(savingsAccountId, amount, startDateString, CommonConstants.RESPONSE_RESOURCE_ID);
|
this.savingsAccountHelper.depositToSavingsAccount(savingsAccountId, amount, startDateString,
|
||||||
|
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||||
|
|
||||||
// --- ACT ---
|
// --- ACT ---
|
||||||
schedulerJobHelper.executeAndAwaitJob("Add Accrual Transactions For Savings");
|
schedulerJobHelper.executeAndAwaitJob("Add Accrual Transactions For Savings");
|
||||||
|
|
||||||
// --- ASSERT ---
|
// --- ASSERT ---
|
||||||
List<HashMap> accrualTransactions = getAccrualTransactions(savingsAccountId);
|
List<HashMap> accrualTransactions = getAccrualTransactions(savingsAccountId);
|
||||||
Assertions.assertFalse(accrualTransactions.isEmpty(), "No accrual transactions were found.");
|
Assertions.assertFalse(accrualTransactions.isEmpty(), "No accrual transactions were found.");
|
||||||
|
|
||||||
Number firstTransactionIdNumber = (Number) accrualTransactions.get(0).get("id");
|
Number firstTransactionIdNumber = (Number) accrualTransactions.get(0).get("id");
|
||||||
ArrayList<HashMap> journalEntries = journalEntryHelper.getJournalEntriesByTransactionId("S" + firstTransactionIdNumber.intValue());
|
ArrayList<HashMap> journalEntries = journalEntryHelper
|
||||||
Assertions.assertFalse(journalEntries.isEmpty(), "No journal entries found for positive accrual.");
|
.getJournalEntriesByTransactionId("S" + firstTransactionIdNumber.intValue());
|
||||||
|
Assertions.assertFalse(journalEntries.isEmpty(), "No journal entries found for positive accrual.");
|
||||||
|
|
||||||
boolean debitFound = false;
|
boolean debitFound = false;
|
||||||
boolean creditFound = false;
|
boolean creditFound = false;
|
||||||
for (Map<String, Object> entry : journalEntries) {
|
for (Map<String, Object> entry : journalEntries) {
|
||||||
String entryType = (String) ((HashMap) entry.get("entryType")).get("value");
|
String entryType = (String) ((HashMap) entry.get("entryType")).get("value");
|
||||||
Integer accountId = ((Number) entry.get("glAccountId")).intValue();
|
Integer accountId = ((Number) entry.get("glAccountId")).intValue();
|
||||||
if ("DEBIT".equals(entryType) && accountId.equals(interestOnSavingsAccount.getAccountID())) {
|
if ("DEBIT".equals(entryType) && accountId.equals(interestOnSavingsAccount.getAccountID())) {
|
||||||
debitFound = true;
|
debitFound = true;
|
||||||
|
}
|
||||||
|
if ("CREDIT".equals(entryType) && accountId.equals(interestPayableAccount.getAccountID())) {
|
||||||
|
creditFound = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("CREDIT".equals(entryType) && accountId.equals(interestPayableAccount.getAccountID())) {
|
|
||||||
creditFound = true;
|
Assertions.assertTrue(debitFound, "DEBIT to Interest on Savings (Expense) Account not found for positive accrual.");
|
||||||
|
Assertions.assertTrue(creditFound, "CREDIT to Interest Payable (Liability) Account not found for positive accrual.");
|
||||||
|
|
||||||
|
BigDecimal interest = getCalculateAccrualsForDay(productHelper, amount);
|
||||||
|
|
||||||
|
for (HashMap accrual : accrualTransactions) {
|
||||||
|
BigDecimal amountAccrualTransaccion = BigDecimal.valueOf((Double) accrual.get("amount"));
|
||||||
|
Assertions.assertEquals(interest, amountAccrualTransaccion);
|
||||||
}
|
}
|
||||||
}
|
LOG.info("VALIDATE AMOUNT AND ACCOUNT");
|
||||||
|
});
|
||||||
Assertions.assertTrue(debitFound, "DEBIT to Interest on Savings (Expense) Account not found for positive accrual.");
|
|
||||||
Assertions.assertTrue(creditFound, "CREDIT to Interest Payable (Liability) Account not found for positive accrual.");
|
|
||||||
|
|
||||||
BigDecimal interest = getCalculateAccrualsForDay(productHelper, amount);
|
|
||||||
|
|
||||||
for (HashMap accrual : accrualTransactions) {
|
|
||||||
BigDecimal amountAccrualTransaccion = BigDecimal.valueOf((Double) accrual.get("amount"));
|
|
||||||
Assertions.assertEquals(interest, amountAccrualTransaccion);
|
|
||||||
}
|
|
||||||
LOG.info("VALIDATE AMOUNT AND ACCOUNT");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNegativeAccrualPostsCorrectJournalEntries() {
|
public void testNegativeAccrualPostsCorrectJournalEntries() {
|
||||||
// --- ARRANGE ---
|
runAt("12 August 2021", () -> {
|
||||||
LOG.info("------------------------- INITIATING NEGATIVE ACCRUAL (OVERDRAFT) ACCOUNTING TEST -------------------------");
|
// --- ARRANGE ---
|
||||||
final int daysToSubtract = 10;
|
LOG.info("------------------------- INITIATING NEGATIVE ACCRUAL (OVERDRAFT) ACCOUNTING TEST -------------------------");
|
||||||
final String amount = "10000";
|
final int daysToSubtract = 10;
|
||||||
|
final String amount = "10000";
|
||||||
|
|
||||||
final Account savingsReferenceAccount = this.accountHelper.createAssetAccount("Savings Reference");
|
final Account savingsReferenceAccount = this.accountHelper.createAssetAccount("Savings Reference");
|
||||||
final Account overdraftPortfolioControl = this.accountHelper.createAssetAccount("Overdraft Portfolio");
|
final Account overdraftPortfolioControl = this.accountHelper.createAssetAccount("Overdraft Portfolio");
|
||||||
final Account interestReceivableAccount = this.accountHelper.createAssetAccount("Interest Receivable (Asset)");
|
final Account interestReceivableAccount = this.accountHelper.createAssetAccount("Interest Receivable (Asset)");
|
||||||
final Account savingsControlAccount = this.accountHelper.createLiabilityAccount("Savings Control");
|
final Account savingsControlAccount = this.accountHelper.createLiabilityAccount("Savings Control");
|
||||||
final Account interestPayableAccount = this.accountHelper.createLiabilityAccount("Interest Payable");
|
final Account interestPayableAccount = this.accountHelper.createLiabilityAccount("Interest Payable");
|
||||||
final Account overdraftInterestIncomeAccount = this.accountHelper.createIncomeAccount("Overdraft Interest Income");
|
final Account overdraftInterestIncomeAccount = this.accountHelper.createIncomeAccount("Overdraft Interest Income");
|
||||||
final Account expenseAccount = this.accountHelper.createExpenseAccount("Interest on Savings (Expense)");
|
final Account expenseAccount = this.accountHelper.createExpenseAccount("Interest on Savings (Expense)");
|
||||||
|
|
||||||
final Account[] accountList = { savingsReferenceAccount, savingsControlAccount, expenseAccount, overdraftInterestIncomeAccount };
|
final Account[] accountList = { savingsReferenceAccount, savingsControlAccount, expenseAccount,
|
||||||
|
overdraftInterestIncomeAccount };
|
||||||
|
|
||||||
final String overdraftLimit = "10000";
|
final String overdraftLimit = "10000";
|
||||||
final String overdraftInterestRate = "21.0";
|
final String overdraftInterestRate = "21.0";
|
||||||
final SavingsProductHelper productHelper = new SavingsProductHelper()
|
final SavingsProductHelper productHelper = new SavingsProductHelper()
|
||||||
.withNominalAnnualInterestRate(new BigDecimal(overdraftInterestRate)).withAccountingRuleAsAccrualBased(accountList)
|
.withNominalAnnualInterestRate(new BigDecimal(overdraftInterestRate)).withAccountingRuleAsAccrualBased(accountList)
|
||||||
.withOverDraftRate(overdraftLimit, overdraftInterestRate)
|
.withOverDraftRate(overdraftLimit, overdraftInterestRate)
|
||||||
.withSavingsReferenceAccountId(savingsReferenceAccount.getAccountID().toString())
|
.withSavingsReferenceAccountId(savingsReferenceAccount.getAccountID().toString())
|
||||||
.withSavingsControlAccountId(savingsControlAccount.getAccountID().toString())
|
.withSavingsControlAccountId(savingsControlAccount.getAccountID().toString())
|
||||||
.withInterestReceivableAccountId(interestReceivableAccount.getAccountID().toString())
|
.withInterestReceivableAccountId(interestReceivableAccount.getAccountID().toString())
|
||||||
.withIncomeFromInterestId(overdraftInterestIncomeAccount.getAccountID().toString())
|
.withIncomeFromInterestId(overdraftInterestIncomeAccount.getAccountID().toString())
|
||||||
.withInterestPayableAccountId(interestPayableAccount.getAccountID().toString())
|
.withInterestPayableAccountId(interestPayableAccount.getAccountID().toString())
|
||||||
.withInterestOnSavingsAccountId(expenseAccount.getAccountID().toString())
|
.withInterestOnSavingsAccountId(expenseAccount.getAccountID().toString())
|
||||||
.withOverdraftPortfolioControlId(overdraftPortfolioControl.getAccountID().toString());
|
.withOverdraftPortfolioControlId(overdraftPortfolioControl.getAccountID().toString());
|
||||||
|
|
||||||
final Integer savingsProductId = SavingsProductHelper.createSavingsProduct(productHelper.build(), this.requestSpec,
|
final Integer savingsProductId = SavingsProductHelper.createSavingsProduct(productHelper.build(), this.requestSpec,
|
||||||
this.responseSpec);
|
this.responseSpec);
|
||||||
Assertions.assertNotNull(savingsProductId, "Savings product with overdraft creation failed.");
|
Assertions.assertNotNull(savingsProductId, "Savings product with overdraft creation failed.");
|
||||||
|
|
||||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2020");
|
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2020");
|
||||||
final LocalDate startDate = LocalDate.now(Utils.getZoneIdOfTenant()).minusDays(daysToSubtract);
|
final LocalDate startDate = LocalDate.of(2021, 8, 12).minusDays(daysToSubtract);
|
||||||
final String startDateString = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(startDate);
|
final String startDateString = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(startDate);
|
||||||
final Integer savingsAccountId = this.savingsAccountHelper.applyForSavingsApplicationOnDate(clientId, savingsProductId,
|
final Integer savingsAccountId = this.savingsAccountHelper.applyForSavingsApplicationOnDate(clientId, savingsProductId,
|
||||||
SavingsAccountHelper.ACCOUNT_TYPE_INDIVIDUAL, startDateString);
|
SavingsAccountHelper.ACCOUNT_TYPE_INDIVIDUAL, startDateString);
|
||||||
this.savingsAccountHelper.approveSavingsOnDate(savingsAccountId, startDateString);
|
this.savingsAccountHelper.approveSavingsOnDate(savingsAccountId, startDateString);
|
||||||
this.savingsAccountHelper.activateSavings(savingsAccountId, startDateString);
|
this.savingsAccountHelper.activateSavings(savingsAccountId, startDateString);
|
||||||
this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsAccountId, "10000", startDateString,
|
this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsAccountId, "10000", startDateString,
|
||||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||||
|
|
||||||
// --- ACT ---
|
// --- ACT ---
|
||||||
schedulerJobHelper.executeAndAwaitJob("Add Accrual Transactions For Savings");
|
schedulerJobHelper.executeAndAwaitJob("Add Accrual Transactions For Savings");
|
||||||
|
|
||||||
// --- ASSERT ---
|
// --- ASSERT ---
|
||||||
List<HashMap> accrualTransactions = getAccrualTransactions(savingsAccountId);
|
List<HashMap> accrualTransactions = getAccrualTransactions(savingsAccountId);
|
||||||
Assertions.assertFalse(accrualTransactions.isEmpty(), "No accrual transactions were found for overdraft.");
|
Assertions.assertFalse(accrualTransactions.isEmpty(), "No accrual transactions were found for overdraft.");
|
||||||
|
|
||||||
Number firstTransactionIdNumber = (Number) accrualTransactions.get(0).get("id");
|
Number firstTransactionIdNumber = (Number) accrualTransactions.get(0).get("id");
|
||||||
ArrayList<HashMap> journalEntries = journalEntryHelper.getJournalEntriesByTransactionId("S" + firstTransactionIdNumber.intValue());
|
ArrayList<HashMap> journalEntries = journalEntryHelper
|
||||||
Assertions.assertFalse(journalEntries.isEmpty(), "No journal entries found for negative accrual.");
|
.getJournalEntriesByTransactionId("S" + firstTransactionIdNumber.intValue());
|
||||||
|
Assertions.assertFalse(journalEntries.isEmpty(), "No journal entries found for negative accrual.");
|
||||||
|
|
||||||
boolean debitFound = false;
|
boolean debitFound = false;
|
||||||
boolean creditFound = false;
|
boolean creditFound = false;
|
||||||
for (Map<String, Object> entry : journalEntries) {
|
for (Map<String, Object> entry : journalEntries) {
|
||||||
String entryType = (String) ((HashMap) entry.get("entryType")).get("value");
|
String entryType = (String) ((HashMap) entry.get("entryType")).get("value");
|
||||||
Integer accountId = ((Number) entry.get("glAccountId")).intValue();
|
Integer accountId = ((Number) entry.get("glAccountId")).intValue();
|
||||||
if ("DEBIT".equals(entryType) && accountId.equals(interestReceivableAccount.getAccountID())) {
|
if ("DEBIT".equals(entryType) && accountId.equals(interestReceivableAccount.getAccountID())) {
|
||||||
debitFound = true;
|
debitFound = true;
|
||||||
|
}
|
||||||
|
if ("CREDIT".equals(entryType) && accountId.equals(overdraftInterestIncomeAccount.getAccountID())) {
|
||||||
|
creditFound = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("CREDIT".equals(entryType) && accountId.equals(overdraftInterestIncomeAccount.getAccountID())) {
|
|
||||||
creditFound = true;
|
Assertions.assertTrue(debitFound, "DEBIT to Interest Receivable (Asset) Account not found for negative accrual.");
|
||||||
|
Assertions.assertTrue(creditFound, "CREDIT to Overdraft Interest Income Account not found for negative accrual.");
|
||||||
|
|
||||||
|
BigDecimal interest = getCalculateAccrualsForDay(productHelper, amount);
|
||||||
|
|
||||||
|
for (HashMap accrual : accrualTransactions) {
|
||||||
|
BigDecimal amountAccrualTransaccion = BigDecimal.valueOf((Double) accrual.get("amount"));
|
||||||
|
Assertions.assertEquals(interest, amountAccrualTransaccion);
|
||||||
}
|
}
|
||||||
}
|
LOG.info("VALIDATE AMOUNT AND ACCOUNT");
|
||||||
|
});
|
||||||
Assertions.assertTrue(debitFound, "DEBIT to Interest Receivable (Asset) Account not found for negative accrual.");
|
|
||||||
Assertions.assertTrue(creditFound, "CREDIT to Overdraft Interest Income Account not found for negative accrual.");
|
|
||||||
|
|
||||||
BigDecimal interest = getCalculateAccrualsForDay(productHelper, amount);
|
|
||||||
|
|
||||||
for (HashMap accrual : accrualTransactions) {
|
|
||||||
BigDecimal amountAccrualTransaccion = BigDecimal.valueOf((Double) accrual.get("amount"));
|
|
||||||
Assertions.assertEquals(interest, amountAccrualTransaccion);
|
|
||||||
}
|
|
||||||
LOG.info("VALIDATE AMOUNT AND ACCOUNT");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<HashMap> getAccrualTransactions(Integer savingsAccountId) {
|
private List<HashMap> getAccrualTransactions(Integer savingsAccountId) {
|
||||||
|
|||||||
+56
-50
@@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.integrationtests;
|
package org.apache.fineract.integrationtests;
|
||||||
|
|
||||||
|
import static org.apache.fineract.integrationtests.common.BusinessDateHelper.runAt;
|
||||||
|
|
||||||
import io.restassured.builder.RequestSpecBuilder;
|
import io.restassured.builder.RequestSpecBuilder;
|
||||||
import io.restassured.builder.ResponseSpecBuilder;
|
import io.restassured.builder.ResponseSpecBuilder;
|
||||||
import io.restassured.http.ContentType;
|
import io.restassured.http.ContentType;
|
||||||
@@ -73,73 +75,77 @@ public class SavingsAccrualIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAccrualsAreGeneratedForTenDayPeriod() {
|
public void testAccrualsAreGeneratedForTenDayPeriod() {
|
||||||
// --- ARRANGE ---
|
runAt("12 August 2021", () -> {
|
||||||
|
// --- ARRANGE ---
|
||||||
|
|
||||||
final Account assetAccount = this.accountHelper.createAssetAccount();
|
final Account assetAccount = this.accountHelper.createAssetAccount();
|
||||||
final Account liabilityAccount = this.accountHelper.createLiabilityAccount();
|
final Account liabilityAccount = this.accountHelper.createLiabilityAccount();
|
||||||
final Account incomeAccount = this.accountHelper.createIncomeAccount();
|
final Account incomeAccount = this.accountHelper.createIncomeAccount();
|
||||||
final Account expenseAccount = this.accountHelper.createExpenseAccount();
|
final Account expenseAccount = this.accountHelper.createExpenseAccount();
|
||||||
final String interestRate = "10.0";
|
final String interestRate = "10.0";
|
||||||
final int daysToTest = 10;
|
final int daysToTest = 10;
|
||||||
|
|
||||||
final SavingsProductHelper productHelper = new SavingsProductHelper().withInterestCompoundingPeriodTypeAsDaily()
|
final SavingsProductHelper productHelper = new SavingsProductHelper().withInterestCompoundingPeriodTypeAsDaily()
|
||||||
.withInterestPostingPeriodTypeAsMonthly().withInterestCalculationPeriodTypeAsDailyBalance()
|
.withInterestPostingPeriodTypeAsMonthly().withInterestCalculationPeriodTypeAsDailyBalance()
|
||||||
.withNominalAnnualInterestRate(new BigDecimal(interestRate))
|
.withNominalAnnualInterestRate(new BigDecimal(interestRate))
|
||||||
.withAccountingRuleAsAccrualBased(new Account[] { assetAccount, liabilityAccount, incomeAccount, expenseAccount });
|
.withAccountingRuleAsAccrualBased(new Account[] { assetAccount, liabilityAccount, incomeAccount, expenseAccount });
|
||||||
|
|
||||||
final Integer savingsProductId = SavingsProductHelper.createSavingsProduct(productHelper.build(), this.requestSpec,
|
final Integer savingsProductId = SavingsProductHelper.createSavingsProduct(productHelper.build(), this.requestSpec,
|
||||||
this.responseSpec);
|
this.responseSpec);
|
||||||
Assertions.assertNotNull(savingsProductId, "Error creating savings product.");
|
Assertions.assertNotNull(savingsProductId, "Error creating savings product.");
|
||||||
|
|
||||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2020");
|
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2020");
|
||||||
Assertions.assertNotNull(clientId, "Error creating client.");
|
Assertions.assertNotNull(clientId, "Error creating client.");
|
||||||
|
|
||||||
final LocalDate startDate = LocalDate.now(Utils.getZoneIdOfTenant()).minusDays(daysToTest);
|
final LocalDate startDate = LocalDate.of(2021, 8, 12).minusDays(daysToTest);
|
||||||
final String startDateString = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(startDate);
|
final String startDateString = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US).format(startDate);
|
||||||
|
|
||||||
final Integer savingsAccountId = this.savingsAccountHelper.applyForSavingsApplicationOnDate(clientId, savingsProductId,
|
final Integer savingsAccountId = this.savingsAccountHelper.applyForSavingsApplicationOnDate(clientId, savingsProductId,
|
||||||
SavingsAccountHelper.ACCOUNT_TYPE_INDIVIDUAL, startDateString);
|
SavingsAccountHelper.ACCOUNT_TYPE_INDIVIDUAL, startDateString);
|
||||||
Assertions.assertNotNull(savingsAccountId, "Error applying for savings account.");
|
Assertions.assertNotNull(savingsAccountId, "Error applying for savings account.");
|
||||||
|
|
||||||
this.savingsAccountHelper.approveSavingsOnDate(savingsAccountId, startDateString);
|
this.savingsAccountHelper.approveSavingsOnDate(savingsAccountId, startDateString);
|
||||||
this.savingsAccountHelper.activateSavings(savingsAccountId, startDateString);
|
this.savingsAccountHelper.activateSavings(savingsAccountId, startDateString);
|
||||||
|
|
||||||
final HashMap<String, Object> savingsStatus = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec,
|
final HashMap<String, Object> savingsStatus = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec,
|
||||||
savingsAccountId);
|
savingsAccountId);
|
||||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatus);
|
SavingsStatusChecker.verifySavingsIsActive(savingsStatus);
|
||||||
|
|
||||||
this.savingsAccountHelper.depositToSavingsAccount(savingsAccountId, "10000", startDateString, CommonConstants.RESPONSE_RESOURCE_ID);
|
this.savingsAccountHelper.depositToSavingsAccount(savingsAccountId, "10000", startDateString,
|
||||||
|
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||||
|
|
||||||
// --- ACT ---
|
// --- ACT ---
|
||||||
schedulerJobHelper.executeAndAwaitJob("Add Accrual Transactions For Savings");
|
schedulerJobHelper.executeAndAwaitJob("Add Accrual Transactions For Savings");
|
||||||
|
|
||||||
// --- ASSERT ---
|
// --- ASSERT ---
|
||||||
List<HashMap> allTransactions = savingsAccountHelper.getSavingsTransactions(savingsAccountId);
|
List<HashMap> allTransactions = savingsAccountHelper.getSavingsTransactions(savingsAccountId);
|
||||||
List<HashMap> accrualTransactions = new ArrayList<>();
|
List<HashMap> accrualTransactions = new ArrayList<>();
|
||||||
for (HashMap transaction : allTransactions) {
|
for (HashMap transaction : allTransactions) {
|
||||||
Map<String, Object> type = (Map<String, Object>) transaction.get("transactionType");
|
Map<String, Object> type = (Map<String, Object>) transaction.get("transactionType");
|
||||||
if (type != null && Boolean.TRUE.equals(type.get("accrual"))) {
|
if (type != null && Boolean.TRUE.equals(type.get("accrual"))) {
|
||||||
accrualTransactions.add(transaction);
|
accrualTransactions.add(transaction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
Assertions.assertFalse(accrualTransactions.isEmpty(), "No accrual transactions were found.");
|
||||||
Assertions.assertFalse(accrualTransactions.isEmpty(), "No accrual transactions were found.");
|
|
||||||
|
|
||||||
long daysBetween = ChronoUnit.DAYS.between(startDate, LocalDate.now(Utils.getZoneIdOfTenant()));
|
long daysBetween = ChronoUnit.DAYS.between(startDate, LocalDate.of(2021, 8, 12));
|
||||||
long actualNumberOfTransactions = accrualTransactions.size();
|
long actualNumberOfTransactions = accrualTransactions.size();
|
||||||
|
|
||||||
Assertions.assertTrue(actualNumberOfTransactions >= daysBetween && actualNumberOfTransactions <= daysBetween + 1, "For a period of "
|
Assertions.assertTrue(actualNumberOfTransactions >= daysBetween && actualNumberOfTransactions <= daysBetween + 1,
|
||||||
+ daysBetween + " days, a close number of transactions was expected, but found " + actualNumberOfTransactions);
|
"For a period of " + daysBetween + " days, a close number of transactions was expected, but found "
|
||||||
|
+ actualNumberOfTransactions);
|
||||||
|
|
||||||
BigDecimal principal = new BigDecimal("10000");
|
BigDecimal principal = new BigDecimal("10000");
|
||||||
BigDecimal rate = new BigDecimal(interestRate).divide(new BigDecimal(100));
|
BigDecimal rate = new BigDecimal(interestRate).divide(new BigDecimal(100));
|
||||||
BigDecimal daysInYear = new BigDecimal("365");
|
BigDecimal daysInYear = new BigDecimal("365");
|
||||||
|
|
||||||
BigDecimal expectedTotalAccrual = principal.multiply(rate).divide(daysInYear, 8, RoundingMode.HALF_EVEN)
|
BigDecimal expectedTotalAccrual = principal.multiply(rate).divide(daysInYear, 8, RoundingMode.HALF_EVEN)
|
||||||
.multiply(new BigDecimal(actualNumberOfTransactions)).setScale(2, RoundingMode.HALF_EVEN);
|
.multiply(new BigDecimal(actualNumberOfTransactions)).setScale(2, RoundingMode.HALF_EVEN);
|
||||||
|
|
||||||
BigDecimal actualTotalAccrual = savingsAccountHelper.getTotalAccrualAmount(savingsAccountId);
|
BigDecimal actualTotalAccrual = savingsAccountHelper.getTotalAccrualAmount(savingsAccountId);
|
||||||
|
|
||||||
Assertions.assertEquals(0, expectedTotalAccrual.compareTo(actualTotalAccrual),
|
Assertions.assertEquals(0, expectedTotalAccrual.compareTo(actualTotalAccrual),
|
||||||
"The total accrual (" + actualTotalAccrual + ") does not match the expected (" + expectedTotalAccrual + ")");
|
"The total accrual (" + actualTotalAccrual + ") does not match the expected (" + expectedTotalAccrual + ")");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user