Search in sources :

Example 1 with OperationJsonWriter

use of com.apollographql.apollo.response.OperationJsonWriter in project apollo-android by apollographql.

the class IntegrationTest method operationJsonWriter.

@Test
public void operationJsonWriter() throws Exception {
    String json = Utils.readFileToString(getClass(), "/OperationJsonWriter.json");
    AllPlanetsQuery query = new AllPlanetsQuery();
    Response<AllPlanetsQuery.Data> response = new OperationResponseParser<>(query, query.responseFieldMapper(), new ScalarTypeAdapters(Collections.EMPTY_MAP)).parse(new Buffer().writeUtf8(json));
    Buffer buffer = new Buffer();
    OperationJsonWriter writer = new OperationJsonWriter(response.data(), new ScalarTypeAdapters(Collections.EMPTY_MAP));
    JsonWriter jsonWriter = JsonWriter.of(buffer);
    jsonWriter.setIndent("  ");
    writer.write(jsonWriter);
    assertThat(buffer.readUtf8()).isEqualTo(json);
}
Also used : Buffer(okio.Buffer) OperationJsonWriter(com.apollographql.apollo.response.OperationJsonWriter) ScalarTypeAdapters(com.apollographql.apollo.response.ScalarTypeAdapters) AllPlanetsQuery(com.apollographql.apollo.integration.httpcache.AllPlanetsQuery) OperationJsonWriter(com.apollographql.apollo.response.OperationJsonWriter) JsonWriter(com.apollographql.apollo.internal.json.JsonWriter) Test(org.junit.Test)

Aggregations

AllPlanetsQuery (com.apollographql.apollo.integration.httpcache.AllPlanetsQuery)1 JsonWriter (com.apollographql.apollo.internal.json.JsonWriter)1 OperationJsonWriter (com.apollographql.apollo.response.OperationJsonWriter)1 ScalarTypeAdapters (com.apollographql.apollo.response.ScalarTypeAdapters)1 Buffer (okio.Buffer)1 Test (org.junit.Test)1