Search in sources :

Example 6 with ResponseImpl

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

the class ResponseReaderTest method testGetObjectWrongField.

@Test
public void testGetObjectWrongField() {
    ResponseImpl response = ResponseReader.readFrom(EXAMPLE_RESPONSE_ONE_ITEM, null);
    try {
        response.getObject(Person.class, "WRONG_FIELD");
        fail("Expected an exception");
    } catch (NoSuchElementException e) {
        assertTrue(e.getMessage().contains("people"), "Exception should tell what fields are available in the response");
    }
}
Also used : ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.jupiter.api.Test)

Example 7 with ResponseImpl

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

the class ResponseReaderTest method testGetListWrongField.

@Test
public void testGetListWrongField() {
    ResponseImpl response = ResponseReader.readFrom(EXAMPLE_RESPONSE_TWO_ITEMS, null);
    try {
        response.getList(Person.class, "WRONG_FIELD");
        fail("Expected an exception");
    } catch (NoSuchElementException e) {
        assertTrue(e.getMessage().contains("people"), "Exception should tell what fields are available in the response");
    }
}
Also used : ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.jupiter.api.Test)

Example 8 with ResponseImpl

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

the class ResponseReaderTest method nullPathInError.

@Test
public void nullPathInError() {
    String responseString = "{\"errors\":[{\"message\":\"blabla\"," + "\"path\": null}]}";
    ResponseImpl response = ResponseReader.readFrom(responseString, Collections.emptyMap());
    assertNull(response.getErrors().get(0).getPath());
}
Also used : ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) Test(org.junit.jupiter.api.Test)

Example 9 with ResponseImpl

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

the class ResponseReaderTest method testGetObjectWhenDataIsNull.

@Test
public void testGetObjectWhenDataIsNull() {
    ResponseImpl response = ResponseReader.readFrom(EXAMPLE_RESPONSE_NULL_DATA, null);
    assertNull(response.getObject(Person.class, "people"));
}
Also used : ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) Test(org.junit.jupiter.api.Test)

Example 10 with ResponseImpl

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

the class ResponseReaderTest method testGetList.

@Test
public void testGetList() {
    ResponseImpl response = ResponseReader.readFrom(EXAMPLE_RESPONSE_TWO_ITEMS, null);
    List<Person> list = response.getList(Person.class, "people");
    assertEquals(2, list.size());
}
Also used : ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) Test(org.junit.jupiter.api.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