FINERACT-1971: saving account annual fee test fix

This commit is contained in:
taskain7
2024-01-17 16:33:33 +01:00
committed by Adam Saghy
parent 0672996678
commit 1148f5f974
3 changed files with 242 additions and 163 deletions
@@ -41,6 +41,8 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.apache.fineract.client.models.PostPaymentTypesRequest; import org.apache.fineract.client.models.PostPaymentTypesRequest;
import org.apache.fineract.client.models.PostPaymentTypesResponse; import org.apache.fineract.client.models.PostPaymentTypesResponse;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.integrationtests.common.BusinessDateHelper;
import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CommonConstants; import org.apache.fineract.integrationtests.common.CommonConstants;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper; import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
@@ -631,6 +633,13 @@ public class ClientSavingsIntegrationTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testSavingsAccountCharges() { public void testSavingsAccountCharges() {
Integer savingsId = null;
try {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE);
LocalDate submittedDate = LocalDate.of(2022, 9, 28);
String submittedDateString = "28 September 2022";
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, submittedDate);
final ResponseSpecification erroResponseSpec = new ResponseSpecBuilder().build(); final ResponseSpecification erroResponseSpec = new ResponseSpecBuilder().build();
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
@@ -648,7 +657,8 @@ public class ClientSavingsIntegrationTest {
Assertions.assertNotNull(savingsProductID); Assertions.assertNotNull(savingsProductID);
Assertions.assertNotNull(savingsProductID); Assertions.assertNotNull(savingsProductID);
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); savingsId = this.savingsAccountHelper.applyForSavingsApplicationOnDate(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL,
submittedDateString);
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
@@ -671,25 +681,29 @@ public class ClientSavingsIntegrationTest {
chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId); chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
Assertions.assertTrue(chargesPendingState == null || chargesPendingState.size() == 0); Assertions.assertTrue(chargesPendingState == null || chargesPendingState.size() == 0);
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); savingsStatusHashMap = this.savingsAccountHelper.approveSavingsOnDate(savingsId, submittedDateString);
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId, submittedDateString);
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
final Integer chargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, ChargesHelper.getSavingsAnnualFeeJSON()); final Integer chargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getSavingsAnnualFeeJSON());
Assertions.assertNotNull(chargeId); Assertions.assertNotNull(chargeId);
ArrayList<HashMap> charges = this.savingsAccountHelper.getSavingsCharges(savingsId); ArrayList<HashMap> charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
Assertions.assertTrue(charges == null || charges.size() == 0); Assertions.assertTrue(charges == null || charges.size() == 0);
this.savingsAccountHelper.addChargesForSavings(savingsId, chargeId, true); this.savingsAccountHelper.addChargesForSavingsWithDueDateAndFeeOnMonthDay(savingsId, chargeId, "10 January 2023", 100,
"15 January");
charges = this.savingsAccountHelper.getSavingsCharges(savingsId); charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
Assertions.assertEquals(1, charges.size()); Assertions.assertEquals(1, charges.size());
HashMap savingsChargeForPay = charges.get(0); HashMap savingsChargeForPay = charges.get(0);
Integer annualSavingsChargeId = (Integer) savingsChargeForPay.get("id"); Integer annualSavingsChargeId = (Integer) savingsChargeForPay.get("id");
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, LocalDate.of(2023, 1, 16));
ArrayList<HashMap> savingsAccountErrorData = (ArrayList<HashMap>) validationErrorHelper.inactivateCharge(annualSavingsChargeId, ArrayList<HashMap> savingsAccountErrorData = (ArrayList<HashMap>) validationErrorHelper.inactivateCharge(annualSavingsChargeId,
savingsId, CommonConstants.RESPONSE_ERROR); savingsId, CommonConstants.RESPONSE_ERROR);
assertEquals("validation.msg.savingsaccountcharge.inactivation.of.charge.not.allowed.when.charge.is.due", assertEquals("validation.msg.savingsaccountcharge.inactivation.of.charge.not.allowed.when.charge.is.due",
@@ -711,6 +725,7 @@ public class ClientSavingsIntegrationTest {
cal.set(Calendar.MONTH, (Integer) dates.get(1) - 1); cal.set(Calendar.MONTH, (Integer) dates.get(1) - 1);
cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2)); cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2));
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, LocalDate.of(2024, 1, 17));
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId, this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId,
((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime())); ((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime()));
@@ -773,8 +788,9 @@ public class ClientSavingsIntegrationTest {
cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2)); cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2));
// Depositing huge amount as scheduler job deducts the fee amount // Depositing huge amount as scheduler job deducts the fee amount
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, "100000", String transactionDate = "17 January 2024";
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID); Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, "100000", transactionDate,
CommonConstants.RESPONSE_RESOURCE_ID);
Assertions.assertNotNull(depositTransactionId); Assertions.assertNotNull(depositTransactionId);
this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId, this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId,
@@ -782,10 +798,16 @@ public class ClientSavingsIntegrationTest {
HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id")); HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id"));
assertEquals(savingsChargeForPay.get("amount"), paidCharge.get("amountPaid")); assertEquals(savingsChargeForPay.get("amount"), paidCharge.get("amountPaid"));
List nextDueDates = (List) paidCharge.get("dueDate"); List nextDueDates = (List) paidCharge.get("dueDate");
LocalDate nextDueDate = LocalDate.of((Integer) nextDueDates.get(0), (Integer) nextDueDates.get(1), (Integer) nextDueDates.get(2)); LocalDate nextDueDate = LocalDate.of((Integer) nextDueDates.get(0), (Integer) nextDueDates.get(1),
(Integer) nextDueDates.get(2));
LocalDate expectedNextDueDate = LocalDate.of((Integer) dates.get(0), (Integer) dates.get(1), (Integer) dates.get(2)) LocalDate expectedNextDueDate = LocalDate.of((Integer) dates.get(0), (Integer) dates.get(1), (Integer) dates.get(2))
.plusWeeks((Integer) paidCharge.get("feeInterval")); .plusWeeks((Integer) paidCharge.get("feeInterval"));
assertEquals(expectedNextDueDate, nextDueDate); assertEquals(expectedNextDueDate, nextDueDate);
} finally {
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, LocalDate.of(2024, 11, 11));
savingsAccountHelper.closeSavingsAccountOnDate(savingsId, "true", "11 November 2024");
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
}
} }
/*** /***
@@ -142,6 +142,13 @@ public class SchedulerJobsTestResults {
@Test @Test
public void testApplyAnnualFeeForSavingsJobOutcome() throws InterruptedException { public void testApplyAnnualFeeForSavingsJobOutcome() throws InterruptedException {
Integer savingsId = null;
try {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE);
LocalDate submittedDate = LocalDate.of(2022, 9, 28);
String submittedDateString = "28 September 2022";
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, submittedDate);
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec); this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec); final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
@@ -151,26 +158,29 @@ public class SchedulerJobsTestResults {
ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE); ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE);
Assertions.assertNotNull(savingsProductID); Assertions.assertNotNull(savingsProductID);
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, savingsId = this.savingsAccountHelper.applyForSavingsApplicationOnDate(clientID, savingsProductID,
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL); ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL, submittedDateString);
Assertions.assertNotNull(savingsProductID); Assertions.assertNotNull(savingsProductID);
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(requestSpec, responseSpec, savingsId); HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(requestSpec, responseSpec, savingsId);
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
final Integer annualFeeChargeId = ChargesHelper.createCharges(requestSpec, responseSpec, ChargesHelper.getSavingsAnnualFeeJSON()); final Integer annualFeeChargeId = ChargesHelper.createCharges(requestSpec, responseSpec,
ChargesHelper.getSavingsAnnualFeeJSON());
Assertions.assertNotNull(annualFeeChargeId); Assertions.assertNotNull(annualFeeChargeId);
this.savingsAccountHelper.addChargesForSavings(savingsId, annualFeeChargeId, true); this.savingsAccountHelper.addChargesForSavingsWithDueDateAndFeeOnMonthDay(savingsId, annualFeeChargeId, "10 January 2023", 100,
"15 January");
ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId); ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
Assertions.assertEquals(1, chargesPendingState.size()); Assertions.assertEquals(1, chargesPendingState.size());
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); savingsStatusHashMap = this.savingsAccountHelper.approveSavingsOnDate(savingsId, submittedDateString);
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId, submittedDateString);
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 11, 11));
String JobName = "Apply Annual Fee For Savings"; String JobName = "Apply Annual Fee For Savings";
this.schedulerJobHelper.executeAndAwaitJob(JobName); this.schedulerJobHelper.executeAndAwaitJob(JobName);
@@ -180,10 +190,14 @@ public class SchedulerJobsTestResults {
ArrayList<Integer> annualFeeDueDateAsArrayList = (ArrayList<Integer>) annualFeeDetails.get("dueDate"); ArrayList<Integer> annualFeeDueDateAsArrayList = (ArrayList<Integer>) annualFeeDetails.get("dueDate");
LocalDate nextDueDateForAnnualFee = LocalDate.of(annualFeeDueDateAsArrayList.get(0), annualFeeDueDateAsArrayList.get(1), LocalDate nextDueDateForAnnualFee = LocalDate.of(annualFeeDueDateAsArrayList.get(0), annualFeeDueDateAsArrayList.get(1),
annualFeeDueDateAsArrayList.get(2)); annualFeeDueDateAsArrayList.get(2));
LocalDate todaysDate = Utils.getLocalDateOfTenant(); LocalDate expectedDueDate = LocalDate.of(2023, 1, 15);
Truth.assertWithMessage("Verifying that all due Annual Fees have been paid").that(nextDueDateForAnnualFee) Truth.assertWithMessage("Verifying that all due Annual Fees have been paid").that(nextDueDateForAnnualFee)
.isGreaterThan(todaysDate); .isEquivalentAccordingToCompareTo(expectedDueDate);
} finally {
savingsAccountHelper.closeSavingsAccountOnDate(savingsId, "true", "11 November 2022");
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
}
} }
@Test @Test
@@ -264,12 +264,24 @@ public class SavingsAccountHelper extends IntegrationTest {
IS_BLOCK); IS_BLOCK);
} }
public HashMap activateSavings(final Integer savingsID, final String activationDate) {
LOG.info("---------------------------------- ACTIVATING SAVINGS APPLICATION ----------------------------------");
return performSavingApplicationActions(createSavingsOperationURL(ACTIVATE_SAVINGS_COMMAND, savingsID),
getActivatedSavingsAsJSONOnDate(activationDate), IS_BLOCK);
}
public HashMap closeSavingsAccount(final Integer savingsID, String withdrawBalance) { public HashMap closeSavingsAccount(final Integer savingsID, String withdrawBalance) {
LOG.info("---------------------------------- CLOSE SAVINGS APPLICATION ----------------------------------"); LOG.info("---------------------------------- CLOSE SAVINGS APPLICATION ----------------------------------");
return performSavingApplicationActions(createSavingsOperationURL(CLOSE_SAVINGS_COMMAND, savingsID), return performSavingApplicationActions(createSavingsOperationURL(CLOSE_SAVINGS_COMMAND, savingsID),
getCloseAccountJSON(withdrawBalance, LAST_TRANSACTION_DATE), IS_BLOCK); getCloseAccountJSON(withdrawBalance, LAST_TRANSACTION_DATE), IS_BLOCK);
} }
public HashMap closeSavingsAccountOnDate(final Integer savingsID, String withdrawBalance, final String closedOnDate) {
LOG.info("---------------------------------- CLOSE SAVINGS APPLICATION ----------------------------------");
return performSavingApplicationActions(createSavingsOperationURL(CLOSE_SAVINGS_COMMAND, savingsID),
getCloseAccountJSON(withdrawBalance, closedOnDate), IS_BLOCK);
}
public Object deleteSavingsApplication(final Integer savingsId, final String jsonAttributeToGetBack) { public Object deleteSavingsApplication(final Integer savingsId, final String jsonAttributeToGetBack) {
LOG.info("---------------------------------- DELETE SAVINGS APPLICATION ----------------------------------"); LOG.info("---------------------------------- DELETE SAVINGS APPLICATION ----------------------------------");
return Utils.performServerDelete(this.requestSpec, this.responseSpec, return Utils.performServerDelete(this.requestSpec, this.responseSpec,
@@ -368,6 +380,13 @@ public class SavingsAccountHelper extends IntegrationTest {
getPeriodChargeRequestJSONWithDueDate(chargeId, addDueDate, amount), CommonConstants.RESPONSE_RESOURCE_ID); getPeriodChargeRequestJSONWithDueDate(chargeId, addDueDate, amount), CommonConstants.RESPONSE_RESOURCE_ID);
} }
public Integer addChargesForSavingsWithDueDateAndFeeOnMonthDay(final Integer savingsId, final Integer chargeId, String addDueDate,
Integer amount, String feeOnMonthDay) {
return (Integer) performSavingActions(SAVINGS_ACCOUNT_URL + "/" + savingsId + "/charges?" + Utils.TENANT_IDENTIFIER,
getPeriodChargeRequestJSONWithDueDateAndFeeOnMonthDay(chargeId, addDueDate, amount, feeOnMonthDay),
CommonConstants.RESPONSE_RESOURCE_ID);
}
public Integer payCharge(final Integer chargeId, final Integer savingsId, String amount, String dueDate) { public Integer payCharge(final Integer chargeId, final Integer savingsId, String amount, String dueDate) {
return (Integer) performSavingActions(createChargesURL("paycharge", savingsId, chargeId), getSavingsPayChargeJSON(amount, dueDate), return (Integer) performSavingActions(createChargesURL("paycharge", savingsId, chargeId), getSavingsPayChargeJSON(amount, dueDate),
CommonConstants.RESPONSE_RESOURCE_ID); CommonConstants.RESPONSE_RESOURCE_ID);
@@ -493,6 +512,16 @@ public class SavingsAccountHelper extends IntegrationTest {
return savingsAccountActivateJson; return savingsAccountActivateJson;
} }
private String getActivatedSavingsAsJSONOnDate(final String activationDate) {
final HashMap<String, String> map = new HashMap<>();
map.put("locale", CommonConstants.LOCALE);
map.put("dateFormat", CommonConstants.DATE_FORMAT);
map.put("activatedOnDate", activationDate);
String savingsAccountActivateJson = new Gson().toJson(map);
LOG.info(savingsAccountActivateJson);
return savingsAccountActivateJson;
}
private String getActivatedSavingsAsForHoldJSON() { private String getActivatedSavingsAsForHoldJSON() {
final HashMap<String, String> map = new HashMap<>(); final HashMap<String, String> map = new HashMap<>();
map.put("locale", CommonConstants.LOCALE); map.put("locale", CommonConstants.LOCALE);
@@ -760,6 +789,20 @@ public class SavingsAccountHelper extends IntegrationTest {
return json; return json;
} }
private String getPeriodChargeRequestJSONWithDueDateAndFeeOnMonthDay(Integer chargeId, String addDueDate, Integer amount,
String feeOnMonthDay) {
final HashMap<String, Object> map = new HashMap<>();
map.put("chargeId", chargeId);
map.put("amount", amount);
map.put("feeOnMonthDay", feeOnMonthDay);
map.put("locale", CommonConstants.LOCALE);
map.put("monthDayFormat", "dd MMMM");
map.put("dateFormat", "dd MMMM yyy");
map.put("dueDate", addDueDate);
String json = new Gson().toJson(map);
return json;
}
private String getAccountActivationJSON(final String activationDate) { private String getAccountActivationJSON(final String activationDate) {
final HashMap<String, Object> map = new HashMap<>(); final HashMap<String, Object> map = new HashMap<>();
map.put("locale", CommonConstants.LOCALE); map.put("locale", CommonConstants.LOCALE);