Class WireMockWebTestClient


  • public final class WireMockWebTestClient
    extends Object
    Convenience class for setting up RestDocs to record WireMock stubs. Example usage:
     @RunWith(SpringRunner.class)
     @SpringBootTest
     @AutoConfigureRestDocs(outputDir = "target/snippets")
     @AutoConfigureWebTestClient
     public class WiremockServerRestDocsApplicationTests {
    
            @Autowired
            private WebTestClient client;
    
            @Test
            public void contextLoads() throws Exception {
                    client.get().uri("/resource").exchange()
                                    .expectBody(String.class).isEqualTo("Hello World")
                                    .consumeWith(verify().stub("resource"));
            }
     
    which creates a file "target/snippets/stubs/resource.json" matching any GET request to "/resource". To match POST and PUT, you can also specify the content type using verify().contentType(...) and JSON content of the body using verify().jsonPath(...).
    Author:
    Dave Syer