Skip to content

Commit 28fbaa9

Browse files
MarianaDmytrivBinariksadamsaghy
authored andcommitted
FINERACT-2311: add tests for buy down fees on product level
1 parent dc3ead4 commit 28fbaa9

File tree

6 files changed

+145
-155
lines changed

6 files changed

+145
-155
lines changed

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/factory/LoanRequestFactory.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,6 @@ public static PostLoansLoanIdRequest defaultContractTerminationUndoRequest() {
309309
return new PostLoansLoanIdRequest().note("Contract Termination Undo");
310310
}
311311

312-
public static PostLoansLoanIdTransactionsRequest defaultBuyDownFeeIncomeRequest() {
313-
return new PostLoansLoanIdTransactionsRequest().transactionDate(DEFAULT_TRANSACTION_DATE).dateFormat(DATE_FORMAT)
314-
.locale(DEFAULT_LOCALE).note("Buy Down fee");
315-
}
316-
317312
public static PostLoansLoanIdRequest defaultLoanContractTerminationRequest() {
318313
return new PostLoansLoanIdRequest().dateFormat(DATE_FORMAT).locale(DEFAULT_LOCALE).note("Contract Termination");
319314
}

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java

Lines changed: 96 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
import org.apache.fineract.test.messaging.store.EventStore;
155155
import org.apache.fineract.test.stepdef.AbstractStepDef;
156156
import org.apache.fineract.test.support.TestContextKey;
157+
import org.assertj.core.api.SoftAssertions;
157158
import org.springframework.beans.factory.annotation.Autowired;
158159
import retrofit2.Response;
159160

