FINERACT-2081: Add all loan term validations to loan details

This commit is contained in:
Oleksii Novikov
2024-10-12 08:05:30 +02:00
committed by Arnold Gálovics
parent fe16b61c72
commit 25866edfc9
18 changed files with 383 additions and 161 deletions
@@ -94,6 +94,7 @@ import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.integrationtests.common.BusinessDateHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
import org.apache.fineract.integrationtests.common.LoanRescheduleRequestHelper;
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.accounting.Account;
@@ -176,6 +177,8 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest {
private static final BusinessDateHelper BUSINESS_DATE_HELPER = new BusinessDateHelper();
private static final ChargesHelper CHARGES_HELPER = new ChargesHelper();
private static final ClientHelper CLIENT_HELPER = new ClientHelper(REQUEST_SPEC, RESPONSE_SPEC);
private static final LoanRescheduleRequestHelper LOAN_RESCHEDULE_REQUEST_HELPER = new LoanRescheduleRequestHelper(REQUEST_SPEC,
RESPONSE_SPEC);
private static RequestSpecification createRequestSpecification() {
RequestSpecification request = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
@@ -290,30 +290,23 @@ public class ExternalBusinessEventTest extends BaseLoanIntegrationTest {
&& Objects.equals(statusId, businessEvent.getStatusId().doubleValue())
&& Objects.equals(principalDisbursed, businessEvent.getPrincipalDisbursed())
&& Objects.equals(principalOutstanding, businessEvent.getPrincipalOutstanding())
&& emiAmountVariationsMatch((List<Map<String, Object>>) externalEvent.getPayLoad().get("emiAmountVariations"),
businessEvent.emiAmountVariationType);
&& loanTermVariationsMatch((List<Map<String, Object>>) externalEvent.getPayLoad().get("loanTermVariations"),
businessEvent.loanTermVariationType);
}).count();
Assertions.assertEquals(1, count, "Expected business event not found " + businessEvent);
}
}
private boolean emiAmountVariationsMatch(List<Map<String, Object>> emiAmountVariations, List<String> expectedTypes) {
private boolean loanTermVariationsMatch(final List<Map<String, Object>> loanTermVariations, final List<String> expectedTypes) {
if (CollectionUtils.isEmpty(expectedTypes)) {
return true;
}
int numberOfMatches = 0;
if (CollectionUtils.isNotEmpty(emiAmountVariations)) {
for (String expectedType : expectedTypes) {
int i = 0;
while (i < emiAmountVariations.size() && !StringUtils
.equals((String) ((Map<String, Object>) emiAmountVariations.get(i).get("termType")).get("value"), expectedType)) {
i++;
}
if (i < emiAmountVariations.size()) {
numberOfMatches++;
}
}
}
final long numberOfMatches = expectedTypes
.stream().filter(
expectedType -> loanTermVariations.stream()
.anyMatch(variation -> StringUtils
.equals((String) ((Map<String, Object>) variation.get("termType")).get("value"), expectedType)))
.count();
return numberOfMatches == expectedTypes.size();
}
@@ -335,6 +328,6 @@ public class ExternalBusinessEventTest extends BaseLoanIntegrationTest {
private Integer statusId;
private Double principalDisbursed;
private Double principalOutstanding;
private List<String> emiAmountVariationType;
private List<String> loanTermVariationType;
}
}