Skip to content

Commit

Permalink
Fix tests assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
olegz committed Jun 29, 2023
1 parent 5da5e4b commit 7aec220
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import jakarta.ws.rs.core.HttpHeaders;

@SuppressWarnings("rawtypes")
public class SpringDelegatingLambdaContainerHandlerTests {

private static String API_GATEWAY_EVENT = "{\n"
Expand Down Expand Up @@ -208,7 +209,9 @@ public void testAsyncPost(String jsonEvent) throws Exception {
InputStream targetStream = new ByteArrayInputStream(this.generateHttpRequest(jsonEvent, "POST", "/async", "{\"name\":\"bob\"}", null));
ByteArrayOutputStream output = new ByteArrayOutputStream();
handler.handleRequest(targetStream, output, null);
System.out.println(output.toString(StandardCharsets.UTF_8));
Map result = mapper.readValue(output.toString(StandardCharsets.UTF_8), Map.class);
assertEquals(200, result.get("statusCode"));
assertEquals("{\"name\":\"BOB\"}", result.get("body"));
}

@MethodSource("data")
Expand All @@ -219,7 +222,9 @@ public void testValidate400(String jsonEvent) throws Exception {
InputStream targetStream = new ByteArrayInputStream(this.generateHttpRequest(jsonEvent, "POST", "/validate", mapper.writeValueAsString(ud), null));
ByteArrayOutputStream output = new ByteArrayOutputStream();
handler.handleRequest(targetStream, output, null);
System.out.println(output.toString(StandardCharsets.UTF_8));
Map result = mapper.readValue(output.toString(StandardCharsets.UTF_8), Map.class);
assertEquals(400, result.get("statusCode"));
assertEquals("3", result.get("body"));
}

@MethodSource("data")
Expand All @@ -233,7 +238,9 @@ public void testValidate200(String jsonEvent) throws Exception {
InputStream targetStream = new ByteArrayInputStream(this.generateHttpRequest(jsonEvent, "POST", "/validate", mapper.writeValueAsString(ud), null));
ByteArrayOutputStream output = new ByteArrayOutputStream();
handler.handleRequest(targetStream, output, null);
System.out.println(output.toString(StandardCharsets.UTF_8));
Map result = mapper.readValue(output.toString(StandardCharsets.UTF_8), Map.class);
assertEquals(200, result.get("statusCode"));
assertEquals("VALID", result.get("body"));
}

@MethodSource("data")
Expand All @@ -244,10 +251,12 @@ public void messageObject_parsesObject_returnsCorrectMessage(String jsonEvent) t
mapper.writeValueAsString(new MessageData("test message")), null));
ByteArrayOutputStream output = new ByteArrayOutputStream();
handler.handleRequest(targetStream, output, null);
System.out.println(output.toString(StandardCharsets.UTF_8));
Map result = mapper.readValue(output.toString(StandardCharsets.UTF_8), Map.class);
assertEquals(200, result.get("statusCode"));
assertEquals("VALID", result.get("test message"));
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"unchecked" })
@MethodSource("data")
@ParameterizedTest
void messageObject_propertiesInContentType_returnsCorrectMessage(String jsonEvent) throws Exception {
Expand All @@ -265,7 +274,6 @@ void messageObject_propertiesInContentType_returnsCorrectMessage(String jsonEven
assertEquals("test message", result.get("body"));
}

@SuppressWarnings({ "rawtypes" })
private byte[] generateHttpRequest(String jsonEvent, String method, String path, String body, Map headers) throws Exception {
Map requestMap = mapper.readValue(jsonEvent, Map.class);
if (requestMap.get("version").equals("2.0")) {
Expand All @@ -274,7 +282,7 @@ private byte[] generateHttpRequest(String jsonEvent, String method, String path,
return generateHttpRequest(requestMap, method, path, body, headers);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({ "unchecked"})
private byte[] generateHttpRequest(Map requestMap, String method, String path, String body, Map headers) throws Exception {
requestMap.put("path", path);
requestMap.put("httpMethod", method);
Expand All @@ -285,7 +293,7 @@ private byte[] generateHttpRequest(Map requestMap, String method, String path, S
return mapper.writeValueAsBytes(requestMap);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({ "unchecked"})
private byte[] generateHttpRequest2(Map requestMap, String method, String path, String body, Map headers) throws Exception {
Map map = mapper.readValue(API_GATEWAY_EVENT_V2, Map.class);
Map http = (Map) ((Map) map.get("requestContext")).get("http");
Expand Down

0 comments on commit 7aec220

Please sign in to comment.