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

MessageTarget giving No annotated methods were found error for annotation @PactVerifyProvider #1776

Open
nikhil4892 opened this issue Mar 14, 2024 · 2 comments

Comments

@nikhil4892
Copy link

I am trying to write provider test for kafka communications. I am using Pact-JVM with gradle dependency group:'au.com.dius.pact.provider', name: 'spring', version: '4.1.41' and plugin au.com.dius.pact.gradle.plugin:4.1.41 with JUnit4 for jdk8 framework.

I am getting error 'No annotated methods were found interaction 'Valid message'. You need to provide a method annotated with @PactVerifyProvider("Valid message") on the classpath that returns the message contents.' while running the provider test. My provider test has the same annotated method already present as suggested in the error message.

Below is my provider test:


package consumer.order;

@Provider("order-service")
@Consumer("accounts")
@PactFolder("src/contractTest/resources/pacts/")
@RunWith(PactRunner.class)
public class PublishOrderDetailsTest{

@TestTarget
public final Target target = new MessageTarget(Collections.singletonList("consumer.order.*"));

@Before
public void before(){}

@State("Publish order details")
public void publishOrderDetails(){}

@PactVerifyProvider("Valid message")
public MessageAndMetadata verifyOrderDetailsPubished(){
OrderDetials orderDetails = new OrderDetails("id123", "$200.00", "2024-03-12", "newyork", washington");
Map<String, Object> metaData = new HashMap<>();
metaData.put("contentType", "application/json");
metaData.put("topic", "order-details");

JsonSerializer<OrderDetials> serializer = new JsonSerializer<>();
return new MessageAndMetadata(serializer.serialize("order-details", orderDetails), metaData);
}
}

All values are matched as provided in the pact. InteractionRunner of pact is able to get the details from Pact files and also the details of method under @PactVerifyProvider annotation is getting picked through reflection but the run is, somehow, giving error 'No annotated methods were found for interaction 'Valid message''.

I am stuck at this error and I am new to pact. Can someone please suggest how to fix this issue?

@rholshausen
Copy link
Contributor

I can't see anything wrong with that test. Try removing the parameter from MessageTarget.

@nikhil4892
Copy link
Author

nikhil4892 commented Mar 30, 2024

It gives error when I am trying to use a customised Serializer of Kafka to convert the message to bytes in order to set the instance of MessageAndMetadata. However, the test works fine if I convert OrderDetails instance to String and then to bytes inside MessageAndMetadata.

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

2 participants