Search in sources :

Example 1 with StarshipByIdQuery

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

the class ResponseWriteTestCase method listOfList.

@Test
public void listOfList() throws Exception {
    StarshipByIdQuery query = new StarshipByIdQuery("Starship1");
    enqueueAndAssertResponse(server, "StarshipByIdResponse.json", apolloClient.query(query), new Predicate<Response<StarshipByIdQuery.Data>>() {

        @Override
        public boolean test(Response<StarshipByIdQuery.Data> response) throws Exception {
            assertThat(response.data().starship().__typename()).isEqualTo("Starship");
            assertThat(response.data().starship().name()).isEqualTo("SuperRocket");
            assertThat(response.data().starship().coordinates()).hasSize(3);
            assertThat(response.data().starship().coordinates()).containsExactly(asList(100d, 200d), asList(300d, 400d), asList(500d, 600d));
            return true;
        }
    });
    StarshipByIdQuery.Starship starship = new StarshipByIdQuery.Starship("Starship", "Starship1", "SuperRocket", asList(asList(900d, 800d), asList(700d, 600d)));
    apolloClient.apolloStore().write(query, new StarshipByIdQuery.Data(starship)).execute();
    assertCachedQueryResponse(query, new Predicate<Response<StarshipByIdQuery.Data>>() {

        @Override
        public boolean test(Response<StarshipByIdQuery.Data> response) throws Exception {
            assertThat(response.data().starship().__typename()).isEqualTo("Starship");
            assertThat(response.data().starship().name()).isEqualTo("SuperRocket");
            assertThat(response.data().starship().coordinates()).hasSize(2);
            assertThat(response.data().starship().coordinates()).containsExactly(asList(900d, 800d), asList(700d, 600d));
            return true;
        }
    });
}
Also used : Utils.enqueueAndAssertResponse(com.apollographql.apollo.Utils.enqueueAndAssertResponse) Utils.assertResponse(com.apollographql.apollo.Utils.assertResponse) Response(com.apollographql.apollo.api.Response) StarshipByIdQuery(com.apollographql.apollo.integration.normalizer.StarshipByIdQuery) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 2 with StarshipByIdQuery

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

the class NormalizedCacheTestCase method listOfList.

@Test
public void listOfList() throws Exception {
    enqueueAndAssertResponse(server, "StarshipByIdResponse.json", apolloClient.query(new StarshipByIdQuery("Starship1")), new Predicate<Response<StarshipByIdQuery.Data>>() {

        @Override
        public boolean test(Response<StarshipByIdQuery.Data> response) throws Exception {
            assertThat(response.data().starship().__typename()).isEqualTo("Starship");
            assertThat(response.data().starship().name()).isEqualTo("SuperRocket");
            assertThat(response.data().starship().coordinates()).hasSize(3);
            assertThat(response.data().starship().coordinates()).containsExactly(asList(100d, 200d), asList(300d, 400d), asList(500d, 600d));
            return true;
        }
    });
    assertResponse(apolloClient.query(new StarshipByIdQuery("Starship1")).responseFetcher(CACHE_ONLY), new Predicate<Response<StarshipByIdQuery.Data>>() {

        @Override
        public boolean test(Response<StarshipByIdQuery.Data> response) throws Exception {
            assertThat(response.data().starship().__typename()).isEqualTo("Starship");
            assertThat(response.data().starship().name()).isEqualTo("SuperRocket");
            assertThat(response.data().starship().coordinates()).hasSize(3);
            assertThat(response.data().starship().coordinates()).containsExactly(asList(100d, 200d), asList(300d, 400d), asList(500d, 600d));
            return true;
        }
    });
}
Also used : Utils.mockResponse(com.apollographql.apollo.Utils.mockResponse) Utils.enqueueAndAssertResponse(com.apollographql.apollo.Utils.enqueueAndAssertResponse) Utils.cacheAndAssertCachedResponse(com.apollographql.apollo.Utils.cacheAndAssertCachedResponse) Utils.assertResponse(com.apollographql.apollo.Utils.assertResponse) Response(com.apollographql.apollo.api.Response) StarshipByIdQuery(com.apollographql.apollo.integration.normalizer.StarshipByIdQuery) Test(org.junit.Test)

Aggregations

Utils.assertResponse (com.apollographql.apollo.Utils.assertResponse)2 Utils.enqueueAndAssertResponse (com.apollographql.apollo.Utils.enqueueAndAssertResponse)2 Response (com.apollographql.apollo.api.Response)2 StarshipByIdQuery (com.apollographql.apollo.integration.normalizer.StarshipByIdQuery)2 Test (org.junit.Test)2 Utils.cacheAndAssertCachedResponse (com.apollographql.apollo.Utils.cacheAndAssertCachedResponse)1 Utils.mockResponse (com.apollographql.apollo.Utils.mockResponse)1 ParseException (java.text.ParseException)1