Skip to content

Commit

Permalink
Register the client response builder
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Aug 22, 2021
1 parent 8445d00 commit 72f4bf7
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package io.quarkus.jaxrs.client.reactive.deployment.test;

import java.net.URL;

import javax.enterprise.event.Observes;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.ClientResponseContext;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;

import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext;
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientResponseFilter;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
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;
import io.vertx.core.Handler;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;

public class FailureTestCase {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(Endpoint.class));

@TestHTTPResource
URL url;

private Client client;

@BeforeEach
public void before() {
client = ClientBuilder.newClient().register(TestClientResponseFilter.class);
}

@AfterEach
public void after() {
client.close();
}

@Test
public void test() {
Assertions.assertThrows(WebApplicationException.class,
() -> client.target(url.toExternalForm() + "/hello").request().get());
}

public static class Endpoint {

public void setup(@Observes Router router) {
router.route("/hello").handler(new Handler<RoutingContext>() {
@Override
public void handle(RoutingContext event) {
event.response().end();
}
});
}
}

@Provider
public static class TestClientResponseFilter implements ResteasyReactiveClientResponseFilter {

@Override
public void filter(ResteasyReactiveClientRequestContext requestContext, ClientResponseContext responseContext) {
//make sure the response builder works with no server components installed
throw new WebApplicationException(Response.status(500).build());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.jaxrs.client.reactive.runtime.ClientResponseBuilderFactory

0 comments on commit 72f4bf7

Please sign in to comment.