use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class ApolloInterceptorTest method asyncApplicationInterceptorReturnsNull.
@Test
public void asyncApplicationInterceptorReturnsNull() throws TimeoutException, InterruptedException {
EpisodeHeroNameQuery query = createHeroNameQuery();
ApolloInterceptor interceptor = new ApolloInterceptor() {
@Override
public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain, @Nonnull Executor dispatcher, @Nonnull final CallBack callBack) {
dispatcher.execute(new Runnable() {
@Override
public void run() {
callBack.onResponse(null);
}
});
}
@Override
public void dispose() {
}
};
client = createApolloClient(interceptor);
Rx2Apollo.from(client.query(query)).test().assertError(new Predicate<Throwable>() {
@Override
public boolean test(Throwable throwable) throws Exception {
return throwable instanceof NullPointerException;
}
});
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class ApolloInterceptorTest method asyncApplicationInterceptorRewritesResponsesFromServer.
@Test
public void asyncApplicationInterceptorRewritesResponsesFromServer() throws Exception {
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
EpisodeHeroNameQuery query = createHeroNameQuery();
final InterceptorResponse rewrittenResponse = prepareInterceptorResponse(query);
ApolloInterceptor interceptor = new ApolloInterceptor() {
@Override
public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain, @Nonnull Executor dispatcher, @Nonnull final CallBack callBack) {
chain.proceedAsync(request, dispatcher, new CallBack() {
@Override
public void onResponse(@Nonnull InterceptorResponse response) {
callBack.onResponse(rewrittenResponse);
}
@Override
public void onFailure(@Nonnull ApolloException e) {
throw new RuntimeException(e);
}
@Override
public void onCompleted() {
callBack.onCompleted();
}
@Override
public void onFetch(FetchSourceType sourceType) {
callBack.onFetch(sourceType);
}
});
}
@Override
public void dispose() {
}
};
client = createApolloClient(interceptor);
Rx2Apollo.from(client.query(query)).test().assertValue(rewrittenResponse.parsedResponse.get());
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class ApolloWatcherTest method testQueryWatcherUpdated_SameQuery_DifferentResults_cacheOnly.
@Test
public void testQueryWatcherUpdated_SameQuery_DifferentResults_cacheOnly() throws Exception {
final List<String> heroNameList = new ArrayList<>();
EpisodeHeroNameQuery query = EpisodeHeroNameQuery.builder().episode(Episode.EMPIRE).build();
server.enqueue(mockResponse("EpisodeHeroNameResponseWithId.json"));
apolloClient.query(query).enqueue(new ApolloCall.Callback<EpisodeHeroNameQuery.Data>() {
@Override
public void onResponse(@Nonnull Response<EpisodeHeroNameQuery.Data> response) {
}
@Override
public void onFailure(@Nonnull ApolloException e) {
Assert.fail(e.getMessage());
}
});
ApolloQueryWatcher<EpisodeHeroNameQuery.Data> watcher = apolloClient.query(query).responseFetcher(CACHE_ONLY).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());
}
});
// Another newer call gets updated information
server.enqueue(mockResponse("EpisodeHeroNameResponseNameChange.json"));
apolloClient.query(query).responseFetcher(NETWORK_ONLY).enqueue(null);
watcher.cancel();
assertThat(heroNameList.get(0)).isEqualTo("R2-D2");
assertThat(heroNameList.get(1)).isEqualTo("Artoo");
assertThat(heroNameList.size()).isEqualTo(2);
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class ApolloWatcherTest method testQueryWatcherNotUpdated_DifferentQueries.
@Test
public void testQueryWatcherNotUpdated_DifferentQueries() 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();
server.enqueue(mockResponse("HeroAndFriendsNameWithIdsResponse.json"));
apolloClient.query(friendsQuery).responseFetcher(NETWORK_ONLY).enqueue(null);
watcher.cancel();
assertThat(heroNameList.get(0)).isEqualTo("R2-D2");
assertThat(heroNameList.size()).isEqualTo(1);
}
use of com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery in project apollo-android by apollographql.
the class ApolloWatcherTest method testQueryWatcherUpdated_Store_write.
@Test
public void testQueryWatcherUpdated_Store_write() throws IOException, InterruptedException, TimeoutException, ApolloException {
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());
}
});
assertThat(heroNameList.get(0)).isEqualTo("R2-D2");
// Someone writes to the store directly
Set<String> changedKeys = apolloClient.apolloStore().writeTransaction(new Transaction<WriteableStore, Set<String>>() {
@Nullable
@Override
public Set<String> execute(WriteableStore cache) {
Record record = Record.builder("2001").addField("name", "Artoo").build();
return cache.merge(Collections.singletonList(record), CacheHeaders.NONE);
}
});
apolloClient.apolloStore().publish(changedKeys);
assertThat(heroNameList.get(1)).isEqualTo("Artoo");
watcher.cancel();
}
Aggregations