-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow executing tests on Vert.x blocking thread pool
Relates to: #34222
- Loading branch information
Showing
4 changed files
with
199 additions
and
8 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
73 changes: 73 additions & 0 deletions
73
...nt/src/test/java/io/quarkus/rest/client/reactive/RestClientInTestMethodWithContextVT.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,73 @@ | ||
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.net.MalformedURLException; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientRequestFilter; | ||
|
||
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.jboss.resteasy.reactive.RestHeader; | ||
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.vertx.RunOnVertxContext; | ||
import io.smallrye.common.vertx.ContextLocals; | ||
|
||
public class RestClientInTestMethodWithContextVT { | ||
|
||
public static final String CORRELATION_ID_HEADER_NAME = "correlationId"; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Client.class, Resource.class, ClientFilter.class) | ||
.addAsResource( | ||
new StringAsset(setUrlForClass(Client.class)), "application.properties")); | ||
|
||
@RestClient | ||
Client client; | ||
|
||
@RunOnVertxContext(runOnEventLoop = false) | ||
@Test | ||
public void test() { | ||
ContextLocals.put(CORRELATION_ID_HEADER_NAME, "dummy"); | ||
assertThat(client.getMock()).isEqualTo("dummy"); | ||
} | ||
|
||
@Path("/test") | ||
@RegisterRestClient(configKey = "mock-client") | ||
@RegisterProvider(ClientFilter.class) | ||
public interface Client { | ||
|
||
@GET | ||
String getMock(); | ||
} | ||
|
||
@Path("/test") | ||
public static class Resource { | ||
|
||
@GET | ||
public String get(@RestHeader(CORRELATION_ID_HEADER_NAME) String correlationId) { | ||
return correlationId; | ||
} | ||
} | ||
|
||
public static class ClientFilter implements ClientRequestFilter { | ||
@Override | ||
public void filter(ClientRequestContext clientRequestContext) throws MalformedURLException { | ||
|
||
String correlationId = ContextLocals.<String> get(CORRELATION_ID_HEADER_NAME).orElse(null); | ||
clientRequestContext.getHeaders().putSingle(CORRELATION_ID_HEADER_NAME, correlationId); | ||
} | ||
} | ||
|
||
} |
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