### Question:
BufferedJestHttpClient extends JestHttpClient { protected HttpUriRequest prepareRequest(final BufferedBulk clientRequest) throws IOException { String requestURL = getRequestURL(getNextServer(), clientRequest.getURI()); HttpUriRequest httpUriRequest = new HttpPost(requestURL); ByteBuf byteBuf = clientRequest.serializeRequest(); ByteBufEntityBuilder entityBuilder = (ByteBufEntityBuilder) new ByteBufEntityBuilder() .setByteBuf(byteBuf) .setContentLength(byteBuf.writerIndex()) .setContentType(requestContentType); ((HttpEntityEnclosingRequest) httpUriRequest).setEntity(entityBuilder.build()); return httpUriRequest; }  @Override void executeAsync(Action<T> clientRequest, JestResultHandler<? super T> resultHandler);  }### Answer:
@Test public void prepareRequestCreatesPostRequest() throws IOException { Bulk bulk = createDefaultTestBufferedBulk(); BufferedJestHttpClient client = createDefaultTestHttpClient(); HttpUriRequest request = client.prepareRequest((BufferedBulk) bulk); Assert.assertEquals("POST", request.getRequestLine().getMethod()); }
@Test public void prepareRequestCreatesRequestUsingUriProvidedByAction() throws IOException { BufferedBulk bulk = createDefaultTestBufferedBulk(); String expectedUriPart = UUID.randomUUID().toString(); when(bulk.getURI()).thenReturn(expectedUriPart); BufferedJestHttpClient client = createDefaultTestHttpClient(); HttpUriRequest request = client.prepareRequest(bulk); assertTrue(request.getRequestLine().getUri().contains(expectedUriPart)); }
@Test public void prepareRequestCreatesRequestWithContentTypeHeader() throws IOException { Bulk bulk = createDefaultTestBufferedBulk(); BufferedJestHttpClient client = createDefaultTestHttpClient(); HttpUriRequest request = client.prepareRequest((BufferedBulk) bulk); HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); Assert.assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue()); }
@Test public void prepareRequestCreatesRequestWithSerializedBulk() throws IOException { ItemSource<ByteBuf> payload1 = createDefaultTestItemSource("test1"); ItemSource<ByteBuf> payload2 = createDefaultTestItemSource("test2"); BufferedBulk.Builder builder = spy(new BufferedBulk.Builder()); ByteBufItemSource buffer = new ByteBufItemSource(byteBufAllocator.buffer(32), source -> { }); builder.withBuffer(buffer); Bulk bulk = createTestBatch(builder, payload1, payload2); BufferedJestHttpClient client = createDefaultTestHttpClient(); HttpUriRequest request = client.prepareRequest((BufferedBulk) bulk); ByteBufInputStream byteBufInputStream = new ByteBufInputStream(buffer.getSource()); byte[] expectedBody = new byte[byteBufInputStream.available()]; byteBufInputStream.read(expectedBody); byteBufInputStream.reset(); HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); ByteBufInputStream content = (ByteBufInputStream) entity.getContent(); byte[] actualBody = new byte[content.available()]; content.read(actualBody); Assert.assertEquals(new String(expectedBody), new String(actualBody)); }