PactVerificationContext 位于加载器“app”的未命名模块中 - Quarkus 应用程序中的 Pact 合约

问题描述 投票:0回答:1

我有一个带有 gradle 的 Quarkus 应用程序。我能够生成合同,但在运行验证测试时获取以下代码。

class au.com.dius.pact.provider.junit5.PactVerificationContext cannot be cast to class au.com.dius.pact.provider.junit5.PactVerificationContext (au.com.dius.pact.provider.junit5.PactVerificationContext is in unnamed module of loader 'app'; au.com.dius.pact.provider.junit5.PactVerificationContext is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @6de54b40) java.lang.ClassCastException: class au.com.dius.pact.provider.junit5.PactVerificationContext cannot be cast to class au.com.dius.pact.provider.junit5.PactVerificationContext (au.com.dius.pact.provider.junit5.PactVerificationContext is in unnamed module of loader 'app'; au.com.dius.pact.provider.junit5.PactVerificationContext is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @6de54b40)   at au.com.dius.pact.provider.junit5.PactVerificationContext.verifyInteraction(PactVerificationContext.kt:57)    at com.FruitProviderTest.pactVerificationTestTemplate(FruitProviderTest.java:43)    at java.base/java.lang.reflect.Method.invoke(Method.java:568)   at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:973)     at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:903)     at io.quarkus.test.junit.QuarkusTestExtension.interceptTestTemplateMethod(QuarkusTestExtension.java:863)    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)  at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)  at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)  at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)     at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)    at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:276)  at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)     at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)  at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)   at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)  at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)  at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)     at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)   at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
@PactFolder("build/pacts")
@Provider("provider")
@Testcontainers
@QuarkusTest
@ExtendWith(PactVerificationInvocationContextProvider.class)
public class FruitProviderTest {

    private static final int ENVOY_PORT = 8081;




    @TestTemplate
    @ExtendWith(PactVerificationInvocationContextProvider.class)
    void pactVerificationTestTemplate(PactVerificationContext context) {
        context.verifyInteraction();
    }

    @State(value = "Fruits Exist", action = StateChangeAction.SETUP) // Annotation for the state
    public void fruitsExist() {
        // Set up the state here
        System.out.println("-----------------------Now in the 'Fruits Exist' state-------------------------");
    }

    @State(value = "Fruits Exist", action = StateChangeAction.TEARDOWN) // Annotation for the state
    public void fruitsExistTearDown() {
        // Set up the state here
        System.out.println("-----------------------Now in the 'Fruits Exist Tear Down' state-------------------------");
    }

该服务有一个 GRPC 端点

@GrpcService
public class FruitServiceImpl extends MutinyFruitServiceGrpc.FruitServiceImplBase {
    @Override
    public Uni<CreateJuiceResponse> getFruit(Empty request) {
        return Uni.createFrom().item(CreateJuiceResponse
                .newBuilder().setColour("Red").setName("Apple")
                .build());
    }
}

我能够在消费者方面生成协议。 我还验证了依赖关系是正确的

dependencies {        implementation nforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
    implementation 'io.quarkus:quarkus-grpc'
    implementation 'io.quarkus:quarkus-arc'
    testImplementation 'io.quarkus:quarkus-junit5'
    implementation 'io.quarkus:quarkus-rest-client-reactive'
    testImplementation("au.com.dius.pact.provider:junit5:4.6.14")
    implementation 'com.google.api.grpc:proto-google-common-protos:2.14.3'
    testImplementation 'org.testcontainers:junit-jupiter:1.17.3'
    testImplementation 'io.rest-assured:rest-assured'
    testImplementation 'io.quarkus:quarkus-junit5-mockito'
    //testImplementation enforcedPlatform("au.com.dius.pact:pact-jvm-dependencies:4.6.14")
}

还验证了使用的注释是否正确

@PactFolder("build/pacts")
@Provider("provider")
@QuarkusTest
@ExtendWith(PactVerificationInvocationContextProvider.class)
java quarkus provider pact
1个回答
0
投票
    testImplementation("au.com.dius.pact.provider:junit5:4.6.14")

看来您直接依赖于 Pact。由于 Pact 可能与 Quarkus 类加载交互不良(正如您所发现的),因此最好使用 Quarkus Pact 集成:https://quarkus.io/extensions/io.quarkiverse.pact/quarkus-pact-provider/

© www.soinside.com 2019 - 2024. All rights reserved.