mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(eventbridge): move library usages to imports (#3898)
* refactor(eventbridge): move library usages to imports * refactor(eventbridge): complete qualification cleanups in EventBridgeInvokerTest
This commit is contained in:
1 parent
3a36b8c85c
commit
45bfcc464e
5 files changed
+53
-38
No files matched your search
+13
-9
@@ -1,18 +1,22 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
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 org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
/**
|
||||
* Integration tests for EventBridge ARN-based EventBusName support.
|
||||
@@ -236,8 +240,8 @@ class EventBridgeArnIntegrationTest {
|
||||
* classes share one emulator, and a non-commercial ARN left behind fails the cross-service
|
||||
* scan in ResourceExplorer2IntegrationTest.
|
||||
*/
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.CsvSource({
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"us-east-1, arn:aws:events:",
|
||||
"us-gov-west-1, arn:aws-us-gov:events:",
|
||||
"cn-north-1, arn:aws-cn:events:"})
|
||||
@@ -256,7 +260,7 @@ class EventBridgeArnIntegrationTest {
|
||||
.then().statusCode(200)
|
||||
.extract().jsonPath().getString("EventBusArn");
|
||||
|
||||
org.hamcrest.MatcherAssert.assertThat(busArn, org.hamcrest.Matchers.startsWith(expectedArnPrefix));
|
||||
MatcherAssert.assertThat(busArn, Matchers.startsWith(expectedArnPrefix));
|
||||
|
||||
try {
|
||||
given()
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -162,7 +163,7 @@ class EventBridgeBatchIntegrationTest {
|
||||
.extract().path("jobDefinitionArn");
|
||||
}
|
||||
|
||||
private static io.restassured.specification.RequestSpecification givenBatchJson(String body) {
|
||||
private static RequestSpecification givenBatchJson(String body) {
|
||||
return given()
|
||||
.header("Authorization", BATCH_AUTH)
|
||||
.contentType("application/json")
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -198,7 +199,7 @@ class EventBridgeEcsRunTaskIntegrationTest {
|
||||
.extract().path("taskDefinition.taskDefinitionArn");
|
||||
}
|
||||
|
||||
private static io.restassured.specification.RequestSpecification ecs(String action) {
|
||||
private static RequestSpecification ecs(String action) {
|
||||
return given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", ECS_TARGET_PREFIX + action);
|
||||
|
||||
+24
-18
@@ -1,10 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.batch.BatchService;
|
||||
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
|
||||
import io.github.hectorvent.floci.services.ecs.EcsService;
|
||||
import io.github.hectorvent.floci.services.ecs.container.HostVolumePolicy;
|
||||
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.model.AwsVpcConfiguration;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.BatchParameters;
|
||||
@@ -15,17 +19,18 @@ import io.github.hectorvent.floci.services.eventbridge.model.Target;
|
||||
import io.github.hectorvent.floci.services.firehose.FirehoseService;
|
||||
import io.github.hectorvent.floci.services.firehose.model.Record;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaService;
|
||||
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
|
||||
import io.github.hectorvent.floci.services.sns.SnsService;
|
||||
import io.github.hectorvent.floci.services.sqs.SqsService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.AdditionalMatchers.aryEq;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
@@ -55,9 +60,9 @@ class EventBridgeInvokerTest {
|
||||
when(regionResolver.getAccountId()).thenReturn("000000000000");
|
||||
when(eventBridgeService.putEvents(anyList(), anyString(), any()))
|
||||
.thenReturn(new EventBridgeService.PutEventsResult(0, List.of()));
|
||||
io.github.hectorvent.floci.config.EmulatorConfig emulatorConfig =
|
||||
mock(io.github.hectorvent.floci.config.EmulatorConfig.class,
|
||||
org.mockito.Mockito.RETURNS_DEEP_STUBS);
|
||||
EmulatorConfig emulatorConfig =
|
||||
mock(EmulatorConfig.class,
|
||||
Mockito.RETURNS_DEEP_STUBS);
|
||||
invoker = new EventBridgeInvoker(
|
||||
lambdaService,
|
||||
sqsService,
|
||||
@@ -66,8 +71,8 @@ class EventBridgeInvokerTest {
|
||||
firehoseService,
|
||||
eventBridgeService,
|
||||
ecsService,
|
||||
new io.github.hectorvent.floci.services.ecs.EcsJsonHandler(ecsService, new ObjectMapper(),
|
||||
new io.github.hectorvent.floci.services.ecs.container.HostVolumePolicy(emulatorConfig)),
|
||||
new EcsJsonHandler(ecsService, new ObjectMapper(),
|
||||
new HostVolumePolicy(emulatorConfig)),
|
||||
regionResolver,
|
||||
new ObjectMapper(),
|
||||
emulatorConfig
|
||||
@@ -84,7 +89,7 @@ class EventBridgeInvokerTest {
|
||||
verify(lambdaService).invokeArn(
|
||||
eq(arn),
|
||||
aryEq("{\"detail\":{\"job\":\"workflow-recovery\"}}".getBytes()),
|
||||
eq(io.github.hectorvent.floci.services.lambda.model.InvocationType.Event));
|
||||
eq(InvocationType.Event));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,6 +195,7 @@ class EventBridgeInvokerTest {
|
||||
|
||||
invoker.invokeTarget(target, "{\"detail\":{}}", "us-east-1");
|
||||
|
||||
// Clash with eventbridge.model.NetworkConfiguration
|
||||
ArgumentCaptor<io.github.hectorvent.floci.services.ecs.model.NetworkConfiguration> networkCaptor =
|
||||
ArgumentCaptor.forClass(io.github.hectorvent.floci.services.ecs.model.NetworkConfiguration.class);
|
||||
verify(ecsService).runTask(
|
||||
@@ -248,7 +254,7 @@ class EventBridgeInvokerTest {
|
||||
invoker.invokeTarget(target, "{\"detail\":{\"orderId\":\"o-42\"}}", "us-east-1");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<List<io.github.hectorvent.floci.services.ecs.model.ContainerOverride>> overridesCaptor =
|
||||
ArgumentCaptor<List<ContainerOverride>> overridesCaptor =
|
||||
ArgumentCaptor.forClass(List.class);
|
||||
verify(ecsService).runTask(
|
||||
eq("arn:aws:ecs:us-west-2:000000000000:cluster/my-cluster"),
|
||||
@@ -261,7 +267,7 @@ class EventBridgeInvokerTest {
|
||||
isNull(),
|
||||
eq("us-west-2")
|
||||
);
|
||||
io.github.hectorvent.floci.services.ecs.model.ContainerOverride override = overridesCaptor.getValue().get(0);
|
||||
ContainerOverride override = overridesCaptor.getValue().get(0);
|
||||
assertEquals("app", override.getName());
|
||||
assertEquals(List.of("process", "o-42"), override.getCommand());
|
||||
assertEquals("ORDER_ID", override.getEnvironment().get(0).name());
|
||||
@@ -412,7 +418,7 @@ class EventBridgeInvokerTest {
|
||||
void applyInputTransformer_valuePosition_stringIsQuoted() {
|
||||
String event = "{\"detail\":{\"eventName\":\"site.created\"}}";
|
||||
InputTransformer t = new InputTransformer(
|
||||
java.util.Map.of("e", "$.detail.eventName"), "{\"e\":<e>}");
|
||||
Map.of("e", "$.detail.eventName"), "{\"e\":<e>}");
|
||||
assertEquals("{\"e\":\"site.created\"}", invoker.applyInputTransformer(t, event));
|
||||
}
|
||||
|
||||
@@ -420,7 +426,7 @@ class EventBridgeInvokerTest {
|
||||
void applyInputTransformer_valuePosition_objectNumberBoolAsIs() {
|
||||
String event = "{\"detail\":{\"count\":42,\"ok\":true,\"payload\":{\"id\":\"abc\"}}}";
|
||||
InputTransformer t = new InputTransformer(
|
||||
java.util.Map.of("c", "$.detail.count", "o", "$.detail.ok", "p", "$.detail.payload"),
|
||||
Map.of("c", "$.detail.count", "o", "$.detail.ok", "p", "$.detail.payload"),
|
||||
"{\"c\":<c>,\"o\":<o>,\"p\":<p>}");
|
||||
assertEquals("{\"c\":42,\"o\":true,\"p\":{\"id\":\"abc\"}}", invoker.applyInputTransformer(t, event));
|
||||
}
|
||||
@@ -429,7 +435,7 @@ class EventBridgeInvokerTest {
|
||||
void applyInputTransformer_valuePosition_missingIsEmpty() {
|
||||
String event = "{\"detail\":{}}";
|
||||
InputTransformer t = new InputTransformer(
|
||||
java.util.Map.of("e", "$.detail.nope"), "prefix:<e>:suffix");
|
||||
Map.of("e", "$.detail.nope"), "prefix:<e>:suffix");
|
||||
assertEquals("prefix::suffix", invoker.applyInputTransformer(t, event));
|
||||
}
|
||||
|
||||
@@ -437,7 +443,7 @@ class EventBridgeInvokerTest {
|
||||
void applyInputTransformer_insideString_interpolatesRaw() {
|
||||
String event = "{\"detail\":{\"user\":\"alice\",\"eventName\":\"site.created\"}}";
|
||||
InputTransformer t = new InputTransformer(
|
||||
java.util.Map.of("user", "$.detail.user", "e", "$.detail.eventName"),
|
||||
Map.of("user", "$.detail.user", "e", "$.detail.eventName"),
|
||||
"\"<user> did <e>\"");
|
||||
assertEquals("\"alice did site.created\"", invoker.applyInputTransformer(t, event));
|
||||
}
|
||||
@@ -446,14 +452,14 @@ class EventBridgeInvokerTest {
|
||||
void applyInputTransformer_quotedWholeToken_rawBetweenQuotes() {
|
||||
String event = "{\"detail\":{\"eventName\":\"site.created\"}}";
|
||||
InputTransformer t = new InputTransformer(
|
||||
java.util.Map.of("e", "$.detail.eventName"), "{\"e\":\"<e>\"}");
|
||||
Map.of("e", "$.detail.eventName"), "{\"e\":\"<e>\"}");
|
||||
assertEquals("{\"e\":\"site.created\"}", invoker.applyInputTransformer(t, event));
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyInputTransformer_unknownVarLeftLiteral() {
|
||||
String event = "{\"detail\":{}}";
|
||||
InputTransformer t = new InputTransformer(java.util.Map.of(), "{\"x\":<unknown>}");
|
||||
InputTransformer t = new InputTransformer(Map.of(), "{\"x\":<unknown>}");
|
||||
assertEquals("{\"x\":<unknown>}", invoker.applyInputTransformer(t, event));
|
||||
}
|
||||
|
||||
@@ -562,7 +568,7 @@ class EventBridgeInvokerTest {
|
||||
sqsService,
|
||||
mock(SnsService.class),
|
||||
new ObjectMapper(),
|
||||
mock(io.github.hectorvent.floci.config.EmulatorConfig.class));
|
||||
mock(EmulatorConfig.class));
|
||||
Target target = new Target("id1",
|
||||
"arn:aws:events:eu-west-1:000000000000:event-bus/my-target-bus",
|
||||
null, null);
|
||||
|
||||
+12
-9
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
@@ -17,6 +18,8 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -741,9 +744,9 @@ class EventBridgeServiceTest {
|
||||
EventBridgeService.PutEventsResult result = service.putEvents(entries, "eu-west-1");
|
||||
assertEquals(0, result.failedCount());
|
||||
|
||||
org.mockito.ArgumentCaptor<String> json = org.mockito.ArgumentCaptor.forClass(String.class);
|
||||
ArgumentCaptor<String> json = ArgumentCaptor.forClass(String.class);
|
||||
verify(invokerMock).invokeTarget(eq(target), json.capture(), eq("eu-west-1"));
|
||||
com.fasterxml.jackson.databind.JsonNode envelope = OBJECT_MAPPER.readTree(json.getValue());
|
||||
JsonNode envelope = OBJECT_MAPPER.readTree(json.getValue());
|
||||
assertEquals("eu-west-1", envelope.path("region").asText(),
|
||||
"envelope.region should reflect the PutEvents call's region, not the resolver default");
|
||||
assertEquals("000000000000", envelope.path("account").asText());
|
||||
@@ -769,9 +772,9 @@ class EventBridgeServiceTest {
|
||||
|
||||
service.putEvents(List.of(entry), "us-west-2");
|
||||
|
||||
org.mockito.ArgumentCaptor<String> json = org.mockito.ArgumentCaptor.forClass(String.class);
|
||||
ArgumentCaptor<String> json = ArgumentCaptor.forClass(String.class);
|
||||
verify(invokerMock).invokeTarget(eq(target), json.capture(), eq("us-west-2"));
|
||||
com.fasterxml.jackson.databind.JsonNode envelope = OBJECT_MAPPER.readTree(json.getValue());
|
||||
JsonNode envelope = OBJECT_MAPPER.readTree(json.getValue());
|
||||
assertEquals("ap-northeast-1", envelope.path("region").asText(),
|
||||
"entry.Region should win over the PutEvents call region");
|
||||
assertEquals("111111111111", envelope.path("account").asText(),
|
||||
@@ -796,9 +799,9 @@ class EventBridgeServiceTest {
|
||||
service.putEvents(List.of(
|
||||
Map.of("Source", "my.app", "DetailType", "Test", "Detail", "{}")), "eu-west-1");
|
||||
|
||||
org.mockito.ArgumentCaptor<String> json = org.mockito.ArgumentCaptor.forClass(String.class);
|
||||
ArgumentCaptor<String> json = ArgumentCaptor.forClass(String.class);
|
||||
verify(invokerMock).invokeTarget(eq(target), json.capture(), eq("eu-west-1"));
|
||||
com.fasterxml.jackson.databind.JsonNode envelope = OBJECT_MAPPER.readTree(json.getValue());
|
||||
JsonNode envelope = OBJECT_MAPPER.readTree(json.getValue());
|
||||
assertEquals("eu-west-1", envelope.path("region").asText(),
|
||||
"envelope and pattern matching must agree on the entry's effective region");
|
||||
}
|
||||
@@ -821,7 +824,7 @@ class EventBridgeServiceTest {
|
||||
service.putEvents(List.of(
|
||||
Map.of("Source", "my.app", "DetailType", "Test", "Detail", "{}")), "eu-west-1");
|
||||
|
||||
verify(invokerMock, org.mockito.Mockito.never()).invokeTarget(eq(target), any(), any());
|
||||
verify(invokerMock, Mockito.never()).invokeTarget(eq(target), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -839,9 +842,9 @@ class EventBridgeServiceTest {
|
||||
service.putEvents(List.of(
|
||||
Map.of("Source", "my.app", "DetailType", "Test", "Detail", "{}")), REGION);
|
||||
|
||||
org.mockito.ArgumentCaptor<String> json = org.mockito.ArgumentCaptor.forClass(String.class);
|
||||
ArgumentCaptor<String> json = ArgumentCaptor.forClass(String.class);
|
||||
verify(invokerMock).invokeTarget(eq(target), json.capture(), eq(REGION));
|
||||
com.fasterxml.jackson.databind.JsonNode envelope = OBJECT_MAPPER.readTree(json.getValue());
|
||||
JsonNode envelope = OBJECT_MAPPER.readTree(json.getValue());
|
||||
assertEquals(REGION, envelope.path("region").asText());
|
||||
assertEquals("000000000000", envelope.path("account").asText());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user