Revert "Remove unnecessary placeholder resolution"

This reverts commit 2d9c505715.
This commit is contained in:
Dave Syer
2018-01-30 11:06:26 +00:00
parent af463792ca
commit 3ee5c4c308

View File

@@ -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);
}
}