Break the package cycle caused by the introduction of SnippetFormat

This commit is contained in:
Andy Wilkinson
2016-02-08 10:56:12 +00:00
parent c0fac14fdf
commit cb9e10bf5a
94 changed files with 273 additions and 244 deletions

View File

@@ -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");
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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();

View File

@@ -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

View File

@@ -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();

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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();

View File

@@ -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

View File

@@ -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");
}
}

View File

@@ -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();

View File

@@ -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

View File

@@ -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();

View File

@@ -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

View File

@@ -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();

View File

@@ -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

View File

@@ -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();

View File

@@ -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

View File

@@ -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}.

View File

@@ -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>() {

View File

@@ -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));
}
}

View File

@@ -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

View File

@@ -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");
}
}