Light, fluffy, and always free - The AWS Local Emulator alternative
feat: add ListTagsForResource, TagResource, UntagResource for Step Functions (#767)
Yassir Idhbi4d2a99506a2f
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/StepFunctionsTagsTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/StepFunctionsTagsTest.javanew file mode 100644index 0000000000..b4694058e9--- /dev/null+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/StepFunctionsTagsTest.java@@ -0,0 +1,155 @@+package com.floci.test;++import org.junit.jupiter.api.AfterAll;+import org.junit.jupiter.api.BeforeAll;+import org.junit.jupiter.api.DisplayName;+import org.junit.jupiter.api.MethodOrderer;+import org.junit.jupiter.api.Order;+import org.junit.jupiter.api.Test;+import org.junit.jupiter.api.TestMethodOrder;+import software.amazon.awssdk.services.sfn.SfnClient;+import software.amazon.awssdk.services.sfn.model.ListTagsForResourceResponse;+import software.amazon.awssdk.services.sfn.model.Tag;++import java.util.List;+import java.util.Map;+import java.util.stream.Collectors;++import static org.assertj.core.api.Assertions.*;++/**+ * Compatibility tests for Step Functions tag operations:+ * ListTagsForResource, TagResource, UntagResource on state machines and activities.+ *+ * Covers issue #766: Terraform AWS provider v5+ calls ListTagsForResource+ * unconditionally on every read of aws_sfn_state_machine.+ */+@DisplayName("SFN Tag Operations")+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)+class StepFunctionsTagsTest {++ private static final String ROLE_ARN = System.getenv("SFN_ROLE_ARN") != null+ ? System.getenv("SFN_ROLE_ARN")+ : "arn:aws:iam::000000000000:role/service-role/test-role";++ private static final String SIMPLE_DEFINITION = """+ {"Comment":"tag test","StartAt":"Done","States":{"Done":{"Type":"Pass","End":true}}}+ """.strip();++ private static SfnClient sfn;+ private static String stateMachineArn;+ private static String activityArn;++ @BeforeAll+ static void setup() {+ sfn = TestFixtures.sfnClient();+ String smName = TestFixtures.uniqueName("tags-sm");+ stateMachineArn = sfn.createStateMachine(b -> b+ .name(smName)+ .definition(SIMPLE_DEFINITION)+ .roleArn(ROLE_ARN)).stateMachineArn();++ String actName = TestFixtures.uniqueName("tags-activity");+ activityArn = sfn.createActivity(b -> b.name(actName)).activityArn();+ }++ @AfterAll+ static void cleanup() {+ if (sfn != null) {+ if (stateMachineArn != null) {+ try { sfn.deleteStateMachine(b -> b.stateMachineArn(stateMachineArn)); } catch (Exception ignored) {}+ }+ if (activityArn != null) {+ try { sfn.deleteActivity(b -> b.activityArn(activityArn)); } catch (Exception ignored) {}+ }+ sfn.close();+ }+ }++ // ──────────────── State Machine Tags ────────────────++ @Test+ @Order(1)+ void listTags_newStateMachine_returnsEmptyList() {+ ListTagsForResourceResponse resp = sfn.listTagsForResource(b -> b.resourceArn(stateMachineArn));+ assertThat(resp.tags()).isEmpty();+ }++ @Test+ @Order(2)+ void tagResource_stateMachine_addsTagsAndListReturnsAll() {+ sfn.tagResource(b -> b+ .resourceArn(stateMachineArn)+ .tags(tag("env", "test"), tag("team", "platform")));++ Map<String, String> tags = tagsAsMap(sfn.listTagsForResource(b -> b.resourceArn(stateMachineArn)).tags());+ assertThat(tags)+ .containsEntry("env", "test")+ .containsEntry("team", "platform");+ }++ @Test+ @Order(3)+ void untagResource_stateMachine_removesOnlySpecifiedKeys() {+ sfn.untagResource(b -> b+ .resourceArn(stateMachineArn)+ .tagKeys("team"));++ Map<String, String> tags = tagsAsMap(sfn.listTagsForResource(b -> b.resourceArn(stateMachineArn)).tags());+ assertThat(tags)+ .containsEntry("env", "test")+ .doesNotContainKey("team");+ }++ @Test+ @Order(4)+ void tagResource_stateMachine_overwritesExistingKey() {+ sfn.tagResource(b -> b+ .resourceArn(stateMachineArn)+ .tags(tag("env", "prod")));++ Map<String, String> tags = tagsAsMap(sfn.listTagsForResource(b -> b.resourceArn(stateMachineArn)).tags());+ assertThat(tags).containsEntry("env", "prod");+ }++ // ──────────────── Activity Tags ────────────────++ @Test+ @Order(5)+ void listTags_newActivity_returnsEmptyList() {+ ListTagsForResourceResponse resp = sfn.listTagsForResource(b -> b.resourceArn(activityArn));+ assertThat(resp.tags()).isEmpty();+ }++ @Test+ @Order(6)+ void tagResource_activity_addsTagsAndListReturnsAll() {+ sfn.tagResource(b -> b+ .resourceArn(activityArn)+ .tags(tag("owner", "infra")));++ Map<String, String> tags = tagsAsMap(sfn.listTagsForResource(b -> b.resourceArn(activityArn)).tags());+ assertThat(tags).containsEntry("owner", "infra");+ }++ @Test+ @Order(7)+ void untagResource_activity_removesSpecifiedKey() {+ sfn.untagResource(b -> b+ .resourceArn(activityArn)+ .tagKeys("owner"));++ Map<String, String> tags = tagsAsMap(sfn.listTagsForResource(b -> b.resourceArn(activityArn)).tags());+ assertThat(tags).doesNotContainKey("owner");+ }++ // ──────────────── Helpers ────────────────++ private static Tag tag(String key, String value) {+ return Tag.builder().key(key).value(value).build();+ }++ private static Map<String, String> tagsAsMap(List<Tag> tags) {+ return tags.stream().collect(Collectors.toMap(Tag::key, Tag::value));+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.javaindex b904b7427d..74b213e74a 100644--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.java@@ -14,7 +14,9 @@ import jakarta.enterprise.context.ApplicationScoped;import jakarta.inject.Inject;import jakarta.ws.rs.core.Response;+import java.util.HashMap;import java.util.List;+import java.util.Map;@ApplicationScopedpublic class StepFunctionsJsonHandler {@@ -48,6 +50,9 @@ public class StepFunctionsJsonHandler {case "DescribeActivity" -> handleDescribeActivity(request);case "ListActivities" -> handleListActivities(request, region);case "GetActivityTask" -> handleGetActivityTask(request);+ case "ListTagsForResource" -> handleListTagsForResource(request);+ case "TagResource" -> handleTagResource(request);+ case "UntagResource" -> handleUntagResource(request);default -> Response.status(400).entity(new AwsErrorResponse("UnsupportedOperation", "Operation " + action + " is not supported.")).build();@@ -60,7 +65,8 @@ public class StepFunctionsJsonHandler {request.path("definition").asText(),request.path("roleArn").asText(),request.path("type").asText(null),- region+ region,+ parseTagsArray(request.path("tags")));ObjectNode response = objectMapper.createObjectNode();response.put("stateMachineArn", sm.getStateMachineArn());@@ -214,7 +220,7 @@ public class StepFunctionsJsonHandler {}private Response handleCreateActivity(JsonNode request, String region) {- Activity activity = service.createActivity(request.path("name").asText(), region);+ Activity activity = service.createActivity(request.path("name").asText(), region, parseTagsArray(request.path("tags")));ObjectNode response = objectMapper.createObjectNode();response.put("activityArn", activity.getActivityArn());response.put("creationDate", activity.getCreationDate());@@ -260,4 +266,54 @@ public class StepFunctionsJsonHandler {return Response.ok(response).build();}+ private Response handleListTagsForResource(JsonNode request) {+ java.util.Map<String, String> tags = service.listTags(request.path("resourceArn").asText());+ ObjectNode response = objectMapper.createObjectNode();+ ArrayNode array = response.putArray("tags");+ tags.forEach((k, v) -> {+ ObjectNode entry = array.addObject();+ entry.put("key", k);+ entry.put("value", v);+ });+ return Response.ok(response).build();+ }++ private Response handleTagResource(JsonNode request) {+ String arn = request.path("resourceArn").asText();+ JsonNode tagsNode = request.path("tags");+ if (!tagsNode.isArray()) {+ return Response.status(400)+ .entity(new AwsErrorResponse("ValidationException", "Parameter 'tags' must be a list"))+ .build();+ }+ service.tagResource(arn, parseTagsArray(tagsNode));+ return Response.ok(objectMapper.createObjectNode()).build();+ }++ private Response handleUntagResource(JsonNode request) {+ String arn = request.path("resourceArn").asText();+ JsonNode keysNode = request.path("tagKeys");+ if (!keysNode.isArray()) {+ return Response.status(400)+ .entity(new AwsErrorResponse("ValidationException", "Parameter 'tagKeys' must be a list"))+ .build();+ }+ java.util.List<String> tagKeys = new java.util.ArrayList<>();+ for (JsonNode key : keysNode) {+ tagKeys.add(key.asText());+ }+ service.untagResource(arn, tagKeys);+ return Response.ok(objectMapper.createObjectNode()).build();+ }++ private Map<String, String> parseTagsArray(JsonNode tagsNode) {+ Map<String, String> tags = new HashMap<>();+ if (tagsNode != null && tagsNode.isArray()) {+ for (JsonNode entry : tagsNode) {+ tags.put(entry.path("key").asText(), entry.path("value").asText());+ }+ }+ return tags;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.javaindex a54ace8769..73b01a1044 100644--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java@@ -62,7 +62,7 @@ public class StepFunctionsService {// ──────────────────────────── State Machines ────────────────────────────- public StateMachine createStateMachine(String name, String definition, String roleArn, String type, String region) {+ public StateMachine createStateMachine(String name, String definition, String roleArn, String type, String region, Map<String, String> tags) {String arn = regionResolver.buildArn("states", region, "stateMachine:" + name);if (stateMachineStore.get(arn).isPresent()) {throw new AwsException("StateMachineAlreadyExists", "State machine already exists: " + arn, 400);@@ -78,6 +78,9 @@ public class StepFunctionsService {if (type != null && !type.isEmpty()) {sm.setType(type);}+ if (tags != null && !tags.isEmpty()) {+ sm.getTags().putAll(tags);+ }stateMachineStore.put(arn, sm);LOG.infov("Created State Machine: {0}", arn);@@ -213,7 +216,7 @@ public class StepFunctionsService {// ──────────────────────────── Activities ────────────────────────────- public Activity createActivity(String name, String region) {+ public Activity createActivity(String name, String region, Map<String, String> tags) {String arn = regionResolver.buildArn("states", region, "activity:" + name);if (activityStore.get(arn).isPresent()) {throw new AwsException("ActivityAlreadyExists", "Activity already exists: " + arn, 400);@@ -221,6 +224,9 @@ public class StepFunctionsService {Activity activity = new Activity();activity.setActivityArn(arn);activity.setName(name);+ if (tags != null && !tags.isEmpty()) {+ activity.getTags().putAll(tags);+ }activityStore.put(arn, activity);LOG.infov("Created activity: {0}", arn);return activity;@@ -297,6 +303,56 @@ public class StepFunctionsService {LOG.debugv("Task heartbeat for token {0}", taskToken);}+ // ──────────────────────────── Tags ────────────────────────────++ public Map<String, String> listTags(String arn) {+ Optional<StateMachine> sm = stateMachineStore.get(arn);+ if (sm.isPresent()) {+ return sm.get().getTags();+ }+ Optional<Activity> activity = activityStore.get(arn);+ if (activity.isPresent()) {+ return activity.get().getTags();+ }+ throw new AwsException("ResourceNotFound", "Resource not found: " + arn, 400);+ }++ public void tagResource(String arn, Map<String, String> tags) {+ Optional<StateMachine> smOpt = stateMachineStore.get(arn);+ if (smOpt.isPresent()) {+ StateMachine sm = smOpt.get();+ sm.getTags().putAll(tags);+ stateMachineStore.put(arn, sm);+ return;+ }+ Optional<Activity> actOpt = activityStore.get(arn);+ if (actOpt.isPresent()) {+ Activity activity = actOpt.get();+ activity.getTags().putAll(tags);+ activityStore.put(arn, activity);+ return;+ }+ throw new AwsException("ResourceNotFound", "Resource not found: " + arn, 400);+ }++ public void untagResource(String arn, List<String> tagKeys) {+ Optional<StateMachine> smOpt = stateMachineStore.get(arn);+ if (smOpt.isPresent()) {+ StateMachine sm = smOpt.get();+ tagKeys.forEach(sm.getTags()::remove);+ stateMachineStore.put(arn, sm);+ return;+ }+ Optional<Activity> actOpt = activityStore.get(arn);+ if (actOpt.isPresent()) {+ Activity activity = actOpt.get();+ tagKeys.forEach(activity.getTags()::remove);+ activityStore.put(arn, activity);+ return;+ }+ throw new AwsException("ResourceNotFound", "Resource not found: " + arn, 400);+ }+// ──────────────────────────── Validation ────────────────────────────private void validateDefinition(String definition) {diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Activity.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Activity.javaindex cc114d7c91..8f8efd8646 100644--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Activity.java+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Activity.java@@ -3,12 +3,16 @@ package io.github.hectorvent.floci.services.stepfunctions.model;import com.fasterxml.jackson.annotation.JsonIgnoreProperties;import io.quarkus.runtime.annotations.RegisterForReflection;+import java.util.HashMap;+import java.util.Map;+@RegisterForReflection@JsonIgnoreProperties(ignoreUnknown = true)public class Activity {private String activityArn;private String name;private double creationDate;+ private Map<String, String> tags = new HashMap<>();public Activity() {this.creationDate = System.currentTimeMillis() / 1000.0;@@ -22,4 +26,7 @@ public class Activity {public double getCreationDate() { return creationDate; }public void setCreationDate(double creationDate) { this.creationDate = creationDate; }++ public Map<String, String> getTags() { return tags; }+ public void setTags(Map<String, String> tags) { this.tags = tags; }}diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachine.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachine.javaindex e3c85fe5f6..e89f2c3559 100644--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachine.java+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachine.java@@ -3,6 +3,9 @@ package io.github.hectorvent.floci.services.stepfunctions.model;import com.fasterxml.jackson.annotation.JsonIgnoreProperties;import io.quarkus.runtime.annotations.RegisterForReflection;+import java.util.HashMap;+import java.util.Map;+@RegisterForReflection@JsonIgnoreProperties(ignoreUnknown = true)public class StateMachine {@@ -13,6 +16,7 @@ public class StateMachine {private String type = "STANDARD";private String status = "ACTIVE";private double creationDate;+ private Map<String, String> tags = new HashMap<>();public StateMachine() {this.creationDate = System.currentTimeMillis() / 1000.0;@@ -38,4 +42,7 @@ public class StateMachine {public double getCreationDate() { return creationDate; }public void setCreationDate(double creationDate) { this.creationDate = creationDate; }++ public Map<String, String> getTags() { return tags; }+ public void setTags(Map<String, String> tags) { this.tags = tags; }}diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsTagsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsTagsIntegrationTest.javanew file mode 100644index 0000000000..5caa8f8d7b--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsTagsIntegrationTest.java@@ -0,0 +1,329 @@+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.junit.jupiter.api.*;++import static io.restassured.RestAssured.given;+import static org.hamcrest.Matchers.*;+import static org.junit.jupiter.api.Assertions.*;++/**+ * Integration tests for SFN tag operations via the JSON 1.0 wire path+ * (X-Amz-Target: AWSStepFunctions.*), used by the AWS SDK and Terraform.+ */+@QuarkusTest+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)+class StepFunctionsTagsIntegrationTest {++ private static final String SFN_CONTENT_TYPE = "application/x-amz-json-1.0";+ private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/test-role";+ private static final String SIMPLE_DEFINITION =+ "{\"Comment\":\"tag test\",\"StartAt\":\"Done\",\"States\":{\"Done\":{\"Type\":\"Pass\",\"End\":true}}}";++ private static String stateMachineArn;+ private static String activityArn;++ @BeforeAll+ static void configureRestAssured() {+ RestAssuredJsonUtils.configureAwsContentTypes();+ }++ @Test+ @Order(1)+ void createStateMachine() {+ Response resp = given()+ .header("X-Amz-Target", "AWSStepFunctions.CreateStateMachine")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"name\":\"tag-test-sm\",\"definition\":\"" + SIMPLE_DEFINITION.replace("\"", "\\\"") + "\",\"roleArn\":\"" + ROLE_ARN + "\"}")+ .when().post("/");+ resp.then().statusCode(200);+ stateMachineArn = resp.jsonPath().getString("stateMachineArn");+ assertNotNull(stateMachineArn);+ }++ @Test+ @Order(2)+ void createActivity() {+ Response resp = given()+ .header("X-Amz-Target", "AWSStepFunctions.CreateActivity")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"name\":\"tag-test-activity\"}")+ .when().post("/");+ resp.then().statusCode(200);+ activityArn = resp.jsonPath().getString("activityArn");+ assertNotNull(activityArn);+ }++ // ──────────────── JSON 1.0 path (X-Amz-Target) — SDK / Terraform wire ────────────────++ @Test+ @Order(3)+ void json_listTagsForResourceReturnsEmptyForNewStateMachine() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.ListTagsForResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + stateMachineArn + "\"}")+ .post("/")+ .then()+ .statusCode(200)+ .body("tags", hasSize(0));+ }++ @Test+ @Order(4)+ void json_tagResourceAddsTag() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.TagResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + stateMachineArn + "\",\"tags\":[{\"key\":\"env\",\"value\":\"test\"},{\"key\":\"owner\",\"value\":\"infra\"}]}")+ .post("/")+ .then()+ .statusCode(200);++ given()+ .header("X-Amz-Target", "AWSStepFunctions.ListTagsForResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + stateMachineArn + "\"}")+ .post("/")+ .then()+ .statusCode(200)+ .body("tags", hasSize(2))+ .body("tags.key", hasItems("env", "owner"))+ .body("tags.value", hasItems("test", "infra"));+ }++ @Test+ @Order(5)+ void json_untagResourceRemovesTag() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.UntagResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + stateMachineArn + "\",\"tagKeys\":[\"owner\"]}")+ .post("/")+ .then()+ .statusCode(200);++ given()+ .header("X-Amz-Target", "AWSStepFunctions.ListTagsForResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + stateMachineArn + "\"}")+ .post("/")+ .then()+ .statusCode(200)+ .body("tags", hasSize(1))+ .body("tags[0].key", equalTo("env"))+ .body("tags[0].value", equalTo("test"));+ }++ @Test+ @Order(6)+ void json_createStateMachine_withTags_tagsPersistedImmediately() {+ Response resp = given()+ .header("X-Amz-Target", "AWSStepFunctions.CreateStateMachine")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"name\":\"tag-test-sm-with-tags\",\"definition\":\"" + SIMPLE_DEFINITION.replace("\"", "\\\"") + "\",\"roleArn\":\"" + ROLE_ARN + "\",\"tags\":[{\"key\":\"env\",\"value\":\"prod\"},{\"key\":\"team\",\"value\":\"platform\"}]}")+ .when().post("/");+ resp.then().statusCode(200);+ String arn = resp.jsonPath().getString("stateMachineArn");++ given()+ .header("X-Amz-Target", "AWSStepFunctions.ListTagsForResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + arn + "\"}")+ .post("/")+ .then()+ .statusCode(200)+ .body("tags", hasSize(2))+ .body("tags.key", hasItems("env", "team"))+ .body("tags.value", hasItems("prod", "platform"));++ given()+ .header("X-Amz-Target", "AWSStepFunctions.DeleteStateMachine")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"stateMachineArn\":\"" + arn + "\"}")+ .post("/")+ .then().statusCode(200);+ }++ @Test+ @Order(7)+ void json_createActivity_withTags_tagsPersistedImmediately() {+ Response resp = given()+ .header("X-Amz-Target", "AWSStepFunctions.CreateActivity")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"name\":\"tag-test-activity-with-tags\",\"tags\":[{\"key\":\"owner\",\"value\":\"infra\"}]}")+ .when().post("/");+ resp.then().statusCode(200);+ String arn = resp.jsonPath().getString("activityArn");++ given()+ .header("X-Amz-Target", "AWSStepFunctions.ListTagsForResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + arn + "\"}")+ .post("/")+ .then()+ .statusCode(200)+ .body("tags", hasSize(1))+ .body("tags[0].key", equalTo("owner"))+ .body("tags[0].value", equalTo("infra"));++ given()+ .header("X-Amz-Target", "AWSStepFunctions.DeleteActivity")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"activityArn\":\"" + arn + "\"}")+ .post("/")+ .then().statusCode(200);+ }++ @Test+ @Order(8)+ void json_tagResource_tagsNotArray_returns400() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.TagResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + stateMachineArn + "\",\"tags\":\"not-an-array\"}")+ .post("/")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ValidationException"));+ }++ @Test+ @Order(9)+ void json_untagResource_tagKeysNotArray_returns400() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.UntagResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + stateMachineArn + "\",\"tagKeys\":\"not-an-array\"}")+ .post("/")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ValidationException"));+ }++ @Test+ @Order(10)+ void json_listTags_unknownArn_returns400() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.ListTagsForResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"arn:aws:states:us-east-1:000000000000:stateMachine:does-not-exist\"}")+ .post("/")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ResourceNotFound"));+ }++ @Test+ @Order(11)+ void json_tagResource_unknownArn_returns400() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.TagResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"arn:aws:states:us-east-1:000000000000:stateMachine:does-not-exist\",\"tags\":[{\"key\":\"k\",\"value\":\"v\"}]}")+ .post("/")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ResourceNotFound"));+ }++ @Test+ @Order(12)+ void json_untagResource_unknownArn_returns400() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.UntagResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"arn:aws:states:us-east-1:000000000000:stateMachine:does-not-exist\",\"tagKeys\":[\"k\"]}")+ .post("/")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ResourceNotFound"));+ }++ @Test+ @Order(13)+ void json_tagResource_activity_addsTag() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.TagResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + activityArn + "\",\"tags\":[{\"key\":\"env\",\"value\":\"test\"}]}")+ .post("/")+ .then()+ .statusCode(200);++ given()+ .header("X-Amz-Target", "AWSStepFunctions.ListTagsForResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + activityArn + "\"}")+ .post("/")+ .then()+ .statusCode(200)+ .body("tags", hasSize(1))+ .body("tags[0].key", equalTo("env"))+ .body("tags[0].value", equalTo("test"));+ }++ @Test+ @Order(14)+ void json_untagResource_activity_removesTag() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.UntagResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + activityArn + "\",\"tagKeys\":[\"env\"]}")+ .post("/")+ .then()+ .statusCode(200);++ given()+ .header("X-Amz-Target", "AWSStepFunctions.ListTagsForResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + activityArn + "\"}")+ .post("/")+ .then()+ .statusCode(200)+ .body("tags", hasSize(0));+ }++ @Test+ @Order(15)+ void json_tagResource_overwritesExistingKey() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.TagResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + stateMachineArn + "\",\"tags\":[{\"key\":\"env\",\"value\":\"updated\"}]}")+ .post("/")+ .then()+ .statusCode(200);++ given()+ .header("X-Amz-Target", "AWSStepFunctions.ListTagsForResource")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"resourceArn\":\"" + stateMachineArn + "\"}")+ .post("/")+ .then()+ .statusCode(200)+ .body("tags", hasSize(1))+ .body("tags[0].key", equalTo("env"))+ .body("tags[0].value", equalTo("updated"));+ }++ @Test+ @Order(16)+ void cleanup() {+ given()+ .header("X-Amz-Target", "AWSStepFunctions.DeleteStateMachine")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"stateMachineArn\":\"" + stateMachineArn + "\"}")+ .post("/")+ .then().statusCode(200);++ given()+ .header("X-Amz-Target", "AWSStepFunctions.DeleteActivity")+ .contentType(SFN_CONTENT_TYPE)+ .body("{\"activityArn\":\"" + activityArn + "\"}")+ .post("/")+ .then().statusCode(200);+ }+}