use of io.smallrye.graphql.client.core.Document 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);
}
use of io.smallrye.graphql.client.core.Document 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));
}
use of io.smallrye.graphql.client.core.Document in project smallrye-graphql by smallrye.
the class EnumsTest method invalidValue.
@Test
public void invalidValue() {
try {
Document document = document(operation(QUERY, field("exams", args(arg("result", gqlEnum("wrong { }"))), field("score"))));
fail("Invalid enum value should not be accepted");
} catch (BuildException be) {
// OK
}
}
use of io.smallrye.graphql.client.core.Document in project smallrye-graphql by smallrye.
the class FieldsTest method fieldsTest.
@Test
public void fieldsTest() throws IOException, URISyntaxException {
String expectedRequest = Utils.getResourceFileContent("core/fields.graphql");
Document document = document(operation(QUERY, field("noArgNoSubField"), field("noArgWithSubField", field("bool"), field("string"), field("double")), field("withArgNoSubField", arg("anInt", 42)), field("withArgWithSubField", args(arg("aString", "world"), arg("aDouble", 78.12d), arg("aBool", false)), field("bool"), field("string"), field("double"))));
String generatedRequest = document.build();
AssertGraphQL.assertEquivalentGraphQLRequest(expectedRequest, generatedRequest);
}
use of io.smallrye.graphql.client.core.Document in project smallrye-graphql by smallrye.
the class VariablesTest method variablesArraysTest.
@Test
public void variablesArraysTest() throws IOException, URISyntaxException {
String expectedRequest = Utils.getResourceFileContent("core/variablesArrays.graphql");
Variable varInt1 = var("varInt_1", list(GQL_INT));
Variable varInt1bang = var("varInt_1_bang", nonNull(list(GQL_INT)));
Variable varIntbang1 = var("varInt_bang_1", list(nonNull(GQL_INT)));
Variable varInt12 = var("varInt_1_2", list(list(GQL_INT)));
Variable varInt123 = var("varInt_1_2_3", list(list(list(GQL_INT))));
Variable varInt1bang23bang = var("varInt_1_bang_2_3_bang", nonNull(list(list(nonNull(list(GQL_INT))))));
Variable varIntbang1bang2bang3bang = var("varInt_bang_1_bang_2_bang_3_bang", nonNull(list(nonNull(list(nonNull(list(nonNull(GQL_INT))))))));
/*
* To use for e2e tests
* {
* "varInt_1": [12, 34, 567, 89],
* "varInt_1_2": null,
* "varInt_1_2_3": [[[1, null], [3, 4]], null, [[7], null]],
* "varInt_1_bang": [null],
* "varInt_bang_1": null,
* "varInt_1_bang_2_3_bang": [[[null, 2], [null, 4]], [[5, 6]], null],
* "varInt_bang_1_bang_2_bang_3_bang": [[[1, 2], [3, 4]], [[5, 6], [7], [8, 9]]]
* }
*/
Document document = document(operation(MUTATION, vars(varInt1, varInt12, varInt123, varInt1bang, varIntbang1, varInt1bang23bang, varIntbang1bang2bang3bang), field("nestedArraysHolder", args(arg("nestedArraysHolder", inputObject(prop("int_1", varInt1), prop("int_1_2", varInt12), prop("int_1_2_3", varInt123), prop("int_1_bang", varInt1bang), prop("int_bang_1", varIntbang1), prop("int_1_bang_2_3_bang", varInt1bang23bang), prop("int_bang_1_bang_2_bang_3_bang", varIntbang1bang2bang3bang)))), field("int_1"), field("int_1_2"), field("int_1_2_3"), field("int_1_bang"), field("int_1_bang_2_3_bang"), field("int_bang_1"), field("int_bang_1_bang_2_bang_3_bang"))));
String generatedRequest = document.build();
AssertGraphQL.assertEquivalentGraphQLRequest(expectedRequest, generatedRequest);
}
Aggregations