Merge branch '1.2.x'

This commit is contained in:
Andy Wilkinson
2018-03-27 13:01:20 +01:00
31 changed files with 329 additions and 424 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -167,10 +167,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void postRequestWithMultipleParameters() throws IOException {
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash")
.content("$ curl 'http://localhost/foo' -i -X POST"
+ " -d 'k1=v1&k1=v1-bis&k2=v2'"));
this.snippets.expectCurlRequest().withContents(
codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X POST"
+ " -d 'k1=v1&k1=v1-bis&k2=v2'"));
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo").method("POST")
.param("k1", "v1", "v1-bis").param("k2", "v2").build());
@@ -224,10 +223,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void putRequestWithMultipleParameters() throws IOException {
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash")
.content("$ curl 'http://localhost/foo' -i -X PUT"
+ " -d 'k1=v1&k1=v1-bis&k2=v2'"));
this.snippets.expectCurlRequest().withContents(
codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X PUT"
+ " -d 'k1=v1&k1=v1-bis&k2=v2'"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("PUT").param("k1", "v1")
.param("k1", "v1-bis").param("k2", "v2").build());
@@ -247,11 +245,10 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash").content("$ curl 'http://localhost/foo' -i"
+ " -H 'Content-Type: application/json' -H 'a: alpha'"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
}
@Test
@@ -285,10 +282,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
+ "'metadata={\"description\": \"foo\"}'";
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash").content(expectedContent));
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
}
@@ -299,10 +295,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
+ "'image=@documents/images/example.png;type=image/png'";
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash").content(expectedContent));
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
@@ -315,10 +310,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
+ "'image=@documents/images/example.png'";
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash").content(expectedContent));
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.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());
}
@@ -331,10 +325,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
+ "-F 'b=banana'";
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash").content(expectedContent));
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.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").and()
.param("a", "apple", "avocado").param("b", "banana").build());
@@ -344,11 +337,10 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
public void basicAuthCredentialsAreSuppliedUsingUserOption() throws IOException {
this.snippets.expectCurlRequest().withContents(codeBlock("bash")
.content("$ curl 'http://localhost/foo' -i -u 'user:secret'"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils
.encodeToString("user:secret".getBytes()))
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils.encodeToString("user:secret".getBytes()))
.build());
}
@@ -375,12 +367,11 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
.withContents(codeBlock("bash").content(
"$ curl 'http://localhost/foo' -i" + " -H 'Host: api.example.com'"
+ " -H 'Content-Type: application/json' -H 'a: alpha'"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.header(HttpHeaders.HOST, "api.example.com")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.HOST, "api.example.com")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -168,10 +168,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
@Test
public void postRequestWithMultipleParameters() throws IOException {
this.snippets.expectHttpieRequest()
.withContents(codeBlock("bash")
.content("$ http --form POST 'http://localhost/foo'"
+ " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
this.snippets.expectHttpieRequest().withContents(
codeBlock("bash").content("$ http --form POST 'http://localhost/foo'"
+ " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
new HttpieRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo").method("POST")
.param("k1", "v1", "v1-bis").param("k2", "v2").build());
@@ -225,10 +224,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
@Test
public void putRequestWithMultipleParameters() throws IOException {
this.snippets.expectHttpieRequest()
.withContents(codeBlock("bash")
.content("$ http --form PUT 'http://localhost/foo'"
+ " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
this.snippets.expectHttpieRequest().withContents(
codeBlock("bash").content("$ http --form PUT 'http://localhost/foo'"
+ " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("PUT").param("k1", "v1")
.param("k1", "v1-bis").param("k2", "v2").build());
@@ -248,11 +246,10 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
this.snippets.expectHttpieRequest().withContents(
codeBlock("bash").content("$ http GET 'http://localhost/foo'"
+ " 'Content-Type:application/json' 'a:alpha'"));
new HttpieRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
}
@Test
@@ -283,10 +280,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
+ " 'metadata'@<(echo '{\"description\": \"foo\"}')";
this.snippets.expectHttpieRequest()
.withContents(codeBlock("bash").content(expectedContent));
new HttpieRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
}
@@ -297,10 +293,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
+ " 'image'@'documents/images/example.png'";
this.snippets.expectHttpieRequest()
.withContents(codeBlock("bash").content(expectedContent));
new HttpieRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
@@ -312,10 +307,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
+ " 'image'@'documents/images/example.png'";
this.snippets.expectHttpieRequest()
.withContents(codeBlock("bash").content(expectedContent));
new HttpieRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.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());
}
@@ -327,10 +321,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
+ " 'b=banana'";
this.snippets.expectHttpieRequest()
.withContents(codeBlock("bash").content(expectedContent));
new HttpieRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.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").and()
.param("a", "apple", "avocado").param("b", "banana").build());
@@ -340,11 +333,10 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
public void basicAuthCredentialsAreSuppliedUsingAuthOption() throws IOException {
this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
.content("$ http --auth 'user:secret' GET 'http://localhost/foo'"));
new HttpieRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils
.encodeToString("user:secret".getBytes()))
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils.encodeToString("user:secret".getBytes()))
.build());
}
@@ -371,12 +363,11 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
.withContents(codeBlock("bash").content(
"$ http GET 'http://localhost/foo' 'Host:api.example.com'"
+ " 'Content-Type:application/json' 'a:alpha'"));
new HttpieRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.header(HttpHeaders.HOST, "api.example.com")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.HOST, "api.example.com")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,8 +83,8 @@ public class RestDocumentationConfigurerTests {
assertThat(configuration, hasEntry(equalTo(WriterResolver.class.getName()),
instanceOf(StandardWriterResolver.class)));
assertThat(configuration,
hasEntry(
equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
hasEntry(equalTo(
RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
instanceOf(List.class)));
List<Snippet> defaultSnippets = (List<Snippet>) configuration
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
@@ -138,8 +138,8 @@ public class RestDocumentationConfigurerTests {
this.configurer.snippets().withDefaults(CliDocumentation.curlRequest())
.apply(configuration, createContext());
assertThat(configuration,
hasEntry(
equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
hasEntry(equalTo(
RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
instanceOf(List.class)));
@SuppressWarnings("unchecked")
List<Snippet> defaultSnippets = (List<Snippet>) configuration
@@ -155,8 +155,8 @@ public class RestDocumentationConfigurerTests {
this.configurer.snippets().withAdditionalDefaults(snippet).apply(configuration,
createContext());
assertThat(configuration,
hasEntry(
equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
hasEntry(equalTo(
RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
instanceOf(List.class)));
List<Snippet> defaultSnippets = (List<Snippet>) configuration
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,17 +61,10 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
headerWithName("Accept-Encoding").description("three"),
headerWithName("Accept-Language").description("four"),
headerWithName("Cache-Control").description("five"),
headerWithName(
"Connection")
.description("six")))
.document(
this.operationBuilder
.request(
"http://localhost")
.header("X-Test", "test")
.header("Accept", "*/*")
.header("Accept-Encoding",
"gzip, deflate")
headerWithName("Connection").description("six"))).document(
this.operationBuilder.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());
@@ -105,8 +98,7 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
given(resolver.resolveTemplateResource("request-headers"))
.willReturn(snippetResource("request-headers-with-title"));
new RequestHeadersSnippet(
Arrays.asList(headerWithName("X-Test").description("one")),
attributes(
Arrays.asList(headerWithName("X-Test").description("one")), attributes(
key("title").value("Custom title")))
.document(
this.operationBuilder
@@ -143,7 +135,7 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
.header("X-Test", "test")
.header("Accept-Encoding",
"gzip, deflate")
.header("Accept", "*/*").build());
.header("Accept", "*/*").build());
}
@Test
@@ -160,10 +152,7 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
headerWithName("Accept-Encoding").description("three"),
headerWithName("Accept-Language").description("four"))
.and(headerWithName("Cache-Control").description("five"),
headerWithName(
"Connection")
.description(
"six"))
headerWithName("Connection").description("six"))
.document(this.operationBuilder.request("http://localhost")
.header("X-Test", "test").header("Accept", "*/*")
.header("Accept-Encoding", "gzip, deflate")

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,15 +58,12 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
headerWithName("Content-Type").description("two"),
headerWithName("Etag").description("three"),
headerWithName("Cache-Control").description("five"),
headerWithName("Vary").description("six")))
.document(
this.operationBuilder.response()
.header("X-Test", "test")
.header("Content-Type",
"application/json")
.header("Etag", "lskjadldj3ii32l2ij23")
.header("Cache-Control", "max-age=0")
.header("Vary", "User-Agent").build());
headerWithName("Vary").description("six"))).document(
this.operationBuilder.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
@@ -97,8 +94,7 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
given(resolver.resolveTemplateResource("response-headers"))
.willReturn(snippetResource("response-headers-with-title"));
new ResponseHeadersSnippet(
Arrays.asList(headerWithName("X-Test").description("one")),
attributes(
Arrays.asList(headerWithName("X-Test").description("one")), attributes(
key("title").value("Custom title")))
.document(
this.operationBuilder
@@ -133,7 +129,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

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -278,10 +278,9 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
.header("Content-Type",
"multipart/form-data; boundary=" + BOUNDARY)
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
new HttpRequestSnippet().document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", "<< data >>".getBytes()).build());
}
@@ -294,10 +293,9 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
.header("Content-Type",
"multipart/form-data; boundary=" + BOUNDARY)
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
new HttpRequestSnippet().document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", "<< data >>".getBytes()).submittedFileName("image.png")
.build());
}
@@ -321,10 +319,9 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
.header("Content-Type",
"multipart/form-data; boundary=" + BOUNDARY)
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
new HttpRequestSnippet().document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.param("a", "apple", "avocado").param("b", "banana")
.part("image", "<< data >>".getBytes()).build());
}
@@ -341,11 +338,10 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
.header("Content-Type",
"multipart/form-data; boundary=" + BOUNDARY)
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
new HttpRequestSnippet().document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.param("a").part("image", "<< data >>".getBytes()).build());
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.param("a").part("image", "<< data >>".getBytes()).build());
}
@Test
@@ -358,10 +354,9 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
.header("Content-Type",
"multipart/form-data; boundary=" + BOUNDARY)
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
new HttpRequestSnippet().document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", "<< data >>".getBytes())
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE).build());
}
@@ -383,15 +378,11 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("http-request"))
.willReturn(snippetResource("http-request-with-title"));
new HttpRequestSnippet(
attributes(
key("title").value("Title for the request")))
.document(
this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(
resolver))
.request("http://localhost/foo").build());
new HttpRequestSnippet(attributes(key("title").value("Title for the request")))
.document(this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.request("http://localhost/foo").build());
}
private String createPart(String content) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -65,11 +65,9 @@ public class HttpResponseSnippetTests extends AbstractSnippetTests {
public void responseWithHeaders() throws IOException {
this.snippets.expectHttpResponse().withContents(httpResponse(HttpStatus.OK)
.header("Content-Type", "application/json").header("a", "alpha"));
new HttpResponseSnippet()
.document(this.operationBuilder.response()
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
new HttpResponseSnippet().document(this.operationBuilder.response()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -148,11 +148,10 @@ 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
@@ -163,7 +162,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(this.operationBuilder.build());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -262,10 +262,8 @@ public class JsonFieldTypeResolverTests {
@Test
public void intermediateWildcardWithVaryingType() throws IOException {
assertThat(
this.fieldTypeResolver.resolveFieldType(new FieldDescriptor("a.*.d"),
createPayload(
"{\"a\": {\"b\": {\"d\": 4}, \"c\": {\"d\": \"four\"}}}}")),
assertThat(this.fieldTypeResolver.resolveFieldType(new FieldDescriptor("a.*.d"),
createPayload("{\"a\": {\"b\": {\"d\": 4}, \"c\": {\"d\": \"four\"}}}}")),
equalTo(JsonFieldType.VARIES));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,18 +78,12 @@ public class RequestBodyPartSnippetTests extends AbstractSnippetTests {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("request-part-body"))
.willReturn(snippetResource("request-part-body-with-language"));
requestPartBody("one",
attributes(
key("language").value("json")))
.document(
this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(
resolver))
.request("http://localhost")
.part("one",
"{\"a\":\"alpha\"}".getBytes())
.build());
requestPartBody("one", attributes(key("language").value("json")))
.document(this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.request("http://localhost")
.part("one", "{\"a\":\"alpha\"}".getBytes()).build());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,16 +77,12 @@ public class RequestBodySnippetTests extends AbstractSnippetTests {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("request-body"))
.willReturn(snippetResource("request-body-with-language"));
requestBody(
attributes(
key("language").value("json")))
.document(
this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(
resolver))
.request("http://localhost")
.content("{\"a\":\"alpha\"}").build());
requestBody(attributes(key("language").value("json")))
.document(this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.request("http://localhost").content("{\"a\":\"alpha\"}")
.build());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -233,7 +233,7 @@ public class RequestFieldsSnippetFailureTests {
this.operationBuilder.request("http://localhost")
.content("{\"a\":[{\"b\": 1,\"c\": 2}, "
+ "{\"c\": 2}, {\"b\": 1,\"c\": 2}]}")
.build());
.build());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -118,7 +118,7 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
.document(this.operationBuilder.request("http://localhost")
.content("[{\"a\": {\"b\": 5, \"c\":\"charlie\"}},"
+ "{\"a\": {\"b\": 4, \"c\":\"chalk\"}}]")
.build());
.build());
}
@Test
@@ -235,8 +235,8 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
.willReturn(snippetResource("request-fields-with-title"));
this.snippets.expectRequestFields().withContents(containsString("Custom title"));
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")),
attributes(
new RequestFieldsSnippet(
Arrays.asList(fieldWithPath("a").description("one")), attributes(
key("title").value("Custom title")))
.document(
this.operationBuilder
@@ -265,15 +265,13 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
.attributes(key("foo").value("bravo")),
fieldWithPath("a").description("three")
.attributes(key("foo").value("charlie"))))
.document(
this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(
resolver))
.request("http://localhost")
.content(
"{\"a\": {\"b\": 5, \"c\": \"charlie\"}}")
.build());
.document(this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.request("http://localhost")
.content(
"{\"a\": {\"b\": 5, \"c\": \"charlie\"}}")
.build());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,17 +48,13 @@ public class RequestPartFieldsSnippetTests extends AbstractSnippetTests {
.row("`a.b`", "`Number`", "one").row("`a.c`", "`String`", "two")
.row("`a`", "`Object`", "three"));
new RequestPartFieldsSnippet("one",
Arrays.asList(fieldWithPath("a.b").description("one"),
fieldWithPath("a.c").description("two"), fieldWithPath("a")
.description("three")))
.document(
this.operationBuilder
.request("http://localhost")
.part("one",
"{\"a\": {\"b\": 5, \"c\": \"charlie\"}}"
.getBytes())
.build());
new RequestPartFieldsSnippet("one", Arrays.asList(
fieldWithPath("a.b").description("one"),
fieldWithPath("a.c").description("two"),
fieldWithPath("a").description("three"))).document(this.operationBuilder
.request("http://localhost")
.part("one", "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}".getBytes())
.build());
}
@Test
@@ -67,17 +63,12 @@ public class RequestPartFieldsSnippetTests extends AbstractSnippetTests {
.withContents(tableWithHeader("Path", "Type", "Description")
.row("`b`", "`Number`", "one").row("`c`", "`String`", "two"));
new RequestPartFieldsSnippet("one",
beneathPath("a"), Arrays
.asList(fieldWithPath("b").description("one"),
fieldWithPath("c").description("two")))
.document(
this.operationBuilder
.request("http://localhost")
.part("one",
"{\"a\": {\"b\": 5, \"c\": \"charlie\"}}"
.getBytes())
.build());
new RequestPartFieldsSnippet("one", beneathPath("a"), Arrays.asList(
fieldWithPath("b").description("one"),
fieldWithPath("c").description("two"))).document(this.operationBuilder
.request("http://localhost")
.part("one", "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}".getBytes())
.build());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,16 +77,11 @@ public class ResponseBodySnippetTests extends AbstractSnippetTests {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("response-body"))
.willReturn(snippetResource("response-body-with-language"));
responseBody(
attributes(
key("language").value("json")))
.document(
this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(
resolver))
.response().content("{\"a\":\"alpha\"}")
.build());
responseBody(attributes(key("language").value("json")))
.document(this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.response().content("{\"a\":\"alpha\"}").build());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -108,7 +108,7 @@ public class ResponseFieldsSnippetFailureTests {
.content("<a>foo</a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test
@@ -202,7 +202,7 @@ public class ResponseFieldsSnippetFailureTests {
this.operationBuilder.response()
.content("{\"a\":[{\"b\": 1,\"c\": 2}, "
+ "{\"c\": 2}, {\"b\": 1,\"c\": 2}]}")
.build());
.build());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -121,7 +121,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
Arrays.asList(fieldWithPath("[]a.b").description("one")))
.document(this.operationBuilder.response().content(
"[{\"a\": {\"b\": null}}," + "{\"a\": {\"b\": null}}]")
.build());
.build());
}
@Test
@@ -180,8 +180,8 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.willReturn(snippetResource("response-fields-with-title"));
this.snippets.expectResponseFields().withContents(containsString("Custom title"));
new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")),
attributes(
new ResponseFieldsSnippet(
Arrays.asList(fieldWithPath("a").description("one")), attributes(
key("title").value("Custom title")))
.document(
this.operationBuilder
@@ -241,15 +241,13 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.attributes(key("foo").value("bravo")),
fieldWithPath("a").description("three")
.attributes(key("foo").value("charlie"))))
.document(
this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(
resolver))
.response()
.content(
"{\"a\": {\"b\": 5, \"c\": \"charlie\"}}")
.build());
.document(this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.response()
.content(
"{\"a\": {\"b\": 5, \"c\": \"charlie\"}}")
.build());
}
@Test
@@ -319,7 +317,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.content("<a id=\"1\">foo</a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test
@@ -335,7 +333,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.content("<a>foo</a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
.build());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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(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
@@ -143,13 +142,12 @@ 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(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.document(this.operationBuilder.attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.build());
@@ -168,15 +166,13 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
new PathParametersSnippet(Arrays.asList(
parameterWithName("a").description("one")
.attributes(key("foo").value("alpha")),
parameterWithName("b").description("two")
.attributes(key("foo").value("bravo"))))
.document(this.operationBuilder
.attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.build());
parameterWithName("b").description("two").attributes(key("foo")
.value("bravo")))).document(this.operationBuilder.attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.build());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -122,16 +122,12 @@ public class RequestParametersSnippetTests extends AbstractSnippetTests {
.attributes(key("foo").value("alpha")),
parameterWithName("b").description("two")
.attributes(key("foo").value("bravo"))),
attributes(
key("title").value("The title")))
.document(
this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(
resolver))
.request("http://localhost")
.param("a", "alpha").param("b", "bravo")
.build());
attributes(key("title").value("The title")))
.document(this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.request("http://localhost").param("a", "alpha")
.param("b", "bravo").build());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -113,16 +113,12 @@ public class RequestPartsSnippetTests extends AbstractSnippetTests {
.attributes(key("foo").value("alpha")),
partWithName("b").description("two")
.attributes(key("foo").value("bravo"))),
attributes(
key("title").value("The title")))
.document(
this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(
resolver))
.request("http://localhost")
.part("a", "alpha".getBytes()).and()
.part("b", "bravo".getBytes()).build());
attributes(key("title").value("The title")))
.document(this.operationBuilder
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.request("http://localhost").part("a", "alpha".getBytes())
.and().part("b", "bravo".getBytes()).build());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.