Break the package cycle caused by the introduction of SnippetFormat
This commit is contained in:
@@ -73,7 +73,7 @@
|
||||
<module name="AvoidStarImport" />
|
||||
<module name="AvoidStaticImport">
|
||||
<property name="excludes"
|
||||
value="com.jayway.restassured.RestAssured.*, org.junit.Assert.*, org.junit.Assume.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.springframework.restdocs.curl.CurlDocumentation.*, org.springframework.restdocs.headers.HeaderDocumentation.*, org.springframework.restdocs.hypermedia.HypermediaDocumentation.*, org.springframework.restdocs.mockmvc.IterableEnumeration.*, org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*, org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*, org.springframework.restdocs.payload.PayloadDocumentation.*, org.springframework.restdocs.operation.preprocess.Preprocessors.*, org.springframework.restdocs.request.RequestDocumentation.*, org.springframework.restdocs.restassured.RestAssuredRestDocumentation.*, org.springframework.restdocs.restassured.operation.preprocess.RestAssuredPreprocessors.*, org.springframework.restdocs.snippet.Attributes.*, org.springframework.restdocs.snippet.SnippetFormats.*, org.springframework.restdocs.test.SnippetMatchers.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*" />
|
||||
value="com.jayway.restassured.RestAssured.*, org.junit.Assert.*, org.junit.Assume.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.springframework.restdocs.curl.CurlDocumentation.*, org.springframework.restdocs.headers.HeaderDocumentation.*, org.springframework.restdocs.hypermedia.HypermediaDocumentation.*, org.springframework.restdocs.mockmvc.IterableEnumeration.*, org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*, org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*, org.springframework.restdocs.payload.PayloadDocumentation.*, org.springframework.restdocs.operation.preprocess.Preprocessors.*, org.springframework.restdocs.request.RequestDocumentation.*, org.springframework.restdocs.restassured.RestAssuredRestDocumentation.*, org.springframework.restdocs.restassured.operation.preprocess.RestAssuredPreprocessors.*, org.springframework.restdocs.snippet.Attributes.*, org.springframework.restdocs.templates.TemplateFormats.*, org.springframework.restdocs.test.SnippetMatchers.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*" />
|
||||
</module>
|
||||
<module name="IllegalImport" />
|
||||
<module name="RedundantImport" />
|
||||
|
||||
@@ -59,11 +59,11 @@ include::{examples-dir}/com/example/restassured/CustomEncoding.java[tags=custom-
|
||||
|
||||
|
||||
|
||||
[[configuration-snippet-format]]
|
||||
=== Snippet format
|
||||
[[configuration-snippet-template-format]]
|
||||
=== Snippet template format
|
||||
|
||||
The default snippet format is Asciidoctor. Markdown is also supported out of the box. You
|
||||
can change the default format using the `RestDocumentationConfigurer` API:
|
||||
The default snippet template format is Asciidoctor. Markdown is also supported out of the
|
||||
box. You can change the default format using the `RestDocumentationConfigurer` API:
|
||||
|
||||
[source,java,indent=0,role="primary"]
|
||||
.MockMvc
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.restdocs.RestDocumentation;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
@@ -42,7 +42,7 @@ public class CustomFormat {
|
||||
// tag::custom-format[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation)
|
||||
.snippets().withFormat(SnippetFormats.markdown()))
|
||||
.snippets().withTemplateFormat(TemplateFormats.markdown()))
|
||||
.build();
|
||||
// end::custom-format[]
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.example.restassured;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.springframework.restdocs.RestDocumentation;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
@@ -38,7 +38,7 @@ public class CustomFormat {
|
||||
// tag::custom-format[]
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation)
|
||||
.snippets().withFormat(SnippetFormats.markdown()))
|
||||
.snippets().withTemplateFormat(TemplateFormats.markdown()))
|
||||
.build();
|
||||
// end::custom-format[]
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public abstract class RestDocumentationConfigurer<S extends AbstractConfigurer,
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
engineToUse = new MustacheTemplateEngine(
|
||||
new StandardTemplateResourceResolver(
|
||||
snippetConfiguration.getFormat()));
|
||||
snippetConfiguration.getTemplateFormat()));
|
||||
}
|
||||
configuration.put(TemplateEngine.class.getName(), engineToUse);
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public abstract class RestDocumentationConfigurer<S extends AbstractConfigurer,
|
||||
resolverToUse = new StandardWriterResolver(
|
||||
new RestDocumentationContextPlaceholderResolver(context),
|
||||
snippetConfiguration.getEncoding(),
|
||||
snippetConfiguration.getFormat());
|
||||
snippetConfiguration.getTemplateFormat());
|
||||
}
|
||||
configuration.put(WriterResolver.class.getName(), resolverToUse);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.restdocs.config;
|
||||
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
|
||||
/**
|
||||
* An encapsulation of the configuration for documentation snippets.
|
||||
@@ -27,18 +27,18 @@ class SnippetConfiguration {
|
||||
|
||||
private final String encoding;
|
||||
|
||||
private final SnippetFormat format;
|
||||
private final TemplateFormat format;
|
||||
|
||||
SnippetConfiguration(String encoding, SnippetFormat format) {
|
||||
SnippetConfiguration(String encoding, TemplateFormat templateFormat) {
|
||||
this.encoding = encoding;
|
||||
this.format = format;
|
||||
this.format = templateFormat;
|
||||
}
|
||||
|
||||
String getEncoding() {
|
||||
return this.encoding;
|
||||
}
|
||||
|
||||
SnippetFormat getFormat() {
|
||||
TemplateFormat getTemplateFormat() {
|
||||
return this.format;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.springframework.restdocs.RestDocumentationContext;
|
||||
import org.springframework.restdocs.curl.CurlDocumentation;
|
||||
import org.springframework.restdocs.http.HttpDocumentation;
|
||||
import org.springframework.restdocs.snippet.Snippet;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
|
||||
/**
|
||||
* A configurer that can be used to configure the generated documentation snippets.
|
||||
@@ -55,14 +55,14 @@ public abstract class SnippetConfigurer<P, T> extends AbstractNestedConfigurer<P
|
||||
/**
|
||||
* The default format for documentation snippets.
|
||||
*
|
||||
* @see #withFormat(SnippetFormat)
|
||||
* @see #withTemplateFormat(TemplateFormat)
|
||||
*/
|
||||
public static final SnippetFormat DEFAULT_SNIPPET_FORMAT = SnippetFormats
|
||||
public static final TemplateFormat DEFAULT_TEMPLATE_FORMAT = TemplateFormats
|
||||
.asciidoctor();
|
||||
|
||||
private String snippetEncoding = DEFAULT_SNIPPET_ENCODING;
|
||||
|
||||
private SnippetFormat snippetFormat = DEFAULT_SNIPPET_FORMAT;
|
||||
private TemplateFormat templateFormat = DEFAULT_TEMPLATE_FORMAT;
|
||||
|
||||
/**
|
||||
* Creates a new {@code SnippetConfigurer} with the given {@code parent}.
|
||||
@@ -76,7 +76,7 @@ public abstract class SnippetConfigurer<P, T> extends AbstractNestedConfigurer<P
|
||||
@Override
|
||||
public void apply(Map<String, Object> configuration, RestDocumentationContext context) {
|
||||
configuration.put(SnippetConfiguration.class.getName(), new SnippetConfiguration(
|
||||
this.snippetEncoding, this.snippetFormat));
|
||||
this.snippetEncoding, this.templateFormat));
|
||||
configuration.put(ATTRIBUTE_DEFAULT_SNIPPETS, this.defaultSnippets);
|
||||
}
|
||||
|
||||
@@ -106,14 +106,14 @@ public abstract class SnippetConfigurer<P, T> extends AbstractNestedConfigurer<P
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the format of the documentation snippets.
|
||||
* Configures the format of the documentation snippet templates.
|
||||
*
|
||||
* @param format the snippet format
|
||||
* @param format the snippet template format
|
||||
* @return {@code this}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public T withFormat(SnippetFormat format) {
|
||||
this.snippetFormat = format;
|
||||
public T withTemplateFormat(TemplateFormat format) {
|
||||
this.templateFormat = format;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.restdocs.snippet;
|
||||
|
||||
/**
|
||||
* An enumeration of the built-in snippet formats.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public abstract class SnippetFormats {
|
||||
|
||||
private static final SnippetFormat ASCIIDOCTOR = new AsciidoctorSnippetFormat();
|
||||
|
||||
private static final SnippetFormat MARKDOWN = new MarkdownSnippetFormat();
|
||||
|
||||
private SnippetFormats() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Asciidoctor snippet format.
|
||||
*
|
||||
* @return the snippet format
|
||||
*/
|
||||
public static SnippetFormat asciidoctor() {
|
||||
return ASCIIDOCTOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Markdown snippet format.
|
||||
*
|
||||
* @return the snippet format
|
||||
*/
|
||||
public static SnippetFormat markdown() {
|
||||
return MARKDOWN;
|
||||
}
|
||||
|
||||
private static final class AsciidoctorSnippetFormat implements SnippetFormat {
|
||||
|
||||
private static final String FILE_EXTENSION = "adoc";
|
||||
|
||||
@Override
|
||||
public String getFileExtension() {
|
||||
return FILE_EXTENSION;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class MarkdownSnippetFormat implements SnippetFormat {
|
||||
|
||||
private static final String FILE_EXTENSION = "md";
|
||||
|
||||
@Override
|
||||
public String getFileExtension() {
|
||||
return FILE_EXTENSION;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,8 @@ import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.springframework.restdocs.RestDocumentationContext;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.util.PropertyPlaceholderHelper;
|
||||
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
|
||||
|
||||
@@ -40,7 +42,7 @@ public final class StandardWriterResolver implements WriterResolver {
|
||||
|
||||
private String encoding = "UTF-8";
|
||||
|
||||
private SnippetFormat snippetFormat;
|
||||
private TemplateFormat templateFormat;
|
||||
|
||||
/**
|
||||
* Creates a new {@code StandardWriterResolver} that will use the given
|
||||
@@ -50,29 +52,29 @@ public final class StandardWriterResolver implements WriterResolver {
|
||||
*
|
||||
* @param placeholderResolver the placeholder resolver
|
||||
* @deprecated since 1.1.0 in favor of
|
||||
* {@link #StandardWriterResolver(PropertyPlaceholderHelper.PlaceholderResolver, String, SnippetFormat)}
|
||||
* {@link #StandardWriterResolver(PropertyPlaceholderHelper.PlaceholderResolver, String, TemplateFormat)}
|
||||
*/
|
||||
@Deprecated
|
||||
public StandardWriterResolver(PlaceholderResolver placeholderResolver) {
|
||||
this(placeholderResolver, "UTF-8", SnippetFormats.asciidoctor());
|
||||
this(placeholderResolver, "UTF-8", TemplateFormats.asciidoctor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code StandardWriterResolver} that will use the given
|
||||
* {@code placeholderResolver} to resolve any placeholders in the
|
||||
* {@code operationName}. Writers will use the given {@code encoding} and, when
|
||||
* writing to a file, will use a filename appropriate for content in the given
|
||||
* {@code snippetFormat}.
|
||||
* writing to a file, will use a filename appropriate for content generated from
|
||||
* templates in the given {@code templateFormat}.
|
||||
*
|
||||
* @param placeholderResolver the placeholder resolver
|
||||
* @param encoding the encoding
|
||||
* @param snippetFormat the snippet format
|
||||
* @param templateFormat the snippet format
|
||||
*/
|
||||
public StandardWriterResolver(PlaceholderResolver placeholderResolver,
|
||||
String encoding, SnippetFormat snippetFormat) {
|
||||
String encoding, TemplateFormat templateFormat) {
|
||||
this.placeholderResolver = placeholderResolver;
|
||||
this.encoding = encoding;
|
||||
this.snippetFormat = snippetFormat;
|
||||
this.templateFormat = templateFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,7 +82,7 @@ public final class StandardWriterResolver implements WriterResolver {
|
||||
RestDocumentationContext context) throws IOException {
|
||||
File outputFile = resolveFile(this.propertyPlaceholderHelper.replacePlaceholders(
|
||||
operationName, this.placeholderResolver), snippetName + "."
|
||||
+ this.snippetFormat.getFileExtension(), context);
|
||||
+ this.templateFormat.getFileExtension(), context);
|
||||
|
||||
if (outputFile != null) {
|
||||
createDirectoriesIfNecessary(outputFile);
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.restdocs.templates;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
|
||||
/**
|
||||
* Standard implementation of {@link TemplateResourceResolver}.
|
||||
@@ -33,28 +31,28 @@ import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
*/
|
||||
public class StandardTemplateResourceResolver implements TemplateResourceResolver {
|
||||
|
||||
private final SnippetFormat snippetFormat;
|
||||
private final TemplateFormat templateFormat;
|
||||
|
||||
/**
|
||||
* Creates a new {@code StandardTemplateResourceResolver} that will produce default
|
||||
* template resources formatted with Asciidoctor.
|
||||
*
|
||||
* @deprecated since 1.1.0 in favour of
|
||||
* {@link #StandardTemplateResourceResolver(SnippetFormat)}
|
||||
* {@link #StandardTemplateResourceResolver(TemplateFormat)}
|
||||
*/
|
||||
@Deprecated
|
||||
public StandardTemplateResourceResolver() {
|
||||
this(SnippetFormats.asciidoctor());
|
||||
this(TemplateFormats.asciidoctor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code StandardTemplateResourceResolver} that will produce default
|
||||
* template resources formatted with the given {@code snippetFormat}.
|
||||
* template resources formatted with the given {@code templateFormat}.
|
||||
*
|
||||
* @param snippetFormat the format for the default snippet templates
|
||||
* @param templateFormat the format for the default snippet templates
|
||||
*/
|
||||
public StandardTemplateResourceResolver(SnippetFormat snippetFormat) {
|
||||
this.snippetFormat = snippetFormat;
|
||||
public StandardTemplateResourceResolver(TemplateFormat templateFormat) {
|
||||
this.templateFormat = templateFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,8 +62,7 @@ public class StandardTemplateResourceResolver implements TemplateResourceResolve
|
||||
if (!classPathResource.exists()) {
|
||||
classPathResource = new ClassPathResource(
|
||||
"org/springframework/restdocs/templates/"
|
||||
+ this.snippetFormat.getFileExtension() + "/" + name
|
||||
+ ".snippet");
|
||||
+ this.templateFormat.getId() + "/" + name + ".snippet");
|
||||
if (!classPathResource.exists()) {
|
||||
throw new IllegalStateException("Template named '" + name
|
||||
+ "' could not be resolved");
|
||||
|
||||
@@ -14,18 +14,26 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.restdocs.snippet;
|
||||
package org.springframework.restdocs.templates;
|
||||
|
||||
/**
|
||||
* A {@link SnippetFormat} provides information about a particular snippet format, such as
|
||||
* Asciidoctor or Markdown.
|
||||
* A {@link TemplateFormat} provides information about a particular template format, such
|
||||
* as Asciidoctor or Markdown.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public interface SnippetFormat {
|
||||
public interface TemplateFormat {
|
||||
|
||||
/**
|
||||
* Returns the snippet format's file extension.
|
||||
* Returns the id of this template format.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Returns the file extension to use for files generated from templates in this
|
||||
* format.
|
||||
*
|
||||
* @return the file extension
|
||||
*/
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.restdocs.templates;
|
||||
|
||||
/**
|
||||
* An enumeration of the built-in formats for which templates are provuded.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public abstract class TemplateFormats {
|
||||
|
||||
private static final TemplateFormat ASCIIDOCTOR = new AsciidoctorTemplateFormat();
|
||||
|
||||
private static final TemplateFormat MARKDOWN = new MarkdownTemplateFormat();
|
||||
|
||||
private TemplateFormats() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Asciidoctor template format with the ID {@code asciidoctor} and the
|
||||
* file extension {@code adoc}.
|
||||
*
|
||||
* @return the template format
|
||||
*/
|
||||
public static TemplateFormat asciidoctor() {
|
||||
return ASCIIDOCTOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Markdown template format with the ID {@code markdown} and the file
|
||||
* extension {@code md}.
|
||||
*
|
||||
* @return the template format
|
||||
*/
|
||||
public static TemplateFormat markdown() {
|
||||
return MARKDOWN;
|
||||
}
|
||||
|
||||
private abstract static class AbstractTemplateFormat implements TemplateFormat {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String fileExtension;
|
||||
|
||||
private AbstractTemplateFormat(String name, String fileExtension) {
|
||||
this.name = name;
|
||||
this.fileExtension = fileExtension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileExtension() {
|
||||
return this.fileExtension;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class AsciidoctorTemplateFormat extends AbstractTemplateFormat {
|
||||
|
||||
private AsciidoctorTemplateFormat() {
|
||||
super("asciidoctor", "adoc");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class MarkdownTemplateFormat extends AbstractTemplateFormat {
|
||||
|
||||
private MarkdownTemplateFormat() {
|
||||
super("markdown", "md");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.test.ExpectedSnippet;
|
||||
import org.springframework.restdocs.test.OperationBuilder;
|
||||
import org.springframework.restdocs.test.SnippetMatchers;
|
||||
@@ -35,8 +35,8 @@ import org.springframework.restdocs.test.SnippetMatchers.HttpResponseMatcher;
|
||||
import org.springframework.restdocs.test.SnippetMatchers.TableMatcher;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import static org.springframework.restdocs.snippet.SnippetFormats.asciidoctor;
|
||||
import static org.springframework.restdocs.snippet.SnippetFormats.markdown;
|
||||
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
|
||||
import static org.springframework.restdocs.templates.TemplateFormats.markdown;
|
||||
|
||||
/**
|
||||
* Abstract base class for testing snippet generation.
|
||||
@@ -46,7 +46,7 @@ import static org.springframework.restdocs.snippet.SnippetFormats.markdown;
|
||||
@RunWith(Parameterized.class)
|
||||
public abstract class AbstractSnippetTests {
|
||||
|
||||
protected final SnippetFormat snippetFormat;
|
||||
protected final TemplateFormat templateFormat;
|
||||
|
||||
@Rule
|
||||
public ExpectedSnippet snippet;
|
||||
@@ -57,40 +57,40 @@ public abstract class AbstractSnippetTests {
|
||||
"Markdown", markdown() });
|
||||
}
|
||||
|
||||
public AbstractSnippetTests(String name, SnippetFormat snippetFormat) {
|
||||
this.snippet = new ExpectedSnippet(snippetFormat);
|
||||
this.snippetFormat = snippetFormat;
|
||||
public AbstractSnippetTests(String name, TemplateFormat templateFormat) {
|
||||
this.snippet = new ExpectedSnippet(templateFormat);
|
||||
this.templateFormat = templateFormat;
|
||||
}
|
||||
|
||||
public CodeBlockMatcher<?> codeBlock(String language) {
|
||||
return SnippetMatchers.codeBlock(this.snippetFormat, language);
|
||||
return SnippetMatchers.codeBlock(this.templateFormat, language);
|
||||
}
|
||||
|
||||
public TableMatcher<?> tableWithHeader(String... headers) {
|
||||
return SnippetMatchers.tableWithHeader(this.snippetFormat, headers);
|
||||
return SnippetMatchers.tableWithHeader(this.templateFormat, headers);
|
||||
}
|
||||
|
||||
public TableMatcher<?> tableWithTitleAndHeader(String title, String... headers) {
|
||||
return SnippetMatchers
|
||||
.tableWithTitleAndHeader(this.snippetFormat, title, headers);
|
||||
return SnippetMatchers.tableWithTitleAndHeader(this.templateFormat, title,
|
||||
headers);
|
||||
}
|
||||
|
||||
public HttpRequestMatcher httpRequest(RequestMethod method, String uri) {
|
||||
return SnippetMatchers.httpRequest(this.snippetFormat, method, uri);
|
||||
return SnippetMatchers.httpRequest(this.templateFormat, method, uri);
|
||||
}
|
||||
|
||||
public HttpResponseMatcher httpResponse(HttpStatus responseStatus) {
|
||||
return SnippetMatchers.httpResponse(this.snippetFormat, responseStatus);
|
||||
return SnippetMatchers.httpResponse(this.templateFormat, responseStatus);
|
||||
}
|
||||
|
||||
public OperationBuilder operationBuilder(String name) {
|
||||
return new OperationBuilder(name, this.snippet.getOutputDirectory(),
|
||||
this.snippetFormat);
|
||||
this.templateFormat);
|
||||
}
|
||||
|
||||
protected FileSystemResource snippetResource(String name) {
|
||||
return new FileSystemResource("src/test/resources/custom-snippet-templates/"
|
||||
+ this.snippetFormat.getFileExtension() + "/" + name + ".snippet");
|
||||
+ this.templateFormat.getId() + "/" + name + ".snippet");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ import org.springframework.restdocs.curl.CurlRequestSnippet;
|
||||
import org.springframework.restdocs.http.HttpRequestSnippet;
|
||||
import org.springframework.restdocs.http.HttpResponseSnippet;
|
||||
import org.springframework.restdocs.snippet.Snippet;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.snippet.StandardWriterResolver;
|
||||
import org.springframework.restdocs.snippet.WriterResolver;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
@@ -83,8 +83,8 @@ public class RestDocumentationConfigurerTests {
|
||||
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
assertThat(snippetConfiguration.getEncoding(), is(equalTo("UTF-8")));
|
||||
assertThat(snippetConfiguration.getFormat(),
|
||||
is(equalTo(SnippetFormats.asciidoctor())));
|
||||
assertThat(snippetConfiguration.getTemplateFormat(),
|
||||
is(equalTo(TemplateFormats.asciidoctor())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,10 +139,10 @@ public class RestDocumentationConfigurerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customSnippetFormat() {
|
||||
public void customTemplateFormat() {
|
||||
RestDocumentationContext context = new RestDocumentationContext(null, null, null);
|
||||
Map<String, Object> configuration = new HashMap<>();
|
||||
this.configurer.snippets().withFormat(SnippetFormats.markdown())
|
||||
this.configurer.snippets().withTemplateFormat(TemplateFormats.markdown())
|
||||
.apply(configuration, context);
|
||||
assertThat(
|
||||
configuration,
|
||||
@@ -150,8 +150,8 @@ public class RestDocumentationConfigurerTests {
|
||||
instanceOf(SnippetConfiguration.class)));
|
||||
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
assertThat(snippetConfiguration.getFormat(),
|
||||
is(equalTo(SnippetFormats.markdown())));
|
||||
assertThat(snippetConfiguration.getTemplateFormat(),
|
||||
is(equalTo(TemplateFormats.markdown())));
|
||||
}
|
||||
|
||||
private static final class TestRestDocumentationConfigurer
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.junit.runners.Parameterized;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.AbstractSnippetTests;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
import org.springframework.util.Base64Utils;
|
||||
@@ -48,8 +48,8 @@ import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
@RunWith(Parameterized.class)
|
||||
public class CurlRequestSnippetTests extends AbstractSnippetTests {
|
||||
|
||||
public CurlRequestSnippetTests(String name, SnippetFormat snippetFormat) {
|
||||
super(name, snippetFormat);
|
||||
public CurlRequestSnippetTests(String name, TemplateFormat templateFormat) {
|
||||
super(name, templateFormat);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.restdocs.snippet.SnippetException;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.restdocs.test.ExpectedSnippet;
|
||||
import org.springframework.restdocs.test.OperationBuilder;
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.springframework.restdocs.headers.HeaderDocumentation.headerWit
|
||||
public class RequestHeadersSnippetFailureTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(SnippetFormats.asciidoctor());
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(TemplateFormats.asciidoctor());
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.restdocs.AbstractSnippetTests;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
import org.springframework.restdocs.test.OperationBuilder;
|
||||
@@ -42,8 +42,8 @@ import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
*/
|
||||
public class RequestHeadersSnippetTests extends AbstractSnippetTests {
|
||||
|
||||
public RequestHeadersSnippetTests(String name, SnippetFormat snippetFormat) {
|
||||
super(name, snippetFormat);
|
||||
public RequestHeadersSnippetTests(String name, TemplateFormat templateFormat) {
|
||||
super(name, templateFormat);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.restdocs.snippet.SnippetException;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.restdocs.test.ExpectedSnippet;
|
||||
import org.springframework.restdocs.test.OperationBuilder;
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.springframework.restdocs.headers.HeaderDocumentation.headerWit
|
||||
public class ResponseHeadersSnippetFailureTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(SnippetFormats.asciidoctor());
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(TemplateFormats.asciidoctor());
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.restdocs.AbstractSnippetTests;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
import org.springframework.restdocs.test.OperationBuilder;
|
||||
@@ -42,8 +42,8 @@ import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
*/
|
||||
public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
|
||||
|
||||
public ResponseHeadersSnippetTests(String name, SnippetFormat snippetFormat) {
|
||||
super(name, snippetFormat);
|
||||
public ResponseHeadersSnippetTests(String name, TemplateFormat templateFormat) {
|
||||
super(name, templateFormat);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,8 +22,8 @@ import org.junit.Test;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.AbstractSnippetTests;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -44,8 +44,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
|
||||
|
||||
private static final String BOUNDARY = "6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm";
|
||||
|
||||
public HttpRequestSnippetTests(String name, SnippetFormat snippetFormat) {
|
||||
super(name, snippetFormat);
|
||||
public HttpRequestSnippetTests(String name, TemplateFormat templateFormat) {
|
||||
super(name, templateFormat);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.AbstractSnippetTests;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
|
||||
@@ -42,8 +42,8 @@ import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
*/
|
||||
public class HttpResponseSnippetTests extends AbstractSnippetTests {
|
||||
|
||||
public HttpResponseSnippetTests(String name, SnippetFormat snippetFormat) {
|
||||
super(name, snippetFormat);
|
||||
public HttpResponseSnippetTests(String name, TemplateFormat templateFormat) {
|
||||
super(name, templateFormat);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.restdocs.snippet.SnippetException;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.restdocs.test.ExpectedSnippet;
|
||||
import org.springframework.restdocs.test.OperationBuilder;
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
|
||||
public class LinksSnippetFailureTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(SnippetFormats.asciidoctor());
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(TemplateFormats.asciidoctor());
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.restdocs.AbstractSnippetTests;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
|
||||
@@ -39,8 +39,8 @@ import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
*/
|
||||
public class LinksSnippetTests extends AbstractSnippetTests {
|
||||
|
||||
public LinksSnippetTests(String name, SnippetFormat snippetFormat) {
|
||||
super(name, snippetFormat);
|
||||
public LinksSnippetTests(String name, TemplateFormat templateFormat) {
|
||||
super(name, templateFormat);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.util.Arrays;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.restdocs.templates.TemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
import org.springframework.restdocs.test.ExpectedSnippet;
|
||||
@@ -32,7 +32,7 @@ import org.springframework.restdocs.test.OperationBuilder;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
|
||||
import static org.springframework.restdocs.snippet.SnippetFormats.asciidoctor;
|
||||
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.tableWithHeader;
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ import static org.springframework.restdocs.test.SnippetMatchers.tableWithHeader;
|
||||
public class AsciidoctorRequestFieldsSnippetTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(SnippetFormats.asciidoctor());
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void requestFieldsWithListDescription() throws IOException {
|
||||
@@ -67,8 +67,9 @@ public class AsciidoctorRequestFieldsSnippetTests {
|
||||
}
|
||||
|
||||
private FileSystemResource snippetResource(String name) {
|
||||
return new FileSystemResource("src/test/resources/custom-snippet-templates/adoc/"
|
||||
+ name + ".snippet");
|
||||
return new FileSystemResource(
|
||||
"src/test/resources/custom-snippet-templates/asciidoctor/" + name
|
||||
+ ".snippet");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.junit.rules.ExpectedException;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.snippet.SnippetException;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.restdocs.test.ExpectedSnippet;
|
||||
import org.springframework.restdocs.test.OperationBuilder;
|
||||
|
||||
@@ -44,7 +44,7 @@ import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWit
|
||||
public class RequestFieldsSnippetFailureTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(SnippetFormats.asciidoctor());
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(TemplateFormats.asciidoctor());
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.junit.Test;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.AbstractSnippetTests;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
|
||||
@@ -42,8 +42,8 @@ import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
*/
|
||||
public class RequestFieldsSnippetTests extends AbstractSnippetTests {
|
||||
|
||||
public RequestFieldsSnippetTests(String name, SnippetFormat snippetFormat) {
|
||||
super(name, snippetFormat);
|
||||
public RequestFieldsSnippetTests(String name, TemplateFormat templateFormat) {
|
||||
super(name, templateFormat);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.junit.rules.ExpectedException;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.snippet.SnippetException;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.restdocs.test.ExpectedSnippet;
|
||||
import org.springframework.restdocs.test.OperationBuilder;
|
||||
|
||||
@@ -44,7 +44,7 @@ import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWit
|
||||
public class ResponseFieldsSnippetFailureTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(SnippetFormats.asciidoctor());
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(TemplateFormats.asciidoctor());
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.junit.Test;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.AbstractSnippetTests;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
|
||||
@@ -42,8 +42,8 @@ import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
*/
|
||||
public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
|
||||
|
||||
public ResponseFieldsSnippetTests(String name, SnippetFormat snippetFormat) {
|
||||
super(name, snippetFormat);
|
||||
public ResponseFieldsSnippetTests(String name, TemplateFormat templateFormat) {
|
||||
super(name, templateFormat);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.restdocs.snippet.SnippetException;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.restdocs.test.ExpectedSnippet;
|
||||
import org.springframework.restdocs.test.OperationBuilder;
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.springframework.restdocs.request.RequestDocumentation.paramete
|
||||
public class PathParametersSnippetFailureTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(SnippetFormats.asciidoctor());
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(TemplateFormats.asciidoctor());
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.restdocs.AbstractSnippetTests;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
|
||||
@@ -40,8 +40,8 @@ import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
*/
|
||||
public class PathParametersSnippetTests extends AbstractSnippetTests {
|
||||
|
||||
public PathParametersSnippetTests(String name, SnippetFormat snippetFormat) {
|
||||
super(name, snippetFormat);
|
||||
public PathParametersSnippetTests(String name, TemplateFormat templateFormat) {
|
||||
super(name, templateFormat);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.restdocs.snippet.SnippetException;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.restdocs.test.ExpectedSnippet;
|
||||
import org.springframework.restdocs.test.OperationBuilder;
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.springframework.restdocs.request.RequestDocumentation.paramete
|
||||
public class RequestParametersSnippetFailureTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(SnippetFormats.asciidoctor());
|
||||
public ExpectedSnippet snippet = new ExpectedSnippet(TemplateFormats.asciidoctor());
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.restdocs.AbstractSnippetTests;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
|
||||
@@ -40,8 +40,8 @@ import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
*/
|
||||
public class RequestParametersSnippetTests extends AbstractSnippetTests {
|
||||
|
||||
public RequestParametersSnippetTests(String name, SnippetFormat snippetFormat) {
|
||||
super(name, snippetFormat);
|
||||
public RequestParametersSnippetTests(String name, TemplateFormat templateFormat) {
|
||||
super(name, templateFormat);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,7 +26,7 @@ import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.restdocs.snippet.SnippetFormats.asciidoctor;
|
||||
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
|
||||
|
||||
/**
|
||||
* Tests for {@link StandardWriterResolver}.
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.core.io.Resource;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.restdocs.snippet.SnippetFormats.asciidoctor;
|
||||
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
|
||||
|
||||
/**
|
||||
* Tests for {@link TemplateResourceResolver}.
|
||||
@@ -68,8 +68,8 @@ public class StandardTemplateResourceResolverTests {
|
||||
@Test
|
||||
public void fallsBackToDefaultSnippet() throws Exception {
|
||||
this.classLoader.addResource(
|
||||
"org/springframework/restdocs/templates/adoc/test.snippet", getClass()
|
||||
.getResource("test.snippet"));
|
||||
"org/springframework/restdocs/templates/asciidoctor/test.snippet",
|
||||
getClass().getResource("test.snippet"));
|
||||
Resource snippet = doWithThreadContextClassLoader(this.classLoader,
|
||||
new Callable<Resource>() {
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.hamcrest.Matcher;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.snippet.TemplatedSnippet;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.test.SnippetMatchers.SnippetMatcher;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
@@ -39,7 +39,7 @@ import static org.junit.Assert.assertThat;
|
||||
*/
|
||||
public class ExpectedSnippet implements TestRule {
|
||||
|
||||
private final SnippetFormat snippetFormat;
|
||||
private final TemplateFormat templateFormat;
|
||||
|
||||
private final SnippetMatcher snippet;
|
||||
|
||||
@@ -49,9 +49,9 @@ public class ExpectedSnippet implements TestRule {
|
||||
|
||||
private File outputDirectory;
|
||||
|
||||
public ExpectedSnippet(SnippetFormat snippetFormat) {
|
||||
this.snippetFormat = snippetFormat;
|
||||
this.snippet = SnippetMatchers.snippet(snippetFormat);
|
||||
public ExpectedSnippet(TemplateFormat templateFormat) {
|
||||
this.templateFormat = templateFormat;
|
||||
this.snippet = SnippetMatchers.snippet(templateFormat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,7 +65,7 @@ public class ExpectedSnippet implements TestRule {
|
||||
if (this.outputDirectory != null && this.expectedName != null) {
|
||||
File snippetDir = new File(this.outputDirectory, this.expectedName);
|
||||
File snippetFile = new File(snippetDir, this.expectedType + "."
|
||||
+ this.snippetFormat.getFileExtension());
|
||||
+ this.templateFormat.getFileExtension());
|
||||
assertThat(snippetFile, is(this.snippet));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ import org.springframework.restdocs.operation.OperationResponseFactory;
|
||||
import org.springframework.restdocs.operation.Parameters;
|
||||
import org.springframework.restdocs.operation.StandardOperation;
|
||||
import org.springframework.restdocs.snippet.RestDocumentationContextPlaceholderResolver;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.snippet.StandardWriterResolver;
|
||||
import org.springframework.restdocs.snippet.WriterResolver;
|
||||
import org.springframework.restdocs.templates.StandardTemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
|
||||
/**
|
||||
@@ -60,18 +60,18 @@ public class OperationBuilder {
|
||||
|
||||
private final File outputDirectory;
|
||||
|
||||
private final SnippetFormat snippetFormat;
|
||||
private final TemplateFormat templateFormat;
|
||||
|
||||
private OperationRequestBuilder requestBuilder;
|
||||
|
||||
public OperationBuilder(String name, File outputDirectory) {
|
||||
this(name, outputDirectory, SnippetFormats.asciidoctor());
|
||||
this(name, outputDirectory, TemplateFormats.asciidoctor());
|
||||
}
|
||||
|
||||
public OperationBuilder(String name, File outputDirectory, SnippetFormat snippetFormat) {
|
||||
public OperationBuilder(String name, File outputDirectory, TemplateFormat templateFormat) {
|
||||
this.name = name;
|
||||
this.outputDirectory = outputDirectory;
|
||||
this.snippetFormat = snippetFormat;
|
||||
this.templateFormat = templateFormat;
|
||||
}
|
||||
|
||||
public OperationRequestBuilder request(String uri) {
|
||||
@@ -92,14 +92,14 @@ public class OperationBuilder {
|
||||
if (this.attributes.get(TemplateEngine.class.getName()) == null) {
|
||||
this.attributes.put(TemplateEngine.class.getName(),
|
||||
new MustacheTemplateEngine(new StandardTemplateResourceResolver(
|
||||
this.snippetFormat)));
|
||||
this.templateFormat)));
|
||||
}
|
||||
RestDocumentationContext context = new RestDocumentationContext(null, null,
|
||||
this.outputDirectory);
|
||||
this.attributes.put(RestDocumentationContext.class.getName(), context);
|
||||
this.attributes.put(WriterResolver.class.getName(), new StandardWriterResolver(
|
||||
new RestDocumentationContextPlaceholderResolver(context), "UTF-8",
|
||||
this.snippetFormat));
|
||||
this.templateFormat));
|
||||
return new StandardOperation(this.name,
|
||||
(this.requestBuilder == null ? new OperationRequestBuilder(
|
||||
"http://localhost/").buildRequest() : this.requestBuilder
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.restdocs.snippet.SnippetFormat;
|
||||
import org.springframework.restdocs.snippet.SnippetFormats;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -47,18 +47,19 @@ public final class SnippetMatchers {
|
||||
|
||||
}
|
||||
|
||||
public static SnippetMatcher snippet(SnippetFormat snippetFormat) {
|
||||
return new SnippetMatcher(snippetFormat);
|
||||
public static SnippetMatcher snippet(TemplateFormat templateFormat) {
|
||||
return new SnippetMatcher(templateFormat);
|
||||
}
|
||||
|
||||
public static TableMatcher<?> tableWithHeader(SnippetFormat format, String... headers) {
|
||||
public static TableMatcher<?> tableWithHeader(TemplateFormat format,
|
||||
String... headers) {
|
||||
if ("adoc".equals(format.getFileExtension())) {
|
||||
return new AsciidoctorTableMatcher(null, headers);
|
||||
}
|
||||
return new MarkdownTableMatcher(null, headers);
|
||||
}
|
||||
|
||||
public static TableMatcher<?> tableWithTitleAndHeader(SnippetFormat format,
|
||||
public static TableMatcher<?> tableWithTitleAndHeader(TemplateFormat format,
|
||||
String title, String... headers) {
|
||||
if ("adoc".equals(format.getFileExtension())) {
|
||||
return new AsciidoctorTableMatcher(title, headers);
|
||||
@@ -66,7 +67,7 @@ public final class SnippetMatchers {
|
||||
return new MarkdownTableMatcher(title, headers);
|
||||
}
|
||||
|
||||
public static HttpRequestMatcher httpRequest(SnippetFormat format,
|
||||
public static HttpRequestMatcher httpRequest(TemplateFormat format,
|
||||
RequestMethod requestMethod, String uri) {
|
||||
if ("adoc".equals(format.getFileExtension())) {
|
||||
return new HttpRequestMatcher(requestMethod, uri,
|
||||
@@ -76,7 +77,8 @@ public final class SnippetMatchers {
|
||||
"http"), 2);
|
||||
}
|
||||
|
||||
public static HttpResponseMatcher httpResponse(SnippetFormat format, HttpStatus status) {
|
||||
public static HttpResponseMatcher httpResponse(TemplateFormat format,
|
||||
HttpStatus status) {
|
||||
if ("adoc".equals(format.getFileExtension())) {
|
||||
return new HttpResponseMatcher(status, new AsciidoctorCodeBlockMatcher<>(
|
||||
"http"), 3);
|
||||
@@ -85,7 +87,7 @@ public final class SnippetMatchers {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public static CodeBlockMatcher<?> codeBlock(SnippetFormat format, String language) {
|
||||
public static CodeBlockMatcher<?> codeBlock(TemplateFormat format, String language) {
|
||||
if ("adoc".equals(format.getFileExtension())) {
|
||||
return new AsciidoctorCodeBlockMatcher(language);
|
||||
}
|
||||
@@ -95,12 +97,12 @@ public final class SnippetMatchers {
|
||||
private static abstract class AbstractSnippetContentMatcher extends
|
||||
BaseMatcher<String> {
|
||||
|
||||
private final SnippetFormat snippetFormat;
|
||||
private final TemplateFormat templateFormat;
|
||||
|
||||
private List<String> lines = new ArrayList<>();
|
||||
|
||||
protected AbstractSnippetContentMatcher(SnippetFormat snippetFormat) {
|
||||
this.snippetFormat = snippetFormat;
|
||||
protected AbstractSnippetContentMatcher(TemplateFormat templateFormat) {
|
||||
this.templateFormat = templateFormat;
|
||||
}
|
||||
|
||||
protected void addLine(String line) {
|
||||
@@ -121,7 +123,7 @@ public final class SnippetMatchers {
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText(this.snippetFormat.getFileExtension() + " snippet");
|
||||
description.appendText(this.templateFormat.getFileExtension() + " snippet");
|
||||
description.appendText(getLinesAsString());
|
||||
}
|
||||
|
||||
@@ -157,8 +159,8 @@ public final class SnippetMatchers {
|
||||
public static class CodeBlockMatcher<T extends CodeBlockMatcher<T>> extends
|
||||
AbstractSnippetContentMatcher {
|
||||
|
||||
protected CodeBlockMatcher(SnippetFormat snippetFormat) {
|
||||
super(snippetFormat);
|
||||
protected CodeBlockMatcher(TemplateFormat templateFormat) {
|
||||
super(templateFormat);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -178,7 +180,7 @@ public final class SnippetMatchers {
|
||||
extends CodeBlockMatcher<T> {
|
||||
|
||||
protected AsciidoctorCodeBlockMatcher(String language) {
|
||||
super(SnippetFormats.asciidoctor());
|
||||
super(TemplateFormats.asciidoctor());
|
||||
this.addLine("[source," + language + "]");
|
||||
this.addLine("----");
|
||||
this.addLine("----");
|
||||
@@ -195,7 +197,7 @@ public final class SnippetMatchers {
|
||||
extends CodeBlockMatcher<T> {
|
||||
|
||||
protected MarkdownCodeBlockMatcher(String language) {
|
||||
super(SnippetFormats.markdown());
|
||||
super(TemplateFormats.markdown());
|
||||
this.addLine("```" + language);
|
||||
this.addLine("```");
|
||||
}
|
||||
@@ -286,8 +288,8 @@ public final class SnippetMatchers {
|
||||
public static abstract class TableMatcher<T extends TableMatcher<T>> extends
|
||||
AbstractSnippetContentMatcher {
|
||||
|
||||
protected TableMatcher(SnippetFormat snippetFormat) {
|
||||
super(snippetFormat);
|
||||
protected TableMatcher(TemplateFormat templateFormat) {
|
||||
super(templateFormat);
|
||||
}
|
||||
|
||||
public abstract T row(String... entries);
|
||||
@@ -303,7 +305,7 @@ public final class SnippetMatchers {
|
||||
TableMatcher<AsciidoctorTableMatcher> {
|
||||
|
||||
private AsciidoctorTableMatcher(String title, String... columns) {
|
||||
super(SnippetFormats.asciidoctor());
|
||||
super(TemplateFormats.asciidoctor());
|
||||
if (StringUtils.hasText(title)) {
|
||||
this.addLine("." + title);
|
||||
}
|
||||
@@ -340,7 +342,7 @@ public final class SnippetMatchers {
|
||||
TableMatcher<MarkdownTableMatcher> {
|
||||
|
||||
private MarkdownTableMatcher(String title, String... columns) {
|
||||
super(SnippetFormats.asciidoctor());
|
||||
super(TemplateFormats.asciidoctor());
|
||||
if (StringUtils.hasText(title)) {
|
||||
this.addLine(title);
|
||||
}
|
||||
@@ -379,12 +381,12 @@ public final class SnippetMatchers {
|
||||
*/
|
||||
public static final class SnippetMatcher extends BaseMatcher<File> {
|
||||
|
||||
private final SnippetFormat snippetFormat;
|
||||
private final TemplateFormat templateFormat;
|
||||
|
||||
private Matcher<String> expectedContents;
|
||||
|
||||
private SnippetMatcher(SnippetFormat snippetFormat) {
|
||||
this.snippetFormat = snippetFormat;
|
||||
private SnippetMatcher(TemplateFormat templateFormat) {
|
||||
this.templateFormat = templateFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -435,8 +437,8 @@ public final class SnippetMatchers {
|
||||
this.expectedContents.describeTo(description);
|
||||
}
|
||||
else {
|
||||
description
|
||||
.appendText(this.snippetFormat.getFileExtension() + " snippet");
|
||||
description.appendText(this.templateFormat.getFileExtension()
|
||||
+ " snippet");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ import static org.springframework.restdocs.request.RequestDocumentation.pathPara
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
|
||||
import static org.springframework.restdocs.snippet.Attributes.attributes;
|
||||
import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
import static org.springframework.restdocs.snippet.SnippetFormats.asciidoctor;
|
||||
import static org.springframework.restdocs.snippet.SnippetFormats.markdown;
|
||||
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
|
||||
import static org.springframework.restdocs.templates.TemplateFormats.markdown;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.codeBlock;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.httpRequest;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.httpResponse;
|
||||
@@ -130,7 +130,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
MockMvc mockMvc = MockMvcBuilders
|
||||
.webAppContextSetup(this.context)
|
||||
.apply(new MockMvcRestDocumentationConfigurer(this.restDocumentation)
|
||||
.snippets().withEncoding("UTF-8").withFormat(markdown())).build();
|
||||
.snippets().withEncoding("UTF-8").withTemplateFormat(markdown())).build();
|
||||
|
||||
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk()).andDo(document("basic-markdown"));
|
||||
|
||||
@@ -70,7 +70,7 @@ import static org.springframework.restdocs.request.RequestDocumentation.requestP
|
||||
import static org.springframework.restdocs.restassured.RestAssuredRestDocumentation.document;
|
||||
import static org.springframework.restdocs.restassured.RestAssuredRestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.restdocs.restassured.operation.preprocess.RestAssuredPreprocessors.modifyUris;
|
||||
import static org.springframework.restdocs.snippet.SnippetFormats.asciidoctor;
|
||||
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.codeBlock;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.httpRequest;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.httpResponse;
|
||||
|
||||
Reference in New Issue
Block a user