Merge branch '1.0.x'

This commit is contained in:
Andy Wilkinson
2016-05-05 09:53:30 +01:00
14 changed files with 80 additions and 81 deletions

View File

@@ -278,8 +278,8 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
}
@Test
@@ -309,7 +309,7 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils
.encodeToString("user:secret".getBytes()))
.build());
.build());
}
@Test

View File

@@ -280,8 +280,8 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
}
@Test
@@ -311,7 +311,7 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils
.encodeToString("user:secret".getBytes()))
.build());
.build());
}
@Test

View File

@@ -61,16 +61,13 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
headerWithName("Accept-Language").description("four"),
headerWithName("Cache-Control").description("five"),
headerWithName("Connection").description("six")))
.document(
operationBuilder("request-with-headers")
.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());
.document(operationBuilder("request-with-headers")
.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
@@ -140,7 +137,7 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
.header("X-Test", "test")
.header("Accept-Encoding",
"gzip, deflate")
.header("Accept", "*/*").build());
.header("Accept", "*/*").build());
}
@Test

View File

@@ -64,9 +64,9 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
.header("X-Test", "test")
.header("Content-Type",
"application/json")
.header("Etag", "lskjadldj3ii32l2ij23")
.header("Cache-Control", "max-age=0")
.header("Vary", "User-Agent").build());
.header("Etag", "lskjadldj3ii32l2ij23")
.header("Cache-Control", "max-age=0")
.header("Vary", "User-Agent").build());
}
@Test
@@ -130,7 +130,8 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
.response().header("X-Test", "test")
.header("Content-Type",
"application/json")
.header("Etag", "lskjadldj3ii32l2ij23").build());
.header("Etag", "lskjadldj3ii32l2ij23")
.build());
}
@Test

View File

@@ -86,8 +86,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
String content = "Hello, world";
this.snippet.expectHttpRequest("post-request-with-content")
.withContents(httpRequest(RequestMethod.POST, "/foo")
.header(HttpHeaders.HOST, "localhost").content(content)
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
.header(HttpHeaders.HOST, "localhost").content(content).header(
HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpRequestSnippet().document(operationBuilder("post-request-with-content")
.request("http://localhost/foo").method("POST").content(content).build());
@@ -140,8 +140,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
String content = "Hello, world";
this.snippet.expectHttpRequest("put-request-with-content")
.withContents(httpRequest(RequestMethod.PUT, "/foo")
.header(HttpHeaders.HOST, "localhost").content(content)
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
.header(HttpHeaders.HOST, "localhost").content(content).header(
HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpRequestSnippet().document(operationBuilder("put-request-with-content")
.request("http://localhost/foo").method("PUT").content(content).build());
@@ -176,7 +176,7 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", "<< data >>".getBytes()).build());
.part("image", "<< data >>".getBytes()).build());
}
@Test

View File

@@ -149,12 +149,14 @@ public class LinksSnippetTests extends AbstractSnippetTests {
new LinkDescriptor("a").description("one")
.attributes(key("foo").value("alpha")),
new LinkDescriptor("b").description("two").attributes(
key("foo").value("bravo")))).document(operationBuilder(
"links-with-custom-descriptor-attributes")
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(
resolver))
.build());
key("foo").value("bravo"))))
.document(operationBuilder(
"links-with-custom-descriptor-attributes")
.attribute(TemplateEngine.class
.getName(),
new MustacheTemplateEngine(
resolver))
.build());
}
@Test
@@ -165,7 +167,7 @@ public class LinksSnippetTests extends AbstractSnippetTests {
HypermediaDocumentation
.links(new StubLinkExtractor().withLinks(new Link("a", "alpha"),
new Link("b", "bravo")),
new LinkDescriptor("a").description("one"))
new LinkDescriptor("a").description("one"))
.and(new LinkDescriptor("b").description("two"))
.document(operationBuilder("additional-descriptors").build());
}

View File

@@ -56,7 +56,7 @@ public class PrettyPrintingContentModifierTests {
equalTo(String
.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n"
+ "<one a=\"alpha\">%n <two b=\"bravo\"/>%n</one>%n")
.getBytes()));
.getBytes()));
}
@Test

