use of com.apollographql.apollo.interceptor.ApolloInterceptor in project apollo-android by apollographql.
the class ApolloInterceptorTest method applicationInterceptorCanMakeMultipleRequestsToServer.
@Test
public void applicationInterceptorCanMakeMultipleRequestsToServer() throws Exception {
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_CHANGE));
EpisodeHeroNameQuery query = createHeroNameQuery();
ApolloInterceptor interceptor = createChainInterceptor();
client = createApolloClient(interceptor);
enqueueAndAssertResponse(server, FILE_EPISODE_HERO_NAME_WITH_ID, client.query(query), new Predicate<Response<EpisodeHeroNameQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
assertThat(response.data().hero().name()).isEqualTo("Artoo");
return true;
}
});
}
use of com.apollographql.apollo.interceptor.ApolloInterceptor in project apollo-android by apollographql.
the class ApolloInterceptorTest method asyncApplicationInterceptorCanShortCircuitResponses.
@Test
public void asyncApplicationInterceptorCanShortCircuitResponses() throws Exception {
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
EpisodeHeroNameQuery query = createHeroNameQuery();
final InterceptorResponse expectedResponse = prepareInterceptorResponse(query);
ApolloInterceptor interceptor = createShortcutInterceptor(expectedResponse);
client = createApolloClient(interceptor);
Rx2Apollo.from(client.query(query)).test().assertValue(expectedResponse.parsedResponse.get());
}
use of com.apollographql.apollo.interceptor.ApolloInterceptor in project apollo-android by apollographql.
the class ApolloInterceptorTest method asyncApplicationInterceptorThrowsApolloException.
@Test
public void asyncApplicationInterceptorThrowsApolloException() throws Exception {
final String message = "ApolloException";
EpisodeHeroNameQuery query = createHeroNameQuery();
ApolloInterceptor interceptor = new ApolloInterceptor() {
@Override
public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain, @Nonnull Executor dispatcher, @Nonnull CallBack callBack) {
ApolloException apolloException = new ApolloParseException(message);
callBack.onFailure(apolloException);
}
@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 message.equals(throwable.getMessage()) && throwable instanceof ApolloParseException;
}
});
}
use of com.apollographql.apollo.interceptor.ApolloInterceptor in project apollo-android by apollographql.
the class ApolloInterceptorTest method onShortCircuitingResponseSubsequentInterceptorsAreNotCalled.
@Test
public void onShortCircuitingResponseSubsequentInterceptorsAreNotCalled() throws IOException, ApolloException {
EpisodeHeroNameQuery query = createHeroNameQuery();
final InterceptorResponse expectedResponse = prepareInterceptorResponse(query);
ApolloInterceptor firstInterceptor = createShortcutInterceptor(expectedResponse);
ApolloInterceptor secondInterceptor = createChainInterceptor();
client = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).addApplicationInterceptor(firstInterceptor).addApplicationInterceptor(secondInterceptor).build();
assertResponse(client.query(query), new Predicate<Response<EpisodeHeroNameQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
assertThat(expectedResponse.parsedResponse.get()).isEqualTo(response);
return true;
}
});
}
use of com.apollographql.apollo.interceptor.ApolloInterceptor 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;
}
});
}
Aggregations