This commit is contained in:
Andy Wilkinson
2017-10-26 16:10:42 +01:00
parent f0c69ade5e
commit 276a1807c7
7 changed files with 57 additions and 60 deletions

View File

@@ -91,7 +91,8 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
@Test
public void responseHeadersWithCustomAttributes() throws IOException {
this.snippets.expectResponseHeaders().withContents(containsString("Custom title"));
this.snippets.expectResponseHeaders()
.withContents(containsString("Custom title"));
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("response-headers"))
.willReturn(snippetResource("response-headers-with-title"));
@@ -132,8 +133,7 @@ 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

@@ -88,8 +88,9 @@ public class LinksSnippetTests extends AbstractSnippetTests {
@Test
public void documentedLinks() throws IOException {
this.snippets.expectLinks().withContents(tableWithHeader("Relation", "Description")
.row("`a`", "one").row("`b`", "two"));
this.snippets.expectLinks()
.withContents(tableWithHeader("Relation", "Description").row("`a`", "one")
.row("`b`", "two"));
new LinksSnippet(
new StubLinkExtractor().withLinks(new Link("a", "alpha"),
new Link("b", "bravo")),
@@ -100,8 +101,9 @@ public class LinksSnippetTests extends AbstractSnippetTests {
@Test
public void linkDescriptionFromTitleInPayload() throws IOException {
this.snippets.expectLinks().withContents(tableWithHeader("Relation", "Description")
.row("`a`", "one").row("`b`", "Link b"));
this.snippets.expectLinks()
.withContents(tableWithHeader("Relation", "Description").row("`a`", "one")
.row("`b`", "Link b"));
new LinksSnippet(
new StubLinkExtractor().withLinks(new Link("a", "alpha", "Link a"),
new Link("b", "bravo", "Link b")),
@@ -146,28 +148,31 @@ public class LinksSnippetTests extends AbstractSnippetTests {
.attributes(key("foo").value("alpha")),
new LinkDescriptor("b").description("two")
.attributes(key("foo").value("bravo"))))
.document(this.operationBuilder.attribute(
TemplateEngine.class.getName(),
.document(this.operationBuilder
.attribute(TemplateEngine.class
.getName(),
new MustacheTemplateEngine(resolver))
.build());
.build());
}
@Test
public void additionalDescriptors() throws IOException {
this.snippets.expectLinks().withContents(tableWithHeader("Relation", "Description")
.row("`a`", "one").row("`b`", "two"));
this.snippets.expectLinks()
.withContents(tableWithHeader("Relation", "Description").row("`a`", "one")
.row("`b`", "two"));
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(this.operationBuilder.build());
}
@Test
public void tableCellContentIsEscapedWhenNecessary() throws IOException {
this.snippets.expectLinks().withContents(tableWithHeader("Relation", "Description")
.row(escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two")));
this.snippets.expectLinks()
.withContents(tableWithHeader("Relation", "Description").row(
escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two")));
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("Foo|Bar", "foo")),
Arrays.asList(new LinkDescriptor("Foo|Bar").description("one|two")))
.document(this.operationBuilder.build());

View File

@@ -58,7 +58,7 @@ public class RequestPartFieldsSnippetTests extends AbstractSnippetTests {
.part("one",
"{\"a\": {\"b\": 5, \"c\": \"charlie\"}}"
.getBytes())
.build());
.build());
}
@Test
@@ -77,7 +77,7 @@ public class RequestPartFieldsSnippetTests extends AbstractSnippetTests {
.part("one",
"{\"a\": {\"b\": 5, \"c\": \"charlie\"}}"
.getBytes())
.build());
.build());
}
@Test

View File

@@ -53,12 +53,10 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
tableWithTitleAndHeader(getTitle(), "Parameter", "Description")
.row("`a`", "one").row("`b`", "two"));
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
parameterWithName("b").description("two")))
.document(this.operationBuilder
.attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.build());
parameterWithName("b").description("two"))).document(this.operationBuilder
.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.build());
}
@Test
@@ -67,12 +65,10 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
tableWithTitleAndHeader(getTitle(), "Parameter", "Description").row("`b`",
"two"));
new PathParametersSnippet(Arrays.asList(parameterWithName("a").ignored(),
parameterWithName("b").description("two")))
.document(this.operationBuilder
.attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.build());
parameterWithName("b").description("two"))).document(this.operationBuilder
.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.build());
}
@Test
@@ -81,10 +77,11 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
tableWithTitleAndHeader(getTitle(), "Parameter", "Description").row("`b`",
"two"));
new PathParametersSnippet(
Arrays.asList(parameterWithName("b").description("two")), true)
.document(this.operationBuilder.attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}").build());
Arrays.asList(parameterWithName("b").description("two")),
true).document(this.operationBuilder
.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.build());
}
@Test
@@ -117,12 +114,10 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
tableWithTitleAndHeader(getTitle(), "Parameter", "Description")
.row("`a`", "one").row("`b`", "two"));
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
parameterWithName("b").description("two")))
.document(this.operationBuilder
.attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}?foo=bar")
.build());
parameterWithName("b").description("two"))).document(this.operationBuilder
.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}?foo=bar")
.build());
}
@Test
@@ -131,12 +126,10 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
tableWithTitleAndHeader(getTitle(), "Parameter", "Description")
.row("`a`", "one").row("`b`", "two"));
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
parameterWithName("b").description("two")))
.document(this.operationBuilder
.attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}?foo={c}")
.build());
parameterWithName("b").description("two"))).document(this.operationBuilder
.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}?foo={c}")
.build());
}
@Test
@@ -150,8 +143,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(this.operationBuilder
.attribute(

View File

@@ -117,12 +117,11 @@ public class RequestParametersSnippetTests extends AbstractSnippetTests {
.willReturn(snippetResource("request-parameters-with-title"));
this.snippets.expectRequestParameters().withContents(containsString("The title"));
new RequestParametersSnippet(
Arrays.asList(
parameterWithName("a").description("one")
.attributes(key("foo").value("alpha")),
parameterWithName("b").description("two")
.attributes(key("foo").value("bravo"))),
new RequestParametersSnippet(Arrays.asList(
parameterWithName("a").description("one")
.attributes(key("foo").value("alpha")),
parameterWithName("b").description("two")
.attributes(key("foo").value("bravo"))),
attributes(
key("title").value("The title")))
.document(

View File

@@ -108,12 +108,11 @@ public class RequestPartsSnippetTests extends AbstractSnippetTests {
.willReturn(snippetResource("request-parts-with-title"));
this.snippets.expectRequestParts().withContents(containsString("The title"));
new RequestPartsSnippet(
Arrays.asList(
partWithName("a").description("one")
.attributes(key("foo").value("alpha")),
partWithName("b").description("two")
.attributes(key("foo").value("bravo"))),
new RequestPartsSnippet(Arrays.asList(
partWithName("a").description("one")
.attributes(key("foo").value("alpha")),
partWithName("b").description("two")
.attributes(key("foo").value("bravo"))),
attributes(
key("title").value("The title")))
.document(

View File

@@ -48,7 +48,8 @@ public class TemplatedSnippetTests {
TemplateFormats.asciidoctor());
@Rule
public ExpectedSnippets snippets = new ExpectedSnippets(TemplateFormats.asciidoctor());
public ExpectedSnippets snippets = new ExpectedSnippets(
TemplateFormats.asciidoctor());
@Test
public void attributesAreCopied() {