Search in sources :

Example 1 with HeroAndFriendsNamesWithIDForParentOnlyQuery

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

the class ResponseNormalizationTest method testHeroAndFriendsNamesWithIDForParentOnly.

@Test
public void testHeroAndFriendsNamesWithIDForParentOnly() throws Exception {
    assertHasNoErrors("HeroAndFriendsNameWithIdsParentOnlyResponse.json", new HeroAndFriendsNamesWithIDForParentOnlyQuery(Input.fromNullable(JEDI)));
    Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
    CacheReference heroReference = (CacheReference) record.field(TEST_FIELD_KEY_JEDI);
    assertThat(heroReference).isEqualTo(new CacheReference("2001"));
    final Record heroRecord = normalizedCache.loadRecord(heroReference.key(), CacheHeaders.NONE);
    assertThat(heroRecord.field("name")).isEqualTo("R2-D2");
    assertThat(heroRecord.field("friends")).isEqualTo(Arrays.asList(new CacheReference("2001.friends.0"), new CacheReference("2001.friends.1"), new CacheReference("2001.friends.2")));
    final Record luke = normalizedCache.loadRecord("2001.friends.0", CacheHeaders.NONE);
    assertThat(luke.field("name")).isEqualTo("Luke Skywalker");
}
Also used : HeroAndFriendsNamesWithIDForParentOnlyQuery(com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDForParentOnlyQuery) Record(com.apollographql.apollo.cache.normalized.Record) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) Test(org.junit.Test)

Aggregations

CacheReference (com.apollographql.apollo.cache.normalized.CacheReference)1 Record (com.apollographql.apollo.cache.normalized.Record)1 HeroAndFriendsNamesWithIDForParentOnlyQuery (com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDForParentOnlyQuery)1 Test (org.junit.Test)1