forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resteasy Reactive: Support use of optional with list/set/sortedset
Support use when using query params with some collections. Example: ```java @path("/list") @get public String sayHelloToList(@QueryParam("name") final Optional<List<String>> names) { return doSayHelloToCollection(names); } ``` fix quarkusio#23898
- Loading branch information
Showing
6 changed files
with
180 additions
and
7 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...sy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/QueryParamTest.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,46 @@ | ||
package io.quarkus.resteasy.test; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.QueryParam; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class QueryParamTest { | ||
|
||
private static final String HELLO = "hello "; | ||
private static final String NOBODY = "nobody"; | ||
private static final String ALBERT = "albert"; | ||
private static final String AND = " and "; | ||
private static final String JOSE = "jose"; | ||
private static final String NAME = "name"; | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(MyResource.class)); | ||
|
||
@Test | ||
public void testWithSomeNames() { | ||
Assertions.assertEquals(HELLO + ALBERT + AND + JOSE, | ||
RestAssured.given().queryParam(NAME, ALBERT, JOSE).get("/greetings").asString()); | ||
} | ||
|
||
@Path("/greetings") | ||
public static class MyResource { | ||
|
||
@GET | ||
public String sayHello(@QueryParam("name") final Optional<List<String>> names) { | ||
return HELLO + names.map(l -> l.stream().collect(Collectors.joining(AND))) | ||
.orElse(NOBODY); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...test/java/io/quarkus/resteasy/reactive/server/test/simple/OptionalQueryParamResource.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,49 @@ | ||
package io.quarkus.resteasy.reactive.server.test.simple; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.SortedSet; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.QueryParam; | ||
|
||
@Path("/optional-query/greetings") | ||
public class OptionalQueryParamResource { | ||
|
||
public static final String HELLO = "hello "; | ||
public static final String NOBODY = "nobody"; | ||
public static final String AND = " and "; | ||
|
||
@Path("/one") | ||
@GET | ||
public String sayHelloToValue(@QueryParam("name") final Optional<String> name) { | ||
return HELLO + name.orElse(NOBODY); | ||
} | ||
|
||
@Path("/list") | ||
@GET | ||
public String sayHelloToList(@QueryParam("name") final Optional<List<String>> names) { | ||
return doSayHelloToCollection(names); | ||
} | ||
|
||
@Path("/set") | ||
@GET | ||
public String sayHelloToSet(@QueryParam("name") final Optional<Set<String>> names) { | ||
return doSayHelloToCollection(names); | ||
} | ||
|
||
@Path("/sortedset") | ||
@GET | ||
public String sayHelloToSortedSet(@QueryParam("name") final Optional<SortedSet<String>> names) { | ||
return doSayHelloToCollection(names); | ||
} | ||
|
||
private String doSayHelloToCollection(final Optional<? extends Collection<String>> names) { | ||
return HELLO + names.map(l -> l.stream().collect(Collectors.joining(AND))) | ||
.orElse(NOBODY); | ||
} | ||
} |
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
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