Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMQP Pact Consumer tests impossible to invoke method with annotation @PactVerifyProvider #1431

Open
nicolasmingo opened this issue Sep 6, 2021 · 2 comments

Comments

@nicolasmingo
Copy link

nicolasmingo commented Sep 6, 2021

I'm using message pacts with AMQP feature. After generating pact files (JSON), I'm not able to use it inside Provider test.

Steps to reproduce:

  @ExtendWith ( PactVerificationInvocationContextProvider.class )
  @PactFolder("pacts")
  class MyProviderTest {
  
      @BeforeEach
      void before(PactVerificationContext context) {
          context.setTarget(new MessageTestTarget());
      }
  
      @TestTemplate
      void pactVerificationTestTemplate(PactVerificationContext context) {
          context.verifyInteraction();
      }
  
      @State("My Init state")
      public void initState() {
          // ...
      }
  
      @PactVerifyProvider("a success response")
      public static MessageAndMetadata verifySuccessResponse() {
          final Map<String, Object> metadata = new HashMap<>();
          final byte[] data = .... // my body
          return new MessageAndMetadata(data, metadata).toString();
      }
  
  }

Current behaviour
1.1) Failed to invoke provider method 'verifySuccessResponse'

Expected behaviour
verifySuccessResponse should be invoked

Environment
Gradle + Java 11 + IntelliJ + pact-jvm libraries:
'au.com.dius.pact.provider:junit5:4.2.10'
'au.com.dius.pact.consumer:junit5:4.2.10'

Analysis

    fun invokeProviderMethod(m: Method, instance: Any?): Any? {
        try {
          return m.invoke(instance)
        } catch (e: Throwable) {
          throw RuntimeException("Failed to invoke provider method '${m.name}'", e)
        }
    }

The invoke method failed:
java.lang.IllegalAccessException: class au.com.dius.pact.provider.ProviderVerifier$Companion cannot access a member of class MyProviderTest.

If I set "m.setAccessible(true)" it will succeed.

@nicolasmingo
Copy link
Author

nicolasmingo commented Sep 7, 2021

The problem appears when the Test class is declared with private-package visibility, set it as public will solve the issue.

uglyog pushed a commit that referenced this issue Sep 18, 2021
@uglyog
Copy link
Member

uglyog commented Sep 19, 2021

4.1.27 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants