A convenience library for working with rebound in the jvm.
Please visit rebound for details on the rebound mock server and it's API.
Include the dependency in your build:
<dependency>
<groupId>io.pileworx</groupId>
<artifactId>rebound-client-java</artifactId>
<version>0.2.0</version>
</dependency>
Create an instance of the client
String reboundHost = "http://localhost:8585";
ReboundRestClient client = ReboundRestClient.create(reboundHost);
Defining a mock:
Mock mock = new DefineMock().with(m -> {
m.scenario = "Test Scenario";
m.when = new DefineRequest().with(req -> {
req.method = Method.GET;
req.path = "/foo";
req.query = "foo=bar&bar=baz";
req.headers = Header.of("Accept", "application/hal+json");
req.body = "{\"foo\":\"bar\"}";
}).build();
m.then = List.of(
new DefineResponse().with(resp1 -> {
resp1.status = 200;
resp1.headers = Header.of("Content-Type", "application/json");
resp1.body = "[#foreach($i in [1..5]){\"propertyName\":\"this is my value\"} #if($foreach.count != 5), #end #end]";
}).build(),
new DefineResponse().with(resp2 -> {
resp2.status = 200;
resp2.headers = Header.of("Content-Type", "application/json");
resp2.bodyFromFile = Paths.get("./src/test/java/io/pileworx/rebound/client/velocity.vm");
resp2.values = Map.of("myValue", "this is my value");
}).build()
);
}).build();
If one response is supplied, it will be returned on every matching request. If a list is supplied, they will return in order. After the last response is returned following requests will result in error. Response Body support velocity templates. They can be defined inline or from a vm file. For more info please see Velocity. For more info on each of the properties, please see the rebound documentation at rebound.
Then you can add the mock to the server:
Status status = client.createMock(mock);
In your teardown, you can reset the mock server like this.
Status status = client.clearMocks();