-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
Exception when no pacts to verify & test template has also an HttpRequest
parameter
#1564
Comments
The problem is that to know if it can inject an HTTP request, it needs to know the type of the interaction, but there is no Pact files, so it does not know that and there won't be any request object to inject. |
We just migrated from pact version 4.2.7 (where it was working fine without any pacts to verify) to 4.4.3 and encountered this problem. |
So what changed from 4.2 to also 4.5 that this can't be detected anymore? |
With 4.2.x, there was only one type of interaction. With 4.5.x, there can be multiple types of interactions. |
As a workaround I just added this ParameterResolver and registered it via ExtendWith to my test base class: public class PactNoPactsWorkaround implements ParameterResolver {
@Override
public boolean supportsParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext)
throws ParameterResolutionException {
final ExtensionContext.Store store = extensionContext.getStore(ExtensionContext.Namespace.create("pact-jvm"));
final PactVerificationContext testContext = (PactVerificationContext) store.get("interactionContext");
return testContext == null && parameterContext.getParameter().getType() == HttpRequest.class;
}
@Override
public Object resolveParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext)
throws ParameterResolutionException {
return null;
}
} |
I used this workaround, maybe it helps someone. Create Junit5 extension to ignore class IgnoreParameterResolutionException implements TestExecutionExceptionHandler {
@Override
public void handleTestExecutionException(ExtensionContext extensionContext, Throwable throwable) throws Throwable {
if (throwable instanceof ParameterResolutionException) {
return;
}
throw throwable;
}
} Use it on @TestTemplate
@ExtendWith({PactVerificationSpringProvider.class, IgnoreParameterResolutionException.class})
void pactVerificationTestTemplate(PactVerificationContext context, MockHttpServletRequestBuilder requestBuilder) {
requestBuilder
.with(csrf())
.contextPath(servletContextPath);
if (context != null) {
context.verifyInteraction();
}
} |
The recommended way to address this is per the above extension: #1564 (comment) Closing this ticket. |
When there is no PACTs to verify (that satisfy the constraints)
PactVerificationContext context
isnull
. The prefered solution is to check that. But ifTestTemplate
method has also anHttpRequest
parameter like:It throws:
When this
HttpRequest
is removed it logs expectedNo pact found to verify
Any thoughts?
Originally posted by @fragonib in #768 (comment)
The text was updated successfully, but these errors were encountered: