Simple switching from @PactFolder to @PactUrl makes it work
@luvLinux I have found the issue. @PactFolder loads the pacts from a resource folder via class.getClassLoader().getResource(). If you put your directory in a project resource folder (for example src/test/resources/pacts) and then use @PactFolder("pacts") it will work.
For reference, working source code is here, but I had to use @PackUrl
Test file in Java: https://gist.github.com/luvLinux/188394b94e98ad3716f9864d3a882f06
Pact file in JSON: https://gist.github.com/luvLinux/fc38200a2b08f767017b55eae2579a90
@PactFolder loader will load pacts from a directory now.
This has been released with versions 3.2.7 and 2.4.9
The fix does not work on Windows (tested with au.com.dius:pact-jvm-provider-spring_2.11:3.5.1).
When defining e.g. @PactFolder("src/test/resources/pact_contracts") then no pact files are found (java.lang.Exception: Did not find any pact files for provider Xyz)
The problem is in method au.com.dius.pact.provider.junit.loader.PactFolderLoader.resolvePath() on line 74:
URL resourcePath = PactFolderLoader.class.getClassLoader().getResource(path.getPath());
path.getPath() returns "src\test\resources\pact_contracts" which results in resourcePath being set to "file:/C:/path/to/project/src%5ctest%5cresources%5cpact_contracts" which does not correspond with the folder defined in the annotation.
To fix this, the backslashes '\' in the value returned by path.getPath() have to be converted to forward slashes '/', e.g. path.getPath().replace('\\', '/')
Re-opening this to resolve issues with Windows.
I can not reproduce this issue (with the latest version). Have a look at AmqpTest, it works on Windows.
Unfortunately the issue explaned by @tspoeri still exists on Windows. I updated vom 2.4.19 to 3.5.15 and got "Did not find any pact files for provider". A quick debug confirms that /s result in %5cs in the resourcePath. My workaround was to move all pact file to a path without slashes...
Most helpful comment
@PactFolderloader will load pacts from a directory now.