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