|
| 1 | +package org.jboss.resteasy.microprofile.client; |
| 2 | + |
| 3 | +import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam; |
| 4 | +import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; |
| 5 | +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; |
| 6 | +import org.eclipse.microprofile.rest.client.inject.RestClient; |
| 7 | +import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer; |
| 8 | +import org.jboss.weld.environment.se.Weld; |
| 9 | +import org.jboss.weld.environment.se.WeldContainer; |
| 10 | +import org.junit.AfterClass; |
| 11 | +import org.junit.Assert; |
| 12 | +import org.junit.BeforeClass; |
| 13 | +import org.junit.Test; |
| 14 | + |
| 15 | +import javax.inject.Inject; |
| 16 | +import javax.ws.rs.ApplicationPath; |
| 17 | +import javax.ws.rs.GET; |
| 18 | +import javax.ws.rs.Path; |
| 19 | +import javax.ws.rs.PathParam; |
| 20 | +import javax.ws.rs.core.Application; |
| 21 | +import javax.ws.rs.core.Context; |
| 22 | +import javax.ws.rs.core.HttpHeaders; |
| 23 | +import java.util.HashSet; |
| 24 | +import java.util.Set; |
| 25 | + |
| 26 | +public class ClientHeadersDefaultFactoryCDITest { |
| 27 | + |
| 28 | + private static UndertowJaxrsServer server; |
| 29 | + private static WeldContainer container; |
| 30 | + |
| 31 | + static class Worker { |
| 32 | + |
| 33 | + @Inject |
| 34 | + @RestClient |
| 35 | + private TestResourceIntf service; |
| 36 | + |
| 37 | + public String work() { |
| 38 | + return service.hello("Stefano"); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + @Path("/") |
| 43 | + @RegisterRestClient(baseUri="http://localhost:8081") |
| 44 | + @RegisterClientHeaders |
| 45 | + @ClientHeaderParam(name="IntfHeader", value="intfValue") |
| 46 | + public interface TestResourceIntf { |
| 47 | + |
| 48 | + @Path("hello/{h}") |
| 49 | + @GET |
| 50 | + @ClientHeaderParam(name = "MthdHeader", value = "hello") |
| 51 | + String hello(@PathParam("h") String h); |
| 52 | + } |
| 53 | + |
| 54 | + @Path("/") |
| 55 | + public static class TestResource { |
| 56 | + |
| 57 | + @Path("hello/{h}") |
| 58 | + @GET |
| 59 | + public String hello(@PathParam("h") String h, @Context HttpHeaders httpHeaders) { |
| 60 | + return "IntfHeader: " + httpHeaders.getRequestHeader("IntfHeader").get(0) |
| 61 | + + " - MthdHeader: " + httpHeaders.getRequestHeader("MthdHeader").get(0); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + @ApplicationPath("") |
| 66 | + public static class MyApp extends Application { |
| 67 | + |
| 68 | + @Override |
| 69 | + public Set<Class<?>> getClasses() { |
| 70 | + HashSet<Class<?>> classes = new HashSet<Class<?>>(); |
| 71 | + classes.add(TestResource.class); |
| 72 | + return classes; |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + @BeforeClass |
| 77 | + public static void init() throws Exception { |
| 78 | + Weld weld = new Weld(); |
| 79 | + weld.addBeanClass(Worker.class); |
| 80 | + weld.addBeanClass(TestResourceIntf.class); |
| 81 | + container = weld.initialize(); |
| 82 | + server = new UndertowJaxrsServer().start(); |
| 83 | + server.deploy(MyApp.class); |
| 84 | + } |
| 85 | + |
| 86 | + @AfterClass |
| 87 | + public static void stop() throws Exception { |
| 88 | + server.stop(); |
| 89 | + container.shutdown(); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + public void test() { |
| 94 | + String result = container.select(Worker.class).get().work(); |
| 95 | + Assert.assertTrue(result.contains("IntfHeader: intfValue")); |
| 96 | + Assert.assertTrue(result.contains("MthdHeader: hello")); |
| 97 | + } |
| 98 | +} |
0 commit comments