FINERACT-2421: Allow multiple interest rate schedule adjustments same date - E2E tests

This commit is contained in:
Peter Kovacs
2026-01-27 15:04:30 +01:00
committed by Adam Saghy
parent 532190a649
commit 6cc5323090
3 changed files with 374 additions and 1 deletions
@@ -470,6 +470,18 @@ public final class ErrorMessageHelper {
+ "%nNumber of transaction tab lines: %s %nNumber of expected datatable lines: %s%n", resourceId, actual, expected);
}
public static String wrongValueInLineInRescheduleTab(String resourceId, int line, List<List<String>> actualList,
List<String> expected) {
String actual = actualList.stream().map(Object::toString).collect(Collectors.joining(System.lineSeparator()));
return String.format("%nWrong value in Reschedule tab of resource %s line %s." //
+ "%nActual values in line are: %n%s %nExpected values in line: %n%s", resourceId, line, actual, expected);
}
public static String nrOfLinesWrongInRescheduleTab(String resourceId, int actual, int expected) {
return String.format("%nNumber of lines does not match in Reschedule tab and expected datatable of resource %s." //
+ "%nNumber of reschedule tab lines: %s %nNumber of expected datatable lines: %s%n", resourceId, actual, expected);
}
public static String wrongValueInLineInChargesTab(String resourceId, int line, List<List<String>> actualList, List<String> expected) {
String actual = actualList.stream().map(Object::toString).collect(Collectors.joining(System.lineSeparator()));
return String.format("%nWrong value in Charges tab of resource %s line %s." //
@@ -29,11 +29,13 @@ import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.client.feign.FineractFeignClient;
import org.apache.fineract.client.feign.util.CallFailedRuntimeException;
import org.apache.fineract.client.models.GetLoanRescheduleRequestResponse;
import org.apache.fineract.client.models.PostCreateRescheduleLoansRequest;
import org.apache.fineract.client.models.PostCreateRescheduleLoansResponse;
import org.apache.fineract.client.models.PostLoansResponse;
@@ -159,4 +161,51 @@ public class LoanRescheduleStepDef extends AbstractStepDef {
log.debug("ERROR CODE: {}", exception.getStatus());
log.debug("ERROR MESSAGE: {}", exception.getDeveloperMessage());
}
@Then("Loan Reschedule tab has the following data:")
public void loanRescheduleTabCheck(DataTable table) {
PostLoansResponse loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
long loanId = loanCreateResponse.getLoanId();
String resourceId = String.valueOf(loanId);
List<GetLoanRescheduleRequestResponse> loanRescheduleRequestResponses = ok(
() -> fineractClient.rescheduleLoans().retrieveAllRescheduleRequest("", loanId));
List<List<String>> data = table.asLists();
List<String> header = table.row(0);
checkLoanRescheduleTab(data, loanRescheduleRequestResponses, header, resourceId);
}
public void checkLoanRescheduleTab(List<List<String>> data, List<GetLoanRescheduleRequestResponse> reschedules, List<String> header,
String resourceId) {
assertThat(reschedules.size()).as(ErrorMessageHelper.nrOfLinesWrongInRescheduleTab(resourceId, reschedules.size(), data.size() - 1))
.isEqualTo(data.size() - 1);
checkLoanRescheduleTabRows(data, reschedules, header, resourceId);
}
public void checkLoanRescheduleTabRows(List<List<String>> data, List<GetLoanRescheduleRequestResponse> reschedules, List<String> header,
String resourceId) {
for (int i = 1; i < data.size(); i++) {
List<String> expectedValues = data.get(i);
GetLoanRescheduleRequestResponse reschedule = reschedules.get(i - 1);
List<String> actualValues = fetchValuesOfReschedule(header, reschedule);
assertThat(actualValues)
.as(ErrorMessageHelper.wrongValueInLineInRescheduleTab(resourceId, i, List.of(actualValues), expectedValues))
.isEqualTo(expectedValues);
}
}
private List<String> fetchValuesOfReschedule(List<String> header, GetLoanRescheduleRequestResponse r) {
List<String> actualValues = new ArrayList<>();
for (String headerName : header) {
switch (headerName) {
case "From Date" ->
actualValues.add(r.getRescheduleFromDate() == null ? null : FORMATTER_EN.format(r.getRescheduleFromDate()));
case "Reason" ->
actualValues.add(r.getRescheduleReasonCodeValue() == null ? null : r.getRescheduleReasonCodeValue().getName());
case "Status" -> actualValues.add(r.getStatusEnum() == null ? null : r.getStatusEnum().getValue());
default -> throw new IllegalStateException(String.format("Header name %s cannot be found", headerName));
}
}
return actualValues;
}
}