Merge branch '1.0.x'

This commit is contained in:
Andy Wilkinson
2016-05-05 10:24:36 +01:00
3 changed files with 48 additions and 4 deletions

View File

@@ -68,12 +68,12 @@ public class LinksSnippetTests extends AbstractSnippetTests {
}
@Test
public void documentedOptionalLink() throws IOException {
this.snippet.expectLinks("documented-optional-link").withContents(
public void presentOptionalLink() throws IOException {
this.snippet.expectLinks("present-optional-link").withContents(
tableWithHeader("Relation", "Description").row("foo", "bar"));
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("foo", "blah")),
Arrays.asList(new LinkDescriptor("foo").description("bar").optional()))
.document(operationBuilder("documented-optional-link").build());
.document(operationBuilder("present-optional-link").build());
}
@Test

View File

@@ -98,7 +98,6 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
this.snippet.expectRequestFields("ignore-all-undocumented")
.withContents(tableWithHeader("Path", "Type", "Description").row("b",
"Number", "Field b"));
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("b").description("Field b")),
true).document(
operationBuilder("ignore-all-undocumented")
@@ -106,6 +105,29 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
.content("{\"a\": 5, \"b\": 4}").build());
}
@Test
public void missingOptionalRequestField() throws IOException {
this.snippet.expectRequestFields("missing-optional-request-field")
.withContents(tableWithHeader("Path", "Type", "Description").row("a.b",
"String", "one"));
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one")
.type(JsonFieldType.STRING).optional()))
.document(operationBuilder("missing-optional-request-field")
.request("http://localhost").content("{}").build());
}
@Test
public void presentOptionalRequestField() throws IOException {
this.snippet.expectRequestFields("present-optional-request-field")
.withContents(tableWithHeader("Path", "Type", "Description").row("a.b",
"String", "one"));
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one")
.type(JsonFieldType.STRING).optional()))
.document(operationBuilder("present-optional-request-field")
.request("http://localhost")
.content("{\"a\": { \"b\": \"bravo\"}}").build());
}
@Test
public void requestFieldsWithCustomAttributes() throws IOException {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);

View File

@@ -133,6 +133,28 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.response().content("{\"a\": \"foo\"}").build());
}
@Test
public void missingOptionalResponseField() throws IOException {
this.snippet.expectResponseFields("missing-optional-response-field")
.withContents(tableWithHeader("Path", "Type", "Description").row("a.b",
"String", "one"));
new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one")
.type(JsonFieldType.STRING).optional()))
.document(operationBuilder("missing-optional-response-field")
.response().content("{}").build());
}
@Test
public void presentOptionalResponseField() throws IOException {
this.snippet.expectResponseFields("present-optional-response-field")
.withContents(tableWithHeader("Path", "Type", "Description").row("a.b",
"String", "one"));
new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one")
.type(JsonFieldType.STRING).optional())).document(
operationBuilder("present-optional-response-field").response()
.content("{\"a\": { \"b\": \"bravo\"}}").build());
}
@Test
public void responseFieldsWithCustomDescriptorAttributes() throws IOException {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);