FnRequestHandler extends
	SimpleRequestHandler<FnRequestHandler.WrappedInput, FnRequestHandler.WrappedOutput> { @Override public JRestlessContainerRequest createContainerRequest(WrappedInput wrappedInput) { InputEvent inputEvent = wrappedInput.inputEvent; InputStream entityStream = wrappedInput.stream; requireNonNull(inputEvent); return new DefaultJRestlessContainerRequest( getRequestAndBaseUri(inputEvent), inputEvent.getMethod(), entityStream, this.expandHeaders(inputEvent.getHeaders().getAll())); }  @Override JRestlessContainerRequest createContainerRequest(WrappedInput wrappedInput); RequestAndBaseUri getRequestAndBaseUri(InputEvent inputEvent); @FnConfiguration void setRuntimeContext(RuntimeContext rctx); final OutputEvent handleRequest(InputEvent inputEvent);  }
@Test public void createContainerRequest_testHttpMethodAndHeaders() { Headers headers = Headers.fromMap(ImmutableMap.of("key_one", "value_one", "key_two", "value_two")); InputEvent inputEvent = new DefaultInputEvent() .setHeaders(headers) .getInputEvent(); FnRequestHandler.WrappedInput wrappedInput = new FnRequestHandler.WrappedInput(inputEvent, defaultBody); JRestlessContainerRequest containerRequest = requestHandler.createContainerRequest(wrappedInput); assertEquals("GET", containerRequest.getHttpMethod()); assertEquals(ImmutableMap.of("key-one", singletonList("value_one"), "key-two", singletonList("value_two")), containerRequest.getHeaders()); }
@Test public void createContainerRequest_NullHeaderValueGiven_ShouldFilterHeader() { Map<String, String> headers = new HashMap<>(); headers.put("key-one", null); headers.put("key-two", "value_two"); InputEvent inputEvent = new DefaultInputEvent() .setHeaders(headers) .getInputEvent(); FnRequestHandler.WrappedInput wrappedInput = new FnRequestHandler.WrappedInput(inputEvent, defaultBody); JRestlessContainerRequest containerRequest = requestHandler.createContainerRequest(wrappedInput); assertEquals(ImmutableMap.of("key-two", singletonList("value_two")), containerRequest.getHeaders()); }
@Test public void createContainerRequest_BodyGiven_ShouldUseBody() { String content = "42"; ByteArrayInputStream body = new ByteArrayInputStream(content.getBytes()); InputEvent inputEvent = new DefaultInputEvent() .setBody(body) .getInputEvent(); FnRequestHandler.WrappedInput wrappedInput = new FnRequestHandler.WrappedInput(inputEvent, body); JRestlessContainerRequest containerRequest = requestHandler.createContainerRequest(wrappedInput); assertEquals(ByteArrayInputStream.class, (containerRequest.getEntityStream()).getClass()); assertEquals(content, toString((ByteArrayInputStream) (containerRequest.getEntityStream()))); }
@Test public void createContainerRequest_NoBodyGiven_ShouldUseEmptyBais() { InputEvent inputEvent = new DefaultInputEvent() .getInputEvent(); FnRequestHandler.WrappedInput wrappedInput = new FnRequestHandler.WrappedInput(inputEvent, defaultBody); JRestlessContainerRequest containerRequest = requestHandler.createContainerRequest(wrappedInput); assertEquals(ByteArrayInputStream.class, (containerRequest.getEntityStream()).getClass()); assertEquals("", toString((ByteArrayInputStream) (containerRequest.getEntityStream()))); }