getConfiguration(T result);
+
+ @SuppressWarnings("unchecked")
+ public S wiremock(MappingBuilder builder) {
+ this.builder = builder;
+ return (S) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public S jsonPath(String expression, Object... args) {
+ compile(expression, args);
+ return (S) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public S contentType(MediaType contentType) {
+ this.contentType = contentType;
+ return (S) this;
+ }
+
+ private void compile(String expression, Object... args) {
+ org.springframework.util.Assert.hasText((expression == null ? null : expression),
+ "expression must not be null or empty");
+ expression = String.format(expression, args);
+ this.jsonPaths.put(expression, JsonPath.compile(expression));
+ }
+
+}
diff --git a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockWebTestClient.java b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockWebTestClient.java
new file mode 100644
index 0000000000..2693a26580
--- /dev/null
+++ b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockWebTestClient.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2012-2015 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.contract.wiremock.restdocs;
+
+/**
+ * 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
+ *
+ */
+public class WireMockWebTestClient {
+
+ public static ContractExchangeHandler verify() {
+ return new ContractExchangeHandler();
+ }
+
+}
diff --git a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockWebTestClientConfiguration.java b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockWebTestClientConfiguration.java
new file mode 100644
index 0000000000..685e9a9b7a
--- /dev/null
+++ b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockWebTestClientConfiguration.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2012-2015 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.contract.wiremock.restdocs;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.test.autoconfigure.restdocs.RestDocsWebTestClientConfigurationCustomizer;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentationConfigurer;
+
+/**
+ * Custom configuration for Spring RestDocs that adds a WireMock snippet (for generating
+ * JSON stubs). Applied automatically if you use
+ * {@link org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs @AutoConfigureRestDocs}
+ * in your test case and this class is available. JSON stubs are generated and added to
+ * the restdocs path under "stubs".
+ *
+ * @see WireMockRestDocs for a convenient entry point for customizing and asserting the
+ * stub behaviour
+ *
+ * @author Dave Syer
+ *
+ */
+@Configuration
+@ConditionalOnClass(WebTestClientRestDocumentationConfigurer.class)
+public class WireMockWebTestClientConfiguration
+ implements RestDocsWebTestClientConfigurationCustomizer {
+
+ @Override
+ public void customize(WebTestClientRestDocumentationConfigurer configurer) {
+ configurer.snippets().withAdditionalDefaults(new WireMockSnippet());
+ }
+
+}
diff --git a/spring-cloud-contract-wiremock/src/main/resources/META-INF/spring.factories b/spring-cloud-contract-wiremock/src/main/resources/META-INF/spring.factories
index c0e49b7d51..3ee4bf2e9f 100644
--- a/spring-cloud-contract-wiremock/src/main/resources/META-INF/spring.factories
+++ b/spring-cloud-contract-wiremock/src/main/resources/META-INF/spring.factories
@@ -5,4 +5,5 @@ org.springframework.cloud.contract.wiremock.WireMockApplicationListener
# RestDocs Auto Configuration
org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs=\
org.springframework.cloud.contract.wiremock.restdocs.WireMockRestDocsConfiguration,\
+org.springframework.cloud.contract.wiremock.restdocs.WireMockWebTestClientConfiguration,\
org.springframework.cloud.contract.wiremock.restdocs.WireMockRestAssuredConfiguration
diff --git a/spring-cloud-contract-wiremock/src/test/java/org/springframework/cloud/contract/wiremock/WiremockServerWebTestClientApplicationTests.java b/spring-cloud-contract-wiremock/src/test/java/org/springframework/cloud/contract/wiremock/WiremockServerWebTestClientApplicationTests.java
new file mode 100644
index 0000000000..d16d6c7c44
--- /dev/null
+++ b/spring-cloud-contract-wiremock/src/test/java/org/springframework/cloud/contract/wiremock/WiremockServerWebTestClientApplicationTests.java
@@ -0,0 +1,64 @@
+package org.springframework.cloud.contract.wiremock;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
+import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
+import org.springframework.cloud.contract.wiremock.WiremockServerWebTestClientApplicationTests.TestConfiguration;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;
+
+import wiremock.org.eclipse.jetty.http.HttpStatus;
+
+@RunWith(SpringRunner.class)
+@WebFluxTest
+@ContextConfiguration(classes = TestConfiguration.class)
+@AutoConfigureRestDocs(outputDir = "target/snippets/webtestclient")
+@AutoConfigureWebTestClient
+@DirtiesContext
+public class WiremockServerWebTestClientApplicationTests {
+
+ @Autowired
+ private WebTestClient client;
+
+ @Test
+ public void contextLoads() throws Exception {
+ this.client.get().uri("/resource").exchange().expectBody(String.class)
+ .isEqualTo("Hello World").consumeWith(document("resource"));
+ }
+
+ @Test
+ public void statusIsMaintained() throws Exception {
+ this.client.get().uri("/status").exchange().expectStatus().isAccepted()
+ .expectBody(String.class).isEqualTo("Hello World")
+ .consumeWith(document("status"));
+ }
+
+ @Configuration
+ @RestController
+ protected static class TestConfiguration {
+
+ @RequestMapping("/resource")
+ public String resource() {
+ return "Hello World";
+ }
+
+ @RequestMapping("/status")
+ public ResponseEntity status() {
+ return ResponseEntity.status(HttpStatus.ACCEPTED_202).body("Hello World");
+ }
+
+ }
+
+}