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;
}
});
}
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;
}
});
}
Aggregations