FINERACT-2226: added e2e tests for validation of progressive loan charge-off reverse replay events fix
This commit is contained in:
committed by
Adam Saghy
parent
49feaab3e5
commit
9bf365b62d
+23
-1
@@ -25,6 +25,7 @@ import java.math.BigDecimal;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -80,7 +81,10 @@ public class EventAssertion {
|
||||
T event = eventFactory.create(eventClazz);
|
||||
try {
|
||||
await().atMost(Duration.ofSeconds(eventProperties.getEventWaitTimeoutInSec())).until(() -> {
|
||||
return eventStore.existsEventById(event, id);
|
||||
if (id == null) {
|
||||
return !eventStore.findByType(event).isEmpty();
|
||||
}
|
||||
return eventStore.findByType(event).stream().anyMatch(em -> event.getIdExtractor().apply(em.getData()).equals(id));
|
||||
});
|
||||
|
||||
String receivedEventsLogParam = eventStore.getReceivedEvents().stream().map(LoggedEvent::new).map(LoggedEvent::toString)
|
||||
@@ -105,6 +109,24 @@ public class EventAssertion {
|
||||
return new EventAssertionBuilder<>(eventMessage);
|
||||
}
|
||||
|
||||
public <R, T extends Event<R>> void assertEventNotRaised(Class<T> eventClazz, Predicate<? super EventMessage<R>> filter) {
|
||||
if (eventProperties.isEventVerificationDisabled()) {
|
||||
return;
|
||||
}
|
||||
T event = eventFactory.create(eventClazz);
|
||||
try {
|
||||
await().atMost(Duration.ofSeconds(eventProperties.getEventWaitTimeoutInSec()))
|
||||
.until(() -> eventStore.findByType(event).stream().anyMatch(filter));
|
||||
|
||||
String receivedEventsLogParam = eventStore.getReceivedEvents().stream().map(LoggedEvent::new).map(LoggedEvent::toString)
|
||||
.reduce("", (s, e) -> format("%s%s%n", s, e));
|
||||
Assertions.fail("%s has been received, but it was unexpected. Events received but not verified: %s", event.getEventName(),
|
||||
receivedEventsLogParam);
|
||||
} catch (ConditionTimeoutException e) {
|
||||
// This is the expected outcome here!
|
||||
}
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class EventAssertionBuilder<R> {
|
||||
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import java.util.function.Function;
|
||||
import org.apache.fineract.avro.BulkMessagePayloadV1;
|
||||
import org.apache.fineract.test.messaging.event.Event;
|
||||
|
||||
public class BulkBusinessEvent implements Event<BulkMessagePayloadV1> {
|
||||
|
||||
public static final String TYPE = "BulkBusinessEvent";
|
||||
|
||||
@Override
|
||||
public String getEventName() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BulkMessagePayloadV1> getDataClass() {
|
||||
return BulkMessagePayloadV1.class;
|
||||
}
|
||||
|
||||
// not implemented
|
||||
@Override
|
||||
public Function<BulkMessagePayloadV1, Long> getIdExtractor() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -127,6 +127,7 @@ import org.apache.fineract.test.messaging.config.EventProperties;
|
||||
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;
|
||||
import org.apache.fineract.test.messaging.event.loan.transaction.BulkBusinessEvent;
|
||||
import org.apache.fineract.test.messaging.event.loan.transaction.LoanAccrualAdjustmentTransactionBusinessEvent;
|
||||
import org.apache.fineract.test.messaging.event.loan.transaction.LoanAccrualTransactionCreatedBusinessEvent;
|
||||
import org.apache.fineract.test.messaging.event.loan.transaction.LoanAdjustTransactionBusinessEvent;
|
||||
@@ -2337,7 +2338,8 @@ public class LoanStepDef extends AbstractStepDef {
|
||||
|
||||
List<GetLoansLoanIdTransactions> transactions = loanDetailsResponse.body().getTransactions();
|
||||
GetLoansLoanIdTransactions accrualTransaction = transactions.stream()
|
||||
.filter(t -> date.equals(FORMATTER.format(t.getDate())) && "Accrual".equals(t.getType().getValue())).findFirst()
|
||||
.filter(t -> date.equals(FORMATTER.format(t.getDate())) && "Accrual".equals(t.getType().getValue()))
|
||||
.reduce((first, second) -> second)
|
||||
.orElseThrow(() -> new IllegalStateException(String.format("No Accrual transaction found on %s", date)));
|
||||
Long accrualTransactionId = accrualTransaction.getId();
|
||||
|
||||
@@ -2378,6 +2380,11 @@ public class LoanStepDef extends AbstractStepDef {
|
||||
eventAssertion.assertEventRaised(LoanChargeAdjustmentPostBusinessEvent.class, loadTransaction.getId());
|
||||
}
|
||||
|
||||
@Then("BulkBusinessEvent is not raised on {string}")
|
||||
public void checkLoanBulkBusinessEventNotCreatedBusinessEvent(String date) {
|
||||
eventAssertion.assertEventNotRaised(BulkBusinessEvent.class, em -> FORMATTER.format(em.getBusinessDate()).equals(date));
|
||||
}
|
||||
|
||||
@Then("LoanAccrualTransactionCreatedBusinessEvent is not raised on {string}")
|
||||
public void checkLoanAccrualTransactionNotCreatedBusinessEvent(String date) throws IOException {
|
||||
Response<PostLoansResponse> loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
|
||||
@@ -2390,6 +2397,9 @@ public class LoanStepDef extends AbstractStepDef {
|
||||
|
||||
assertThat(transactions).as("Unexpected Accrual activity transaction found on %s", date)
|
||||
.noneMatch(t -> date.equals(FORMATTER.format(t.getDate())) && "Accrual Activity".equals(t.getType().getValue()));
|
||||
|
||||
eventAssertion.assertEventNotRaised(LoanAccrualTransactionCreatedBusinessEvent.class,
|
||||
em -> FORMATTER.format(em.getBusinessDate()).equals(date));
|
||||
}
|
||||
|
||||
@Then("{string} transaction on {string} got reverse-replayed on {string}")
|
||||
|
||||
Reference in New Issue
Block a user