use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method cacheOnlyMiss.
@Test
public void cacheOnlyMiss() throws Exception {
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_ONLY)).test().assertError(ApolloHttpException.class);
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class IntegrationTest method operationJsonWriter.
@Test
public void operationJsonWriter() throws Exception {
String json = Utils.readFileToString(getClass(), "/OperationJsonWriter.json");
AllPlanetsQuery query = new AllPlanetsQuery();
Response<AllPlanetsQuery.Data> response = new OperationResponseParser<>(query, query.responseFieldMapper(), new ScalarTypeAdapters(Collections.EMPTY_MAP)).parse(new Buffer().writeUtf8(json));
Buffer buffer = new Buffer();
OperationJsonWriter writer = new OperationJsonWriter(response.data(), new ScalarTypeAdapters(Collections.EMPTY_MAP));
JsonWriter jsonWriter = JsonWriter.of(buffer);
jsonWriter.setIndent(" ");
writer.write(jsonWriter);
assertThat(buffer.readUtf8()).isEqualTo(json);
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class NormalizedCacheTestCase method cacheResponseWithNullableFields.
@Test
public void cacheResponseWithNullableFields() throws Exception {
enqueueAndAssertResponse(server, "AllPlanetsNullableField.json", apolloClient.query(new AllPlanetsQuery()).responseFetcher(NETWORK_ONLY), new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
assertThat(response).isNotNull();
assertThat(response.hasErrors()).isFalse();
return true;
}
});
assertResponse(apolloClient.query(new AllPlanetsQuery()).responseFetcher(CACHE_ONLY), new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
assertThat(response).isNotNull();
assertThat(response.hasErrors()).isFalse();
return true;
}
});
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method cacheStale.
@Test
@SuppressWarnings("CheckReturnValue")
public void cacheStale() 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())).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 cacheNonStale.
@Test
@SuppressWarnings("CheckReturnValue")
public void cacheNonStale() throws Exception {
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test();
assertThat(server.takeRequest()).isNotNull();
checkCachedResponse("/HttpCacheTestAllPlanets.json");
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_FIRST)).test();
assertThat(server.getRequestCount()).isEqualTo(1);
assertThat(lastHttResponse.networkResponse()).isNull();
assertThat(lastHttResponse.cacheResponse()).isNotNull();
}
Aggregations