-
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.
Add @ClientQueryParam to Reactive REST Client
This is analogous to what MP REST Client provides in @ClientHeaderParam Resolves: #21443
- Loading branch information
Showing
12 changed files
with
655 additions
and
10 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
239 changes: 229 additions & 10 deletions
239
.../main/java/io/quarkus/rest/client/reactive/deployment/MicroProfileRestClientEnricher.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
142 changes: 142 additions & 0 deletions
142
...src/test/java/io/quarkus/rest/client/reactive/queries/ClientQueryParamFromMethodTest.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,142 @@ | ||
package io.quarkus.rest.client.reactive.queries; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.QueryParam; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.rest.client.reactive.ClientQueryParam; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
|
||
public class ClientQueryParamFromMethodTest { | ||
|
||
@TestHTTPResource | ||
URI baseUri; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(Client.class, SubClient.class, Resource.class, ComputedParam.class)); | ||
|
||
@Test | ||
void shouldUseValuesOnlyFromClass() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri) | ||
.build(Client.class); | ||
|
||
assertThat(client.setFromClass()).isEqualTo("1/"); | ||
} | ||
|
||
@Test | ||
void shouldUseValuesFromClassAndMethod() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri) | ||
.build(Client.class); | ||
|
||
assertThat(client.setFromMethodAndClass()).isEqualTo("1/2"); | ||
} | ||
|
||
@Test | ||
void shouldUseValuesFromMethodWithParam() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri) | ||
.build(Client.class); | ||
|
||
assertThat(client.setFromMethodWithParam()).isEqualTo("-11/-2"); | ||
} | ||
|
||
@Test | ||
void shouldUseValuesFromQueryParam() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri) | ||
.build(Client.class); | ||
|
||
assertThat(client.setFromQueryParam("111")).isEqualTo("111/2"); | ||
} | ||
|
||
@Test | ||
void shouldUseValuesFromQueryParams() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri) | ||
.build(Client.class); | ||
|
||
assertThat(client.setFromQueryParams("111", "222")).isEqualTo("111/222"); | ||
} | ||
|
||
@Test | ||
void shouldUseValuesFromSubclientAnnotations() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri) | ||
.build(Client.class); | ||
|
||
assertThat(client.sub().sub("22")).isEqualTo("11/22"); | ||
} | ||
|
||
@Path("/") | ||
@ApplicationScoped | ||
public static class Resource { | ||
@GET | ||
public String returnQueryParamValues(@QueryParam("first") List<String> first, | ||
@QueryParam("second") List<String> second) { | ||
return String.join(",", first) + "/" + String.join(",", second); | ||
} | ||
} | ||
|
||
@ClientQueryParam(name = "first", value = "{first}") | ||
public interface Client { | ||
@GET | ||
String setFromClass(); | ||
|
||
@GET | ||
@ClientQueryParam(name = "second", value = "{second}") | ||
String setFromMethodAndClass(); | ||
|
||
@GET | ||
@ClientQueryParam(name = "second", value = "{second}") | ||
String setFromQueryParam(@QueryParam("first") String first); | ||
|
||
@GET | ||
@ClientQueryParam(name = "second", value = "{second}") | ||
String setFromQueryParams(@QueryParam("first") String first, @QueryParam("second") String second); | ||
|
||
@GET | ||
@ClientQueryParam(name = "first", value = "{io.quarkus.rest.client.reactive.queries.ComputedParam.withParam}") | ||
@ClientQueryParam(name = "second", value = "{withParam}") | ||
String setFromMethodWithParam(); | ||
|
||
@Path("") | ||
SubClient sub(); | ||
|
||
default String first() { | ||
return "1"; | ||
} | ||
|
||
default String second() { | ||
return "2"; | ||
} | ||
|
||
default String withParam(String name) { | ||
if ("first".equals(name)) { | ||
return "-1"; | ||
} else if ("second".equals(name)) { | ||
return "-2"; | ||
} | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
|
||
@ClientQueryParam(name = "first", value = "{first}") | ||
public interface SubClient { | ||
|
||
@GET | ||
String sub(@QueryParam("second") String second); | ||
|
||
default String first() { | ||
return "11"; | ||
} | ||
} | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
...c/test/java/io/quarkus/rest/client/reactive/queries/ClientQueryParamFromPropertyTest.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,96 @@ | ||
package io.quarkus.rest.client.reactive.queries; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.net.URI; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.QueryParam; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.rest.client.reactive.ClientQueryParam; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
|
||
public class ClientQueryParamFromPropertyTest { | ||
private static final String QUERY_VALUE = "foo"; | ||
|
||
@TestHTTPResource | ||
URI baseUri; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(Client.class, Resource.class) | ||
.addAsResource( | ||
new StringAsset("my.property-value=" + QUERY_VALUE), | ||
"application.properties")); | ||
|
||
@Test | ||
void shouldSetFromProperties() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri) | ||
.build(Client.class); | ||
|
||
assertThat(client.getWithParam()).isEqualTo(QUERY_VALUE); | ||
} | ||
|
||
@Test | ||
void shouldFailOnMissingRequiredProperty() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri) | ||
.build(Client.class); | ||
|
||
assertThatThrownBy(client::missingRequiredProperty) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void shouldSucceedOnMissingNonRequiredProperty() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri) | ||
.build(Client.class); | ||
|
||
assertThat(client.missingNonRequiredProperty()).isEqualTo(QUERY_VALUE); | ||
} | ||
|
||
@Test | ||
void shouldSucceedOnMissingNonRequiredPropertyAndUseOverriddenValue() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri) | ||
.build(Client.class); | ||
|
||
assertThat(client.missingNonRequiredPropertyAndOverriddenValue()).isEqualTo("other"); | ||
} | ||
|
||
@Path("/") | ||
@ApplicationScoped | ||
public static class Resource { | ||
@GET | ||
public String returnQueryParamValue(@QueryParam("my-param") String param) { | ||
return param; | ||
} | ||
} | ||
|
||
@ClientQueryParam(name = "my-param", value = "${my.property-value}") | ||
public interface Client { | ||
@GET | ||
String getWithParam(); | ||
|
||
@GET | ||
@ClientQueryParam(name = "some-other-param", value = "${non-existent-property}") | ||
String missingRequiredProperty(); | ||
|
||
@GET | ||
@ClientQueryParam(name = "some-other-param", value = "${non-existent-property}", required = false) | ||
String missingNonRequiredProperty(); | ||
|
||
@GET | ||
@ClientQueryParam(name = "some-other-param", value = "${non-existent-property}", required = false) | ||
@ClientQueryParam(name = "my-param", value = "other") | ||
String missingNonRequiredPropertyAndOverriddenValue(); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...ctive/deployment/src/test/java/io/quarkus/rest/client/reactive/queries/ComputedParam.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.queries; | ||
|
||
public class ComputedParam { | ||
|
||
public static String withParam(String name) { | ||
if ("first".equals(name)) { | ||
return "-11"; | ||
} else if ("second".equals(name)) { | ||
return "-22"; | ||
} | ||
throw new IllegalArgumentException(); | ||
} | ||
} |
Oops, something went wrong.