@@ -4181,6 +4182,13 @@ public void checkPagination(Integer totalPagesExpected, Integer size, String exc
41814182

41824183
@Then("Loan Product response contains interestRecognitionOnDisbursementDate flag with value {string}")
41834184
public void verifyInterestRecognitionOnDisbursementDateFlag(final String expectedValue) throws IOException {
4185+
GetLoanProductsResponse targetProduct = getLoanProductResponse();
4186+
4187+
assertNotNull(targetProduct.getInterestRecognitionOnDisbursementDate());
4188+
assertThat(targetProduct.getInterestRecognitionOnDisbursementDate().toString()).isEqualTo(expectedValue);
4189+
}
4190+
4191+
public GetLoanProductsResponse getLoanProductResponse() throws IOException {
41844192
final Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
41854193
assertNotNull(loanResponse.body());
41864194
final Long loanId = loanResponse.body().getLoanId();
@@ -4203,8 +4211,94 @@ public void verifyInterestRecognitionOnDisbursementDateFlag(final String expecte
42034211
return product.getId().equals(targetLoanProductId);
42044212
}).findFirst().orElseThrow(() -> new AssertionError("Loan product with ID " + targetLoanProductId + " not found in response"));
42054213

4206-
assertNotNull(targetProduct.getInterestRecognitionOnDisbursementDate());
4207-
assertThat(targetProduct.getInterestRecognitionOnDisbursementDate().toString()).isEqualTo(expectedValue);
4214+
return targetProduct;
4215+
}
4216+
4217+
@Then("Loan Product response contains Buy Down Fees flag {string} with data:")
4218+
public void verifyLoanProductWithBuyDownFeesData(String expectedValue, DataTable table) throws IOException {
4219+
GetLoanProductsResponse targetProduct = getLoanProductResponse();
4220+
4221+
assertNotNull(targetProduct.getEnableBuyDownFee());
4222+
assertThat(targetProduct.getEnableBuyDownFee().toString()).isEqualTo(expectedValue);
4223+
4224+
List<String> data = table.asLists().get(1); // skip header
4225+
String buyDownFeeCalculationType = data.get(0);
4226+
String buyDownFeeStrategy = data.get(1);
4227+
String buyDownFeeIncomeType = data.get(2);
4228+
4229+
assertNotNull(targetProduct.getBuyDownFeeCalculationType());
4230+
assertNotNull(targetProduct.getBuyDownFeeStrategy());
4231+
assertNotNull(targetProduct.getBuyDownFeeIncomeType());
4232+
4233+
SoftAssertions assertions = new SoftAssertions();
4234+
assertions.assertThat(buyDownFeeCalculationType).isEqualTo(targetProduct.getBuyDownFeeCalculationType().getValue());
4235+
assertions.assertThat(buyDownFeeStrategy).isEqualTo(targetProduct.getBuyDownFeeStrategy().getValue());
4236+
assertions.assertThat(buyDownFeeIncomeType).isEqualTo(targetProduct.getBuyDownFeeIncomeType().getValue());
4237+
assertions.assertAll();
4238+
}
4239+
4240+
@Then("Loan Product response contains Buy Down Fees flag {string}")
4241+
public void verifyLoanProductWithBuyDownFeesFlag(String expectedValue) throws IOException {
4242+
GetLoanProductsResponse targetProduct = getLoanProductResponse();
4243+
4244+
assertNotNull(targetProduct.getEnableBuyDownFee());
4245+
assertThat(targetProduct.getEnableBuyDownFee().toString()).isEqualTo(expectedValue);
4246+
}
4247+
4248+
public Response<GetLoansLoanIdResponse> getLoanDetailsResponse() throws IOException {
4249+
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
4250+
4251+
long loanId = loanResponse.body().getLoanId();
4252+
4253+
Optional<Response<GetLoansLoanIdResponse>> loanDetailsResponseOptional = Optional
4254+
.of(loansApi.retrieveLoan(loanId, false, "", "", "").execute());
4255+
Response<GetLoansLoanIdResponse> loanDetailsResponse = loanDetailsResponseOptional
4256+
.orElseThrow(() -> new RuntimeException("Failed to retrieve loan details - response is null"));
4257+
4258+
ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse);
4259+
testContext().set(TestContextKey.LOAN_RESPONSE, loanDetailsResponse);
4260+
return loanDetailsResponse;
4261+
}
4262+
4263+
@Then("Loan Details response contains Buy Down Fees flag {string} and data:")
4264+
public void verifyBuyDownFeeDataInLoanResponse(final String expectedValue, DataTable table) throws IOException {
4265+
Response<GetLoansLoanIdResponse> loanDetailsResponse = getLoanDetailsResponse();
4266+
4267+
ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse);
4268+
testContext().set(TestContextKey.LOAN_RESPONSE, loanDetailsResponse);
4269+
4270+
GetLoansLoanIdResponse loanDetails = loanDetailsResponse.body();
4271+
4272+
assertNotNull(loanDetails.getEnableBuyDownFee());
4273+
assertThat(loanDetails.getEnableBuyDownFee().toString()).isEqualTo(expectedValue);
4274+
4275+
List<String> data = table.asLists().get(1); // skip header
4276+
String buyDownFeeCalculationType = data.get(0);
4277+
String buyDownFeeStrategy = data.get(1);
4278+
String buyDownFeeIncomeType = data.get(2);
4279+
4280+
assertNotNull(loanDetails.getBuyDownFeeCalculationType());
4281+
assertNotNull(loanDetails.getBuyDownFeeStrategy());
4282+
assertNotNull(loanDetails.getBuyDownFeeIncomeType());
4283+
4284+
SoftAssertions assertions = new SoftAssertions();
4285+
assertions.assertThat(buyDownFeeCalculationType).isEqualTo(loanDetails.getBuyDownFeeCalculationType().getValue());
4286+
assertions.assertThat(buyDownFeeStrategy).isEqualTo(loanDetails.getBuyDownFeeStrategy().getValue());
4287+
assertions.assertThat(buyDownFeeIncomeType).isEqualTo(loanDetails.getBuyDownFeeIncomeType().getValue());
4288+
assertions.assertAll();
4289+
}
4290+
4291+
@Then("Loan Details response contains Buy Down Fees flag {string}")
4292+
public void verifyBuyDownFeeFlagInLoanResponse(final String expectedValue) throws IOException {
4293+
Response<GetLoansLoanIdResponse> loanDetailsResponse = getLoanDetailsResponse();
4294+
4295+
ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse);
4296+
testContext().set(TestContextKey.LOAN_RESPONSE, loanDetailsResponse);
4297+
4298+
GetLoansLoanIdResponse loanDetails = loanDetailsResponse.body();
4299+
4300+
assertNotNull(loanDetails.getEnableBuyDownFee());
4301+
assertThat(loanDetails.getEnableBuyDownFee().toString()).isEqualTo(expectedValue);
42084302
}
42094303

42104304
@Then("Loan Details response contains chargedOffOnDate set to {string}")
@@ -4283,23 +4377,6 @@ public Response<PostLoansLoanIdTransactionsResponse> addCapitalizedIncomeToTheLo
42834377
return capitalizedIncomeResponse;
42844378
}
42854379

