Hoverfly Java
Hoverfly Java is a native Java language binding for Hoverfly.
If you are using Maven, add the dependency to your pom.xml
<dependency>
<groupId>io.specto</groupId>
<artifactId>hoverfly-java</artifactId>
<version>0.14.1</version>
<scope>test</scope>
</dependency>
If you are using Gradle, add the dependency to your *.gradle file
testCompile "io.specto:hoverfly-java:0.14.1"
Quickstart
public class HoverflyExample {
@ClassRule
public static HoverflyRule hoverflyRule = HoverflyRule.inSimulationMode(dsl(
service("www.my-test.com")
.get("/api/bookings/1")
.willReturn(success("{\"bookingId\":\"1\"}", "application/json"))
));
@Test
public void shouldBeAbleToGetABookingUsingHoverfly() {
// When
final ResponseEntity<String> getBookingResponse = restTemplate.getForEntity("http://www.my-test.com/api/bookings/1", String.class);
// Then
assertThat(getBookingResponse.getStatusCode()).isEqualTo(OK);
assertThatJSON(getBookingResponse.getBody()).isEqualTo("{"\"bookingId\":\"1\"}");
}
// Continues...
Next steps