Skip to content

Load files and mappings from src/test/resources by default #184

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lhcopetti
Copy link

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. It 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");

References

Submitter checklist

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • 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

@lhcopetti
Copy link
Author

lhcopetti commented Apr 6, 2025

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?

@oleg-nenashev
Copy link
Member

@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

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

Successfully merging this pull request may close these issues.

Support for loading mapping files from 'mappings' folder by default
2 participants