use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project media by androidx.
the class WebServerDispatcherTest method rangeRequestsUnsupported_conventionalRequestWorksAsExpected.
@Test
public void rangeRequestsUnsupported_conventionalRequestWorksAsExpected() throws Exception {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(mockWebServer.url(RANGE_UNSUPPORTED_PATH)).build();
try (Response response = client.newCall(request).execute()) {
assertThat(response.code()).isEqualTo(200);
assertThat(response.header("Accept-Ranges")).isNull();
assertThat(response.header("Content-Length")).isEqualTo("20");
assertThat(response.header("Content-Range")).isNull();
assertThat(response.body().bytes()).isEqualTo(RANGE_UNSUPPORTED_DATA);
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project media by androidx.
the class WebServerDispatcherTest method rangeRequestsSupported_rejectsRangeWithEndBeforeStart.
@Test
public void rangeRequestsSupported_rejectsRangeWithEndBeforeStart() throws Exception {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(mockWebServer.url(RANGE_SUPPORTED_PATH)).addHeader("Range", "bytes=15-10").build();
try (Response response = client.newCall(request).execute()) {
assertThat(response.code()).isEqualTo(416);
assertThat(response.header("Accept-Ranges")).isEqualTo("bytes");
assertThat(response.header("Content-Range")).isEqualTo("bytes */20");
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project media by androidx.
the class WebServerDispatcherTest method gzipDisabled_acceptEncodingHeaderRequiresGzip_406Response.
@Test
public void gzipDisabled_acceptEncodingHeaderRequiresGzip_406Response() throws Exception {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(mockWebServer.url(RANGE_SUPPORTED_PATH)).addHeader("Accept-Encoding", "gzip;q=1.0").addHeader("Accept-Encoding", "identity;q=0").build();
try (Response response = client.newCall(request).execute()) {
assertThat(response.code()).isEqualTo(406);
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project media by androidx.
the class WebServerDispatcherTest method gzipEnabled_acceptEncodingHeaderAllowsGzip_responseGzipped.
@Test
public void gzipEnabled_acceptEncodingHeaderAllowsGzip_responseGzipped() throws Exception {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(mockWebServer.url(GZIP_ENABLED_PATH)).addHeader("Accept-Encoding", "gzip").build();
try (Response response = client.newCall(request).execute()) {
byte[] expectedData = Util.gzip(GZIP_ENABLED_DATA);
assertThat(response.code()).isEqualTo(200);
assertThat(response.header("Content-Encoding")).isEqualTo("gzip");
assertThat(response.header("Content-Length")).isEqualTo(String.valueOf(expectedData.length));
assertThat(response.body().bytes()).isEqualTo(expectedData);
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project media by androidx.
the class WebServerDispatcherTest method gzipForced_acceptEncodingHeaderAllowsGzip_responseGzipped.
@Test
public void gzipForced_acceptEncodingHeaderAllowsGzip_responseGzipped() throws Exception {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(mockWebServer.url(GZIP_FORCED_PATH)).addHeader("Accept-Encoding", "gzip").build();
try (Response response = client.newCall(request).execute()) {
byte[] expectedData = Util.gzip(GZIP_FORCED_DATA);
assertThat(response.code()).isEqualTo(200);
assertThat(response.header("Content-Encoding")).isEqualTo("gzip");
assertThat(response.header("Content-Length")).isEqualTo(String.valueOf(expectedData.length));
assertThat(response.body().bytes()).isEqualTo(expectedData);
}
}
Aggregations