diff --git a/src/main/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvoker.java b/src/main/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvoker.java index 8da929cb52..826445a801 100644 --- a/src/main/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvoker.java +++ b/src/main/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvoker.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.pipes; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.config.EmulatorConfig; @@ -118,7 +119,7 @@ public class PipesTargetInvoker { if ((node.isObject() || node.isArray()) && node.isEmpty()) { return null; } - } catch (com.fasterxml.jackson.core.JsonProcessingException e) { + } catch (JsonProcessingException e) { // Non-JSON textual enrichment response — forward as-is. } LOG.debugv("Pipe {0}: enrichment {1} produced target payload", pipe.getName(), enrichment); diff --git a/src/test/java/io/github/hectorvent/floci/services/pipes/KarapaceManagerTest.java b/src/test/java/io/github/hectorvent/floci/services/pipes/KarapaceManagerTest.java index fce9a62c9b..909ccb6bba 100644 --- a/src/test/java/io/github/hectorvent/floci/services/pipes/KarapaceManagerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/pipes/KarapaceManagerTest.java @@ -27,6 +27,7 @@ import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.lenient; @@ -184,7 +185,7 @@ class KarapaceManagerTest { Map.of(REST_PORT, new EndpointInfo("localhost", 1))); when(lifecycleManager.createAndStart(any())).thenReturn(info); - org.junit.jupiter.api.Assertions.assertThrows(IllegalStateException.class, + assertThrows(IllegalStateException.class, () -> manager.ensureStarted("broker-1:9092")); verify(lifecycleManager).stopAndRemove("container-1", null); diff --git a/src/test/java/io/github/hectorvent/floci/services/pipes/PipesKafkaConsumerManagerTest.java b/src/test/java/io/github/hectorvent/floci/services/pipes/PipesKafkaConsumerManagerTest.java index 3cdde4f8cc..4e22d2f459 100644 --- a/src/test/java/io/github/hectorvent/floci/services/pipes/PipesKafkaConsumerManagerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/pipes/PipesKafkaConsumerManagerTest.java @@ -3,19 +3,21 @@ package io.github.hectorvent.floci.services.pipes; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.services.msk.MskService; import io.github.hectorvent.floci.services.pipes.model.Pipe; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; import java.net.URI; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -30,9 +32,9 @@ class PipesKafkaConsumerManagerTest { @BeforeEach void setUp() { - mskService = Mockito.mock(MskService.class); - karapaceManager = Mockito.mock(KarapaceManager.class); - restClient = Mockito.mock(PipesKafkaRestClient.class); + mskService = mock(MskService.class); + karapaceManager = mock(KarapaceManager.class); + restClient = mock(PipesKafkaRestClient.class); manager = new PipesKafkaConsumerManager(mskService, karapaceManager, restClient); } @@ -55,7 +57,7 @@ class PipesKafkaConsumerManagerTest { URI.create("http://localhost:8082/consumers/g/instances/instance-1")); when(karapaceManager.ensureStarted("broker-1:9092")).thenReturn(restBaseUri); when(restClient.createConsumer(eq(restBaseUri), anyString(), anyString())).thenReturn(handle); - Mockito.doThrow(new RuntimeException("subscribe failed")) + doThrow(new RuntimeException("subscribe failed")) .when(restClient).subscribe(eq(handle), anyList()); assertThrows(RuntimeException.class, () -> manager.poll(pipe)); @@ -197,7 +199,7 @@ class PipesKafkaConsumerManagerTest { String fallbackGroupId = manager.resolveConsumerGroupId(fallback); assertEquals(fallbackGroupId, manager.resolveConsumerGroupId(fallback)); - org.junit.jupiter.api.Assertions.assertTrue( + assertTrue( fallbackGroupId.startsWith("floci-pipes-orders-pipe-"), "Expected generated consumer group id prefix, got: " + fallbackGroupId); } diff --git a/src/test/java/io/github/hectorvent/floci/services/pipes/PipesPollerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/pipes/PipesPollerIntegrationTest.java index 90a51f0998..8a2ef4fe30 100644 --- a/src/test/java/io/github/hectorvent/floci/services/pipes/PipesPollerIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/pipes/PipesPollerIntegrationTest.java @@ -6,6 +6,8 @@ import org.junit.jupiter.api.*; import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.assertTrue; @QuarkusTest @@ -119,7 +121,7 @@ class PipesPollerIntegrationTest { return; } } - org.junit.jupiter.api.Assertions.fail("Source queue should be drained"); + fail("Source queue should be drained"); } @Test @@ -270,7 +272,7 @@ class PipesPollerIntegrationTest { } assertTrue(body.contains("match-1"), "Target should contain the matching message"); - org.junit.jupiter.api.Assertions.assertFalse(body.contains("no-match"), + assertFalse(body.contains("no-match"), "Target should NOT contain the non-matching message"); } @@ -294,7 +296,7 @@ class PipesPollerIntegrationTest { return; } } - org.junit.jupiter.api.Assertions.fail( + fail( "Source queue should be drained (non-matching messages deleted per AWS behavior)"); } diff --git a/src/test/java/io/github/hectorvent/floci/services/pipes/PipesPollerTest.java b/src/test/java/io/github/hectorvent/floci/services/pipes/PipesPollerTest.java index 9524d2db6a..700b3b6999 100644 --- a/src/test/java/io/github/hectorvent/floci/services/pipes/PipesPollerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/pipes/PipesPollerTest.java @@ -16,6 +16,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import java.nio.charset.StandardCharsets; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -26,6 +27,8 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -173,11 +176,11 @@ class PipesPollerTest { void pollKafka_doesNotCommitWhenDeliveryFails() throws Exception { Pipe pipe = selfManagedKafkaPipe(); KafkaRecordDto record = kafkaRecord("orders", 0, 7L, null, - "{\"status\":\"active\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8)); + "{\"status\":\"active\"}".getBytes(StandardCharsets.UTF_8)); when(kafkaConsumerManager.poll(pipe)).thenReturn(List.of(record)); when(kafkaConsumerManager.resolveBootstrapServers(pipe)).thenReturn("broker-1:9092"); - org.mockito.Mockito.doThrow(new RuntimeException("boom")) + doThrow(new RuntimeException("boom")) .when(targetInvoker).invoke(eq(pipe), anyString(), eq("us-east-1")); poller.pollKafka(pipe, "us-east-1"); @@ -189,13 +192,13 @@ class PipesPollerTest { void pollKafka_commitsDeliveredPrefixWhenLaterRecordFails() throws Exception { Pipe pipe = selfManagedKafkaPipe(); KafkaRecordDto first = kafkaRecord("orders", 0, 0L, null, - "{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8)); + "{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(StandardCharsets.UTF_8)); KafkaRecordDto second = kafkaRecord("orders", 0, 1L, null, - "{\"status\":\"active\",\"id\":\"order-2\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8)); + "{\"status\":\"active\",\"id\":\"order-2\"}".getBytes(StandardCharsets.UTF_8)); when(kafkaConsumerManager.poll(pipe)).thenReturn(List.of(first, second)); when(kafkaConsumerManager.resolveBootstrapServers(pipe)).thenReturn("broker-1:9092"); - org.mockito.Mockito.doNothing() + doNothing() .doThrow(new RuntimeException("boom")) .when(targetInvoker).invoke(eq(pipe), anyString(), eq("us-east-1")); @@ -216,13 +219,13 @@ class PipesPollerTest { Pipe pipe = selfManagedKafkaPipe(); when(kafkaConsumerManager.resolveBatchSize(eq(pipe), anyInt())).thenReturn(1); KafkaRecordDto first = kafkaRecord("orders", 0, 0L, null, - "{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8)); + "{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(StandardCharsets.UTF_8)); KafkaRecordDto second = kafkaRecord("orders", 0, 1L, null, - "{\"status\":\"active\",\"id\":\"order-2\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8)); + "{\"status\":\"active\",\"id\":\"order-2\"}".getBytes(StandardCharsets.UTF_8)); when(kafkaConsumerManager.poll(pipe)).thenReturn(List.of(first, second)); when(kafkaConsumerManager.resolveBootstrapServers(pipe)).thenReturn("broker-1:9092"); - org.mockito.Mockito.doThrow(new RuntimeException("boom")) + doThrow(new RuntimeException("boom")) .doNothing() .when(targetInvoker).invoke(eq(pipe), anyString(), eq("us-east-1")); @@ -252,15 +255,15 @@ class PipesPollerTest { void pollKafka_lambdaCommitsSuccessfulPrefixBeforeLaterFailure() throws Exception { Pipe pipe = lambdaSelfManagedKafkaPipe(); KafkaRecordDto first = kafkaRecord("orders", 0, 0L, null, - "{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8)); + "{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(StandardCharsets.UTF_8)); KafkaRecordDto skipped = kafkaRecord("orders", 0, 1L, null, - "{\"status\":\"inactive\",\"id\":\"order-2\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8)); + "{\"status\":\"inactive\",\"id\":\"order-2\"}".getBytes(StandardCharsets.UTF_8)); KafkaRecordDto failing = kafkaRecord("orders", 0, 2L, null, - "{\"status\":\"active\",\"id\":\"order-3\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8)); + "{\"status\":\"active\",\"id\":\"order-3\"}".getBytes(StandardCharsets.UTF_8)); when(kafkaConsumerManager.poll(pipe)).thenReturn(List.of(first, skipped, failing)); when(kafkaConsumerManager.resolveBootstrapServers(pipe)).thenReturn("broker-1:9092"); - org.mockito.Mockito.doNothing() + doNothing() .doThrow(new RuntimeException("boom")) .when(targetInvoker).invoke(eq(pipe), anyString(), eq("us-east-1"));