Introduce constants for common attribute names

Closes gh-193
This commit is contained in:
Andy Wilkinson
2016-02-05 20:57:46 +00:00
parent 6df01419cd
commit 83b72f7962
14 changed files with 89 additions and 57 deletions

View File

@@ -22,6 +22,7 @@ import java.util.Map;
import org.springframework.restdocs.RestDocumentationContext;
import org.springframework.restdocs.curl.CurlDocumentation;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.restdocs.http.HttpDocumentation;
import org.springframework.restdocs.snippet.Snippet;
import org.springframework.restdocs.templates.TemplateFormat;
@@ -36,11 +37,6 @@ import org.springframework.restdocs.templates.TemplateFormats;
*/
public abstract class SnippetConfigurer<P, T> extends AbstractNestedConfigurer<P> {
/**
* The name of the attribute that is used to hold the default snippets.
*/
public static final String ATTRIBUTE_DEFAULT_SNIPPETS = "org.springframework.restdocs.defaultSnippets";
private List<Snippet> defaultSnippets = Arrays.asList(
CurlDocumentation.curlRequest(), HttpDocumentation.httpRequest(),
HttpDocumentation.httpResponse());
@@ -77,7 +73,8 @@ public abstract class SnippetConfigurer<P, T> extends AbstractNestedConfigurer<P
public void apply(Map<String, Object> configuration, RestDocumentationContext context) {
configuration.put(SnippetConfiguration.class.getName(), new SnippetConfiguration(
this.snippetEncoding, this.templateFormat));
configuration.put(ATTRIBUTE_DEFAULT_SNIPPETS, this.defaultSnippets);
configuration.put(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS,
this.defaultSnippets);
}
/**

View File

@@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.restdocs.config.SnippetConfigurer;
import org.springframework.restdocs.operation.Operation;
import org.springframework.restdocs.operation.OperationRequest;
import org.springframework.restdocs.operation.OperationResponse;
@@ -45,6 +44,16 @@ import org.springframework.util.Assert;
*/
public final class RestDocumentationGenerator<REQ, RESP> {
/**
* Name of the operation attribute used to hold the request's URL template.
*/
public static final String ATTRIBUTE_NAME_URL_TEMPLATE = "org.springframework.restdocs.urlTemplate";
/**
* Name of the operation attribute used to hold the {@link List} of default snippets.
*/
public static final String ATTRIBUTE_NAME_DEFAULT_SNIPPETS = "org.springframework.restdocs.defaultSnippets";
private final String identifier;
private final OperationRequestPreprocessor requestPreprocessor;
@@ -58,8 +67,8 @@ public final class RestDocumentationGenerator<REQ, RESP> {
private final ResponseConverter<RESP> responseConverter;
/**
* Creates a new {@code RestDocumentationGenerator} for the operation identified by the
* given {@code identifier}. The given {@code requestConverter} and
* Creates a new {@code RestDocumentationGenerator} for the operation identified by
* the given {@code identifier}. The given {@code requestConverter} and
* {@code responseConverter} are used to convert the operation's request and response
* into generic {@code OperationRequest} and {@code OperationResponse} instances that
* can then be documented. The given documentation {@code snippets} will be produced.
@@ -78,8 +87,8 @@ public final class RestDocumentationGenerator<REQ, RESP> {
}
/**
* Creates a new {@code RestDocumentationGenerator} for the operation identified by the
* given {@code identifier}. The given {@code requestConverter} and
* Creates a new {@code RestDocumentationGenerator} for the operation identified by
* the given {@code identifier}. The given {@code requestConverter} and
* {@code responseConverter} are used to convert the operation's request and response
* into generic {@code OperationRequest} and {@code OperationResponse} instances that
* can then be documented. The given {@code requestPreprocessor} is applied to the
@@ -101,8 +110,8 @@ public final class RestDocumentationGenerator<REQ, RESP> {
}
/**
* Creates a new {@code RestDocumentationGenerator} for the operation identified by the
* given {@code identifier}. The given {@code requestConverter} and
* Creates a new {@code RestDocumentationGenerator} for the operation identified by
* the given {@code identifier}. The given {@code requestConverter} and
* {@code responseConverter} are used to convert the operation's request and response
* into generic {@code OperationRequest} and {@code OperationResponse} instances that
* can then be documented. The given {@code responsePreprocessor} is applied to the
@@ -125,8 +134,8 @@ public final class RestDocumentationGenerator<REQ, RESP> {
}
/**
* Creates a new {@code RestDocumentationGenerator} for the operation identified by the
* given {@code identifier}. The given {@code requestConverter} and
* Creates a new {@code RestDocumentationGenerator} for the operation identified by
* the given {@code identifier}. The given {@code requestConverter} and
* {@code responseConverter} are used to convert the operation's request and response
* into generic {@code OperationRequest} and {@code OperationResponse} instances that
* can then be documented. The given {@code requestPreprocessor} and
@@ -202,7 +211,7 @@ public final class RestDocumentationGenerator<REQ, RESP> {
private List<Snippet> getSnippets(Map<String, Object> configuration) {
List<Snippet> combinedSnippets = new ArrayList<>(this.snippets);
List<Snippet> defaultSnippets = (List<Snippet>) configuration
.get(SnippetConfigurer.ATTRIBUTE_DEFAULT_SNIPPETS);
.get(ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
if (defaultSnippets != null) {
combinedSnippets.addAll(defaultSnippets);
}

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.restdocs.operation.Operation;
import org.springframework.restdocs.snippet.Snippet;
import org.springframework.restdocs.snippet.SnippetException;
@@ -91,7 +92,7 @@ public class PathParametersSnippet extends AbstractParametersSnippet {
private String extractUrlTemplate(Operation operation) {
String urlTemplate = (String) operation.getAttributes().get(
"org.springframework.restdocs.urlTemplate");
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE);
Assert.notNull(
urlTemplate,
"urlTemplate not found. If you are using MockMvc, did you use RestDocumentationRequestBuilders to "

View File

@@ -25,7 +25,6 @@ import java.util.Map;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.http.HttpHeaders;
import org.springframework.restdocs.config.SnippetConfigurer;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.restdocs.operation.Operation;
import org.springframework.restdocs.operation.OperationRequest;
@@ -91,7 +90,7 @@ public class RestDocumentationGeneratorTests {
HashMap<String, Object> configuration = new HashMap<>();
Snippet defaultSnippet1 = mock(Snippet.class);
Snippet defaultSnippet2 = mock(Snippet.class);
configuration.put(SnippetConfigurer.ATTRIBUTE_DEFAULT_SNIPPETS,
configuration.put(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS,
Arrays.asList(defaultSnippet1, defaultSnippet2));
new RestDocumentationGenerator<>("id", this.requestConverter,
this.responseConverter, this.snippet).handle(this.request, this.response,

View File

@@ -25,6 +25,7 @@ import org.junit.Test;
import org.springframework.restdocs.RestDocumentationContext;
import org.springframework.restdocs.curl.CurlDocumentation;
import org.springframework.restdocs.curl.CurlRequestSnippet;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.restdocs.http.HttpRequestSnippet;
import org.springframework.restdocs.http.HttpResponseSnippet;
import org.springframework.restdocs.snippet.Snippet;
@@ -67,10 +68,11 @@ public class RestDocumentationConfigurerTests {
instanceOf(StandardWriterResolver.class)));
assertThat(
configuration,
hasEntry(equalTo("org.springframework.restdocs.defaultSnippets"),
hasEntry(
equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
instanceOf(List.class)));
List<Snippet> defaultSnippets = (List<Snippet>) configuration
.get("org.springframework.restdocs.defaultSnippets");
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
assertThat(
defaultSnippets,
contains(instanceOf(CurlRequestSnippet.class),
@@ -115,11 +117,12 @@ public class RestDocumentationConfigurerTests {
.apply(configuration, context);
assertThat(
configuration,
hasEntry(equalTo("org.springframework.restdocs.defaultSnippets"),
hasEntry(
equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
instanceOf(List.class)));
@SuppressWarnings("unchecked")
List<Snippet> defaultSnippets = (List<Snippet>) configuration
.get("org.springframework.restdocs.defaultSnippets");
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
assertThat(defaultSnippets, contains(instanceOf(CurlRequestSnippet.class)));
}

View File

@@ -23,6 +23,7 @@ import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.restdocs.snippet.SnippetException;
import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.test.ExpectedSnippet;
@@ -53,7 +54,8 @@ public class PathParametersSnippetFailureTests {
new PathParametersSnippet(Collections.<ParameterDescriptor>emptyList())
.document(new OperationBuilder("undocumented-path-parameter",
this.snippet.getOutputDirectory()).attribute(
"org.springframework.restdocs.urlTemplate", "/{a}/").build());
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, "/{a}/")
.build());
}
@Test
@@ -65,7 +67,8 @@ public class PathParametersSnippetFailureTests {
Arrays.asList(parameterWithName("a").description("one")))
.document(new OperationBuilder("missing-path-parameter", this.snippet
.getOutputDirectory()).attribute(
"org.springframework.restdocs.urlTemplate", "/").build());
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, "/")
.build());
}
@Test
@@ -79,7 +82,8 @@ public class PathParametersSnippetFailureTests {
.document(new OperationBuilder(
"undocumented-and-missing-path-parameters", this.snippet
.getOutputDirectory()).attribute(
"org.springframework.restdocs.urlTemplate", "/{b}").build());
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, "/{b}")
.build());
}
}

View File

@@ -21,6 +21,7 @@ import java.util.Arrays;
import org.junit.Test;
import org.springframework.restdocs.AbstractSnippetTests;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.restdocs.templates.TemplateEngine;
import org.springframework.restdocs.templates.TemplateFormat;
import org.springframework.restdocs.templates.TemplateResourceResolver;
@@ -51,9 +52,10 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
"one").row("b", "two"));
new PathParametersSnippet(Arrays.asList(
parameterWithName("a").description("one"), parameterWithName("b")
.description("two"))).document(operationBuilder("path-parameters")
.attribute("org.springframework.restdocs.urlTemplate", "/{a}/{b}")
.build());
.description("two")))
.document(operationBuilder("path-parameters").attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}").build());
}
@Test
@@ -64,7 +66,8 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
new PathParametersSnippet(Arrays.asList(parameterWithName("a").ignored(),
parameterWithName("b").description("two"))).document(operationBuilder(
"ignored-path-parameter").attribute(
"org.springframework.restdocs.urlTemplate", "/{a}/{b}").build());
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, "/{a}/{b}")
.build());
}
@Test
@@ -77,7 +80,8 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
parameterWithName("a").description("one"), parameterWithName("b")
.description("two"))).document(operationBuilder(
"path-parameters-with-query-string").attribute(
"org.springframework.restdocs.urlTemplate", "/{a}/{b}?foo=bar").build());
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}?foo=bar").build());
}
@Test
@@ -93,7 +97,8 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
.description("two").attributes(key("foo").value("bravo"))),
attributes(key("title").value("The title"))).document(operationBuilder(
"path-parameters-with-custom-attributes")
.attribute("org.springframework.restdocs.urlTemplate", "/{a}/{b}")
.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver)).build());
@@ -112,8 +117,11 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one")
.attributes(key("foo").value("alpha")), parameterWithName("b")
.description("two").attributes(key("foo").value("bravo"))))
.document(operationBuilder("path-parameters-with-custom-descriptor-attributes")
.attribute("org.springframework.restdocs.urlTemplate", "/{a}/{b}")
.document(operationBuilder(
"path-parameters-with-custom-descriptor-attributes")
.attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver)).build());
}

View File

@@ -23,6 +23,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.restdocs.RestDocumentation;
import org.springframework.restdocs.RestDocumentationContext;
import org.springframework.restdocs.config.RestDocumentationConfigurer;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
import org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder;
import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
@@ -90,11 +91,12 @@ public class MockMvcRestDocumentationConfigurer
RestDocumentationContext context = this.restDocumentation.beforeOperation();
Map<String, Object> configuration = new HashMap<>();
configuration.put(MockHttpServletRequest.class.getName(), request);
String urlTemplateAttribute = "org.springframework.restdocs.urlTemplate";
configuration.put(urlTemplateAttribute,
request.getAttribute(urlTemplateAttribute));
configuration
.put(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
request.getAttribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE));
configuration.put(RestDocumentationContext.class.getName(), context);
request.setAttribute("org.springframework.restdocs.configuration",
request.setAttribute(
RestDocumentationResultHandler.ATTRIBUTE_NAME_CONFIGURATION,
configuration);
MockMvcRestDocumentationConfigurer.this.apply(configuration, context);
MockMvcRestDocumentationConfigurer.this.uriConfigurer.apply(configuration,

View File

@@ -19,6 +19,7 @@ package org.springframework.restdocs.mockmvc;
import java.net.URI;
import org.springframework.http.HttpMethod;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.restdocs.request.RequestDocumentation;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder;
@@ -38,8 +39,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
*/
public abstract class RestDocumentationRequestBuilders {
private static final String ATTRIBUTE_NAME_URL_TEMPLATE = "org.springframework.restdocs.urlTemplate";
private RestDocumentationRequestBuilders() {
}
@@ -55,7 +54,7 @@ public abstract class RestDocumentationRequestBuilders {
public static MockHttpServletRequestBuilder get(String urlTemplate,
Object... urlVariables) {
return MockMvcRequestBuilders.get(urlTemplate, urlVariables).requestAttr(
ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
}
/**
@@ -79,7 +78,7 @@ public abstract class RestDocumentationRequestBuilders {
public static MockHttpServletRequestBuilder post(String urlTemplate,
Object... urlVariables) {
return MockMvcRequestBuilders.post(urlTemplate, urlVariables).requestAttr(
ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
}
/**
@@ -103,7 +102,7 @@ public abstract class RestDocumentationRequestBuilders {
public static MockHttpServletRequestBuilder put(String urlTemplate,
Object... urlVariables) {
return MockMvcRequestBuilders.put(urlTemplate, urlVariables).requestAttr(
ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
}
/**
@@ -127,7 +126,7 @@ public abstract class RestDocumentationRequestBuilders {
public static MockHttpServletRequestBuilder patch(String urlTemplate,
Object... urlVariables) {
return MockMvcRequestBuilders.patch(urlTemplate, urlVariables).requestAttr(
ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
}
/**
@@ -151,7 +150,7 @@ public abstract class RestDocumentationRequestBuilders {
public static MockHttpServletRequestBuilder delete(String urlTemplate,
Object... urlVariables) {
return MockMvcRequestBuilders.delete(urlTemplate, urlVariables).requestAttr(
ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
}
/**
@@ -175,7 +174,7 @@ public abstract class RestDocumentationRequestBuilders {
public static MockHttpServletRequestBuilder options(String urlTemplate,
Object... urlVariables) {
return MockMvcRequestBuilders.options(urlTemplate, urlVariables).requestAttr(
ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
}
/**
@@ -199,7 +198,7 @@ public abstract class RestDocumentationRequestBuilders {
public static MockHttpServletRequestBuilder head(String urlTemplate,
Object... urlVariables) {
return MockMvcRequestBuilders.head(urlTemplate, urlVariables).requestAttr(
ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
}
/**
@@ -224,7 +223,8 @@ public abstract class RestDocumentationRequestBuilders {
public static MockHttpServletRequestBuilder request(HttpMethod httpMethod,
String urlTemplate, Object... urlVariables) {
return MockMvcRequestBuilders.request(httpMethod, urlTemplate, urlVariables)
.requestAttr(ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
.requestAttr(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
urlTemplate);
}
/**
@@ -250,7 +250,8 @@ public abstract class RestDocumentationRequestBuilders {
Object... urlVariables) {
return (MockMultipartHttpServletRequestBuilder) MockMvcRequestBuilders
.fileUpload(urlTemplate, urlVariables).requestAttr(
ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
urlTemplate);
}
/**

View File

@@ -35,6 +35,8 @@ import org.springframework.util.Assert;
*/
public class RestDocumentationResultHandler implements ResultHandler {
static final String ATTRIBUTE_NAME_CONFIGURATION = "org.springframework.restdocs.configuration";
private final RestDocumentationGenerator<MockHttpServletRequest, MockHttpServletResponse> delegate;
RestDocumentationResultHandler(
@@ -47,7 +49,7 @@ public class RestDocumentationResultHandler implements ResultHandler {
public void handle(MvcResult result) throws Exception {
@SuppressWarnings("unchecked")
Map<String, Object> configuration = (Map<String, Object>) result.getRequest()
.getAttribute("org.springframework.restdocs.configuration");
.getAttribute(ATTRIBUTE_NAME_CONFIGURATION);
this.delegate.handle(result.getRequest(), result.getResponse(), configuration);
}

View File

@@ -24,6 +24,7 @@ import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockServletContext;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import static org.hamcrest.CoreMatchers.equalTo;
@@ -143,7 +144,8 @@ public class RestDocumentationRequestBuildersTests {
HttpMethod httpMethod) {
MockHttpServletRequest request = builder.buildRequest(this.servletContext);
assertThat(
(String) request.getAttribute("org.springframework.restdocs.urlTemplate"),
(String) request
.getAttribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE),
is(equalTo("{template}")));
assertThat(request.getRequestURI(), is(equalTo("t")));
assertThat(request.getMethod(), is(equalTo(httpMethod.name())));

View File

@@ -59,7 +59,7 @@ public final class RestAssuredRestDocumentationConfigurer
RestDocumentationContext context = this.restDocumentation.beforeOperation();
filterContext.setValue(RestDocumentationContext.class.getName(), context);
Map<String, Object> configuration = new HashMap<>();
filterContext.setValue("org.springframework.restdocs.configuration",
filterContext.setValue(RestDocumentationFilter.CONTEXT_KEY_CONFIGURATION,
configuration);
apply(configuration, context);
return filterContext.next(requestSpec, responseSpec);

View File

@@ -37,6 +37,8 @@ import com.jayway.restassured.specification.FilterableResponseSpecification;
*/
public final class RestDocumentationFilter implements Filter {
static final String CONTEXT_KEY_CONFIGURATION = "org.springframework.restdocs.configuration";
private final RestDocumentationGenerator<FilterableRequestSpecification, Response> delegate;
RestDocumentationFilter(
@@ -51,11 +53,11 @@ public final class RestDocumentationFilter implements Filter {
Response response = context.next(requestSpec, responseSpec);
Map<String, Object> configuration = new HashMap<>(
context.<Map<String, Object>>getValue("org.springframework.restdocs.configuration"));
context.<Map<String, Object>>getValue(CONTEXT_KEY_CONFIGURATION));
configuration.put(RestDocumentationContext.class.getName(), context
.<RestDocumentationContext>getValue(RestDocumentationContext.class
.getName()));
configuration.put("org.springframework.restdocs.urlTemplate",
configuration.put(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
requestSpec.getUserDefinedPath());
this.delegate.handle(requestSpec, response, configuration);

View File

@@ -23,6 +23,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.restdocs.RestDocumentation;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.restdocs.snippet.WriterResolver;
import org.springframework.restdocs.templates.TemplateEngine;
@@ -62,7 +63,7 @@ public class RestAssuredRestDocumentationConfigurerTests {
public void nextFilterIsCalled() {
this.configurer.filter(this.requestSpec, this.responseSpec, this.filterContext);
verify(this.filterContext).setValue(
eq("org.springframework.restdocs.configuration"), any(Map.class));
eq(RestDocumentationFilter.CONTEXT_KEY_CONFIGURATION), any(Map.class));
}
@Test
@@ -71,7 +72,7 @@ public class RestAssuredRestDocumentationConfigurerTests {
@SuppressWarnings("rawtypes")
ArgumentCaptor<Map> configurationCaptor = ArgumentCaptor.forClass(Map.class);
verify(this.filterContext).setValue(
eq("org.springframework.restdocs.configuration"),
eq(RestDocumentationFilter.CONTEXT_KEY_CONFIGURATION),
configurationCaptor.capture());
@SuppressWarnings("unchecked")
Map<String, Object> configuration = configurationCaptor.getValue();
@@ -85,7 +86,8 @@ public class RestAssuredRestDocumentationConfigurerTests {
instanceOf(WriterResolver.class)));
assertThat(
configuration,
hasEntry(equalTo("org.springframework.restdocs.defaultSnippets"),
hasEntry(
equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
instanceOf(List.class)));
}
}