Search in sources :

Example 11 with HeroAndFriendsNamesWithIDsQuery

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");
}
Also used : Utils.mockResponse(com.apollographql.apollo.Utils.mockResponse) Utils.enqueueAndAssertResponse(com.apollographql.apollo.Utils.enqueueAndAssertResponse) Utils.cacheAndAssertCachedResponse(com.apollographql.apollo.Utils.cacheAndAssertCachedResponse) Utils.assertResponse(com.apollographql.apollo.Utils.assertResponse) Response(com.apollographql.apollo.api.Response) HeroAndFriendsNamesWithIDsQuery(com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery) Map(java.util.Map) Test(org.junit.Test)

Example 12 with HeroAndFriendsNamesWithIDsQuery

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;
        }
    });
}
Also used : Utils.mockResponse(com.apollographql.apollo.Utils.mockResponse) Utils.enqueueAndAssertResponse(com.apollographql.apollo.Utils.enqueueAndAssertResponse) Utils.cacheAndAssertCachedResponse(com.apollographql.apollo.Utils.cacheAndAssertCachedResponse) Utils.assertResponse(com.apollographql.apollo.Utils.assertResponse) Response(com.apollographql.apollo.api.Response) CharacterDetailsQuery(com.apollographql.apollo.integration.normalizer.CharacterDetailsQuery) HeroAndFriendsNamesWithIDsQuery(com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery) Test(org.junit.Test)

Example 13 with HeroAndFriendsNamesWithIDsQuery

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;
        }
    });
}
Also used : Utils.mockResponse(com.apollographql.apollo.Utils.mockResponse) Response(com.apollographql.apollo.api.Response) Function(io.reactivex.functions.Function) EpisodeHeroNameQuery(com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery) HeroAndFriendsNamesWithIDsQuery(com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery) TestObserver(io.reactivex.observers.TestObserver) Predicate(io.reactivex.functions.Predicate) Test(org.junit.Test)

Aggregations

HeroAndFriendsNamesWithIDsQuery (com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery)13 Test (org.junit.Test)13 Response (com.apollographql.apollo.api.Response)11 Utils.enqueueAndAssertResponse (com.apollographql.apollo.Utils.enqueueAndAssertResponse)10 Utils.assertResponse (com.apollographql.apollo.Utils.assertResponse)9 Utils.mockResponse (com.apollographql.apollo.Utils.mockResponse)8 Utils.cacheAndAssertCachedResponse (com.apollographql.apollo.Utils.cacheAndAssertCachedResponse)6 ApolloException (com.apollographql.apollo.exception.ApolloException)4 CharacterNameByIdQuery (com.apollographql.apollo.integration.normalizer.CharacterNameByIdQuery)3 EpisodeHeroNameQuery (com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery)3 IOException (java.io.IOException)3 HeroNameWithIdQuery (com.apollographql.apollo.integration.normalizer.HeroNameWithIdQuery)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 CacheReference (com.apollographql.apollo.cache.normalized.CacheReference)1 Record (com.apollographql.apollo.cache.normalized.Record)1 CharacterDetailsQuery (com.apollographql.apollo.integration.normalizer.CharacterDetailsQuery)1 HeroWithFriendsFragment (com.apollographql.apollo.integration.normalizer.fragment.HeroWithFriendsFragment)1 HumanWithIdFragment (com.apollographql.apollo.integration.normalizer.fragment.HumanWithIdFragment)1