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 - support injection for providers used in @RegisterProvider
- i.e. for providers not annotated with @Provider - resolves quarkusio#7531 - follows up on quarkusio#5752
- Loading branch information
Showing
7 changed files
with
137 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
22 changes: 22 additions & 0 deletions
22
...st-client/deployment/src/test/java/io/quarkus/restclient/registerprovider/EchoClient.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,22 @@ | ||
package io.quarkus.restclient.registerprovider; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@Path("/echo") | ||
@RegisterRestClient | ||
@RegisterProvider(MyFilter.class) | ||
public interface EchoClient { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
String echo(@QueryParam("message") String message); | ||
} |
17 changes: 17 additions & 0 deletions
17
...-client/deployment/src/test/java/io/quarkus/restclient/registerprovider/EchoResource.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,17 @@ | ||
package io.quarkus.restclient.registerprovider; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Path("/echo") | ||
public class EchoResource { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String echo(@QueryParam("message") String message) { | ||
return message; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ent/deployment/src/test/java/io/quarkus/restclient/registerprovider/MethodsCollector.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,21 @@ | ||
package io.quarkus.restclient.registerprovider; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
public class MethodsCollector { | ||
|
||
private final List<String> methods = new CopyOnWriteArrayList<>(); | ||
|
||
void collect(String method) { | ||
methods.add(method); | ||
} | ||
|
||
List<String> getMethods() { | ||
return methods; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...rest-client/deployment/src/test/java/io/quarkus/restclient/registerprovider/MyFilter.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,18 @@ | ||
package io.quarkus.restclient.registerprovider; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.client.ClientRequestContext; | ||
import javax.ws.rs.client.ClientRequestFilter; | ||
|
||
public class MyFilter implements ClientRequestFilter { | ||
|
||
@Inject | ||
MethodsCollector collector; | ||
|
||
@Override | ||
public void filter(ClientRequestContext requestContext) throws IOException { | ||
collector.collect(requestContext.getMethod()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...deployment/src/test/java/io/quarkus/restclient/registerprovider/RegisterProviderTest.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,39 @@ | ||
package io.quarkus.restclient.registerprovider; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import javax.inject.Inject; | ||
|
||
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; | ||
|
||
public class RegisterProviderTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(EchoResource.class, EchoClient.class, MyFilter.class, MethodsCollector.class) | ||
.addAsResource(new StringAsset("io.quarkus.restclient.registerprovider.EchoClient/mp-rest/url=${test.url}"), | ||
"application.properties")); | ||
|
||
@RestClient | ||
EchoClient client; | ||
|
||
@Inject | ||
MethodsCollector collector; | ||
|
||
@Test | ||
public void testProvider() { | ||
collector.getMethods().clear(); | ||
assertEquals("ping", client.echo("ping")); | ||
assertEquals(1, collector.getMethods().size()); | ||
assertEquals("GET", collector.getMethods().get(0)); | ||
} | ||
|
||
} |