diff --git a/2.0.x/multi/multi__contract_dsl.html b/2.0.x/multi/multi__contract_dsl.html
index 7a9d31671c..65228fc61b 100644
--- a/2.0.x/multi/multi__contract_dsl.html
+++ b/2.0.x/multi/multi__contract_dsl.html
@@ -260,7 +260,7 @@ where the value can be a dynamic property (e.g. formParame
}, {
"matches" : ".*--(.*)\\r\\nContent-Disposition: form-data; name=\\"someBooleanParameter\\"\\r\\n(Content-Type: .*\\r\\n)?(Content-Length: \\\\d+\\r\\n)?\\r\\n(true|false)\\r\\n--\\\\1.*"
}, {
- "matches" : ".*--(.*)\\r\\nContent-Disposition: form-data; name=\\"file\\"; filename=\\".+\\"\\r\\n(Content-Type: .*\\r\\n)?(Content-Length: \\\\d+\\r\\n)?\\r\\n.+\\r\\n--\\\\1.*"
+ "matches" : ".*--(.*)\\r\\nContent-Disposition: form-data; name=\\"file\\"; filename=\\"[\\\\S\\\\s]+\\"\\r\\n(Content-Type: .*\\r\\n)?(Content-Length: \\\\d+\\r\\n)?\\r\\n[\\\\S\\\\s]+\\r\\n--\\\\1.*"
} ]
},
"response" : {
@@ -344,8 +344,8 @@ provide the generated string that matches the provided regular expression. For e
protected static final Pattern ANY_DATE = Pattern.compile('(\\d\\d\\d\\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])')
protected static final Pattern ANY_DATE_TIME = Pattern.compile('([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])')
protected static final Pattern ANY_TIME = Pattern.compile('(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])')
-protected static final Pattern NON_EMPTY = Pattern.compile(/.+/)
-protected static final Pattern NON_BLANK = Pattern.compile(/.*(\S+|\R).*|!^\R*$/)
+protected static final Pattern NON_EMPTY = Pattern.compile(/[\S\s]+/)
+protected static final Pattern NON_BLANK = Pattern.compile(/^\s*\S[\S\s]*/)
protected static final Pattern ISO8601_WITH_OFFSET = Pattern.compile(/([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.\d{3})?(Z|[+-][01]\d:[0-5]\d)/)
protected static Pattern anyOf(String... values){
@@ -556,7 +556,7 @@ It would more or less like this:
// then: assertThat(response.statusCode()).isEqualTo(200);
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 URLfromRequest().query(String key) - return the first query parameter with a given namefromRequest().query(String key, int index) - return the nth query parameter with a given namefromRequest().header(String key) - return the first header with a given namefromRequest().header(String key, int index) - return the nth header with a given namefromRequest().body() - return the full request bodyfromRequest().body(String jsonPath) - return the element from the request that matches the JSON PathLet’s take a look at the following contract
Contract contractDsl = Contract.make {
+of elements from the HTTP request. You can use the following options:fromRequest().url() - return the request URL and query parametersfromRequest().query(String key) - return the first query parameter with a given namefromRequest().query(String key, int index) - return the nth query parameter with a given namefromRequest().path() - return the full pathfromRequest().path(int index) - return the nth path elementfromRequest().header(String key) - return the first header with a given namefromRequest().header(String key, int index) - return the nth header with a given namefromRequest().body() - return the full request bodyfromRequest().body(String jsonPath) - return the element from the request that matches the JSON Path
Let’s take a look at the following contract
Contract contractDsl = Contract.make {
request {
method 'GET'
url('/api/v1/xxxx') {
@@ -578,6 +578,8 @@ of elements from the HTTP request. You can use the following options:1),
param: fromRequest().query("foo"),
paramIndex: fromRequest().query("foo", 1),
authorization: fromRequest().header("Authorization"),
@@ -605,15 +607,17 @@ of elements from the HTTP request. You can use the following options:"Authorization")).isEqualTo("foo secret bar");
// and:
DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
- assertThatJson(parsedJson).field("url").isEqualTo("/api/v1/xxxx");
- assertThatJson(parsedJson).field("fullBody").isEqualTo("{\"foo\":\"bar\",\"baz\":5}");
- assertThatJson(parsedJson).field("paramIndex").isEqualTo("bar2");
- assertThatJson(parsedJson).field("responseFoo").isEqualTo("bar");
- assertThatJson(parsedJson).field("authorization2").isEqualTo("secret2");
- assertThatJson(parsedJson).field("responseBaz").isEqualTo(5);
- assertThatJson(parsedJson).field("responseBaz2").isEqualTo("Bla bla bar bla bla");
- assertThatJson(parsedJson).field("param").isEqualTo("bar");
- assertThatJson(parsedJson).field("authorization").isEqualTo("secret");As you can see elements from the request have been properly referenced in the response.
The generated WireMock stub will look more or less like this:
{
+ assertThatJson(parsedJson).field("['fullBody']").isEqualTo("{\"foo\":\"bar\",\"baz\":5}");
+ assertThatJson(parsedJson).field("['authorization']").isEqualTo("secret");
+ assertThatJson(parsedJson).field("['authorization2']").isEqualTo("secret2");
+ assertThatJson(parsedJson).field("['path']").isEqualTo("/api/v1/xxxx");
+ assertThatJson(parsedJson).field("['param']").isEqualTo("bar");
+ assertThatJson(parsedJson).field("['paramIndex']").isEqualTo("bar2");
+ assertThatJson(parsedJson).field("['pathIndex']").isEqualTo("v1");
+ assertThatJson(parsedJson).field("['responseBaz']").isEqualTo(5);
+ assertThatJson(parsedJson).field("['responseFoo']").isEqualTo("bar");
+ assertThatJson(parsedJson).field("['url']").isEqualTo("/api/v1/xxxx?foo=bar&foo=bar2");
+ assertThatJson(parsedJson).field("['responseBaz2']").isEqualTo("Bla bla bar bla bla");
As you can see elements from the request have been properly referenced in the response.
The generated WireMock stub will look more or less like this:
{
"request" : {
"urlPath" : "/api/v1/xxxx",
"method" : "POST",
@@ -628,22 +632,24 @@ of elements from the HTTP request. You can use the following options:}
},
"bodyPatterns" : [ {
- "matchesJsonPath" : "$[?(@.baz == 5)]"
+ "matchesJsonPath" : "$[?(@.['baz'] == 5)]"
}, {
- "matchesJsonPath" : "$[?(@.foo == 'bar')]"
+ "matchesJsonPath" : "$[?(@.['foo'] == 'bar')]"
} ]
},
"response" : {
"status" : 200,
- "body" : "{\"url\":\"{{{request.url}}}\",\"param\":\"{{{request.query.foo.[0]}}}\",\"paramIndex\":\"{{{request.query.foo.[1]}}}\",\"authorization\":\"{{{request.headers.Authorization.[0]}}}\",\"authorization2\":\"{{{request.headers.Authorization.[1]}}}\",\"fullBody\":\"{{{escapejsonbody}}}\",\"responseFoo\":\"{{{jsonpath this '$.foo'}}}\",\"responseBaz\":{{{jsonpath this '$.baz'}}} ,\"responseBaz2\":\"Bla bla {{{jsonpath this '$.foo'}}} bla bla\"}",
+ "body" : "{\"authorization\":\"{{{request.headers.Authorization.[0]}}}\",\"path\":\"{{{request.path}}}\",\"responseBaz\":{{{jsonpath this '$.baz'}}} ,\"param\":\"{{{request.query.foo.[0]}}}\",\"pathIndex\":\"{{{request.path.[1]}}}\",\"responseBaz2\":\"Bla bla {{{jsonpath this '$.foo'}}} bla bla\",\"responseFoo\":\"{{{jsonpath this '$.foo'}}}\",\"authorization2\":\"{{{request.headers.Authorization.[1]}}}\",\"fullBody\":\"{{{escapejsonbody}}}\",\"url\":\"{{{request.url}}}\",\"paramIndex\":\"{{{request.query.foo.[1]}}}\"}",
"headers" : {
- "Authorization" : "{{{request.headers.Authorization.[0]}}}"
+ "Authorization" : "{{{request.headers.Authorization.[0]}}};foo"
},
"transformers" : [ "response-template" ]
}
}So sending a request as the one presented in the request part of the contract will lead in sending the following
response body
{
"url" : "/api/v1/xxxx?foo=bar&foo=bar2",
+ "path" : "/api/v1/xxxx",
+ "pathIndex" : "v1",
"param" : "bar",
"paramIndex" : "bar2",
"authorization" : "secret",
@@ -876,7 +882,7 @@ that we took the method name and passed the proper JSON path as a parameter to i
},
"response" : {
"status" : 200,
- "body" : "{\\"duck\\":123,\\"alpha\\":\\"abc\\",\\"number\\":123,\\"aBoolean\\":true,\\"date\\":\\"2017-01-01\\",\\"dateTime\\":\\"2017-01-01T01:23:45\\",\\"time\\":\\"01:02:34\\",\\"valueWithoutAMatcher\\":\\"foo\\",\\"valueWithTypeMatch\\":\\"string\\",\\"valueWithMin\\":[1,2,3],\\"valueWithMax\\":[1,2,3],\\"valueWithMinMax\\":[1,2,3]}",
+ "body" : "{\\"date\\":\\"2017-01-01\\",\\"dateTime\\":\\"2017-01-01T01:23:45\\",\\"number\\":123,\\"aBoolean\\":true,\\"duck\\":123,\\"alpha\\":\\"abc\\",\\"valueWithMin\\":[1,2,3],\\"time\\":\\"01:02:34\\",\\"valueWithTypeMatch\\":\\"string\\",\\"valueWithMax\\":[1,2,3],\\"valueWithMinMax\\":[1,2,3],\\"valueWithoutAMatcher\\":\\"foo\\"}",
"headers" : {
"Content-Type" : "application/json"
}
diff --git a/2.0.x/multi/multi__migrations.html b/2.0.x/multi/multi__migrations.html
index cf9ef4a1d1..1ad50d32d7 100644
--- a/2.0.x/multi/multi__migrations.html
+++ b/2.0.x/multi/multi__migrations.html
@@ -80,4 +80,6 @@ snippet above.Maven.
have to implement that method too. It should return a String representing
all mappings available in a single HttpServerStub. Related to
issue 355.
The flow for setting the generated tests package name will look like this:
- pick
basePackageForTests - if
basePackageForTests wasn’t set pick the package from baseClassForTests - if
baseClassForTests wasn’t set pick packageWithBaseClasses - if nothing got set pick the default
org.springframework.cloud.contract.verifier.tests value
Related to
-issue 260.