@@ -61,47 +61,50 @@ static void tearDown() {
6161
6262 @ Test
6363 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 );
64+ try ( InputStream is = this .getClass ().getResourceAsStream ("/validation/valid_api_gw_in_out_event.json" )) {
65+ String validEvent = IOUtils .toString (is , StandardCharsets .UTF_8 );
6666
67- // WHEN
68- InvocationResult invocationResult = invokeFunction (functionName , validEvent );
67+ // WHEN
68+ InvocationResult invocationResult = invokeFunction (functionName , validEvent );
6969
70- // THEN
71- // invocation should pass validation and return 200
72- JsonNode validJsonNode = objectMapper .readTree (invocationResult .getResult ());
73- assertThat (validJsonNode .get ("statusCode" ).asInt ()).isEqualTo (200 );
74- assertThat (validJsonNode .get ("body" ).asText ()).isEqualTo ("{\" price\" : 150}" );
70+ // THEN
71+ // invocation should pass validation and return 200
72+ JsonNode validJsonNode = objectMapper .readTree (invocationResult .getResult ());
73+ assertThat (validJsonNode .get ("statusCode" ).asInt ()).isEqualTo (200 );
74+ assertThat (validJsonNode .get ("body" ).asText ()).isEqualTo ("{\" price\" : 150}" );
75+ }
7576 }
7677
7778 @ Test
7879 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 );
80+ try ( InputStream is = this .getClass ().getResourceAsStream ("/validation/invalid_api_gw_in_event.json" )) {
81+ String invalidEvent = IOUtils .toString (is , StandardCharsets .UTF_8 );
8182
82- // WHEN
83- InvocationResult invocationResult = invokeFunction (functionName , invalidEvent );
83+ // WHEN
84+ InvocationResult invocationResult = invokeFunction (functionName , invalidEvent );
8485
85- // THEN
86- // invocation should fail inbound validation and return 400
87- JsonNode validJsonNode = objectMapper .readTree (invocationResult .getResult ());
88- assertThat (validJsonNode .get ("statusCode" ).asInt ()).isEqualTo (400 );
89- assertThat (validJsonNode .get ("body" ).asText ()).contains (": required property 'price' not found" );
86+ // THEN
87+ // invocation should fail inbound validation and return 400
88+ JsonNode validJsonNode = objectMapper .readTree (invocationResult .getResult ());
89+ assertThat (validJsonNode .get ("statusCode" ).asInt ()).isEqualTo (400 );
90+ assertThat (validJsonNode .get ("body" ).asText ()).contains (": required property 'price' not found" );
91+ }
9092 }
9193
9294 @ Test
9395 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-
97- // WHEN
98- InvocationResult invocationResult = invokeFunction (functionName , invalidEvent );
99-
100- // THEN
101- // invocation should fail outbound validation and return 400
102- JsonNode validJsonNode = objectMapper .readTree (invocationResult .getResult ());
103- assertThat (validJsonNode .get ("statusCode" ).asInt ()).isEqualTo (400 );
104- assertThat (validJsonNode .get ("body" ).asText ())
105- .contains ("/price: must have an exclusive maximum value of 1000" );
96+ try (InputStream is = this .getClass ().getResourceAsStream ("/validation/invalid_api_gw_out_event.json" )) {
97+ String invalidEvent = IOUtils .toString (is , StandardCharsets .UTF_8 );
98+
99+ // WHEN
100+ InvocationResult invocationResult = invokeFunction (functionName , invalidEvent );
101+
102+ // THEN
103+ // invocation should fail outbound validation and return 400
104+ JsonNode validJsonNode = objectMapper .readTree (invocationResult .getResult ());
105+ assertThat (validJsonNode .get ("statusCode" ).asInt ()).isEqualTo (400 );
106+ assertThat (validJsonNode .get ("body" ).asText ())
107+ .contains ("/price: must have an exclusive maximum value of 1000" );
108+ }
106109 }
107110}
0 commit comments