FINERACT-1724 fix flaky testCatchUpInLockedInstanceLastCOBDateIsNotNull test

This commit is contained in:
Peter Bagrij
2023-11-20 09:16:49 +01:00
committed by Arnold Gálovics
parent c65a763c7f
commit 03154f3101
2 changed files with 29 additions and 1 deletions
@@ -25,6 +25,7 @@ import io.restassured.path.json.JsonPath;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
@@ -46,6 +47,7 @@ import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.apache.fineract.integrationtests.inlinecob.InlineLoanCOBHelper;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -193,6 +195,7 @@ public class LoanCOBAccountLockCatchupInlineCOBTest {
loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
loanAccountLockHelper = new LoanAccountLockHelper(requestSpec, new ResponseSpecBuilder().expectStatusCode(202).build());
// create client
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
Assertions.assertNotNull(clientID);
@@ -200,6 +203,7 @@ public class LoanCOBAccountLockCatchupInlineCOBTest {
ChargesHelper.getLoanOverdueFeeJSONWithCalculationTypePercentage("1"));
Assertions.assertNotNull(overdueFeeChargeId);
// create loan product
final Integer loanProductID = createLoanProduct(overdueFeeChargeId.toString());
Assertions.assertNotNull(loanProductID);
HashMap loanStatusHashMap;
@@ -210,28 +214,39 @@ public class LoanCOBAccountLockCatchupInlineCOBTest {
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
// approve loan
loanStatusHashMap = loanTransactionHelper.approveLoan("01 March 2020", loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
String loanDetails = loanTransactionHelper.getLoanDetails(requestSpec, responseSpec, loanID);
// disburse loan
loanStatusHashMap = loanTransactionHelper.disburseLoanWithNetDisbursalAmount("02 March 2020", loanID,
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
// update business date 2020-03-02
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.COB_DATE, LocalDate.of(2020, 3, 2));
// execute inline cob for the loan
inlineLoanCOBHelper.executeInlineCOB(List.of(loanID.longValue()));
GetLoansLoanIdResponse loan = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanID);
Assertions.assertEquals(LocalDate.of(2020, 3, 2), loan.getLastClosedBusinessDate());
// update business date to 2020-03-05
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, LocalDate.of(2020, 3, 5));
// apply lock on the loan
loanAccountLockHelper.placeSoftLockOnLoanAccount(loanID, "LOAN_INLINE_COB_PROCESSING", "Sample error");
loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
// execute catchup which sets the last cob date first 2020-03-04 and then 2020-03-05, as this loan is two
// days behind
loanCOBCatchUpHelper.executeLoanCOBCatchUp();
Utils.conditionalSleepWithMaxWait(30, 5, () -> loanCOBCatchUpHelper.isLoanCOBCatchUpRunning());
Awaitility.await().atMost(Duration.ofSeconds(30)).with().pollInterval(Duration.ofSeconds(5)) //
.until(() -> loanCOBCatchUpHelper.isLoanCOBCatchUpFinishedFor(LocalDate.of(2020, 3, 4))); //
loan = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanID);
Assertions.assertEquals(LocalDate.of(2020, 3, 4), loan.getLastClosedBusinessDate());
@@ -18,12 +18,16 @@
*/
package org.apache.fineract.integrationtests.common.loans;
import java.time.LocalDate;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.client.models.GetOldestCOBProcessedLoanResponse;
import org.apache.fineract.client.models.IsCatchUpRunningResponse;
import org.apache.fineract.integrationtests.client.IntegrationTest;
import org.jetbrains.annotations.NotNull;
import retrofit2.Response;
@Slf4j
public class LoanCOBCatchUpHelper extends IntegrationTest {
public LoanCOBCatchUpHelper() {}
@@ -33,6 +37,15 @@ public class LoanCOBCatchUpHelper extends IntegrationTest {
return Boolean.TRUE.equals(Objects.requireNonNull(response.body()).getIsCatchUpRunning());
}
public boolean isLoanCOBCatchUpFinishedFor(@NotNull LocalDate cobBusinessDate) {
Response<IsCatchUpRunningResponse> response = executeGetLoanCatchUpStatus();
IsCatchUpRunningResponse isCatchUpRunningResponse = Objects.requireNonNull(response.body());
GetOldestCOBProcessedLoanResponse getOldestCOBProcessedLoanResponse = executeRetrieveOldestCOBProcessedLoan();
return !Boolean.TRUE.equals(isCatchUpRunningResponse.getIsCatchUpRunning())
&& cobBusinessDate.equals(getOldestCOBProcessedLoanResponse.getCobProcessedDate());
}
public Response<Void> executeLoanCOBCatchUp() {
return okR(fineract().loanCobCatchUpApi.executeLoanCOBCatchUp());
}