I would also like to do this -- we already have a large suite of integration tests which run against the real server, but we feel that pact would help isolate reasons for test failures and improve performance.
I'm using pact-jvm and I've written a filter which creates PactFragments:
@Singleton
@Provider
public class PactFilter implements ContainerResponseFilter {
@Override
public ContainerResponse filter(ContainerRequest req,
ContainerResponse res) {
ConsumerPactBuilder
.consumer("client")
.hasPactWith("server")
.uponReceiving("a request")
.path(req.getPath())
.method(req.getMethod())
.body(req.getEntity(String.class))
.willRespondWith()
.status(res.getStatus())
.body(res.getResponse().getEntity().toString())
.toFragment()
.runConsumer(null, new TestRun() {
@Override
public void run(MockProviderConfig mockProviderConfig) throws Throwable {
// do nothing
}
});
return res;
}
}
At present this is on the server -- I may put it in the client instead, and it will need to be enhanced to handle headers, cookies etc.
What I'm not clear on is how I ask Pact to write the fragments to a file after my tests have run?
Thanks,
Tom