Redefining WireMock: A New Horizon of Mappings Loading Flexibility

Bharat
Deutsche Telekom Digital Labs
4 min readOct 17, 2023

Problem Statement

We faced a common challenge related to the testing process. The availability of third-party APIs was often delayed, making it difficult to conduct thorough testing of new features. Since our applications heavily relied on these APIs, this posed a significant challenge for our development and testing workflows.

We sought a solution to simulate third-party APIs, allowing us to move forward without having to wait for them to become available.

To tackle this issue, we used WireMock, a popular mocking framework, is used to simulate responses from these third party APIs. However, WireMock has inherent limitations that posed obstacles for our processes.

First and foremost, WireMock relies on adding stubs or mappings via its REST endpoints. This approach led to several issues for us. When the WireMock server was restarted, all stubs were lost, necessitating manual reconfiguration each time. This disruption not only affected our testing process but also hindered our development efforts.

Moreover, relying solely on WireMock’s REST endpoints for adding stubs and mappings made it challenging for our team to assess and manage the numerous mocks used in our applications efficiently.

To resolve these issues, we needed a solution to create a centralized repository or knowledge base for stubs and mappings, enhancing accessibility and management. Our vision was to make WireMock more versatile, allowing it to load stubs from various sources beyond a directory. This enhancement would significantly benefit our development and testing workflows, enabling us to have better control, manage, and streamline our stubs and mappings.

The Solution

To enhance WireMock’s functionality and offer a more versatile solution, we put forth to introduce a feature allowing WireMock to load mocks from various sources beyond a directory. This proposed enhancement aimed to enable users to specify their preferred `MappingsLoader` implementation, providing the ability to load mocks from diverse sources like Git repositories, S3, and more.

Custom MappingsLoader implementation

The primary objective of this enhancement was to extend WireMock’s capabilities and offer a more flexible approach for loading mappings. The envisioned feature would allow developers to create custom `MappingsLoader` implementations tailored to their specific use cases. This would empower them to fetch mappings from sources beyond a directory, such as Git repositories or other external platforms.

Benefits of the Enhancement

The proposed enhancement offered several advantages to the open-source community and developers utilizing WireMock:

  1. Diverse Mapping Sources: Developers could now fetch mocks from a variety of sources, enhancing flexibility and easing the integration of WireMock into their existing workflows.
  2. Centralized Repository of Mocks/ Stubs: The enhancement allows for the creation of a centralized repository for all mocks and stubs, streamlining access and management.
  3. Version Control via Git Repositories: Mocks can now be versioned and managed effectively using Git repositories, enabling tracking and reverting to previous versions if needed.
  4. Control and Audit on Changes in Mocks: The ability to load mocks from external sources like Git repositories provides better control and audit capabilities, ensuring a more structured and organized approach to mock management.
  5. Community Contributions: By allowing the community to contribute alternative `MappingsLoader` implementations, WireMock became a more powerful and adaptable tool for a broader range of use cases.

The enhancement proposal included extending WireMock through an additional extension point to enable loading mappings from different sources. By implementing the `MappingsLoader` interface, developers could define their logic to load mappings from sources like Git repositories.

Example

Imagine a scenario where a development team is collaborating on a project and needs to mock responses from a Git repository due to ongoing developments in a third-party API. With the enhanced WireMock, they can easily define a MappingsLoader implementation that fetches mappings from a Git repository. This allows for seamless integration of mock responses from the repository, enabling uninterrupted development and testing.

The enhancement to WireMock, allowing for flexible mappings loading, stands as a testament to the open-source community’s collaborative efforts. By embracing this change, WireMock has become a more adaptable tool, capable of meeting a wider array of mocking requirements. This enhancement encourages developers to extend WireMock according to their needs, fostering a more diverse and innovative ecosystem in the world of mocking frameworks.

Extending WireMock for Mapping Loading for a comprehensive guide on extending WireMock to load stub mappings from various sources, refer to the official WireMock documentation: Extending WireMock to Load Stub Mappings.

Embracing the Change: The Community’s Response

This proposal was well-received by the WireMock community, and a pull request (WireMock Enhancement PR) was created to introduce the proposed enhancement. The PR went through the rigorous review process, and after necessary iterations, it was successfully merged into the WireMock repository.

--

--