Hey there, how do i implement sync & async pro...
# pact-jvm
t
Hey there, how do i implement sync & async provider tests (so REST and event based messaging) for the same provider? Currently we get "No test target has been configured for AsynchronousMessage interactions" in the REST Provider Test class. Do we need to set a filter for this class or something?
t
Okay thanks. A bit of a pitty that this needs to be added even if the test class doesn't run async tests. I've send this to the affected team, but it seems like the ones responsible are out of office. I will try to respond here if this solved the issue, but if I respond nothing, it worked and i just forgot.
r
Oh, if you don't want to verify the async interactions, then, yes, there is a filter you can use
t
okay that seems to be exactly the problem. How do I set the filter?
r
You can filter the interactions by either the description or provider state. The properties to use are
pact.filter.description
and
pact.filter.providerState
I thought you could filter by the type of interaction, but that only works for JUnit 4
r
In our codebase which uses Junit 5 we implemented our own interaction filters:
Copy code
public static class Async<I extends Interaction> implements InteractionFilter<I> {
        public Predicate<I> buildPredicate(String[] ignored) {
            return (interaction) -> interaction instanceof V4Interaction.AsynchronousMessage;
        }
    }

    public static class Sync<I extends Interaction> implements InteractionFilter<I> {
        public Predicate<I> buildPredicate(String[] ignored) {
            return (interaction) -> interaction instanceof SynchronousRequestResponse;
        }
    }
By using these in the
@PactFilter
annotation, you can filter for Snyc / Ansyc interactions