Merge branch '1.2.x'
This commit is contained in:
@@ -77,10 +77,6 @@ public class ContractDslSnippet extends TemplatedSnippet {
|
||||
filterHeaders(headers);
|
||||
model.put("response_headers_present", !headers.isEmpty());
|
||||
model.put("response_headers", headers.entrySet());
|
||||
@SuppressWarnings("unchecked") Set<String> jsonPaths = (Set<String>) operation.getAttributes()
|
||||
.get("contract.jsonPaths");
|
||||
model.put("response_json_paths_present", jsonPaths != null && !jsonPaths.isEmpty());
|
||||
model.put("response_json_paths", jsonPaths(jsonPaths));
|
||||
}
|
||||
|
||||
private Set<JsonPaths> jsonPaths(Set<String> jsonPaths) {
|
||||
@@ -104,6 +100,10 @@ public class ContractDslSnippet extends TemplatedSnippet {
|
||||
filterHeaders(headers);
|
||||
model.put("request_headers_present", !headers.isEmpty());
|
||||
model.put("request_headers", headers.entrySet());
|
||||
@SuppressWarnings("unchecked") Set<String> jsonPaths = (Set<String>) operation.getAttributes()
|
||||
.get("contract.jsonPaths");
|
||||
model.put("request_json_paths_present", jsonPaths != null && !jsonPaths.isEmpty());
|
||||
model.put("request_json_paths", jsonPaths(jsonPaths));
|
||||
}
|
||||
|
||||
private void filterHeaders(Map<String, String> headers) {
|
||||
|
||||
@@ -16,6 +16,14 @@
|
||||
|
||||
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;
|
||||
@@ -23,6 +31,7 @@ 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;
|
||||
@@ -31,17 +40,8 @@ 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,9 +72,6 @@ public class WireMockSnippet implements Snippet {
|
||||
|
||||
private boolean hasJsonBodyRequestToMatch = false;
|
||||
|
||||
private final PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper(
|
||||
"{", "}");
|
||||
|
||||
private static final TemplateFormat TEMPLATE_FORMAT = new TemplateFormat() {
|
||||
|
||||
@Override
|
||||
@@ -100,9 +97,8 @@ public class WireMockSnippet implements Snippet {
|
||||
RestDocumentationContextPlaceholderResolverFactory placeholders = new RestDocumentationContextPlaceholderResolverFactory();
|
||||
WriterResolver writerResolver = new StandardWriterResolver(placeholders, "UTF-8",
|
||||
TEMPLATE_FORMAT);
|
||||
String path = this.propertyPlaceholderHelper.replacePlaceholders(operation.getName(),
|
||||
placeholders.create(context));
|
||||
try (Writer writer = writerResolver.resolve(this.snippetName, path, context)) {
|
||||
try (Writer writer = writerResolver.resolve(this.snippetName, operation.getName(),
|
||||
context)) {
|
||||
writer.append(json);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,13 @@ Contract.make {
|
||||
{{/request_headers}}
|
||||
}
|
||||
{{/request_headers_present}}
|
||||
{{#request_json_paths_present}}
|
||||
stubMatchers {
|
||||
{{#request_json_paths}}
|
||||
jsonPath('''{{jsonPath}}''', byEquality())
|
||||
{{/request_json_paths}}
|
||||
}
|
||||
{{/request_json_paths_present}}
|
||||
}
|
||||
response {
|
||||
status {{response_status}}
|
||||
@@ -31,12 +38,5 @@ Contract.make {
|
||||
{{/response_headers}}
|
||||
}
|
||||
{{/response_headers_present}}
|
||||
{{#response_json_paths_present}}
|
||||
testMatchers {
|
||||
{{#response_json_paths}}
|
||||
jsonPath('''{{jsonPath}}''', byType())
|
||||
{{/response_json_paths}}
|
||||
}
|
||||
{{/response_json_paths_present}}
|
||||
}
|
||||
}
|
||||
@@ -91,10 +91,10 @@ public class ContractDslSnippetTests {
|
||||
then(parsedContract.getRequest().getUrl().getClientValue()).isNotNull();
|
||||
then(parsedContract.getRequest().getUrl().getClientValue().toString()).startsWith("/");
|
||||
then(parsedContract.getRequest().getBody().getClientValue()).isNotNull();
|
||||
then(parsedContract.getRequest().getMatchers().hasMatchers()).isTrue();
|
||||
then(parsedContract.getResponse().getStatus().getClientValue()).isNotNull();
|
||||
then(parsedContract.getResponse().getHeaders().getEntries()).isNotEmpty();
|
||||
then(parsedContract.getResponse().getBody().getClientValue()).isNotNull();
|
||||
then(parsedContract.getResponse().getMatchers().hasMatchers()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user