-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rest Client Reactive: SmallRye Stork integration
- Loading branch information
1 parent
fdb9f5e
commit ec20dd3
Showing
32 changed files
with
879 additions
and
55 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
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
13 changes: 13 additions & 0 deletions
13
...-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/stork/HelloClient.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,13 @@ | ||
package io.quarkus.rest.client.reactive.stork; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@Path("/") | ||
@RegisterRestClient(configKey = "hello2") | ||
public interface HelloClient { | ||
@GET | ||
String hello(); | ||
} |
15 changes: 15 additions & 0 deletions
15
...eactive/deployment/src/test/java/io/quarkus/rest/client/reactive/stork/HelloResource.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,15 @@ | ||
package io.quarkus.rest.client.reactive.stork; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("/hello") | ||
public class HelloResource { | ||
|
||
public static final String HELLO_WORLD = "Hello, World!"; | ||
|
||
@GET | ||
public String hello() { | ||
return HELLO_WORLD; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...e/deployment/src/test/java/io/quarkus/rest/client/reactive/stork/PassThroughResource.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,30 @@ | ||
package io.quarkus.rest.client.reactive.stork; | ||
|
||
import java.net.URI; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
@Path("/helper") | ||
public class PassThroughResource { | ||
|
||
@RestClient | ||
HelloClient client; | ||
|
||
@GET | ||
public String invokeClient() { | ||
HelloClient client = RestClientBuilder.newBuilder() | ||
.baseUri(URI.create("stork://hello-service/hello")) | ||
.build(HelloClient.class); | ||
return client.hello(); | ||
} | ||
|
||
@Path("/cdi") | ||
@GET | ||
public String invokeCdiClient() { | ||
return client.hello(); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...tive/deployment/src/test/java/io/quarkus/rest/client/reactive/stork/StorkDevModeTest.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,72 @@ | ||
package io.quarkus.rest.client.reactive.stork; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; | ||
import static io.quarkus.rest.client.reactive.stork.HelloResource.HELLO_WORLD; | ||
import static io.restassured.RestAssured.when; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import java.io.File; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
|
||
public class StorkDevModeTest { | ||
|
||
public static final String WIREMOCK_RESPONSE = "response from the wiremock server"; | ||
|
||
private static WireMockServer wireMockServer; | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
wireMockServer = new WireMockServer(options().port(8766)); | ||
wireMockServer.stubFor(WireMock.get("/hello") | ||
.willReturn(aResponse().withFixedDelay(1000) | ||
.withBody(WIREMOCK_RESPONSE).withStatus(200))); | ||
wireMockServer.start(); | ||
} | ||
|
||
@AfterAll | ||
public static void shutDown() { | ||
wireMockServer.stop(); | ||
} | ||
|
||
@RegisterExtension | ||
static QuarkusDevModeTest TEST = new QuarkusDevModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(PassThroughResource.class, HelloResource.class, HelloClient.class) | ||
.addAsResource( | ||
new File("src/test/resources/stork-dev-application.properties"), | ||
"application.properties")); | ||
|
||
@Test | ||
void shouldModifyStorkSettings() { | ||
// @formatter:off | ||
when() | ||
.get("/helper") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo(HELLO_WORLD)); | ||
// @formatter:on | ||
|
||
TEST.modifyResourceFile("application.properties", | ||
v -> v.replaceAll("stork.hello-service.service-discovery.1=.*", | ||
"stork.hello-service.service-discovery.1=localhost:8766")); | ||
// @formatter:off | ||
when() | ||
.get("/helper") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo(WIREMOCK_RESPONSE)); | ||
// @formatter:on | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
.../deployment/src/test/java/io/quarkus/rest/client/reactive/stork/StorkIntegrationTest.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,61 @@ | ||
package io.quarkus.rest.client.reactive.stork; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.net.URI; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Timeout; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.rest.client.reactive.HelloClient2; | ||
import io.quarkus.rest.client.reactive.HelloResource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class StorkIntegrationTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(HelloClient2.class, HelloResource.class)) | ||
.withConfigurationResource("stork-application.properties"); | ||
|
||
@RestClient | ||
HelloClient2 client; | ||
|
||
@Test | ||
void shouldDetermineUrlViaStork() { | ||
String greeting = RestClientBuilder.newBuilder().baseUri(URI.create("stork://hello-service/hello")) | ||
.build(HelloClient2.class) | ||
.echo("black and white bird"); | ||
assertThat(greeting).isEqualTo("hello, black and white bird"); | ||
} | ||
|
||
@Test | ||
void shouldDetermineUrlViaStorkCDI() { | ||
String greeting = client.echo("big bird"); | ||
assertThat(greeting).isEqualTo("hello, big bird"); | ||
} | ||
|
||
@Test | ||
@Timeout(20) | ||
void shouldFailOnUnknownService() { | ||
HelloClient2 client2 = RestClientBuilder.newBuilder() | ||
.baseUri(URI.create("stork://nonexistent-service")) | ||
.build(HelloClient2.class); | ||
assertThatThrownBy(() -> client2.echo("foo")).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
@Timeout(20) | ||
void shouldFailForServiceWithoutEndpoints() { | ||
HelloClient2 client2 = RestClientBuilder.newBuilder() | ||
.baseUri(URI.create("stork://service-without-endpoints")) | ||
.build(HelloClient2.class); | ||
assertThatThrownBy(() -> client2.echo("foo")).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
} |
Oops, something went wrong.