Search in sources :

Example 11 with ResponseImpl

use of io.smallrye.graphql.client.impl.ResponseImpl in project smallrye-graphql by smallrye.

the class ResponseReaderTest method testScalarsList.

@Test
public void testScalarsList() {
    ResponseImpl response = ResponseReader.readFrom(EXAMPLE_RESPONSE_SCALARS_LIST, null);
    assertEquals("hello", response.getList(String.class, "strings").get(0));
    assertEquals("bye", response.getList(String.class, "strings").get(1));
    assertEquals(32, response.getList(Long.class, "numbers").get(0));
    assertEquals(33, response.getList(Long.class, "numbers").get(1));
}
Also used : ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) Test(org.junit.jupiter.api.Test)

Example 12 with ResponseImpl

use of io.smallrye.graphql.client.impl.ResponseImpl in project smallrye-graphql by smallrye.

the class ResponseReaderTest method verifyErrors.

@Test
public void verifyErrors() {
    String responseString = "{\"errors\":[{\"message\":\"blabla\"," + "\"path\": [1, 2, 3, \"asd\"]," + "\"locations\": [{\"line\":1,\"column\":30}]," + "\"somethingExtra\": 123456," + "\"extensions\": {" + "\"exception\":\"EXCEPTION_EXT\"," + "\"classification\":\"CLASSIFICATION_EXT\"," + "\"code\":\"CODE_EXT\"," + "\"description\":\"DESCRIPTION_EXT\"," + "\"validationErrorType\":\"VALIDATION_ERROR_TYPE_EXT\"," + "\"queryPath\":\"QUERYPATH_EXT\"" + "}}]}";
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("Cookie", Collections.singletonList("myCookie"));
    ResponseImpl response = ResponseReader.readFrom(responseString, headers);
    GraphQLError theError = response.getErrors().get(0);
    assertEquals("blabla", theError.getMessage());
    assertEquals(123456L, theError.getOtherFields().get("somethingExtra"));
    assertEquals("EXCEPTION_EXT", theError.getException());
    assertEquals("CLASSIFICATION_EXT", theError.getClassification());
    assertEquals("CODE_EXT", theError.getCode());
    assertEquals("DESCRIPTION_EXT", theError.getDescription());
    assertEquals("VALIDATION_ERROR_TYPE_EXT", theError.getValidationErrorType());
    assertEquals("QUERYPATH_EXT", theError.getQueryPath());
    assertEquals(1, theError.getLocations().get(0).get("line"));
    assertEquals(30, theError.getLocations().get(0).get("column"));
    assertArrayEquals(new Object[] { 1, 2, 3, "asd" }, theError.getPath());
    assertEquals(response.getHeaders().get("Cookie").get(0), "myCookie");
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) Test(org.junit.jupiter.api.Test)

Example 13 with ResponseImpl

use of io.smallrye.graphql.client.impl.ResponseImpl in project smallrye-graphql by smallrye.

the class ResponseReaderTest method testScalars.

@Test
public void testScalars() {
    ResponseImpl response = ResponseReader.readFrom(EXAMPLE_RESPONSE_SCALARS, null);
    assertEquals("hello", response.getObject(String.class, "string"));
    assertEquals(32, response.getObject(Long.class, "number"));
}
Also used : ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) Test(org.junit.jupiter.api.Test)

Example 14 with ResponseImpl

use of io.smallrye.graphql.client.impl.ResponseImpl in project smallrye-graphql by smallrye.

the class DynamicClientErrorTest method convertToGraphQLClientException.

/**
 * Test the `ResponseImpl.throwExceptionIfErrors` method that should throw a `GraphQLClientException` if the Response
 * contains any errors.
 */
@Test
public void convertToGraphQLClientException() throws ExecutionException, InterruptedException {
    Response response = client.executeSync(document(operation(field("dummy", field("foo"), field("bar")))));
    try {
        ((ResponseImpl) response).throwExceptionIfErrors();
        fail("`throwExceptionIfErrors` call should throw a GraphQLClientException");
    } catch (GraphQLClientException e) {
        assertArrayEquals(new Object[] { "dummy", "bar" }, e.getErrors().get(0).getPath());
    }
}
Also used : Response(io.smallrye.graphql.client.Response) GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) Test(org.junit.Test)

Aggregations

ResponseImpl (io.smallrye.graphql.client.impl.ResponseImpl)14 Test (org.junit.jupiter.api.Test)13 NoSuchElementException (java.util.NoSuchElementException)4 GraphQLClientException (io.smallrye.graphql.client.GraphQLClientException)1 Response (io.smallrye.graphql.client.Response)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Test (org.junit.Test)1