From af463792ca3fb678645631a83e799095b8aa3a85 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 29 Jan 2018 15:18:58 +0100 Subject: [PATCH 1/2] Updated the docs --- docs/src/main/asciidoc/verifier_contract.adoc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/src/main/asciidoc/verifier_contract.adoc b/docs/src/main/asciidoc/verifier_contract.adoc index 718a5bad2f..f60565e9c6 100644 --- a/docs/src/main/asciidoc/verifier_contract.adoc +++ b/docs/src/main/asciidoc/verifier_contract.adoc @@ -742,15 +742,15 @@ following matching possibilities: .Groovy DSL * For `stubMatchers`: -** `byEquality()`: The value taken from the response via the provided JSON Path must be +** `byEquality()`: The value taken from the request via the provided JSON Path must be equal to the value provided in the contract. -** `byRegex(...)`: The value taken from the response via the provided JSON Path must +** `byRegex(...)`: The value taken from the request via the provided JSON Path must match the regex. -** `byDate()`: The value taken from the response via the provided JSON Path must +** `byDate()`: The value taken from the request via the provided JSON Path must match the regex for an ISO Date value. -** `byTimestamp()`: The value taken from the response via the provided JSON Path must +** `byTimestamp()`: The value taken from the request via the provided JSON Path must match the regex for an ISO DateTime value. -** `byTime()`: The value taken from the response via the provided JSON Path must +** `byTime()`: The value taken from the request via the provided JSON Path must match the regex for an ISO Time value. * For `testMatchers`: ** `byEquality()`: The value taken from the response via the provided JSON Path must be From 3ee5c4c3082ee134adc2140dc5ba00c16aa7f85c Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 30 Jan 2018 11:06:26 +0000 Subject: [PATCH 2/2] Revert "Remove unnecessary placeholder resolution" This reverts commit 2d9c50571535767603e400b6b53bd018f4042d5a. --- .../wiremock/restdocs/WireMockSnippet.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockSnippet.java b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockSnippet.java index 59713a9178..cec2f7ab04 100644 --- a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockSnippet.java +++ b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockSnippet.java @@ -16,14 +16,6 @@ package org.springframework.cloud.contract.wiremock.restdocs; -import java.io.IOException; -import java.io.Writer; -import java.util.Arrays; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.regex.Pattern; - import com.github.tomakehurst.wiremock.client.MappingBuilder; import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; import com.github.tomakehurst.wiremock.common.Json; @@ -31,7 +23,6 @@ import com.github.tomakehurst.wiremock.http.HttpHeader; import com.github.tomakehurst.wiremock.http.HttpHeaders; import com.github.tomakehurst.wiremock.matching.UrlPattern; import com.github.tomakehurst.wiremock.stubbing.StubMapping; - import org.springframework.http.MediaType; import org.springframework.restdocs.RestDocumentationContext; import org.springframework.restdocs.operation.Operation; @@ -40,8 +31,17 @@ import org.springframework.restdocs.snippet.Snippet; import org.springframework.restdocs.snippet.StandardWriterResolver; import org.springframework.restdocs.snippet.WriterResolver; import org.springframework.restdocs.templates.TemplateFormat; +import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.StringUtils; +import java.io.IOException; +import java.io.Writer; +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.regex.Pattern; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.delete; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; @@ -72,6 +72,9 @@ public class WireMockSnippet implements Snippet { private boolean hasJsonBodyRequestToMatch = false; + private final PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper( + "{", "}"); + private static final TemplateFormat TEMPLATE_FORMAT = new TemplateFormat() { @Override @@ -97,8 +100,9 @@ public class WireMockSnippet implements Snippet { RestDocumentationContextPlaceholderResolverFactory placeholders = new RestDocumentationContextPlaceholderResolverFactory(); WriterResolver writerResolver = new StandardWriterResolver(placeholders, "UTF-8", TEMPLATE_FORMAT); - try (Writer writer = writerResolver.resolve(this.snippetName, operation.getName(), - context)) { + String path = this.propertyPlaceholderHelper.replacePlaceholders(operation.getName(), + placeholders.create(context)); + try (Writer writer = writerResolver.resolve(this.snippetName, path, context)) { writer.append(json); } }