FINERACT-2181: Enhance job execution polling in E2E tests

This commit is contained in:
Adam Saghy
2025-06-10 17:54:51 +02:00
parent 3cef64f3cf
commit c37e2daa86
5 changed files with 137 additions and 97 deletions
@@ -0,0 +1,38 @@
/**
* 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.config;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
@Getter
public class JobPollingProperties {
@Value("${fineract-test.job.interval-in-sec}")
private long pollingIntervalInSec;
@Value("${fineract-test.job.delay-in-sec}")
private long pollingDelayInSec;
@Value("${fineract-test.job.at-most-in-sec}")
private long pollingAtMostInSec;
}
@@ -31,6 +31,7 @@ import org.apache.fineract.client.services.SchedulerJobApi;
import org.apache.fineract.test.data.job.Job;
import org.apache.fineract.test.data.job.JobResolver;
import org.apache.fineract.test.helper.ErrorHelper;
import org.apache.fineract.test.messaging.config.JobPollingProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import retrofit2.Response;
@@ -43,6 +44,9 @@ public class JobService {
@Autowired
private SchedulerJobApi schedulerJobApi;
@Autowired
private JobPollingProperties jobPollingProperties;
private final JobResolver jobResolver;
public void execute(Job job) {
@@ -62,10 +66,10 @@ public class JobService {
private void waitUntilJobIsFinished(Job job) {
String jobName = job.getName();
await().atMost(Duration.ofMinutes(2)) //
await().atMost(Duration.ofSeconds(jobPollingProperties.getPollingAtMostInSec())) //
.alias("%s didn't finish on time".formatted(jobName)) //
.pollInterval(Duration.ofSeconds(5)) //
.pollDelay(Duration.ofSeconds(5)) //
.pollInterval(Duration.ofSeconds(jobPollingProperties.getPollingIntervalInSec())) //
.pollDelay(Duration.ofSeconds(jobPollingProperties.getPollingDelayInSec())) //
.until(() -> {
log.info("Waiting for job {} to finish", jobName);
Long jobId = jobResolver.resolve(job);
@@ -130,6 +130,7 @@ import org.apache.fineract.test.helper.Utils;
import org.apache.fineract.test.initializer.global.LoanProductGlobalInitializerStep;
import org.apache.fineract.test.messaging.EventAssertion;
import org.apache.fineract.test.messaging.config.EventProperties;
import org.apache.fineract.test.messaging.config.JobPollingProperties;
import org.apache.fineract.test.messaging.event.EventCheckHelper;
import org.apache.fineract.test.messaging.event.loan.LoanRescheduledDueAdjustScheduleEvent;
import org.apache.fineract.test.messaging.event.loan.LoanStatusChangedEvent;
@@ -217,6 +218,9 @@ public class LoanStepDef extends AbstractStepDef {
@Autowired
private LoanDisbursementDetailsApi loanDisbursementDetailsApi;
@Autowired
private JobPollingProperties jobPollingProperties;
@When("Admin creates a new Loan")
public void createLoan() throws IOException {
Response<PostClientsResponse> clientResponse = testContext().get(TestContextKey.CLIENT_CREATE_RESPONSE);
@@ -2493,18 +2497,9 @@ public class LoanStepDef extends AbstractStepDef {
@When("Admin checks that Loan COB is running until the current business date")
public void checkLoanCOBCatchUpRunningUntilCOBBusinessDate() {
await().atMost(Duration.ofMinutes(2)) //
.pollInterval(Duration.ofSeconds(5)) //
.pollDelay(Duration.ofSeconds(5)) //
.until(() -> {
Response<IsCatchUpRunningDTO> isCatchUpRunningResponse = loanCobCatchUpApi.isCatchUpRunning().execute();
ErrorHelper.checkSuccessfulApiCall(isCatchUpRunningResponse);
IsCatchUpRunningDTO isCatchUpRunning = isCatchUpRunningResponse.body();
return isCatchUpRunning.getCatchUpRunning();
});
await().atMost(Duration.ofMinutes(4)) //
.pollInterval(Duration.ofSeconds(5)) //
.pollDelay(Duration.ofSeconds(5)) //
await().atMost(Duration.ofSeconds(jobPollingProperties.getPollingAtMostInSec())) //
.pollInterval(Duration.ofSeconds(jobPollingProperties.getPollingIntervalInSec())) //
.pollDelay(Duration.ofSeconds(jobPollingProperties.getPollingDelayInSec())) //
.until(() -> {
Response<IsCatchUpRunningDTO> isCatchUpRunningResponse = loanCobCatchUpApi.isCatchUpRunning().execute();
ErrorHelper.checkSuccessfulApiCall(isCatchUpRunningResponse);
@@ -40,3 +40,6 @@ fineract-test.event.wait-timeout-in-sec=${EVENT_WAIT_TIMEOUT_IN_SEC:5}
fineract-test.event.verification-enabled=${EVENT_VERIFICATION_ENABLED:false}
fineract-test.client-read-timeout=${CLIENT_READ_TIMEOUT:60}
fineract-test.job.interval-in-sec=${POLLING_INTERVAL_IN_SEC:1}
fineract-test.job.delay-in-sec=${POLLING_DELAY_IN_SEC:3}
fineract-test.job.at-most-in-sec=${POLLING_AT_MOST_IN_SEC:120}
@@ -35,108 +35,108 @@ Feature: COBFeature
@TestRailId:C2791
Scenario: Verify that COB processes loans which are not closed/overpaid and has a last_closed_business_date exactly 1 day behind COB date
When Admin sets the business date to "01 July 2023"
When Admin sets the business date to "01 January 2022"
When Admin creates a client with random data
When Admin creates a new default Loan with date: "01 July 2023"
And Admin successfully approves the loan on "01 July 2023" with "1000" amount and expected disbursement date on "01 July 2023"
When Admin successfully disburse the loan on "01 July 2023" with "1000" EUR transaction amount
When Admin creates a new default Loan with date: "01 January 2022"
And Admin successfully approves the loan on "01 January 2022" with "1000" amount and expected disbursement date on "01 January 2022"
When Admin successfully disburse the loan on "01 January 2022" with "1000" EUR transaction amount
Then Loan status will be "ACTIVE"
Then Admin checks that last closed business date of loan is "null"
When Admin sets the business date to "02 July 2023"
When Admin sets the business date to "02 January 2022"
When Admin runs COB job
Then Admin checks that last closed business date of loan is "01 July 2023"
When Admin sets the business date to "03 July 2023"
Then Admin checks that last closed business date of loan is "01 January 2022"
When Admin sets the business date to "03 January 2022"
When Admin runs COB job
Then Admin checks that last closed business date of loan is "02 July 2023"
Then Admin checks that last closed business date of loan is "02 January 2022"
@TestRailId:C2792
Scenario: Verify that COB doesn’t touch loans with last closed business date behind COB date
When Admin sets the business date to "01 July 2023"
When Admin sets the business date to "01 January 2022"
When Admin creates a client with random data
When Admin creates a new default Loan with date: "01 July 2023"
And Admin successfully approves the loan on "01 July 2023" with "1000" amount and expected disbursement date on "01 July 2023"
When Admin successfully disburse the loan on "01 July 2023" with "1000" EUR transaction amount
When Admin creates a new default Loan with date: "01 January 2022"
And Admin successfully approves the loan on "01 January 2022" with "1000" amount and expected disbursement date on "01 January 2022"
When Admin successfully disburse the loan on "01 January 2022" with "1000" EUR transaction amount
Then Loan status will be "ACTIVE"
Then Admin checks that last closed business date of loan is "null"
When Admin sets the business date to "10 August 2023"
When Admin sets the business date to "10 February 2022"
When Admin runs inline COB job for Loan
Then Admin checks that last closed business date of loan is "09 August 2023"
Then Admin checks that delinquency range is: "RANGE_3" and has delinquentDate "2023-08-03"
Then Admin checks that last closed business date of loan is "09 February 2022"
Then Admin checks that delinquency range is: "RANGE_3" and has delinquentDate "2022-02-03"
Then Loan delinquency history has the following details:
| Range (Classification) | Added on date | Lifted on date |
| RANGE_3 | 10 August 2023 | |
| RANGE_1 | 04 August 2023 | 09 August 2023 |
When Admin sets the business date to "12 August 2023"
| RANGE_3 | 10 February 2022 | |
| RANGE_1 | 04 February 2022 | 09 February 2022 |
When Admin sets the business date to "12 February 2022"
When Admin runs COB job
Then Admin checks that last closed business date of loan is "09 August 2023"
Then Admin checks that last closed business date of loan is "09 February 2022"
Then Loan delinquency history has the following details:
| Range (Classification) | Added on date | Lifted on date |
| RANGE_3 | 10 August 2023 | |
| RANGE_1 | 04 August 2023 | 09 August 2023 |
| RANGE_3 | 10 February 2022 | |
| RANGE_1 | 04 February 2022 | 09 February 2022 |
@TestRailId:C2793
Scenario: Verify that COB doesn’t touch CLOSED loans
When Admin sets the business date to "01 July 2023"
When Admin sets the business date to "01 January 2022"
When Admin creates a client with random data
When Admin creates a new default Loan with date: "01 July 2023"
And Admin successfully approves the loan on "01 July 2023" with "1000" amount and expected disbursement date on "01 July 2023"
When Admin successfully disburse the loan on "01 July 2023" with "1000" EUR transaction amount
When Admin creates a new default Loan with date: "01 January 2022"
And Admin successfully approves the loan on "01 January 2022" with "1000" amount and expected disbursement date on "01 January 2022"
When Admin successfully disburse the loan on "01 January 2022" with "1000" EUR transaction amount
Then Loan status will be "ACTIVE"
Then Admin checks that last closed business date of loan is "null"
When Admin sets the business date to "10 August 2023"
When Admin sets the business date to "10 February 2022"
When Admin runs inline COB job for Loan
Then Admin checks that last closed business date of loan is "09 August 2023"
Then Admin checks that delinquency range is: "RANGE_3" and has delinquentDate "2023-08-03"
Then Admin checks that last closed business date of loan is "09 February 2022"
Then Admin checks that delinquency range is: "RANGE_3" and has delinquentDate "2022-02-03"
Then Loan delinquency history has the following details:
| Range (Classification) | Added on date | Lifted on date |
| RANGE_3 | 10 August 2023 | |
| RANGE_1 | 04 August 2023 | 09 August 2023 |
And Customer makes "AUTOPAY" repayment on "10 August 2023" with 1000 EUR transaction amount
| RANGE_3 | 10 February 2022 | |
| RANGE_1 | 04 February 2022 | 09 February 2022 |
And Customer makes "AUTOPAY" repayment on "10 February 2022" with 1000 EUR transaction amount
Then Loan status will be "CLOSED_OBLIGATIONS_MET"
Then Admin checks that delinquency range is: "NO_DELINQUENCY" and has delinquentDate ""
Then Loan delinquency history has the following details:
| Range (Classification) | Added on date | Lifted on date |
| RANGE_3 | 10 August 2023 | 10 August 2023 |
| RANGE_1 | 04 August 2023 | 09 August 2023 |
When Admin sets the business date to "11 August 2023"
| RANGE_3 | 10 February 2022 | 10 February 2022 |
| RANGE_1 | 04 February 2022 | 09 February 2022 |
When Admin sets the business date to "11 February 2022"
When Admin runs COB job
Then Admin checks that last closed business date of loan is "09 August 2023"
Then Admin checks that last closed business date of loan is "09 February 2022"
Then Loan delinquency history has the following details:
| Range (Classification) | Added on date | Lifted on date |
| RANGE_3 | 10 August 2023 | 10 August 2023 |
| RANGE_1 | 04 August 2023 | 09 August 2023 |
| RANGE_3 | 10 February 2022 | 10 February 2022 |
| RANGE_1 | 04 February 2022 | 09 February 2022 |
@TestRailId:C2794
Scenario: Verify that COB doesn’t touch OVERPAID loans
When Admin sets the business date to "01 July 2023"
When Admin sets the business date to "01 January 2022"
When Admin creates a client with random data
When Admin creates a new default Loan with date: "01 July 2023"
And Admin successfully approves the loan on "01 July 2023" with "1000" amount and expected disbursement date on "01 July 2023"
When Admin successfully disburse the loan on "01 July 2023" with "1000" EUR transaction amount
When Admin creates a new default Loan with date: "01 January 2022"
And Admin successfully approves the loan on "01 January 2022" with "1000" amount and expected disbursement date on "01 January 2022"
When Admin successfully disburse the loan on "01 January 2022" with "1000" EUR transaction amount
Then Loan status will be "ACTIVE"
Then Admin checks that last closed business date of loan is "null"
When Admin sets the business date to "10 August 2023"
When Admin sets the business date to "10 February 2022"
When Admin runs inline COB job for Loan
Then Admin checks that last closed business date of loan is "09 August 2023"
Then Admin checks that delinquency range is: "RANGE_3" and has delinquentDate "2023-08-03"
Then Admin checks that last closed business date of loan is "09 February 2022"
Then Admin checks that delinquency range is: "RANGE_3" and has delinquentDate "2022-02-03"
Then Loan delinquency history has the following details:
| Range (Classification) | Added on date | Lifted on date |
| RANGE_3 | 10 August 2023 | |
| RANGE_1 | 04 August 2023 | 09 August 2023 |
And Customer makes "AUTOPAY" repayment on "10 August 2023" with 1200 EUR transaction amount
| RANGE_3 | 10 February 2022 | |
| RANGE_1 | 04 February 2022 | 09 February 2022 |
And Customer makes "AUTOPAY" repayment on "10 February 2022" with 1200 EUR transaction amount
Then Loan status will be "OVERPAID"
Then Admin checks that delinquency range is: "NO_DELINQUENCY" and has delinquentDate ""
Then Loan delinquency history has the following details:
| Range (Classification) | Added on date | Lifted on date |
| RANGE_3 | 10 August 2023 | 10 August 2023 |
| RANGE_1 | 04 August 2023 | 09 August 2023 |
When Admin sets the business date to "11 August 2023"
| RANGE_3 | 10 February 2022 | 10 February 2022 |
| RANGE_1 | 04 February 2022 | 09 February 2022 |
When Admin sets the business date to "11 February 2022"
When Admin runs COB job
Then Admin checks that last closed business date of loan is "09 August 2023"
Then Admin checks that last closed business date of loan is "09 February 2022"
Then Loan delinquency history has the following details:
| Range (Classification) | Added on date | Lifted on date |
| RANGE_3 | 10 August 2023 | 10 August 2023 |
| RANGE_1 | 04 August 2023 | 09 August 2023 |
| RANGE_3 | 10 February 2022 | 10 February 2022 |
| RANGE_1 | 04 February 2022 | 09 February 2022 |
@TestRailId:C2795
Scenario: Verify that COB catch up runs properly on loan which is behind date because of locked with error
@@ -163,66 +163,66 @@ Feature: COBFeature
@TestRailId:C2796
Scenario: Verify that after COB runs there are no unreleased loan locks
When Admin sets the business date to "01 July 2023"
When Admin sets the business date to "01 January 2022"
When Admin creates a client with random data
When Admin creates a new default Loan with date: "01 July 2023"
And Admin successfully approves the loan on "01 July 2023" with "1000" amount and expected disbursement date on "01 July 2023"
When Admin successfully disburse the loan on "01 July 2023" with "1000" EUR transaction amount
When Admin creates a new default Loan with date: "01 January 2022"
And Admin successfully approves the loan on "01 January 2022" with "1000" amount and expected disbursement date on "01 January 2022"
When Admin successfully disburse the loan on "01 January 2022" with "1000" EUR transaction amount
Then Loan status will be "ACTIVE"
Then Admin checks that last closed business date of loan is "null"
When Admin sets the business date to "02 July 2023"
When Admin sets the business date to "02 January 2022"
When Admin runs COB job
Then The loan account is not locked
@TestRailId:C2797
Scenario: Verify that Inline COB is executed for stuck loans - when payment happened on a loan with last closed business date in the past, COB got executed before the repayment
When Admin sets the business date to "01 July 2023"
When Admin sets the business date to "01 January 2022"
When Admin creates a client with random data
When Admin creates a new default Loan with date: "01 July 2023"
And Admin successfully approves the loan on "01 July 2023" with "1000" amount and expected disbursement date on "01 July 2023"
When Admin successfully disburse the loan on "01 July 2023" with "1000" EUR transaction amount
When Admin creates a new default Loan with date: "01 January 2022"
And Admin successfully approves the loan on "01 January 2022" with "1000" amount and expected disbursement date on "01 January 2022"
When Admin successfully disburse the loan on "01 January 2022" with "1000" EUR transaction amount
Then Loan status will be "ACTIVE"
Then Admin checks that last closed business date of loan is "null"
When Admin sets the business date to "02 July 2023"
When Admin sets the business date to "02 January 2022"
When Admin runs COB job
Then Admin checks that last closed business date of loan is "01 July 2023"
When Admin sets the business date to "04 July 2023"
Then Admin checks that last closed business date of loan is "01 January 2022"
When Admin sets the business date to "04 January 2022"
When Admin creates new user with "NO_BYPASS_AUTOTEST" username, "NO_BYPASS_AUTOTEST_ROLE" role name and given permissions:
| REPAYMENT_LOAN |
When Created user makes externalID controlled "AUTOPAY" repayment on "04 July 2023" with 500 EUR transaction amount
Then Admin checks that last closed business date of loan is "03 July 2023"
When Created user makes externalID controlled "AUTOPAY" repayment on "04 January 2022" with 500 EUR transaction amount
Then Admin checks that last closed business date of loan is "03 January 2022"
@TestRailId:C2798
Scenario: Verify that Inline COB is executed for stuck loans - when payment happened on a locked loan COB got executed before the repayment
When Admin sets the business date to "01 July 2023"
When Admin sets the business date to "01 January 2022"
When Admin creates a client with random data
When Admin creates a new default Loan with date: "01 July 2023"
And Admin successfully approves the loan on "01 July 2023" with "1000" amount and expected disbursement date on "01 July 2023"
When Admin successfully disburse the loan on "01 July 2023" with "1000" EUR transaction amount
When Admin creates a new default Loan with date: "01 January 2022"
And Admin successfully approves the loan on "01 January 2022" with "1000" amount and expected disbursement date on "01 January 2022"
When Admin successfully disburse the loan on "01 January 2022" with "1000" EUR transaction amount
Then Loan status will be "ACTIVE"
Then Admin checks that last closed business date of loan is "null"
When Admin sets the business date to "02 July 2023"
When Admin sets the business date to "02 January 2022"
When Admin runs COB job
Then Admin checks that last closed business date of loan is "01 July 2023"
Then Admin checks that last closed business date of loan is "01 January 2022"
When Admin places a lock on loan account with an error message
When Admin sets the business date to "04 July 2023"
When Admin sets the business date to "04 January 2022"
When Admin creates new user with "NO_BYPASS_AUTOTEST" username, "NO_BYPASS_AUTOTEST_ROLE" role name and given permissions:
| REPAYMENT_LOAN |
When Created user makes externalID controlled "AUTOPAY" repayment on "04 July 2023" with 500 EUR transaction amount
Then Admin checks that last closed business date of loan is "03 July 2023"
When Created user makes externalID controlled "AUTOPAY" repayment on "04 January 2022" with 500 EUR transaction amount
Then Admin checks that last closed business date of loan is "03 January 2022"
@TestRailId:C3044 @AdvancedPaymentAllocation
Scenario: Verify that LoanAccountCustomSnapshotBusinessEvent is created with proper business date when installment is due date and COB runs
When Admin sets the business date to "01 January 2024"
When Admin sets the business date to "01 January 2022"
When Admin creates a client with random data
When Admin set "LP2_DOWNPAYMENT_AUTO_ADVANCED_PAYMENT_ALLOCATION" loan product "DEFAULT" transaction type to "NEXT_INSTALLMENT" future installment allocation rule
When Admin creates a fully customized loan with the following data:
| LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy |
| LP2_DOWNPAYMENT_AUTO_ADVANCED_PAYMENT_ALLOCATION | 01 January 2024 | 1000 | 0 | FLAT | SAME_AS_REPAYMENT_PERIOD | EQUAL_INSTALLMENTS | 45 | DAYS | 15 | DAYS | 3 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
And Admin successfully approves the loan on "01 January 2024" with "1000" amount and expected disbursement date on "01 January 2024"
When Admin successfully disburse the loan on "01 January 2024" with "1000" EUR transaction amount
When Admin sets the business date to "17 January 2024"
| LP2_DOWNPAYMENT_AUTO_ADVANCED_PAYMENT_ALLOCATION | 01 January 2022 | 1000 | 0 | FLAT | SAME_AS_REPAYMENT_PERIOD | EQUAL_INSTALLMENTS | 45 | DAYS | 15 | DAYS | 3 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
And Admin successfully approves the loan on "01 January 2022" with "1000" amount and expected disbursement date on "01 January 2022"
When Admin successfully disburse the loan on "01 January 2022" with "1000" EUR transaction amount
When Admin sets the business date to "17 January 2022"
When Admin runs inline COB job for Loan
Then LoanAccountCustomSnapshotBusinessEvent is created with business date "17 January 2024"
Then LoanAccountCustomSnapshotBusinessEvent is created with business date "17 January 2022"