Java binding for Hoverfly

Overview

Hoverfly Java - Easy Creation of Stub Http Servers for Testing

CircleCI Read the Docs Codecov Known Vulnerabilities Maven Central

A Java native language binding for Hoverfly, a Go proxy which allows you to simulate http services in your unit tests. Another term for this is Service Virtualisation.

Features

  • Simulation of http/https services

  • Strict or loose http request matching based on URL, method, body and header combinations

  • Fluent and expressive DSL for easy generation of simulated services

  • Automatic marshalling of objects into JSON during request / response body generation

  • Create simulations by capturing live traffic

  • Hoverfly is a proxy, so you don’t need to alter the host that you make requests to

  • Multiple hosts / services per single instance of Hoverfly

  • Https automatically supported, no extra configuration required

  • Supports Mutual TLS authentication capture

  • Interoperable with standard Hoverfly JSON, making it easy to re-use data between Java and other native language bindings.

  • Use externally managed Hoverfly cluster for API simulations

  • Request verification

  • Response templating

  • Stateful capture / simulation

  • JUnit 5 extension

Documentation

Full documentation is available here

Maven Dependency

<dependency>
    <groupId>io.specto</groupId>
    <artifactId>hoverfly-java</artifactId>
    <version>0.14.0</version>
    <scope>test</scope>
</dependency>

Example

Create API simulation using capture mode

// Capture and output HTTP traffic to json file
@ClassRule
public static HoverflyRule hoverflyRule = HoverflyRule.inCaptureMode("simulation.json");


// After the capturing, switch to inSimulationMode to spin up a stub server
@ClassRule
public static HoverflyRule hoverflyRule = HoverflyRule.inSimulationMode(defaultPath("simulation.json"));

// Or you can use both approaches at once. If json file not present in capture mode, if present in simulation mode
@ClassRule
public static HoverflyRule hoverflyRule = HoverflyRule.inCaptureOrSimulationMode("simulation.json");

Create API simulation using DSL

@ClassRule
public static HoverflyRule hoverflyRule = HoverflyRule.inSimulationMode(dsl(
    service("www.my-test.com")
        .get("/api/bookings/1")
        .willReturn(created("http://localhost/api/bookings/1"))
));

@Test
public void shouldBeAbleToGetABookingUsingHoverfly() {
    // When
    final ResponseEntity<String> getBookingResponse = restTemplate.getForEntity("http://www.my-test.com/api/bookings/1", String.class);

    // Then
    assertEquals(bookFlightResponse.getStatusCode(), CREATED);
    assertEquals(bookFlightResponse.getHeaders().getLocation(), "http://localhost/api/bookings/1");
}

Some code examples for the DSL are available here.

More code examples for the DSL using request matchers can be found here.

Verify requests

// Verify that at least one request to a specific endpoint with any query params
hoverflyRule.verify(service(matches("*.flight.*")).get("/api/bookings").anyQueryParams(), atLeastOnce());

// Verify that an external service/dependency was not called
hoverflyRule.verifyZeroRequestTo(service(matches("*.flight.*")));

// Verify all the stubbed requests were made at least once
hoverflyRule.verifyAll();

Contributions

Contributions are welcome!

To submit a pull request you should fork the Hoverfly-Java repository, and make your change on a feature branch of your fork.

As of v0.10.2, hoverfly binaries are no longer stored in the repository. You should run ./gradlew clean test once to cache the binaries for development with your IDE.

If you have forked this project prior to v0.10.2, please re-fork to get a slimmer version of the repository.

Issues

Feel free to raise an issues on Github.

License

Apache License version 2.0.

(c) SpectoLabs 2020.

