Contract contractDsl = Contract.make {
+ request {
+ method 'GET'
+ url '/something'
+ body(
+ $(c("foo"), p(execute("hashCode()")))
+ )
+ }
+ response {
+ status 200
+ }
+}
+From ef87f0115a5ae44348ed83bbaadd037d94767653 Mon Sep 17 00:00:00 2001
From: buildmaster
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);
+