Contract contractDsl = Contract.make {
+ request {
+ method 'GET'
+ url '/something'
+ body(
+ $(c("foo"), p(execute("hashCode()")))
+ )
+ }
+ response {
+ status 200
+ }
+}
+diff --git a/spring-cloud-contract.html b/spring-cloud-contract.html index 208453a0c9..a33374e267 100644 --- a/spring-cloud-contract.html +++ b/spring-cloud-contract.html @@ -7310,6 +7310,60 @@ JSON path:
+In the request part of the contract you can specify that the body should be
+taken from a method.
|
+ Important
+ |
+
+You have to provide both the consumer and the producer side
+and the execute part can be applied for the whole body. Not for parts of it!
+ |
+
Example:
+Contract contractDsl = Contract.make {
+ request {
+ method 'GET'
+ url '/something'
+ body(
+ $(c("foo"), p(execute("hashCode()")))
+ )
+ }
+ response {
+ status 200
+ }
+}
+This will result in calling the hashCode() method in the request body.
+It would more or less like this:
// given:
+ MockMvcRequestSpecification request = given()
+ .body(hashCode());
+
+// when:
+ ResponseOptions response = given().spec(request)
+ .get("/something");
+
+// then:
+ assertThat(response.statusCode()).isEqualTo(200);
+