use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method cacheStaleBeforeNetworkError.
@Test
@SuppressWarnings("CheckReturnValue")
public void cacheStaleBeforeNetworkError() throws Exception {
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test();
assertThat(server.getRequestCount()).isEqualTo(1);
server.enqueue(new MockResponse().setResponseCode(504).setBody(""));
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.NETWORK_FIRST)).test();
assertThat(server.getRequestCount()).isEqualTo(2);
assertThat(lastHttResponse.networkResponse()).isNotNull();
assertThat(lastHttResponse.cacheResponse()).isNotNull();
checkCachedResponse("/HttpCacheTestAllPlanets.json");
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method cacheUpdate.
@Test
@SuppressWarnings("CheckReturnValue")
public void cacheUpdate() throws Exception {
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test();
assertThat(server.getRequestCount()).isEqualTo(1);
checkCachedResponse("/HttpCacheTestAllPlanets.json");
enqueueResponse("/HttpCacheTestAllPlanets2.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test();
assertThat(server.getRequestCount()).isEqualTo(2);
checkCachedResponse("/HttpCacheTestAllPlanets2.json");
assertThat(lastHttResponse.networkResponse()).isNotNull();
assertThat(lastHttResponse.cacheResponse()).isNull();
enqueueResponse("/HttpCacheTestAllPlanets2.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_FIRST)).test();
assertThat(server.getRequestCount()).isEqualTo(2);
assertThat(lastHttResponse.networkResponse()).isNull();
assertThat(lastHttResponse.cacheResponse()).isNotNull();
checkCachedResponse("/HttpCacheTestAllPlanets2.json");
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method networkFirst.
@Test
public void networkFirst() throws Exception {
enqueueResponse("/HttpCacheTestAllPlanets.json");
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();
}
});
assertThat(server.getRequestCount()).isEqualTo(1);
assertThat(lastHttResponse.networkResponse()).isNotNull();
assertThat(lastHttResponse.cacheResponse()).isNull();
checkCachedResponse("/HttpCacheTestAllPlanets.json");
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.NETWORK_FIRST)).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
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 networkOnly_responseWithGraphError_noCached.
@Test
public void networkOnly_responseWithGraphError_noCached() throws Exception {
enqueueResponse("/ResponseError.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();
checkNoCachedResponse();
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method cacheNetworkError.
@Test
public void cacheNetworkError() throws IOException, ApolloException {
server.enqueue(new MockResponse().setResponseCode(504).setBody(""));
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test().assertError(Exception.class);
checkNoCachedResponse();
enqueueResponse("/HttpCacheTestAllPlanets.json");
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();
}
});
checkCachedResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_ONLY)).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
}
Aggregations