Documentation Authors: Adam Dudczak, Mathias Düsterhöft, Marcin Grzejszczak, Jakub Kubryński, Karol Lassak,
+
Documentation Authors: Adam Dudczak, Mathias Düsterhöft, Marcin Grzejszczak, Dennis Kieselhorst, Jakub Kubryński, Karol Lassak,
Olga Maciaszek-Sharma, Mariusz Smykuła, Dave Syer
@@ -1139,7 +1142,7 @@ public class ApplicationTests {
public void contextLoads() throws Exception {
mockMvc.perform(post("/resource")
.content("{\"id\":\"123456\",\"message\":\"Hello World\"}"))
- .andExpect(status.isOk())
+ .andExpect(status().isOk())
.andDo(verify().jsonPath("$.id")
.stub("resource"));
}
@@ -1164,7 +1167,7 @@ created stub. Example:
public void contextLoads() throws Exception {
mockMvc.perform(post("/resource")
.content("{\"id\":\"123456\",\"message\":\"Hello World\"}"))
- .andExpect(status.isOk())
+ .andExpect(status().isOk())
.andDo(verify()
.wiremock(WireMock.post(
urlPathEquals("/resource"))
@@ -2099,7 +2102,6 @@ import org.junit.Before;
import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc;
public class FraudBase {
-
@Before
public void setup() {
RestAssuredMockMvc.standaloneSetup(new FraudDetectionController(),
@@ -2902,6 +2904,13 @@ when some incompatible changes are done.
of either Gradle or Maven plugins.
+
+
Can I reference the request from the response?
+
+
Yes! With version 1.1.0 we’ve added such a possibility. On the HTTP stub server side we’re providing support
+for this for WireMock. In case of other HTTP server stubs you’ll have to implement the approach yourself.
+
+
Spring Cloud Contract Verifier HTTP
@@ -4666,6 +4675,13 @@ public void should_start_wiremock_servers() throws Exception {
Check the Common properties for JUnit and Spring for more information on how to apply global configuration of Stub Runner.
+
Maven settings
+
+
The stub downloader honors Maven settings for a different local repository folder.
+Authentication details for repositories and profiles are currently not taken into account, so you need to specify it using the properties mentioned above.
+
+
+
Providing fixed ports
You can also run your stubs on fixed ports. You can do it in two different ways. One is to pass it in the properties, and the other via fluent API of
@@ -6911,6 +6927,186 @@ the authToken() method returns everything that you need.
+
Referencing request from response
+
+
The best situation is to provide fixed values but sometimes you need to reference a request in your response.
+In order to do this you can profit from the fromRequest() method that allows you to reference a bunch
+of elements from the HTTP request. You can use the following options:
+
+
+
+
+
fromRequest().url() - return the request URL
+
+
+
fromRequest().query(String key) - return the first query parameter with a given name
+
+
+
fromRequest().query(String key, int index) - return the nth query parameter with a given name
+
+
+
fromRequest().header(String key) - return the first header with a given name
+
+
+
fromRequest().header(String key, int index) - return the nth header with a given name
+
+
+
fromRequest().body() - return the full request body
+
+
+
fromRequest().body(String jsonPath) - return the element from the request that matches the JSON Path
+This feature will work only with WireMock having version greater or equal to 2.5.1. We’re using WireMock’s
+response-template response transformer. It’s using Handlebars to convert the Mustache {{{ }}} templates into
+proper values. Additionally we’re registering 2 helper functions. escapejsonbody - that escapes the request
+body in a format that can be embedded in a JSON. Another is jsonpath that for a given parameter knows how to
+find an object in the request body.
+
+
+
+
+
+
Dynamic properties in matchers sections
If you’ve been working with Pact this might seem familiar. Quite a few users