Merge branch '1.2.x'

This commit is contained in:
Andy Wilkinson
2018-08-08 14:48:16 +01:00
155 changed files with 465 additions and 1030 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 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.
@@ -27,6 +27,7 @@ import org.junit.runners.Parameterized.Parameters;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpStatus;
import org.springframework.restdocs.templates.TemplateFormat;
import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.test.GeneratedSnippets;
import org.springframework.restdocs.test.OperationBuilder;
import org.springframework.restdocs.test.SnippetConditions;
@@ -36,9 +37,6 @@ import org.springframework.restdocs.test.SnippetConditions.HttpResponseCondition
import org.springframework.restdocs.test.SnippetConditions.TableCondition;
import org.springframework.web.bind.annotation.RequestMethod;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
import static org.springframework.restdocs.templates.TemplateFormats.markdown;
/**
* Abstract base class for testing snippet generation.
*
@@ -57,8 +55,9 @@ public abstract class AbstractSnippetTests {
@Parameters(name = "{0}")
public static List<Object[]> parameters() {
return Arrays.asList(new Object[] { "Asciidoctor", asciidoctor() },
new Object[] { "Markdown", markdown() });
return Arrays.asList(
new Object[] { "Asciidoctor", TemplateFormats.asciidoctor() },
new Object[] { "Markdown", TemplateFormats.markdown() });
}
public AbstractSnippetTests(String name, TemplateFormat templateFormat) {

View File

@@ -279,6 +279,7 @@ public class RestDocumentationConfigurerTests {
public TestOperationPreprocessorsConfigurer operationPreprocessors() {
return this.operationPreprocessorsConfigurer;
}
}
private static final class TestSnippetConfigurer extends
@@ -297,6 +298,7 @@ public class RestDocumentationConfigurerTests {
TestRestDocumentationConfigurer parent) {
super(parent);
}
}
}

View File

@@ -458,6 +458,7 @@ public class ResourceBundleConstraintDescriptionResolverTests {
@org.hibernate.validator.constraints.URL
private String url;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 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.
@@ -24,12 +24,12 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.restdocs.snippet.SnippetException;
import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.test.OperationBuilder;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
/**
* Tests for failures when rendering {@link RequestHeadersSnippet} due to missing or
@@ -40,7 +40,8 @@ import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor
public class RequestHeadersSnippetFailureTests {
@Rule
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
public OperationBuilder operationBuilder = new OperationBuilder(
TemplateFormats.asciidoctor());
@Rule
public ExpectedException thrown = ExpectedException.none();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 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.
@@ -24,12 +24,12 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.restdocs.snippet.SnippetException;
import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.test.OperationBuilder;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
/**
* Tests for failures when rendering {@link ResponseHeadersSnippet} due to missing or
@@ -40,7 +40,8 @@ import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor
public class ResponseHeadersSnippetFailureTests {
@Rule
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
public OperationBuilder operationBuilder = new OperationBuilder(
TemplateFormats.asciidoctor());
@Rule
public ExpectedException thrown = ExpectedException.none();

View File

@@ -25,10 +25,10 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.restdocs.snippet.SnippetException;
import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.test.OperationBuilder;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
/**
* Tests for failures when rendering {@link LinksSnippet} due to missing or undocumented
@@ -39,7 +39,8 @@ import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor
public class LinksSnippetFailureTests {
@Rule
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
public OperationBuilder operationBuilder = new OperationBuilder(
TemplateFormats.asciidoctor());
@Rule
public ExpectedException thrown = ExpectedException.none();

View File

@@ -24,17 +24,17 @@ import org.junit.Test;
import org.springframework.core.io.FileSystemResource;
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.GeneratedSnippets;
import org.springframework.restdocs.test.OperationBuilder;
import org.springframework.restdocs.test.SnippetConditions;
import static org.assertj.core.api.Assertions.assertThat;
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.templates.TemplateFormats.asciidoctor;
import static org.springframework.restdocs.test.SnippetConditions.tableWithHeader;
/**
* Tests for {@link RequestFieldsSnippet} that are specific to Asciidoctor.
@@ -44,10 +44,12 @@ import static org.springframework.restdocs.test.SnippetConditions.tableWithHeade
public class AsciidoctorRequestFieldsSnippetTests {
@Rule
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
public OperationBuilder operationBuilder = new OperationBuilder(
TemplateFormats.asciidoctor());
@Rule
public GeneratedSnippets generatedSnippets = new GeneratedSnippets(asciidoctor());
public GeneratedSnippets generatedSnippets = new GeneratedSnippets(
TemplateFormats.asciidoctor());
@Test
public void requestFieldsWithListDescription() throws IOException {
@@ -64,11 +66,12 @@ public class AsciidoctorRequestFieldsSnippetTests {
resolver))
.request("http://localhost")
.content("{\"a\": \"foo\"}").build());
assertThat(this.generatedSnippets.requestFields())
.is(tableWithHeader(asciidoctor(), "Path", "Type", "Description")
//
.row("a", "String", String.format(" - one%n - two"))
.configuration("[cols=\"1,1,1a\"]"));
assertThat(this.generatedSnippets.requestFields()).is(SnippetConditions
.tableWithHeader(TemplateFormats.asciidoctor(), "Path", "Type",
"Description")
//
.row("a", "String", String.format(" - one%n - two"))
.configuration("[cols=\"1,1,1a\"]"));
}
private FileSystemResource snippetResource(String name) {

View File

@@ -27,13 +27,13 @@ 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.templates.TemplateFormats;
import org.springframework.restdocs.test.OperationBuilder;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
/**
* Tests for failures when rendering {@link ResponseFieldsSnippet} due to missing or
@@ -44,7 +44,8 @@ import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor
public class ResponseFieldsSnippetFailureTests {
@Rule
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
public OperationBuilder operationBuilder = new OperationBuilder(
TemplateFormats.asciidoctor());
@Rule
public ExpectedException thrown = ExpectedException.none();

View File

@@ -26,11 +26,11 @@ import org.junit.rules.ExpectedException;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.restdocs.snippet.SnippetException;
import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.test.OperationBuilder;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
/**
* Tests for failures when rendering {@link PathParametersSnippet} due to missing or
@@ -41,7 +41,8 @@ import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor
public class PathParametersSnippetFailureTests {
@Rule
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
public OperationBuilder operationBuilder = new OperationBuilder(
TemplateFormats.asciidoctor());
@Rule
public ExpectedException thrown = ExpectedException.none();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 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.
@@ -25,11 +25,11 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.restdocs.snippet.SnippetException;
import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.test.OperationBuilder;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
/**
* Tests for failures when rendering {@link RequestParametersSnippet} due to missing or
@@ -40,7 +40,8 @@ import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor
public class RequestParametersSnippetFailureTests {
@Rule
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
public OperationBuilder operationBuilder = new OperationBuilder(
TemplateFormats.asciidoctor());
@Rule
public ExpectedException thrown = ExpectedException.none();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 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.
@@ -25,11 +25,11 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.restdocs.snippet.SnippetException;
import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.test.OperationBuilder;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.springframework.restdocs.request.RequestDocumentation.partWithName;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
/**
* Tests for failures when rendering {@link RequestPartsSnippet} due to missing or
@@ -40,7 +40,8 @@ import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor
public class RequestPartsSnippetFailureTests {
@Rule
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
public OperationBuilder operationBuilder = new OperationBuilder(
TemplateFormats.asciidoctor());
@Rule
public ExpectedException thrown = ExpectedException.none();

View File

@@ -27,13 +27,13 @@ import org.junit.rules.TemporaryFolder;
import org.springframework.restdocs.ManualRestDocumentation;
import org.springframework.restdocs.RestDocumentationContext;
import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
/**
* Tests for {@link StandardWriterResolver}.
@@ -49,7 +49,7 @@ public class StandardWriterResolverTests {
PlaceholderResolverFactory.class);
private final StandardWriterResolver resolver = new StandardWriterResolver(
this.placeholderResolverFactory, "UTF-8", asciidoctor());
this.placeholderResolverFactory, "UTF-8", TemplateFormats.asciidoctor());
@Test
public void absoluteInput() {

View File

@@ -29,7 +29,6 @@ import org.springframework.core.io.Resource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
/**
* Tests for {@link TemplateResourceResolver}.
@@ -42,7 +41,7 @@ public class StandardTemplateResourceResolverTests {
public final ExpectedException thrown = ExpectedException.none();
private final TemplateResourceResolver resolver = new StandardTemplateResourceResolver(
asciidoctor());
TemplateFormats.asciidoctor());
private final TestClassLoader classLoader = new TestClassLoader();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 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.
@@ -115,10 +115,10 @@ public class OperationBuilder extends OperationTestRule {
new RestDocumentationContextPlaceholderResolverFactory(), "UTF-8",
this.templateFormat));
return new StandardOperation(this.name,
(this.requestBuilder == null
((this.requestBuilder == null)
? new OperationRequestBuilder("http://localhost/").buildRequest()
: this.requestBuilder.buildRequest()),
this.responseBuilder == null
(this.responseBuilder == null)
? new OperationResponseBuilder().buildResponse()
: this.responseBuilder.buildResponse(),
this.attributes);
@@ -259,7 +259,9 @@ public class OperationBuilder extends OperationTestRule {
this.headers.add(name, value);
return this;
}
}
}
/**

View File

@@ -104,7 +104,6 @@ public class OutputCapture implements TestRule {
/**
* Verify that the output is matched by the supplied {@code matcher}. Verification is
* performed after the test method has executed.
*
* @param matcher the matcher
*/
public final void expect(Matcher<? super String> matcher) {

View File

@@ -96,7 +96,7 @@ public final class SnippetConditions {
return new MarkdownCodeBlockCondition(language);
}
private static abstract class AbstractSnippetContentCondition
private abstract static class AbstractSnippetContentCondition
extends Condition<String> {
private List<String> lines = new ArrayList<>();
@@ -143,6 +143,7 @@ public final class SnippetConditions {
}
return writer.toString();
}
}
/**
@@ -170,8 +171,8 @@ public final class SnippetConditions {
extends CodeBlockCondition<T> {
protected AsciidoctorCodeBlockCondition(String language, String options) {
this.addLine("[source" + (language == null ? "" : "," + language)
+ (options == null ? "" : ",options=\"" + options + "\"") + "]");
this.addLine("[source" + ((language != null) ? "," + language : "")
+ ((options != null) ? ",options=\"" + options + "\"" : "") + "]");
this.addLine("----");
this.addLine("----");
}
@@ -187,7 +188,7 @@ public final class SnippetConditions {
extends CodeBlockCondition<T> {
protected MarkdownCodeBlockCondition(String language) {
this.addLine("```" + (language == null ? "" : language));
this.addLine("```" + ((language != null) ? language : ""));
this.addLine("```");
}
@@ -198,7 +199,7 @@ public final class SnippetConditions {
*
* @param <T> The type of the Condition
*/
public static abstract class HttpCondition<T extends HttpCondition<T>>
public abstract static class HttpCondition<T extends HttpCondition<T>>
extends Condition<String> {
private final CodeBlockCondition<?> delegate;
@@ -233,11 +234,6 @@ public final class SnippetConditions {
return this.delegate.matches(item);
}
// @Override
// public void describeTo(Description description) {
// this.delegate.describeTo(description);
// }
}
/**
@@ -275,7 +271,7 @@ public final class SnippetConditions {
*
* @param <T> The concrete type of the Condition
*/
public static abstract class TableCondition<T extends TableCondition<T>>
public abstract static class TableCondition<T extends TableCondition<T>>
extends AbstractSnippetContentCondition {
public abstract T row(String... entries);