FINERACT-2418: Extend disbursal and reage events with changed terms flag

This commit is contained in:
Oleksii Novikov
2026-02-18 09:27:59 +00:00
committed by Adam Saghy
parent 136a966fc3
commit 1feb1d730f
17 changed files with 279 additions and 18 deletions
@@ -0,0 +1,28 @@
/**
* 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.event.loan.transaction;
public class LoanReAgeTransactionEvent extends AbstractLoanTransactionEvent {
@Override
public String getEventName() {
return "LoanReAgeTransactionBusinessEvent";
}
}
@@ -37,6 +37,7 @@ import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.avro.loan.v1.LoanTransactionFlagsDataV1;
import org.apache.fineract.client.feign.FineractFeignClient;
import org.apache.fineract.client.feign.util.CallFailedRuntimeException;
import org.apache.fineract.client.models.LoanScheduleData;
@@ -49,6 +50,7 @@ import org.apache.fineract.test.helper.ErrorMessageHelper;
import org.apache.fineract.test.helper.Utils;
import org.apache.fineract.test.messaging.EventAssertion;
import org.apache.fineract.test.messaging.event.loan.LoanReAgeEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanReAgeTransactionEvent;
import org.apache.fineract.test.stepdef.AbstractStepDef;
import org.apache.fineract.test.support.TestContextKey;
import org.junit.jupiter.api.Assertions;
@@ -414,4 +416,20 @@ public class LoanReAgingStepDef extends AbstractStepDef {
assertThat(exception.getDeveloperMessage()).contains(errorMessage);
}
@Then("LoanReAgeTransactionBusinessEvent has changedTerms {string}")
public void checkReAgeTransactionEventChangedTerms(final String expectedChangedTerms) {
final PostLoansLoanIdTransactionsResponse reAgingResponse = testContext().get(TestContextKey.LOAN_REAGING_RESPONSE);
Assertions.assertNotNull(reAgingResponse);
final Long transactionId = reAgingResponse.getResourceId();
Assertions.assertNotNull(transactionId);
final Boolean expectedValue = "null".equalsIgnoreCase(expectedChangedTerms) ? null : Boolean.valueOf(expectedChangedTerms);
eventAssertion.assertEvent(LoanReAgeTransactionEvent.class, transactionId).extractingData(loanTransactionDataV1 -> {
final LoanTransactionFlagsDataV1 flags = loanTransactionDataV1.getFlags();
final Boolean actualChangedTerms = flags == null ? null : flags.getChangedTerms();
assertThat(actualChangedTerms).as("changedTerms in LoanReAgeTransactionBusinessEvent").isEqualTo(expectedValue);
return null;
});
}
}
@@ -67,6 +67,7 @@ import org.apache.fineract.avro.loan.v1.LoanChargePaidByDataV1;
import org.apache.fineract.avro.loan.v1.LoanStatusEnumDataV1;
import org.apache.fineract.avro.loan.v1.LoanTransactionAdjustmentDataV1;
import org.apache.fineract.avro.loan.v1.LoanTransactionDataV1;
import org.apache.fineract.avro.loan.v1.LoanTransactionFlagsDataV1;
import org.apache.fineract.client.feign.FineractFeignClient;
import org.apache.fineract.client.feign.util.CallFailedRuntimeException;
import org.apache.fineract.client.models.AdvancedPaymentData;
@@ -162,6 +163,7 @@ import org.apache.fineract.test.messaging.event.loan.transaction.LoanCapitalized
import org.apache.fineract.test.messaging.event.loan.transaction.LoanChargeAdjustmentPostBusinessEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanChargeOffEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanChargeOffUndoEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanDisbursalTransactionEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanTransactionAccrualActivityPostEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanTransactionContractTerminationPostBusinessEvent;
import org.apache.fineract.test.messaging.store.EventStore;
@@ -5922,4 +5924,35 @@ public class LoanStepDef extends AbstractStepDef {
return advancedPaymentData;
}
@When("Admin disburses the loan on {string} with {string} EUR transaction amount")
public void disburseLoanForEventVerification(String actualDisbursementDate, String transactionAmount) {
PostLoansResponse loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
assertNotNull(loanResponse);
long loanId = loanResponse.getLoanId();
PostLoansLoanIdRequest disburseRequest = LoanRequestFactory.defaultLoanDisburseRequest()
.actualDisbursementDate(actualDisbursementDate).transactionAmount(new BigDecimal(transactionAmount));
PostLoansLoanIdResponse loanDisburseResponse = ok(
() -> fineractClient.loans().stateTransitions(loanId, disburseRequest, Map.of("command", "disburse")));
testContext().set(TestContextKey.LOAN_DISBURSE_RESPONSE, loanDisburseResponse);
}
@Then("LoanDisbursalTransactionBusinessEvent has changedTerms {string}")
public void checkDisbursalTransactionEventChangedTerms(final String expectedChangedTerms) {
final PostLoansLoanIdResponse disburseResponse = testContext().get(TestContextKey.LOAN_DISBURSE_RESPONSE);
assertNotNull(disburseResponse);
final Long transactionId = disburseResponse.getSubResourceId();
assertNotNull(transactionId);
final Boolean expectedValue = "null".equalsIgnoreCase(expectedChangedTerms) ? null : Boolean.valueOf(expectedChangedTerms);
eventAssertion.assertEvent(LoanDisbursalTransactionEvent.class, transactionId).extractingData(loanTransactionDataV1 -> {
final LoanTransactionFlagsDataV1 flags = loanTransactionDataV1.getFlags();
final Boolean actualChangedTerms = flags == null ? null : flags.getChangedTerms();
assertThat(actualChangedTerms).as("changedTerms in LoanDisbursalTransactionBusinessEvent").isEqualTo(expectedValue);
return null;
});
}
}