forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting user-agent via configuration for the Reactive REST Client
Closes: quarkusio#25445
- Loading branch information
Showing
7 changed files
with
118 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
83 changes: 83 additions & 0 deletions
83
...oyment/src/test/java/io/quarkus/rest/client/reactive/headers/UserAgentFromConfigTest.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,83 @@ | ||
package io.quarkus.rest.client.reactive.headers; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.URI; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.HeaderParam; | ||
import javax.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
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.quarkus.test.common.http.TestHTTPResource; | ||
|
||
public class UserAgentFromConfigTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(Resource.class, Client.class) | ||
.addAsResource(new StringAsset( | ||
"quarkus.rest-client.user-agent=base\n" + | ||
"quarkus.rest-client.client1.url=http://localhost:${quarkus.http.test-port:8081}\n" + | ||
"quarkus.rest-client.client2.url=http://localhost:${quarkus.http.test-port:8081}\n" + | ||
"quarkus.rest-client.client2.user-agent=specific"), | ||
"application.properties")); | ||
|
||
@TestHTTPResource | ||
URI baseUri; | ||
|
||
@RestClient | ||
Client client; | ||
|
||
@RestClient | ||
Client2 client2; | ||
|
||
@Test | ||
void testProgrammaticClient() { | ||
Client client = RestClientBuilder.newBuilder().baseUri(baseUri).build(Client.class); | ||
assertThat(client.call()).isEqualTo("base"); | ||
} | ||
|
||
@Test | ||
void testBaseUserAgent() { | ||
assertThat(client.call()).isEqualTo("base"); | ||
} | ||
|
||
@Test | ||
void testSpecificUserAgent() { | ||
assertThat(client2.call()).isEqualTo("specific"); | ||
} | ||
|
||
@Path("/") | ||
@ApplicationScoped | ||
public static class Resource { | ||
@GET | ||
public String returnHeaders(@HeaderParam("user-agent") String header) { | ||
return header; | ||
} | ||
} | ||
|
||
@RegisterRestClient(configKey = "client1") | ||
public interface Client { | ||
|
||
@Path("/") | ||
@GET | ||
String call(); | ||
} | ||
|
||
@RegisterRestClient(configKey = "client2") | ||
public interface Client2 { | ||
|
||
@Path("/") | ||
@GET | ||
String call(); | ||
} | ||
|
||
} |
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