-
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.
Merge pull request #45672 from lasteris/docs-rest-client-fix-link
Support java.util.Optional<T> passing to @QueryParam/@restquery for RestСlient
- Loading branch information
Showing
4 changed files
with
90 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
63 changes: 63 additions & 0 deletions
63
...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,63 @@ | ||
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).isNullOrEmpty(); | ||
|
||
String responseForValueOptional = client.optional(Optional.of("value")); | ||
assertThat(responseForValueOptional).isEqualTo("parameter=value"); | ||
} | ||
|
||
@Path("optional") | ||
public static class Resource { | ||
|
||
@Path("query") | ||
@GET | ||
public String queryParams(@Context UriInfo uriInfo) { | ||
|
||
var entries = new ArrayList<String>(uriInfo.getQueryParameters().size()); | ||
for (var entry : uriInfo.getQueryParameters().entrySet()) { | ||
entries.add(entry.getKey() + "=" + String.join(",", entry.getValue())); | ||
} | ||
return String.join(";", entries); | ||
|
||
} | ||
} | ||
|
||
@Path("optional") | ||
public interface Client { | ||
|
||
@Path("query") | ||
@GET | ||
String optional(@RestQuery Optional<String> parameter); | ||
|
||
} | ||
} |