Skip to content

Commit 6cf2398

Browse files
committed
Additional unit tests on Jersey to validate that it honors the produces annotations (#250)
1 parent c6f96b4 commit 6cf2398

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

aws-serverless-java-container-jersey/src/test/java/com/amazonaws/serverless/proxy/jersey/EchoJerseyResource.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.io.IOException;
4242
import java.io.InputStream;
4343
import java.util.Enumeration;
44+
import java.util.HashMap;
4445
import java.util.List;
4546
import java.util.Random;
4647

@@ -272,4 +273,11 @@ public Response fileSize(@FormDataParam("file") final File uploadedFile,
272273
return Response.status(500).build();
273274
}
274275
}
276+
277+
@Path("/plain") @GET
278+
@Produces(MediaType.TEXT_PLAIN)
279+
@Consumes(MediaType.APPLICATION_JSON)
280+
public Response plain() {
281+
return Response.status(200).entity("Hello!").build();
282+
}
275283
}

aws-serverless-java-container-jersey/src/test/java/com/amazonaws/serverless/proxy/jersey/JerseyAwsProxyTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,20 @@ public void refererHeader_headerParam_expectCorrectInjection() {
363363
validateSingleValueModel(resp, refererValue);
364364
}
365365

366+
@Test
367+
public void textPlainContent_plain_responseHonorsContentType() {
368+
AwsProxyRequest req = getRequestBuilder("/echo/plain", "GET")
369+
.nullBody()
370+
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
371+
.header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN)
372+
.build();
373+
374+
AwsProxyResponse resp = handler.proxy(req, lambdaContext);
375+
assertEquals(200, resp.getStatusCode());
376+
assertTrue(resp.getMultiValueHeaders().containsKey(HttpHeaders.CONTENT_TYPE));
377+
assertEquals(MediaType.TEXT_PLAIN, resp.getMultiValueHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
378+
}
379+
366380
private void validateMapResponseModel(AwsProxyResponse output) {
367381
validateMapResponseModel(output, CUSTOM_HEADER_KEY, CUSTOM_HEADER_VALUE);
368382
}

0 commit comments

Comments
 (0)