FINERACT-2232: added e2e automation tests for capitalized income reversal
This commit is contained in:
+1
@@ -37,6 +37,7 @@ public enum TransactionType {
|
||||
CAPITALIZED_INCOME("capitalizedIncome"), //
|
||||
CAPITALIZED_INCOME_AMORTIZATION("capitalizedIncomeAmortization"), //
|
||||
CAPITALIZED_INCOME_ADJUSTMENT("capitalizedIncomeAdjustment"), //
|
||||
CAPITALIZED_INCOME_AMORTIZATION_ADJUSTMENT("capitalizedIncomeAmortizationAdjustment"), //
|
||||
;
|
||||
|
||||
public final String value;
|
||||
|
||||
+8
@@ -158,6 +158,14 @@ public final class ErrorMessageHelper {
|
||||
return "Failed data validation due to: cannot.be.in.the.future.";
|
||||
}
|
||||
|
||||
public static String addCapitalizedIncomeUndoFailureTransactionTypeNonReversal() {
|
||||
return "Only (non-reversed) transactions of type repayment, waiver, accrual, credit balance refund, capitalized income or capitalized income adjustment can be adjusted.";
|
||||
}
|
||||
|
||||
public static String addCapitalizedIncomeUndoFailureAdjustmentExists() {
|
||||
return "Capitalized income transaction cannot be reversed when non-reversed adjustment exists for it.";
|
||||
}
|
||||
|
||||
public static String wrongAmountInRepaymentSchedule(int line, BigDecimal actual, BigDecimal expected) {
|
||||
String lineToStr = String.valueOf(line);
|
||||
String actualToStr = actual.toString();
|
||||
|
||||
+2
-2
@@ -2542,7 +2542,7 @@ public class LoanProductGlobalInitializerStep implements FineractGlobalInitializ
|
||||
|
||||
// Merchant issued with Interest refund + interest recalculation, 360/30
|
||||
// accrual activity enabled
|
||||
// (LP2_ADV_PYMNT_INTEREST_DAILY_EMI_ACTUAL_ACTUAL_INTEREST_REFUND_INTEREST_RECALCULATION)
|
||||
// (LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_INTEREST_REFUND_INTEREST_RECALC_ACCRUAL_ACTIVITY)
|
||||
String name103 = DefaultLoanProduct.LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_INTEREST_REFUND_INTEREST_RECALC_ACCRUAL_ACTIVITY
|
||||
.getName();
|
||||
PostLoanProductsRequest loanProductsRequestLP2AdvancedpaymentInterestEmi36030InterestRefundRecalculationAccrualActivity = loanProductsRequestFactory
|
||||
@@ -2573,7 +2573,7 @@ public class LoanProductGlobalInitializerStep implements FineractGlobalInitializ
|
||||
|
||||
// Merchant issued with Interest refund + interest recalculation, 360/30
|
||||
// accrual activity enabled
|
||||
// (LP2_ADV_PYMNT_INTEREST_DAILY_EMI_ACTUAL_ACTUAL_INTEREST_REFUND_INTEREST_RECALCULATION)
|
||||
// (LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_INTEREST_REFUND_INTEREST_RECALC_DOWNPAYMENT_ACCRUAL_ACTIVITY)
|
||||
String name104 = DefaultLoanProduct.LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_INTEREST_REFUND_INTEREST_RECALC_DOWNPAYMENT_ACCRUAL_ACTIVITY
|
||||
.getName();
|
||||
PostLoanProductsRequest loanProductsRequestLP2AdvancedpaymentInterestEmi36030InterestRefundRecalculation = loanProductsRequestFactory
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.test.messaging.event.loan.transaction;
|
||||
|
||||
public class LoanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent extends AbstractLoanTransactionEvent {
|
||||
|
||||
@Override
|
||||
public String getEventName() {
|
||||
return "LoanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent";
|
||||
}
|
||||
}
|
||||
+47
-13
@@ -410,8 +410,8 @@ public class LoanRepaymentStepDef extends AbstractStepDef {
|
||||
GetLoansLoanIdTransactions targetTransaction = transactions.stream()
|
||||
.filter(t -> Boolean.TRUE.equals(t.getType().getCapitalizedIncomeAdjustment())).toList().get(nthItem);
|
||||
|
||||
PostLoansLoanIdTransactionsTransactionIdRequest capitalizedIncomeUndoRequest = LoanRequestFactory.defaultCapitalizedIncomeAdjustmentUndoRequest()
|
||||
.transactionDate(transactionDate);
|
||||
PostLoansLoanIdTransactionsTransactionIdRequest capitalizedIncomeUndoRequest = LoanRequestFactory
|
||||
.defaultCapitalizedIncomeAdjustmentUndoRequest().transactionDate(transactionDate);
|
||||
|
||||
Response<PostLoansLoanIdTransactionsResponse> capitalizedIncomeUndoResponse = loanTransactionsApi
|
||||
.adjustLoanTransaction(loanId, targetTransaction.getId(), capitalizedIncomeUndoRequest, "").execute();
|
||||
@@ -449,18 +449,13 @@ public class LoanRepaymentStepDef extends AbstractStepDef {
|
||||
@When("Customer undo {string}th {string} transaction made on {string}")
|
||||
public void undoNthTransactionType(String nthItemStr, String transactionType, String transactionDate) throws IOException {
|
||||
eventStore.reset();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT);
|
||||
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
|
||||
long loanId = loanResponse.body().getLoanId();
|
||||
List<GetLoansLoanIdTransactions> transactions = loansApi.retrieveLoan(loanId, false, "transactions", "", "").execute().body()
|
||||
.getTransactions();
|
||||
|
||||
int nthItem = Integer.parseInt(nthItemStr) - 1;
|
||||
GetLoansLoanIdTransactions targetTransaction = transactions//
|
||||
.stream()//
|
||||
.filter(t -> transactionDate.equals(formatter.format(t.getDate())) && transactionType.equals(t.getType().getValue()))//
|
||||
.toList()//
|
||||
.get(nthItem);//
|
||||
GetLoansLoanIdTransactions targetTransaction = eventCheckHelper.getNthTransactionType(nthItemStr, transactionType, transactionDate,
|
||||
transactions);
|
||||
|
||||
PostLoansLoanIdTransactionsTransactionIdRequest transactionUndoRequest = LoanRequestFactory.defaultTransactionUndoRequest()
|
||||
.transactionDate(transactionDate);
|
||||
@@ -487,15 +482,19 @@ public class LoanRepaymentStepDef extends AbstractStepDef {
|
||||
Response<PostLoansLoanIdTransactionsResponse> transactionUndoResponse = loanTransactionsApi
|
||||
.adjustLoanTransaction(loanId, targetTransaction.getId(), transactionUndoRequest, "").execute();
|
||||
|
||||
Integer httpStatusCodeExpected = 403;
|
||||
String developerMessageExpected = String.format("Interest refund transaction: %s cannot be reversed or adjusted directly",
|
||||
targetTransaction.getId());
|
||||
checkMakeTransactionForbidden(transactionUndoResponse, httpStatusCodeExpected, developerMessageExpected);
|
||||
}
|
||||
|
||||
public void checkMakeTransactionForbidden(Response<PostLoansLoanIdTransactionsResponse> transactionUndoResponse,
|
||||
Integer httpStatusCodeExpected, String developerMessageExpected) throws IOException {
|
||||
String string = transactionUndoResponse.errorBody().string();
|
||||
ErrorResponse errorResponse = GSON.fromJson(string, ErrorResponse.class);
|
||||
Integer httpStatusCodeActual = errorResponse.getHttpStatusCode();
|
||||
String developerMessageActual = errorResponse.getErrors().get(0).getDeveloperMessage();
|
||||
|
||||
Integer httpStatusCodeExpected = 403;
|
||||
String developerMessageExpected = String.format("Interest refund transaction: %s cannot be reversed or adjusted directly",
|
||||
targetTransaction.getId());
|
||||
|
||||
assertThat(httpStatusCodeActual)
|
||||
.as(ErrorMessageHelper.wrongErrorCodeInFailedChargeAdjustment(httpStatusCodeActual, httpStatusCodeExpected))
|
||||
.isEqualTo(httpStatusCodeExpected);
|
||||
@@ -507,6 +506,41 @@ public class LoanRepaymentStepDef extends AbstractStepDef {
|
||||
log.debug("Error message: {}", developerMessageActual);
|
||||
}
|
||||
|
||||
@Then("Customer is forbidden to undo {string}th {string} transaction made on {string} due to transaction type is non-reversal")
|
||||
public void makeTransactionUndoForbiddenNonReversal(String nthItemStr, String transactionType, String transactionDate)
|
||||
throws IOException {
|
||||
eventStore.reset();
|
||||
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
|
||||
long loanId = loanResponse.body().getLoanId();
|
||||
GetLoansLoanIdTransactions targetTransaction = eventCheckHelper.findNthTransaction(nthItemStr, transactionType, transactionDate,
|
||||
loanId);
|
||||
|
||||
PostLoansLoanIdTransactionsTransactionIdRequest transactionUndoRequest = LoanRequestFactory.defaultTransactionUndoRequest()
|
||||
.transactionDate(transactionDate);
|
||||
|
||||
Response<PostLoansLoanIdTransactionsResponse> transactionUndoResponse = loanTransactionsApi
|
||||
.adjustLoanTransaction(loanId, targetTransaction.getId(), transactionUndoRequest, "").execute();
|
||||
checkMakeTransactionForbidden(transactionUndoResponse, 403,
|
||||
ErrorMessageHelper.addCapitalizedIncomeUndoFailureTransactionTypeNonReversal());
|
||||
}
|
||||
|
||||
@Then("Customer is forbidden to undo {string}th {string} transaction made on {string} due to adjustment exists")
|
||||
public void makeTransactionUndoForbiddenAdjustmentExiists(String nthItemStr, String transactionType, String transactionDate)
|
||||
throws IOException {
|
||||
eventStore.reset();
|
||||
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
|
||||
long loanId = loanResponse.body().getLoanId();
|
||||
GetLoansLoanIdTransactions targetTransaction = eventCheckHelper.findNthTransaction(nthItemStr, transactionType, transactionDate,
|
||||
loanId);
|
||||
|
||||
PostLoansLoanIdTransactionsTransactionIdRequest transactionUndoRequest = LoanRequestFactory.defaultTransactionUndoRequest()
|
||||
.transactionDate(transactionDate);
|
||||
|
||||
Response<PostLoansLoanIdTransactionsResponse> transactionUndoResponse = loanTransactionsApi
|
||||
.adjustLoanTransaction(loanId, targetTransaction.getId(), transactionUndoRequest, "").execute();
|
||||
checkMakeTransactionForbidden(transactionUndoResponse, 403, ErrorMessageHelper.addCapitalizedIncomeUndoFailureAdjustmentExists());
|
||||
}
|
||||
|
||||
@When("Customer undo {string}th {string} transaction made on {string} with linked {string} transaction")
|
||||
public void checkNthTransactionType(String nthItemStr, String transactionType, String transactionDate, String linkedTransactionType)
|
||||
throws IOException {
|
||||
|
||||
+21
@@ -137,6 +137,7 @@ import org.apache.fineract.test.messaging.event.loan.transaction.BulkBusinessEve
|
||||
import org.apache.fineract.test.messaging.event.loan.transaction.LoanAccrualAdjustmentTransactionBusinessEvent;
|
||||
import org.apache.fineract.test.messaging.event.loan.transaction.LoanAccrualTransactionCreatedBusinessEvent;
|
||||
import org.apache.fineract.test.messaging.event.loan.transaction.LoanAdjustTransactionBusinessEvent;
|
||||
import org.apache.fineract.test.messaging.event.loan.transaction.LoanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent;
|
||||
import org.apache.fineract.test.messaging.event.loan.transaction.LoanCapitalizedIncomeAmortizationTransactionCreatedBusinessEvent;
|
||||
import org.apache.fineract.test.messaging.event.loan.transaction.LoanChargeAdjustmentPostBusinessEvent;
|
||||
import org.apache.fineract.test.messaging.event.loan.transaction.LoanChargeOffEvent;
|
||||
@@ -4197,6 +4198,26 @@ public class LoanStepDef extends AbstractStepDef {
|
||||
finalAmortizationTransactionId);
|
||||
}
|
||||
|
||||
@Then("LoanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent is raised on {string}")
|
||||
public void checkLoanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent(final String date) throws IOException {
|
||||
Response<PostLoansResponse> loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
|
||||
long loanId = loanCreateResponse.body().getLoanId();
|
||||
|
||||
Response<GetLoansLoanIdResponse> loanDetailsResponse = loansApi.retrieveLoan(loanId, false, "transactions", "", "").execute();
|
||||
ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse);
|
||||
|
||||
List<GetLoansLoanIdTransactions> transactions = loanDetailsResponse.body().getTransactions();
|
||||
GetLoansLoanIdTransactions finalAmortizationTransaction = transactions.stream()
|
||||
.filter(t -> date.equals(FORMATTER.format(t.getDate()))
|
||||
&& "Capitalized Income Amortization Adjustment".equals(t.getType().getValue()))
|
||||
.findFirst().orElseThrow(() -> new IllegalStateException(
|
||||
String.format("No Capitalized Income Amortization Adjustment transaction found on %s", date)));
|
||||
Long finalAmortizationTransactionId = finalAmortizationTransaction.getId();
|
||||
|
||||
eventAssertion.assertEventRaised(LoanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent.class,
|
||||
finalAmortizationTransactionId);
|
||||
}
|
||||
|
||||
@And("Admin adds capitalized income adjustment with {string} payment type to the loan on {string} with {string} EUR transaction amount")
|
||||
public void adminAddsCapitalizedIncomeAdjustmentToTheLoan(final String transactionPaymentType, final String transactionDate,
|
||||
final String amount) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user