-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw exception on unknown input to prevent invalid json
- Loading branch information
1 parent
07bf7dd
commit 3934c2c
Showing
6 changed files
with
230 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...entation/src/test/java/io/smallrye/graphql/client/impl/core/utils/ValueFormatterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.smallrye.graphql.client.impl.core.utils; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class ValueFormatterTest { | ||
|
||
@Test | ||
public void testUnsupportedInput() { | ||
|
||
assertThrows(IllegalStateException.class, () -> { | ||
ValueFormatter.format(new Object()); | ||
}); | ||
|
||
assertThrows(IllegalStateException.class, () -> { | ||
ValueFormatter.format(Map.of("test", "value")); | ||
}); | ||
|
||
assertThrows(IllegalStateException.class, () -> { | ||
ValueFormatter.format(new Date()); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
client/tck/src/main/java/tck/graphql/dynamic/core/IterableTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package tck.graphql.dynamic.core; | ||
|
||
import io.smallrye.graphql.client.core.Document; | ||
import org.junit.jupiter.api.Test; | ||
import tck.graphql.dynamic.helper.AssertGraphQL; | ||
import tck.graphql.dynamic.helper.Utils; | ||
|
||
import java.io.IOException; | ||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.net.URISyntaxException; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
import static io.smallrye.graphql.client.core.Argument.arg; | ||
import static io.smallrye.graphql.client.core.Argument.args; | ||
import static io.smallrye.graphql.client.core.Document.document; | ||
import static io.smallrye.graphql.client.core.Field.field; | ||
import static io.smallrye.graphql.client.core.InputObject.inputObject; | ||
import static io.smallrye.graphql.client.core.InputObjectField.prop; | ||
import static io.smallrye.graphql.client.core.Operation.operation; | ||
import static io.smallrye.graphql.client.core.OperationType.QUERY; | ||
|
||
public class IterableTest { | ||
|
||
@Test | ||
public void iterableTest() throws IOException, URISyntaxException { | ||
String expectedRequest = Utils.getResourceFileContent("core/iterable.graphql"); | ||
|
||
Document document = document( | ||
operation(QUERY, "iterableHolderQuery", | ||
field("iterableHolder", | ||
args( | ||
arg("iterableHolder", inputObject( | ||
|
||
prop("boolObjectList", List.of(true, false)), | ||
|
||
prop("byteObjectList", List.of( (byte)0, (byte)2, (byte)3)), | ||
|
||
prop("shortObjectList", List.of( (short)78,(short) 789,(short) 645 )), | ||
|
||
prop("intObjectList", List.of( 78, 65, 12354 )), | ||
|
||
prop("longObjectList", List.of( 789L, 947894L, 1874448L )), | ||
|
||
prop("floatObjectList", List.of( 1567.654f, 8765f, 123789456.1851f )), | ||
|
||
prop("doubleObjectList", List.of( 789.3242d, 1815d, 98765421.654897d )), | ||
|
||
prop("bigIntegerList", | ||
List.of( BigInteger.ZERO, BigInteger.ONE, BigInteger.TEN )), | ||
|
||
prop("bigDecimalList", | ||
List.of( BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN )), | ||
|
||
prop("charObjectList", List.of( 'f', 'o', 'o' )), | ||
|
||
prop("stringList", List.of( "foo", "bar", "baz" )), | ||
|
||
prop("uuidList", | ||
List.of(UUID.fromString("fc4bb4f4-13fe-4908-8d6a-afa64f1b56c9"), | ||
UUID.fromString("863c9e3c-7538-41b9-9d63-0852f6a50815"))) | ||
|
||
))), | ||
field("boolObjectList"), | ||
|
||
field("byteObjectList"), | ||
|
||
field("shortObjectList"), | ||
|
||
field("intObjectList"), | ||
|
||
field("longObjectList"), | ||
|
||
field("floatObjectList"), | ||
|
||
field("doubleObjectList"), | ||
|
||
field("bigIntegerList"), | ||
|
||
field("bigDecimalList"), | ||
|
||
field("charObjectList"), | ||
|
||
field("stringList"), | ||
|
||
field("uuidList") | ||
))); | ||
|
||
String generatedRequest = document.build(); | ||
AssertGraphQL.assertEquivalentGraphQLRequest(expectedRequest, generatedRequest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
query iterableHolderQuery { | ||
iterableHolder(iterableHolder:{ | ||
|
||
boolObjectList: [true, false] | ||
|
||
byteObjectList: [0, 2, 3] | ||
|
||
shortObjectList: [78, 789, 645] | ||
|
||
intObjectList: [78, 65, 12354] | ||
|
||
longObjectList: [789, 947894, 1874448] | ||
|
||
floatObjectList: [1567.654, 8765.0, 1.23789456E8] | ||
|
||
doubleObjectList: [789.3242, 1815.0, 9.8765421654897E7] | ||
|
||
bigIntegerList: [0, 1, 10] | ||
|
||
bigDecimalList: [0, 1, 10] | ||
|
||
charObjectList: ["f", "o", "o"] | ||
|
||
stringList: ["foo", "bar", "baz"] | ||
|
||
uuidList: ["fc4bb4f4-13fe-4908-8d6a-afa64f1b56c9", "863c9e3c-7538-41b9-9d63-0852f6a50815"] | ||
|
||
}) { | ||
boolObjectList | ||
|
||
byteObjectList | ||
|
||
shortObjectList | ||
|
||
intObjectList | ||
|
||
longObjectList | ||
|
||
floatObjectList | ||
|
||
doubleObjectList | ||
|
||
bigIntegerList | ||
|
||
bigDecimalList | ||
|
||
charObjectList | ||
|
||
stringList | ||
|
||
uuidList | ||
} | ||
} |