ServiceRequestHandler extends SimpleRequestHandler<ServiceRequestAndLambdaContext, ServiceResponse> { @Override protected JRestlessContainerRequest createContainerRequest(ServiceRequestAndLambdaContext requestAndLambdaContext) { requireNonNull(requestAndLambdaContext); ServiceRequest request = requireNonNull(requestAndLambdaContext.getServiceRequest()); String body = request.getBody(); InputStream entityStream; if (body != null) { entityStream = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)); } else { entityStream = new ByteArrayInputStream(new byte[0]); } RequestAndBaseUri requestAndBaseUri = getRequestAndBaseUri(requestAndLambdaContext); return new DefaultJRestlessContainerRequest(requestAndBaseUri, request.getHttpMethod(), entityStream, request.getHeaders()); } protected  ServiceRequestHandler();   }
@Test public void createContainerRequest_NoBodyGiven_ShouldUseEmptyBaos() { ServiceRequestAndLambdaContext request = createMinimalRequest(); JRestlessContainerRequest containerRequest = serviceHandler.createContainerRequest(request); InputStream is = containerRequest.getEntityStream(); assertEquals(ByteArrayInputStream.class, is.getClass()); assertArrayEquals(new byte[0], toBytes((ByteArrayInputStream) is)); }
@Test public void createContainerRequest_BodyGiven_ShouldUseBody() { ServiceRequestAndLambdaContext request = createMinimalRequest(); ((DefaultServiceRequest) request.getServiceRequest()).setBody("abc"); JRestlessContainerRequest containerRequest = serviceHandler.createContainerRequest(request); InputStream is = containerRequest.getEntityStream(); assertEquals(ByteArrayInputStream.class, is.getClass()); assertArrayEquals("abc".getBytes(), toBytes((ByteArrayInputStream) is)); }
@Test public void createContainerRequest_HttpMethodGiven_ShouldUseHttpMethod() { ServiceRequestAndLambdaContext request = createMinimalRequest(); ((DefaultServiceRequest) request.getServiceRequest()).setHttpMethod("X"); JRestlessContainerRequest containerRequest = serviceHandler.createContainerRequest(request); assertEquals("X", containerRequest.getHttpMethod()); }
@Test public void createContainerRequest_PathGiven_ShouldUsePath() { ServiceRequestAndLambdaContext request = createMinimalRequest(); ((DefaultServiceRequest) request.getServiceRequest()).setRequestUri(URI.create("/a?b=c&d=e")); JRestlessContainerRequest containerRequest = serviceHandler.createContainerRequest(request); assertEquals(URI.create("/a?b=c&d=e"), containerRequest.getRequestUri()); }
@Test public void createContainerRequest_HeadersGiven_ShouldUseHeaders() { ServiceRequestAndLambdaContext request = createMinimalRequest(); Map<String, List<String>> headers = ImmutableMap.of("0", emptyList(), "1", singletonList("a"), "2", ImmutableList.of("b", "c")); ((DefaultServiceRequest) request.getServiceRequest()).setHeaders(headers); JRestlessContainerRequest containerRequest = serviceHandler.createContainerRequest(request); assertEquals(headers, containerRequest.getHeaders()); }