From 3615e325e7d92e1743bdba4523748fe6b2b1bb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Marti=C5=A1ka?= Date: Mon, 13 Sep 2021 12:09:28 +0200 Subject: [PATCH] Module with JDK16 tests --- .github/workflows/build.yml | 2 +- .../graphql/client/dynamic/ErrorImpl.java | 2 +- pom.xml | 16 ++ power-annotations/tck/pom.xml | 2 + server/integration-tests-jdk16/pom.xml | 221 ++++++++++++++++++ .../SmallRyeGraphQLArchiveProcessor.java | 39 ++++ .../tests/SmallRyeGraphQLExtension.java | 17 ++ ...boss.arquillian.core.spi.LoadableExtension | 1 + .../RecordAsInputToDynamicClientTest.java | 97 ++++++++ .../RecordAsInputToTypesafeClientTest.java | 67 ++++++ server/pom.xml | 2 +- server/runner/pom.xml | 12 +- tools/gradle-plugin/pom.xml | 1 - 13 files changed, 474 insertions(+), 5 deletions(-) create mode 100644 server/integration-tests-jdk16/pom.xml create mode 100644 server/integration-tests-jdk16/src/main/java/io/smallrye/graphql/tests/SmallRyeGraphQLArchiveProcessor.java create mode 100644 server/integration-tests-jdk16/src/main/java/io/smallrye/graphql/tests/SmallRyeGraphQLExtension.java create mode 100644 server/integration-tests-jdk16/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension create mode 100644 server/integration-tests-jdk16/src/test/java/io/smallrye/graphql/tests/client/RecordAsInputToDynamicClientTest.java create mode 100644 server/integration-tests-jdk16/src/test/java/io/smallrye/graphql/tests/client/RecordAsInputToTypesafeClientTest.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 554b6a72e..8e5fac952 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [8, 11] + java: [8, 11, 16] name: build with jdk ${{matrix.java}} steps: diff --git a/client/implementation/src/main/java/io/smallrye/graphql/client/dynamic/ErrorImpl.java b/client/implementation/src/main/java/io/smallrye/graphql/client/dynamic/ErrorImpl.java index 9d12501b8..88788b06c 100644 --- a/client/implementation/src/main/java/io/smallrye/graphql/client/dynamic/ErrorImpl.java +++ b/client/implementation/src/main/java/io/smallrye/graphql/client/dynamic/ErrorImpl.java @@ -70,7 +70,7 @@ public void setOtherFields(Map otherFields) { @Override public String toString() { - String other = otherFields.isEmpty() ? "" : ", otherFields=" + otherFields; + String other = (otherFields == null || otherFields.isEmpty()) ? "" : ", otherFields=" + otherFields; return "GraphQLError{message=" + message + ", locations=" + locations + ", path=" + Arrays.toString(path) + diff --git a/pom.xml b/pom.xml index b4c04988e..ed1ea2cf6 100644 --- a/pom.xml +++ b/pom.xml @@ -411,5 +411,21 @@ + + jdk16plus + + [16,) + + + server/integration-tests-jdk16 + + + + --add-opens java.base/java.util=ALL-UNNAMED + + true + + diff --git a/power-annotations/tck/pom.xml b/power-annotations/tck/pom.xml index 2cf9945b7..ed63dd580 100644 --- a/power-annotations/tck/pom.xml +++ b/power-annotations/tck/pom.xml @@ -52,6 +52,8 @@ maven-surefire-plugin !InheritedAnnotationsTestSuite & !TypeToMemberAnnotationsTestSuite + + ${powerannotations.tck.argLine} diff --git a/server/integration-tests-jdk16/pom.xml b/server/integration-tests-jdk16/pom.xml new file mode 100644 index 000000000..16854f66f --- /dev/null +++ b/server/integration-tests-jdk16/pom.xml @@ -0,0 +1,221 @@ + + + + smallrye-graphql-server-parent + io.smallrye + 1.3.4-SNAPSHOT + + 4.0.0 + + smallrye-graphql-integration-tests-jdk16 + SmallRye: GraphQL Server :: Integration Tests :: Java 16+ tests + + + 16 + 16 + UTF-8 + + + + + org.jboss.arquillian.container + arquillian-container-test-spi + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + + + + + org.junit.vintage + junit-vintage-engine + test + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.assertj + assertj-core + test + + + io.rest-assured + rest-assured + test + + + + + io.smallrye + smallrye-graphql-client-implementation-vertx + test + + + + + + + + + + + org.jboss.arquillian.container + arquillian-jetty-embedded-9 + test + + + org.eclipse.jetty + jetty-webapp + test + + + org.eclipse.jetty + jetty-deploy + test + + + org.eclipse.jetty + jetty-annotations + test + + + org.eclipse.jetty.websocket + javax-websocket-client-impl + test + + + org.eclipse.jetty.websocket + javax-websocket-server-impl + test + + + org.jboss.weld.servlet + weld-servlet-core + test + + + org.eclipse + yasson + test + + + jakarta.validation + jakarta.validation-api + test + + + org.eclipse.microprofile.config + microprofile-config-api + test + + + io.smallrye.config + smallrye-config + test + + + org.eclipse.microprofile.metrics + microprofile-metrics-api + test + + + io.smallrye + smallrye-metrics + test + + + io.opentracing + opentracing-mock + test + + + io.smallrye + smallrye-opentracing + test + + + org.eclipse.microprofile.context-propagation + microprofile-context-propagation-api + test + + + io.smallrye + smallrye-context-propagation + test + + + io.smallrye.reactive + mutiny + test + + + io.smallrye.reactive + mutiny-smallrye-context-propagation + test + + + org.hibernate.validator + hibernate-validator + test + + + org.glassfish + jakarta.el + test + + + org.eclipse.microprofile.graphql + microprofile-graphql-api + test + + + io.smallrye + smallrye-graphql-servlet + test + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + + true + + + + org.apache.maven.plugins + maven-surefire-plugin + + false + 1 + + + + + net.revelc.code + impsort-maven-plugin + + true + + + + org.apache.maven.plugins + maven-compiler-plugin + + 16 + + + + + + + \ No newline at end of file diff --git a/server/integration-tests-jdk16/src/main/java/io/smallrye/graphql/tests/SmallRyeGraphQLArchiveProcessor.java b/server/integration-tests-jdk16/src/main/java/io/smallrye/graphql/tests/SmallRyeGraphQLArchiveProcessor.java new file mode 100644 index 000000000..5b4389885 --- /dev/null +++ b/server/integration-tests-jdk16/src/main/java/io/smallrye/graphql/tests/SmallRyeGraphQLArchiveProcessor.java @@ -0,0 +1,39 @@ +package io.smallrye.graphql.tests; + +import java.io.File; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Set; + +import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; +import org.jboss.arquillian.test.spi.TestClass; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.Maven; + +/** + * Creates the deployable unit with all the needed dependencies. + * + * @author Phillip Kruger (phillip.kruger@redhat.com) + */ +public class SmallRyeGraphQLArchiveProcessor implements ApplicationArchiveProcessor { + + @Override + public void process(Archive applicationArchive, TestClass testClass) { + + if (applicationArchive instanceof WebArchive) { + WebArchive testDeployment = (WebArchive) applicationArchive; + + final File[] dependencies = Maven.resolver() + .loadPomFromFile("pom.xml") + .resolve("io.smallrye:smallrye-graphql-servlet") + .withoutTransitivity() + .asFile(); + // Make sure it's unique + Set dependenciesSet = new LinkedHashSet<>(Arrays.asList(dependencies)); + testDeployment.addAsLibraries(dependenciesSet.toArray(new File[] {})); + } + + System.out.println(applicationArchive.toString(true)); + } +} diff --git a/server/integration-tests-jdk16/src/main/java/io/smallrye/graphql/tests/SmallRyeGraphQLExtension.java b/server/integration-tests-jdk16/src/main/java/io/smallrye/graphql/tests/SmallRyeGraphQLExtension.java new file mode 100644 index 000000000..5ea2267bc --- /dev/null +++ b/server/integration-tests-jdk16/src/main/java/io/smallrye/graphql/tests/SmallRyeGraphQLExtension.java @@ -0,0 +1,17 @@ +package io.smallrye.graphql.tests; + +import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; +import org.jboss.arquillian.core.spi.LoadableExtension; + +/** + * Activating the extension + * + * @author Phillip Kruger (phillip.kruger@redhat.com) + */ +public class SmallRyeGraphQLExtension implements LoadableExtension { + @Override + public void register(ExtensionBuilder builder) { + builder.service(ApplicationArchiveProcessor.class, SmallRyeGraphQLArchiveProcessor.class); + } + +} diff --git a/server/integration-tests-jdk16/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension b/server/integration-tests-jdk16/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension new file mode 100644 index 000000000..a78f12fd9 --- /dev/null +++ b/server/integration-tests-jdk16/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension @@ -0,0 +1 @@ +io.smallrye.graphql.tests.SmallRyeGraphQLExtension \ No newline at end of file diff --git a/server/integration-tests-jdk16/src/test/java/io/smallrye/graphql/tests/client/RecordAsInputToDynamicClientTest.java b/server/integration-tests-jdk16/src/test/java/io/smallrye/graphql/tests/client/RecordAsInputToDynamicClientTest.java new file mode 100644 index 000000000..56d5a2221 --- /dev/null +++ b/server/integration-tests-jdk16/src/test/java/io/smallrye/graphql/tests/client/RecordAsInputToDynamicClientTest.java @@ -0,0 +1,97 @@ +package io.smallrye.graphql.tests.client; + +import io.smallrye.graphql.client.Response; +import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient; +import io.smallrye.graphql.client.dynamic.vertx.VertxDynamicGraphQLClientBuilder; +import org.eclipse.microprofile.graphql.GraphQLApi; +import org.eclipse.microprofile.graphql.Query; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.net.URL; +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +/** + * Verify that dynamic clients can parse Java records from responses + */ +@RunWith(Arquillian.class) +@RunAsClient +public class RecordAsInputToDynamicClientTest { + + @Deployment + public static WebArchive deployment() { + return ShrinkWrap.create(WebArchive.class) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") + .addClasses(SimpleRecord.class); + } + + @ArquillianResource + URL testingURL; + + @Test + public void testSimpleRecord() throws Exception { + try (DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder() + .url(testingURL.toString() + "graphql").build()) { + Response response = client.executeSync("query { simple {a b} }"); + SimpleRecord result = response.getObject(SimpleRecord.class, "simple"); + assertEquals("a", result.a()); + assertEquals("b", result.b()); + } + + } + + /** + * Try selecting only a subset of fields supported by the record. + */ + @Test + public void testPartial() throws Exception { + try (DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder() + .url(testingURL.toString() + "graphql").build()) { + Response response = client.executeSync("query { simple {a} }"); + SimpleRecord result = response.getObject(SimpleRecord.class, "simple"); + assertEquals("a", result.a()); + assertNull(result.b()); + } + + } + + /** + * Just to be sure that if I reverse the order of fields in the query, + * they won't get mixed up on the client side. + */ + @Test + public void testReversed() throws Exception { + try (DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder() + .url(testingURL.toString() + "graphql").build()) { + Response response = client.executeSync("query { simple {b a} }"); + SimpleRecord result = response.getObject(SimpleRecord.class, "simple"); + assertEquals("a", result.a()); + assertEquals("b", result.b()); + } + + } + + @GraphQLApi + public static class Api { + + @Query + public SimpleRecord simple() { + return new SimpleRecord("a", "b"); + } + + } + + public record SimpleRecord(String a, String b) { + } + +} diff --git a/server/integration-tests-jdk16/src/test/java/io/smallrye/graphql/tests/client/RecordAsInputToTypesafeClientTest.java b/server/integration-tests-jdk16/src/test/java/io/smallrye/graphql/tests/client/RecordAsInputToTypesafeClientTest.java new file mode 100644 index 000000000..84f176902 --- /dev/null +++ b/server/integration-tests-jdk16/src/test/java/io/smallrye/graphql/tests/client/RecordAsInputToTypesafeClientTest.java @@ -0,0 +1,67 @@ +package io.smallrye.graphql.tests.client; + +import io.smallrye.graphql.client.typesafe.api.GraphQLClientApi; +import io.smallrye.graphql.client.typesafe.api.TypesafeGraphQLClientBuilder; +import org.eclipse.microprofile.graphql.GraphQLApi; +import org.eclipse.microprofile.graphql.Query; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.net.URL; + +import static org.junit.Assert.assertEquals; + +@RunWith(Arquillian.class) +@RunAsClient +public class RecordAsInputToTypesafeClientTest { + + @Deployment + public static WebArchive deployment() { + return ShrinkWrap.create(WebArchive.class) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") + .addClasses(SimpleRecord.class); + } + + @ArquillianResource + URL testingURL; + + @Test + public void testSimpleRecord() { + ClientApi client = TypesafeGraphQLClientBuilder.newBuilder() + .endpoint(testingURL.toString() + "graphql") + .build(ClientApi.class); + SimpleRecord result = client.simple(); + assertEquals("a", result.a()); + assertEquals("b", result.b()); + } + + @GraphQLClientApi + public interface ClientApi { + + @Query + SimpleRecord simple(); + + } + + @GraphQLApi + public static class Api implements ClientApi { + + @Query + public SimpleRecord simple() { + return new SimpleRecord("a", "b"); + } + + } + + public record SimpleRecord(String a, String b) { + } + +} diff --git a/server/pom.xml b/server/pom.xml index 672dae0d1..9cb965424 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -29,5 +29,5 @@ integration-tests federation - + diff --git a/server/runner/pom.xml b/server/runner/pom.xml index da1d05e6b..58361374b 100644 --- a/server/runner/pom.xml +++ b/server/runner/pom.xml @@ -149,7 +149,17 @@ - + + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.1 + + false + + diff --git a/tools/gradle-plugin/pom.xml b/tools/gradle-plugin/pom.xml index f939972e4..61d674769 100644 --- a/tools/gradle-plugin/pom.xml +++ b/tools/gradle-plugin/pom.xml @@ -17,7 +17,6 @@ ./gradlew build - false