use of com.apollographql.apollo.api.Response 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.api.Response in project apollo-android by apollographql.
the class ApolloWatcherTest method testQueryWatcherNotCalled_WhenCanceled.
@Test
public void testQueryWatcherNotCalled_WhenCanceled() throws Exception {
final List<String> heroNameList = new ArrayList<>();
EpisodeHeroNameQuery query = EpisodeHeroNameQuery.builder().episode(Episode.EMPIRE).build();
server.enqueue(mockResponse("EpisodeHeroNameResponseWithId.json"));
ApolloQueryWatcher<EpisodeHeroNameQuery.Data> watcher = apolloClient.query(query).watcher();
watcher.enqueueAndWatch(new ApolloCall.Callback<EpisodeHeroNameQuery.Data>() {
@Override
public void onResponse(@Nonnull Response<EpisodeHeroNameQuery.Data> response) {
heroNameList.add(response.data().hero().name());
}
@Override
public void onFailure(@Nonnull ApolloException e) {
Assert.fail(e.getMessage());
}
});
watcher.cancel();
enqueueAndAssertResponse(server, "EpisodeHeroNameResponseNameChange.json", apolloClient.query(query).responseFetcher(NETWORK_ONLY), new Predicate<Response<EpisodeHeroNameQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
assertThat(heroNameList.get(0)).isEqualTo("R2-D2");
assertThat(heroNameList.size()).isEqualTo(1);
}
use of com.apollographql.apollo.api.Response in project apollo-android by apollographql.
the class ApolloWatcherTest method testQueryWatcherUpdated_DifferentQuery_DifferentResults.
@Test
public void testQueryWatcherUpdated_DifferentQuery_DifferentResults() throws Exception {
final List<String> heroNameList = new ArrayList<>();
server.enqueue(mockResponse("EpisodeHeroNameResponseWithId.json"));
EpisodeHeroNameQuery query = EpisodeHeroNameQuery.builder().episode(Episode.EMPIRE).build();
ApolloQueryWatcher<EpisodeHeroNameQuery.Data> watcher = apolloClient.query(query).watcher();
watcher.enqueueAndWatch(new ApolloCall.Callback<EpisodeHeroNameQuery.Data>() {
@Override
public void onResponse(@Nonnull Response<EpisodeHeroNameQuery.Data> response) {
heroNameList.add(response.data().hero().name());
}
@Override
public void onFailure(@Nonnull ApolloException e) {
Assert.fail(e.getMessage());
}
});
HeroAndFriendsNamesWithIDsQuery friendsQuery = HeroAndFriendsNamesWithIDsQuery.builder().episode(Episode.NEWHOPE).build();
enqueueAndAssertResponse(server, "HeroAndFriendsNameWithIdsNameChange.json", apolloClient.query(friendsQuery).responseFetcher(NETWORK_ONLY), new Predicate<Response<HeroAndFriendsNamesWithIDsQuery.Data>>() {
@Override
public boolean test(Response<HeroAndFriendsNamesWithIDsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
watcher.cancel();
assertThat(heroNameList.get(0)).isEqualTo("R2-D2");
assertThat(heroNameList.get(1)).isEqualTo("Artoo");
}
use of com.apollographql.apollo.api.Response 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.api.Response 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