Skip to content

Commit

Permalink
GH-28: add support for multiple property injection (updated README.md) (
Browse files Browse the repository at this point in the history
#31)

* GH-28: add support for multiple property injection

* GH-28: add support for multiple property injection
  • Loading branch information
rfelgent authored Apr 2, 2024
1 parent 4a85af0 commit d9fc958
Showing 1 changed file with 52 additions and 0 deletions.
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

0 comments on commit d9fc958

Please sign in to comment.