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