-
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.
Merge pull request #23721 from pravussum/fix-reactive-rest-client-lis…
…teners-discovery Fix RestClientListener discovery for Reactive REST Client
- Loading branch information
Showing
3 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...tive/deployment/src/test/java/io/quarkus/rest/client/reactive/RestClientListenerTest.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,64 @@ | ||
package io.quarkus.rest.client.reactive; | ||
|
||
import static io.quarkus.rest.client.reactive.RestClientTestUtil.setUrlForClass; | ||
import static io.quarkus.rest.client.reactive.TestRestClientListener.HEADER_PARAM_NAME; | ||
import static io.quarkus.rest.client.reactive.TestRestClientListener.HEADER_PARAM_VALUE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.Duration; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.HeaderParam; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class RestClientListenerTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Client.class, Resource.class, TestRestClientListener.class) | ||
.addAsResource( | ||
new StringAsset(setUrlForClass(Client.class)), | ||
"application.properties") | ||
.addAsResource( | ||
new StringAsset(TestRestClientListener.class.getCanonicalName()), | ||
"META-INF/services/org.eclipse.microprofile.rest.client.spi.RestClientListener")); | ||
|
||
@RestClient | ||
Client client; | ||
|
||
@Test | ||
void shouldCallRegisteredRestClient() { | ||
String result = client.get() | ||
.await().atMost(Duration.ofSeconds(10)); | ||
assertThat(result).isEqualTo(HEADER_PARAM_VALUE); | ||
} | ||
|
||
@Path("/") | ||
@RegisterRestClient | ||
@Produces(MediaType.TEXT_PLAIN) | ||
interface Client { | ||
@GET | ||
Uni<String> get(); | ||
} | ||
|
||
@Path("/") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
static class Resource { | ||
|
||
@GET | ||
public String get(@HeaderParam(HEADER_PARAM_NAME) String headerParam) { | ||
return headerParam; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...tive/deployment/src/test/java/io/quarkus/rest/client/reactive/TestRestClientListener.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,26 @@ | ||
package io.quarkus.rest.client.reactive; | ||
|
||
import javax.ws.rs.client.ClientRequestContext; | ||
import javax.ws.rs.client.ClientRequestFilter; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
import org.eclipse.microprofile.rest.client.spi.RestClientListener; | ||
|
||
public class TestRestClientListener implements RestClientListener { | ||
|
||
public static final String HEADER_PARAM_NAME = "filterheader"; | ||
public static final String HEADER_PARAM_VALUE = "present"; | ||
|
||
@Override | ||
public void onNewClient(Class<?> aClass, RestClientBuilder restClientBuilder) { | ||
restClientBuilder.register(new TestRestClientFilter()); | ||
} | ||
|
||
static class TestRestClientFilter implements ClientRequestFilter { | ||
|
||
@Override | ||
public void filter(ClientRequestContext clientRequestContext) { | ||
clientRequestContext.getHeaders().putSingle(HEADER_PARAM_NAME, HEADER_PARAM_VALUE); | ||
} | ||
} | ||
} |
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