Polish contribution that added support for documenting HTTP headers
The main changes are:
- Update javadoc to align with changes made in 5a01016
- Update documentation with details of the new support for documenting
HTTP headers
- Add tests to verify that HTTP headers are matched case-insensitively
Closes gh-71
This commit is contained in:
@@ -44,6 +44,7 @@ import static org.springframework.restdocs.test.SnippetMatchers.tableWithHeader;
|
||||
* Tests for {@link RequestHeadersSnippet}.
|
||||
*
|
||||
* @author Andreas Evers
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class RequestHeadersSnippetTests {
|
||||
|
||||
@@ -55,31 +56,36 @@ public class RequestHeadersSnippetTests {
|
||||
|
||||
@Test
|
||||
public void requestWithHeaders() throws IOException {
|
||||
this.snippet.expectRequestHeaders("request-with-headers").withContents(//
|
||||
tableWithHeader("Name", "Description") //
|
||||
.row("X-Test", "one") //
|
||||
.row("Accept", "two") //
|
||||
.row("Accept-Encoding", "three") //
|
||||
.row("Accept-Language", "four") //
|
||||
.row("Cache-Control", "five") //
|
||||
this.snippet.expectRequestHeaders("request-with-headers").withContents(
|
||||
tableWithHeader("Name", "Description").row("X-Test", "one")
|
||||
.row("Accept", "two").row("Accept-Encoding", "three")
|
||||
.row("Accept-Language", "four").row("Cache-Control", "five")
|
||||
.row("Connection", "six"));
|
||||
new RequestHeadersSnippet(Arrays.asList(
|
||||
headerWithName("X-Test").description("one"), //
|
||||
headerWithName("Accept").description("two"), //
|
||||
headerWithName("Accept-Encoding").description("three"), //
|
||||
headerWithName("Accept-Language").description("four"), //
|
||||
headerWithName("Cache-Control").description("five"), //
|
||||
headerWithName("Connection").description("six"))) //
|
||||
headerWithName("X-Test").description("one"), headerWithName("Accept")
|
||||
.description("two"), headerWithName("Accept-Encoding")
|
||||
.description("three"), headerWithName("Accept-Language")
|
||||
.description("four"), headerWithName("Cache-Control")
|
||||
.description("five"),
|
||||
headerWithName("Connection").description("six")))
|
||||
.document(new OperationBuilder("request-with-headers", this.snippet
|
||||
.getOutputDirectory()) //
|
||||
.request("http://localhost") //
|
||||
.header("X-Test", "test") //
|
||||
.header("Accept", "*/*") //
|
||||
.header("Accept-Encoding", "gzip, deflate") //
|
||||
.header("Accept-Language", "en-US,en;q=0.5") //
|
||||
.header("Cache-Control", "max-age=0") //
|
||||
.header("Connection", "keep-alive") //
|
||||
.build());
|
||||
.getOutputDirectory()).request("http://localhost")
|
||||
.header("X-Test", "test").header("Accept", "*/*")
|
||||
.header("Accept-Encoding", "gzip, deflate")
|
||||
.header("Accept-Language", "en-US,en;q=0.5")
|
||||
.header("Cache-Control", "max-age=0")
|
||||
.header("Connection", "keep-alive").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caseInsensitiveRequestHeaders() throws IOException {
|
||||
this.snippet
|
||||
.expectRequestHeaders("case-insensitive-request-headers")
|
||||
.withContents(tableWithHeader("Name", "Description").row("X-Test", "one"));
|
||||
new RequestHeadersSnippet(Arrays.asList(headerWithName("X-Test").description(
|
||||
"one"))).document(new OperationBuilder(
|
||||
"case-insensitive-request-headers", this.snippet.getOutputDirectory())
|
||||
.request("/").header("X-test", "test").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,9 +124,9 @@ public class RequestHeadersSnippetTests {
|
||||
public void requestHeadersWithCustomDescriptorAttributes() throws IOException {
|
||||
this.snippet.expectRequestHeaders("request-headers-with-custom-attributes")
|
||||
.withContents(//
|
||||
tableWithHeader("Name", "Description", "Foo") //
|
||||
.row("X-Test", "one", "alpha") //
|
||||
.row("Accept-Encoding", "two", "bravo") //
|
||||
tableWithHeader("Name", "Description", "Foo")
|
||||
.row("X-Test", "one", "alpha")
|
||||
.row("Accept-Encoding", "two", "bravo")
|
||||
.row("Accept", "three", "charlie"));
|
||||
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
|
||||
given(resolver.resolveTemplateResource("request-headers")).willReturn(
|
||||
|
||||
@@ -41,9 +41,10 @@ import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.tableWithHeader;
|
||||
|
||||
/**
|
||||
* Tests for {@link ReponseHeadersSnippet}.
|
||||
* Tests for {@link ResponseHeadersSnippet}.
|
||||
*
|
||||
* @author Andreas Evers
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ResponseHeadersSnippetTests {
|
||||
|
||||
@@ -55,40 +56,41 @@ public class ResponseHeadersSnippetTests {
|
||||
|
||||
@Test
|
||||
public void responseWithHeaders() throws IOException {
|
||||
this.snippet.expectResponseHeaders("response-headers").withContents(//
|
||||
tableWithHeader("Name", "Description") //
|
||||
.row("X-Test", "one") //
|
||||
.row("Content-Type", "two") //
|
||||
.row("Etag", "three") //
|
||||
.row("Content-Length", "four") //
|
||||
.row("Cache-Control", "five") //
|
||||
.row("Vary", "six"));
|
||||
this.snippet.expectResponseHeaders("response-headers").withContents(
|
||||
tableWithHeader("Name", "Description").row("X-Test", "one")
|
||||
.row("Content-Type", "two").row("Etag", "three")
|
||||
.row("Cache-Control", "five").row("Vary", "six"));
|
||||
new ResponseHeadersSnippet(Arrays.asList(
|
||||
headerWithName("X-Test").description("one"), //
|
||||
headerWithName("Content-Type").description("two"), //
|
||||
headerWithName("Etag").description("three"), //
|
||||
headerWithName("Content-Length").description("four"), //
|
||||
headerWithName("Cache-Control").description("five"), //
|
||||
headerWithName("Vary").description("six"))) //
|
||||
headerWithName("X-Test").description("one"),
|
||||
headerWithName("Content-Type").description("two"), headerWithName("Etag")
|
||||
.description("three"), headerWithName("Cache-Control")
|
||||
.description("five"), headerWithName("Vary").description("six")))
|
||||
.document(new OperationBuilder("response-headers", this.snippet
|
||||
.getOutputDirectory()) //
|
||||
.response() //
|
||||
.header("X-Test", "test") //
|
||||
.header("Content-Type", "application/json") //
|
||||
.header("Etag", "lskjadldj3ii32l2ij23") //
|
||||
.header("Content-Length", "19166") //
|
||||
.header("Cache-Control", "max-age=0") //
|
||||
.header("Vary", "User-Agent") //
|
||||
.build());
|
||||
.getOutputDirectory()).response().header("X-Test", "test")
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Etag", "lskjadldj3ii32l2ij23")
|
||||
.header("Cache-Control", "max-age=0")
|
||||
.header("Vary", "User-Agent").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caseInsensitiveResponseHeaders() throws IOException {
|
||||
this.snippet
|
||||
.expectResponseHeaders("case-insensitive-response-headers")
|
||||
.withContents(tableWithHeader("Name", "Description").row("X-Test", "one"));
|
||||
new ResponseHeadersSnippet(Arrays.asList(headerWithName("X-Test").description(
|
||||
"one"))).document(new OperationBuilder(
|
||||
"case-insensitive-response-headers", this.snippet.getOutputDirectory())
|
||||
.response().header("X-test", "test").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseHeadersWithCustomDescriptorAttributes() throws IOException {
|
||||
this.snippet.expectResponseHeaders("response-headers-with-custom-attributes")
|
||||
.withContents(//
|
||||
tableWithHeader("Name", "Description", "Foo") //
|
||||
.row("X-Test", "one", "alpha") //
|
||||
.row("Content-Type", "two", "bravo") //
|
||||
.withContents(
|
||||
tableWithHeader("Name", "Description", "Foo")
|
||||
.row("X-Test", "one", "alpha")
|
||||
.row("Content-Type", "two", "bravo")
|
||||
.row("Etag", "three", "charlie"));
|
||||
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
|
||||
given(resolver.resolveTemplateResource("response-headers")).willReturn(
|
||||
|
||||
@@ -34,6 +34,7 @@ import static org.junit.Assert.assertThat;
|
||||
* generated the expected snippet.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Andreas Evers
|
||||
*/
|
||||
public class ExpectedSnippet implements TestRule {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user