Skip to content

Commit

Permalink
fix smallrye#796: client impls depend on TCK, not the other way around
Browse files Browse the repository at this point in the history
  • Loading branch information
t1 committed May 15, 2021
1 parent 1a7a122 commit 7fb055e
Show file tree
Hide file tree
Showing 46 changed files with 336 additions and 144 deletions.
1 change: 0 additions & 1 deletion client/generator/pom.xml
Expand Up @@ -21,7 +21,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>*Behavior</include>
Expand Down
20 changes: 16 additions & 4 deletions client/implementation-jaxrs/pom.xml
Expand Up @@ -17,16 +17,28 @@
<artifactId>smallrye-graphql-client</artifactId>
</dependency>

<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<scope>provided</scope>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-tck</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>4.6.0.Final</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@@ -0,0 +1,6 @@
package test.tck;

import tck.graphql.dynamic.core.DynamicTCK;

class DynamicTckSuite extends DynamicTCK {
}
@@ -1,4 +1,4 @@
package test.unit;
package test.tck;

import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -25,34 +25,34 @@
import org.mockito.Mockito;

import io.smallrye.graphql.client.typesafe.api.TypesafeGraphQLClientBuilder;
import tck.graphql.typesafe.TypesafeGraphQLClientFixture;

/**
* Builds {@link TypesafeGraphQLClientBuilder} instances with mocked backend and helps testing that.
* Only this class relies on the JAX-RS implementation, but the tests are independent of that detail.
*/
class GraphQLClientFixture {
public class JaxRsTypesafeGraphQLClientFixture implements TypesafeGraphQLClientFixture {
private final Client mockClient = Mockito.mock(Client.class);
private final WebTarget mockWebTarget = Mockito.mock(WebTarget.class);
private final Invocation.Builder mockInvocationBuilder = Mockito.mock(Invocation.Builder.class);
private Response response;
private Entity<JsonObject> entitySent;

GraphQLClientFixture() {
public JaxRsTypesafeGraphQLClientFixture() {
given(mockClient.target(any(URI.class))).willReturn(mockWebTarget);
given(mockWebTarget.request(any(MediaType.class))).willReturn(mockInvocationBuilder);
given(mockInvocationBuilder.headers(any())).willReturn(mockInvocationBuilder);
given(mockInvocationBuilder.post(any())).will(i -> response);
}

@Override
public <T> T build(Class<T> apiClass) {
return builder().build(apiClass);
}

TypesafeGraphQLClientBuilder builder() {
@Override
public TypesafeGraphQLClientBuilder builder() {
return builderWithoutEndpointConfig().endpoint("urn:dummy-endpoint");
}

TypesafeGraphQLClientBuilder builderWithoutEndpointConfig() {
@Override
public TypesafeGraphQLClientBuilder builderWithoutEndpointConfig() {
TypesafeGraphQLClientBuilder builder = TypesafeGraphQLClientBuilder.newBuilder();
try {
Method method = builder.getClass().getMethod("client", Client.class);
Expand All @@ -63,32 +63,39 @@ TypesafeGraphQLClientBuilder builderWithoutEndpointConfig() {
return builder;
}

void returnsData(String data) {
@Override
public void returnsData(String data) {
returns("{\"data\":{" + data.replace('\'', '\"') + "}}");
}

void returns(String response) {
@Override
public void returns(String response) {
this.response = Response.ok(response).build();
}

@Override
public void returnsServerError() {
this.response = Response.serverError().type(TEXT_PLAIN_TYPE).entity("failed").build();
}

String variables() {
@Override
public String variables() {
return rawVariables().replace('\"', '\'');
}

String rawVariables() {
@Override
public String rawVariables() {
JsonObject variables = entitySent().getEntity().getJsonObject("variables");
return String.valueOf(variables);
}

String operationName() {
@Override
public String operationName() {
return entitySent().getEntity().getString("operationName", "null");
}

String query() {
@Override
public String query() {
return entitySent().getEntity().getString("query").replace('\"', '\'');
}

Expand All @@ -104,11 +111,13 @@ private Entity<JsonObject> entitySent() {
return entitySent;
}

Object sentHeader(String name) {
@Override
public Object sentHeader(String name) {
return sentHeaders().getFirst(name);
}

URI endpointUsed() {
@Override
public URI endpointUsed() {
ArgumentCaptor<URI> captor = ArgumentCaptor.forClass(URI.class);
then(mockClient).should().target(captor.capture());
return captor.getValue();
Expand All @@ -135,6 +144,7 @@ private MediaType captureAcceptHeader() {
return captor.getValue();
}

@Override
public void verifyClosed() {
verify(mockClient).close();
}
Expand Down
@@ -0,0 +1,6 @@
package test.tck;

import tck.graphql.typesafe.TypesafeTCK;

class TypesafeTckSuite extends TypesafeTCK {
}
@@ -0,0 +1 @@
test.tck.JaxRsTypesafeGraphQLClientFixture
18 changes: 11 additions & 7 deletions client/implementation-vertx/pom.xml
@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>smallrye-graphql-client-parent</artifactId>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-parent</artifactId>
<version>1.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>smallrye-graphql-client-implementation-vertx</artifactId>
<name>SmallRye: GraphQL Client :: Implementation :: Vert.x</name>
Expand All @@ -27,10 +31,10 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-tck</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
</project>
@@ -0,0 +1,6 @@
package io.smallrye.graphql.client.vertx.test;

import tck.graphql.dynamic.core.DynamicTCK;

class DynamicTckSuite extends DynamicTCK {
}
@@ -1,7 +1,8 @@
package io.smallrye.graphql.client.vertx.test;

import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClientBuilder;
import io.smallrye.graphql.client.dynamic.vertx.VertxDynamicGraphQLClientBuilder;
Expand All @@ -11,7 +12,6 @@ public class VertxDynamicGraphQLClientBuilderTest {
@Test
public void testBuilder() {
DynamicGraphQLClientBuilder builder = DynamicGraphQLClientBuilder.newBuilder();
Assert.assertEquals(VertxDynamicGraphQLClientBuilder.class, builder.getClass());
assertEquals(VertxDynamicGraphQLClientBuilder.class, builder.getClass());
}

}
86 changes: 84 additions & 2 deletions client/pom.xml
Expand Up @@ -7,12 +7,17 @@
<artifactId>smallrye-graphql-parent</artifactId>
<version>1.2.1-SNAPSHOT</version>
</parent>

<artifactId>smallrye-graphql-client-parent</artifactId>
<packaging>pom</packaging>

<name>SmallRye: GraphQL Client</name>
<description>Client side of the GraphQL Implementation</description>

<properties>
<version.surefire.plugin>3.0.0-M5</version.surefire.plugin>
</properties>

<modules>
<module>api</module>
<module>implementation</module>
Expand All @@ -23,4 +28,81 @@
<module>tck</module>
<module>all</module>
</modules>

<!-- TODO remove the dependency management when the parent dependency management was updated to 5.8.0/1.8.0 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.8.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.8.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>1.8.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.8.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>1.8.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-api</artifactId>
<version>1.8.0-M1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>*Behavior</include>
<include>*Test</include>
<include>*Suite</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 7fb055e

Please sign in to comment.