https://github.com/xdev-software/mockserver-neolight
A lightweight rewrite of the MockServer project with focus on simplicity, maintainability and Testcontainers
https://github.com/xdev-software/mockserver-neolight
java mock-server mockserver proxy testcontainers
Last synced: 2 months ago
JSON representation
A lightweight rewrite of the MockServer project with focus on simplicity, maintainability and Testcontainers
- Host: GitHub
- URL: https://github.com/xdev-software/mockserver-neolight
- Owner: xdev-software
- License: apache-2.0
- Created: 2024-05-17T11:58:57.000Z (almost 2 years ago)
- Default Branch: develop
- Last Pushed: 2025-02-24T04:11:39.000Z (about 1 year ago)
- Last Synced: 2025-02-25T14:55:55.740Z (about 1 year ago)
- Topics: java, mock-server, mockserver, proxy, testcontainers
- Language: Java
- Homepage:
- Size: 2.95 MB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
[](https://mvnrepository.com/artifact/software.xdev.mockserver/client)
[](https://hub.docker.com/r/xdevsoftware/mockserver)
[](https://github.com/xdev-software/mockserver-neolight/actions/workflows/check-build.yml?query=branch%3Adevelop)
#
MockServer NeoLight
A lightweight rewrite of the abandoned [MockServer project](https://github.com/mock-server/mockserver) with focus on simplicity, maintainability and [Testcontainers](https://java.testcontainers.org/).
> [!NOTE]
> The full list of changes can be found in the [changelog](./CHANGELOG.md#100).
> You may also have a look at the [comparison with other frameworks](./COMPARISON.md).
## Usage
### In combination with Testcontainers
Besides a few differences the usage is mostly identical to the original project.
```java
try(MockServerContainer container = new MockServerContainer())
{
container.start();
try(MockServerClient client = new MockServerClient(
container.getHost(),
container.getServerPort()))
{
String expectedResponse = "Test";
// Setup expectation
client.when(request("/test").withMethod("GET"))
.respond(response().withBody(expectedResponse));
HttpClient httpClient = HttpClient.newHttpClient();
// Execute request
HttpResponse resp = httpClient.send(
HttpRequest.newBuilder()
.uri(URI.create(container.getEndpoint() + "/test"))
.GET()
.build(),
HttpResponse.BodyHandlers.ofString());
assertEquals(expectedResponse, resp.body());
}
}
```
Example using forwarding/recording
```java
try(MockServerContainer container = new MockServerContainer())
{
container.start();
try(MockServerClient client = new MockServerClient(
container.getHost(),
container.getServerPort()))
{
// Setup forwarding
client.when(request("/"))
.forward(HttpForward.forward().withHost("my-nginx.local"));
HttpClient httpClient = HttpClient.newHttpClient();
// Execute request
HttpResponse resp = httpClient.send(
HttpRequest.newBuilder()
.uri(URI.create(container.getEndpoint() + "/"))
.GET()
.build(),
HttpResponse.BodyHandlers.ofString());
assertTrue(resp.body().contains("Welcome to nginx!"));
// You can also retrieve requests, expectations and responses
String recorded =
client.retrieveRecordedRequestsAndResponses(request("/"), Format.JSON);
// or generate the code for writing them
String codeToGenerateExpectation =
client.retrieveRecordedExpectations(request("/"), Format.JAVA);
}
}
```
The returned ``codeToGenerateExpectation`` will look like this:
```java
new MockServerClient("localhost", 1080)
.when(
request()
.withMethod("GET")
.withPath("/")
...,
Times.once(),
TimeToLive.unlimited(),
0
)
.respond(
response()
.withStatusCode(200)
.withReasonPhrase("OK")
.withHeaders(...)
.withBody("\n\n\nWelcome to nginx!...")
);
```
Required dependencies in pom.xml
```xml
software.xdev.mockserver
client
...
test
software.xdev.mockserver
testcontainers
...
test
```
### Further related documentation
* [Original project](https://www.mock-server.com/)
* [Testcontainers (original) Mockserver module](https://java.testcontainers.org/modules/mockserver/)
Note: MockServer also works really well together with a network failure simulation tools such as [ToxiProxy](https://java.testcontainers.org/modules/toxiproxy/).
## Installation
[Installation guide for the latest release](https://github.com/xdev-software/mockserver-neolight/releases/latest#Installation)
Module
Distribution via
client
server
testcontainers
## Support
If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support).
## Contributing
See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how to get started with our project.
## Dependencies and Licenses
View the [license of the current project](LICENSE) or the [docs that contain a dependency summary (per module)](https://xdev-software.github.io/mockserver-neolight/)