2

I try to write a QuarkusTest in order to test a class that is actually working as an ElasticSearchStore. In the app, there is a rest client for accessing GoogleMaps API which looks like:

    @RegisterRestClient(configKey = "google-maps-api")
    public interface GoogleMapsApiService {

    @GET
    @Retry(retryOn = {InternalServerException.class})
    @Path("address")
    String geocode(@QueryParam("address") String address);
}

The rest client is not injected into the class I want to test but it is injected to another class through the constructor:

@JBossLog
@ApplicationScoped
public class GoogleMapsClient {

    private final GoogleMapsApiService googleMapsApiService;


public GoogleMapsClient(
        @RestClient GoogleMapsApiService googleMapsApiService
    ) {
        this.googleMapsApiService = googleMapsApiService;
    }

Normally, the application builds without any problem on the IDE and CI/CD pipelines. However, when I try to run the test with QuarkusTest annotation I get the following error:

java.lang.RuntimeException: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
    [error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type 
 xxxx.GoogleMapsApiService and qualifiers [@RestClient]
    - java member: xxxx.GoogleMapsClient().googleMapsApiService
    - declared on CLASS bean [types=[xxxx.GoogleMapsClient, java.lang.Object], qualifiers=[@Default, @Any], target=xxxx.GoogleMapsClient]
    at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1196)
    at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:269)
    at io.quarkus.arc.processor.BeanProcessor.initialize(BeanProcessor.java:134)
    at io.quarkus.arc.deployment.ArcProcessor.validate(ArcProcessor.java:454)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:887)
    at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
    at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
    at java.base/java.lang.Thread.run(Thread.java:833)
    at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type xxxx.GoogleMapsApiService and qualifiers [@RestClient]
    - java member: xxxx.GoogleMapsClient().googleMapsApiService
    - declared on CLASS bean [types=[xxxx.GoogleMapsClient, java.lang.Object], qualifiers=[@Default, @Any], target=xxxx.GoogleMapsClient]
    at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:428)
    at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:508)
    at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:257)
IbrahimD
  • 891
  • 1
  • 7
  • 14
  • Are both classes in the same maven module? – geoand Feb 03 '22 at 15:28
  • Yes, they both are. – IbrahimD Feb 04 '22 at 10:58
  • Any chance you can upload a sample to Github? – geoand Feb 04 '22 at 12:27
  • Does it work when you inject the REST client as a field instead of through the constructor? If it does, then maybe this is a limitation in the REST client Quarkus integration. Also, did you define the endpoint URL in application.properties? Example: `xxx.GoogleMapsApiService/mp-rest/url=https://whatever`. – Rob Spoor Feb 07 '22 at 10:50
  • No, it doesn't work when injected as a field and the endpoint URL is defined. As I have stated, this is a service that builds works without any problem. The only issue is that it fails to build when you add a QuarkusTest. – IbrahimD Feb 10 '22 at 15:09
  • can you put a reproducer to github or gitlab ? – ozkanpakdil Feb 11 '22 at 17:26
  • This should work. Do you get the failure during a maven/gradle build or while running the test in the IDE? If the former, can you clear IDE caches and restart? If it fails when building with gradle or maven, please create an issue in https://github.com/quarkusio/quarkus/issues and attach a reproducer – Michał Szynkiewicz Feb 13 '22 at 12:42

0 Answers0