Comments
  • [WiP] Adds JUnit5 extension for Hoverfly Core integration

    [WiP] Adds JUnit5 extension for Hoverfly Core integration

    This is only first implementation to start discussing. When we agree with this basis then I implement the extension for automatic Simulate and automatic Capture.

    opened by lordofthejars 22
  • not able to simulate the test case. its always capture the response

    not able to simulate the test case. its always capture the response

    package Junit;

    import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import java.util.Set; import static io.specto.hoverfly.junit.core.HoverflyConfig.localConfigs; import static io.specto.hoverfly.junit.core.HoverflyMode.*; import static io.specto.hoverfly.junit.core.SimulationSource.file;

    import io.restassured.RestAssured; import io.restassured.specification.RequestSpecification; import io.restassured.response.Response; import io.specto.hoverfly.junit.core.HoverflyConfig; import io.specto.hoverfly.junit.core.model.; import io.specto.hoverfly.junit.dsl.StubServiceBuilder; import io.specto.hoverfly.junit.dsl.; import io.specto.hoverfly.junit.rule.HoverflyRule; import io.specto.hoverfly.junit.core.config.; import io.specto.hoverfly.junit.verification.; import io.specto.hoverfly.junit.dsl.matchers.; import io.specto.hoverfly.junit.api.; import org.junit.Test; import static org.junit.Assert.assertEquals;

    import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Rule; import org.junit.rules.*;

    public class test {

    // @Autowired // LoginController lcontroller;

    @ClassRule
    public static HoverflyRule hoverflyRule = HoverflyRule
    		.inCaptureOrSimulationMode("response.json", HoverflyConfig.localConfigs().proxyLocalHost())
    	    .printSimulationData();
    
    
    @Test
    

    public void test2(){

    	RestAssured.baseURI = "http://time.jsontest.com/";
    	//RestAssured.baseURI = "http://restapi.demoqa.com/utilities/weather/city/Hyderabad";
    	
        Response res;
    	res=RestAssured.given()
    
    	.relaxedHTTPSValidation()
    
    	.when()
    
    	.get()
    	
    	.then()
    
    	.contentType("application/json")
    
    	.and()
    
    	.extract().response();
    
    	String responseBodyGet=res.asString();    
    	System.out.println("Response body: "+responseBodyGet);
    }
    
    
    @Test
    public void test4(){
    		
    		RestAssured.baseURI = "https://jsonplaceholder.typicode.com/todos/1";
    		//RestAssured.baseURI = "http://restapi.demoqa.com/utilities/weather/city/Hyderabad";
    		
            Response res;
    		res=RestAssured.given()
    
    		.relaxedHTTPSValidation()
    
    		.when()
    
    		.get()
    		
    		.then()
    
    		.contentType("application/json")
    
    		.and()
    
    		.extract().response();
    
    		String responseBodyGet=res.asString();    
    		System.out.println("Response body: "+responseBodyGet);
    	}
    

    i }

    bug 
    opened by antika08 18
  • Hoverfly has not become healthy in 10 seconds while running on an environment connected to a VPN

    Hoverfly has not become healthy in 10 seconds while running on an environment connected to a VPN

    Description of the bug

    run test in jdk 11 and junit5 in a springboot project

    import io.specto.hoverfly.junit.core.Hoverfly;
    import io.specto.hoverfly.junit5.HoverflyExtension;
    import org.junit.jupiter.api.extension.ExtendWith;
    
    @ExtendWith(HoverflyExtension.class)
    public class Test extends DemoApplicationTests {
      
      @org.junit.jupiter.api.Test
      public void test(Hoverfly hoverfly){
    
      }
    }
    

    Observed result

    18:31:05.530 [Test worker] INFO io.specto.hoverfly.junit.core.TempFileManager - Selecting the following binary based on the current operating system: hoverfly_OSX_amd64
        18:31:05.532 [Test worker] INFO io.specto.hoverfly.junit.core.TempFileManager - Storing binary in temporary directory /var/folders/68/3_sx_12x691cqbfh35w148hr0000gq/T/hoverfly.4183811405764542695/hoverfly_OSX_amd64
        18:31:05.659 [Test worker] INFO io.specto.hoverfly.junit.core.Hoverfly - Executing binary at /var/folders/68/3_sx_12x691cqbfh35w148hr0000gq/T/hoverfly.4183811405764542695/hoverfly_OSX_amd64
        18:31:05.665 [Test worker] DEBUG org.zeroturnaround.exec.ProcessExecutor - Executing [/var/folders/68/3_sx_12x691cqbfh35w148hr0000gq/T/hoverfly.4183811405764542695/hoverfly_OSX_amd64, -pp, 62476, -ap, 62477, -logs, json] in /var/folders/68/3_sx_12x691cqbfh35w148hr0000gq/T/hoverfly.4183811405764542695.
        18:31:05.798 [Test worker] DEBUG org.zeroturnaround.exec.ProcessExecutor - Started Process[pid=31563, exitValue="not exited"]
        18:31:05.816 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:05.919 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:05.952 [Thread-4] INFO hoverfly - Default proxy port has been overwritten port=62476
        18:31:05.953 [Thread-4] INFO hoverfly - Default admin port has been overwritten port=62477
        18:31:05.953 [Thread-4] INFO hoverfly - Using memory backend 
        18:31:05.953 [Thread-4] INFO hoverfly - Proxy prepared... Destination=. Mode=simulate ProxyPort=62476
        18:31:05.953 [Thread-4] INFO hoverfly - current proxy configuration destination=. mode=simulate port=62476
        18:31:05.953 [Thread-4] INFO hoverfly - serving proxy 
        18:31:05.954 [Thread-4] INFO hoverfly - Admin interface is starting... AdminPort=62477
        18:31:06.022 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:06.125 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:06.230 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:06.332 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:06.434 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:06.538 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:06.644 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:06.747 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:06.851 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:06.953 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:07.060 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:07.166 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:07.268 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:07.372 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:07.477 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:07.579 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:07.681 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:07.782 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:07.888 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:07.992 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:08.096 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:08.197 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:08.300 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:08.405 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:08.510 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:08.614 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:08.720 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:08.826 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:08.927 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:09.032 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:09.134 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:09.239 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:09.341 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:09.446 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:09.552 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:09.653 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:09.755 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:09.860 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:09.964 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:10.067 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:10.173 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:10.278 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:10.381 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:10.485 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:10.589 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:10.695 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:10.800 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:10.902 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:11.004 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:11.110 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:11.214 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:11.315 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:11.419 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:11.526 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:11.628 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:11.729 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:11.835 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:11.937 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:12.040 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:12.145 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:12.250 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:12.356 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:12.459 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:12.563 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:12.667 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:12.772 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:12.879 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:12.981 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:13.085 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:13.191 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:13.296 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:13.400 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:13.501 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:13.608 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:13.713 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:13.818 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:13.921 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:14.026 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:14.129 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:14.232 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:14.333 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:14.434 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:14.541 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:14.646 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:14.751 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:14.858 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:14.963 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:15.065 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:15.167 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:15.271 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:15.376 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:15.477 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:15.579 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:15.685 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:15.787 [Test worker] DEBUG io.specto.hoverfly.junit.api.HoverflyClient - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62477
        18:31:15.891 [Test worker] INFO io.specto.hoverfly.junit.core.Hoverfly - Destroying hoverfly process
        18:31:15.892 [WaitForProcess-Process[pid=31563, exitValue="not exited"]] DEBUG org.zeroturnaround.exec.WaitForProcess - Process[pid=31563, exitValue=143] stopped with exit code 143
        18
    
    18:31:15.891 [Test worker] INFO io.specto.hoverfly.junit.core.Hoverfly - Destroying hoverfly process
    18:31:15.892 [WaitForProcess-Process[pid=31563, exitValue="not exited"]] DEBUG org.zeroturnaround.exec.WaitForProcess - Process[pid=31563, exitValue=143] stopped with exit code 143
    18:31:15.896 [Test worker] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - After test class: context [DefaultTestContext@209ad819 testClass = Test, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@625e6f76 testClass = Test, locations = '{}', classes = '{class com.example.demo.DemoApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@16a01d9c, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@326e6f60, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@78d9803c, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@16a6a53a], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]], class annotated with @DirtiesContext [false] with mode [null].
    Gradle Test Executor 6 finished executing tests.
    > Task :test FAILED
    
    Hoverfly has not become healthy in 10 seconds
    java.lang.IllegalStateException: Hoverfly has not become healthy in 10 seconds
    	at io.specto.hoverfly.junit.core.Hoverfly.waitForHoverflyToBecomeHealthy(Hoverfly.java:543)
    	at io.specto.hoverfly.junit.core.Hoverfly.start(Hoverfly.java:145)
    	at io.specto.hoverfly.junit5.HoverflyExtension.beforeAll(HoverflyExtension.java:114)
    	at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeBeforeAllCallbacks$4(ClassTestDescriptor.java:213)
    	at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
    	at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeBeforeAllCallbacks(ClassTestDescriptor.java:213)
    	at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:148)
    	at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:61)
    	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:132)
    	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    	at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
    	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
    	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
    	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
    	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
    	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
    	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
    	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
    	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    	at com.sun.proxy.$Proxy2.stop(Unknown Source)
    	at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:132)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:413)
    	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    	at java.base/java.lang.Thread.run(Thread.java:834)
    
    Test > initializationError FAILED
        java.lang.IllegalStateException: Hoverfly has not become healthy in 10 seconds
    

    version info

    plugins {
        id 'org.springframework.boot' version '2.2.0.RELEASE'
        id 'io.spring.dependency-management' version '1.0.10.RELEASE'
        id 'java'
    }
    
    group = 'com.example'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = '8'
    
    repositories {
        mavenCentral()
    }
    
    
    
    dependencies {
    
        implementation 'org.springframework.boot:spring-boot-starter'
        testImplementation('org.springframework.boot:spring-boot-starter-test') {
            exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
        }
        testImplementation("org.junit.platform:junit-platform-launcher:1.0.1")
        testImplementation("org.junit.jupiter:junit-jupiter-engine:5.0.1")
        testImplementation("io.specto:hoverfly-java-junit5:0.13.0")
        testImplementation("org.junit.platform:junit-platform-launcher:1.0.1")
        compile group: 'org.junit.platform', name: 'junit-platform-gradle-plugin', version: '1.0.3'
    
    }
    
    test {
        useJUnitPlatform{
            includeEngines 'junit-jupiter', 'junit-vintage'
        }
    }
    
    
    bug 
    opened by Lin-Liang 13
  • Add support for Diff mode in JUnit 5

    Add support for Diff mode in JUnit 5

    Add support for Diff mode in JUnit 5 so you can use annotations instead of a programmatic way.

    This implies creating two annotations @HoverflyDiff (Hoverfly hoverfly = new Hoverfly(configs(), DIFF) hoverfly.importSimulation(classpath("simulation-to-compare.json"));)

    and @HoverflyValidate ( hoverfly.assertThatNoDiffIsReported(false);)

    I am starting working on it

    enhancement 
    opened by lordofthejars 12
  • Resetting Hoverfly states

    Resetting Hoverfly states

    HoverflyRule should always start Hoverfly from a clean state, meaning that there is no existing simulation or journal.

    The following commands should also trigger a full reset:

    hoverflyRule.capture('test.json')
    hoverflyRule.simulate(classPath('test.json))
    

    In addition, HoverflyRule should provide manual reset methods:

    // delete all simulations and journal logs
    hoverflyRule.reset(); 
    
    // delete journal logs but reset simulation to the original SimulationSource
    hoverflyRule.resetToDefault(); 
    
    enhancement 
    opened by tommysitu 11
  • Runtime Exception when using WildFly Swarm + Hoverfly Java

    Runtime Exception when using WildFly Swarm + Hoverfly Java

    When running some tests using Hoverfly Java where some other JAXRS provider (like Resteasy in Wildfly Swarm) in classpath you get next exception:

    java.lang.ExceptionInInitializerError
    	at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:182)
    	at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:176)
    	at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:162)
    	at com.sun.jersey.api.client.Client.init(Client.java:343)
    	at com.sun.jersey.api.client.Client.access$000(Client.java:119)
    	at com.sun.jersey.api.client.Client$1.f(Client.java:192)
    	at com.sun.jersey.api.client.Client$1.f(Client.java:188)
    	at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    	at com.sun.jersey.api.client.Client.<init>(Client.java:188)
    	at com.sun.jersey.api.client.Client.<init>(Client.java:160)
    	at com.sun.jersey.api.client.Client.create(Client.java:673)
    	at io.specto.hoverfly.junit.core.Hoverfly.<init>(Hoverfly.java:73)
    	at io.specto.hoverfly.junit.rule.HoverflyRule.<init>(HoverflyRule.java:93)
    	at io.specto.hoverfly.junit.rule.HoverflyRule.inCaptureMode(HoverflyRule.java:142)
    	at io.specto.hoverfly.junit.rule.HoverflyRule.inCaptureMode(HoverflyRule.java:131)
    	at org.music.ServiceVirtualizationTest.<clinit>(ServiceVirtualizationTest.java:16)
    	at sun.misc.Unsafe.ensureClassInitialized(Native Method)
    	at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
    	at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142)
    	at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088)
    	at java.lang.reflect.Field.getFieldAccessor(Field.java:1069)
    	at java.lang.reflect.Field.get(Field.java:393)
    	at org.junit.runners.model.FrameworkField.get(FrameworkField.java:73)
    	at org.junit.runners.model.TestClass.getAnnotatedFieldValues(TestClass.java:230)
    	at org.junit.runners.ParentRunner.classRules(ParentRunner.java:255)
    	at org.junit.runners.ParentRunner.withClassRules(ParentRunner.java:244)
    	at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:194)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:362)
    	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
    	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:497)
    	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
    Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.jboss.resteasy.spi.ResteasyProviderFactory
    	at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:152)
    	at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:120)
    	at javax.ws.rs.core.MediaType.valueOf(MediaType.java:179)
    	at com.sun.jersey.core.header.MediaTypes.<clinit>(MediaTypes.java:65)
    	... 38 more
    Caused by: java.lang.ClassNotFoundException: org.jboss.resteasy.spi.ResteasyProviderFactory
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:264)
    	at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:114)
    	at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:207)
    	at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:135)
    	... 41 more
    

    This class of JAXRS providers might happen in other scenarios where for example tests are executed within the container. I suggest ( I can help on that) on changing client from JAXRS to one more neutral implementation like OkHttp + gson/jackson

    enhancement 
    opened by lordofthejars 11
  • Verification

    Verification

    The ability to verify requests which have been made would be useful, in a way similar to Mockito but for http. The problem stems around us being dependant on the functionality to be implemented in Hoverfly itself, although it is currently on the roadmap.

    enhancement 
    opened by mogronalol 11
  • Invalid Http response

    Invalid Http response

    It seems to be an issue using @ClassRule with https. If I run more than one test, then one of them will fail with the following exception:

    Caused by: java.io.IOException: Invalid Http response
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1606)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
      at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)
      at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:253)
    ... 34 more
    

    If I change the protocol to be http then the problem disappears.

    Using @Rule instead of @ClassRule is another work around, but brings additional overhead.

    bug 
    opened by mlundela 10
  • Can't capture the same request executed multiple times with different response.

    Can't capture the same request executed multiple times with different response.

    The test use case POST create a record ==> 201 OK a new record created with id 1 DELETE delete the record by id 1 ==> 204 OK DELETE delete the record by id 1 ==> 404 record doesn't exist

    Problem hoverfly can't capture the 2 DELETE request and so can't simulate this two HTTP requests with the same parameters and different response.

    Possible solution A solution maybe to maintain the captured test requests with an order and use that order to simulate the exact execution behavior.

    enhancement 
    opened by akhabali 10
  • RFC: Issue 193 Simulation Preprocessing

    RFC: Issue 193 Simulation Preprocessing

    This PR introduces Simulation Pre-Processing. A first usage can be seen in HoverflyConfigTest.

    This PR does not yet contain all relevant tests (especially for JUnit 4). In its current state, it is meant as RFC, to get feedback if the solution matches the Hoverfly-Java architecture. Thus follow-up commits are expected to increase the test coverage.

    Changes in detail

    hoverfly/junit/api:
    • Extended HoverflyClientException by message/cause constructor and added recommended serial version UID.
    hoverfly/junit/core:
    • Introduces SimulationPreprocessor to the configurations (Base, Local, Remote)
    • Hoverfly: Extended to apply the preprocessor prior to handing it over to the Hoverfly client instance. Required to provide an extended version of simulate in order to support instantiating nested inner non-static classes as it is quite common when you write nested JUnit 5 tests.

    New classes

    • SimulationPreprocessor: The central class for simulation preprocessing. It assumes a mutable Simulation instance which, according to the discussion in #193 is just fine. Note, that this PR will not include enhancing customization of Simulation instances, which is actually recommended if we stick to such preprocessing approaches.
    • ~SimulationPreprocessorProvider: This provider contains the algorithm of how to create an instance of SimulationPreprocessor for various scenarios. It is only required for JUnit 5 support, as we can instantiate the preprocessor in JUnit 4 directly.~
    • UnsetSimulationPreprocessor: Required as a default value for JUnit 5, as null is not a valid default for annotation parameters. Could not guess of a better solution.

    See Also

    • SpectoLabs/hoverfly-java#193
    opened by mmichaelis 9
  • Add ResponseCreator method converter from single quote to double quotes

    Add ResponseCreator method converter from single quote to double quotes

    Currently to return a success you need to skip double quotes:

    .willReturn(success("{\"bookingId\":\"1\"}", "application/json"))
    

    With small documents is ok but if it is bigger might annoying dealing with it. There are some workarounds like reading from file, but providing a method that allows you to use single quotes as double quotes might simplify things, so for example previous example could be written:

    .willReturn(successWithSingleQuotes("{'bookingId':'1'}", "application/json"))
    

    Which is quite better to read but also to write.

    I'll provide a PR.

    enhancement 
    opened by lordofthejars 9
  • Xpath Function is not working

    Xpath Function is not working

    Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

    Describe the solution you'd like A clear and concise description of what you want to happen.

    Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

    Additional context Add any other context or screenshots about the feature request here.

    New Request regarding Xpath Match

    Hi, I am trying to use XPath functions to capture value from the request and return it in the response. eg: string-length('hoverfly'), string(format-date(//Date/@ArrivalDate, '[M01]-[D01]-[Y0001]')) But it's returning blank. Can anyone help with this? Format I tried in response : {{ Request.Body "xpath" "string-length('hoverfly')" }}

    Is this possible in Hoverfly?

    opened by sheril-infy 1
  • Allow Java API access to the DiffView objects from HoverflyClient.getDiffs()

    Allow Java API access to the DiffView objects from HoverflyClient.getDiffs()

    Is your feature request related to a problem? Please describe. I currently have the problem that when the remote service returns varying, unpredictable values in responses (e.g. timestamps), Hoverfly in DIFF mode will always return a diff because only can do exact matching of actual against expected response bodies. I would like to circumvent this problem by looking at each individual diff in my Java application and check whether it's a real difference or just because some timestamps changed. However given the current Hoverfly-Java this is not possible since the only way to interact with the DIFF API is asserting that there are no diffs.

    Describe the solution you'd like Either:

    • Add a public API method in io.specto.hoverfly.junit.core.Hoverfly to give public access to the HoverflyClient::getDiffs method Or:
    • Instead of calling Assert.fail(message.toString()), where message is the combined string of all diff messages, throw a custom subclass of AssertionError that takes the individual expected/actual pairs as arguments and gives access to them to the caller that catches the excepion.

    Describe alternatives you've considered I've submitted a feature request to the spectolabs/hoverfly repo as well, as to solve the problem on the hoverfly side.

    enhancement 
    opened by zudljk 0
  • [0.14.0] Working directory doesn't seem to be relative to workspace directory

    [0.14.0] Working directory doesn't seem to be relative to workspace directory

    Description of the bug

    The working directory of the hoverfly instance seems to be located in the temproary folder instead of the workspace/project directory. And since hoverfly requires relative paths this makes it almost impossible to reliably specify your response files let alone specify them in a way that is not machine dependent.

    Instead the working directory should in the default path (src/test/resources/hoverfly) or where the simulation file is so relative paths can be used easily

    Steps to reproduce the issue

    Start a simulation from a simulation file. Specify a path relative to the default path or the simulation JSON.

    Example gist: https://gist.github.com/BrainStone/14b5facb30a17e3d0c658d12ba49796d

    Observed result

    Hoverfly errors out:

    [02:05:12.589][Test worker][WARN ][i.s.h.junit.api.HoverflyClient]: Failed to set simulation: Unexpected response (code=500, message={"error":"An error occurred: open test.json: The system cannot find the path specified."}{"data":{"pairs":[],"globalActions":{"delays":[],"delaysLogNormal":[]}},"meta":{"schemaVersion":"v5.1","hoverflyVersion":"v1.3.1","timeExported":"2020-11-29T02:05:12+01:00"}}
    )
    

    Expected result

    The simulation just working fine and being able to find the files.

    Additional relevant information

    • Hoverfly Java version: 0.13.2-SNAPSHOT - 0.14.0
    • OS: Windows 10

    Only way I was able to get it working was using a pseudo absolut path. So just a bunch of ../../../.. until you eventually reach the root dir, then specify the path like you would with an absolute path, excluding the drive specification on Windows (needs to be on the same drive)

    enhancement 
    opened by BrainStone 7
  • Supporting using different json files in Class/SubClass

    Supporting using different json files in Class/SubClass

    A TestBase class is commonly useful to setup shared test context . Hope Hoverfly could support this scenario below,

    Public class TestBase() { @ClassRule public static HoverflyRule logonRule = HoverflyRule.inCaptureOrSimulationMode("logon.json"); }

    public class TestA extends TestBase { @ClassRule public static HoverflyRule TestARule = HoverflyRule.inCaptureOrSimulationMode("TestA.json"); // }

    public class TestB extends TestBase { @ClassRule public static HoverflyRule TestBRule = HoverflyRule.inCaptureOrSimulationMode("TestB.json"); // }

    enhancement 
    opened by patown 3
  • `Text file busy` while running hoverfly with surefire forkmode

    `Text file busy` while running hoverfly with surefire forkmode

    Description of the bug

    Currently we run a larger testsuite from maven and used hoverfly to simulate request. Lately we switched from sequential task execution to parallel execution with surefire and fork mode. This mean we are starting up to 4 JVM processes and run those simultaneously. After the switch ones or twice a day a test run fails with the mentioned error below. It seems that two JVM trying to access the same hoverfly file.

    Steps to reproduce the issue

    Run multiple hoverfly test with surefire fork mode more then 2.

    Observed result

    Hoverfly Java and Hoverfly error messages seen (If none, say none)

    java.lang.IllegalStateException: Could not start Hoverfly process
    Caused by: org.zeroturnaround.exec.ProcessInitException: Could not execute [/tmp/hoverfly.8441131355742916126/hoverfly_linux_amd64, -pp, 34205, -ap, 45433, -logs, json] in /tmp/hoverfly.8441131355742916126. Error=26, Text file busy
    Caused by: java.io.IOException: Cannot run program "/tmp/hoverfly.8441131355742916126/hoverfly_linux_amd64" (in directory "/tmp/hoverfly.8441131355742916126"): error=26, Text file busy
    Caused by: java.io.IOException: error=26, Text file busy
    

    Expected result

    Two JVM do not share the same hoverfly binary.

    Additional relevant information

    If not indicated above:

    1. Hoverfly Java version: 0.12.2, openjdk 1.8 Update 241
    opened by datenbrille 1
  • The exe files is not signed

    The exe files is not signed

    I cant use hoverfly since the company uses a whitelist of exe-files. When I started the process of whitelisting it I noticed that the exe-files that is extracted from the jar and the hoverflyctl. is not signed and contains no details about the exe-files. This makes it impossible to whitelist hoverfly in a secure way.

    I would like the exe files inside the jar to be signed by a certificate and the details populated, it can be self signed since anything is better than nothing.

    opened by joros11 2
Owner
null
HATEOAS with HAL for Java. Create hypermedia APIs by easily serializing your Java models into HAL JSON.

hate HATEOAS with HAL for Java. Create hypermedia APIs by easily serializing your Java models into HAL JSON. More info in the wiki. Install with Maven

null 20 Oct 5, 2022
Never debug a test again: Detailed failure reports and hassle free assertions for Java tests - Power Asserts for Java

Scott Test Reporter for Maven and Gradle Get extremely detailed failure messages for your tests without assertion libraries, additional configuration

Dávid Csákvári 133 Nov 17, 2022
TCP Chat Application - Java networking, java swing

TCP-Chat-Application-in-Java TCP Chat Application - Java networking, java swing Java – Multithread Chat System Java Project on core Java, Java swing &

Muhammad Asad 5 Feb 4, 2022
A sample repo to help you handle basic auth for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to handle basic auth for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - htt

null 12 Jul 13, 2022
A sample repo to help you clear browser cache with Selenium 4 Java on LambdaTest cloud. Run your Java Selenium tests on LambdaTest platform.

How to clear browser cache with Selenium 4 Java on LambdaTest cloud Prerequisites Install and set environment variable for java. Windows - https://www

null 12 Jul 13, 2022
A sample repo to help you run automation test in incognito mode in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to run automation test in incognito mode in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - htt

null 12 Jul 13, 2022
A sample repo to help you handle cookies for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to handle cookies for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - https:

null 13 Jul 13, 2022
A sample repo to help you set geolocation for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to set geolocation for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - https

null 12 Jul 13, 2022
A sample repo to help you capture JavaScript exception for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to capture JavaScript exception for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Wi

null 12 Jul 13, 2022
A sample repo to help you find an element by text for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to find an element by text for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows

null 12 Jul 13, 2022
A sample repo to help you emulate network conditions in Java-selenium automation test on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to emulate network conditions in Java-selenium automation test on LambdaTest Prerequisites Install and set environment variable for java. Windows

null 12 Jul 13, 2022
Awaitility is a small Java DSL for synchronizing asynchronous operations

Testing asynchronous systems is hard. Not only does it require handling threads, timeouts and concurrency issues, but the intent of the test code can

Awaitility 3.3k Dec 31, 2022
Java DSL for easy testing of REST services

Testing and validation of REST services in Java is harder than in dynamic languages such as Ruby and Groovy. REST Assured brings the simplicity of usi

REST Assured 6.2k Dec 31, 2022
Library that allows tests written in Java to follow the BDD style introduced by RSpec and Jasmine.

J8Spec J8Spec is a library that allows tests written in Java to follow the BDD style introduced by RSpec and Jasmine. More details here: j8spec.github

J8Spec 45 Feb 17, 2022
A modern testing and behavioural specification framework for Java 8

Introduction If you're a Java developer and you've seen the fluent, modern specification frameworks available in other programming languages such as s

Richard Warburton 250 Sep 12, 2022
A library for setting up Java objects as test data.

Beanmother Beanmother helps to create various objects, simple and complex, super easily with fixtures for testing. It encourages developers to write m

Jaehyun Shin 113 Nov 7, 2022
Java fake data generator

jFairy by Devskiller Java fake data generator. Based on Wikipedia: Fairyland, in folklore, is the fabulous land or abode of fairies or fays. Try jFair

DevSkiller 718 Dec 10, 2022
Brings the popular ruby faker gem to Java

Java Faker This library is a port of Ruby's faker gem (as well as Perl's Data::Faker library) that generates fake data. It's useful when you're develo

DiUS Computing Pty Ltd 3.9k Dec 31, 2022