Light, fluffy, and always free - The AWS Local Emulator alternative
refactor(stepfunctions): move library usages to imports (#3904)
Vũ Thế Huydc0cbaf6b15f
diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.javaindex dc18c6daaa..bde16a5536 100644--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java@@ -71,6 +71,7 @@ import jakarta.enterprise.inject.Instance;import jakarta.inject.Inject;import jakarta.ws.rs.core.MultivaluedHashMap;import jakarta.ws.rs.core.MultivaluedMap;+import jakarta.ws.rs.core.Response;import org.jboss.logging.Logger;import java.io.IOException;@@ -1151,7 +1152,7 @@ public class AslExecutor {MultivaluedMap<String, String> params = new MultivaluedHashMap<>();flattenQueryParams(input, "", params);- jakarta.ws.rs.core.Response response;+ Response response;try {response = cloudFormationHandler.handle(pascalAction, params, region);} catch (AwsException e) {@@ -1406,7 +1407,7 @@ public class AslExecutor {* which entry it was.*/private JsonNode invokeOptimizedPutEvents(JsonNode input, String region) throws Exception {- jakarta.ws.rs.core.Response response;+ Response response;try {response = eventBridgeHandler.handle("PutEvents", input, region);} catch (AwsException e) {@@ -1875,7 +1876,7 @@ public class AslExecutor {// Convert camelCase to PascalCase (e.g., putItem → PutItem)String pascalAction = Character.toUpperCase(camelCaseAction.charAt(0)) + camelCaseAction.substring(1);- jakarta.ws.rs.core.Response response;+ Response response;try {response = dynamoDbJsonHandler.handle(pascalAction, input, region);} catch (AwsException e) {@@ -1933,7 +1934,7 @@ public class AslExecutor {}private JsonNode invokeSqsAction(String action, JsonNode input, String region, String errorPrefix, boolean awsSdkStyleErrors) {- jakarta.ws.rs.core.Response response;+ Response response;try {response = sqsJsonHandler.handle(action, input, region);} catch (AwsException e) {@@ -1981,7 +1982,7 @@ public class AslExecutor {request.put("Message", message.toString());}- jakarta.ws.rs.core.Response response;+ Response response;try {response = snsJsonHandler.handle("Publish", request, region);} catch (AwsException e) {diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCustomResourceLivenessTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCustomResourceLivenessTest.javaindex 223f55cca5..6e2517f17b 100644--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCustomResourceLivenessTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCustomResourceLivenessTest.java@@ -22,6 +22,7 @@ import jakarta.enterprise.inject.Instance;import jakarta.inject.Inject;import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.Test;+import org.mockito.ArgumentMatchers;import java.util.ArrayList;import java.util.List;@@ -147,7 +148,7 @@ class AslExecutorCustomResourceLivenessTest {""".formatted(FUNCTION_ARN),"{\"Records\":[{\"body\":\"hello\"}]}");- verify(customResourceLiveness, never()).touch(org.mockito.ArgumentMatchers.anyString());+ verify(customResourceLiveness, never()).touch(ArgumentMatchers.anyString());}private void run(String definition, String input) {diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFailStateErrorCauseTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFailStateErrorCauseTest.javaindex aedb5ae7d8..d0742136ad 100644--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFailStateErrorCauseTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFailStateErrorCauseTest.java@@ -17,6 +17,7 @@ import jakarta.enterprise.inject.Instance;import jakarta.inject.Inject;import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.Test;+import org.mockito.Mockito;import java.util.ArrayList;import java.util.List;@@ -174,6 +175,6 @@ class AslExecutorFailStateErrorCauseTest {}private static <T> T mock(Class<T> type) {- return org.mockito.Mockito.mock(type);+ return Mockito.mock(type);}}diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultWriterTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultWriterTest.javaindex e63dd4c3fb..8123d3597c 100644--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultWriterTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultWriterTest.java@@ -1,9 +1,9 @@package io.github.hectorvent.floci.services.stepfunctions;import com.fasterxml.jackson.databind.JsonNode;-import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.node.ArrayNode;import com.fasterxml.jackson.databind.node.ObjectNode;+import com.fasterxml.jackson.databind.ObjectMapper;import io.github.hectorvent.floci.config.EmulatorConfig;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;@@ -20,6 +20,7 @@ import jakarta.enterprise.inject.Instance;import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.Test;import org.mockito.ArgumentCaptor;+import org.mockito.Mockito;import java.util.ArrayList;import java.util.List;@@ -128,7 +129,7 @@ class AslExecutorResultWriterTest {// Capture the two S3 writes: SUCCEEDED_0.json and manifest.json.ArgumentCaptor<String> keys = ArgumentCaptor.forClass(String.class);ArgumentCaptor<byte[]> bodies = ArgumentCaptor.forClass(byte[].class);- verify(s3Service, org.mockito.Mockito.times(2))+ verify(s3Service, Mockito.times(2)).putObject(eq("my-bucket"), keys.capture(), bodies.capture(), anyString(), any());int manifestIdx = keys.getAllValues().indexOf(manifestKey);@@ -173,7 +174,7 @@ class AslExecutorResultWriterTest {// COMPACT keeps the original per-child array structure; no S3 Resource -> no export.assertEquals(results, out);- verify(s3Service, org.mockito.Mockito.never())+ verify(s3Service, Mockito.never()).putObject(anyString(), anyString(), any(byte[].class), anyString(), any());}@@ -210,7 +211,7 @@ class AslExecutorResultWriterTest {results, inputs, timings, sm, context, false);ArgumentCaptor<byte[]> bodies = ArgumentCaptor.forClass(byte[].class);- verify(s3Service, org.mockito.Mockito.times(2))+ verify(s3Service, Mockito.times(2)).putObject(eq("my-bucket"), anyString(), bodies.capture(), anyString(), any());// The records file is the JSON array write (the other write is manifest.json, an object).JsonNode first = mapper.readTree(bodies.getAllValues().get(0));@@ -278,7 +279,7 @@ class AslExecutorResultWriterTest {assertTrue(manifestKey.startsWith("/csvJobs//" + mapRunId + "/"), manifestKey);ArgumentCaptor<String> keys = ArgumentCaptor.forClass(String.class);- verify(s3Service, org.mockito.Mockito.times(2))+ verify(s3Service, Mockito.times(2)).putObject(eq("selected-bucket"), keys.capture(), any(byte[].class), anyString(), any());assertTrue(keys.getAllValues().stream().allMatch(key -> key.startsWith("/csvJobs//" + mapRunId + "/")));}@@ -327,7 +328,7 @@ class AslExecutorResultWriterTest {JsonNode output = mapper.readTree(execution.getOutput());assertEquals("jsonata-bucket", output.path("ResultWriterDetails").path("Bucket").asText());ArgumentCaptor<String> keys = ArgumentCaptor.forClass(String.class);- verify(s3Service, org.mockito.Mockito.times(2))+ verify(s3Service, Mockito.times(2)).putObject(eq("jsonata-bucket"), keys.capture(), any(byte[].class), anyString(), any());assertTrue(keys.getAllValues().stream().allMatch(key -> key.startsWith("exports/")));}@@ -347,7 +348,7 @@ class AslExecutorResultWriterTest {assertEquals("States.QueryEvaluationError", failure.error);assertTrue(failure.getMessage().contains("must resolve to an object"), failure.getMessage());- verify(s3Service, org.mockito.Mockito.never())+ verify(s3Service, Mockito.never()).putObject(anyString(), anyString(), any(byte[].class), anyString(), any());}@@ -366,7 +367,7 @@ class AslExecutorResultWriterTest {assertEquals("States.QueryEvaluationError", failure.error);assertTrue(failure.getMessage().contains("Bucket must resolve to a string"), failure.getMessage());- verify(s3Service, org.mockito.Mockito.never())+ verify(s3Service, Mockito.never()).putObject(anyString(), anyString(), any(byte[].class), anyString(), any());}@@ -407,7 +408,7 @@ class AslExecutorResultWriterTest {assertEquals("States.QueryEvaluationError", nestedBucketFailure.error);assertTrue(nestedBucketFailure.getMessage().contains("Bucket must resolve to a string"));- verify(s3Service, org.mockito.Mockito.never())+ verify(s3Service, Mockito.never()).putObject(anyString(), anyString(), any(byte[].class), anyString(), any());}@@ -428,7 +429,7 @@ class AslExecutorResultWriterTest {assertEquals("States.QueryEvaluationError", failure.error);assertEquals("The JSONata expression '$states.input.missing' specified for the field "+ "'ResultWriter/Arguments/Prefix' returned nothing (undefined).", failure.cause);- verify(s3Service, org.mockito.Mockito.never())+ verify(s3Service, Mockito.never()).putObject(anyString(), anyString(), any(byte[].class), anyString(), any());}@@ -448,7 +449,7 @@ class AslExecutorResultWriterTest {assertEquals("States.ResultWriterFailed", failure.error);assertTrue(failure.getMessage().contains("same AWS Region"), failure.getMessage());- verify(s3Service, org.mockito.Mockito.never())+ verify(s3Service, Mockito.never()).putObject(anyString(), anyString(), any(byte[].class), anyString(), any());}@@ -513,7 +514,7 @@ class AslExecutorResultWriterTest {sm, context, false));assertEquals("States.ResultWriterFailed", failure.error);- verify(s3Service, org.mockito.Mockito.never())+ verify(s3Service, Mockito.never()).putObject(anyString(), anyString(), any(byte[].class), anyString(), any());}@@ -544,7 +545,7 @@ class AslExecutorResultWriterTest {assertEquals("FAILED", execution.getStatus());assertEquals("States.Runtime", execution.getError());assertTrue(execution.getCause().contains("not supported for INLINE maps"), execution.getCause());- verify(s3Service, org.mockito.Mockito.never())+ verify(s3Service, Mockito.never()).putObject(anyString(), anyString(), any(byte[].class), anyString(), any());}@@ -564,7 +565,7 @@ class AslExecutorResultWriterTest {String resultKey = null;ArgumentCaptor<String> keys = ArgumentCaptor.forClass(String.class);ArgumentCaptor<byte[]> bodies = ArgumentCaptor.forClass(byte[].class);- verify(s3Service, org.mockito.Mockito.times(2))+ verify(s3Service, Mockito.times(2)).putObject(anyString(), keys.capture(), bodies.capture(), anyString(), any());for (int i = 0; i < keys.getAllValues().size(); i++) {if (keys.getAllValues().get(i).endsWith("SUCCEEDED_0.json")) {diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/MapIterationSchedulerTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/MapIterationSchedulerTest.javaindex 2598c03121..b8e3985453 100644--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/MapIterationSchedulerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/MapIterationSchedulerTest.java@@ -1,5 +1,6 @@package io.github.hectorvent.floci.services.stepfunctions;+import org.junit.jupiter.api.Assertions;import org.junit.jupiter.api.Test;import java.time.Duration;@@ -115,7 +116,7 @@ class MapIterationSchedulerTest {void preservesInputOrderWhenItemsCompleteOutOfOrder() throws Exception {CountDownLatch laterItemsCompleted = new CountDownLatch(2);- List<Integer> results = org.junit.jupiter.api.Assertions.assertTimeoutPreemptively(+ List<Integer> results = Assertions.assertTimeoutPreemptively(Duration.ofSeconds(2),() -> MapIterationScheduler.execute(3, 3, index -> () -> {if (index == 0) {diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAccountContextIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAccountContextIntegrationTest.javaindex 41df6a0f1f..37e5cc09ea 100644--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAccountContextIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAccountContextIntegrationTest.java@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.stepfunctions;import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;import io.quarkus.test.junit.QuarkusTest;import io.restassured.response.Response;+import org.hamcrest.Matchers;import org.junit.jupiter.api.BeforeAll;import org.junit.jupiter.api.Test;@@ -113,7 +114,7 @@ class StepFunctionsAccountContextIntegrationTest {""".formatted(TABLE)).when().post("/").then().statusCode(200)- .body("Item.v.S", org.hamcrest.Matchers.equalTo("hello"));+ .body("Item.v.S", Matchers.equalTo("hello"));// 6. Isolation: a different account has no such table at all.given()@@ -225,7 +226,7 @@ class StepFunctionsAccountContextIntegrationTest {""".formatted(PARALLEL_TABLE)).when().post("/").then().statusCode(200)- .body("Item.v.S", org.hamcrest.Matchers.equalTo("A"));+ .body("Item.v.S", Matchers.equalTo("A"));given().header("Authorization", auth(ACCOUNT, "dynamodb")).header("X-Amz-Target", "DynamoDB_20120810.GetItem")@@ -235,7 +236,7 @@ class StepFunctionsAccountContextIntegrationTest {""".formatted(PARALLEL_TABLE)).when().post("/").then().statusCode(200)- .body("Item.v.S", org.hamcrest.Matchers.equalTo("B"));+ .body("Item.v.S", Matchers.equalTo("B"));}private String waitForTerminal(String execArn) throws InterruptedException {diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkQueryIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkQueryIntegrationTest.javaindex a019236032..dd6b59a3d4 100644--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkQueryIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkQueryIntegrationTest.java@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;import io.quarkus.test.junit.QuarkusTest;import io.restassured.response.Response;+import org.hamcrest.Matchers;import org.junit.jupiter.api.BeforeAll;import org.junit.jupiter.api.Test;@@ -64,7 +65,7 @@ class StepFunctionsAwsSdkQueryIntegrationTest {// Confirm the object is actually retrievable.given().when().get("/" + bucket + "/from-sfn.txt")- .then().statusCode(200).body(org.hamcrest.Matchers.containsString("hello from step functions"));+ .then().statusCode(200).body(Matchers.containsString("hello from step functions"));}// ── helpers ─────────────────────────────────────────────────────────────diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkTaskIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkTaskIntegrationTest.javaindex ceee268ad9..59db6791b6 100644--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkTaskIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkTaskIntegrationTest.java@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;import io.quarkus.test.junit.QuarkusTest;import io.restassured.response.Response;+import org.hamcrest.Matchers;import org.junit.jupiter.api.BeforeAll;import org.junit.jupiter.api.MethodOrderer;import org.junit.jupiter.api.Order;@@ -348,7 +349,7 @@ class StepFunctionsAwsSdkTaskIntegrationTest {given().when().get("/schedules/payout-nightly").then().statusCode(200)- .body("ScheduleExpression", org.hamcrest.Matchers.equalTo("rate(1 day)"));+ .body("ScheduleExpression", Matchers.equalTo("rate(1 day)"));}@Test@@ -362,7 +363,7 @@ class StepFunctionsAwsSdkTaskIntegrationTest {given().when().get("/schedules/payout-nightly").then().statusCode(200)- .body("ScheduleExpression", org.hamcrest.Matchers.equalTo("rate(2 days)"));+ .body("ScheduleExpression", Matchers.equalTo("rate(2 days)"));}@Test