2

我尝试编写 QuarkusTest 来测试一个实际上作为 ElasticSearchStore 工作的类。在应用程序中,有一个用于访问 GoogleMaps API 的休息客户端,如下所示:

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

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

其余客户端没有注入到我要测试的类中,而是通过构造函数注入到另一个类中:

@JBossLog
@ApplicationScoped
public class GoogleMapsClient {

    private final GoogleMapsApiService googleMapsApiService;


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

通常,应用程序在 IDE 和 CI/CD 管道上构建没有任何问题。但是,当我尝试使用 QuarkusTest 注释运行测试时,出现以下错误:

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)
4

0 回答 0