use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project SpaceLaunchNow-Android by ItsCalebJones.
the class RetrofitBuilder method defaultClient.
private static OkHttpClient defaultClient() {
OkHttpClient.Builder client = new OkHttpClient().newBuilder();
client.connectTimeout(15, TimeUnit.SECONDS);
client.readTimeout(15, TimeUnit.SECONDS);
client.writeTimeout(15, TimeUnit.SECONDS);
return client.build();
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project SpaceLaunchNow-Android by ItsCalebJones.
the class YouTubeAPIHelper method defaultClient.
private static OkHttpClient defaultClient(Context context) {
File httpCacheDirectory = new File(context.getCacheDir(), "responses-youtube");
// 1 MiB
int cacheSize = 1024 * 1024;
Cache cache = new Cache(httpCacheDirectory, cacheSize);
OkHttpClient.Builder client = new OkHttpClient().newBuilder();
client.cache(cache);
client.addNetworkInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR);
client.connectTimeout(15, TimeUnit.SECONDS);
client.readTimeout(15, TimeUnit.SECONDS);
client.writeTimeout(15, TimeUnit.SECONDS);
return client.build();
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project spring-framework-debug by Joker-5.
the class InvalidHttpMethodIntegrationTests method invalidHttpMethod.
@ParameterizedHttpServerTest
void invalidHttpMethod(HttpServer httpServer) throws Exception {
startServer(httpServer);
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().method("BAZ", null).url("http://localhost:" + port + "/").build();
try (Response response = client.newCall(request).execute()) {
assertThat(response.body().string()).isEqualTo("BAR");
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project media by androidx.
the class OkHttpDataSourceTest method open_setsCorrectHeaders.
/**
* This test will set HTTP default request parameters (1) in the OkHttpDataSource, (2) via
* OkHttpDataSource.setRequestProperty() and (3) in the DataSpec instance according to the table
* below. Values wrapped in '*' are the ones that should be set in the connection request.
*
* <pre>{@code
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* | | Header Key |
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* | Location | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* | Constructor | *Y* | Y | Y | | Y | | |
* | Setter | | *Y* | Y | Y | | *Y* | |
* | DataSpec | | | *Y* | *Y* | *Y* | | *Y* |
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* }</pre>
*/
@Test
public void open_setsCorrectHeaders() throws Exception {
MockWebServer mockWebServer = new MockWebServer();
mockWebServer.enqueue(new MockResponse());
String propertyFromFactory = "fromFactory";
Map<String, String> defaultRequestProperties = new HashMap<>();
defaultRequestProperties.put("0", propertyFromFactory);
defaultRequestProperties.put("1", propertyFromFactory);
defaultRequestProperties.put("2", propertyFromFactory);
defaultRequestProperties.put("4", propertyFromFactory);
HttpDataSource dataSource = new OkHttpDataSource.Factory(new OkHttpClient()).setDefaultRequestProperties(defaultRequestProperties).createDataSource();
String propertyFromSetter = "fromSetter";
dataSource.setRequestProperty("1", propertyFromSetter);
dataSource.setRequestProperty("2", propertyFromSetter);
dataSource.setRequestProperty("3", propertyFromSetter);
dataSource.setRequestProperty("5", propertyFromSetter);
String propertyFromDataSpec = "fromDataSpec";
Map<String, String> dataSpecRequestProperties = new HashMap<>();
dataSpecRequestProperties.put("2", propertyFromDataSpec);
dataSpecRequestProperties.put("3", propertyFromDataSpec);
dataSpecRequestProperties.put("4", propertyFromDataSpec);
dataSpecRequestProperties.put("6", propertyFromDataSpec);
DataSpec dataSpec = new DataSpec.Builder().setUri(mockWebServer.url("/test-path").toString()).setHttpRequestHeaders(dataSpecRequestProperties).build();
dataSource.open(dataSpec);
Headers headers = mockWebServer.takeRequest(10, SECONDS).getHeaders();
assertThat(headers.get("0")).isEqualTo(propertyFromFactory);
assertThat(headers.get("1")).isEqualTo(propertyFromSetter);
assertThat(headers.get("2")).isEqualTo(propertyFromDataSpec);
assertThat(headers.get("3")).isEqualTo(propertyFromDataSpec);
assertThat(headers.get("4")).isEqualTo(propertyFromDataSpec);
assertThat(headers.get("5")).isEqualTo(propertyFromSetter);
assertThat(headers.get("6")).isEqualTo(propertyFromDataSpec);
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project media by androidx.
the class OkHttpDataSourceTest method open_invalidResponseCode.
@Test
public void open_invalidResponseCode() {
MockWebServer mockWebServer = new MockWebServer();
mockWebServer.enqueue(new MockResponse().setResponseCode(404).setBody("failure msg"));
HttpDataSource okHttpDataSource = new OkHttpDataSource.Factory(new OkHttpClient()).createDataSource();
DataSpec dataSpec = new DataSpec.Builder().setUri(mockWebServer.url("/test-path").toString()).build();
HttpDataSource.InvalidResponseCodeException exception = assertThrows(HttpDataSource.InvalidResponseCodeException.class, () -> okHttpDataSource.open(dataSpec));
assertThat(exception.responseCode).isEqualTo(404);
assertThat(exception.responseBody).isEqualTo("failure msg".getBytes(Charsets.UTF_8));
}
Aggregations