diff --git a/src/main/java/io/github/hectorvent/floci/services/scheduler/ScheduleInvoker.java b/src/main/java/io/github/hectorvent/floci/services/scheduler/ScheduleInvoker.java index 41940514c9..649d3212e1 100644 --- a/src/main/java/io/github/hectorvent/floci/services/scheduler/ScheduleInvoker.java +++ b/src/main/java/io/github/hectorvent/floci/services/scheduler/ScheduleInvoker.java @@ -10,6 +10,7 @@ import io.github.hectorvent.floci.core.common.RequestScopes; import io.github.hectorvent.floci.core.common.ServiceRegistry; import io.github.hectorvent.floci.services.ecs.EcsService; import io.github.hectorvent.floci.services.ecs.model.LaunchType; +import io.github.hectorvent.floci.services.ecs.model.NetworkConfiguration; import io.github.hectorvent.floci.services.eventbridge.EventBridgeService; import io.github.hectorvent.floci.services.lambda.LambdaService; import io.github.hectorvent.floci.services.lambda.model.InvocationType; @@ -387,7 +388,8 @@ public class ScheduleInvoker { } } - private static io.github.hectorvent.floci.services.ecs.model.NetworkConfiguration ecsNetworkConfiguration( + // two NetworkConfiguration types: the ECS model's is imported, the scheduler model's is qualified. + private static NetworkConfiguration ecsNetworkConfiguration( io.github.hectorvent.floci.services.scheduler.model.NetworkConfiguration source) { if (source == null || source.getAwsvpcConfiguration() == null) { return null; @@ -400,8 +402,7 @@ public class ScheduleInvoker { targetVpc.setSecurityGroups(sourceVpc.getSecurityGroups()); targetVpc.setAssignPublicIp(sourceVpc.getAssignPublicIp()); - io.github.hectorvent.floci.services.ecs.model.NetworkConfiguration target = - new io.github.hectorvent.floci.services.ecs.model.NetworkConfiguration(); + NetworkConfiguration target = new NetworkConfiguration(); target.setAwsvpcConfiguration(targetVpc); return target; } diff --git a/src/test/java/io/github/hectorvent/floci/services/eventbridge/ReplayDispatcherTest.java b/src/test/java/io/github/hectorvent/floci/services/eventbridge/ReplayDispatcherTest.java index dcd1cd8556..a54bc8c36a 100644 --- a/src/test/java/io/github/hectorvent/floci/services/eventbridge/ReplayDispatcherTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/eventbridge/ReplayDispatcherTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.eventbridge; +import io.github.hectorvent.floci.services.eventbridge.model.ArchivedEvent; import io.github.hectorvent.floci.services.eventbridge.model.Replay; import io.github.hectorvent.floci.services.eventbridge.model.ReplayState; import io.vertx.core.Vertx; @@ -84,9 +85,8 @@ class ReplayDispatcherTest { return replay; } - private static io.github.hectorvent.floci.services.eventbridge.model.ArchivedEvent archivedEvent() { - io.github.hectorvent.floci.services.eventbridge.model.ArchivedEvent event = - new io.github.hectorvent.floci.services.eventbridge.model.ArchivedEvent(); + private static ArchivedEvent archivedEvent() { + ArchivedEvent event = new ArchivedEvent(); event.setEventTime(Instant.EPOCH.plusSeconds(1)); return event; } 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 4e22d2f459..0a332b11a6 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 @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.pipes; import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.services.msk.MskService; import io.github.hectorvent.floci.services.pipes.model.Pipe; import org.junit.jupiter.api.BeforeEach; @@ -145,10 +146,10 @@ class PipesKafkaConsumerManagerTest { """)); assertEquals("SourceParameters.ManagedStreamingKafkaParameters.TopicName is required", - assertThrows(io.github.hectorvent.floci.core.common.AwsException.class, + assertThrows(AwsException.class, () -> manager.resolveTopicName(managed)).getMessage()); assertEquals("SourceParameters.SelfManagedKafkaParameters.TopicName is required", - assertThrows(io.github.hectorvent.floci.core.common.AwsException.class, + assertThrows(AwsException.class, () -> manager.resolveTopicName(selfManaged)).getMessage()); } @@ -163,10 +164,10 @@ class PipesKafkaConsumerManagerTest { selfManaged.setSourceParameters(MAPPER.createObjectNode()); assertEquals("SourceParameters.ManagedStreamingKafkaParameters is required", - assertThrows(io.github.hectorvent.floci.core.common.AwsException.class, + assertThrows(AwsException.class, () -> manager.resolveTopicName(managed)).getMessage()); assertEquals("SourceParameters.SelfManagedKafkaParameters is required", - assertThrows(io.github.hectorvent.floci.core.common.AwsException.class, + assertThrows(AwsException.class, () -> manager.resolveTopicName(selfManaged)).getMessage()); } diff --git a/src/test/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvokerTest.java b/src/test/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvokerTest.java index bf6bb33486..5645172c1f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvokerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/pipes/PipesTargetInvokerTest.java @@ -7,6 +7,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig; import io.github.hectorvent.floci.services.eventbridge.EventBridgeService; import io.github.hectorvent.floci.services.lambda.LambdaService; import io.github.hectorvent.floci.services.lambda.model.InvocationType; +import io.github.hectorvent.floci.services.lambda.model.InvokeResult; import io.github.hectorvent.floci.services.pipes.model.DesiredState; import io.github.hectorvent.floci.services.pipes.model.Pipe; import io.github.hectorvent.floci.services.sns.SnsService; @@ -19,6 +20,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.HashMap; import java.util.List; @@ -109,7 +111,7 @@ class PipesTargetInvokerTest { void invoke_keepsTheQualifierOfTheTargetFunctionArn() { Pipe pipe = createPipe("arn:aws:lambda:us-east-1:000000000000:function:my-fn:PROD", null); when(lambdaService.invoke(anyString(), anyString(), any(byte[].class), any(InvocationType.class))) - .thenReturn(new io.github.hectorvent.floci.services.lambda.model.InvokeResult(200, null, "{}".getBytes(), null, "req")); + .thenReturn(new InvokeResult(200, null, "{}".getBytes(), null, "req")); invoker.invoke(pipe, "{}", "us-east-1"); @@ -359,9 +361,9 @@ class PipesTargetInvokerTest { void applyEnrichment_invokesLambdaAndReturnsResponse() { String region = "us-east-1"; Pipe pipe = enrichmentPipe(region, "arn:aws:lambda:" + region + ":000000000000:function:enrich-fn"); - byte[] resp = "{\"systemId\":\"S1\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8); + byte[] resp = "{\"systemId\":\"S1\"}".getBytes(StandardCharsets.UTF_8); when(lambdaService.invoke(eq(region), eq("enrich-fn"), any(byte[].class), eq(InvocationType.RequestResponse))) - .thenReturn(new io.github.hectorvent.floci.services.lambda.model.InvokeResult(200, null, resp, null, "req")); + .thenReturn(new InvokeResult(200, null, resp, null, "req")); String out = invoker.applyEnrichment(pipe, "[{\"body\":\"{}\"}]", region); @@ -369,7 +371,7 @@ class PipesTargetInvokerTest { ArgumentCaptor payloadCaptor = ArgumentCaptor.forClass(byte[].class); verify(lambdaService).invoke(eq(region), eq("enrich-fn"), payloadCaptor.capture(), eq(InvocationType.RequestResponse)); assertEquals("[{\"body\":\"{}\"}]", - new String(payloadCaptor.getValue(), java.nio.charset.StandardCharsets.UTF_8)); + new String(payloadCaptor.getValue(), StandardCharsets.UTF_8)); } @Test @@ -377,7 +379,7 @@ class PipesTargetInvokerTest { String region = "us-east-1"; Pipe pipe = enrichmentPipe(region, "arn:aws:lambda:" + region + ":000000000000:function:enrich-fn:PROD"); when(lambdaService.invoke(eq(region), eq("enrich-fn:PROD"), any(byte[].class), eq(InvocationType.RequestResponse))) - .thenReturn(new io.github.hectorvent.floci.services.lambda.model.InvokeResult(200, null, "{}".getBytes(), null, "req")); + .thenReturn(new InvokeResult(200, null, "{}".getBytes(), null, "req")); invoker.applyEnrichment(pipe, "[]", region); @@ -397,7 +399,7 @@ class PipesTargetInvokerTest { String region = "us-east-1"; Pipe pipe = enrichmentPipe(region, "arn:aws:lambda:" + region + ":000000000000:function:enrich-fn"); when(lambdaService.invoke(eq(region), eq("enrich-fn"), any(byte[].class), eq(InvocationType.RequestResponse))) - .thenReturn(new io.github.hectorvent.floci.services.lambda.model.InvokeResult(200, null, new byte[0], null, "req")); + .thenReturn(new InvokeResult(200, null, new byte[0], null, "req")); assertNull(invoker.applyEnrichment(pipe, "[]", region)); } @@ -408,8 +410,8 @@ class PipesTargetInvokerTest { Pipe pipe = enrichmentPipe(region, "arn:aws:lambda:" + region + ":000000000000:function:enrich-fn"); for (String body : new String[]{"{}", "[]", " { } ", "[ ]"}) { when(lambdaService.invoke(eq(region), eq("enrich-fn"), any(byte[].class), eq(InvocationType.RequestResponse))) - .thenReturn(new io.github.hectorvent.floci.services.lambda.model.InvokeResult( - 200, null, body.getBytes(java.nio.charset.StandardCharsets.UTF_8), null, "req")); + .thenReturn(new InvokeResult( + 200, null, body.getBytes(StandardCharsets.UTF_8), null, "req")); assertNull(invoker.applyEnrichment(pipe, "[]", region), "enrichment response " + body + " should skip the target"); } @@ -421,8 +423,8 @@ class PipesTargetInvokerTest { String region = "us-east-1"; Pipe pipe = enrichmentPipe(region, "arn:aws:lambda:" + region + ":000000000000:function:enrich-fn"); when(lambdaService.invoke(eq(region), eq("enrich-fn"), any(byte[].class), eq(InvocationType.RequestResponse))) - .thenReturn(new io.github.hectorvent.floci.services.lambda.model.InvokeResult( - 200, null, "[{}]".getBytes(java.nio.charset.StandardCharsets.UTF_8), null, "req")); + .thenReturn(new InvokeResult( + 200, null, "[{}]".getBytes(StandardCharsets.UTF_8), null, "req")); assertEquals("[{}]", invoker.applyEnrichment(pipe, "[]", region)); } @@ -441,7 +443,7 @@ class PipesTargetInvokerTest { String region = "us-east-1"; Pipe pipe = enrichmentPipe(region, "arn:aws:lambda:" + region + ":000000000000:function:enrich-fn"); when(lambdaService.invoke(eq(region), eq("enrich-fn"), any(byte[].class), eq(InvocationType.RequestResponse))) - .thenReturn(new io.github.hectorvent.floci.services.lambda.model.InvokeResult(200, "Unhandled", "boom".getBytes(), null, "req")); + .thenReturn(new InvokeResult(200, "Unhandled", "boom".getBytes(), null, "req")); assertThrows(RuntimeException.class, () -> invoker.applyEnrichment(pipe, "[]", region)); } @@ -452,7 +454,7 @@ class PipesTargetInvokerTest { String region = "us-east-1"; Pipe pipe = createPipe("arn:aws:lambda:" + region + ":000000000000:function:my-fn", null); when(lambdaService.invoke(eq(region), eq("my-fn"), any(byte[].class), eq(InvocationType.RequestResponse))) - .thenReturn(new io.github.hectorvent.floci.services.lambda.model.InvokeResult(200, "Unhandled", "boom".getBytes(), null, "req")); + .thenReturn(new InvokeResult(200, "Unhandled", "boom".getBytes(), null, "req")); assertThrows(RuntimeException.class, () -> invoker.invoke(pipe, "{}", region)); } diff --git a/src/test/java/io/github/hectorvent/floci/services/scheduler/ScheduleInvokerTest.java b/src/test/java/io/github/hectorvent/floci/services/scheduler/ScheduleInvokerTest.java index c1b2039b71..d552a75f43 100644 --- a/src/test/java/io/github/hectorvent/floci/services/scheduler/ScheduleInvokerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/scheduler/ScheduleInvokerTest.java @@ -10,6 +10,7 @@ import io.github.hectorvent.floci.services.ecs.model.ContainerOverride; import io.github.hectorvent.floci.services.ecs.model.LaunchType; import io.github.hectorvent.floci.services.eventbridge.EventBridgeService; import io.github.hectorvent.floci.services.lambda.LambdaService; +import io.github.hectorvent.floci.services.lambda.model.InvocationType; import io.github.hectorvent.floci.services.redshiftdata.RedshiftDataService; import io.github.hectorvent.floci.services.scheduler.model.AwsVpcConfiguration; import io.github.hectorvent.floci.services.scheduler.model.EcsParameters; @@ -31,6 +32,7 @@ import org.mockito.ArgumentCaptor; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.UUID; @@ -42,6 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.AdditionalMatchers.aryEq; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.argThat; @@ -280,7 +283,7 @@ class ScheduleInvokerTest { attrs != null && attrs.containsKey("BinAttr") && "Binary".equals(attrs.get("BinAttr").getDataType()) - && java.util.Arrays.equals("hello".getBytes(), attrs.get("BinAttr").getBinaryValue())), + && Arrays.equals("hello".getBytes(), attrs.get("BinAttr").getBinaryValue())), isNull(), isNull(), eq("us-east-1")); } @@ -555,9 +558,9 @@ class ScheduleInvokerTest { verify(lambdaService).invokeArn( eq(arn), - org.mockito.AdditionalMatchers.aryEq( + aryEq( "{\"detail\":{\"job\":\"workflow-recovery\"}}".getBytes()), - eq(io.github.hectorvent.floci.services.lambda.model.InvocationType.Event)); + eq(InvocationType.Event)); } @Test @@ -679,6 +682,7 @@ class ScheduleInvokerTest { invoke(target, "us-west-2"); + // two NetworkConfiguration and AwsVpcConfiguration types: the scheduler model's are imported. ArgumentCaptor networkCaptor = ArgumentCaptor.forClass(io.github.hectorvent.floci.services.ecs.model.NetworkConfiguration.class); verify(ecsService).runTask( @@ -693,9 +697,9 @@ class ScheduleInvokerTest { eq("us-east-1")); io.github.hectorvent.floci.services.ecs.model.AwsVpcConfiguration awsvpc = networkCaptor.getValue().getAwsvpcConfiguration(); - org.junit.jupiter.api.Assertions.assertEquals(List.of("subnet-a", "subnet-b"), awsvpc.getSubnets()); - org.junit.jupiter.api.Assertions.assertEquals(List.of("sg-a"), awsvpc.getSecurityGroups()); - org.junit.jupiter.api.Assertions.assertEquals("DISABLED", awsvpc.getAssignPublicIp()); + assertEquals(List.of("subnet-a", "subnet-b"), awsvpc.getSubnets()); + assertEquals(List.of("sg-a"), awsvpc.getSecurityGroups()); + assertEquals("DISABLED", awsvpc.getAssignPublicIp()); } @Test diff --git a/tools/checkstyle/suppressions.xml b/tools/checkstyle/suppressions.xml index f2aab779ea..143fb524d8 100644 --- a/tools/checkstyle/suppressions.xml +++ b/tools/checkstyle/suppressions.xml @@ -229,7 +229,6 @@ - @@ -312,7 +311,6 @@ -