use of com.apollographql.apollo.integration.normalizer.HeroNameQuery 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.HeroNameQuery in project apollo-android by apollographql.
the class IntegrationTest method operationResponseParser.
@Test
public void operationResponseParser() throws Exception {
String json = Utils.readFileToString(getClass(), "/HeroNameResponse.json");
HeroNameQuery query = new HeroNameQuery();
Response<HeroNameQuery.Data> response = new OperationResponseParser<>(query, query.responseFieldMapper(), new ScalarTypeAdapters(Collections.EMPTY_MAP)).parse(new Buffer().writeUtf8(json));
assertThat(response.data().hero().name()).isEqualTo("R2-D2");
}
use of com.apollographql.apollo.integration.normalizer.HeroNameQuery in project apollo-android by apollographql.
the class ResponseNormalizationTest method testHeroName.
@Test
public void testHeroName() throws Exception {
assertHasNoErrors("HeroNameResponse.json", new HeroNameQuery());
Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
CacheReference reference = (CacheReference) record.field("hero");
assertThat(reference).isEqualTo(new CacheReference("hero"));
final Record heroRecord = normalizedCache.loadRecord(reference.key(), CacheHeaders.NONE);
assertThat(heroRecord.field("name")).isEqualTo("R2-D2");
}
Aggregations