From 1199c32b9b718e9bca9acb057a68b932e6bfccce Mon Sep 17 00:00:00 2001 From: Pavel Filippov Date: Thu, 25 Apr 2024 17:42:20 +0300 Subject: [PATCH] MGRENTITLE-21 Fix kafka event assertions --- .../folio/am/support/KafkaEventAssertions.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/folio/am/support/KafkaEventAssertions.java b/src/test/java/org/folio/am/support/KafkaEventAssertions.java index bc268ba..c1d9cf8 100644 --- a/src/test/java/org/folio/am/support/KafkaEventAssertions.java +++ b/src/test/java/org/folio/am/support/KafkaEventAssertions.java @@ -2,15 +2,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.folio.am.integration.kafka.DiscoveryPublisher.DISCOVERY_DESTINATION; +import static org.folio.common.utils.CollectionUtils.mapItems; import static org.folio.integration.kafka.KafkaUtils.getEnvTopicName; import static org.folio.test.FakeKafkaConsumer.getEvents; -import static org.hamcrest.Matchers.hasSize; import java.util.Arrays; import java.util.stream.Collectors; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.apache.commons.lang3.ArrayUtils; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.awaitility.Awaitility; import org.awaitility.core.ConditionFactory; @@ -26,12 +25,19 @@ private static ConditionFactory await() { public static void assertDiscoveryEvents(String... moduleIds) { var topic = getEnvTopicName(DISCOVERY_DESTINATION); - var kafkaEvents = await().until(() -> getEvents(topic, DiscoveryEvent.class), hasSize(moduleIds.length)); var expectedEvents = Arrays.stream(moduleIds).map(DiscoveryEvent::new).collect(Collectors.toList()); - assertThat(kafkaEvents).map(ConsumerRecord::value).containsExactlyInAnyOrderElementsOf(expectedEvents); + await().untilAsserted(() -> { + var consumerRecords = getEvents(topic, DiscoveryEvent.class); + var entitlementEvents = mapItems(consumerRecords, ConsumerRecord::value); + assertThat(entitlementEvents).containsSequence(expectedEvents); + }); } public static void assertNoDiscoveryEvents() { - assertDiscoveryEvents(ArrayUtils.EMPTY_STRING_ARRAY); + var topic = getEnvTopicName(DISCOVERY_DESTINATION); + await().untilAsserted(() -> { + var consumerRecords = getEvents(topic, DiscoveryEvent.class); + assertThat(consumerRecords).isEmpty(); + }); } }