Search in sources :

Example 1 with HeroNameWithEnumsQuery

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

the class OptimisticCacheTestCase method full_persisted_partial_optimistic.

@Test
public void full_persisted_partial_optimistic() throws Exception {
    enqueueAndAssertResponse(server, "HeroNameWithEnumsResponse.json", apolloClient.query(new HeroNameWithEnumsQuery()), new Predicate<Response<HeroNameWithEnumsQuery.Data>>() {

        @Override
        public boolean test(Response<HeroNameWithEnumsQuery.Data> response) throws Exception {
            return !response.hasErrors();
        }
    });
    UUID mutationId = UUID.randomUUID();
    apolloClient.apolloStore().writeOptimisticUpdates(new HeroNameQuery(), new HeroNameQuery.Data(new HeroNameQuery.Hero("Droid", "R22-D22")), mutationId).execute();
    assertResponse(apolloClient.query(new HeroNameWithEnumsQuery()).responseFetcher(CACHE_ONLY), new Predicate<Response<HeroNameWithEnumsQuery.Data>>() {

        @Override
        public boolean test(Response<HeroNameWithEnumsQuery.Data> response) throws Exception {
            assertThat(response.data().hero().name()).isEqualTo("R22-D22");
            assertThat(response.data().hero().firstAppearsIn()).isEqualTo(Episode.EMPIRE);
            assertThat(response.data().hero().appearsIn()).isEqualTo(Arrays.asList(Episode.NEWHOPE, Episode.EMPIRE, Episode.JEDI));
            return true;
        }
    });
    apolloClient.apolloStore().rollbackOptimisticUpdates(mutationId).execute();
    assertResponse(apolloClient.query(new HeroNameWithEnumsQuery()).responseFetcher(CACHE_ONLY), new Predicate<Response<HeroNameWithEnumsQuery.Data>>() {

        @Override
        public boolean test(Response<HeroNameWithEnumsQuery.Data> response) throws Exception {
            assertThat(response.data().hero().name()).isEqualTo("R2-D2");
            assertThat(response.data().hero().firstAppearsIn()).isEqualTo(Episode.EMPIRE);
            assertThat(response.data().hero().appearsIn()).isEqualTo(Arrays.asList(Episode.NEWHOPE, Episode.EMPIRE, Episode.JEDI));
            return true;
        }
    });
}
Also used : Utils.enqueueAndAssertResponse(com.apollographql.apollo.Utils.enqueueAndAssertResponse) Utils.assertResponse(com.apollographql.apollo.Utils.assertResponse) Response(com.apollographql.apollo.api.Response) MockResponse(okhttp3.mockwebserver.MockResponse) HeroNameWithEnumsQuery(com.apollographql.apollo.integration.normalizer.HeroNameWithEnumsQuery) HeroNameQuery(com.apollographql.apollo.integration.normalizer.HeroNameQuery) UUID(java.util.UUID) IOException(java.io.IOException) ApolloException(com.apollographql.apollo.exception.ApolloException) Test(org.junit.Test)

Example 2 with HeroNameWithEnumsQuery

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

the class ResponseWriteTestCase method enums.

@Test
public void enums() throws Exception {
    HeroNameWithEnumsQuery query = new HeroNameWithEnumsQuery();
    enqueueAndAssertResponse(server, "HeroNameWithEnumsResponse.json", apolloClient.query(query), new Predicate<Response<HeroNameWithEnumsQuery.Data>>() {

        @Override
        public boolean test(Response<HeroNameWithEnumsQuery.Data> response) throws Exception {
            assertThat(response.data().hero().__typename()).isEqualTo("Droid");
            assertThat(response.data().hero().name()).isEqualTo("R2-D2");
            assertThat(response.data().hero().firstAppearsIn()).isEqualTo(Episode.EMPIRE);
            assertThat(response.data().hero().appearsIn()).hasSize(3);
            assertThat(response.data().hero().appearsIn().get(0)).isEqualTo(Episode.NEWHOPE);
            assertThat(response.data().hero().appearsIn().get(1)).isEqualTo(Episode.EMPIRE);
            assertThat(response.data().hero().appearsIn().get(2)).isEqualTo(Episode.JEDI);
            return true;
        }
    });
    HeroNameWithEnumsQuery.Hero hero = new HeroNameWithEnumsQuery.Hero("Droid", "R222-D222", Episode.JEDI, Collections.<Episode>emptyList());
    apolloClient.apolloStore().write(query, new HeroNameWithEnumsQuery.Data(hero)).execute();
    assertCachedQueryResponse(query, new Predicate<Response<HeroNameWithEnumsQuery.Data>>() {

        @Override
        public boolean test(Response<HeroNameWithEnumsQuery.Data> response) throws Exception {
            assertThat(response.data().hero().__typename()).isEqualTo("Droid");
            assertThat(response.data().hero().name()).isEqualTo("R222-D222");
            assertThat(response.data().hero().firstAppearsIn()).isEqualTo(Episode.JEDI);
            assertThat(response.data().hero().appearsIn()).hasSize(0);
            return true;
        }
    });
    hero = new HeroNameWithEnumsQuery.Hero(hero.__typename(), "R22-D22", Episode.JEDI, asList(Episode.EMPIRE));
    apolloClient.apolloStore().write(query, new HeroNameWithEnumsQuery.Data(hero)).execute();
    assertCachedQueryResponse(query, new Predicate<Response<HeroNameWithEnumsQuery.Data>>() {

        @Override
        public boolean test(Response<HeroNameWithEnumsQuery.Data> response) throws Exception {
            assertThat(response.data().hero().__typename()).isEqualTo("Droid");
            assertThat(response.data().hero().name()).isEqualTo("R22-D22");
            assertThat(response.data().hero().firstAppearsIn()).isEqualTo(Episode.JEDI);
            assertThat(response.data().hero().appearsIn()).hasSize(1);
            assertThat(response.data().hero().appearsIn().get(0)).isEqualTo(Episode.EMPIRE);
            return true;
        }
    });
}
Also used : Utils.enqueueAndAssertResponse(com.apollographql.apollo.Utils.enqueueAndAssertResponse) Utils.assertResponse(com.apollographql.apollo.Utils.assertResponse) Response(com.apollographql.apollo.api.Response) HeroNameWithEnumsQuery(com.apollographql.apollo.integration.normalizer.HeroNameWithEnumsQuery) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

Utils.assertResponse (com.apollographql.apollo.Utils.assertResponse)2 Utils.enqueueAndAssertResponse (com.apollographql.apollo.Utils.enqueueAndAssertResponse)2 Response (com.apollographql.apollo.api.Response)2 HeroNameWithEnumsQuery (com.apollographql.apollo.integration.normalizer.HeroNameWithEnumsQuery)2 Test (org.junit.Test)2 ApolloException (com.apollographql.apollo.exception.ApolloException)1 HeroNameQuery (com.apollographql.apollo.integration.normalizer.HeroNameQuery)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 UUID (java.util.UUID)1 MockResponse (okhttp3.mockwebserver.MockResponse)1