use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class ApolloPrefetchTest method prefetchDefault.
@Test
public void prefetchDefault() throws IOException, ApolloException {
server.enqueue(mockResponse("HttpCacheTestAllPlanets.json"));
prefetch(apolloClient.prefetch(new AllPlanetsQuery()));
checkCachedResponse("HttpCacheTestAllPlanets.json");
assertResponse(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_ONLY.expireAfter(2, TimeUnit.SECONDS)), new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> dataResponse) throws Exception {
return !dataResponse.hasErrors();
}
});
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method noCacheStore.
@Test
public void noCacheStore() throws Exception {
enqueueResponse("/HttpCacheTestAllPlanets.json");
ApolloClient apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(new OkHttpClient.Builder().addInterceptor(new TrackingInterceptor()).dispatcher(new Dispatcher(Utils.immediateExecutorService())).build()).dispatcher(Utils.immediateExecutor()).build();
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
checkNoCachedResponse();
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method cacheStaleBeforeNetwork.
@Test
@SuppressWarnings("CheckReturnValue")
public void cacheStaleBeforeNetwork() throws Exception {
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test();
assertThat(server.getRequestCount()).isEqualTo(1);
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.NETWORK_FIRST)).test();
assertThat(server.getRequestCount()).isEqualTo(2);
assertThat(lastHttResponse.networkResponse()).isNotNull();
assertThat(lastHttResponse.cacheResponse()).isNull();
checkCachedResponse("/HttpCacheTestAllPlanets.json");
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method prematureDisconnect.
@Test
public void prematureDisconnect() throws Exception {
MockResponse mockResponse = mockResponse("/HttpCacheTestAllPlanets.json");
Buffer truncatedBody = new Buffer();
truncatedBody.write(mockResponse.getBody(), 16);
mockResponse.setBody(truncatedBody);
server.enqueue(mockResponse);
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.NETWORK_ONLY)).test().assertError(ApolloException.class);
checkNoCachedResponse();
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method networkOnly.
@Test
public void networkOnly() throws Exception {
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.NETWORK_ONLY)).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
assertThat(server.getRequestCount()).isEqualTo(1);
assertThat(lastHttResponse.networkResponse()).isNotNull();
assertThat(lastHttResponse.cacheResponse()).isNull();
checkCachedResponse("/HttpCacheTestAllPlanets.json");
}
Aggregations