Search in sources :

Example 11 with CacheReference

use of com.apollographql.apollo.cache.normalized.CacheReference in project apollo-android by apollographql.

the class ResponseNormalizationTest method testSameHeroTwiceQuery.

@Test
public void testSameHeroTwiceQuery() throws Exception {
    assertHasNoErrors("SameHeroTwiceResponse.json", new SameHeroTwiceQuery());
    Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
    CacheReference heroReference = (CacheReference) record.field("hero");
    final Record hero = normalizedCache.loadRecord(heroReference.key(), CacheHeaders.NONE);
    assertThat(hero.field("name")).isEqualTo("R2-D2");
    assertThat(hero.field("appearsIn")).isEqualTo(Arrays.asList("NEWHOPE", "EMPIRE", "JEDI"));
}
Also used : Record(com.apollographql.apollo.cache.normalized.Record) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) SameHeroTwiceQuery(com.apollographql.apollo.integration.normalizer.SameHeroTwiceQuery) Test(org.junit.Test)

Example 12 with CacheReference

use of com.apollographql.apollo.cache.normalized.CacheReference in project apollo-android by apollographql.

the class ResponseNormalizationTest method testHeroParentTypeDependentFieldDroid.

@Test
public void testHeroParentTypeDependentFieldDroid() throws Exception {
    assertHasNoErrors("HeroParentTypeDependentFieldDroidResponse.json", new HeroParentTypeDependentFieldQuery(Input.fromNullable(JEDI)));
    Record lukeRecord = normalizedCache.loadRecord(TEST_FIELD_KEY_JEDI + ".friends.0", CacheHeaders.NONE);
    assertThat(lukeRecord.field("name")).isEqualTo("Luke Skywalker");
    assertThat(lukeRecord.field("height({\"unit\":\"METER\"})")).isEqualTo(BigDecimal.valueOf(1.72));
    final List<Object> friends = (List<Object>) normalizedCache.loadRecord(TEST_FIELD_KEY_JEDI, CacheHeaders.NONE).field("friends");
    assertThat(friends.get(0)).isEqualTo(new CacheReference(TEST_FIELD_KEY_JEDI + ".friends.0"));
    assertThat(friends.get(1)).isEqualTo(new CacheReference(TEST_FIELD_KEY_JEDI + ".friends.1"));
    assertThat(friends.get(2)).isEqualTo(new CacheReference(TEST_FIELD_KEY_JEDI + ".friends.2"));
}
Also used : HeroParentTypeDependentFieldQuery(com.apollographql.apollo.integration.normalizer.HeroParentTypeDependentFieldQuery) Record(com.apollographql.apollo.cache.normalized.Record) List(java.util.List) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) Test(org.junit.Test)

Example 13 with CacheReference

use of com.apollographql.apollo.cache.normalized.CacheReference in project apollo-android by apollographql.

the class ResponseNormalizationTest method testHeroAppearsInQuery.

@Test
public void testHeroAppearsInQuery() throws Exception {
    assertHasNoErrors("HeroAppearsInResponse.json", new HeroAppearsInQuery());
    Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
    CacheReference heroReference = (CacheReference) record.field("hero");
    assertThat(heroReference).isEqualTo(new CacheReference("hero"));
    final Record hero = normalizedCache.loadRecord(heroReference.key(), CacheHeaders.NONE);
    assertThat(hero.field("appearsIn")).isEqualTo(Arrays.asList("NEWHOPE", "EMPIRE", "JEDI"));
}
Also used : HeroAppearsInQuery(com.apollographql.apollo.integration.normalizer.HeroAppearsInQuery) Record(com.apollographql.apollo.cache.normalized.Record) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) Test(org.junit.Test)

Example 14 with CacheReference

use of com.apollographql.apollo.cache.normalized.CacheReference 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");
}
Also used : Record(com.apollographql.apollo.cache.normalized.Record) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) EpisodeHeroNameQuery(com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery) HeroNameQuery(com.apollographql.apollo.integration.normalizer.HeroNameQuery) Test(org.junit.Test)

Example 15 with CacheReference

use of com.apollographql.apollo.cache.normalized.CacheReference in project apollo-android by apollographql.

the class RecordWeigherTest method testRecordWeigher.

@Test
public void testRecordWeigher() {
    Record.Builder recordBuilder = Record.builder("root");
    BigDecimal expectedBigDecimal = new BigDecimal(1.23);
    String expectedStringValue = "StringValue";
    Boolean expectedBooleanValue = true;
    CacheReference expectedCacheReference = new CacheReference("foo");
    List<CacheReference> expectedCacheReferenceList = Arrays.asList(new CacheReference("bar"), new CacheReference("baz"));
    List<Object> expectedScalarList = Arrays.<Object>asList("scalarOne", "scalarTwo");
    recordBuilder.addField("bigDecimal", expectedBigDecimal);
    recordBuilder.addField("string", expectedStringValue);
    recordBuilder.addField("boolean", expectedBooleanValue);
    recordBuilder.addField("cacheReference", expectedCacheReference);
    recordBuilder.addField("scalarList", expectedScalarList);
    recordBuilder.addField("referenceList", expectedCacheReferenceList);
    Record record = recordBuilder.build();
    record.sizeEstimateBytes();
    // It's difficult to say what the "right" size estimate is, so just checking it is has been calculate at all.
    assertThat(record.sizeEstimateBytes()).isNotEqualTo(-1);
}
Also used : Record(com.apollographql.apollo.cache.normalized.Record) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

CacheReference (com.apollographql.apollo.cache.normalized.CacheReference)15 Record (com.apollographql.apollo.cache.normalized.Record)15 Test (org.junit.Test)12 HeroTypeDependentAliasedFieldQuery (com.apollographql.apollo.integration.normalizer.HeroTypeDependentAliasedFieldQuery)3 EpisodeHeroNameQuery (com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery)2 List (java.util.List)2 CacheKey (com.apollographql.apollo.cache.normalized.CacheKey)1 HeroAndFriendsNamesQuery (com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesQuery)1 HeroAndFriendsNamesWithIDForParentOnlyQuery (com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDForParentOnlyQuery)1 HeroAndFriendsNamesWithIDsQuery (com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery)1 HeroAppearsInQuery (com.apollographql.apollo.integration.normalizer.HeroAppearsInQuery)1 HeroNameQuery (com.apollographql.apollo.integration.normalizer.HeroNameQuery)1 HeroParentTypeDependentFieldQuery (com.apollographql.apollo.integration.normalizer.HeroParentTypeDependentFieldQuery)1 SameHeroTwiceQuery (com.apollographql.apollo.integration.normalizer.SameHeroTwiceQuery)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1