Introduce constants for common attribute names
Closes gh-193
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user