This is an automated email from the ASF dual-hosted git repository.
arnold pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new 03154f310 FINERACT-1724 fix flaky
testCatchUpInLockedInstanceLastCOBDateIsNotNull test
03154f310 is described below
commit 03154f31018d8965bc61bd649a45461e7da84df9
Author: Peter Bagrij <[email protected]>
AuthorDate: Sat Nov 18 16:33:54 2023 +0100
FINERACT-1724 fix flaky testCatchUpInLockedInstanceLastCOBDateIsNotNull test
---
.../LoanCOBAccountLockCatchupInlineCOBTest.java | 17 ++++++++++++++++-
.../common/loans/LoanCOBCatchUpHelper.java | 13 +++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanCOBAccountLockCatchupInlineCOBTest.java
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanCOBAccountLockCatchupInlineCOBTest.java
index 75a4850ba..d4fdbde03 100644
---
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanCOBAccountLockCatchupInlineCOBTest.java
+++
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanCOBAccountLockCatchupInlineCOBTest.java
@@ -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());
diff --git
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanCOBCatchUpHelper.java
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanCOBCatchUpHelper.java
index 606fef58a..f34341c30 100644
---
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanCOBCatchUpHelper.java
+++
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanCOBCatchUpHelper.java
@@ -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());
}