Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3787,7 +3787,7 @@ public void testLoanScheduleWithInterestRecalculation_WITH_REST_DAILY_INTEREST_C
todaysDate = Calendar.getInstance(Utils.getTimeZoneOfTenant());

Integer overdueFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getLoanOverdueFeeJSONWithCalculattionTypePercentage());
ChargesHelper.getLoanOverdueFeeJSONWithCalculattionTypePercentage("10"));
Assert.assertNotNull(overdueFeeChargeId);

final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,70 @@ public void testApplyPenaltyForOverdueLoansJobOutcome() throws InterruptedExcept

}

@Test
public void testAvoidUnncessaryPenaltyWhenAmountZeroForOverdueLoansJobOutcome() throws InterruptedException {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unable to say if this is functionally correct - would someone else be able to review and confirm it is?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@awasum @Anh3h do you understand more about the functionality here than I do and can you confirm this new test is functionally correct?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can throw some light into this.
It is creating a loan with a very small interest rate 0.000001%.
It is verifying that the totalChargesDue is 0 for the loan ( which is also the feature currently as 0+ 0 + 0 is 0).
I am then calling the api /loans/{id}?associations=charges and then verifying that there are no charges created for this loan. This actually tests correctly what I have done.

this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);

final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
Assert.assertNotNull(clientID);

Integer overdueFeeChargeId = ChargesHelper
.createCharges(this.requestSpec, this.responseSpec, ChargesHelper.getLoanOverdueFeeJSONWithCalculattionTypePercentage("0.000001"));
Assert.assertNotNull(overdueFeeChargeId);

final Integer loanProductID = createLoanProduct(overdueFeeChargeId.toString());
Assert.assertNotNull(loanProductID);

final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
Assert.assertNotNull(loanID);

HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);

loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);

loanStatusHashMap = this.loanTransactionHelper.disburseLoan(AccountTransferTest.LOAN_APPROVAL_DATE_PLUS_ONE, loanID);
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);

ArrayList<HashMap> repaymentScheduleDataBefore = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec,
this.responseSpec, loanID);

String JobName = "Apply penalty to overdue loans";
Integer jobId = 12;

this.schedulerJobHelper.executeJob(JobName);

HashMap schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());

Assert.assertNotNull(schedulerJob);
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
Thread.sleep(15000);
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
Assert.assertNotNull(schedulerJob);
}

final HashMap chargeData = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);

ArrayList<HashMap> repaymentScheduleDataAfter = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec,
this.responseSpec, loanID);

Assert.assertEquals("Verifying From Penalty Charges due fot first Repayment after Successful completion of Scheduler Job",
0, repaymentScheduleDataAfter.get(1).get("penaltyChargesDue"));

final ArrayList loanCharges = this.loanTransactionHelper.getLoanCharges(this.requestSpec,
this.responseSpec, loanID);

Assert.assertNull("Verifying that charge isn't created when the amount is 0", loanCharges);

loanStatusHashMap = this.loanTransactionHelper.undoDisbursal(loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);

}

@Test
public void testUpdateOverdueDaysForNPA() throws InterruptedException {
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ public static String getLoanOverdueFeeJSON() {
return chargesCreateJson;
}

public static String getLoanOverdueFeeJSONWithCalculattionTypePercentage() {
public static String getLoanOverdueFeeJSONWithCalculattionTypePercentage(String penaltyPercentageAmount) {
final HashMap<String, Object> map = populateDefaultsForLoan();
map.put("penalty", ChargesHelper.penalty);
map.put("amount", "10");
map.put("amount", penaltyPercentageAmount);
map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
map.put("chargeTimeType", CHARGE_OVERDUE_INSTALLMENT_FEE);
map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ public ArrayList getLoanRepaymentSchedule(final RequestSpecification requestSpec
return (ArrayList) response.get("periods");
}

public ArrayList getLoanCharges(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer loanID) {
final String URL = "/fineract-provider/api/v1/loans/" + loanID + "?associations=charges&" + Utils.TENANT_IDENTIFIER;
return (ArrayList) Utils.performServerGet(requestSpec, responseSpec, URL, "charges");
}

public ArrayList getLoanFutureRepaymentSchedule(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer loanID) {
final String URL = "/fineract-provider/api/v1/loans/" + loanID + "?associations=repaymentSchedule,futureSchedule&"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2490,6 +2490,9 @@ public LoanOverdueDTO applyChargeToOverdueLoanInstallment(final Long loanId, fin

final LoanCharge loanCharge = LoanCharge.createNewFromJson(loan, chargeDefinition, command, entry.getValue());

if (BigDecimal.ZERO.compareTo(loanCharge.amount()) == 0) {
continue;
}
LoanOverdueInstallmentCharge overdueInstallmentCharge = new LoanOverdueInstallmentCharge(loanCharge, installment,
entry.getKey());
loanCharge.updateOverdueInstallmentCharge(overdueInstallmentCharge);
Expand Down