Default snippet encoding to UTF-8 and make it configurable
Previously, snippets were written to disk using the JVM’s default encoding. While this could be controlled by the file.encoding system property it was not ideal as, if the proper was not always set, it could lead to platform-dependent output being generated. Furthermore, Asciidoctor uses UTF-8 encoding by default so there was a risk of the snippets being generated in a different encoding to the encoding expected by Asciidoctor. This commit updates the configuration so that, by default, snippets are encoded as UTF-8. The RestDocumentationConfigurer API has been enhanced to allow this default to be configured as part of building the MockMvc instance. This enhancement as brought with it a more fluent configuration API that separates configuration that is related to URIs from configuration that is related to snippets. Closes gh-67
This commit is contained in:
@@ -18,6 +18,7 @@ package com.example.notes;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.springframework.restdocs.RestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.restdocs.RestDocumentation.document;
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
|
||||
@@ -40,7 +41,6 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.restdocs.config.RestDocumentationConfigurer;
|
||||
import org.springframework.restdocs.payload.FieldType;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
@@ -72,7 +72,18 @@ public class ApiDocumentation {
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(new RestDocumentationConfigurer()).build();
|
||||
.apply(documentationConfiguration()).build();
|
||||
this.mockMvc = MockMvcBuilders
|
||||
.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration()
|
||||
.uris()
|
||||
.withScheme("https")
|
||||
.withHost("localhost")
|
||||
.withPort(8443)
|
||||
.and().snippets()
|
||||
.withEncoding("ISO-8859-1"))
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user