-
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.
Support optional @QueryParam on Rest client
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 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
66 changes: 66 additions & 0 deletions
66
...ent/deployment/src/test/java/io/quarkus/rest/client/reactive/OptionalQueryParamsTest.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,66 @@ | ||
package io.quarkus.rest.client.reactive; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.URI; | ||
import java.util.*; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.UriInfo; | ||
|
||
import org.jboss.resteasy.reactive.RestQuery; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
|
||
public class OptionalQueryParamsTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(Resource.class, Client.class)); | ||
|
||
@TestHTTPResource | ||
URI baseUri; | ||
|
||
@Test | ||
void testQueryParamsWithOptionals() { | ||
Client client = QuarkusRestClientBuilder.newBuilder().baseUri(baseUri).build(Client.class); | ||
String responseForEmptyOptional = client.optional(Optional.empty()); | ||
assertThat(responseForEmptyOptional).isNull(); | ||
|
||
String responseForValueOptional = client.optional(Optional.of("value")); | ||
assertThat(responseForValueOptional).isEqualTo("value"); | ||
} | ||
|
||
@Path("optional") | ||
public static class Resource { | ||
|
||
@Path("query") | ||
@GET | ||
public String queryParams(@Context UriInfo uriInfo) { | ||
|
||
if (uriInfo.getQueryParameters().isEmpty()) { | ||
return null; | ||
} | ||
|
||
Map.Entry<String, List<String>> optionalParam = uriInfo.getQueryParameters().entrySet().iterator() | ||
.next(); | ||
|
||
return optionalParam.getValue().get(0); | ||
|
||
} | ||
} | ||
|
||
@Path("optional") | ||
public interface Client { | ||
|
||
@Path("query") | ||
@GET | ||
String optional(@RestQuery Optional<String> parameter); | ||
|
||
} | ||
} |