use of com.apollographql.apollo.integration.normalizer.EpisodeHeroWithInlineFragmentQuery in project apollo-android by apollographql.
the class ResponseWriteTestCase method operation_with_inline_fragments.
@SuppressWarnings("CheckReturnValue")
@Test
public void operation_with_inline_fragments() throws Exception {
EpisodeHeroWithInlineFragmentQuery query = new EpisodeHeroWithInlineFragmentQuery(Input.fromNullable(Episode.NEWHOPE));
enqueueAndAssertResponse(server, "EpisodeHeroWithInlineFragmentResponse.json", apolloClient.query(query), new Predicate<Response<EpisodeHeroWithInlineFragmentQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroWithInlineFragmentQuery.Data> response) throws Exception {
assertThat(response.data().hero().__typename()).isEqualTo("Droid");
assertThat(response.data().hero().name()).isEqualTo("R2-D2");
assertThat(response.data().hero().friends()).hasSize(3);
EpisodeHeroWithInlineFragmentQuery.AsHuman asHuman = (EpisodeHeroWithInlineFragmentQuery.AsHuman) response.data().hero().friends().get(0);
assertThat(asHuman.__typename()).isEqualTo("Human");
assertThat(asHuman.id()).isEqualTo("1000");
assertThat(asHuman.name()).isEqualTo("Luke Skywalker");
assertThat(asHuman.height()).isWithin(1.5);
EpisodeHeroWithInlineFragmentQuery.AsDroid asDroid1 = (EpisodeHeroWithInlineFragmentQuery.AsDroid) response.data().hero().friends().get(1);
assertThat(asDroid1.__typename()).isEqualTo("Droid");
assertThat(asDroid1.name()).isEqualTo("Android");
assertThat(asDroid1.primaryFunction()).isEqualTo("Hunt and destroy iOS devices");
EpisodeHeroWithInlineFragmentQuery.AsDroid asDroid2 = (EpisodeHeroWithInlineFragmentQuery.AsDroid) response.data().hero().friends().get(2);
assertThat(asDroid2.__typename()).isEqualTo("Droid");
assertThat(asDroid2.name()).isEqualTo("Battle Droid");
assertThat(asDroid2.primaryFunction()).isEqualTo("Controlled alternative to human soldiers");
return true;
}
});
EpisodeHeroWithInlineFragmentQuery.Hero hero = new EpisodeHeroWithInlineFragmentQuery.Hero("Droid", "R22-D22", asList(new EpisodeHeroWithInlineFragmentQuery.AsHuman("Human", "1002", "Han Solo", 2.5), new EpisodeHeroWithInlineFragmentQuery.AsDroid("Droid", "RD", "Entertainment")));
apolloClient.apolloStore().write(query, new EpisodeHeroWithInlineFragmentQuery.Data(hero)).execute();
assertCachedQueryResponse(query, new Predicate<Response<EpisodeHeroWithInlineFragmentQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroWithInlineFragmentQuery.Data> response) throws Exception {
assertThat(response.data().hero().__typename()).isEqualTo("Droid");
assertThat(response.data().hero().name()).isEqualTo("R22-D22");
assertThat(response.data().hero().friends()).hasSize(2);
EpisodeHeroWithInlineFragmentQuery.AsHuman asHuman = (EpisodeHeroWithInlineFragmentQuery.AsHuman) response.data().hero().friends().get(0);
assertThat(asHuman.__typename()).isEqualTo("Human");
assertThat(asHuman.id()).isEqualTo("1002");
assertThat(asHuman.name()).isEqualTo("Han Solo");
assertThat(asHuman.height()).isWithin(2.5);
EpisodeHeroWithInlineFragmentQuery.AsDroid asDroid = (EpisodeHeroWithInlineFragmentQuery.AsDroid) response.data().hero().friends().get(1);
assertThat(asDroid.__typename()).isEqualTo("Droid");
assertThat(asDroid.name()).isEqualTo("RD");
assertThat(asDroid.primaryFunction()).isEqualTo("Entertainment");
return true;
}
});
}
Aggregations