-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rest Client Reactive: Support PathParam from BeanParam
fixes #20027
- Loading branch information
1 parent
70e5b80
commit 9cc6a05
Showing
5 changed files
with
127 additions
and
5 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
74 changes: 74 additions & 0 deletions
74
...deployment/src/test/java/io/quarkus/rest/client/reactive/beanparam/BeanPathParamTest.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,74 @@ | ||
package io.quarkus.rest.client.reactive.beanparam; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.URI; | ||
|
||
import javax.ws.rs.BeanParam; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
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 BeanPathParamTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest(); | ||
|
||
@TestHTTPResource | ||
URI baseUri; | ||
|
||
@Test | ||
void shouldPassPathParamFromBeanParam() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri).build(Client.class); | ||
assertThat(client.getWithBeanParam(new MyBeanParam("123"))).isEqualTo("it works!"); | ||
} | ||
|
||
@Test | ||
void shouldPassPathParamFromBeanParamAndMethod() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri).build(Client.class); | ||
assertThat(client.getWithBeanParam("foo", new MyBeanParam("123"))).isEqualTo("it works with method too!"); | ||
} | ||
|
||
@Path("/my/{id}/resource") | ||
public interface Client { | ||
@GET | ||
String getWithBeanParam(@BeanParam MyBeanParam beanParam); | ||
|
||
@GET | ||
@Path("/{name}") | ||
String getWithBeanParam(@PathParam("name") String name, @BeanParam MyBeanParam beanParam); | ||
} | ||
|
||
public static class MyBeanParam { | ||
private final String id; | ||
|
||
public MyBeanParam(String id) { | ||
this.id = id; | ||
} | ||
|
||
@PathParam("id") | ||
public String getId() { | ||
return id; | ||
} | ||
} | ||
|
||
@Path("/my/123/resource") | ||
public static class Resource { | ||
@GET | ||
public String get() { | ||
return "it works!"; | ||
} | ||
|
||
@Path("/foo") | ||
@GET | ||
public String getWithLongerPath() { | ||
return "it works with method too!"; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ public enum ItemType { | |
QUERY_PARAM, | ||
COOKIE, | ||
HEADER_PARAM, | ||
PATH_PARAM, | ||
// TODO: more | ||
} |
15 changes: 15 additions & 0 deletions
15
...r/src/main/java/org/jboss/resteasy/reactive/client/processor/beanparam/PathParamItem.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,15 @@ | ||
package org.jboss.resteasy.reactive.client.processor.beanparam; | ||
|
||
public class PathParamItem extends Item { | ||
|
||
private final String pathParamName; | ||
|
||
public PathParamItem(String pathParamName, ValueExtractor valueExtractor) { | ||
super(ItemType.PATH_PARAM, valueExtractor); | ||
this.pathParamName = pathParamName; | ||
} | ||
|
||
public String getPathParamName() { | ||
return pathParamName; | ||
} | ||
} |