Java Code Examples for okhttp3.mockwebserver.MockResponse#setChunkedBody()

The following examples show how to use okhttp3.mockwebserver.MockResponse#setChunkedBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractMockServerTest.java    From influxdb-client-java with MIT License 6 votes vote down vote up
@Nonnull
protected MockResponse createErrorResponse(@Nullable final String influxError,
                                           final boolean chunked,
                                           final int responseCode) {

    String body = String.format("{\"error\":\"%s\"}", influxError);

    MockResponse mockResponse = new MockResponse()
            .setResponseCode(responseCode)
            .addHeader("X-Influx-Error", influxError);

    if (chunked) {
        return mockResponse.setChunkedBody(body, body.length());
    }

    return mockResponse.setBody(body);
}
 
Example 2
Source File: InfluxDBInterpeterTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Nonnull
protected MockResponse createResponse(final String data, final String
    contentType, final boolean chunked) {

  MockResponse response = new MockResponse()
      .setHeader("Content-Type", contentType + "; charset=utf-8")
      .setHeader("Date", "Tue, 26 Jun 2018 13:15:01 GMT");

  if (chunked) {
    response.setChunkedBody(data, data.length());
  } else {
    response.setBody(data);
  }

  return response;
}
 
Example 3
Source File: AbstractMockServerTest.java    From influxdb-client-java with MIT License 5 votes vote down vote up
@Nonnull
protected MockResponse createResponse(final String data, final String contentType, final boolean chunked) {

    MockResponse response = new MockResponse()
            .setHeader("Content-Type", contentType + "; charset=utf-8")
            .setHeader("Date", "Tue, 26 Jun 2018 13:15:01 GMT");

    if (chunked) {
        response.setChunkedBody(data, data.length());
    } else {
        response.setBody(data);
    }

    return response;
}
 
Example 4
Source File: ChunkedResponse.java    From mockwebserver with Apache License 2.0 5 votes vote down vote up
public MockResponse toMockResponse(RecordedRequest request) {
    MockResponse mockResponse = new MockResponse();
    mockResponse.setHeaders(bodyProvider.getHeaders());
    mockResponse.setChunkedBody(concatBody(request), DEFAULT_MAX_CHUNK_SIZE);
    mockResponse.setResponseCode(bodyProvider.getStatusCode(request));

    if (responseDelay > 0) {
        mockResponse.setBodyDelay(responseDelay, responseDelayUnit);
    }

    return mockResponse;
}
 
Example 5
Source File: Benchmark.java    From jus with Apache License 2.0 5 votes vote down vote up
private MockResponse newResponse(States.GenericState state) throws IOException {
  byte[] bytes = new byte[state.bodyByteCount];
  state.random.nextBytes(bytes);
  Buffer body = new Buffer().write(bytes);

  MockResponse result = new MockResponse();

  if (state.gzip) {
    Buffer gzipBody = new Buffer();
    GzipSink gzipSink = new GzipSink(gzipBody);
    gzipSink.write(body, body.size());
    gzipSink.close();
    body = gzipBody;
    result.addHeader("Content-Encoding: gzip");
  }

  if (state.chunked) {
    result.setChunkedBody(body, 1024);
  } else {
    result.setBody(body);
  }

  for (int i = 0; i < state.headerCount; i++) {
    result.addHeader(randomString(12, state), randomString(20, state));
  }

  return result;
}