FINERACT-1785: Waive loan charge with same disbursement date
This commit is contained in:
committed by
Arnold Gálovics
parent
adcd76154e
commit
9fba52abbb
+64
@@ -31,6 +31,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
||||
import org.apache.fineract.client.models.PostChargesResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdChargesChargeIdResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdChargesResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
@@ -169,6 +170,69 @@ public class LoanChargeSpecificDueDateTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyAndWaiveLoanSpecificDueDatePenaltyWithDisbursementDate() {
|
||||
|
||||
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||
|
||||
// Client and Loan account creation
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
|
||||
final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProduct(loanTransactionHelper, null);
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
|
||||
// Older date to have more than one overdue installment
|
||||
LocalDate transactionDate = todaysDate;
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
log.info("Operation date {}", transactionDate);
|
||||
|
||||
// Create Loan Account
|
||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
||||
|
||||
// Get loan details
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
validateLoanAccount(getLoansLoanIdResponse, Double.valueOf(principalAmount), Double.valueOf("0.00"), true);
|
||||
|
||||
// Apply Loan Charge with specific due date
|
||||
final String feeAmount = "10.00";
|
||||
String payloadJSON = ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, feeAmount, true);
|
||||
final PostChargesResponse postChargesResponse = ChargesHelper.createLoanCharge(requestSpec, responseSpec, payloadJSON);
|
||||
assertNotNull(postChargesResponse);
|
||||
final Long chargeId = postChargesResponse.getResourceId();
|
||||
assertNotNull(chargeId);
|
||||
|
||||
payloadJSON = LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(chargeId.toString(), operationDate, feeAmount);
|
||||
PostLoansLoanIdChargesResponse postLoansLoanIdChargesResponse = loanTransactionHelper.addChargeForLoan(loanId, payloadJSON,
|
||||
responseSpec);
|
||||
assertNotNull(postLoansLoanIdChargesResponse);
|
||||
final Long loanChargeId = postLoansLoanIdChargesResponse.getResourceId();
|
||||
assertNotNull(loanChargeId);
|
||||
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
validateLoanAccount(getLoansLoanIdResponse, Double.valueOf(principalAmount), Double.valueOf("10.00"), true);
|
||||
|
||||
// Waive the Loan Charge
|
||||
final PostLoansLoanIdChargesChargeIdResponse postWaiveLoanChargesResponse = loanTransactionHelper.applyLoanChargeCommand(loanId,
|
||||
loanChargeId, "waive", Utils.emptyJson());
|
||||
assertNotNull(postWaiveLoanChargesResponse);
|
||||
|
||||
// evaluate the outstanding
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
validateLoanAccount(getLoansLoanIdResponse, Double.valueOf(principalAmount), Double.valueOf("10.00"), true);
|
||||
|
||||
// Make a full repayment to close the Loan
|
||||
Float amount = Float.valueOf("1010.00");
|
||||
PostLoansLoanIdTransactionsResponse loanIdTransactionsResponse = loanTransactionHelper.makeLoanRepayment(operationDate, amount,
|
||||
loanId);
|
||||
assertNotNull(loanIdTransactionsResponse);
|
||||
log.info("Loan Transaction Id: {} {}", loanId, loanIdTransactionsResponse.getResourceId());
|
||||
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
loanTransactionHelper.validateLoanStatus(getLoansLoanIdResponse, "loanStatusType.closed.obligations.met");
|
||||
|
||||
}
|
||||
|
||||
private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper,
|
||||
final Integer delinquencyBucketId) {
|
||||
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().build(null, delinquencyBucketId);
|
||||
|
||||
+9
@@ -814,6 +814,15 @@ public class LoanTransactionHelper extends IntegrationTest {
|
||||
return (Integer) response.get("resourceId");
|
||||
}
|
||||
|
||||
public PostLoansLoanIdChargesChargeIdResponse applyLoanChargeCommand(final Integer loanId, final Long loanchargeId, final String commad,
|
||||
final String json) {
|
||||
log.info("--------------------------------- WAIVE CHARGES FOR LOAN --------------------------------");
|
||||
final String CHARGES_URL = "/fineract-provider/api/v1/loans/" + loanId + "/charges/" + loanchargeId + "?command=" + commad + "&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
final String response = Utils.performServerPost(requestSpec, responseSpec, CHARGES_URL, json, null);
|
||||
return GSON.fromJson(response, PostLoansLoanIdChargesChargeIdResponse.class);
|
||||
}
|
||||
|
||||
public Integer waiveChargesForLoan(final Integer loanId, final Integer loanchargeId, final String json) {
|
||||
log.info("--------------------------------- WAIVE CHARGES FOR LOAN --------------------------------");
|
||||
final String CHARGES_URL = "/fineract-provider/api/v1/loans/" + loanId + "/charges/" + loanchargeId + "?command=waive&"
|
||||
|
||||
Reference in New Issue
Block a user