Marcello Rigan
04/25/2022, 8:11 AMYousaf Nabi (pactflow.io)
Marcello Rigan
04/25/2022, 10:07 AM@SpringBootTest(classes = { X.class }, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@Provider("ProviderX")
@Consumer("ConsumerX")
@PactFolder("src/test/resources/pacts")
@ExtendWith(SpringExtension.class)
public class XProviderTest {
@BeforeEach
void before(PactVerificationContext context) throws MalformedURLException {
String myProviderUrl = "<Http://localhost:8080>";
context.setTarget(HttpTestTarget.fromUrl(new URL(myProviderUrl)));
}
@TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class)
void pactVerificationTestTemplate(PactVerificationContext context, HttpRequest request) {
replaceAuthHeader(request);
context.verifyInteraction();
}
private void replaceAuthHeader(HttpRequest request) {
if (request.containsHeader("authorization")) {
String header = "Bearer " + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm").format(new Date());
request.removeHeaders("authorization");
request.addHeader("authorization", header);
}
}
i need to change the replaceAuthHeader method later for our rules for a valid Bearer Token. but i get an error while running the test. org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [org.apache.http.HttpRequest arg1] in method [void pactVerificationTestTemplate(au.com.dius.pact.provider.junit5.PactVerificationContext,org.apache.http.HttpRequest)].Yousaf Nabi (pactflow.io)
Marcello Rigan
04/25/2022, 10:16 AMYousaf Nabi (pactflow.io)
Marcello Rigan
04/25/2022, 10:21 AMYousaf Nabi (pactflow.io)