-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests for rest-client-reactive URL override feature #2275
Open
mocenas
wants to merge
1
commit into
quarkus-qe:main
Choose a base branch
from
mocenas:test_rest_url_override
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...-reactive/src/main/java/io/quarkus/ts/http/restclient/reactive/UrlOverrideableClient.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,33 @@ | ||
package io.quarkus.ts.http.restclient.reactive; | ||
|
||
import java.net.URI; | ||
import java.net.URL; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
import io.quarkus.rest.client.reactive.Url; | ||
|
||
/** | ||
* RestClient which provides capability to override base URL. | ||
* URL might be overridden to access different service. | ||
* Base URL can be overridden by String, URL or URI parameter type. | ||
*/ | ||
@RegisterRestClient | ||
@Path("urlOverride") | ||
public interface UrlOverrideableClient { | ||
|
||
@GET | ||
@Path("basic") | ||
String getByString(@Url String uri); | ||
|
||
@GET | ||
@Path("basic") | ||
String getByUrl(@Url URL uri); | ||
|
||
@GET | ||
@Path("basic") | ||
String getByUri(@Url URI uri); | ||
} |
57 changes: 57 additions & 0 deletions
57
.../java/io/quarkus/ts/http/restclient/reactive/resources/UrlOverrideClientTestResource.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,57 @@ | ||
package io.quarkus.ts.http.restclient.reactive.resources; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URL; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.QueryParam; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
import io.quarkus.ts.http.restclient.reactive.UrlOverrideableClient; | ||
|
||
@Path("testUrlOverride") | ||
public class UrlOverrideClientTestResource { | ||
@Inject | ||
@RestClient | ||
UrlOverrideableClient urlOverrideableClient; | ||
|
||
@Path("/defaultString") | ||
@GET | ||
public String defaultString() { | ||
return urlOverrideableClient.getByString(null); | ||
} | ||
|
||
@Path("/overrideString/") | ||
@GET | ||
public String overrideString(@QueryParam("port") Integer port) { | ||
return urlOverrideableClient.getByString(String.format("http://localhost:%d/", port)); | ||
} | ||
|
||
@Path("/defaultUrl") | ||
@GET | ||
public String defaultUrl() { | ||
return urlOverrideableClient.getByUrl(null); | ||
} | ||
|
||
@Path("/overrideUrl/") | ||
@GET | ||
public String overrideUrl(@QueryParam("port") Integer port) throws MalformedURLException { | ||
return urlOverrideableClient.getByUrl(new URL(String.format("http://localhost:%d/", port))); | ||
} | ||
|
||
@Path("/defaultUri") | ||
@GET | ||
public String defaultUri() { | ||
return urlOverrideableClient.getByUri(null); | ||
} | ||
|
||
@Path("/overrideUri/") | ||
@GET | ||
public String overrideUri(@QueryParam("port") Integer port) { | ||
return urlOverrideableClient.getByUri(URI.create(String.format("http://localhost:%d/", port))); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...e/src/main/java/io/quarkus/ts/http/restclient/reactive/resources/UrlOverrideResource.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,21 @@ | ||
package io.quarkus.ts.http.restclient.reactive.resources; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
@ApplicationScoped | ||
@Path("urlOverride") | ||
public class UrlOverrideResource { | ||
|
||
@ConfigProperty(name = "ts.quarkus.urlOverride.response", defaultValue = "empty") | ||
String response; | ||
|
||
@GET | ||
@Path("basic") | ||
public String basic() { | ||
return response; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
http/rest-client-reactive/src/main/resources/urlOverride.properties
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,2 @@ | ||
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.UrlOverrideableClient".uri=http://localhost:${quarkus.http.port} | ||
ts.quarkus.urlOverride.response=default |
54 changes: 54 additions & 0 deletions
54
...nt-reactive/src/test/java/io/quarkus/ts/http/restclient/reactive/UrlOverrideClientIT.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,54 @@ | ||
package io.quarkus.ts.http.restclient.reactive; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.bootstrap.Protocol; | ||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
|
||
@QuarkusScenario | ||
public class UrlOverrideClientIT { | ||
/* | ||
* Start two application. By default, restClient in app will do HTTP requests against app. | ||
* But if we override the URL, it will do requests against app2. | ||
* Both apps will be distinguished by value of "ts.quarkus.urlOverride.response" which they return as HTTP response. | ||
* The URL override feature overrides base URL, but not HTTP path. So we cannot easily test it using just one app. | ||
*/ | ||
@QuarkusApplication() | ||
static RestService app = new RestService() | ||
.withProperties("urlOverride.properties"); | ||
|
||
@QuarkusApplication() | ||
static RestService app2 = new RestService() | ||
.withProperties("urlOverride.properties") | ||
.withProperty("quarkus.http.ssl-port", "8444") | ||
.withProperty("ts.quarkus.urlOverride.response", "overridden"); | ||
|
||
@Test | ||
public void shouldOverrideUrlByString() { | ||
testEndpoints("defaultString", "overrideString"); | ||
} | ||
|
||
@Test | ||
public void shouldOverrideUrlByUrl() { | ||
testEndpoints("defaultUrl", "overrideUrl"); | ||
} | ||
|
||
@Test | ||
public void shouldOverrideUrlByUri() { | ||
testEndpoints("defaultUri", "overrideUri"); | ||
} | ||
|
||
private void testEndpoints(String defaultEndpoint, String overrideEndpoint) { | ||
String defaultResponse = app.given().get("/testUrlOverride/" + defaultEndpoint).asString(); | ||
assertEquals("default", defaultResponse); | ||
|
||
String overriddenResponse = app.given() | ||
.get("/testUrlOverride/" + overrideEndpoint + "/?port=" + app2.getURI(Protocol.HTTP).getPort()) | ||
.body().asString(); | ||
assertEquals("overridden", overriddenResponse); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.