|
19 | 19 | import static software.amazon.lambda.powertools.testutils.lambda.LambdaInvoker.invokeFunction;
|
20 | 20 |
|
21 | 21 | import java.io.IOException;
|
| 22 | +import java.io.InputStream; |
| 23 | +import java.nio.charset.StandardCharsets; |
22 | 24 | import java.util.Map;
|
23 | 25 | import java.util.concurrent.TimeUnit;
|
24 | 26 |
|
| 27 | +import org.apache.commons.io.IOUtils; |
25 | 28 | import org.junit.jupiter.api.AfterAll;
|
26 | 29 | import org.junit.jupiter.api.BeforeAll;
|
| 30 | +import org.junit.jupiter.api.Test; |
27 | 31 | import org.junit.jupiter.api.Timeout;
|
28 |
| -import org.junit.jupiter.params.ParameterizedTest; |
29 | 32 |
|
30 |
| -import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; |
31 |
| -import com.amazonaws.services.lambda.runtime.tests.annotations.Event; |
32 | 33 | import com.fasterxml.jackson.databind.JsonNode;
|
33 | 34 | import com.fasterxml.jackson.databind.ObjectMapper;
|
34 | 35 |
|
@@ -58,42 +59,49 @@ public static void tearDown() {
|
58 | 59 | }
|
59 | 60 | }
|
60 | 61 |
|
61 |
| - @ParameterizedTest |
62 |
| - @Event(value = "/validation/valid_api_gw_in_out_event.json", type = APIGatewayProxyRequestEvent.class) |
63 |
| - void test_validInboundApiGWEvent(APIGatewayProxyRequestEvent validEvent) throws IOException { |
| 62 | + @Test |
| 63 | + void test_validInboundApiGWEvent() throws IOException { |
| 64 | + InputStream inputStream = this.getClass().getResourceAsStream("/validation/valid_api_gw_in_out_event.json"); |
| 65 | + String validEvent = IOUtils.toString(inputStream, StandardCharsets.UTF_8); |
| 66 | + |
64 | 67 | // WHEN
|
65 |
| - InvocationResult invocationResult = invokeFunction(functionName, objectMapper.writeValueAsString(validEvent)); |
| 68 | + InvocationResult invocationResult = invokeFunction(functionName, validEvent); |
66 | 69 |
|
67 | 70 | // THEN
|
68 | 71 | // invocation should pass validation and return 200
|
69 | 72 | JsonNode validJsonNode = objectMapper.readTree(invocationResult.getResult());
|
70 | 73 | assertThat(validJsonNode.get("statusCode").asInt()).isEqualTo(200);
|
71 | 74 | assertThat(validJsonNode.get("body").asText()).isEqualTo("{\"price\": 150}");
|
72 | 75 | }
|
73 |
| - |
74 |
| - @ParameterizedTest |
75 |
| - @Event(value = "/validation/invalid_api_gw_in_event.json", type = APIGatewayProxyRequestEvent.class) |
76 |
| - void test_invalidInboundApiGWEvent(APIGatewayProxyRequestEvent validEvent) throws IOException { |
| 76 | + |
| 77 | + @Test |
| 78 | + void test_invalidInboundApiGWEvent() throws IOException { |
| 79 | + InputStream inputStream = this.getClass().getResourceAsStream("/validation/invalid_api_gw_in_event.json"); |
| 80 | + String invalidEvent = IOUtils.toString(inputStream, StandardCharsets.UTF_8); |
| 81 | + |
77 | 82 | // WHEN
|
78 |
| - InvocationResult invocationResult = invokeFunction(functionName, objectMapper.writeValueAsString(validEvent)); |
| 83 | + InvocationResult invocationResult = invokeFunction(functionName, invalidEvent); |
79 | 84 |
|
80 | 85 | // THEN
|
81 | 86 | // invocation should fail inbound validation and return 400
|
82 | 87 | JsonNode validJsonNode = objectMapper.readTree(invocationResult.getResult());
|
83 | 88 | assertThat(validJsonNode.get("statusCode").asInt()).isEqualTo(400);
|
84 | 89 | assertThat(validJsonNode.get("body").asText()).contains("$.price: is missing but it is required");
|
85 | 90 | }
|
86 |
| - |
87 |
| - @ParameterizedTest |
88 |
| - @Event(value = "/validation/invalid_api_gw_out_event.json", type = APIGatewayProxyRequestEvent.class) |
89 |
| - void test_invalidOutboundApiGWEvent(APIGatewayProxyRequestEvent validEvent) throws IOException { |
| 91 | + |
| 92 | + @Test |
| 93 | + void test_invalidOutboundApiGWEvent() throws IOException { |
| 94 | + InputStream inputStream = this.getClass().getResourceAsStream("/validation/invalid_api_gw_out_event.json"); |
| 95 | + String invalidEvent = IOUtils.toString(inputStream, StandardCharsets.UTF_8); |
| 96 | + |
90 | 97 | // WHEN
|
91 |
| - InvocationResult invocationResult = invokeFunction(functionName, objectMapper.writeValueAsString(validEvent)); |
| 98 | + InvocationResult invocationResult = invokeFunction(functionName, invalidEvent); |
92 | 99 |
|
93 | 100 | // THEN
|
94 | 101 | // invocation should fail outbound validation and return 400
|
95 | 102 | JsonNode validJsonNode = objectMapper.readTree(invocationResult.getResult());
|
96 | 103 | assertThat(validJsonNode.get("statusCode").asInt()).isEqualTo(400);
|
97 |
| - assertThat(validJsonNode.get("body").asText()).contains("$.price: must have an exclusive maximum value of 1000"); |
| 104 | + assertThat(validJsonNode.get("body").asText()) |
| 105 | + .contains("$.price: must have an exclusive maximum value of 1000"); |
98 | 106 | }
|
99 | 107 | }
|
0 commit comments