Load files and mappings from src/test/resources by default
This PR adds support for loading files and mappings from test resources directory.
By default, It will look into src/test/resources/mappings and src/test/resources/__files behaving very similarly to when WireMockServer is started programmatically. This path can be configured via withRootDir(File file).
This addition simplifies the testing setup by providing an alternative to having to map all stub and file paths individually using with...() calls.
Before:
@Testcontainers
public class WireMockLoadsFileMappingsByDefaultTest {
@Container
private WireMockContainer server = new WireMockContainer("wiremock/wiremock:latest")
.withFile(new File("src/test/resources/static-file-1.txt"))
.withFile(new File("src/test/resources/static-file-2.txt"))
// other files
.withMappingFromResource("src/test/resources/mappings/simple-mapping-1.json")
.withMappingFromResource("src/test/resources/mappings/simple-mapping-2.json")
// other mappings
;
[...]
After:
Make sure all stubs and files are stored in the proper sub-directories and all the manual inclusions may be removed:
@Container
private WireMockContainer server = new WireMockContainer("wiremock/wiremock:latest");
Alternatively, one can choose a different path to load mappings/files from:
@Container
private WireMockContainer server = new WireMockContainer("wiremock/wiremock:latest")
.withRootDir("src/integration-test/resources")
References
- Closes #134
Submitter checklist
- [x] Recommended: Join WireMock Slack to get any help in
#help-contributingor a project-specific channel like#wiremock-java - [x] The PR request is well described and justified, including the body and the references
- [x] The PR title represents the desired changelog entry
- [x] The repository's code style is followed (see the contributing guide)
- [x] Test coverage that demonstrates that the change works as expected
- [ ] For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org
Hey @oleg-nenashev , I decided to give this ticket a try. I believe it would be a good idea to allow the root directory to be customizable as well but I thought about getting some feedback and suggestions to ensure I'm on the right track. Thanks!
I see some unintended formatting changes as well, maybe I could add a PR to include spotless to the project same as the main wiremock project?
@lhcopetti thank you for the pull request, I will take a look
Regarding spotless, I do not plan to include the same configuration as in WireMock core as it is overly prescriptive and damaging to contributor experience. I do not mind if there are some reasonable refactorings along with the pull requests, the flow of contributions is not that high to worry about merge conflicts. Some basic rules from spotless could be introduced though
Path definitely needs to be configurable. The most obvious example being src/integrationTest/resources/mappings.
Hey @oleg-nenashev @mplanchant . I updated the PR to add the configurable rootDir option. Please let me know if that makes sense. Thanks!
If this is merged and released, I'm happy to try it out.