Skip to content

Commit

Permalink
test: Added tests for more complex content types mentioned in issue #315
Browse files Browse the repository at this point in the history
  • Loading branch information
sapessi committed Apr 7, 2020
1 parent 50166c3 commit 2255820
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public AwsProxyRequestBuilder nullBody() {
}

public AwsProxyRequestBuilder body(Object body) {
if (request.getMultiValueHeaders() != null && request.getMultiValueHeaders().getFirst(HttpHeaders.CONTENT_TYPE).equals(MediaType.APPLICATION_JSON)) {
if (request.getMultiValueHeaders() != null && request.getMultiValueHeaders().getFirst(HttpHeaders.CONTENT_TYPE).startsWith(MediaType.APPLICATION_JSON)) {
try {
return body(LambdaContainerHandler.getObjectMapper().writeValueAsString(body));
} catch (JsonProcessingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public void messageObject_parsesObject_returnsCorrectMessage() {
assertEquals("test message", resp.getBody());
}

@Test
public void messageObject_propertiesInContentType_returnsCorrectMessage() {
AwsProxyRequestBuilder req = new AwsProxyRequestBuilder("/message", "POST")
.header(HttpHeaders.CONTENT_TYPE, "application/json;v=1")
.header(HttpHeaders.ACCEPT, "application/json;v=1")
.body(new MessageData("test message"));
AwsProxyResponse resp = handler.handleRequest(req, lambdaContext);
assertNotNull(resp);
assertEquals(200, resp.getStatusCode());
assertEquals("test message", resp.getBody());
}

@Test
public void echoMessage_fileNameLikeParameter_returnsMessage() {
AwsProxyRequestBuilder req = new AwsProxyRequestBuilder("/echo/test.test.test", "GET");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ResponseEntity<String> validateBody(@RequestBody @Valid UserData userData
return ResponseEntity.ok(VALID_MESSAGE);
}

@RequestMapping(path="/message", method = RequestMethod.POST, produces={"text/plain"}, consumes = {"application/json"})
@RequestMapping(path="/message", method = RequestMethod.POST)
public String returnMessage(@RequestBody MessageData data) {
if (data == null) {
throw new RuntimeException("No message data");
Expand Down

0 comments on commit 2255820

Please sign in to comment.