use of com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery in project apollo-android by apollographql.
the class NormalizedCacheTestCase method dump.
@Test
public void dump() throws Exception {
enqueueAndAssertResponse(server, "HeroAndFriendsNameWithIdsResponse.json", apolloClient.query(new HeroAndFriendsNamesWithIDsQuery(Input.fromNullable(Episode.NEWHOPE))).responseFetcher(NETWORK_ONLY), new Predicate<Response<HeroAndFriendsNamesWithIDsQuery.Data>>() {
@Override
public boolean test(Response<HeroAndFriendsNamesWithIDsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
Map<Class, Map<String, Record>> dump = apolloClient.apolloStore().normalizedCache().dump();
assertThat(NormalizedCache.prettifyDump(dump)).isEqualTo("OptimisticNormalizedCache {}\n" + "LruNormalizedCache {\n" + " \"1002\" : {\n" + " \"__typename\" : Human\n" + " \"id\" : 1002\n" + " \"name\" : Han Solo\n" + " }\n" + "\n" + " \"QUERY_ROOT\" : {\n" + " \"hero({\"episode\":\"NEWHOPE\"})\" : CacheRecordRef(2001)\n" + " }\n" + "\n" + " \"1003\" : {\n" + " \"__typename\" : Human\n" + " \"id\" : 1003\n" + " \"name\" : Leia Organa\n" + " }\n" + "\n" + " \"1000\" : {\n" + " \"__typename\" : Human\n" + " \"id\" : 1000\n" + " \"name\" : Luke Skywalker\n" + " }\n" + "\n" + " \"2001\" : {\n" + " \"__typename\" : Droid\n" + " \"id\" : 2001\n" + " \"name\" : R2-D2\n" + " \"friends\" : [\n" + " CacheRecordRef(1000)\n" + " CacheRecordRef(1002)\n" + " CacheRecordRef(1003)\n" + " ]\n" + " }\n" + "}\n");
}
use of com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery in project apollo-android by apollographql.
the class NormalizedCacheTestCase method masterDetailFailIncomplete.
@Test
public void masterDetailFailIncomplete() throws Exception {
enqueueAndAssertResponse(server, "HeroAndFriendsNameWithIdsResponse.json", apolloClient.query(new HeroAndFriendsNamesWithIDsQuery(Input.fromNullable(Episode.NEWHOPE))).responseFetcher(NETWORK_ONLY), new Predicate<Response<HeroAndFriendsNamesWithIDsQuery.Data>>() {
@Override
public boolean test(Response<HeroAndFriendsNamesWithIDsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
assertResponse(apolloClient.query(new CharacterDetailsQuery("1002")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterDetailsQuery.Data>>() {
@Override
public boolean test(Response<CharacterDetailsQuery.Data> response) throws Exception {
assertThat(response.data()).isNull();
return true;
}
});
}
use of com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery in project apollo-android by apollographql.
the class Rx2ApolloTest method queryWatcherUpdatedDifferentQueryDifferentResults.
@Test
@SuppressWarnings("CheckReturnValue")
public void queryWatcherUpdatedDifferentQueryDifferentResults() 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("HeroAndFriendsNameWithIdsNameChange.json"));
apolloClient.query(new HeroAndFriendsNamesWithIDsQuery(Input.fromNullable(NEWHOPE))).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