View File

@@ -75,11 +75,13 @@ public class RequestFieldsSnippetFailureTests {
@Test
public void missingOptionalRequestFieldWithNoTypeProvided() throws IOException {
this.thrown.expect(FieldTypeRequiredException.class);
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one")
.optional())).document(new OperationBuilder(
"missing-optional-request-field-with-no-type",
this.snippet.getOutputDirectory()).request("http://localhost")
.content("{ }").build());
new RequestFieldsSnippet(
Arrays.asList(fieldWithPath("a.b").description("one").optional()))
.document(new OperationBuilder(
"missing-optional-request-field-with-no-type",
this.snippet.getOutputDirectory())
.request("http://localhost").content("{ }")
.build());
}
@Test
@@ -136,7 +138,7 @@ public class RequestFieldsSnippetFailureTests {
.content("<a></a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test

View File

@@ -51,8 +51,8 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
public void mapRequestWithFields() throws IOException {
this.snippet.expectRequestFields("map-request-with-fields")
.withContents(tableWithHeader("Path", "Type", "Description")
.row("a.b", "Number", "one").row("a.c", "String", "two")
.row("a", "Object", "three"));
.row("a.b", "Number", "one").row("a.c", "String", "two").row("a",
"Object", "three"));
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one"),
fieldWithPath("a.c").description("two"),
@@ -150,15 +150,15 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
.request("http://localhost")
.content(
"{\"a\": {\"b\": 5, \"c\": \"charlie\"}}")
.build());
.build());
}
@Test
public void xmlRequestFields() throws IOException {
this.snippet.expectRequestFields("xml-request")
.withContents(tableWithHeader("Path", "Type", "Description")
.row("a/b", "b", "one").row("a/c", "c", "two")
.row("a", "a", "three"));
.row("a/b", "b", "one").row("a/c", "c", "two").row("a", "a",
"three"));
new RequestFieldsSnippet(
Arrays.asList(fieldWithPath("a/b").description("one").type("b"),
@@ -170,15 +170,15 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
.content("<a><b>5</b><c>charlie</c></a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test
public void additionalDescriptors() throws IOException {
this.snippet.expectRequestFields("additional-descriptors")
.withContents(tableWithHeader("Path", "Type", "Description")
.row("a.b", "Number", "one").row("a.c", "String", "two")
.row("a", "Object", "three"));
.row("a.b", "Number", "one").row("a.c", "String", "two").row("a",
"Object", "three"));
PayloadDocumentation
.requestFields(fieldWithPath("a.b").description("one"),
@@ -193,8 +193,8 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
public void prefixedAdditionalDescriptors() throws IOException {
this.snippet.expectRequestFields("prefixed-additional-descriptors")
.withContents(tableWithHeader("Path", "Type", "Description")
.row("a", "Object", "one").row("a.b", "Number", "two")
.row("a.c", "String", "three"));
.row("a", "Object", "one").row("a.b", "Number", "two").row("a.c",
"String", "three"));
PayloadDocumentation.requestFields(fieldWithPath("a").description("one"))
.andWithPrefix("a.", fieldWithPath("b").description("two"),

View File

@@ -63,7 +63,7 @@ public class ResponseFieldsSnippetFailureTests {
.content("<a><b>5</b></a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test
@@ -79,7 +79,7 @@ public class ResponseFieldsSnippetFailureTests {
.content("<a>foo</a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test
@@ -89,15 +89,14 @@ public class ResponseFieldsSnippetFailureTests {
String.format("The following parts of the payload were not documented:"
+ "%n<a>bar</a>%n")));
new ResponseFieldsSnippet(
Arrays.asList(
fieldWithPath("a/@id").description("one")
.type("a"))).document(new OperationBuilder(
"documented-attribute-is-removed",
Arrays.asList(fieldWithPath("a/@id").description("one").type("a")))
.document(
new OperationBuilder("documented-attribute-is-removed",
this.snippet.getOutputDirectory()).response()
.content("<a id=\"foo\">bar</a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test
@@ -124,7 +123,7 @@ public class ResponseFieldsSnippetFailureTests {
.content("<a></a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test
@@ -145,7 +144,7 @@ public class ResponseFieldsSnippetFailureTests {
.content("<a><c>5</c></a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
}

View File

@@ -80,7 +80,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
operationBuilder("array-response-with-fields").response()
.content(
"[{\"a\": {\"b\": 5}},{\"a\": {\"c\": \"charlie\"}}]")
.build());
.build());
}
@Test
@@ -145,8 +145,8 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.row("a", "Object", "three", "charlie"));
new ResponseFieldsSnippet(Arrays.asList(
fieldWithPath("a.b").description("one")
.attributes(key("foo").value("alpha")),
fieldWithPath("a.b").description("one").attributes(key("foo")
.value("alpha")),
fieldWithPath("a.c").description("two")
.attributes(key("foo").value("bravo")),
fieldWithPath("a").description("three")
@@ -164,8 +164,8 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
public void xmlResponseFields() throws IOException {
this.snippet.expectResponseFields("xml-response")
.withContents(tableWithHeader("Path", "Type", "Description")
.row("a/b", "b", "one").row("a/c", "c", "two")
.row("a", "a", "three"));
.row("a/b", "b", "one").row("a/c", "c", "two").row("a", "a",
"three"));
new ResponseFieldsSnippet(
Arrays.asList(fieldWithPath("a/b").description("one").type("b"),
fieldWithPath("a/c").description("two").type("c"),
@@ -175,7 +175,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.content("<a><b>5</b><c>charlie</c></a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test
@@ -191,7 +191,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.content("<a id=\"1\">foo</a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test
@@ -207,7 +207,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.response().content("<a>foo</a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test
@@ -248,8 +248,8 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
public void prefixedAdditionalDescriptors() throws IOException {
this.snippet.expectResponseFields("prefixed-additional-descriptors")
.withContents(tableWithHeader("Path", "Type", "Description")
.row("a", "Object", "one").row("a.b", "Number", "two")
.row("a.c", "String", "three"));
.row("a", "Object", "one").row("a.b", "Number", "two").row("a.c",
"String", "three"));
PayloadDocumentation.responseFields(fieldWithPath("a").description("one"))
.andWithPrefix("a.", fieldWithPath("b").description("two"),

View File

@@ -77,11 +77,10 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
tableWithTitleAndHeader(getTitle(), "Parameter", "Description").row("b",
"two"));
new PathParametersSnippet(
Arrays.asList(parameterWithName("b").description("two")),
true).document(operationBuilder("ignore-all-undocumented")
.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.build());
Arrays.asList(parameterWithName("b").description("two")), true)
.document(operationBuilder("ignore-all-undocumented").attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}").build());
}
@Test
@@ -125,8 +124,8 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
Arrays.asList(
parameterWithName("a").description("one")
.attributes(key("foo").value("alpha")),
parameterWithName("b").description("two")
.attributes(key("foo").value("bravo"))),
parameterWithName("b").description("two")
.attributes(key("foo").value("bravo"))),
attributes(key("title").value("The title"))).document(
operationBuilder("path-parameters-with-custom-attributes")
.attribute(

View File

@@ -116,8 +116,8 @@ public class RequestParametersSnippetTests extends AbstractSnippetTests {
Arrays.asList(
parameterWithName("a").description("one")
.attributes(key("foo").value("alpha")),
parameterWithName("b").description("two")
.attributes(key("foo").value("bravo"))),
parameterWithName("b").description("two")
.attributes(key("foo").value("bravo"))),
attributes(key("title").value("The title"))).document(
operationBuilder("request-parameters-with-custom-attributes")
.attribute(TemplateEngine.class.getName(),

View File

@@ -266,9 +266,8 @@ public class MockMvcRestDocumentationIntegrationTests {
mockMvc.perform(get("/").param("foo", "bar").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("links",
responseFields(fieldWithPath("a")
.description("The description"),
.andDo(document("links", responseFields(
fieldWithPath("a").description("The description"),
fieldWithPath("links").description("Links to other resources"))));
assertExpectedSnippetFilesExist(new File("build/generated-snippets/links"),