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