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.
Rest Client Reactive - passing headers for async calls
fixes quarkusio#16577
- Loading branch information
1 parent
29d257f
commit aacd94d
Showing
8 changed files
with
96 additions
and
17 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
75 changes: 75 additions & 0 deletions
75
...nt-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/AsyncHeaderTest.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,75 @@ | ||
package io.quarkus.rest.client.reactive; | ||
|
||
import static io.quarkus.rest.client.reactive.RestClientTestUtil.setUrlForClass; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
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.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
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 AsyncHeaderTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Client.class, Resource.class) | ||
.addAsResource( | ||
new StringAsset(setUrlForClass(Client.class)), | ||
"application.properties")); | ||
|
||
@RestClient | ||
Client client; | ||
|
||
@Test | ||
void shouldSendHeaderWithUni() { | ||
String headerValue = "jaka piekna i dluga wartosc headera"; | ||
String result = client.uniGet(headerValue) | ||
.await().atMost(Duration.ofSeconds(10)); | ||
assertThat(result).isEqualTo(String.format("passedHeader:%s", headerValue)); | ||
} | ||
|
||
@Test | ||
void shouldSendHeaderWithCompletionStage() throws ExecutionException, InterruptedException, TimeoutException { | ||
String headerValue = "jaka piekna i dluga wartosc headera"; | ||
String result = client.completionStageGet(headerValue) | ||
.toCompletableFuture().get(10, TimeUnit.SECONDS); | ||
assertThat(result).isEqualTo(String.format("passedHeader:%s", headerValue)); | ||
} | ||
|
||
@Path("/") | ||
@RegisterRestClient | ||
@Produces(MediaType.TEXT_PLAIN) | ||
interface Client { | ||
@GET | ||
Uni<String> uniGet(@HeaderParam("some-header") String headerValue); | ||
|
||
@GET | ||
CompletionStage<String> completionStageGet(@HeaderParam("some-header") String headerValue); | ||
} | ||
|
||
@Path("/") | ||
static class Resource { | ||
@GET | ||
public String get(@HeaderParam("some-header") String headerValue) { | ||
return String.format("passedHeader:%s", headerValue); | ||
} | ||
} | ||
} |
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
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