Search in sources :

Example 1 with CharacterNameByIdQuery

use of com.apollographql.apollo.integration.normalizer.CharacterNameByIdQuery in project apollo-android by apollographql.

the class NormalizedCacheTestCase method removeMultipleFromStore.

@Test
public void removeMultipleFromStore() 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 {
            assertThat(response.data().hero().name()).isEqualTo("R2-D2");
            assertThat(response.data().hero().friends()).hasSize(3);
            return true;
        }
    });
    assertResponse(apolloClient.query(new CharacterNameByIdQuery("1000")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterNameByIdQuery.Data>>() {

        @Override
        public boolean test(Response<CharacterNameByIdQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(((CharacterNameByIdQuery.AsHuman) response.data().character()).name()).isEqualTo("Luke Skywalker");
            return true;
        }
    });
    assertResponse(apolloClient.query(new CharacterNameByIdQuery("1002")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterNameByIdQuery.Data>>() {

        @Override
        public boolean test(Response<CharacterNameByIdQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(((CharacterNameByIdQuery.AsHuman) response.data().character()).name()).isEqualTo("Han Solo");
            return true;
        }
    });
    assertResponse(apolloClient.query(new CharacterNameByIdQuery("1003")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterNameByIdQuery.Data>>() {

        @Override
        public boolean test(Response<CharacterNameByIdQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(((CharacterNameByIdQuery.AsHuman) response.data().character()).name()).isEqualTo("Leia Organa");
            return true;
        }
    });
    assertThat(apolloClient.apolloStore().remove(asList(CacheKey.from("1002"), CacheKey.from("1000"))).execute()).isEqualTo(2);
    assertResponse(apolloClient.query(new CharacterNameByIdQuery("1000")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterNameByIdQuery.Data>>() {

        @Override
        public boolean test(Response<CharacterNameByIdQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(response.data()).isNull();
            return true;
        }
    });
    assertResponse(apolloClient.query(new CharacterNameByIdQuery("1002")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterNameByIdQuery.Data>>() {

        @Override
        public boolean test(Response<CharacterNameByIdQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(response.data()).isNull();
            return true;
        }
    });
    assertResponse(apolloClient.query(new CharacterNameByIdQuery("1003")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterNameByIdQuery.Data>>() {

        @Override
        public boolean test(Response<CharacterNameByIdQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(((CharacterNameByIdQuery.AsHuman) response.data().character()).name()).isEqualTo("Leia Organa");
            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) HeroAndFriendsNamesWithIDsQuery(com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery) CharacterNameByIdQuery(com.apollographql.apollo.integration.normalizer.CharacterNameByIdQuery) Test(org.junit.Test)

Example 2 with CharacterNameByIdQuery

use of com.apollographql.apollo.integration.normalizer.CharacterNameByIdQuery in project apollo-android by apollographql.

the class NormalizedCacheTestCase method removeFromStore.

@Test
public void removeFromStore() 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 {
            assertThat(response.data().hero().name()).isEqualTo("R2-D2");
            assertThat(response.data().hero().friends()).hasSize(3);
            return true;
        }
    });
    assertResponse(apolloClient.query(new CharacterNameByIdQuery("1002")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterNameByIdQuery.Data>>() {

        @Override
        public boolean test(Response<CharacterNameByIdQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(((CharacterNameByIdQuery.AsHuman) response.data().character()).name()).isEqualTo("Han Solo");
            return true;
        }
    });
    // test remove root query object
    assertThat(apolloClient.apolloStore().remove(CacheKey.from("2001")).execute()).isTrue();
    assertResponse(apolloClient.query(new HeroAndFriendsNamesWithIDsQuery(Input.fromNullable(Episode.NEWHOPE))).responseFetcher(CACHE_ONLY), new Predicate<Response<HeroAndFriendsNamesWithIDsQuery.Data>>() {

        @Override
        public boolean test(Response<HeroAndFriendsNamesWithIDsQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(response.data()).isNull();
            return true;
        }
    });
    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 CharacterNameByIdQuery("1002")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterNameByIdQuery.Data>>() {

        @Override
        public boolean test(Response<CharacterNameByIdQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(((CharacterNameByIdQuery.AsHuman) response.data().character()).name()).isEqualTo("Han Solo");
            return true;
        }
    });
    // test remove object from the list
    assertThat(apolloClient.apolloStore().remove(CacheKey.from("1002")).execute()).isTrue();
    assertResponse(apolloClient.query(new HeroAndFriendsNamesWithIDsQuery(Input.fromNullable(Episode.NEWHOPE))).responseFetcher(CACHE_ONLY), new Predicate<Response<HeroAndFriendsNamesWithIDsQuery.Data>>() {

        @Override
        public boolean test(Response<HeroAndFriendsNamesWithIDsQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(response.data()).isNull();
            return true;
        }
    });
    assertResponse(apolloClient.query(new CharacterNameByIdQuery("1002")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterNameByIdQuery.Data>>() {

        @Override
        public boolean test(Response<CharacterNameByIdQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(response.data()).isNull();
            return true;
        }
    });
    assertResponse(apolloClient.query(new CharacterNameByIdQuery("1003")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterNameByIdQuery.Data>>() {

        @Override
        public boolean test(Response<CharacterNameByIdQuery.Data> response) throws Exception {
            assertThat(response.fromCache()).isTrue();
            assertThat(response.data()).isNotNull();
            assertThat(((CharacterNameByIdQuery.AsHuman) response.data().character()).name()).isEqualTo("Leia Organa");
            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) HeroAndFriendsNamesWithIDsQuery(com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery) CharacterNameByIdQuery(com.apollographql.apollo.integration.normalizer.CharacterNameByIdQuery) Test(org.junit.Test)

Example 3 with CharacterNameByIdQuery

use of com.apollographql.apollo.integration.normalizer.CharacterNameByIdQuery in project apollo-android by apollographql.

the class NormalizedCacheTestCase method masterDetailSuccess.

@Test
public void masterDetailSuccess() 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 CharacterNameByIdQuery("1002")).responseFetcher(CACHE_ONLY), new Predicate<Response<CharacterNameByIdQuery.Data>>() {

        @Override
        public boolean test(Response<CharacterNameByIdQuery.Data> response) throws Exception {
            assertThat(response.data().character()).isNotNull();
            assertThat(((CharacterNameByIdQuery.AsHuman) response.data().character()).name()).isEqualTo("Han Solo");
            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) HeroAndFriendsNamesWithIDsQuery(com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery) CharacterNameByIdQuery(com.apollographql.apollo.integration.normalizer.CharacterNameByIdQuery) Test(org.junit.Test)

Aggregations

Utils.assertResponse (com.apollographql.apollo.Utils.assertResponse)3 Utils.cacheAndAssertCachedResponse (com.apollographql.apollo.Utils.cacheAndAssertCachedResponse)3 Utils.enqueueAndAssertResponse (com.apollographql.apollo.Utils.enqueueAndAssertResponse)3 Utils.mockResponse (com.apollographql.apollo.Utils.mockResponse)3 Response (com.apollographql.apollo.api.Response)3 CharacterNameByIdQuery (com.apollographql.apollo.integration.normalizer.CharacterNameByIdQuery)3 HeroAndFriendsNamesWithIDsQuery (com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery)3 Test (org.junit.Test)3