Skip to content
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

GH-28: add support for multiple property injection (updated README.md) #31

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,58 @@ WireMock extensions can be registered independently with each `@ConfigureWireMoc
@ConfigureWireMock(name = "...", property = "...", extensions = { ... })
```

### Single vs Multiple Property Injection

The concept of single property injection can be described as wiring _one_ `WireMockServer` to _one_ property.

```java
@SpringBootTest
@EnableWireMock({
@ConfigureWireMock(name = "foo-service", property = "app.client-apis.foo.base-path"}),
@ConfigureWireMock(name = "bar-service", property = "app.client-apis.bar.base-path"}),
@ConfigureWireMock(name = "mojo-service", property = "app.client-apis.mojo.base-path"})
})
class AppIT {
@InjectWireMock("foo-service")
private WireMockServer fooService;
@InjectWireMock("bar-service")
private WireMockServer barService;
@InjectWireMock("mojo-service")
private WireMockServer mojoService;

@Test
void contextLoads() {
// your test code
}
}
```

The concept of multiple property injection can be described as wiring _one_ `WireMockServer` to _multiple_ properties.

```java
@SpringBootTest
@EnableWireMock({
@ConfigureWireMock(name = "services", property = {
"app.client-apis.foo.base-path",
"app.client-apis.bar.base-path",
"app.client-apis.mojo.base-path"})
})
class AppIT {

@InjectWireMock("services")
private WireMockServer services;

@Test
void contextLoads() {
// your test code
}
}
```

The *single* property injection provides a high level of isolation when mocking and stubbing 3rd pary RESTful api, because every service
is associated to its own dedicated `WireMockServer` instance.
The *multiple* property injections provides a less complex test setup at the cost of isolation.

### Customizing mappings directory

By default, each `WireMockServer` is configured to load mapping files from a classpath directory `wiremock/{server-name}/mappings`.
Expand Down