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

Add WireMock Spring Boot to the Solutions page #187

Merged
merged 1 commit into from
Sep 29, 2023
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
47 changes: 45 additions & 2 deletions _docs/solutions/spring-boot.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
---
layout: solution
title: "Using with Spring Boot"
title: "Using WireMock with Spring Boot"
meta_title: Running WireMock with Spring Boot | WireMock
toc_rank: 116
description: The team behind Spring Cloud Contract have created a library to support running WireMock using the “ambient” HTTP server
redirect_from: "/docs/spring-boot.html"
redirect_from:
- "/docs/spring-boot.html"
logo: /images/logos/technology/spring.svg
---

## WireMock Spring Boot

[WireMock Spring Boot](https://github.com/maciejwalkowiak/wiremock-spring-boot)
simplifies testing HTTP clients in Spring Boot & Junit 5 based integration tests.
It includes fully declarative WireMock setup,
supports multiple `WireMockServer` instances,
automatically sets Spring environment properties,
and does not pollute Spring application context with extra beans.

Example:

```java
@SpringBootTest
@EnableWireMock({
@ConfigureWireMock(name = "user-service", property = "user-client.url")
})
class TodoControllerTests {

@InjectWireMock("user-service")
private WireMockServer wiremock;

@Autowired
private Environment env;

@Test
void aTest() {
// returns a URL to WireMockServer instance
env.getProperty("user-client.url");
wiremock.stubFor(stubFor(get("/todolist").willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody("""
[
{ "id": 1, "userId": 1, "title": "my todo" },
]
""")
)));
}
}
```

## Spring Cloud Contract

The team behind Spring Cloud Contract have created a library to support running WireMock using the "ambient" HTTP server.
It also simplifies some aspects of configuration and eliminates some common issues that occur when running Spring Boot and WireMock together.

Expand Down