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

New verification type: FUNCTION #1379

Closed
solarmosaic-kflorence opened this issue Jun 9, 2021 · 10 comments
Closed

New verification type: FUNCTION #1379

solarmosaic-kflorence opened this issue Jun 9, 2021 · 10 comments

Comments

@solarmosaic-kflorence
Copy link

solarmosaic-kflorence commented Jun 9, 2021

Currently there exist two verification types:

  • PactVerification.REQUEST_RESPONSE -- verifies an HTTP response from a request
  • PactVerification.ANNOTATED_METHOD -- can be used to verify either an HTTP response, or a message and metadata

I would like to propose a third verification type, PactVerification.FUNCTION, which would be similar to PactVerification.ANNOTATED_METHOD except that:

  • only a single function is required, it would be a factory of String -> Any (but really, it would return specific types that the library already understands, like MessageAndMetadata).
  • the function would be provided explicitly to ProviderVerifier instead of via scanning the classpath for annotated methods
  • the function would not be invoked by reflection (e.g. java.lang.reflect.Method.invoke()), it would just be called normally like any other callback method in the ProviderVerifier. this means the method scope would be the same as any method in the test class instead of having to provide a specific instance for invocation.

This could be used for both messages and request/response, although the return types would need to vary depending on the interaction type. Probably the return value can be the same as the return values that are currently supported by the PactVerification.ANNOTATED_METHOD type.

My guess is the easiest way to implement this is to have another bifurcation in ProviderVerifier.verifyInteraction which would call a different method if the verification type is FUNCTION, for example verifyResponseByFunction, and define a new property on the ProviderVerifier that would contain the available function to call (verificationFunction: Function<String, Any>, or something like that). There can probably be some refactoring around verifyResponseByInvokingProviderMethods and verifyMessage to split common functionality into common methods, since mostly the only change is how to call the method and get the return value.

@uglyog
Copy link
Member

uglyog commented Jun 9, 2021

How are the functions going to be specified in the test class?

@solarmosaic-kflorence
Copy link
Author

solarmosaic-kflorence commented Jun 10, 2021

@uglyog open to suggestions, but maybe something like:

interface IProviderVerifier {
  var verificationFunction: Function<String, Any>
}

Really just need one method that can take in the description and return the appropriate response.

@uglyog
Copy link
Member

uglyog commented Jun 10, 2021

I was more referring to the user's test class. Will it need to be a public instance? The verifier class is not directly exposed to user code. We will need to support it across the implementations: Groovy, JUnit 4, JUnit 5, etc.

@solarmosaic-kflorence
Copy link
Author

@uglyog it would need to be supplied to the ProviderVerifier I guess, similar to things like the method instance: new ProviderVerifier().setVerificationFunction(...) -- maybe there is a better way?

@solarmosaic-kflorence
Copy link
Author

I am hoping we can apply this change first to the underlying Provider library before we need to implement it in all the other places, if that's possible.

@solarmosaic-kflorence
Copy link
Author

Maybe a better name is FACTORY_FUNCTION since it is essentially a factory for String -> response

@uglyog
Copy link
Member

uglyog commented Jun 10, 2021

@solarmosaic-kflorence
Copy link
Author

It's probably best to support Future as well, if it's not too difficult. Function<String, Future<Any>> 🤔

@uglyog
Copy link
Member

uglyog commented Jun 21, 2021

As long as it's java.util.concurrent.Future and not the Scala one

@uglyog
Copy link
Member

uglyog commented Aug 22, 2021

4.1.25 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

2 participants