4286-
public Response<PostLoansLoanIdTransactionsResponse> addBuyDownFeeToTheLoanOnWithEURTransactionAmount(
4287-
final String transactionPaymentType, final String transactionDate, final String amount) throws IOException {
4288-
final Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
4289-
final long loanId = loanResponse.body().getLoanId();
4290-
4291-
final DefaultPaymentType paymentType = DefaultPaymentType.valueOf(transactionPaymentType);
4292-
final Long paymentTypeValue = paymentTypeResolver.resolve(paymentType);
4293-
4294-
final PostLoansLoanIdTransactionsRequest buyDownFeeRequest = LoanRequestFactory.defaultBuyDownFeeIncomeRequest()
4295-
.transactionDate(transactionDate).transactionAmount(Double.valueOf(amount)).paymentTypeId(paymentTypeValue)
4296-
.externalId("EXT-BUY-DOWN-FEES" + UUID.randomUUID());
4297-
4298-
final Response<PostLoansLoanIdTransactionsResponse> buyDownFeeResponse = loanTransactionsApi
4299-
.executeLoanTransaction(loanId, buyDownFeeRequest, "buyDownFee").execute();
4300-
return buyDownFeeResponse;
4301-
}
4302-
43034380
@And("Admin adds capitalized income with {string} payment type to the loan on {string} with {string} EUR transaction amount")
43044381
public void adminAddsCapitalizedIncomeToTheLoanOnWithEURTransactionAmount(final String transactionPaymentType,
43054382
final String transactionDate, final String amount) throws IOException {
@@ -4309,15 +4386,6 @@ public void adminAddsCapitalizedIncomeToTheLoanOnWithEURTransactionAmount(final
43094386
ErrorHelper.checkSuccessfulApiCall(capitalizedIncomeResponse);
43104387
}
43114388

4312-
@And("Admin adds buy down fee with {string} payment type to the loan on {string} with {string} EUR transaction amount")
4313-
public void adminAddsBuyDownFeesToTheLoanOnWithEURTransactionAmount(final String transactionPaymentType, final String transactionDate,
4314-
final String amount) throws IOException {
4315-
final Response<PostLoansLoanIdTransactionsResponse> buyDownFeesIncomeResponse = addBuyDownFeeToTheLoanOnWithEURTransactionAmount(
4316-
transactionPaymentType, transactionDate, amount);
4317-
testContext().set(TestContextKey.LOAN_BUY_DOWN_FEE_RESPONSE, buyDownFeesIncomeResponse);
4318-
ErrorHelper.checkSuccessfulApiCall(buyDownFeesIncomeResponse);
4319-
}
4320-
43214389
public Response<PostLoansLoanIdTransactionsResponse> adjustCapitalizedIncome(final String transactionPaymentType,
43224390
final String transactionDate, final String amount, final Long transactionId) throws IOException {
43234391

fineract-e2e-tests-runner/src/test/resources/features/Loan.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ Feature: Loan
104104
When Admin sets the business date to "1 January 2024"
105105
And Admin creates a client with random data
106106
And Admin creates a fully customized loan with the following data:
107-
| LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy | charge calculation type | charge amount % |
108-
| LP2_ADV_PYMNT_INTEREST_DAILY_RECALC_EMI_360_30_APPROVED_OVER_APPLIED_FLAT_CAPITALIZED_INCOME | 01 January 2024 | 1000 | 7 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION | LOAN_DISBURSEMENT_CHARGE | 2 |
107+
| LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy |
108+
| LP2_ADV_PYMNT_INTEREST_DAILY_RECALC_EMI_360_30_APPROVED_OVER_APPLIED_FLAT_CAPITALIZED_INCOME | 01 January 2024 | 1000 | 7 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
109109
Then Admin fails to approve the loan on "1 January 2024" with "2001" amount and expected disbursement date on "1 January 2024" because of wrong amount
110110

111111
And Admin successfully rejects the loan on "1 January 2024"
@@ -116,8 +116,8 @@ Feature: Loan
116116
When Admin sets the business date to "1 January 2024"
117117
And Admin creates a client with random data
118118
And Admin creates a fully customized loan with the following data:
119-
| LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy | charge calculation type | charge amount % |
120-
| LP2_ADV_CUSTOM_PMT_ALLOC_PROGRESSIVE_LOAN_SCHEDULE_HORIZONTAL | 01 January 2024 | 1000 | 7 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION | LOAN_DISBURSEMENT_CHARGE | 2 |
119+
| LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy |
120+
| LP2_ADV_CUSTOM_PMT_ALLOC_PROGRESSIVE_LOAN_SCHEDULE_HORIZONTAL | 01 January 2024 | 1000 | 7 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
121121
And Admin successfully approves the loan on "1 January 2024" with "9000" amount and expected disbursement date on "1 January 2024"
122122
And Admin successfully disburse the loan on "1 January 2024" with "9900" EUR transaction amount
123123
Then Admin fails to disburse the loan on "1 January 2024" with "1200" EUR transaction amount because of wrong amount

0 commit comments

Comments
 (0)