Rebound Java Client

Client library for rebound mock server

License

License

Categories

Categories

Java Languages CLI User Interface
GroupId

GroupId

io.pileworx
ArtifactId

ArtifactId

rebound-client-java
Last Version

Last Version

0.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

Rebound Java Client
Client library for rebound mock server
Project URL

Project URL

https://github.com/pileworx/rebound-client-java
Source Code Management

Source Code Management

https://github.com/pileworx/rebound-client-java

Download rebound-client-java

How to add to project

<!-- https://jarcasting.com/artifacts/io.pileworx/rebound-client-java/ -->
<dependency>
    <groupId>io.pileworx</groupId>
    <artifactId>rebound-client-java</artifactId>
    <version>0.2.1</version>
</dependency>
// https://jarcasting.com/artifacts/io.pileworx/rebound-client-java/
implementation 'io.pileworx:rebound-client-java:0.2.1'
// https://jarcasting.com/artifacts/io.pileworx/rebound-client-java/
implementation ("io.pileworx:rebound-client-java:0.2.1")
'io.pileworx:rebound-client-java:jar:0.2.1'
<dependency org="io.pileworx" name="rebound-client-java" rev="0.2.1">
  <artifact name="rebound-client-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.pileworx', module='rebound-client-java', version='0.2.1')
)
libraryDependencies += "io.pileworx" % "rebound-client-java" % "0.2.1"
[io.pileworx/rebound-client-java "0.2.1"]

Dependencies

compile (3)

Group / Artifact Type Version
com.konghq : unirest-java jar 3.7.02
com.fasterxml.jackson.core : jackson-databind jar 2.9.8
com.fasterxml.jackson.core : jackson-annotations jar 2.9.8

test (4)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-core jar 2.23.0
org.hamcrest : hamcrest-core jar 1.3
org.hamcrest : hamcrest-library jar 1.3

Project Modules

There are no modules declared in this project.

rebound-client-java

A convenience library for working with rebound in the jvm.

Build Status Codacy Badge Codacy Badge

Please visit rebound for details on the rebound mock server and it's API.

Usage

Include the dependency in your build:

<dependency>
  <groupId>io.pileworx</groupId>
  <artifactId>rebound-client-java</artifactId>
  <version>0.2.0</version>
</dependency>

API

Create an instance of the client

String reboundHost = "http://localhost:8585";
ReboundRestClient client = ReboundRestClient.create(reboundHost);

Mocking

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);

Teardown

In your teardown, you can reset the mock server like this.

Status status = client.clearMocks();
io.pileworx

pileworx

Versions

Version
0.2.1
0.2.0