Search in sources :

Example 6 with Response

use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.

the class DynamicClientFormatAnnotationsTest method testParsingDateWithJsonbFormatAnnotation.

/**
 * Test parsing a date formatted using a @JsonbDateFormat annotation
 */
@Test
public void testParsingDateWithJsonbFormatAnnotation() throws ExecutionException, InterruptedException {
    Document document = document(operation(field("something", field("dateWithJsonbAnnotation"))));
    Response response = client.executeSync(document);
    ObjectWithFormattedFields objectWithFormattedFields = response.getObject(ObjectWithFormattedFields.class, "something");
    Date parsedDate = objectWithFormattedFields.getDateWithJsonbAnnotation();
    Calendar calendar = toCalendar(parsedDate);
    assertEquals(Calendar.MAY, calendar.get(Calendar.MONTH));
    assertEquals(13, calendar.get(Calendar.DAY_OF_MONTH));
    assertEquals(1997, calendar.get(Calendar.YEAR));
}
Also used : Response(io.smallrye.graphql.client.Response) Calendar(java.util.Calendar) Document(io.smallrye.graphql.client.core.Document) Date(java.util.Date) Test(org.junit.Test)

Example 7 with Response

use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.

the class DynamicClientFormatAnnotationsTest method testParsingLongWithCustomFormat.

/**
 * Test parsing a long formatted using a @NumberFormat annotation
 */
@Test
public void testParsingLongWithCustomFormat() throws ExecutionException, InterruptedException {
    Document document = document(operation(field("something", field("longNumber"))));
    Response response = client.executeSync(document);
    ObjectWithFormattedFields objectWithFormattedFields = response.getObject(ObjectWithFormattedFields.class, "something");
    Long parsedNumber = objectWithFormattedFields.getLongNumber();
    assertEquals((Long) 123456789L, parsedNumber);
}
Also used : Response(io.smallrye.graphql.client.Response) Document(io.smallrye.graphql.client.core.Document) Test(org.junit.Test)

Example 8 with Response

use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.

the class DynamicClientFormatAnnotationsTest method testParsingDoubleWithCustomFormat.

/**
 * Test parsing a double formatted using a @NumberFormat annotation
 */
@Test
public void testParsingDoubleWithCustomFormat() throws ExecutionException, InterruptedException {
    Document document = document(operation(field("something", field("doubleNumber"))));
    Response response = client.executeSync(document);
    assertEquals("Sanity check failed: the server did not return the number in the desired custom format", "12.345.678,9", response.getData().getJsonObject("something").getString("doubleNumber"));
    ObjectWithFormattedFields objectWithFormattedFields = response.getObject(ObjectWithFormattedFields.class, "something");
    Double parsedNumber = objectWithFormattedFields.getDoubleNumber();
    assertEquals(12345678.9, parsedNumber, 0.00001);
}
Also used : Response(io.smallrye.graphql.client.Response) Document(io.smallrye.graphql.client.core.Document) Test(org.junit.Test)

Example 9 with Response

use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.

the class DynamicClientFormatAnnotationsTest method testParsingDateWithCustomFormat.

/**
 * Test parsing a date formatted using a @DateFormat annotation
 */
@Test
public void testParsingDateWithCustomFormat() throws ExecutionException, InterruptedException {
    Document document = document(operation(field("something", field("date"))));
    Response response = client.executeSync(document);
    // a sanity check to make sure that the server really returned the custom format
    // because if not, then this test would not be actually verifying anything
    assertEquals("Sanity check failed: the server did not return the date in the desired custom format", "May 1997 13 04,20,03 May Tue", response.getData().getJsonObject("something").getString("date"));
    ObjectWithFormattedFields objectWithFormattedFields = response.getObject(ObjectWithFormattedFields.class, "something");
    Date parsedDate = objectWithFormattedFields.getDate();
    Calendar calendar = toCalendar(parsedDate);
    assertEquals(Calendar.MAY, calendar.get(Calendar.MONTH));
    assertEquals(13, calendar.get(Calendar.DAY_OF_MONTH));
    assertEquals(1997, calendar.get(Calendar.YEAR));
}
Also used : Response(io.smallrye.graphql.client.Response) Calendar(java.util.Calendar) Document(io.smallrye.graphql.client.core.Document) Date(java.util.Date) Test(org.junit.Test)

Example 10 with Response

use of io.smallrye.graphql.client.Response in project quarkus-quickstarts by quarkusio.

the class StarWarsResource method getAllFilmsUsingDynamicClient.

@GET
@Path("/dynamic")
@Produces(MediaType.APPLICATION_JSON)
@Blocking
public List<Film> getAllFilmsUsingDynamicClient() throws Exception {
    Document query = document(operation(field("allFilms", field("films", field("title"), field("planetConnection", field("planets", field("name")))))));
    Response response = dynamicClient.executeSync(query);
    // translate it into an instance of the corresponding model class
    return response.getObject(FilmConnection.class, "allFilms").getFilms();
}
Also used : Response(io.smallrye.graphql.client.Response) FilmConnection(org.acme.microprofile.graphql.client.model.FilmConnection) Document(io.smallrye.graphql.client.core.Document) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Blocking(io.smallrye.common.annotation.Blocking)

Aggregations

Response (io.smallrye.graphql.client.Response)17 Test (org.junit.Test)13 Document (io.smallrye.graphql.client.core.Document)11 DynamicGraphQLClient (io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient)4 VertxDynamicGraphQLClientBuilder (io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder)4 Calendar (java.util.Calendar)2 Date (java.util.Date)2 SuperHero (examples.typesafeclient.SuperHero)1 Blocking (io.smallrye.common.annotation.Blocking)1 GraphQLClientException (io.smallrye.graphql.client.GraphQLClientException)1 ResponseImpl (io.smallrye.graphql.client.impl.ResponseImpl)1 HttpServer (io.vertx.core.http.HttpServer)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 JsonArray (javax.json.JsonArray)1 JsonObject (javax.json.JsonObject)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1