use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class Rx2ApolloTest method prefetchCompletes.
@Test
public void prefetchCompletes() throws Exception {
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
Rx2Apollo.from(apolloClient.prefetch(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE)))).test().assertNoErrors().assertComplete();
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class Rx2ApolloTest method queryWatcherNotCalledWhenCanceled.
@Test
public void queryWatcherNotCalledWhenCanceled() throws Exception {
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
TestObserver<EpisodeHeroNameQuery.Data> testObserver = new TestObserver<>();
TestScheduler scheduler = new TestScheduler();
Disposable disposable = 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();
}
}).observeOn(scheduler).subscribeWith(testObserver);
scheduler.triggerActions();
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_CHANGE));
apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE))).responseFetcher(NETWORK_ONLY).enqueue(null);
disposable.dispose();
scheduler.triggerActions();
testObserver.assertValueCount(1).assertValueAt(0, new Predicate<EpisodeHeroNameQuery.Data>() {
@Override
public boolean test(EpisodeHeroNameQuery.Data data) throws Exception {
assertThat(data.hero().name()).isEqualTo("R2-D2");
return true;
}
});
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class NetworkOnlyFetcherTest method enqueue.
@Test
public void enqueue() throws IOException, ApolloException, TimeoutException, InterruptedException {
EpisodeHeroNameQuery query = EpisodeHeroNameQuery.builder().episode(Episode.EMPIRE).build();
TrackingCallback trackingCallback;
// Has error when cache empty, and network error
server.enqueue(new MockResponse().setResponseCode(HTTP_INTERNAL_ERROR).setBody("Server Error"));
trackingCallback = new TrackingCallback();
apolloClient.query(query).responseFetcher(NETWORK_ONLY).enqueue(trackingCallback);
assertThat(trackingCallback.exceptions.size()).isEqualTo(1);
// Goes to network when empty
server.enqueue(mockResponse("HeroNameResponse.json"));
trackingCallback = new TrackingCallback();
apolloClient.query(query).responseFetcher(NETWORK_ONLY).enqueue(trackingCallback);
assertThat(trackingCallback.exceptions).isEmpty();
assertThat(trackingCallback.responseList.size()).isEqualTo(1);
assertThat(trackingCallback.responseList.get(0).fromCache()).isFalse();
assertThat(trackingCallback.responseList.get(0).data().hero().name()).isEqualTo("R2-D2");
// Goes to network after cache populated
server.enqueue(mockResponse("HeroNameResponse.json"));
trackingCallback = new TrackingCallback();
apolloClient.query(query).responseFetcher(NETWORK_ONLY).enqueue(trackingCallback);
assertThat(trackingCallback.exceptions).isEmpty();
assertThat(trackingCallback.responseList.size()).isEqualTo(1);
assertThat(trackingCallback.responseList.get(0).fromCache()).isFalse();
assertThat(trackingCallback.responseList.get(0).data().hero().name()).isEqualTo("R2-D2");
// Has error when cache empty, and network error
server.enqueue(new MockResponse().setResponseCode(HTTP_INTERNAL_ERROR).setBody("Server Error"));
trackingCallback = new TrackingCallback();
apolloClient.query(query).responseFetcher(NETWORK_ONLY).enqueue(trackingCallback);
assertThat(trackingCallback.exceptions.size()).isEqualTo(1);
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class ApolloCancelCallTest method cancelPrefetchBeforeEnqueueCanceledException.
@Test
public void cancelPrefetchBeforeEnqueueCanceledException() throws Exception {
server.enqueue(mockResponse("EpisodeHeroNameResponse.json"));
ApolloCall<EpisodeHeroNameQuery.Data> call = apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(Episode.EMPIRE)));
call.cancel();
Rx2Apollo.from(call).test().assertError(ApolloCanceledException.class);
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class ApolloCancelCallTest method cancelCallBeforeEnqueueCanceledException.
@Test
public void cancelCallBeforeEnqueueCanceledException() throws Exception {
server.enqueue(mockResponse("EpisodeHeroNameResponse.json"));
ApolloCall<EpisodeHeroNameQuery.Data> call = apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(Episode.EMPIRE)));
call.cancel();
Rx2Apollo.from(call).test().assertError(ApolloCanceledException.class);
}
Aggregations