From 326263201dd22bda16c9b10e825f03ee58defef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Marti=C5=A1ka?= Date: Thu, 3 Jun 2021 10:59:39 +0200 Subject: [PATCH] Test for subscriptions with dynamic GraphQL clients --- .../graphql/client/LuckyNumbersResource.java | 8 +++++++ .../graphql/client/DynamicClientTest.java | 22 +++++++++++++++++++ .../graphql/client/TypesafeClientTest.java | 2 -- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/integration-tests/smallrye-graphql-client/src/main/java/io/quarkus/io/smallrye/graphql/client/LuckyNumbersResource.java b/integration-tests/smallrye-graphql-client/src/main/java/io/quarkus/io/smallrye/graphql/client/LuckyNumbersResource.java index ed0f85d2bc4ba..7d01ab7534e84 100644 --- a/integration-tests/smallrye-graphql-client/src/main/java/io/quarkus/io/smallrye/graphql/client/LuckyNumbersResource.java +++ b/integration-tests/smallrye-graphql-client/src/main/java/io/quarkus/io/smallrye/graphql/client/LuckyNumbersResource.java @@ -6,6 +6,9 @@ import org.eclipse.microprofile.graphql.Mutation; import org.eclipse.microprofile.graphql.Query; +import io.smallrye.graphql.api.Subscription; +import io.smallrye.mutiny.Multi; + @GraphQLApi @ApplicationScoped public class LuckyNumbersResource { @@ -23,4 +26,9 @@ public Integer setLuckyNumber(Integer newLuckyNumber) { return luckyNumber; } + @Subscription + public Multi primeNumbers() { + return Multi.createFrom().items(2, 3, 5, 7, 11, 13); + } + } diff --git a/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/DynamicClientTest.java b/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/DynamicClientTest.java index bab062d8e9ec5..9cc901f2c028a 100644 --- a/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/DynamicClientTest.java +++ b/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/DynamicClientTest.java @@ -6,8 +6,11 @@ import static io.smallrye.graphql.client.core.Field.field; import static io.smallrye.graphql.client.core.Operation.operation; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.net.URL; +import java.util.List; +import java.util.stream.Collectors; import org.junit.jupiter.api.Test; @@ -44,4 +47,23 @@ public void testDynamicClient() throws Exception { assertEquals(15, response.getData().getInt("get"), response.toString()); } } + + @Test + public void testDynamicClientSubscription() throws Exception { + try (DynamicGraphQLClient client = DynamicGraphQLClientBuilder.newBuilder().url(url.toString() + "/graphql").build()) { + Document op = document( + operation(OperationType.SUBSCRIPTION, + field("primeNumbers"))); + List expectedNumbers = List.of(2, 3, 5, 7, 11, 13); + List responses = client.subscription(op) + .subscribe() + .asStream() + .collect(Collectors.toList()); + for (int i = 0; i < expectedNumbers.size(); i++) { + assertEquals(expectedNumbers.get(i), responses.get(i).getData().getInt("primeNumbers")); + assertFalse(responses.get(i).hasError()); + } + } + } + } diff --git a/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/TypesafeClientTest.java b/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/TypesafeClientTest.java index f69d5976373a6..0b600d16e3fa0 100644 --- a/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/TypesafeClientTest.java +++ b/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/TypesafeClientTest.java @@ -1,6 +1,5 @@ package io.quarkus.it.smallrye.graphql.client; -import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.URL; @@ -20,7 +19,6 @@ public class TypesafeClientTest { @Test public void testTypesafeClient() throws Exception { - LuckyNumbersClientApi client = TypesafeGraphQLClientBuilder.newBuilder() .endpoint(url.toString() + "/graphql") .build(LuckyNumbersClientApi.class);