pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 480 forks source link

method does not conform required method signature 'public RequestResponsePact xxx(PactDslWithProvider builder)' #1047

Closed TheGitHubGuy1 closed 4 years ago

TheGitHubGuy1 commented 4 years ago

Hi,

I am trying to use the MessagePact and am getting Method pact does not conform required method signature 'public RequestResponsePact xxx(PactDslWithProvider builder)' when running ./gradlew test

Here is my gradle.build deps for pact:

    ...
    testImplementation "org.junit.jupiter:junit-jupiter-api"
    testImplementation "au.com.dius:pact-jvm-consumer-junit5:4.0.6"
    testImplementation "au.com.dius:pact-jvm-provider-junit5:4.0.6"
    testCompile "au.com.dius:pact-jvm-consumer-junit5:4.0.6"
    testCompile "au.com.dius:pact-jvm-provider-junit5:4.0.6"
    testCompile "org.mockito:mockito-junit-jupiter:2.22.0"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
    ...

here is my code:

@ExtendWith(PactConsumerTestExt.class)
public HelloControllerSpec {
    @Pact(consumer="message-pact-consumer", provider = "provider")
    public MessagePact pact(MessagePactBuilder builder){
        return builder
                .hasPactWith("provider")
                .expectsToReceive("json data")
                .withContent(new PactDslJsonBody().stringType("thing","thingo"))
                .toPact();
    }

    @Test
    @PactTestFor(pactMethod = "pact")
    public void testEntityMQTT(List<Message> messages){
        for(Message message: messages){
            System.out.println(message.toString());
        }
    }
}

The standard HTTP implementation seems to work ok.

Full log:

java.lang.UnsupportedOperationException: Method pact does not conform required method signature 'public RequestResponsePact xxx(PactDslWithProvider builder)'
    at au.com.dius.pact.consumer.junit.JUnitTestSupport.conformsToSignature(JUnitTestSupport.kt:25)
    at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.lookupPact(PactConsumerTestExt.kt:274)
    at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.beforeTestExecution(PactConsumerTestExt.kt:199)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeTestExecutionCallbacks$4(TestMethodTestDescriptor.java:179)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeMethodsOrCallbacksUntilExceptionOccurs$5(TestMethodTestDescriptor.java:190)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:190)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeTestExecutionCallbacks(TestMethodTestDescriptor.java:178)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:71)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.util.ArrayList.forEach(ArrayList.java:1257)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.util.ArrayList.forEach(ArrayList.java:1257)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:102)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:82)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:78)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.stop(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:132)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:175)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:157)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:748)
TheGitHubGuy1 commented 4 years ago

Just a note, I've tried using the following packages also:

    testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.2"
    testImplementation "org.mockito:mockito-junit-jupiter:2.22.0"
    testImplementation "au.com.dius:pact-jvm-provider-junit5_2.12:3.6.10"
    testImplementation "au.com.dius:pact-jvm-consumer-junit5_2.12:3.6.10"
    testImplementation "au.com.dius:pact-jvm-consumer-java8_2.12:3.6.10"

With the same result, because I assumed these guys got it working: https://blog.codecentric.de/en/2019/11/message-pact-contract-testing-in-event-driven-applications/ and they were the deps in their gradle.build

https://github.com/rafaroca/pact-msg/

s1apped commented 4 years ago

Hi,

Not sure if same issue but I'm having problem with consumer HTTP implementation when running gradle task after updating pact to 4.0.6+. Provider tests seems to be working just fine.

java.lang.AssertionError: The following methods annotated with @Pact were not executed during the test: Test1, Test2, Test3
09:18:09.790 [DEBUG] [TestEventLogger]     If these are currently a work in progress, and a @Disabled annotation to the method
09:18:09.790 [DEBUG] [TestEventLogger]         at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.afterAll(PactConsumerTestExt.kt:350)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeAfterAllCallbacks$11(ClassTestDescriptor.java:396)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeAfterAllCallbacks$12(ClassTestDescriptor.java:396)
09:18:09.790 [DEBUG] [TestEventLogger]         at java.util.ArrayList.forEach(ArrayList.java:1257)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeAfterAllCallbacks(ClassTestDescriptor.java:396)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.after(ClassTestDescriptor.java:221)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.after(ClassTestDescriptor.java:74)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:118)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:118)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
09:18:09.790 [DEBUG] [TestEventLogger]         at java.util.ArrayList.forEach(ArrayList.java:1257)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
09:18:09.790 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:102)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:82)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:78)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
09:18:09.791 [DEBUG] [TestEventLogger]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
09:18:09.791 [DEBUG] [TestEventLogger]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
09:18:09.791 [DEBUG] [TestEventLogger]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
09:18:09.791 [DEBUG] [TestEventLogger]         at java.lang.reflect.Method.invoke(Method.java:498)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
09:18:09.791 [DEBUG] [TestEventLogger]         at com.sun.proxy.$Proxy2.stop(Unknown Source)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:132)
09:18:09.791 [DEBUG] [TestEventLogger]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
09:18:09.791 [DEBUG] [TestEventLogger]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
09:18:09.791 [DEBUG] [TestEventLogger]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
09:18:09.791 [DEBUG] [TestEventLogger]         at java.lang.reflect.Method.invoke(Method.java:498)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
09:18:09.791 [DEBUG] [TestEventLogger]         at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
09:18:09.791 [DEBUG] [TestEventLogger]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
09:18:09.792 [DEBUG] [TestEventLogger]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
09:18:09.792 [DEBUG] [TestEventLogger]         at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
09:18:09.792 [DEBUG] [TestEventLogger]         at java.lang.Thread.run(Thread.java:748)
uglyog commented 4 years ago

@BenStuart You can specify providerType = ProviderType.ASYNCH on the @PactTestFor annotation and that will resolve your issue.

uglyog commented 4 years ago

@s1apped that is not related. The test runner checks that all methods annotated with @Pact where executed during the test.

s1apped commented 4 years ago

@uglyog do you want me to open separate issues with more details?

uglyog commented 4 years ago

Yes, that is not related to this issue

TheGitHubGuy1 commented 4 years ago

Yes that resolved my issue thank you. If it's not in the documentation. Perhaps it's a good idea to add it.

Elio-Shyti commented 2 years ago

providerType = ProviderType.ASYNCH https://github.com/pact-foundation/pact-jvm/issues/1047#issuecomment-601989810

That worked for me!