events = archivedEventStore
.get(archivedEventKey(region, archiveName))
@@ -2512,18 +2508,15 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
public Replay describeReplay(String replayName, String region) {
return replayStore.get(replayKey(region, replayName))
- .orElseThrow(() -> new AwsException("ResourceNotFoundException",
- "Replay not found: " + replayName, 400));
+ .orElseThrow(() -> EventBridgeErrors.replayNotFound(replayName));
}
public Replay cancelReplay(String replayName, String region) {
String key = replayKey(region, replayName);
Replay replay = replayStore.get(key)
- .orElseThrow(() -> new AwsException("ResourceNotFoundException",
- "Replay not found: " + replayName, 400));
+ .orElseThrow(() -> EventBridgeErrors.replayNotFound(replayName));
if (replay.getState() != ReplayState.RUNNING && replay.getState() != ReplayState.STARTING) {
- throw new AwsException("IllegalStatusException",
- "Replay is not in a cancellable state: " + replay.getState(), 400);
+ throw EventBridgeErrors.replayNotCancellable(replayName);
}
boolean signalled = replayDispatcher.requestCancel(replay.getReplayArn());
if (!signalled) {
diff --git a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationEventBusIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationEventBusIntegrationTest.java
index c379a03406..3950c445a1 100644
--- a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationEventBusIntegrationTest.java
+++ b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationEventBusIntegrationTest.java
@@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* Previously the type had no provisioner case, so it fell through to the generic stub: the resource
* reported CREATE_COMPLETE with a physical id but the bus was never registered with the EventBridge
* service. Any {@code AWS::Events::Rule} referencing it via {@code {"Ref": bus}} then failed
- * "EventBus not found", rolling the whole stack back. Per the AWS spec {@code Ref} returns the bus
+ * "Event bus ... does not exist.", rolling the whole stack back. Per the AWS spec {@code Ref} returns the bus
* name and {@code Fn::GetAtt "Arn"} the ARN.
*
*
All resources are metadata-only (no container), so the test is Docker-free.
@@ -266,7 +266,7 @@ class CloudFormationEventBusIntegrationTest {
String busName = "domain-events-" + suffix;
String stackName = "eventbus-stack-" + suffix;
- // The stub-only behaviour failed the Rule with "EventBus not found" -> ROLLBACK.
+ // The stub-only behaviour failed the Rule with "Event bus ... does not exist." -> ROLLBACK.
createStack(stackName, eventBusAndRuleTemplate(busName));
assertStackStatus(stackName, "CREATE_COMPLETE");
@@ -401,7 +401,7 @@ class CloudFormationEventBusIntegrationTest {
throw new AssertionError("collision failure was not preserved: " + resources);
}
String events = describeStackEvents(stackB);
- if (!events.contains("EventBus already exists: " + busName)) {
+ if (!events.contains("Event bus " + busName + " already exists.")) {
throw new AssertionError("collision reason was not preserved: " + events);
}
diff --git a/src/test/java/io/floci/aws/services/cloudformation/provisioners/EventsArchiveCfnProvisionerTest.java b/src/test/java/io/floci/aws/services/cloudformation/provisioners/EventsArchiveCfnProvisionerTest.java
index 7344d3b2d8..4a6b87e7de 100644
--- a/src/test/java/io/floci/aws/services/cloudformation/provisioners/EventsArchiveCfnProvisionerTest.java
+++ b/src/test/java/io/floci/aws/services/cloudformation/provisioners/EventsArchiveCfnProvisionerTest.java
@@ -89,7 +89,7 @@ class EventsArchiveCfnProvisionerTest {
when(events.describeArchive(anyString(), eq(REGION))).thenAnswer(i -> {
Archive archive = archives.get(i.getArgument(0));
if (archive == null) {
- throw new AwsException("ResourceNotFoundException", "Archive not found: " + i.getArgument(0), 400);
+ throw new AwsException("ResourceNotFoundException", "Archive " + i.getArgument(0) + " does not exist.", 400);
}
return archive;
});
diff --git a/src/test/java/io/floci/aws/services/eventbridge/EventBridgeErrorMessagesIntegrationTest.java b/src/test/java/io/floci/aws/services/eventbridge/EventBridgeErrorMessagesIntegrationTest.java
new file mode 100644
index 0000000000..cacfd50a34
--- /dev/null
+++ b/src/test/java/io/floci/aws/services/eventbridge/EventBridgeErrorMessagesIntegrationTest.java
@@ -0,0 +1,175 @@
+package io.floci.aws.services.eventbridge;
+
+import io.floci.aws.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.ValidatableResponse;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+
+/** Exact code, message and status of the not-found, already-exists and invalid-state refusals. */
+@QuarkusTest
+class EventBridgeErrorMessagesIntegrationTest {
+
+ private static final String BUS_ARN = "arn:aws:events:us-east-1:000000000000:event-bus/";
+
+ @BeforeAll
+ static void configure() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static ValidatableResponse call(String op, String body) {
+ return RestAssuredJsonUtils.awsAction("AWSEvents", op, body).then();
+ }
+
+ private static void ok(String op, String body) {
+ call(op, body).statusCode(200);
+ }
+
+ private static void refused(String op, String body, String type, String message) {
+ call(op, body).statusCode(400).body("__type", equalTo(type)).body("message", equalTo(message));
+ }
+
+ private static void createBus(String name) {
+ ok("CreateEventBus", "{\"Name\":\"" + name + "\"}");
+ }
+
+ private static void createArchive(String name, String bus) {
+ ok("CreateArchive", "{\"ArchiveName\":\"" + name + "\",\"EventSourceArn\":\"" + BUS_ARN + bus + "\"}");
+ }
+
+ @Test
+ void notFoundIsWordedPerResourceKind() {
+ String nf = "ResourceNotFoundException";
+ createBus("emsg-bus");
+
+ refused("DescribeEventBus", "{\"Name\":\"emsg-nobus\"}", nf, "Event bus emsg-nobus does not exist.");
+ refused("DescribeRule", "{\"Name\":\"emsg-norule\"}", nf,
+ "Rule emsg-norule does not exist on EventBus default.");
+ refused("DescribeRule", "{\"Name\":\"emsg-norule\",\"EventBusName\":\"emsg-bus\"}", nf,
+ "Rule emsg-norule does not exist on EventBus emsg-bus.");
+ refused("EnableRule", "{\"Name\":\"emsg-norule\"}", nf,
+ "Rule emsg-norule does not exist on EventBus default.");
+ refused("PutTargets", "{\"Rule\":\"emsg-norule\",\"Targets\":[{\"Id\":\"1\","
+ + "\"Arn\":\"arn:aws:sqs:us-east-1:000000000000:q\"}]}", nf,
+ "Rule emsg-norule does not exist on EventBus default.");
+ refused("DescribeArchive", "{\"ArchiveName\":\"emsg-noarch\"}", nf,
+ "Archive emsg-noarch does not exist.");
+ refused("DescribeReplay", "{\"ReplayName\":\"emsg-noreplay\"}", nf,
+ "Replay emsg-noreplay does not exist.");
+ refused("DescribeConnection", "{\"Name\":\"emsg-noconn\"}", nf,
+ "Failed to describe the connection(s). Connection 'emsg-noconn' does not exist.");
+ refused("DescribeApiDestination", "{\"Name\":\"emsg-nodest\"}", nf,
+ "Failed to describe the api-destination(s). An api-destination 'emsg-nodest' does not exist.");
+ String ghost = "arn:aws:events:us-east-1:000000000000:connection/emsg-ghost/"
+ + "00000000-0000-0000-0000-000000000000";
+ refused("CreateApiDestination", "{\"Name\":\"emsg-d\",\"ConnectionArn\":\"" + ghost + "\","
+ + "\"InvocationEndpoint\":\"https://example.com\",\"HttpMethod\":\"POST\"}", nf,
+ "Failed to create the api-destination(s). Connection '" + ghost + "' does not exist.");
+ refused("TagResource", "{\"ResourceARN\":\"" + BUS_ARN + "emsg-nobus\",\"Tags\":[]}", nf,
+ "Event bus emsg-nobus does not exist.");
+ }
+
+ @Test
+ void deletedResourcesReadBackAsNotFound() {
+ createBus("emsg-del-bus");
+ ok("DeleteEventBus", "{\"Name\":\"emsg-del-bus\"}");
+ refused("DescribeEventBus", "{\"Name\":\"emsg-del-bus\"}", "ResourceNotFoundException",
+ "Event bus emsg-del-bus does not exist.");
+
+ createArchive("emsg-del-arch", "default");
+ ok("DeleteArchive", "{\"ArchiveName\":\"emsg-del-arch\"}");
+ refused("DescribeArchive", "{\"ArchiveName\":\"emsg-del-arch\"}", "ResourceNotFoundException",
+ "Archive emsg-del-arch does not exist.");
+
+ ok("PutRule", "{\"Name\":\"emsg-del-rule\",\"EventPattern\":\"{\\\"source\\\":[\\\"x\\\"]}\"}");
+ ok("DeleteRule", "{\"Name\":\"emsg-del-rule\"}");
+ refused("DescribeRule", "{\"Name\":\"emsg-del-rule\"}", "ResourceNotFoundException",
+ "Rule emsg-del-rule does not exist on EventBus default.");
+ }
+
+ @Test
+ void duplicateCreatesAreAlreadyExists() {
+ String ae = "ResourceAlreadyExistsException";
+ createBus("emsg-dup-bus");
+ refused("CreateEventBus", "{\"Name\":\"emsg-dup-bus\"}", ae, "Event bus emsg-dup-bus already exists.");
+
+ createArchive("emsg-dup-arch", "default");
+ refused("CreateArchive", "{\"ArchiveName\":\"emsg-dup-arch\",\"EventSourceArn\":\"" + BUS_ARN
+ + "default\"}", ae, "Archive emsg-dup-arch already exists.");
+
+ String conn = "{\"Name\":\"emsg-dup-conn\",\"AuthorizationType\":\"API_KEY\",\"AuthParameters\":"
+ + "{\"ApiKeyAuthParameters\":{\"ApiKeyName\":\"k\",\"ApiKeyValue\":\"v\"}}}";
+ ok("CreateConnection", conn);
+ refused("CreateConnection", conn, ae,
+ "Connection emsg-dup-conn already exists.");
+
+ String replay = "{\"ReplayName\":\"emsg-dup-replay\",\"EventSourceArn\":\"arn:aws:events:us-east-1:"
+ + "000000000000:archive/emsg-dup-arch\",\"EventStartTime\":1700000000,\"EventEndTime\":1700000100,"
+ + "\"Destination\":{\"Arn\":\"" + BUS_ARN + "default\"}}";
+ ok("StartReplay", replay);
+ refused("StartReplay", replay, ae, "Replay emsg-dup-replay already exists.");
+ }
+
+ @Test
+ void invalidStateAndPreconditionRefusals() {
+ refused("DeleteEventBus", "{\"Name\":\"default\"}", "ValidationException",
+ "Cannot delete event bus default.");
+
+ createBus("emsg-rules-bus");
+ ok("PutRule", "{\"Name\":\"r1\",\"EventBusName\":\"emsg-rules-bus\","
+ + "\"EventPattern\":\"{\\\"source\\\":[\\\"x\\\"]}\"}");
+ refused("DeleteEventBus", "{\"Name\":\"emsg-rules-bus\"}", "ValidationException",
+ "EventBus can't be deleted since it has rules.");
+
+ ok("PutTargets", "{\"Rule\":\"r1\",\"EventBusName\":\"emsg-rules-bus\",\"Targets\":[{\"Id\":\"1\","
+ + "\"Arn\":\"arn:aws:sqs:us-east-1:000000000000:q\"}]}");
+ refused("DeleteRule", "{\"Name\":\"r1\",\"EventBusName\":\"emsg-rules-bus\"}", "ValidationException",
+ "Rule can't be deleted since it has targets.");
+
+ refused("StartReplay", "{\"ReplayName\":\"emsg-bad-src\",\"EventSourceArn\":\"arn:aws:events:us-east-1:"
+ + "000000000000:archive/emsg-gone\",\"EventStartTime\":1700000000,\"EventEndTime\":1700000100,"
+ + "\"Destination\":{\"Arn\":\"" + BUS_ARN + "default\"}}", "ValidationException",
+ "Parameter EventSourceArn is not valid. Reason: Archive emsg-gone does not exist.");
+ }
+
+ @Test
+ void connectionAndApiDestinationWritesOnMissingResourcesNameTheCall() {
+ String nf = "ResourceNotFoundException";
+ refused("UpdateConnection", "{\"Name\":\"emsg-w-conn\",\"Description\":\"d\"}", nf,
+ "Failed to update the connection(s). Connection 'emsg-w-conn' does not exist.");
+ refused("DeleteConnection", "{\"Name\":\"emsg-w-conn\"}", nf,
+ "Connection emsg-w-conn does not exist.");
+ refused("UpdateApiDestination", "{\"Name\":\"emsg-w-dest\",\"Description\":\"d\"}", nf,
+ "Failed to update the api-destination(s). An api-destination 'emsg-w-dest' does not exist.");
+ refused("DeleteApiDestination", "{\"Name\":\"emsg-w-dest\"}", nf,
+ "ApiDestination emsg-w-dest does not exist.");
+ }
+
+ @Test
+ void untagOnMissingRuleArnNamesRuleAndBus() {
+ refused("UntagResource", "{\"ResourceARN\":\"arn:aws:events:us-east-1:000000000000:rule/emsg-untag\","
+ + "\"TagKeys\":[\"k\"]}", "ResourceNotFoundException",
+ "Rule emsg-untag does not exist on EventBus default.");
+ }
+
+ @Test
+ void tagCallsOnMissingResourcesUseThePerKindWording() {
+ String nf = "ResourceNotFoundException";
+ String events = "arn:aws:events:us-east-1:000000000000:";
+ refused("ListTagsForResource", "{\"ResourceARN\":\"" + events + "archive/emsg-tag-arch\"}", nf,
+ "Resource not found: " + events + "archive/emsg-tag-arch");
+ refused("TagResource", "{\"ResourceARN\":\"" + events + "rule/emsg-tag-bus/emsg-tag-rule\","
+ + "\"Tags\":[]}", nf, "Rule emsg-tag-rule does not exist on EventBus emsg-tag-bus.");
+ refused("UntagResource", "{\"ResourceARN\":\"" + events + "event-bus/emsg-tag-bus\","
+ + "\"TagKeys\":[\"k\"]}", nf, "Event bus emsg-tag-bus does not exist.");
+ }
+
+ @Test
+ void listRuleNamesByTargetOnMissingBusUsesTheBusWording() {
+ refused("ListRuleNamesByTarget", "{\"TargetArn\":\"arn:aws:sqs:us-east-1:000000000000:q\","
+ + "\"EventBusName\":\"emsg-lrnbt-bus\"}", "ResourceNotFoundException",
+ "Event bus emsg-lrnbt-bus does not exist.");
+ }
+}
diff --git a/src/test/java/io/floci/aws/services/eventbridge/EventBridgeReplayIntegrationTest.java b/src/test/java/io/floci/aws/services/eventbridge/EventBridgeReplayIntegrationTest.java
index 412942962c..50eea00db7 100644
--- a/src/test/java/io/floci/aws/services/eventbridge/EventBridgeReplayIntegrationTest.java
+++ b/src/test/java/io/floci/aws/services/eventbridge/EventBridgeReplayIntegrationTest.java
@@ -265,6 +265,19 @@ class EventBridgeReplayIntegrationTest {
@Test
@Order(11)
+ void completedReplayCannotBeCancelled() {
+ given()
+ .contentType(EB_CT)
+ .header("X-Amz-Target", "AWSEvents.CancelReplay")
+ .body("{\"ReplayName\":\"test-replay-1\"}")
+ .when().post("/")
+ .then().statusCode(400)
+ .body("__type", equalTo("IllegalStatusException"))
+ .body("message", equalTo("Replay test-replay-1 is not in a valid state for this operation."));
+ }
+
+ @Test
+ @Order(12)
void updateArchive() {
given()
.contentType(EB_CT)
@@ -291,7 +304,7 @@ class EventBridgeReplayIntegrationTest {
}
@Test
- @Order(12)
+ @Order(13)
void deleteArchive() {
given()
.contentType(EB_CT)
@@ -310,7 +323,7 @@ class EventBridgeReplayIntegrationTest {
}
@Test
- @Order(13)
+ @Order(14)
void missingReplayUsesAwsResourceNotFoundStatus() {
given()
.contentType(EB_CT)
@@ -322,7 +335,7 @@ class EventBridgeReplayIntegrationTest {
}
@Test
- @Order(14)
+ @Order(15)
void updateArchiveKeepsTheFieldsTheRequestOmits() {
createPartialUpdateArchive("partial-keep-archive");
@@ -338,7 +351,7 @@ class EventBridgeReplayIntegrationTest {
}
@Test
- @Order(15)
+ @Order(16)
void updateArchiveClearsTheDescriptionAndPatternGivenAsEmptyStrings() {
createPartialUpdateArchive("partial-clear-archive");
@@ -354,7 +367,7 @@ class EventBridgeReplayIntegrationTest {
}
@Test
- @Order(16)
+ @Order(17)
void updateArchiveSetsAnExplicitZeroRetention() {
createPartialUpdateArchive("partial-zero-archive");
diff --git a/src/test/java/io/floci/aws/services/eventbridge/EventBridgeServiceTest.java b/src/test/java/io/floci/aws/services/eventbridge/EventBridgeServiceTest.java
index c8396fba8f..b392d78877 100644
--- a/src/test/java/io/floci/aws/services/eventbridge/EventBridgeServiceTest.java
+++ b/src/test/java/io/floci/aws/services/eventbridge/EventBridgeServiceTest.java
@@ -2497,4 +2497,11 @@ class EventBridgeServiceTest {
assertEquals(0, ((ArrayNode) EventBridgeService.serviceEventEntry("s", "d", "{}", null).get("Resources")).size());
assertEquals(0, ((ArrayNode) EventBridgeService.serviceEventEntry("s", "d", "{}", " ").get("Resources")).size());
}
+
+ @Test
+ void findConnectionByArnKeepsThePlainMessageForInternalCallers() {
+ String arn = "arn:aws:events:us-east-1:000000000000:connection/nope/abc";
+ AwsException e = assertThrows(AwsException.class, () -> service.findConnectionByArn(arn, "us-east-1"));
+ assertEquals("Connection " + arn + " does not exist.", e.getMessage());
+ }
}