use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class RxApolloTest method queryWatcherUpdatedSameQueryDifferentResults.
@Test
public void queryWatcherUpdatedSameQueryDifferentResults() throws Exception {
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_CHANGE));
final TestSubscriber<Response<EpisodeHeroNameQuery.Data>> testSubscriber = new TestSubscriber<>();
RxApollo.from(apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE))).watcher()).subscribe(testSubscriber);
apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE))).responseFetcher(NETWORK_ONLY).enqueue(null);
testSubscriber.assertValueCount(2);
assertThat(testSubscriber.getOnNextEvents().get(0).data().hero().name()).isEqualTo("R2-D2");
assertThat(testSubscriber.getOnNextEvents().get(1).data().hero().name()).isEqualTo("Artoo");
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class NormalizedCacheTestCase method fromCacheFlag.
@Test
public void fromCacheFlag() throws Exception {
enqueueAndAssertResponse(server, "HeroNameResponse.json", apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(Episode.EMPIRE))), new Predicate<Response<EpisodeHeroNameQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
return !response.fromCache();
}
});
enqueueAndAssertResponse(server, "HeroNameResponse.json", apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(Episode.EMPIRE))).responseFetcher(NETWORK_ONLY), new Predicate<Response<EpisodeHeroNameQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
return !response.fromCache();
}
});
assertResponse(apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(Episode.EMPIRE))).responseFetcher(CACHE_ONLY), new Predicate<Response<EpisodeHeroNameQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
return response.fromCache();
}
});
assertResponse(apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(Episode.EMPIRE))).responseFetcher(CACHE_FIRST), new Predicate<Response<EpisodeHeroNameQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
return response.fromCache();
}
});
assertResponse(apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(Episode.EMPIRE))).responseFetcher(NETWORK_FIRST), new Predicate<Response<EpisodeHeroNameQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
return response.fromCache();
}
});
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class Rx2ApolloTest method callIsCanceledWhenDisposed.
@Test
public void callIsCanceledWhenDisposed() throws Exception {
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
TestObserver<Response<EpisodeHeroNameQuery.Data>> testObserver = new TestObserver<>();
Disposable disposable = Rx2Apollo.from(apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE)))).subscribeWith(testObserver);
disposable.dispose();
testObserver.assertComplete();
assertThat(testObserver.isDisposed()).isTrue();
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class Rx2ApolloTest method prefetchIsCanceledWhenDisposed.
@Test
public void prefetchIsCanceledWhenDisposed() throws Exception {
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
TestObserver<EpisodeHeroNameQuery.Data> testObserver = new TestObserver<>();
Disposable disposable = Rx2Apollo.from(apolloClient.prefetch(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE)))).observeOn(new TestScheduler()).subscribeWith(testObserver);
disposable.dispose();
testObserver.assertNotComplete();
assertThat(testObserver.isDisposed()).isTrue();
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class Rx2ApolloTest method queryWatcherUpdatedSameQueryDifferentResults.
@Test
@SuppressWarnings("CheckReturnValue")
public void queryWatcherUpdatedSameQueryDifferentResults() throws Exception {
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
TestObserver<EpisodeHeroNameQuery.Data> observer = new TestObserver<>();
Rx2Apollo.from(apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE))).watcher()).map(new Function<Response<EpisodeHeroNameQuery.Data>, EpisodeHeroNameQuery.Data>() {
@Override
public EpisodeHeroNameQuery.Data apply(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
return response.data();
}
}).subscribeWith(observer);
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_CHANGE));
apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE))).responseFetcher(NETWORK_ONLY).enqueue(null);
observer.assertValueCount(2).assertValueAt(0, new Predicate<EpisodeHeroNameQuery.Data>() {
@Override
public boolean test(EpisodeHeroNameQuery.Data data) throws Exception {
assertThat(data.hero().name()).isEqualTo("R2-D2");
return true;
}
}).assertValueAt(1, new Predicate<EpisodeHeroNameQuery.Data>() {
@Override
public boolean test(EpisodeHeroNameQuery.Data data) throws Exception {
assertThat(data.hero().name()).isEqualTo("Artoo");
return true;
}
});
}
Aggregations