question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AmqpTarget doesn't find @PactVerifyProvider annotation

See original GitHub issue

I’m running a simple message provider test:

@RunWith(PactRunner.class)
@Provider("userservice")
@PactFolder("../pact-message-consumer/target/pacts")
@SpringBootTest
public class MessageProviderTest {

	@TestTarget
	public final Target target = new AmqpTarget(Collections.singletonList("io.reflectoring"));

	@PactVerifyProvider("a user created message")
	public String verifyUserCreatedMessage() {
		return "{\"testParam1\": \"value1\",\"testParam2\": \"value2\"}";
	}
}

Executing this test results in

Failures:

0) a user created message
      No annotated methods were found for interaction 'a user created message'. You need to provide a method annotated with @PactVerifyProvider("a user created message") that returns the message contents.

The cause for this is that the Reflections call in ProviderVerifier#verifyResponseByInvokingProviderMethods doesn’t find the @PactVerifyProvider annotation on my test method. There must be something wrong with the setup of the Reflections instance (class loader?).

When I’m using the following code snippet from a test, the annotation is found:

Reflections r = new Reflections(ClasspathHelper.forPackage("io.reflectoring"), new MethodAnnotationsScanner());
Set<Method> methods = r.getMethodsAnnotatedWith(PactVerifyProvider.class);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:20 (13 by maintainers)

github_iconTop GitHub Comments

5reactions
jon-ruckwoodcommented, Apr 30, 2019

@eranberg I was experiencing the same issue but with 3.6.4. I found that after upgrading maven-surefire-plugin, everything started to work:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
    <configuration>
        <useSystemClassLoader>false</useSystemClassLoader>
    </configuration>
</plugin>

Intermediate versions may work, however I didn’t look into it.

2reactions
tylerkroncommented, May 22, 2019

Had this issue as well. My issue is that I am using Java 11. Upgraded to pact-jvm-consumer-junit version 4.0.0-beta.2 and I have provider verification working again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AmqpTarget doesn't find @PactVerifyProvider annotation #763
I'm running a simple message provider test: @RunWith(PactRunner.class) @Provider("userservice") @PactFolder(".
Read more >
Pact verify not working - Annotated method not found during ...
When doing producer side testing you need to provide the JSON contract. In those contracts you have the name of the producer.
Read more >
au.com.dius.pact.provider.junit.target.AmqpTarget Maven ...
Rule** JUnit annotations, that will be run before/after each test of an ... name of tested provider @PactFolder("pacts") // Point where to find...
Read more >
Testing a Spring Message Producer and Consumer against a ...
This annotation is part of the standard Java Bean Validation annotations we'll ... You can find the code for the consumer in my...
Read more >
pact-jvm
Pact will automatically search for test method which is annotated with @PactVerifyProvider("") and will match the message returned by test method & the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found