GatewayRequestHandler extends SimpleRequestHandler<GatewayRequestAndLambdaContext, GatewayResponse> { @Override protected SimpleResponseWriter<GatewayResponse> createResponseWriter( GatewayRequestAndLambdaContext requestAndContext) { return new ResponseWriter(); } protected  GatewayRequestHandler();   }
@Test public void testResponseWriterFiltersInternalBinaryHeader() throws IOException { Map<String, List<String>> headers = new HashMap<>(); headers.put("a_k", Collections.singletonList("a_v")); headers.put(GatewayBinaryResponseFilter.HEADER_BINARY_RESPONSE, Collections.singletonList("true")); headers.put("b_k", Collections.singletonList("b_v")); SimpleResponseWriter<GatewayResponse> responseWriter = gatewayHandler.createResponseWriter(null); responseWriter.writeResponse(Status.OK, headers, new ByteArrayOutputStream()); assertEquals(ImmutableMap.of("a_k", "a_v", "b_k", "b_v"), responseWriter.getResponse().getHeaders()); }
@Test public void testResponseWriterSetsBase64EncodedFlagIfExactlyOneBinaryHeaderSetToTrue() throws IOException { Map<String, List<String>> headers = new HashMap<>(); headers.put(GatewayBinaryResponseFilter.HEADER_BINARY_RESPONSE, Collections.singletonList("true")); SimpleResponseWriter<GatewayResponse> responseWriter = gatewayHandler.createResponseWriter(null); responseWriter.writeResponse(Status.OK, headers, new ByteArrayOutputStream()); assertTrue(responseWriter.getResponse().isIsBase64Encoded()); }
@Test public void testResponseWriterDoesntSetBase64EncodedFlagIfMultipleBinaryHeadersSet() throws IOException { Map<String, List<String>> headers = new HashMap<>(); headers.put(GatewayBinaryResponseFilter.HEADER_BINARY_RESPONSE, ImmutableList.of("true", "true")); SimpleResponseWriter<GatewayResponse> responseWriter = gatewayHandler.createResponseWriter(null); responseWriter.writeResponse(Status.OK, headers, new ByteArrayOutputStream()); assertFalse(responseWriter.getResponse().isIsBase64Encoded()); }
@Test public void testResponseWriterDoesntSetBase64EncodedFlagIfNoBinaryHeadersSet() throws IOException { Map<String, List<String>> headers = new HashMap<>(); SimpleResponseWriter<GatewayResponse> responseWriter = gatewayHandler.createResponseWriter(null); responseWriter.writeResponse(Status.OK, headers, new ByteArrayOutputStream()); assertFalse(responseWriter.getResponse().isIsBase64Encoded()); }
@Test public void testResponseWriterDoesntSetBase64EncodedFlagIfBinaryHeaderSetToFalse() throws IOException { Map<String, List<String>> headers = new HashMap<>(); headers.put(GatewayBinaryResponseFilter.HEADER_BINARY_RESPONSE, Collections.singletonList("false")); SimpleResponseWriter<GatewayResponse> responseWriter = gatewayHandler.createResponseWriter(null); responseWriter.writeResponse(Status.OK, headers, new ByteArrayOutputStream()); assertFalse(responseWriter.getResponse().isIsBase64Encoded()); }