Search in sources :

Example 1 with ResponseImpl

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

the class ResponseReaderTest method testGetObjectWhenResponseContainsList.

@Test
public void testGetObjectWhenResponseContainsList() {
    ResponseImpl response = ResponseReader.readFrom(EXAMPLE_RESPONSE_TWO_ITEMS, null);
    try {
        response.getObject(Person.class, "people");
        fail("Exception expected");
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("SRGQLDC035007"));
    }
}
Also used : ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.jupiter.api.Test)

Example 2 with ResponseImpl

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

the class ResponseReaderTest method nullResponse.

@Test
public void nullResponse() {
    ResponseImpl response;
    try {
        response = ResponseReader.readFrom(null, Collections.emptyMap());
        Assertions.fail();
    } catch (InvalidResponseException ire) {
        Assertions.assertTrue(ire.getMessage().contains("Response body was null"));
    }
}
Also used : ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) Test(org.junit.jupiter.api.Test)

Example 3 with ResponseImpl

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

the class ResponseReaderTest method testGetListWhenResponseContainsObject.

@Test
public void testGetListWhenResponseContainsObject() {
    ResponseImpl response = ResponseReader.readFrom(EXAMPLE_RESPONSE_ONE_ITEM, null);
    try {
        response.getList(Person.class, "people");
        fail("Exception expected");
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("SRGQLDC035006"));
    }
}
Also used : ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.jupiter.api.Test)

Example 4 with ResponseImpl

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

the class ResponseReaderTest method testGetListWhenDataIsNull.

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

Example 5 with ResponseImpl

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

the class ResponseReaderTest method testGetObject.

@Test
public void testGetObject() {
    ResponseImpl response = ResponseReader.readFrom(EXAMPLE_RESPONSE_ONE_ITEM, null);
    Person person = response.getObject(Person.class, "people");
    assertEquals("jane", person.getName());
    assertEquals(Gender.FEMALE, person.getGender());
}
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