Upgrade to Spring Java Format 0.0.38
Closes gh-890
This commit is contained in:
@@ -80,7 +80,7 @@ subprojects { subproject ->
|
||||
checkstyle {
|
||||
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
|
||||
configProperties = [ "checkstyle.config.dir" : rootProject.file("config/checkstyle") ]
|
||||
toolVersion = "8.22"
|
||||
toolVersion = "10.11.0"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -31,7 +31,7 @@ public final class Hypermedia {
|
||||
// tag::ignore-links[]
|
||||
public static LinksSnippet links(LinkDescriptor... descriptors) {
|
||||
return HypermediaDocumentation.links(linkWithRel("self").ignored().optional(), linkWithRel("curies").ignored())
|
||||
.and(descriptors);
|
||||
.and(descriptors);
|
||||
}
|
||||
// end::ignore-links[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -42,10 +42,10 @@ public class CustomDefaultOperationPreprocessors {
|
||||
public void setup() {
|
||||
// tag::custom-default-operation-preprocessors[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
.apply(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
// end::custom-default-operation-preprocessors[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -43,8 +43,8 @@ public class CustomDefaultSnippets {
|
||||
public void setUp() {
|
||||
// tag::custom-default-snippets[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation).snippets().withDefaults(curlRequest()))
|
||||
.build();
|
||||
.apply(documentationConfiguration(this.restDocumentation).snippets().withDefaults(curlRequest()))
|
||||
.build();
|
||||
// end::custom-default-snippets[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -42,8 +42,8 @@ public class CustomEncoding {
|
||||
public void setUp() {
|
||||
// tag::custom-encoding[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation).snippets().withEncoding("ISO-8859-1"))
|
||||
.build();
|
||||
.apply(documentationConfiguration(this.restDocumentation).snippets().withEncoding("ISO-8859-1"))
|
||||
.build();
|
||||
// end::custom-encoding[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -43,9 +43,9 @@ public class CustomFormat {
|
||||
public void setUp() {
|
||||
// tag::custom-format[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation).snippets()
|
||||
.withTemplateFormat(TemplateFormats.markdown()))
|
||||
.build();
|
||||
.apply(documentationConfiguration(this.restDocumentation).snippets()
|
||||
.withTemplateFormat(TemplateFormats.markdown()))
|
||||
.build();
|
||||
// end::custom-format[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -42,9 +42,11 @@ public class CustomUriConfiguration {
|
||||
public void setUp() {
|
||||
// tag::custom-uri-configuration[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation).uris().withScheme("https")
|
||||
.withHost("example.com").withPort(443))
|
||||
.build();
|
||||
.apply(documentationConfiguration(this.restDocumentation).uris()
|
||||
.withScheme("https")
|
||||
.withHost("example.com")
|
||||
.withPort(443))
|
||||
.build();
|
||||
// end::custom-uri-configuration[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -46,17 +46,18 @@ public class EveryTestPreprocessing {
|
||||
@Before
|
||||
public void setup() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
.apply(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
public void use() throws Exception {
|
||||
// tag::use[]
|
||||
this.mockMvc.perform(get("/")).andExpect(status().isOk())
|
||||
.andDo(document("index", links(linkWithRel("self").description("Canonical self link"))));
|
||||
this.mockMvc.perform(get("/"))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("index", links(linkWithRel("self").description("Canonical self link"))));
|
||||
// end::use[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -37,8 +37,8 @@ class ExampleApplicationJUnit5Tests {
|
||||
@BeforeEach
|
||||
void setUp(WebApplicationContext webApplicationContext, RestDocumentationContextProvider restDocumentation) {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
|
||||
.apply(documentationConfiguration(restDocumentation)) // <1>
|
||||
.build();
|
||||
.apply(documentationConfiguration(restDocumentation)) // <1>
|
||||
.build();
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -43,7 +43,8 @@ public class ExampleApplicationTestNgTests {
|
||||
@BeforeMethod
|
||||
public void setUp(Method method) {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation)).build();
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
this.restDocumentation.beforeTest(getClass(), method.getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -42,8 +42,8 @@ public class ExampleApplicationTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation)) // <1>
|
||||
.build();
|
||||
.apply(documentationConfiguration(this.restDocumentation)) // <1>
|
||||
.build();
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -32,15 +32,16 @@ public class HttpHeaders {
|
||||
public void headers() throws Exception {
|
||||
// tag::headers[]
|
||||
this.mockMvc.perform(get("/people").header("Authorization", "Basic dXNlcjpzZWNyZXQ=")) // <1>
|
||||
.andExpect(status().isOk()).andDo(document("headers", requestHeaders(// <2>
|
||||
headerWithName("Authorization").description("Basic auth credentials")), // <3>
|
||||
responseHeaders(// <4>
|
||||
headerWithName("X-RateLimit-Limit")
|
||||
.description("The total number of requests permitted per period"),
|
||||
headerWithName("X-RateLimit-Remaining")
|
||||
.description("Remaining requests permitted in current period"),
|
||||
headerWithName("X-RateLimit-Reset")
|
||||
.description("Time at which the rate limit period will reset"))));
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("headers", requestHeaders(// <2>
|
||||
headerWithName("Authorization").description("Basic auth credentials")), // <3>
|
||||
responseHeaders(// <4>
|
||||
headerWithName("X-RateLimit-Limit")
|
||||
.description("The total number of requests permitted per period"),
|
||||
headerWithName("X-RateLimit-Remaining")
|
||||
.description("Remaining requests permitted in current period"),
|
||||
headerWithName("X-RateLimit-Reset")
|
||||
.description("Time at which the rate limit period will reset"))));
|
||||
// end::headers[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -32,19 +32,21 @@ public class Hypermedia {
|
||||
|
||||
public void defaultExtractor() throws Exception {
|
||||
// tag::links[]
|
||||
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
.andDo(document("index", links(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"), // <2>
|
||||
linkWithRel("bravo").description("Link to the bravo resource")))); // <3>
|
||||
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("index", links(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"), // <2>
|
||||
linkWithRel("bravo").description("Link to the bravo resource")))); // <3>
|
||||
// end::links[]
|
||||
}
|
||||
|
||||
public void explicitExtractor() throws Exception {
|
||||
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
// tag::explicit-extractor[]
|
||||
.andDo(document("index", links(halLinks(), // <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
linkWithRel("bravo").description("Link to the bravo resource"))));
|
||||
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
// tag::explicit-extractor[]
|
||||
.andDo(document("index", links(halLinks(), // <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
linkWithRel("bravo").description("Link to the bravo resource"))));
|
||||
// end::explicit-extractor[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -30,8 +30,8 @@ public class InvokeService {
|
||||
public void invokeService() throws Exception {
|
||||
// tag::invoke-service[]
|
||||
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)) // <1>
|
||||
.andExpect(status().isOk()) // <2>
|
||||
.andDo(document("index")); // <3>
|
||||
.andExpect(status().isOk()) // <2>
|
||||
.andDo(document("index")); // <3>
|
||||
// end::invoke-service[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -32,10 +32,11 @@ public class MockMvcSnippetReuse extends SnippetReuse {
|
||||
|
||||
public void documentation() throws Exception {
|
||||
// tag::use[]
|
||||
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
.andDo(document("example", this.pagingLinks.and(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
linkWithRel("bravo").description("Link to the bravo resource"))));
|
||||
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("example", this.pagingLinks.and(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
linkWithRel("bravo").description("Link to the bravo resource"))));
|
||||
// end::use[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -41,8 +41,9 @@ public class ParameterizedOutput {
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation)).alwaysDo(document("{method-name}/{step}/"))
|
||||
.build();
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.alwaysDo(document("{method-name}/{step}/"))
|
||||
.build();
|
||||
}
|
||||
// end::parameterized-output[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -31,10 +31,11 @@ public class PathParameters {
|
||||
public void pathParametersSnippet() throws Exception {
|
||||
// tag::path-parameters[]
|
||||
this.mockMvc.perform(get("/locations/{latitude}/{longitude}", 51.5072, 0.1275)) // <1>
|
||||
.andExpect(status().isOk()).andDo(document("locations", pathParameters(// <2>
|
||||
parameterWithName("latitude").description("The location's latitude"), // <3>
|
||||
parameterWithName("longitude").description("The location's longitude") // <4>
|
||||
)));
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("locations", pathParameters(// <2>
|
||||
parameterWithName("latitude").description("The location's latitude"), // <3>
|
||||
parameterWithName("longitude").description("The location's longitude") // <4>
|
||||
)));
|
||||
// end::path-parameters[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -40,37 +40,41 @@ public class Payload {
|
||||
|
||||
public void response() throws Exception {
|
||||
// tag::response[]
|
||||
this.mockMvc.perform(get("/user/5").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
.andDo(document("index", responseFields(// <1>
|
||||
fieldWithPath("contact.email").description("The user's email address"), // <2>
|
||||
fieldWithPath("contact.name").description("The user's name")))); // <3>
|
||||
this.mockMvc.perform(get("/user/5").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("index", responseFields(// <1>
|
||||
fieldWithPath("contact.email").description("The user's email address"), // <2>
|
||||
fieldWithPath("contact.name").description("The user's name")))); // <3>
|
||||
// end::response[]
|
||||
}
|
||||
|
||||
public void subsection() throws Exception {
|
||||
// tag::subsection[]
|
||||
this.mockMvc.perform(get("/user/5").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
.andDo(document("index", responseFields(// <1>
|
||||
subsectionWithPath("contact").description("The user's contact details")))); // <1>
|
||||
this.mockMvc.perform(get("/user/5").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("index", responseFields(// <1>
|
||||
subsectionWithPath("contact").description("The user's contact details")))); // <1>
|
||||
// end::subsection[]
|
||||
}
|
||||
|
||||
public void explicitType() throws Exception {
|
||||
this.mockMvc.perform(get("/user/5").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
// tag::explicit-type[]
|
||||
.andDo(document("index", responseFields(fieldWithPath("contact.email").type(JsonFieldType.STRING) // <1>
|
||||
.description("The user's email address"))));
|
||||
this.mockMvc.perform(get("/user/5").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
// tag::explicit-type[]
|
||||
.andDo(document("index", responseFields(fieldWithPath("contact.email").type(JsonFieldType.STRING) // <1>
|
||||
.description("The user's email address"))));
|
||||
// end::explicit-type[]
|
||||
}
|
||||
|
||||
public void constraints() throws Exception {
|
||||
this.mockMvc.perform(post("/users/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
// tag::constraints[]
|
||||
.andDo(document("create-user", requestFields(attributes(key("title").value("Fields for user creation")), // <1>
|
||||
fieldWithPath("name").description("The user's name")
|
||||
.attributes(key("constraints").value("Must not be null. Must not be empty")), // <2>
|
||||
fieldWithPath("email").description("The user's email address")
|
||||
.attributes(key("constraints").value("Must be a valid email address"))))); // <3>
|
||||
this.mockMvc.perform(post("/users/").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
// tag::constraints[]
|
||||
.andDo(document("create-user", requestFields(attributes(key("title").value("Fields for user creation")), // <1>
|
||||
fieldWithPath("name").description("The user's name")
|
||||
.attributes(key("constraints").value("Must not be null. Must not be empty")), // <2>
|
||||
fieldWithPath("email").description("The user's email address")
|
||||
.attributes(key("constraints").value("Must be a valid email address"))))); // <3>
|
||||
// end::constraints[]
|
||||
}
|
||||
|
||||
@@ -79,30 +83,34 @@ public class Payload {
|
||||
fieldWithPath("author").description("Author of the book") };
|
||||
|
||||
// tag::single-book[]
|
||||
this.mockMvc.perform(get("/books/1").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
.andDo(document("book", responseFields(book))); // <1>
|
||||
this.mockMvc.perform(get("/books/1").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("book", responseFields(book))); // <1>
|
||||
// end::single-book[]
|
||||
|
||||
// tag::book-array[]
|
||||
this.mockMvc.perform(get("/books").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
.andDo(document("book", responseFields(fieldWithPath("[]").description("An array of books")) // <1>
|
||||
.andWithPrefix("[].", book))); // <2>
|
||||
this.mockMvc.perform(get("/books").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("book", responseFields(fieldWithPath("[]").description("An array of books")) // <1>
|
||||
.andWithPrefix("[].", book))); // <2>
|
||||
// end::book-array[]
|
||||
}
|
||||
|
||||
public void fieldsSubsection() throws Exception {
|
||||
// tag::fields-subsection[]
|
||||
this.mockMvc.perform(get("/locations/1").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
.andDo(document("location", responseFields(beneathPath("weather.temperature"), // <1>
|
||||
fieldWithPath("high").description("The forecast high in degrees celcius"), // <2>
|
||||
fieldWithPath("low").description("The forecast low in degrees celcius"))));
|
||||
this.mockMvc.perform(get("/locations/1").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("location", responseFields(beneathPath("weather.temperature"), // <1>
|
||||
fieldWithPath("high").description("The forecast high in degrees celcius"), // <2>
|
||||
fieldWithPath("low").description("The forecast low in degrees celcius"))));
|
||||
// end::fields-subsection[]
|
||||
}
|
||||
|
||||
public void bodySubsection() throws Exception {
|
||||
// tag::body-subsection[]
|
||||
this.mockMvc.perform(get("/locations/1").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
.andDo(document("location", responseBody(beneathPath("weather.temperature")))); // <1>
|
||||
this.mockMvc.perform(get("/locations/1").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("location", responseBody(beneathPath("weather.temperature")))); // <1>
|
||||
|
||||
// end::body-subsection[]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -32,9 +32,10 @@ public class PerTestPreprocessing {
|
||||
|
||||
public void general() throws Exception {
|
||||
// tag::preprocessing[]
|
||||
this.mockMvc.perform(get("/")).andExpect(status().isOk())
|
||||
.andDo(document("index", preprocessRequest(removeHeaders("Foo")), // <1>
|
||||
preprocessResponse(prettyPrint()))); // <2>
|
||||
this.mockMvc.perform(get("/"))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("index", preprocessRequest(removeHeaders("Foo")), // <1>
|
||||
preprocessResponse(prettyPrint()))); // <2>
|
||||
// end::preprocessing[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -32,18 +32,20 @@ public class RequestParameters {
|
||||
public void getQueryStringSnippet() throws Exception {
|
||||
// tag::request-parameters-query-string[]
|
||||
this.mockMvc.perform(get("/users?page=2&per_page=100")) // <1>
|
||||
.andExpect(status().isOk()).andDo(document("users", requestParameters(// <2>
|
||||
parameterWithName("page").description("The page to retrieve"), // <3>
|
||||
parameterWithName("per_page").description("Entries per page") // <4>
|
||||
)));
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("users", requestParameters(// <2>
|
||||
parameterWithName("page").description("The page to retrieve"), // <3>
|
||||
parameterWithName("per_page").description("Entries per page") // <4>
|
||||
)));
|
||||
// end::request-parameters-query-string[]
|
||||
}
|
||||
|
||||
public void postFormDataSnippet() throws Exception {
|
||||
// tag::request-parameters-form-data[]
|
||||
this.mockMvc.perform(post("/users").param("username", "Tester")) // <1>
|
||||
.andExpect(status().isCreated()).andDo(document("create-user",
|
||||
requestParameters(parameterWithName("username").description("The user's username"))));
|
||||
.andExpect(status().isCreated())
|
||||
.andDo(document("create-user",
|
||||
requestParameters(parameterWithName("username").description("The user's username"))));
|
||||
// end::request-parameters-form-data[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -38,8 +38,9 @@ public class RequestPartPayload {
|
||||
"{ \"version\": \"1.0\"}".getBytes());
|
||||
|
||||
this.mockMvc.perform(multipart("/images").file(image).file(metadata).accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk()).andDo(document("image-upload", requestPartFields("metadata", // <1>
|
||||
fieldWithPath("version").description("The version of the image")))); // <2>
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("image-upload", requestPartFields("metadata", // <1>
|
||||
fieldWithPath("version").description("The version of the image")))); // <2>
|
||||
// end::fields[]
|
||||
}
|
||||
|
||||
@@ -50,7 +51,8 @@ public class RequestPartPayload {
|
||||
"{ \"version\": \"1.0\"}".getBytes());
|
||||
|
||||
this.mockMvc.perform(multipart("/images").file(image).file(metadata).accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk()).andDo(document("image-upload", requestPartBody("metadata"))); // <1>
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("image-upload", requestPartBody("metadata"))); // <1>
|
||||
// end::body[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -31,9 +31,10 @@ public class RequestParts {
|
||||
public void upload() throws Exception {
|
||||
// tag::request-parts[]
|
||||
this.mockMvc.perform(multipart("/upload").file("file", "example".getBytes())) // <1>
|
||||
.andExpect(status().isOk()).andDo(document("upload", requestParts(// <2>
|
||||
partWithName("file").description("The file to upload")) // <3>
|
||||
));
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("upload", requestParts(// <2>
|
||||
partWithName("file").description("The file to upload")) // <3>
|
||||
));
|
||||
// end::request-parts[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -39,10 +39,10 @@ public class CustomDefaultOperationPreprocessors {
|
||||
public void setup() {
|
||||
// tag::custom-default-operation-preprocessors[]
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
// end::custom-default-operation-preprocessors[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -38,8 +38,8 @@ public class CustomDefaultSnippets {
|
||||
public void setUp() {
|
||||
// tag::custom-default-snippets[]
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).snippets().withDefaults(curlRequest()))
|
||||
.build();
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).snippets().withDefaults(curlRequest()))
|
||||
.build();
|
||||
// end::custom-default-snippets[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -37,8 +37,8 @@ public class CustomEncoding {
|
||||
public void setUp() {
|
||||
// tag::custom-encoding[]
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).snippets().withEncoding("ISO-8859-1"))
|
||||
.build();
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).snippets().withEncoding("ISO-8859-1"))
|
||||
.build();
|
||||
// end::custom-encoding[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -37,8 +37,10 @@ public class CustomFormat {
|
||||
@Before
|
||||
public void setUp() {
|
||||
// tag::custom-format[]
|
||||
this.spec = new RequestSpecBuilder().addFilter(documentationConfiguration(this.restDocumentation).snippets()
|
||||
.withTemplateFormat(TemplateFormats.markdown())).build();
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).snippets()
|
||||
.withTemplateFormat(TemplateFormats.markdown()))
|
||||
.build();
|
||||
// end::custom-format[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -43,18 +43,22 @@ public class EveryTestPreprocessing {
|
||||
@Before
|
||||
public void setup() {
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
public void use() {
|
||||
// tag::use[]
|
||||
RestAssured.given(this.spec)
|
||||
.filter(document("index", links(linkWithRel("self").description("Canonical self link")))).when()
|
||||
.get("/").then().assertThat().statusCode(is(200));
|
||||
.filter(document("index", links(linkWithRel("self").description("Canonical self link"))))
|
||||
.when()
|
||||
.get("/")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::use[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -36,7 +36,7 @@ class ExampleApplicationJUnit5Tests {
|
||||
@BeforeEach
|
||||
void setUp(RestDocumentationContextProvider restDocumentation) {
|
||||
this.spec = new RequestSpecBuilder().addFilter(documentationConfiguration(restDocumentation)) // <1>
|
||||
.build();
|
||||
.build();
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -37,7 +37,7 @@ public class ExampleApplicationTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.spec = new RequestSpecBuilder().addFilter(documentationConfiguration(this.restDocumentation)) // <1>
|
||||
.build();
|
||||
.build();
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -31,17 +31,22 @@ public class HttpHeaders {
|
||||
|
||||
public void headers() {
|
||||
// tag::headers[]
|
||||
RestAssured.given(this.spec).filter(document("headers", requestHeaders(// <1>
|
||||
headerWithName("Authorization").description("Basic auth credentials")), // <2>
|
||||
responseHeaders(// <3>
|
||||
headerWithName("X-RateLimit-Limit")
|
||||
RestAssured.given(this.spec)
|
||||
.filter(document("headers", requestHeaders(// <1>
|
||||
headerWithName("Authorization").description("Basic auth credentials")), // <2>
|
||||
responseHeaders(// <3>
|
||||
headerWithName("X-RateLimit-Limit")
|
||||
.description("The total number of requests permitted per period"),
|
||||
headerWithName("X-RateLimit-Remaining")
|
||||
headerWithName("X-RateLimit-Remaining")
|
||||
.description("Remaining requests permitted in current period"),
|
||||
headerWithName("X-RateLimit-Reset")
|
||||
headerWithName("X-RateLimit-Reset")
|
||||
.description("Time at which the rate limit period will reset"))))
|
||||
.header("Authorization", "Basic dXNlcjpzZWNyZXQ=") // <4>
|
||||
.when().get("/people").then().assertThat().statusCode(is(200));
|
||||
.header("Authorization", "Basic dXNlcjpzZWNyZXQ=") // <4>
|
||||
.when()
|
||||
.get("/people")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::headers[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -31,21 +31,30 @@ public class Hypermedia {
|
||||
|
||||
public void defaultExtractor() {
|
||||
// tag::links[]
|
||||
RestAssured.given(this.spec).accept("application/json").filter(document("index", links(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"), // <2>
|
||||
linkWithRel("bravo").description("Link to the bravo resource")))) // <3>
|
||||
.get("/").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
.filter(document("index", links(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"), // <2>
|
||||
linkWithRel("bravo").description("Link to the bravo resource")))) // <3>
|
||||
.get("/")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::links[]
|
||||
}
|
||||
|
||||
public void explicitExtractor() {
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
// tag::explicit-extractor[]
|
||||
.filter(document("index", links(halLinks(), // <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
linkWithRel("bravo").description("Link to the bravo resource"))))
|
||||
// end::explicit-extractor[]
|
||||
.get("/").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
// tag::explicit-extractor[]
|
||||
.filter(document("index", links(halLinks(), // <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
linkWithRel("bravo").description("Link to the bravo resource"))))
|
||||
// end::explicit-extractor[]
|
||||
.get("/")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -29,10 +29,13 @@ public class InvokeService {
|
||||
public void invokeService() {
|
||||
// tag::invoke-service[]
|
||||
RestAssured.given(this.spec) // <1>
|
||||
.accept("application/json") // <2>
|
||||
.filter(document("index")) // <3>
|
||||
.when().get("/") // <4>
|
||||
.then().assertThat().statusCode(is(200)); // <5>
|
||||
.accept("application/json") // <2>
|
||||
.filter(document("index")) // <3>
|
||||
.when()
|
||||
.get("/") // <4>
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200)); // <5>
|
||||
// end::invoke-service[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -38,7 +38,8 @@ public class ParameterizedOutput {
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.spec = new RequestSpecBuilder().addFilter(documentationConfiguration(this.restDocumentation))
|
||||
.addFilter(document("{method-name}/{step}")).build();
|
||||
.addFilter(document("{method-name}/{step}"))
|
||||
.build();
|
||||
}
|
||||
// end::parameterized-output[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -30,11 +30,15 @@ public class PathParameters {
|
||||
|
||||
public void pathParametersSnippet() {
|
||||
// tag::path-parameters[]
|
||||
RestAssured.given(this.spec).filter(document("locations", pathParameters(// <1>
|
||||
parameterWithName("latitude").description("The location's latitude"), // <2>
|
||||
parameterWithName("longitude").description("The location's longitude")))) // <3>
|
||||
.when().get("/locations/{latitude}/{longitude}", 51.5072, 0.1275) // <4>
|
||||
.then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.filter(document("locations", pathParameters(// <1>
|
||||
parameterWithName("latitude").description("The location's latitude"), // <2>
|
||||
parameterWithName("longitude").description("The location's longitude")))) // <3>
|
||||
.when()
|
||||
.get("/locations/{latitude}/{longitude}", 51.5072, 0.1275) // <4>
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::path-parameters[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -39,42 +39,62 @@ public class Payload {
|
||||
|
||||
public void response() {
|
||||
// tag::response[]
|
||||
RestAssured.given(this.spec).accept("application/json").filter(document("user", responseFields(// <1>
|
||||
fieldWithPath("contact.name").description("The user's name"), // <2>
|
||||
fieldWithPath("contact.email").description("The user's email address")))) // <3>
|
||||
.when().get("/user/5").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
.filter(document("user", responseFields(// <1>
|
||||
fieldWithPath("contact.name").description("The user's name"), // <2>
|
||||
fieldWithPath("contact.email").description("The user's email address")))) // <3>
|
||||
.when()
|
||||
.get("/user/5")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::response[]
|
||||
}
|
||||
|
||||
public void subsection() {
|
||||
// tag::subsection[]
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
.filter(document("user",
|
||||
responseFields(subsectionWithPath("contact").description("The user's contact details")))) // <1>
|
||||
.when().get("/user/5").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
.filter(document("user",
|
||||
responseFields(subsectionWithPath("contact").description("The user's contact details")))) // <1>
|
||||
.when()
|
||||
.get("/user/5")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::subsection[]
|
||||
}
|
||||
|
||||
public void explicitType() {
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
// tag::explicit-type[]
|
||||
.filter(document("user", responseFields(fieldWithPath("contact.email").type(JsonFieldType.STRING) // <1>
|
||||
.description("The user's email address"))))
|
||||
// end::explicit-type[]
|
||||
.when().get("/user/5").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
// tag::explicit-type[]
|
||||
.filter(document("user", responseFields(fieldWithPath("contact.email").type(JsonFieldType.STRING) // <1>
|
||||
.description("The user's email address"))))
|
||||
// end::explicit-type[]
|
||||
.when()
|
||||
.get("/user/5")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
public void constraints() {
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
// tag::constraints[]
|
||||
.filter(document("create-user",
|
||||
requestFields(attributes(key("title").value("Fields for user creation")), // <1>
|
||||
fieldWithPath("name").description("The user's name")
|
||||
.attributes(key("constraints").value("Must not be null. Must not be empty")), // <2>
|
||||
fieldWithPath("email").description("The user's email address")
|
||||
.attributes(key("constraints").value("Must be a valid email address"))))) // <3>
|
||||
// end::constraints[]
|
||||
.when().post("/users").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
// tag::constraints[]
|
||||
.filter(document("create-user", requestFields(attributes(key("title").value("Fields for user creation")), // <1>
|
||||
fieldWithPath("name").description("The user's name")
|
||||
.attributes(key("constraints").value("Must not be null. Must not be empty")), // <2>
|
||||
fieldWithPath("email").description("The user's email address")
|
||||
.attributes(key("constraints").value("Must be a valid email address"))))) // <3>
|
||||
// end::constraints[]
|
||||
.when()
|
||||
.post("/users")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
public void descriptorReuse() {
|
||||
@@ -82,33 +102,54 @@ public class Payload {
|
||||
fieldWithPath("author").description("Author of the book") };
|
||||
|
||||
// tag::single-book[]
|
||||
RestAssured.given(this.spec).accept("application/json").filter(document("book", responseFields(book))) // <1>
|
||||
.when().get("/books/1").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
.filter(document("book", responseFields(book))) // <1>
|
||||
.when()
|
||||
.get("/books/1")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::single-book[]
|
||||
|
||||
// tag::book-array[]
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
.filter(document("books", responseFields(fieldWithPath("[]").description("An array of books")) // <1>
|
||||
.andWithPrefix("[].", book))) // <2>
|
||||
.when().get("/books").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
.filter(document("books", responseFields(fieldWithPath("[]").description("An array of books")) // <1>
|
||||
.andWithPrefix("[].", book))) // <2>
|
||||
.when()
|
||||
.get("/books")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::book-array[]
|
||||
}
|
||||
|
||||
public void fieldsSubsection() {
|
||||
// tag::fields-subsection[]
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
.filter(document("location", responseFields(beneathPath("weather.temperature"), // <1>
|
||||
fieldWithPath("high").description("The forecast high in degrees celcius"), // <2>
|
||||
fieldWithPath("low").description("The forecast low in degrees celcius"))))
|
||||
.when().get("/locations/1").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
.filter(document("location", responseFields(beneathPath("weather.temperature"), // <1>
|
||||
fieldWithPath("high").description("The forecast high in degrees celcius"), // <2>
|
||||
fieldWithPath("low").description("The forecast low in degrees celcius"))))
|
||||
.when()
|
||||
.get("/locations/1")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::fields-subsection[]
|
||||
}
|
||||
|
||||
public void bodySubsection() {
|
||||
// tag::body-subsection[]
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
.filter(document("location", responseBody(beneathPath("weather.temperature")))) // <1>
|
||||
.when().get("/locations/1").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
.filter(document("location", responseBody(beneathPath("weather.temperature")))) // <1>
|
||||
.when()
|
||||
.get("/locations/1")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::body-subsection[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -32,9 +32,14 @@ public class PerTestPreprocessing {
|
||||
|
||||
public void general() {
|
||||
// tag::preprocessing[]
|
||||
RestAssured.given(this.spec).filter(document("index", preprocessRequest(removeHeaders("Foo")), // <1>
|
||||
preprocessResponse(prettyPrint()))) // <2>
|
||||
.when().get("/").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.filter(document("index", preprocessRequest(removeHeaders("Foo")), // <1>
|
||||
preprocessResponse(prettyPrint()))) // <2>
|
||||
.when()
|
||||
.get("/")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::preprocessing[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -30,22 +30,29 @@ public class RequestParameters {
|
||||
|
||||
public void getQueryStringSnippet() {
|
||||
// tag::request-parameters-query-string[]
|
||||
RestAssured.given(this.spec).filter(document("users", requestParameters(// <1>
|
||||
parameterWithName("page").description("The page to retrieve"), // <2>
|
||||
parameterWithName("per_page").description("Entries per page")))) // <3>
|
||||
.when().get("/users?page=2&per_page=100") // <4>
|
||||
.then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.filter(document("users", requestParameters(// <1>
|
||||
parameterWithName("page").description("The page to retrieve"), // <2>
|
||||
parameterWithName("per_page").description("Entries per page")))) // <3>
|
||||
.when()
|
||||
.get("/users?page=2&per_page=100") // <4>
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::request-parameters-query-string[]
|
||||
}
|
||||
|
||||
public void postFormDataSnippet() {
|
||||
// tag::request-parameters-form-data[]
|
||||
RestAssured.given(this.spec)
|
||||
.filter(document("create-user",
|
||||
requestParameters(parameterWithName("username").description("The user's username"))))
|
||||
.formParam("username", "Tester") // <1>
|
||||
.when().post("/users") // <2>
|
||||
.then().assertThat().statusCode(is(200));
|
||||
.filter(document("create-user",
|
||||
requestParameters(parameterWithName("username").description("The user's username"))))
|
||||
.formParam("username", "Tester") // <1>
|
||||
.when()
|
||||
.post("/users") // <2>
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::request-parameters-form-data[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -37,11 +37,17 @@ public class RequestPartPayload {
|
||||
// tag::fields[]
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("version", "1.0");
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
.filter(document("image-upload", requestPartFields("metadata", // <1>
|
||||
fieldWithPath("version").description("The version of the image")))) // <2>
|
||||
.when().multiPart("image", new File("image.png"), "image/png").multiPart("metadata", metadata)
|
||||
.post("images").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
.filter(document("image-upload", requestPartFields("metadata", // <1>
|
||||
fieldWithPath("version").description("The version of the image")))) // <2>
|
||||
.when()
|
||||
.multiPart("image", new File("image.png"), "image/png")
|
||||
.multiPart("metadata", metadata)
|
||||
.post("images")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::fields[]
|
||||
}
|
||||
|
||||
@@ -49,10 +55,16 @@ public class RequestPartPayload {
|
||||
// tag::body[]
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("version", "1.0");
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
.filter(document("image-upload", requestPartBody("metadata"))) // <1>
|
||||
.when().multiPart("image", new File("image.png"), "image/png").multiPart("metadata", metadata)
|
||||
.post("images").then().assertThat().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
.filter(document("image-upload", requestPartBody("metadata"))) // <1>
|
||||
.when()
|
||||
.multiPart("image", new File("image.png"), "image/png")
|
||||
.multiPart("metadata", metadata)
|
||||
.post("images")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::body[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -30,11 +30,14 @@ public class RequestParts {
|
||||
|
||||
public void upload() {
|
||||
// tag::request-parts[]
|
||||
RestAssured.given(this.spec).filter(document("users", requestParts(// <1>
|
||||
partWithName("file").description("The file to upload")))) // <2>
|
||||
.multiPart("file", "example") // <3>
|
||||
.when().post("/upload") // <4>
|
||||
.then().statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.filter(document("users", requestParts(// <1>
|
||||
partWithName("file").description("The file to upload")))) // <2>
|
||||
.multiPart("file", "example") // <3>
|
||||
.when()
|
||||
.post("/upload") // <4>
|
||||
.then()
|
||||
.statusCode(is(200));
|
||||
// end::request-parts[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -30,10 +30,15 @@ public class RestAssuredSnippetReuse extends SnippetReuse {
|
||||
|
||||
public void documentation() {
|
||||
// tag::use[]
|
||||
RestAssured.given(this.spec).accept("application/json").filter(document("example", this.pagingLinks.and(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
linkWithRel("bravo").description("Link to the bravo resource")))).get("/").then().assertThat()
|
||||
.statusCode(is(200));
|
||||
RestAssured.given(this.spec)
|
||||
.accept("application/json")
|
||||
.filter(document("example", this.pagingLinks.and(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
linkWithRel("bravo").description("Link to the bravo resource"))))
|
||||
.get("/")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(is(200));
|
||||
// end::use[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -40,9 +40,11 @@ public class CustomUriConfiguration {
|
||||
// tag::custom-uri-configuration[]
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(this.context).configureClient()
|
||||
.baseUrl("https://api.example.com") // <1>
|
||||
.filter(documentationConfiguration(this.restDocumentation)).build();
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(this.context)
|
||||
.configureClient()
|
||||
.baseUrl("https://api.example.com") // <1>
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
}
|
||||
// end::custom-uri-configuration[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -35,9 +35,10 @@ class ExampleApplicationJUnit5Tests {
|
||||
|
||||
@BeforeEach
|
||||
void setUp(ApplicationContext applicationContext, RestDocumentationContextProvider restDocumentation) {
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(applicationContext).configureClient()
|
||||
.filter(documentationConfiguration(restDocumentation)) // <1>
|
||||
.build();
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(applicationContext)
|
||||
.configureClient()
|
||||
.filter(documentationConfiguration(restDocumentation)) // <1>
|
||||
.build();
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -41,9 +41,10 @@ public class ExampleApplicationTestNgTests {
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp(Method method) {
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(this.context).configureClient()
|
||||
.filter(documentationConfiguration(this.restDocumentation)) // <1>
|
||||
.build();
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(this.context)
|
||||
.configureClient()
|
||||
.filter(documentationConfiguration(this.restDocumentation)) // <1>
|
||||
.build();
|
||||
this.restDocumentation.beforeTest(getClass(), method.getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -40,9 +40,10 @@ public class ExampleApplicationTests {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(this.context).configureClient()
|
||||
.filter(documentationConfiguration(this.restDocumentation)) // <1>
|
||||
.build();
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(this.context)
|
||||
.configureClient()
|
||||
.filter(documentationConfiguration(this.restDocumentation)) // <1>
|
||||
.build();
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -30,20 +30,31 @@ public class Hypermedia {
|
||||
|
||||
public void defaultExtractor() {
|
||||
// tag::links[]
|
||||
this.webTestClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk()
|
||||
.expectBody().consumeWith(document("index", links(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"), // <2>
|
||||
linkWithRel("bravo").description("Link to the bravo resource")))); // <3>
|
||||
this.webTestClient.get()
|
||||
.uri("/")
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody()
|
||||
.consumeWith(document("index", links(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"), // <2>
|
||||
linkWithRel("bravo").description("Link to the bravo resource")))); // <3>
|
||||
// end::links[]
|
||||
}
|
||||
|
||||
public void explicitExtractor() {
|
||||
this.webTestClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk()
|
||||
.expectBody()
|
||||
// tag::explicit-extractor[]
|
||||
.consumeWith(document("index", links(halLinks(), // <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
linkWithRel("bravo").description("Link to the bravo resource"))));
|
||||
this.webTestClient.get()
|
||||
.uri("/")
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody()
|
||||
// tag::explicit-extractor[]
|
||||
.consumeWith(document("index", links(halLinks(), // <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
linkWithRel("bravo").description("Link to the bravo resource"))));
|
||||
// end::explicit-extractor[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -27,9 +27,14 @@ public class InvokeService {
|
||||
|
||||
public void invokeService() {
|
||||
// tag::invoke-service[]
|
||||
this.webTestClient.get().uri("/").accept(MediaType.APPLICATION_JSON) // <1>
|
||||
.exchange().expectStatus().isOk() // <2>
|
||||
.expectBody().consumeWith(document("index")); // <3>
|
||||
this.webTestClient.get()
|
||||
.uri("/")
|
||||
.accept(MediaType.APPLICATION_JSON) // <1>
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk() // <2>
|
||||
.expectBody()
|
||||
.consumeWith(document("index")); // <3>
|
||||
// end::invoke-service[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -41,9 +41,11 @@ public class ParameterizedOutput {
|
||||
// tag::parameterized-output[]
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(this.context).configureClient()
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.entityExchangeResultConsumer(document("{method-name}/{step}")).build();
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(this.context)
|
||||
.configureClient()
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.entityExchangeResultConsumer(document("{method-name}/{step}"))
|
||||
.build();
|
||||
}
|
||||
// end::parameterized-output[]
|
||||
|
||||
|
||||
@@ -13,5 +13,5 @@ asciidoctorj23Version=2.3.0
|
||||
asciidoctorj24Version=2.4.3
|
||||
asciidoctorj25Version=2.5.1
|
||||
|
||||
javaFormatVersion=0.0.34
|
||||
javaFormatVersion=0.0.38
|
||||
jmustacheVersion=1.12
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -33,9 +33,9 @@ public final class RestDocsAsciidoctorJ15ExtensionRegistry implements ExtensionR
|
||||
}
|
||||
asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesAsciidoctorJ15Preprocessor());
|
||||
asciidoctor.rubyExtensionRegistry()
|
||||
.loadClass(RestDocsAsciidoctorJ15ExtensionRegistry.class
|
||||
.getResourceAsStream("/extensions/operation_block_macro.rb"))
|
||||
.blockMacro("operation", "OperationBlockMacro");
|
||||
.loadClass(RestDocsAsciidoctorJ15ExtensionRegistry.class
|
||||
.getResourceAsStream("/extensions/operation_block_macro.rb"))
|
||||
.blockMacro("operation", "OperationBlockMacro");
|
||||
}
|
||||
|
||||
private boolean asciidoctorJ15() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -33,9 +33,9 @@ public final class RestDocsAsciidoctorJ16ExtensionRegistry implements ExtensionR
|
||||
}
|
||||
asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesAsciidoctorJ16Preprocessor());
|
||||
asciidoctor.rubyExtensionRegistry()
|
||||
.loadClass(RestDocsAsciidoctorJ16ExtensionRegistry.class
|
||||
.getResourceAsStream("/extensions/operation_block_macro.rb"))
|
||||
.blockMacro("operation", "OperationBlockMacro");
|
||||
.loadClass(RestDocsAsciidoctorJ16ExtensionRegistry.class
|
||||
.getResourceAsStream("/extensions/operation_block_macro.rb"))
|
||||
.blockMacro("operation", "OperationBlockMacro");
|
||||
}
|
||||
|
||||
private boolean asciidoctorJ16() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -30,9 +30,9 @@ public final class RestDocsAsciidoctorJ2xExtensionRegistry implements ExtensionR
|
||||
public void register(Asciidoctor asciidoctor) {
|
||||
asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesAsciidoctorJ2xPreprocessor());
|
||||
asciidoctor.rubyExtensionRegistry()
|
||||
.loadClass(RestDocsAsciidoctorJ2xExtensionRegistry.class
|
||||
.getResourceAsStream("/extensions/operation_block_macro.rb"))
|
||||
.blockMacro("operation", "OperationBlockMacro");
|
||||
.loadClass(RestDocsAsciidoctorJ2xExtensionRegistry.class
|
||||
.getResourceAsStream("/extensions/operation_block_macro.rb"))
|
||||
.blockMacro("operation", "OperationBlockMacro");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -54,14 +54,14 @@ public class SnippetsDirectoryResolverTests {
|
||||
String docdir = new File(this.temporaryFolder.getRoot(), "src/main/asciidoc").getAbsolutePath();
|
||||
attributes.put("docdir", docdir);
|
||||
assertThatIllegalStateException().isThrownBy(() -> getMavenSnippetsDirectory(attributes))
|
||||
.withMessage("pom.xml not found in '" + docdir + "' or above");
|
||||
.withMessage("pom.xml not found in '" + docdir + "' or above");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void illegalStateWhenDocdirAttributeIsNotSetInMavenProject() {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
assertThatIllegalStateException().isThrownBy(() -> getMavenSnippetsDirectory(attributes))
|
||||
.withMessage("docdir attribute not found");
|
||||
.withMessage("docdir attribute not found");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,8 +93,8 @@ public class SnippetsDirectoryResolverTests {
|
||||
public void illegalStateWhenGradleProjectdirAndProjectdirAttributesAreNotSetInGradleProject() {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> new SnippetsDirectoryResolver().getSnippetsDirectory(attributes))
|
||||
.withMessage("projectdir attribute not found");
|
||||
.isThrownBy(() -> new SnippetsDirectoryResolver().getSnippetsDirectory(attributes))
|
||||
.withMessage("projectdir attribute not found");
|
||||
}
|
||||
|
||||
private File getMavenSnippetsDirectory(Map<String, Object> attributes) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -126,16 +126,16 @@ public abstract class AbstractOperationBlockMacroTests {
|
||||
@Test
|
||||
public void includeSnippetInSectionWithAbsoluteLevelOffset() throws Exception {
|
||||
String result = this.asciidoctor
|
||||
.convert("= A\n:doctype: book\n:sectnums:\n:leveloffset: 1\n\nAlpha\n\n= B\n\nBravo\n\n"
|
||||
+ "operation::some-operation[snippets='curl-request']\n\n= C\n", this.options);
|
||||
.convert("= A\n:doctype: book\n:sectnums:\n:leveloffset: 1\n\nAlpha\n\n= B\n\nBravo\n\n"
|
||||
+ "operation::some-operation[snippets='curl-request']\n\n= C\n", this.options);
|
||||
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-in-section"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includeSnippetInSectionWithRelativeLevelOffset() throws Exception {
|
||||
String result = this.asciidoctor
|
||||
.convert("= A\n:doctype: book\n:sectnums:\n:leveloffset: +1\n\nAlpha\n\n= B\n\nBravo\n\n"
|
||||
+ "operation::some-operation[snippets='curl-request']\n\n= C\n", this.options);
|
||||
.convert("= A\n:doctype: book\n:sectnums:\n:leveloffset: +1\n\nAlpha\n\n= B\n\nBravo\n\n"
|
||||
+ "operation::some-operation[snippets='curl-request']\n\n= C\n", this.options);
|
||||
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-in-section"));
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public abstract class AbstractOperationBlockMacroTests {
|
||||
assertThat(result).startsWith(getExpectedContentFromFile("missing-snippet"));
|
||||
assertThat(CapturingLogHandler.getLogRecords()).hasSize(1);
|
||||
assertThat(CapturingLogHandler.getLogRecords().get(0).getMessage())
|
||||
.contains("Snippet missing-snippet not found");
|
||||
.contains("Snippet missing-snippet not found");
|
||||
assertThat(CapturingLogHandler.getLogRecords().get(0).getCursor().getLineNumber()).isEqualTo(1);
|
||||
CapturingLogHandler.getLogRecords().clear();
|
||||
}
|
||||
@@ -189,7 +189,7 @@ public abstract class AbstractOperationBlockMacroTests {
|
||||
assertThat(result).startsWith(getExpectedContentFromFile("missing-operation"));
|
||||
assertThat(CapturingLogHandler.getLogRecords()).hasSize(1);
|
||||
assertThat(CapturingLogHandler.getLogRecords().get(0).getMessage())
|
||||
.contains("No snippets were found for operation missing-operation");
|
||||
.contains("No snippets were found for operation missing-operation");
|
||||
assertThat(CapturingLogHandler.getLogRecords().get(0).getCursor().getLineNumber()).isEqualTo(1);
|
||||
CapturingLogHandler.getLogRecords().clear();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -81,8 +81,9 @@ public class RestDocumentationExtension implements BeforeEachCallback, AfterEach
|
||||
|
||||
private ManualRestDocumentation getDelegate(ExtensionContext context) {
|
||||
Namespace namespace = Namespace.create(getClass(), context.getUniqueId());
|
||||
return context.getStore(namespace).getOrComputeIfAbsent(ManualRestDocumentation.class,
|
||||
this::createManualRestDocumentation, ManualRestDocumentation.class);
|
||||
return context.getStore(namespace)
|
||||
.getOrComputeIfAbsent(ManualRestDocumentation.class, this::createManualRestDocumentation,
|
||||
ManualRestDocumentation.class);
|
||||
}
|
||||
|
||||
private ManualRestDocumentation createManualRestDocumentation(Class<ManualRestDocumentation> key) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -94,7 +94,7 @@ public class CurlRequestSnippet extends TemplatedSnippet {
|
||||
HttpMethod method = request.getMethod();
|
||||
return (method != HttpMethod.PUT && method != HttpMethod.POST && method != HttpMethod.PATCH)
|
||||
|| (request.getContent().length > 0 && !MediaType.APPLICATION_FORM_URLENCODED
|
||||
.isCompatibleWith(request.getHeaders().getContentType()));
|
||||
.isCompatibleWith(request.getHeaders().getContentType()));
|
||||
}
|
||||
|
||||
private String getOptions(Operation operation) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -135,7 +135,7 @@ public class HttpieRequestSnippet extends TemplatedSnippet {
|
||||
HttpMethod method = request.getMethod();
|
||||
return (method != HttpMethod.PUT && method != HttpMethod.POST && method != HttpMethod.PATCH)
|
||||
|| (request.getContent().length > 0 && !MediaType.APPLICATION_FORM_URLENCODED
|
||||
.isCompatibleWith(request.getHeaders().getContentType()));
|
||||
.isCompatibleWith(request.getHeaders().getContentType()));
|
||||
}
|
||||
|
||||
private boolean includeParametersAsFormOptions(OperationRequest request) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2020 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -110,7 +110,7 @@ public abstract class RestDocumentationConfigurer<S extends AbstractConfigurer,
|
||||
TemplateEngine engineToUse = this.templateEngine;
|
||||
if (engineToUse == null) {
|
||||
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
Map<String, Object> templateContext = new HashMap<>();
|
||||
if (snippetConfiguration.getTemplateFormat().getId().equals(TemplateFormats.asciidoctor().getId())) {
|
||||
templateContext.put("tableCellContent", new AsciidoctorTableCellContentLambda());
|
||||
@@ -138,7 +138,7 @@ public abstract class RestDocumentationConfigurer<S extends AbstractConfigurer,
|
||||
WriterResolver resolverToUse = this.writerResolver;
|
||||
if (resolverToUse == null) {
|
||||
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
resolverToUse = new StandardWriterResolver(new RestDocumentationContextPlaceholderResolverFactory(),
|
||||
snippetConfiguration.getEncoding(), snippetConfiguration.getTemplateFormat());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -97,7 +97,7 @@ public class HttpRequestSnippet extends TemplatedSnippet {
|
||||
HttpMethod method = request.getMethod();
|
||||
return (method != HttpMethod.PUT && method != HttpMethod.POST && method != HttpMethod.PATCH)
|
||||
|| (request.getContent().length > 0 && !MediaType.APPLICATION_FORM_URLENCODED
|
||||
.isCompatibleWith(request.getHeaders().getContentType()));
|
||||
.isCompatibleWith(request.getHeaders().getContentType()));
|
||||
}
|
||||
|
||||
private List<Map<String, String>> getHeaders(OperationRequest request) {
|
||||
@@ -153,8 +153,10 @@ public class HttpRequestSnippet extends TemplatedSnippet {
|
||||
|
||||
private void writeParts(OperationRequest request, PrintWriter writer) {
|
||||
writer.println();
|
||||
Set<String> partNames = request.getParts().stream().map(OperationRequestPart::getName)
|
||||
.collect(Collectors.toSet());
|
||||
Set<String> partNames = request.getParts()
|
||||
.stream()
|
||||
.map(OperationRequestPart::getName)
|
||||
.collect(Collectors.toSet());
|
||||
for (Entry<String, List<String>> parameter : request.getParameters().entrySet()) {
|
||||
if (!partNames.contains(parameter.getKey())) {
|
||||
if (parameter.getValue().isEmpty()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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,8 +118,10 @@ public class Link {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("rel", this.rel).append("href", this.href).append("title", this.title)
|
||||
.toString();
|
||||
return new ToStringCreator(this).append("rel", this.rel)
|
||||
.append("href", this.href)
|
||||
.append("title", this.title)
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2020 the original author or authors.
|
||||
* Copyright 2014-2023 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,8 @@ public class OperationRequestFactory {
|
||||
|
||||
private HttpHeaders augmentHeaders(HttpHeaders originalHeaders, URI uri, byte[] content) {
|
||||
return new HttpHeadersHelper(originalHeaders).addIfAbsent(HttpHeaders.HOST, createHostHeader(uri))
|
||||
.setContentLengthHeader(content).getHeaders();
|
||||
.setContentLengthHeader(content)
|
||||
.getHeaders();
|
||||
}
|
||||
|
||||
private String createHostHeader(URI uri) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -53,7 +53,7 @@ import org.springframework.http.MediaType;
|
||||
public class PrettyPrintingContentModifier implements ContentModifier {
|
||||
|
||||
private static final List<PrettyPrinter> PRETTY_PRINTERS = Collections
|
||||
.unmodifiableList(Arrays.asList(new JsonPrettyPrinter(), new XmlPrettyPrinter()));
|
||||
.unmodifiableList(Arrays.asList(new JsonPrettyPrinter(), new XmlPrettyPrinter()));
|
||||
|
||||
@Override
|
||||
public byte[] modifyContent(byte[] originalContent, MediaType contentType) {
|
||||
@@ -142,7 +142,7 @@ public class PrettyPrintingContentModifier implements ContentModifier {
|
||||
private static final class JsonPrettyPrinter implements PrettyPrinter {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true)
|
||||
.configure(DeserializationFeature.FAIL_ON_TRAILING_TOKENS, true);
|
||||
.configure(DeserializationFeature.FAIL_ON_TRAILING_TOKENS, true);
|
||||
|
||||
@Override
|
||||
public byte[] prettyPrint(byte[] original) throws IOException {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -169,7 +169,7 @@ public class UriModifyingOperationPreprocessor implements OperationPreprocessor
|
||||
private static final class UriModifyingContentModifier implements ContentModifier {
|
||||
|
||||
private static final Pattern SCHEME_HOST_PORT_PATTERN = Pattern
|
||||
.compile("(http[s]?)://([a-zA-Z0-9-\\.]+)(:[0-9]+)?");
|
||||
.compile("(http[s]?)://([a-zA-Z0-9-\\.]+)(:[0-9]+)?");
|
||||
|
||||
private String scheme;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -44,7 +44,7 @@ public class FieldPathPayloadSubsectionExtractor
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private static final ObjectMapper prettyPrintingOjectMapper = new ObjectMapper()
|
||||
.enable(SerializationFeature.INDENT_OUTPUT);
|
||||
.enable(SerializationFeature.INDENT_OUTPUT);
|
||||
|
||||
private final String fieldPath;
|
||||
|
||||
@@ -87,23 +87,26 @@ public class FieldPathPayloadSubsectionExtractor
|
||||
throw new PayloadHandlingException(this.fieldPath + " does not identify a section of the payload");
|
||||
}
|
||||
Map<JsonFieldPath, FieldDescriptor> descriptorsByPath = descriptors.stream()
|
||||
.collect(Collectors.toMap(
|
||||
(descriptor) -> JsonFieldPath.compile(this.fieldPath + "." + descriptor.getPath()),
|
||||
this::prependFieldPath));
|
||||
.collect(Collectors.toMap(
|
||||
(descriptor) -> JsonFieldPath.compile(this.fieldPath + "." + descriptor.getPath()),
|
||||
this::prependFieldPath));
|
||||
if (value instanceof List) {
|
||||
List<?> extractedList = (List<?>) value;
|
||||
if (extractedList.isEmpty()) {
|
||||
throw new PayloadHandlingException(this.fieldPath + " identifies an empty section of the payload");
|
||||
}
|
||||
JsonContentHandler contentHandler = new JsonContentHandler(payload, descriptorsByPath.values());
|
||||
Set<JsonFieldPath> uncommonPaths = JsonFieldPaths.from(extractedList).getUncommon().stream()
|
||||
.map((path) -> JsonFieldPath
|
||||
.compile((path.equals("")) ? this.fieldPath : this.fieldPath + "." + path))
|
||||
.filter((path) -> {
|
||||
FieldDescriptor descriptorForPath = descriptorsByPath.getOrDefault(path,
|
||||
new FieldDescriptor(path.toString()));
|
||||
return contentHandler.isMissing(descriptorForPath);
|
||||
}).collect(Collectors.toSet());
|
||||
Set<JsonFieldPath> uncommonPaths = JsonFieldPaths.from(extractedList)
|
||||
.getUncommon()
|
||||
.stream()
|
||||
.map((path) -> JsonFieldPath
|
||||
.compile((path.equals("")) ? this.fieldPath : this.fieldPath + "." + path))
|
||||
.filter((path) -> {
|
||||
FieldDescriptor descriptorForPath = descriptorsByPath.getOrDefault(path,
|
||||
new FieldDescriptor(path.toString()));
|
||||
return contentHandler.isMissing(descriptorForPath);
|
||||
})
|
||||
.collect(Collectors.toSet());
|
||||
if (uncommonPaths.isEmpty()) {
|
||||
value = extractedList.get(0);
|
||||
}
|
||||
@@ -111,8 +114,9 @@ public class FieldPathPayloadSubsectionExtractor
|
||||
String message = this.fieldPath + " identifies multiple sections of "
|
||||
+ "the payload and they do not have a common structure. The "
|
||||
+ "following non-optional uncommon paths were found: ";
|
||||
message += uncommonPaths.stream().map(JsonFieldPath::toString)
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
message += uncommonPaths.stream()
|
||||
.map(JsonFieldPath::toString)
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
throw new PayloadHandlingException(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -149,7 +149,7 @@ class JsonContentHandler implements ContentHandler {
|
||||
public Object resolveFieldType(FieldDescriptor fieldDescriptor) {
|
||||
if (fieldDescriptor.getType() == null) {
|
||||
return this.fieldTypesDiscoverer.discoverFieldTypes(fieldDescriptor.getPath(), readContent())
|
||||
.coalesce(fieldDescriptor.isOptional());
|
||||
.coalesce(fieldDescriptor.isOptional());
|
||||
}
|
||||
if (!(fieldDescriptor.getType() instanceof JsonFieldType)) {
|
||||
return fieldDescriptor.getType();
|
||||
@@ -157,8 +157,8 @@ class JsonContentHandler implements ContentHandler {
|
||||
JsonFieldType descriptorFieldType = (JsonFieldType) fieldDescriptor.getType();
|
||||
try {
|
||||
JsonFieldType actualFieldType = this.fieldTypesDiscoverer
|
||||
.discoverFieldTypes(fieldDescriptor.getPath(), readContent())
|
||||
.coalesce(fieldDescriptor.isOptional());
|
||||
.discoverFieldTypes(fieldDescriptor.getPath(), readContent())
|
||||
.coalesce(fieldDescriptor.isOptional());
|
||||
if (descriptorFieldType == JsonFieldType.VARIES || descriptorFieldType == actualFieldType
|
||||
|| (fieldDescriptor.isOptional() && actualFieldType == JsonFieldType.NULL)
|
||||
|| (isNestedBeneathMissingOptionalField(fieldDescriptor, readContent())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -31,7 +31,7 @@ import java.util.regex.Pattern;
|
||||
final class JsonFieldPath {
|
||||
|
||||
private static final Pattern BRACKETS_AND_ARRAY_PATTERN = Pattern
|
||||
.compile("\\[\'(.+?)\'\\]|\\[([0-9]+|\\*){0,1}\\]");
|
||||
.compile("\\[\'(.+?)\'\\]|\\[([0-9]+|\\*){0,1}\\]");
|
||||
|
||||
private static final Pattern ARRAY_INDEX_PATTERN = Pattern.compile("\\[([0-9]+|\\*){0,1}\\]");
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -163,7 +163,7 @@ final class JsonFieldProcessor {
|
||||
@Override
|
||||
public void foundMatch(Match match) {
|
||||
this.matchType = this.matchType
|
||||
.combinedWith((match.getValue() != null) ? MatchType.NON_NULL : MatchType.NULL);
|
||||
.combinedWith((match.getValue() != null) ? MatchType.NON_NULL : MatchType.NULL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -1507,8 +1507,9 @@ public abstract class PayloadDocumentation {
|
||||
String prefixedPath = pathPrefix + descriptor.getPath();
|
||||
FieldDescriptor prefixedDescriptor = (descriptor instanceof SubsectionDescriptor)
|
||||
? new SubsectionDescriptor(prefixedPath) : new FieldDescriptor(prefixedPath);
|
||||
prefixedDescriptor.description(descriptor.getDescription()).type(descriptor.getType())
|
||||
.attributes(asArray(descriptor.getAttributes()));
|
||||
prefixedDescriptor.description(descriptor.getDescription())
|
||||
.type(descriptor.getType())
|
||||
.attributes(asArray(descriptor.getAttributes()));
|
||||
if (descriptor.isIgnored()) {
|
||||
prefixedDescriptor.ignored();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -189,7 +189,7 @@ public class RequestFieldsSnippet extends AbstractFieldsSnippet {
|
||||
List<FieldDescriptor> combinedDescriptors = new ArrayList<>();
|
||||
combinedDescriptors.addAll(getFieldDescriptors());
|
||||
combinedDescriptors
|
||||
.addAll(PayloadDocumentation.applyPathPrefix(pathPrefix, Arrays.asList(additionalDescriptors)));
|
||||
.addAll(PayloadDocumentation.applyPathPrefix(pathPrefix, Arrays.asList(additionalDescriptors)));
|
||||
return new RequestFieldsSnippet(getSubsectionExtractor(), combinedDescriptors, getAttributes(),
|
||||
isIgnoredUndocumentedFields());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -216,7 +216,7 @@ public class RequestPartFieldsSnippet extends AbstractFieldsSnippet {
|
||||
List<FieldDescriptor> combinedDescriptors = new ArrayList<>();
|
||||
combinedDescriptors.addAll(getFieldDescriptors());
|
||||
combinedDescriptors
|
||||
.addAll(PayloadDocumentation.applyPathPrefix(pathPrefix, Arrays.asList(additionalDescriptors)));
|
||||
.addAll(PayloadDocumentation.applyPathPrefix(pathPrefix, Arrays.asList(additionalDescriptors)));
|
||||
return new RequestPartFieldsSnippet(this.partName, combinedDescriptors, this.getAttributes());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -193,7 +193,7 @@ public class ResponseFieldsSnippet extends AbstractFieldsSnippet {
|
||||
List<FieldDescriptor> combinedDescriptors = new ArrayList<>();
|
||||
combinedDescriptors.addAll(getFieldDescriptors());
|
||||
combinedDescriptors
|
||||
.addAll(PayloadDocumentation.applyPathPrefix(pathPrefix, Arrays.asList(additionalDescriptors)));
|
||||
.addAll(PayloadDocumentation.applyPathPrefix(pathPrefix, Arrays.asList(additionalDescriptors)));
|
||||
return new ResponseFieldsSnippet(getSubsectionExtractor(), combinedDescriptors, this.getAttributes(),
|
||||
isIgnoredUndocumentedFields());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2020 the original author or authors.
|
||||
* Copyright 2014-2023 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,7 +122,7 @@ public class PathParametersSnippet extends AbstractParametersSnippet {
|
||||
|
||||
private String extractUrlTemplate(Operation operation) {
|
||||
String urlTemplate = (String) operation.getAttributes()
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE);
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE);
|
||||
Assert.notNull(urlTemplate, "urlTemplate not found. If you are using MockMvc did "
|
||||
+ "you use RestDocumentationRequestBuilders to build the request?");
|
||||
return urlTemplate;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -72,13 +72,13 @@ public abstract class TemplatedSnippet implements Snippet {
|
||||
@Override
|
||||
public void document(Operation operation) throws IOException {
|
||||
RestDocumentationContext context = (RestDocumentationContext) operation.getAttributes()
|
||||
.get(RestDocumentationContext.class.getName());
|
||||
.get(RestDocumentationContext.class.getName());
|
||||
WriterResolver writerResolver = (WriterResolver) operation.getAttributes().get(WriterResolver.class.getName());
|
||||
try (Writer writer = writerResolver.resolve(operation.getName(), this.snippetName, context)) {
|
||||
Map<String, Object> model = createModel(operation);
|
||||
model.putAll(this.attributes);
|
||||
TemplateEngine templateEngine = (TemplateEngine) operation.getAttributes()
|
||||
.get(TemplateEngine.class.getName());
|
||||
.get(TemplateEngine.class.getName());
|
||||
writer.append(templateEngine.compileTemplate(this.templateName).render(model));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -67,7 +67,7 @@ public class RestDocumentationGeneratorTests {
|
||||
private final Object response = new Object();
|
||||
|
||||
private final OperationRequest operationRequest = new OperationRequestFactory()
|
||||
.create(URI.create("http://localhost:8080"), null, null, new HttpHeaders(), null, null);
|
||||
.create(URI.create("http://localhost:8080"), null, null, new HttpHeaders(), null, null);
|
||||
|
||||
private final OperationResponse operationResponse = new OperationResponseFactory().create(0, null, null);
|
||||
|
||||
@@ -83,7 +83,7 @@ public class RestDocumentationGeneratorTests {
|
||||
given(this.responseConverter.convert(this.response)).willReturn(this.operationResponse);
|
||||
HashMap<String, Object> configuration = new HashMap<>();
|
||||
new RestDocumentationGenerator<>("id", this.requestConverter, this.responseConverter, this.snippet)
|
||||
.handle(this.request, this.response, configuration);
|
||||
.handle(this.request, this.response, configuration);
|
||||
verifySnippetInvocation(this.snippet, configuration);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class RestDocumentationGeneratorTests {
|
||||
configuration.put(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS,
|
||||
Arrays.asList(defaultSnippet1, defaultSnippet2));
|
||||
new RestDocumentationGenerator<>("id", this.requestConverter, this.responseConverter, this.snippet)
|
||||
.handle(this.request, this.response, configuration);
|
||||
.handle(this.request, this.response, configuration);
|
||||
InOrder inOrder = Mockito.inOrder(defaultSnippet1, defaultSnippet2, this.snippet);
|
||||
verifySnippetInvocation(inOrder, defaultSnippet1, configuration);
|
||||
verifySnippetInvocation(inOrder, defaultSnippet2, configuration);
|
||||
@@ -120,8 +120,8 @@ public class RestDocumentationGeneratorTests {
|
||||
given(defaultPreprocessor1.preprocess(first)).willReturn(second);
|
||||
given(defaultPreprocessor2.preprocess(second)).willReturn(third);
|
||||
new RestDocumentationGenerator<>("id", this.requestConverter, this.responseConverter,
|
||||
Preprocessors.preprocessRequest(this.requestPreprocessor), this.snippet).handle(this.request,
|
||||
this.response, configuration);
|
||||
Preprocessors.preprocessRequest(this.requestPreprocessor), this.snippet)
|
||||
.handle(this.request, this.response, configuration);
|
||||
verifySnippetInvocation(this.snippet, third, this.operationResponse, configuration, 1);
|
||||
}
|
||||
|
||||
@@ -141,8 +141,8 @@ public class RestDocumentationGeneratorTests {
|
||||
given(defaultPreprocessor1.preprocess(first)).willReturn(second);
|
||||
given(defaultPreprocessor2.preprocess(second)).willReturn(third);
|
||||
new RestDocumentationGenerator<>("id", this.requestConverter, this.responseConverter,
|
||||
Preprocessors.preprocessResponse(this.responsePreprocessor), this.snippet).handle(this.request,
|
||||
this.response, configuration);
|
||||
Preprocessors.preprocessResponse(this.responsePreprocessor), this.snippet)
|
||||
.handle(this.request, this.response, configuration);
|
||||
verifySnippetInvocation(this.snippet, this.operationRequest, third, configuration, 1);
|
||||
}
|
||||
|
||||
@@ -159,8 +159,8 @@ public class RestDocumentationGeneratorTests {
|
||||
RestDocumentationGenerator<Object, Object> generator = new RestDocumentationGenerator<>("id",
|
||||
this.requestConverter, this.responseConverter, requestPreprocessor, responsePreprocessor, this.snippet);
|
||||
HashMap<String, Object> configuration = new HashMap<>();
|
||||
generator.withSnippets(additionalSnippet1, additionalSnippet2).handle(this.request, this.response,
|
||||
configuration);
|
||||
generator.withSnippets(additionalSnippet1, additionalSnippet2)
|
||||
.handle(this.request, this.response, configuration);
|
||||
verifyNoMoreInteractions(this.snippet);
|
||||
verifySnippetInvocation(additionalSnippet1, configuration);
|
||||
verifySnippetInvocation(additionalSnippet2, configuration);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -51,7 +51,7 @@ public class ConcatenatingCommandFormatterTests {
|
||||
@Test
|
||||
public void formattingMultipleElements() {
|
||||
assertThat(this.singleLineFormat.format(Arrays.asList("alpha", "bravo")))
|
||||
.isEqualTo(String.format(" alpha bravo"));
|
||||
.isEqualTo(String.format(" alpha bravo"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -52,41 +52,41 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void getRequest() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X GET"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X GET"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithParameter() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").param("a", "alpha").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").param("a", "alpha").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha' -i -X GET"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha' -i -X GET"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonGetRequest() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithContent() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").content("content").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").content("content").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X GET -d 'content'"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X GET -d 'content'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithQueryString() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param=value").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param=value").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?param=value' -i -X GET"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?param=value' -i -X GET"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,173 +94,203 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo?param=value").param("param", "value").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?param=value' -i -X GET"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?param=value' -i -X GET"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithPartiallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
|
||||
.request("http://localhost/foo?a=alpha").param("a", "alpha").param("b", "bravo").build());
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X GET"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X GET"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithDisjointQueryStringAndParameters() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha").param("b", "bravo").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha").param("b", "bravo").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X GET"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X GET"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithQueryStringWithNoValue() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?param' -i -X GET"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?param' -i -X GET"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithQueryString() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param=value").method("POST").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param=value").method("POST").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?param=value' -i -X POST"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?param=value' -i -X POST"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithQueryStringWithNoValue() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param").method("POST").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param").method("POST").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?param' -i -X POST"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?param' -i -X POST"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithOneParameter() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("POST").param("k1", "v1").build());
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").param("k1", "v1").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST -d 'k1=v1'"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST -d 'k1=v1'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithOneParameterWithNoValue() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").param("k1").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").param("k1").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST -d 'k1='"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST -d 'k1='"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithMultipleParameters() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("POST").param("k1", "v1", "v1-bis").param("k2", "v2").build());
|
||||
.method("POST")
|
||||
.param("k1", "v1", "v1-bis")
|
||||
.param("k2", "v2")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
|
||||
.withContent("$ curl 'http://localhost/foo' -i -X POST" + " -d 'k1=v1&k1=v1-bis&k2=v2'"));
|
||||
.withContent("$ curl 'http://localhost/foo' -i -X POST" + " -d 'k1=v1&k1=v1-bis&k2=v2'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithUrlEncodedParameter() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("POST").param("k1", "a&b").build());
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").param("k1", "a&b").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST -d 'k1=a%26b'"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST -d 'k1=a%26b'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithDisjointQueryStringAndParameter() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
|
||||
.request("http://localhost/foo?a=alpha").method("POST").param("b", "bravo").build());
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
|
||||
.method("POST")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha' -i -X POST -d 'b=bravo'"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha' -i -X POST -d 'b=bravo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithTotallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo").method("POST")
|
||||
.param("a", "alpha").param("b", "bravo").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo")
|
||||
.method("POST")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X POST"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X POST"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithPartiallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha").method("POST")
|
||||
.param("a", "alpha").param("b", "bravo").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
|
||||
.method("POST")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha' -i -X POST -d 'b=bravo'"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha' -i -X POST -d 'b=bravo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithOverlappingParametersAndFormUrlEncodedBody() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("POST").content("a=alpha&b=bravo")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.param("a", "alpha").param("b", "bravo").build());
|
||||
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("POST")
|
||||
.content("a=alpha&b=bravo")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST "
|
||||
+ "-H 'Content-Type: application/x-www-form-urlencoded' " + "-d 'a=alpha&b=bravo'"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST "
|
||||
+ "-H 'Content-Type: application/x-www-form-urlencoded' " + "-d 'a=alpha&b=bravo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putRequestWithOneParameter() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("PUT").param("k1", "v1").build());
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("PUT").param("k1", "v1").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X PUT -d 'k1=v1'"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X PUT -d 'k1=v1'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putRequestWithMultipleParameters() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("PUT").param("k1", "v1").param("k1", "v1-bis").param("k2", "v2").build());
|
||||
.method("PUT")
|
||||
.param("k1", "v1")
|
||||
.param("k1", "v1-bis")
|
||||
.param("k2", "v2")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
|
||||
.withContent("$ curl 'http://localhost/foo' -i -X PUT" + " -d 'k1=v1&k1=v1-bis&k2=v2'"));
|
||||
.withContent("$ curl 'http://localhost/foo' -i -X PUT" + " -d 'k1=v1&k1=v1-bis&k2=v2'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putRequestWithUrlEncodedParameter() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("PUT").param("k1", "a&b").build());
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("PUT").param("k1", "a&b").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X PUT -d 'k1=a%26b'"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X PUT -d 'k1=a%26b'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithHeaders() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).header("a", "alpha").build());
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("a", "alpha")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash").withContent(
|
||||
"$ curl 'http://localhost/foo' -i -X GET" + " -H 'Content-Type: application/json' -H 'a: alpha'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithHeadersMultiline() throws IOException {
|
||||
new CurlRequestSnippet(CliDocumentation.multiLineFormat()).document(this.operationBuilder
|
||||
.request("http://localhost/foo").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("a", "alpha").build());
|
||||
new CurlRequestSnippet(CliDocumentation.multiLineFormat())
|
||||
.document(this.operationBuilder.request("http://localhost/foo")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("a", "alpha")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent(String.format("$ curl 'http://localhost/foo' -i -X GET \\%n"
|
||||
+ " -H 'Content-Type: application/json' \\%n" + " -H 'a: alpha'")));
|
||||
.is(codeBlock("bash").withContent(String.format("$ curl 'http://localhost/foo' -i -X GET \\%n"
|
||||
+ " -H 'Content-Type: application/json' \\%n" + " -H 'a: alpha'")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithCookies() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.cookie("name1", "value1").cookie("name2", "value2").build());
|
||||
.cookie("name1", "value1")
|
||||
.cookie("name2", "value2")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
|
||||
.withContent("$ curl 'http://localhost/foo' -i -X GET" + " --cookie 'name1=value1;name2=value2'"));
|
||||
.withContent("$ curl 'http://localhost/foo' -i -X GET" + " --cookie 'name1=value1;name2=value2'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartPostWithNoSubmittedFileName() throws IOException {
|
||||
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());
|
||||
.method("POST")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
.part("metadata", "{\"description\": \"foo\"}".getBytes())
|
||||
.build());
|
||||
String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
|
||||
+ "'Content-Type: multipart/form-data' -F " + "'metadata={\"description\": \"foo\"}'";
|
||||
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash").withContent(expectedContent));
|
||||
@@ -269,9 +299,12 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void multipartPostWithContentType() throws IOException {
|
||||
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());
|
||||
.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());
|
||||
String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
|
||||
+ "'Content-Type: multipart/form-data' -F " + "'image=@documents/images/example.png;type=image/png'";
|
||||
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash").withContent(expectedContent));
|
||||
@@ -280,8 +313,11 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void multipartPost() throws IOException {
|
||||
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());
|
||||
.method("POST")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
.part("image", new byte[0])
|
||||
.submittedFileName("documents/images/example.png")
|
||||
.build());
|
||||
String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
|
||||
+ "'Content-Type: multipart/form-data' -F " + "'image=@documents/images/example.png'";
|
||||
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash").withContent(expectedContent));
|
||||
@@ -290,9 +326,14 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void multipartPostWithParameters() throws IOException {
|
||||
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());
|
||||
.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());
|
||||
String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
|
||||
+ "'Content-Type: multipart/form-data' -F "
|
||||
+ "'image=@documents/images/example.png' -F 'a=apple' -F 'a=avocado' " + "-F 'b=banana'";
|
||||
@@ -302,9 +343,15 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void multipartPostWithOverlappingPartsAndParameters() throws IOException {
|
||||
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()
|
||||
.part("a", "apple".getBytes()).and().param("a", "apple").build());
|
||||
.method("POST")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
.part("image", new byte[0])
|
||||
.submittedFileName("documents/images/example.png")
|
||||
.and()
|
||||
.part("a", "apple".getBytes())
|
||||
.and()
|
||||
.param("a", "apple")
|
||||
.build());
|
||||
String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
|
||||
+ "'Content-Type: multipart/form-data' -F 'image=@documents/images/example.png' -F 'a=apple'";
|
||||
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash").withContent(expectedContent));
|
||||
@@ -313,44 +360,53 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void basicAuthCredentialsAreSuppliedUsingUserOption() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.header(HttpHeaders.AUTHORIZATION, "Basic " + Base64Utils.encodeToString("user:secret".getBytes()))
|
||||
.build());
|
||||
.header(HttpHeaders.AUTHORIZATION, "Basic " + Base64Utils.encodeToString("user:secret".getBytes()))
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -u 'user:secret' -X GET"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -u 'user:secret' -X GET"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customAttributes() throws IOException {
|
||||
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());
|
||||
.header(HttpHeaders.HOST, "api.example.com")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("a", "alpha")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X GET -H 'Host: api.example.com'"
|
||||
+ " -H 'Content-Type: application/json' -H 'a: alpha'"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X GET -H 'Host: api.example.com'"
|
||||
+ " -H 'Content-Type: application/json' -H 'a: alpha'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postWithContentAndParameters() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.param("a", "alpha").method("POST").param("b", "bravo").content("Some content").build());
|
||||
.param("a", "alpha")
|
||||
.method("POST")
|
||||
.param("b", "bravo")
|
||||
.content("Some content")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
|
||||
.withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i " + "-X POST -d 'Some content'"));
|
||||
.withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i " + "-X POST -d 'Some content'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteWithParameters() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("DELETE").param("a", "alpha").param("b", "bravo").build());
|
||||
.method("DELETE")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i " + "-X DELETE"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i " + "-X DELETE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteWithQueryString() throws IOException {
|
||||
new CurlRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo").method("DELETE").build());
|
||||
new CurlRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo").method("DELETE").build());
|
||||
assertThat(this.generatedSnippets.curlRequest())
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i " + "-X DELETE"));
|
||||
.is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i " + "-X DELETE"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -53,41 +53,41 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void getRequest() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo'"));
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithParameter() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").param("a", "alpha").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").param("a", "alpha").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?a=alpha'"));
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?a=alpha'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonGetRequest() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http POST 'http://localhost/foo'"));
|
||||
.is(codeBlock("bash").withContent("$ http POST 'http://localhost/foo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithContent() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").content("content").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").content("content").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ echo 'content' | http GET 'http://localhost/foo'"));
|
||||
.is(codeBlock("bash").withContent("$ echo 'content' | http GET 'http://localhost/foo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithQueryString() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param=value").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param=value").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?param=value'"));
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?param=value'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,155 +95,181 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo?param=value").param("param", "value").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?param=value'"));
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?param=value'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithPartiallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
|
||||
.request("http://localhost/foo?a=alpha").param("a", "alpha").param("b", "bravo").build());
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithDisjointQueryStringAndParameters() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha").param("b", "bravo").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha").param("b", "bravo").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithQueryStringWithNoValue() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?param'"));
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo?param'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithQueryString() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param=value").method("POST").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param=value").method("POST").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http POST 'http://localhost/foo?param=value'"));
|
||||
.is(codeBlock("bash").withContent("$ http POST 'http://localhost/foo?param=value'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithQueryStringWithNoValue() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param").method("POST").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?param").method("POST").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http POST 'http://localhost/foo?param'"));
|
||||
.is(codeBlock("bash").withContent("$ http POST 'http://localhost/foo?param'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithOneParameter() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("POST").param("k1", "v1").build());
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").param("k1", "v1").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http --form POST 'http://localhost/foo' 'k1=v1'"));
|
||||
.is(codeBlock("bash").withContent("$ http --form POST 'http://localhost/foo' 'k1=v1'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithOneParameterWithNoValue() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").param("k1").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").param("k1").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http --form POST 'http://localhost/foo' 'k1='"));
|
||||
.is(codeBlock("bash").withContent("$ http --form POST 'http://localhost/foo' 'k1='"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithMultipleParameters() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("POST").param("k1", "v1", "v1-bis").param("k2", "v2").build());
|
||||
.method("POST")
|
||||
.param("k1", "v1", "v1-bis")
|
||||
.param("k2", "v2")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
|
||||
.withContent("$ http --form POST 'http://localhost/foo'" + " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
|
||||
.withContent("$ http --form POST 'http://localhost/foo'" + " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithUrlEncodedParameter() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("POST").param("k1", "a&b").build());
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").param("k1", "a&b").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http --form POST 'http://localhost/foo' 'k1=a&b'"));
|
||||
.is(codeBlock("bash").withContent("$ http --form POST 'http://localhost/foo' 'k1=a&b'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithDisjointQueryStringAndParameter() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
|
||||
.request("http://localhost/foo?a=alpha").method("POST").param("b", "bravo").build());
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
|
||||
.method("POST")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http --form POST 'http://localhost/foo?a=alpha' 'b=bravo'"));
|
||||
.is(codeBlock("bash").withContent("$ http --form POST 'http://localhost/foo?a=alpha' 'b=bravo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithTotallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo").method("POST")
|
||||
.param("a", "alpha").param("b", "bravo").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo")
|
||||
.method("POST")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http POST 'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
.is(codeBlock("bash").withContent("$ http POST 'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithPartiallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha").method("POST")
|
||||
.param("a", "alpha").param("b", "bravo").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
|
||||
.method("POST")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http --form POST 'http://localhost/foo?a=alpha' 'b=bravo'"));
|
||||
.is(codeBlock("bash").withContent("$ http --form POST 'http://localhost/foo?a=alpha' 'b=bravo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithOverlappingParametersAndFormUrlEncodedBody() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("POST").content("a=alpha&b=bravo")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.param("a", "alpha").param("b", "bravo").build());
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("POST")
|
||||
.content("a=alpha&b=bravo")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ echo 'a=alpha&b=bravo' | http POST 'http://localhost/foo' "
|
||||
+ "'Content-Type:application/x-www-form-urlencoded'"));
|
||||
.is(codeBlock("bash").withContent("$ echo 'a=alpha&b=bravo' | http POST 'http://localhost/foo' "
|
||||
+ "'Content-Type:application/x-www-form-urlencoded'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putRequestWithOneParameter() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("PUT").param("k1", "v1").build());
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("PUT").param("k1", "v1").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http --form PUT 'http://localhost/foo' 'k1=v1'"));
|
||||
.is(codeBlock("bash").withContent("$ http --form PUT 'http://localhost/foo' 'k1=v1'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putRequestWithMultipleParameters() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("PUT").param("k1", "v1").param("k1", "v1-bis").param("k2", "v2").build());
|
||||
.method("PUT")
|
||||
.param("k1", "v1")
|
||||
.param("k1", "v1-bis")
|
||||
.param("k2", "v2")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
|
||||
.withContent("$ http --form PUT 'http://localhost/foo'" + " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
|
||||
.withContent("$ http --form PUT 'http://localhost/foo'" + " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putRequestWithUrlEncodedParameter() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("PUT").param("k1", "a&b").build());
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("PUT").param("k1", "a&b").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http --form PUT 'http://localhost/foo' 'k1=a&b'"));
|
||||
.is(codeBlock("bash").withContent("$ http --form PUT 'http://localhost/foo' 'k1=a&b'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithHeaders() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).header("a", "alpha").build());
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("a", "alpha")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
|
||||
.withContent("$ http GET 'http://localhost/foo'" + " 'Content-Type:application/json' 'a:alpha'"));
|
||||
.withContent("$ http GET 'http://localhost/foo'" + " 'Content-Type:application/json' 'a:alpha'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithHeadersMultiline() throws IOException {
|
||||
new HttpieRequestSnippet(CliDocumentation.multiLineFormat()).document(this.operationBuilder
|
||||
.request("http://localhost/foo").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("a", "alpha").build());
|
||||
new HttpieRequestSnippet(CliDocumentation.multiLineFormat())
|
||||
.document(this.operationBuilder.request("http://localhost/foo")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("a", "alpha")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash").withContent(String.format(
|
||||
"$ http GET 'http://localhost/foo' \\%n" + " 'Content-Type:application/json' \\%n 'a:alpha'")));
|
||||
}
|
||||
@@ -251,17 +277,21 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void requestWithCookies() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.cookie("name1", "value1").cookie("name2", "value2").build());
|
||||
.cookie("name1", "value1")
|
||||
.cookie("name2", "value2")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
|
||||
.withContent("$ http GET 'http://localhost/foo'" + " 'Cookie:name1=value1' 'Cookie:name2=value2'"));
|
||||
.withContent("$ http GET 'http://localhost/foo'" + " 'Cookie:name1=value1' 'Cookie:name2=value2'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartPostWithNoSubmittedFileName() throws IOException {
|
||||
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());
|
||||
.document(this.operationBuilder.request("http://localhost/upload")
|
||||
.method("POST")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
.part("metadata", "{\"description\": \"foo\"}".getBytes())
|
||||
.build());
|
||||
String expectedContent = "$ http --multipart POST 'http://localhost/upload'"
|
||||
+ " 'metadata'='{\"description\": \"foo\"}'";
|
||||
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash").withContent(expectedContent));
|
||||
@@ -270,10 +300,13 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void multipartPostWithContentType() throws IOException {
|
||||
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());
|
||||
.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());
|
||||
// httpie does not yet support manually set content type by part
|
||||
String expectedContent = "$ http --multipart POST 'http://localhost/upload'"
|
||||
+ " 'image'@'documents/images/example.png'";
|
||||
@@ -283,9 +316,12 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void multipartPost() throws IOException {
|
||||
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());
|
||||
.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());
|
||||
String expectedContent = "$ http --multipart POST 'http://localhost/upload'"
|
||||
+ " 'image'@'documents/images/example.png'";
|
||||
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash").withContent(expectedContent));
|
||||
@@ -294,10 +330,15 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void multipartPostWithParameters() throws IOException {
|
||||
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());
|
||||
.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());
|
||||
String expectedContent = "$ http --multipart POST 'http://localhost/upload'"
|
||||
+ " 'image'@'documents/images/example.png' 'a=apple' 'a=avocado'" + " 'b=banana'";
|
||||
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash").withContent(expectedContent));
|
||||
@@ -306,10 +347,16 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void multipartPostWithOverlappingPartsAndParameters() throws IOException {
|
||||
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()
|
||||
.part("a", "apple".getBytes()).and().param("a", "apple").build());
|
||||
.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()
|
||||
.part("a", "apple".getBytes())
|
||||
.and()
|
||||
.param("a", "apple")
|
||||
.build());
|
||||
String expectedContent = "$ http --multipart POST 'http://localhost/upload'"
|
||||
+ " 'image'@'documents/images/example.png' 'a'='apple'";
|
||||
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash").withContent(expectedContent));
|
||||
@@ -318,44 +365,53 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void basicAuthCredentialsAreSuppliedUsingAuthOption() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.header(HttpHeaders.AUTHORIZATION, "Basic " + Base64Utils.encodeToString("user:secret".getBytes()))
|
||||
.build());
|
||||
.header(HttpHeaders.AUTHORIZATION, "Basic " + Base64Utils.encodeToString("user:secret".getBytes()))
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http --auth 'user:secret' GET 'http://localhost/foo'"));
|
||||
.is(codeBlock("bash").withContent("$ http --auth 'user:secret' GET 'http://localhost/foo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customAttributes() throws IOException {
|
||||
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());
|
||||
.header(HttpHeaders.HOST, "api.example.com")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("a", "alpha")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo' 'Host:api.example.com'"
|
||||
+ " 'Content-Type:application/json' 'a:alpha'"));
|
||||
.is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo' 'Host:api.example.com'"
|
||||
+ " 'Content-Type:application/json' 'a:alpha'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postWithContentAndParameters() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("POST").param("a", "alpha").param("b", "bravo").content("Some content").build());
|
||||
.method("POST")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.content("Some content")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
|
||||
.withContent("$ echo 'Some content' | http POST " + "'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
.withContent("$ echo 'Some content' | http POST " + "'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteWithParameters() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("DELETE").param("a", "alpha").param("b", "bravo").build());
|
||||
.method("DELETE")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http DELETE 'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
.is(codeBlock("bash").withContent("$ http DELETE 'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteWithQueryString() throws IOException {
|
||||
new HttpieRequestSnippet(this.commandFormatter).document(
|
||||
this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo").method("DELETE").build());
|
||||
new HttpieRequestSnippet(this.commandFormatter)
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo").method("DELETE").build());
|
||||
assertThat(this.generatedSnippets.httpieRequest())
|
||||
.is(codeBlock("bash").withContent("$ http DELETE 'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
.is(codeBlock("bash").withContent("$ http DELETE 'http://localhost/foo?a=alpha&b=bravo'"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2020 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -80,24 +80,24 @@ public class RestDocumentationConfigurerTests {
|
||||
assertThat(configuration.get(WriterResolver.class.getName())).isInstanceOf(StandardWriterResolver.class);
|
||||
assertThat(configuration).containsKey(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
|
||||
assertThat(configuration.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS))
|
||||
.isInstanceOf(List.class);
|
||||
.isInstanceOf(List.class);
|
||||
List<Snippet> defaultSnippets = (List<Snippet>) configuration
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
|
||||
assertThat(defaultSnippets).extracting("class").containsExactlyInAnyOrder(CurlRequestSnippet.class,
|
||||
HttpieRequestSnippet.class, HttpRequestSnippet.class, HttpResponseSnippet.class,
|
||||
RequestBodySnippet.class, ResponseBodySnippet.class);
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
|
||||
assertThat(defaultSnippets).extracting("class")
|
||||
.containsExactlyInAnyOrder(CurlRequestSnippet.class, HttpieRequestSnippet.class, HttpRequestSnippet.class,
|
||||
HttpResponseSnippet.class, RequestBodySnippet.class, ResponseBodySnippet.class);
|
||||
assertThat(configuration).containsKey(SnippetConfiguration.class.getName());
|
||||
assertThat(configuration.get(SnippetConfiguration.class.getName())).isInstanceOf(SnippetConfiguration.class);
|
||||
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
assertThat(snippetConfiguration.getEncoding()).isEqualTo("UTF-8");
|
||||
assertThat(snippetConfiguration.getTemplateFormat().getId()).isEqualTo(TemplateFormats.asciidoctor().getId());
|
||||
OperationRequestPreprocessor defaultOperationRequestPreprocessor = (OperationRequestPreprocessor) configuration
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR);
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR);
|
||||
assertThat(defaultOperationRequestPreprocessor).isNull();
|
||||
|
||||
OperationResponsePreprocessor defaultOperationResponsePreprocessor = (OperationResponsePreprocessor) configuration
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR);
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR);
|
||||
assertThat(defaultOperationResponsePreprocessor).isNull();
|
||||
}
|
||||
|
||||
@@ -123,10 +123,10 @@ public class RestDocumentationConfigurerTests {
|
||||
this.configurer.snippets().withDefaults(CliDocumentation.curlRequest()).apply(configuration, createContext());
|
||||
assertThat(configuration).containsKey(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
|
||||
assertThat(configuration.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS))
|
||||
.isInstanceOf(List.class);
|
||||
.isInstanceOf(List.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Snippet> defaultSnippets = (List<Snippet>) configuration
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
|
||||
assertThat(defaultSnippets).hasSize(1);
|
||||
assertThat(defaultSnippets).hasOnlyElementsOfType(CurlRequestSnippet.class);
|
||||
}
|
||||
@@ -139,12 +139,12 @@ public class RestDocumentationConfigurerTests {
|
||||
this.configurer.snippets().withAdditionalDefaults(snippet).apply(configuration, createContext());
|
||||
assertThat(configuration).containsKey(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
|
||||
assertThat(configuration.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS))
|
||||
.isInstanceOf(List.class);
|
||||
.isInstanceOf(List.class);
|
||||
List<Snippet> defaultSnippets = (List<Snippet>) configuration
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
|
||||
assertThat(defaultSnippets).extracting("class").containsExactlyInAnyOrder(CurlRequestSnippet.class,
|
||||
HttpieRequestSnippet.class, HttpRequestSnippet.class, HttpResponseSnippet.class,
|
||||
RequestBodySnippet.class, ResponseBodySnippet.class, snippet.getClass());
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
|
||||
assertThat(defaultSnippets).extracting("class")
|
||||
.containsExactlyInAnyOrder(CurlRequestSnippet.class, HttpieRequestSnippet.class, HttpRequestSnippet.class,
|
||||
HttpResponseSnippet.class, RequestBodySnippet.class, ResponseBodySnippet.class, snippet.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,7 +155,7 @@ public class RestDocumentationConfigurerTests {
|
||||
assertThat(configuration).containsKey(SnippetConfiguration.class.getName());
|
||||
assertThat(configuration.get(SnippetConfiguration.class.getName())).isInstanceOf(SnippetConfiguration.class);
|
||||
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
assertThat(snippetConfiguration.getEncoding()).isEqualTo(StandardCharsets.ISO_8859_1.displayName());
|
||||
assertThat(configuration.get(TemplateEngine.class.getName())).hasFieldOrPropertyWithValue("templateEncoding",
|
||||
StandardCharsets.ISO_8859_1);
|
||||
@@ -168,7 +168,7 @@ public class RestDocumentationConfigurerTests {
|
||||
assertThat(configuration).containsKey(SnippetConfiguration.class.getName());
|
||||
assertThat(configuration.get(SnippetConfiguration.class.getName())).isInstanceOf(SnippetConfiguration.class);
|
||||
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
.get(SnippetConfiguration.class.getName());
|
||||
assertThat(snippetConfiguration.getTemplateFormat().getId()).isEqualTo(TemplateFormats.markdown().getId());
|
||||
}
|
||||
|
||||
@@ -202,10 +202,10 @@ public class RestDocumentationConfigurerTests {
|
||||
public void customDefaultOperationRequestPreprocessor() {
|
||||
Map<String, Object> configuration = new HashMap<>();
|
||||
this.configurer.operationPreprocessors()
|
||||
.withRequestDefaults(Preprocessors.prettyPrint(), Preprocessors.removeHeaders("Foo"))
|
||||
.apply(configuration, createContext());
|
||||
.withRequestDefaults(Preprocessors.prettyPrint(), Preprocessors.removeHeaders("Foo"))
|
||||
.apply(configuration, createContext());
|
||||
OperationRequestPreprocessor preprocessor = (OperationRequestPreprocessor) configuration
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR);
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Foo", "value");
|
||||
OperationRequest request = new OperationRequestFactory().create(URI.create("http://localhost:8080"),
|
||||
@@ -217,10 +217,10 @@ public class RestDocumentationConfigurerTests {
|
||||
public void customDefaultOperationResponsePreprocessor() {
|
||||
Map<String, Object> configuration = new HashMap<>();
|
||||
this.configurer.operationPreprocessors()
|
||||
.withResponseDefaults(Preprocessors.prettyPrint(), Preprocessors.removeHeaders("Foo"))
|
||||
.apply(configuration, createContext());
|
||||
.withResponseDefaults(Preprocessors.prettyPrint(), Preprocessors.removeHeaders("Foo"))
|
||||
.apply(configuration, createContext());
|
||||
OperationResponsePreprocessor preprocessor = (OperationResponsePreprocessor) configuration
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR);
|
||||
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Foo", "value");
|
||||
OperationResponse response = new OperationResponseFactory().create(HttpStatus.OK.value(), headers, null);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -45,7 +45,7 @@ public class ConstraintDescriptionsTests {
|
||||
Constraint constraint1 = new Constraint("constraint1", Collections.<String, Object>emptyMap());
|
||||
Constraint constraint2 = new Constraint("constraint2", Collections.<String, Object>emptyMap());
|
||||
given(this.constraintResolver.resolveForProperty("foo", Constrained.class))
|
||||
.willReturn(Arrays.asList(constraint1, constraint2));
|
||||
.willReturn(Arrays.asList(constraint1, constraint2));
|
||||
given(this.constraintDescriptionResolver.resolveDescription(constraint1)).willReturn("Bravo");
|
||||
given(this.constraintDescriptionResolver.resolveDescription(constraint2)).willReturn("Alpha");
|
||||
assertThat(this.constraintDescriptions.descriptionsForProperty("foo")).containsExactly("Alpha", "Bravo");
|
||||
@@ -54,7 +54,7 @@ public class ConstraintDescriptionsTests {
|
||||
@Test
|
||||
public void emptyListOfDescriptionsWhenThereAreNoConstraints() {
|
||||
given(this.constraintResolver.resolveForProperty("foo", Constrained.class))
|
||||
.willReturn(Collections.<Constraint>emptyList());
|
||||
.willReturn(Collections.<Constraint>emptyList());
|
||||
assertThat(this.constraintDescriptions.descriptionsForProperty("foo").size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -89,13 +89,13 @@ public class ResourceBundleConstraintDescriptionResolverTests {
|
||||
@Test
|
||||
public void defaultMessageCodePointLength() {
|
||||
assertThat(constraintDescriptionForField("codePointLength"))
|
||||
.isEqualTo("Code point length must be between 2 and 5 inclusive");
|
||||
.isEqualTo("Code point length must be between 2 and 5 inclusive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultMessageCurrency() {
|
||||
assertThat(constraintDescriptionForField("currency"))
|
||||
.isEqualTo("Must be in an accepted currency unit (GBP, USD)");
|
||||
.isEqualTo("Must be in an accepted currency unit (GBP, USD)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,7 +111,7 @@ public class ResourceBundleConstraintDescriptionResolverTests {
|
||||
@Test
|
||||
public void defaultMessageDigits() {
|
||||
assertThat(constraintDescriptionForField("digits"))
|
||||
.isEqualTo("Must have at most 2 integral digits and 5 fractional digits");
|
||||
.isEqualTo("Must have at most 2 integral digits and 5 fractional digits");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,7 +157,7 @@ public class ResourceBundleConstraintDescriptionResolverTests {
|
||||
@Test
|
||||
public void defaultMessagePattern() {
|
||||
assertThat(constraintDescriptionForField("pattern"))
|
||||
.isEqualTo("Must match the regular expression `[A-Z][a-z]+`");
|
||||
.isEqualTo("Must match the regular expression `[A-Z][a-z]+`");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -168,7 +168,7 @@ public class ResourceBundleConstraintDescriptionResolverTests {
|
||||
@Test
|
||||
public void defaultMessageCreditCardNumber() {
|
||||
assertThat(constraintDescriptionForField("creditCardNumber"))
|
||||
.isEqualTo("Must be a well-formed credit card number");
|
||||
.isEqualTo("Must be a well-formed credit card number");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,7 +184,7 @@ public class ResourceBundleConstraintDescriptionResolverTests {
|
||||
@Test
|
||||
public void defaultMessageEmailHibernateValidator() {
|
||||
assertThat(constraintDescriptionForField("emailHibernateValidator"))
|
||||
.isEqualTo("Must be a well-formed email address");
|
||||
.isEqualTo("Must be a well-formed email address");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,7 +195,7 @@ public class ResourceBundleConstraintDescriptionResolverTests {
|
||||
@Test
|
||||
public void defaultMessageLuhnCheck() {
|
||||
assertThat(constraintDescriptionForField("luhnCheck"))
|
||||
.isEqualTo("Must pass the Luhn Modulo 10 checksum algorithm");
|
||||
.isEqualTo("Must pass the Luhn Modulo 10 checksum algorithm");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -279,8 +279,8 @@ public class ResourceBundleConstraintDescriptionResolverTests {
|
||||
});
|
||||
|
||||
try {
|
||||
String description = new ResourceBundleConstraintDescriptionResolver().resolveDescription(
|
||||
new Constraint(NotNull.class.getName(), Collections.<String, Object>emptyMap()));
|
||||
String description = new ResourceBundleConstraintDescriptionResolver()
|
||||
.resolveDescription(new Constraint(NotNull.class.getName(), Collections.<String, Object>emptyMap()));
|
||||
assertThat(description).isEqualTo("Should not be null");
|
||||
|
||||
}
|
||||
@@ -300,7 +300,7 @@ public class ResourceBundleConstraintDescriptionResolverTests {
|
||||
|
||||
};
|
||||
String description = new ResourceBundleConstraintDescriptionResolver(bundle)
|
||||
.resolveDescription(new Constraint(NotNull.class.getName(), Collections.<String, Object>emptyMap()));
|
||||
.resolveDescription(new Constraint(NotNull.class.getName(), Collections.<String, Object>emptyMap()));
|
||||
assertThat(description).isEqualTo("Not null");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -42,17 +42,17 @@ public class RequestHeadersSnippetFailureTests {
|
||||
@Test
|
||||
public void missingRequestHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestHeadersSnippet(Arrays.asList(headerWithName("Accept").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").build()))
|
||||
.withMessage("Headers with the following names were not found in the request: [Accept]");
|
||||
.isThrownBy(() -> new RequestHeadersSnippet(Arrays.asList(headerWithName("Accept").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").build()))
|
||||
.withMessage("Headers with the following names were not found in the request: [Accept]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedRequestHeaderAndMissingRequestHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestHeadersSnippet(Arrays.asList(headerWithName("Accept").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").header("X-Test", "test").build()))
|
||||
.withMessageEndingWith("Headers with the following names were not found in the request: [Accept]");
|
||||
.isThrownBy(() -> new RequestHeadersSnippet(Arrays.asList(headerWithName("Accept").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").header("X-Test", "test").build()))
|
||||
.withMessageEndingWith("Headers with the following names were not found in the request: [Accept]");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -53,42 +53,54 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
|
||||
headerWithName("Accept").description("two"), 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")
|
||||
.header("Accept-Language", "en-US,en;q=0.5").header("Cache-Control", "max-age=0")
|
||||
.header("Connection", "keep-alive").build());
|
||||
assertThat(this.generatedSnippets.requestHeaders()).is(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"));
|
||||
.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());
|
||||
assertThat(this.generatedSnippets.requestHeaders())
|
||||
.is(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"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caseInsensitiveRequestHeaders() throws IOException {
|
||||
new RequestHeadersSnippet(Arrays.asList(headerWithName("X-Test").description("one")))
|
||||
.document(this.operationBuilder.request("/").header("X-test", "test").build());
|
||||
.document(this.operationBuilder.request("/").header("X-test", "test").build());
|
||||
assertThat(this.generatedSnippets.requestHeaders())
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedRequestHeader() throws IOException {
|
||||
new RequestHeadersSnippet(Arrays.asList(headerWithName("X-Test").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").header("X-Test", "test")
|
||||
.header("Accept", "*/*").build());
|
||||
.document(this.operationBuilder.request("http://localhost")
|
||||
.header("X-Test", "test")
|
||||
.header("Accept", "*/*")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.requestHeaders())
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestHeadersWithCustomAttributes() throws IOException {
|
||||
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
|
||||
given(resolver.resolveTemplateResource("request-headers"))
|
||||
.willReturn(snippetResource("request-headers-with-title"));
|
||||
.willReturn(snippetResource("request-headers-with-title"));
|
||||
new RequestHeadersSnippet(Arrays.asList(headerWithName("X-Test").description("one")),
|
||||
attributes(key("title").value("Custom title")))
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.request("http://localhost").header("X-Test", "test").build());
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.request("http://localhost")
|
||||
.header("X-Test", "test")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.requestHeaders()).contains("Custom title");
|
||||
}
|
||||
|
||||
@@ -96,42 +108,54 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
|
||||
public void requestHeadersWithCustomDescriptorAttributes() throws IOException {
|
||||
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
|
||||
given(resolver.resolveTemplateResource("request-headers"))
|
||||
.willReturn(snippetResource("request-headers-with-extra-column"));
|
||||
.willReturn(snippetResource("request-headers-with-extra-column"));
|
||||
new RequestHeadersSnippet(
|
||||
Arrays.asList(headerWithName("X-Test").description("one").attributes(key("foo").value("alpha")),
|
||||
headerWithName("Accept-Encoding").description("two").attributes(key("foo").value("bravo")),
|
||||
headerWithName("Accept").description("three").attributes(key("foo").value("charlie"))))
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.request("http://localhost").header("X-Test", "test")
|
||||
.header("Accept-Encoding", "gzip, deflate").header("Accept", "*/*").build());
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.request("http://localhost")
|
||||
.header("X-Test", "test")
|
||||
.header("Accept-Encoding", "gzip, deflate")
|
||||
.header("Accept", "*/*")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.requestHeaders()).is(//
|
||||
tableWithHeader("Name", "Description", "Foo").row("X-Test", "one", "alpha")
|
||||
.row("Accept-Encoding", "two", "bravo").row("Accept", "three", "charlie"));
|
||||
.row("Accept-Encoding", "two", "bravo")
|
||||
.row("Accept", "three", "charlie"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void additionalDescriptors() throws IOException {
|
||||
HeaderDocumentation.requestHeaders(headerWithName("X-Test").description("one"),
|
||||
headerWithName("Accept").description("two"), headerWithName("Accept-Encoding").description("three"),
|
||||
headerWithName("Accept-Language").description("four"))
|
||||
.and(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")
|
||||
.header("Accept-Language", "en-US,en;q=0.5").header("Cache-Control", "max-age=0")
|
||||
.header("Connection", "keep-alive").build());
|
||||
assertThat(this.generatedSnippets.requestHeaders()).is(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"));
|
||||
HeaderDocumentation
|
||||
.requestHeaders(headerWithName("X-Test").description("one"), headerWithName("Accept").description("two"),
|
||||
headerWithName("Accept-Encoding").description("three"),
|
||||
headerWithName("Accept-Language").description("four"))
|
||||
.and(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")
|
||||
.header("Accept-Language", "en-US,en;q=0.5")
|
||||
.header("Cache-Control", "max-age=0")
|
||||
.header("Connection", "keep-alive")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.requestHeaders())
|
||||
.is(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"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tableCellContentIsEscapedWhenNecessary() throws IOException {
|
||||
new RequestHeadersSnippet(Arrays.asList(headerWithName("Foo|Bar").description("one|two")))
|
||||
.document(this.operationBuilder.request("http://localhost").header("Foo|Bar", "baz").build());
|
||||
.document(this.operationBuilder.request("http://localhost").header("Foo|Bar", "baz").build());
|
||||
assertThat(this.generatedSnippets.requestHeaders()).is(tableWithHeader("Name", "Description")
|
||||
.row(escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two")));
|
||||
.row(escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two")));
|
||||
}
|
||||
|
||||
private String escapeIfNecessary(String input) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -41,19 +41,20 @@ public class ResponseHeadersSnippetFailureTests {
|
||||
|
||||
@Test
|
||||
public void missingResponseHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new ResponseHeadersSnippet(Arrays.asList(headerWithName("Content-Type").description("one")))
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(
|
||||
() -> new ResponseHeadersSnippet(Arrays.asList(headerWithName("Content-Type").description("one")))
|
||||
.document(this.operationBuilder.response().build()))
|
||||
.withMessage("Headers with the following names were not found" + " in the response: [Content-Type]");
|
||||
.withMessage("Headers with the following names were not found" + " in the response: [Content-Type]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedResponseHeaderAndMissingResponseHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new ResponseHeadersSnippet(Arrays.asList(headerWithName("Content-Type").description("one")))
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(
|
||||
() -> new ResponseHeadersSnippet(Arrays.asList(headerWithName("Content-Type").description("one")))
|
||||
.document(this.operationBuilder.response().header("X-Test", "test").build()))
|
||||
.withMessageEndingWith(
|
||||
"Headers with the following names were not found in the response: [Content-Type]");
|
||||
.withMessageEndingWith("Headers with the following names were not found in the response: [Content-Type]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -52,40 +52,49 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
|
||||
new ResponseHeadersSnippet(Arrays.asList(headerWithName("X-Test").description("one"),
|
||||
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());
|
||||
.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());
|
||||
assertThat(this.generatedSnippets.responseHeaders())
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one").row("`Content-Type`", "two")
|
||||
.row("`Etag`", "three").row("`Cache-Control`", "five").row("`Vary`", "six"));
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one")
|
||||
.row("`Content-Type`", "two")
|
||||
.row("`Etag`", "three")
|
||||
.row("`Cache-Control`", "five")
|
||||
.row("`Vary`", "six"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caseInsensitiveResponseHeaders() throws IOException {
|
||||
new ResponseHeadersSnippet(Arrays.asList(headerWithName("X-Test").description("one")))
|
||||
.document(this.operationBuilder.response().header("X-test", "test").build());
|
||||
.document(this.operationBuilder.response().header("X-test", "test").build());
|
||||
assertThat(this.generatedSnippets.responseHeaders())
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedResponseHeader() throws IOException {
|
||||
new ResponseHeadersSnippet(Arrays.asList(headerWithName("X-Test").description("one"))).document(
|
||||
this.operationBuilder.response().header("X-Test", "test").header("Content-Type", "*/*").build());
|
||||
new ResponseHeadersSnippet(Arrays.asList(headerWithName("X-Test").description("one")))
|
||||
.document(this.operationBuilder.response().header("X-Test", "test").header("Content-Type", "*/*").build());
|
||||
assertThat(this.generatedSnippets.responseHeaders())
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseHeadersWithCustomAttributes() throws IOException {
|
||||
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
|
||||
given(resolver.resolveTemplateResource("response-headers"))
|
||||
.willReturn(snippetResource("response-headers-with-title"));
|
||||
.willReturn(snippetResource("response-headers-with-title"));
|
||||
new ResponseHeadersSnippet(Arrays.asList(headerWithName("X-Test").description("one")),
|
||||
attributes(key("title").value("Custom title")))
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.response().header("X-Test", "test").build());
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.response()
|
||||
.header("X-Test", "test")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.responseHeaders()).contains("Custom title");
|
||||
}
|
||||
|
||||
@@ -93,39 +102,51 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
|
||||
public void responseHeadersWithCustomDescriptorAttributes() throws IOException {
|
||||
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
|
||||
given(resolver.resolveTemplateResource("response-headers"))
|
||||
.willReturn(snippetResource("response-headers-with-extra-column"));
|
||||
.willReturn(snippetResource("response-headers-with-extra-column"));
|
||||
new ResponseHeadersSnippet(
|
||||
Arrays.asList(headerWithName("X-Test").description("one").attributes(key("foo").value("alpha")),
|
||||
headerWithName("Content-Type").description("two").attributes(key("foo").value("bravo")),
|
||||
headerWithName("Etag").description("three").attributes(key("foo").value("charlie"))))
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.response().header("X-Test", "test").header("Content-Type", "application/json")
|
||||
.header("Etag", "lskjadldj3ii32l2ij23").build());
|
||||
assertThat(this.generatedSnippets.responseHeaders()).is(tableWithHeader("Name", "Description", "Foo")
|
||||
.row("X-Test", "one", "alpha").row("Content-Type", "two", "bravo").row("Etag", "three", "charlie"));
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.response()
|
||||
.header("X-Test", "test")
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Etag", "lskjadldj3ii32l2ij23")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.responseHeaders())
|
||||
.is(tableWithHeader("Name", "Description", "Foo").row("X-Test", "one", "alpha")
|
||||
.row("Content-Type", "two", "bravo")
|
||||
.row("Etag", "three", "charlie"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void additionalDescriptors() throws IOException {
|
||||
HeaderDocumentation
|
||||
.responseHeaders(headerWithName("X-Test").description("one"),
|
||||
headerWithName("Content-Type").description("two"), headerWithName("Etag").description("three"))
|
||||
.and(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());
|
||||
.responseHeaders(headerWithName("X-Test").description("one"),
|
||||
headerWithName("Content-Type").description("two"), headerWithName("Etag").description("three"))
|
||||
.and(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());
|
||||
assertThat(this.generatedSnippets.responseHeaders())
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one").row("`Content-Type`", "two")
|
||||
.row("`Etag`", "three").row("`Cache-Control`", "five").row("`Vary`", "six"));
|
||||
.is(tableWithHeader("Name", "Description").row("`X-Test`", "one")
|
||||
.row("`Content-Type`", "two")
|
||||
.row("`Etag`", "three")
|
||||
.row("`Cache-Control`", "five")
|
||||
.row("`Vary`", "six"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tableCellContentIsEscapedWhenNecessary() throws IOException {
|
||||
new ResponseHeadersSnippet(Arrays.asList(headerWithName("Foo|Bar").description("one|two")))
|
||||
.document(this.operationBuilder.response().header("Foo|Bar", "baz").build());
|
||||
.document(this.operationBuilder.response().header("Foo|Bar", "baz").build());
|
||||
assertThat(this.generatedSnippets.responseHeaders()).is(tableWithHeader("Name", "Description")
|
||||
.row(escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two")));
|
||||
.row(escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two")));
|
||||
}
|
||||
|
||||
private String escapeIfNecessary(String input) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -52,270 +52,345 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void getRequest() throws IOException {
|
||||
new HttpRequestSnippet()
|
||||
.document(this.operationBuilder.request("http://localhost/foo").header("Alpha", "a").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").header("Alpha", "a").build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.GET, "/foo").header("Alpha", "a").header(HttpHeaders.HOST, "localhost"));
|
||||
.is(httpRequest(RequestMethod.GET, "/foo").header("Alpha", "a").header(HttpHeaders.HOST, "localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithParameters() throws IOException {
|
||||
new HttpRequestSnippet().document(
|
||||
this.operationBuilder.request("http://localhost/foo").header("Alpha", "a").param("b", "bravo").build());
|
||||
assertThat(this.generatedSnippets.httpRequest()).is(httpRequest(RequestMethod.GET, "/foo?b=bravo")
|
||||
.header("Alpha", "a").header(HttpHeaders.HOST, "localhost"));
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.GET, "/foo?b=bravo").header("Alpha", "a")
|
||||
.header(HttpHeaders.HOST, "localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithPort() throws IOException {
|
||||
new HttpRequestSnippet()
|
||||
.document(this.operationBuilder.request("http://localhost:8080/foo").header("Alpha", "a").build());
|
||||
assertThat(this.generatedSnippets.httpRequest()).is(
|
||||
httpRequest(RequestMethod.GET, "/foo").header("Alpha", "a").header(HttpHeaders.HOST, "localhost:8080"));
|
||||
.document(this.operationBuilder.request("http://localhost:8080/foo").header("Alpha", "a").build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.GET, "/foo").header("Alpha", "a").header(HttpHeaders.HOST, "localhost:8080"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithCookies() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo")
|
||||
.cookie("name1", "value1").cookie("name2", "value2").build());
|
||||
.cookie("name1", "value1")
|
||||
.cookie("name2", "value2")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.GET, "/foo").header(HttpHeaders.HOST, "localhost")
|
||||
.header(HttpHeaders.COOKIE, "name1=value1").header(HttpHeaders.COOKIE, "name2=value2"));
|
||||
.is(httpRequest(RequestMethod.GET, "/foo").header(HttpHeaders.HOST, "localhost")
|
||||
.header(HttpHeaders.COOKIE, "name1=value1")
|
||||
.header(HttpHeaders.COOKIE, "name2=value2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithQueryString() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo?bar=baz").build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.GET, "/foo?bar=baz").header(HttpHeaders.HOST, "localhost"));
|
||||
.is(httpRequest(RequestMethod.GET, "/foo?bar=baz").header(HttpHeaders.HOST, "localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithQueryStringWithNoValue() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo?bar").build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.GET, "/foo?bar").header(HttpHeaders.HOST, "localhost"));
|
||||
.is(httpRequest(RequestMethod.GET, "/foo?bar").header(HttpHeaders.HOST, "localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWithPartiallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo?a=alpha")
|
||||
.param("a", "alpha").param("b", "bravo").build());
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.GET, "/foo?a=alpha&b=bravo").header(HttpHeaders.HOST, "localhost"));
|
||||
.is(httpRequest(RequestMethod.GET, "/foo?a=alpha&b=bravo").header(HttpHeaders.HOST, "localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWithTotallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo")
|
||||
.param("a", "alpha").param("b", "bravo").build());
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.GET, "/foo?a=alpha&b=bravo").header(HttpHeaders.HOST, "localhost"));
|
||||
.is(httpRequest(RequestMethod.GET, "/foo?a=alpha&b=bravo").header(HttpHeaders.HOST, "localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithContent() throws IOException {
|
||||
String content = "Hello, world";
|
||||
new HttpRequestSnippet().document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("POST").content(content).build());
|
||||
new HttpRequestSnippet()
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").content(content).build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.POST, "/foo").header(HttpHeaders.HOST, "localhost").content(content)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
.is(httpRequest(RequestMethod.POST, "/foo").header(HttpHeaders.HOST, "localhost")
|
||||
.content(content)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithContentAndParameters() throws IOException {
|
||||
String content = "Hello, world";
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo").method("POST")
|
||||
.param("a", "alpha").content(content).build());
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("POST")
|
||||
.param("a", "alpha")
|
||||
.content(content)
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.POST, "/foo?a=alpha").header(HttpHeaders.HOST, "localhost")
|
||||
.content(content).header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
.is(httpRequest(RequestMethod.POST, "/foo?a=alpha").header(HttpHeaders.HOST, "localhost")
|
||||
.content(content)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithContentAndDisjointQueryStringAndParameters() throws IOException {
|
||||
String content = "Hello, world";
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo?b=bravo").method("POST")
|
||||
.param("a", "alpha").content(content).build());
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo?b=bravo")
|
||||
.method("POST")
|
||||
.param("a", "alpha")
|
||||
.content(content)
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha").header(HttpHeaders.HOST, "localhost")
|
||||
.content(content).header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
.is(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha").header(HttpHeaders.HOST, "localhost")
|
||||
.content(content)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithContentAndPartiallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
String content = "Hello, world";
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo?b=bravo").method("POST")
|
||||
.param("a", "alpha").param("b", "bravo").content(content).build());
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo?b=bravo")
|
||||
.method("POST")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.content(content)
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha").header(HttpHeaders.HOST, "localhost")
|
||||
.content(content).header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
.is(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha").header(HttpHeaders.HOST, "localhost")
|
||||
.content(content)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithContentAndTotallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
String content = "Hello, world";
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo?b=bravo&a=alpha")
|
||||
.method("POST").param("a", "alpha").param("b", "bravo").content(content).build());
|
||||
.method("POST")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.content(content)
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha").header(HttpHeaders.HOST, "localhost")
|
||||
.content(content).header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
.is(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha").header(HttpHeaders.HOST, "localhost")
|
||||
.content(content)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithOverlappingParametersAndFormUrlEncodedBody() throws IOException {
|
||||
String content = "a=alpha&b=bravo";
|
||||
new HttpRequestSnippet().document(
|
||||
this.operationBuilder.request("http://localhost/foo").method("POST").content("a=alpha&b=bravo")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.param("a", "alpha").param("b", "bravo").build());
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("POST")
|
||||
.content("a=alpha&b=bravo")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest()).is(httpRequest(RequestMethod.POST, "/foo")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.header(HttpHeaders.HOST, "localhost").content(content)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.header(HttpHeaders.HOST, "localhost")
|
||||
.content(content)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithCharset() throws IOException {
|
||||
String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4";
|
||||
byte[] contentBytes = japaneseContent.getBytes("UTF-8");
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo").method("POST")
|
||||
.header("Content-Type", "text/plain;charset=UTF-8").content(contentBytes).build());
|
||||
assertThat(this.generatedSnippets.httpRequest()).is(httpRequest(RequestMethod.POST, "/foo")
|
||||
.header("Content-Type", "text/plain;charset=UTF-8").header(HttpHeaders.HOST, "localhost")
|
||||
.header(HttpHeaders.CONTENT_LENGTH, contentBytes.length).content(japaneseContent));
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("POST")
|
||||
.header("Content-Type", "text/plain;charset=UTF-8")
|
||||
.content(contentBytes)
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.POST, "/foo").header("Content-Type", "text/plain;charset=UTF-8")
|
||||
.header(HttpHeaders.HOST, "localhost")
|
||||
.header(HttpHeaders.CONTENT_LENGTH, contentBytes.length)
|
||||
.content(japaneseContent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithParameter() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo").method("POST")
|
||||
.param("b&r", "baz").param("a", "alpha").build());
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("POST")
|
||||
.param("b&r", "baz")
|
||||
.param("a", "alpha")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.POST, "/foo").header(HttpHeaders.HOST, "localhost")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded").content("b%26r=baz&a=alpha"));
|
||||
.is(httpRequest(RequestMethod.POST, "/foo").header(HttpHeaders.HOST, "localhost")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.content("b%26r=baz&a=alpha"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithParameterWithNoValue() throws IOException {
|
||||
new HttpRequestSnippet()
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").param("bar").build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("POST").param("bar").build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.POST, "/foo").header(HttpHeaders.HOST, "localhost")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded").content("bar="));
|
||||
.is(httpRequest(RequestMethod.POST, "/foo").header(HttpHeaders.HOST, "localhost")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.content("bar="));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putRequestWithContent() throws IOException {
|
||||
String content = "Hello, world";
|
||||
new HttpRequestSnippet()
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("PUT").content(content).build());
|
||||
.document(this.operationBuilder.request("http://localhost/foo").method("PUT").content(content).build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.PUT, "/foo").header(HttpHeaders.HOST, "localhost").content(content)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
.is(httpRequest(RequestMethod.PUT, "/foo").header(HttpHeaders.HOST, "localhost")
|
||||
.content(content)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putRequestWithParameter() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo").method("PUT")
|
||||
.param("b&r", "baz").param("a", "alpha").build());
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("PUT")
|
||||
.param("b&r", "baz")
|
||||
.param("a", "alpha")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.PUT, "/foo").header(HttpHeaders.HOST, "localhost")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded").content("b%26r=baz&a=alpha"));
|
||||
.is(httpRequest(RequestMethod.PUT, "/foo").header(HttpHeaders.HOST, "localhost")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.content("b%26r=baz&a=alpha"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putRequestWithTotallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo")
|
||||
.method("PUT").param("a", "alpha").param("b", "bravo").build());
|
||||
.method("PUT")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.PUT, "/foo?a=alpha&b=bravo").header(HttpHeaders.HOST, "localhost"));
|
||||
.is(httpRequest(RequestMethod.PUT, "/foo?a=alpha&b=bravo").header(HttpHeaders.HOST, "localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartPost() throws IOException {
|
||||
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());
|
||||
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());
|
||||
String expectedContent = createPart(
|
||||
String.format("Content-Disposition: " + "form-data; " + "name=image%n%n<< data >>"));
|
||||
assertThat(this.generatedSnippets.httpRequest()).is(httpRequest(RequestMethod.POST, "/upload")
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost")
|
||||
.content(expectedContent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartPostWithFilename() throws IOException {
|
||||
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());
|
||||
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());
|
||||
String expectedContent = createPart(String
|
||||
.format("Content-Disposition: " + "form-data; " + "name=image; filename=image.png%n%n<< data >>"));
|
||||
.format("Content-Disposition: " + "form-data; " + "name=image; filename=image.png%n%n<< data >>"));
|
||||
assertThat(this.generatedSnippets.httpRequest()).is(httpRequest(RequestMethod.POST, "/upload")
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost")
|
||||
.content(expectedContent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartPostWithParameters() throws IOException {
|
||||
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());
|
||||
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());
|
||||
String param1Part = createPart(String.format("Content-Disposition: form-data; " + "name=a%n%napple"), false);
|
||||
String param2Part = createPart(String.format("Content-Disposition: form-data; " + "name=a%n%navocado"), false);
|
||||
String param3Part = createPart(String.format("Content-Disposition: form-data; " + "name=b%n%nbanana"), false);
|
||||
String filePart = createPart(String.format("Content-Disposition: form-data; " + "name=image%n%n<< data >>"));
|
||||
String expectedContent = param1Part + param2Part + param3Part + filePart;
|
||||
assertThat(this.generatedSnippets.httpRequest()).is(httpRequest(RequestMethod.POST, "/upload")
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost")
|
||||
.content(expectedContent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartPostWithOverlappingPartsAndParameters() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/upload").method("POST")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE).param("a", "apple")
|
||||
.part("a", "apple".getBytes()).and().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", "apple")
|
||||
.part("a", "apple".getBytes())
|
||||
.and()
|
||||
.part("image", "<< data >>".getBytes())
|
||||
.build());
|
||||
String paramPart = createPart(String.format("Content-Disposition: form-data; " + "name=a%n%napple"), false);
|
||||
String filePart = createPart(String.format("Content-Disposition: form-data; " + "name=image%n%n<< data >>"));
|
||||
String expectedContent = paramPart + filePart;
|
||||
assertThat(this.generatedSnippets.httpRequest()).is(httpRequest(RequestMethod.POST, "/upload")
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost")
|
||||
.content(expectedContent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartPostWithParameterWithNoValue() throws IOException {
|
||||
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());
|
||||
String paramPart = createPart(String.format("Content-Disposition: form-data; " + "name=a%n"), false);
|
||||
String filePart = createPart(String.format("Content-Disposition: form-data; " + "name=image%n%n<< data >>"));
|
||||
String expectedContent = paramPart + filePart;
|
||||
assertThat(this.generatedSnippets.httpRequest()).is(httpRequest(RequestMethod.POST, "/upload")
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost")
|
||||
.content(expectedContent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartPostWithContentType() throws IOException {
|
||||
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());
|
||||
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());
|
||||
String expectedContent = createPart(String
|
||||
.format("Content-Disposition: form-data; name=image%nContent-Type: " + "image/png%n%n<< data >>"));
|
||||
.format("Content-Disposition: form-data; name=image%nContent-Type: " + "image/png%n%n<< data >>"));
|
||||
assertThat(this.generatedSnippets.httpRequest()).is(httpRequest(RequestMethod.POST, "/upload")
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
|
||||
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
|
||||
.header(HttpHeaders.HOST, "localhost")
|
||||
.content(expectedContent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithCustomHost() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo")
|
||||
.header(HttpHeaders.HOST, "api.example.com").build());
|
||||
.header(HttpHeaders.HOST, "api.example.com")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.GET, "/foo").header(HttpHeaders.HOST, "api.example.com"));
|
||||
.is(httpRequest(RequestMethod.GET, "/foo").header(HttpHeaders.HOST, "api.example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -324,24 +399,28 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
|
||||
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());
|
||||
.request("http://localhost/foo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest()).contains("Title for the request");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteWithParameters() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo").method("DELETE")
|
||||
.param("a", "alpha").param("b", "bravo").build());
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo")
|
||||
.method("DELETE")
|
||||
.param("a", "alpha")
|
||||
.param("b", "bravo")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.DELETE, "/foo?a=alpha&b=bravo").header("Host", "localhost"));
|
||||
.is(httpRequest(RequestMethod.DELETE, "/foo?a=alpha&b=bravo").header("Host", "localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteWithQueryString() throws IOException {
|
||||
new HttpRequestSnippet().document(
|
||||
this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo").method("DELETE").build());
|
||||
new HttpRequestSnippet()
|
||||
.document(this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo").method("DELETE").build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.DELETE, "/foo?a=alpha&b=bravo").header("Host", "localhost"));
|
||||
.is(httpRequest(RequestMethod.DELETE, "/foo?a=alpha&b=bravo").header("Host", "localhost"));
|
||||
}
|
||||
|
||||
private String createPart(String content) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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,16 +56,18 @@ public class HttpResponseSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void nonOkResponse() throws IOException {
|
||||
new HttpResponseSnippet()
|
||||
.document(this.operationBuilder.response().status(HttpStatus.BAD_REQUEST.value()).build());
|
||||
.document(this.operationBuilder.response().status(HttpStatus.BAD_REQUEST.value()).build());
|
||||
assertThat(this.generatedSnippets.httpResponse()).is(httpResponse(HttpStatus.BAD_REQUEST));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseWithHeaders() throws IOException {
|
||||
new HttpResponseSnippet().document(this.operationBuilder.response()
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).header("a", "alpha").build());
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("a", "alpha")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpResponse())
|
||||
.is(httpResponse(HttpStatus.OK).header("Content-Type", "application/json").header("a", "alpha"));
|
||||
.is(httpResponse(HttpStatus.OK).header("Content-Type", "application/json").header("a", "alpha"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +75,7 @@ public class HttpResponseSnippetTests extends AbstractSnippetTests {
|
||||
String content = "content";
|
||||
new HttpResponseSnippet().document(this.operationBuilder.response().content(content).build());
|
||||
assertThat(this.generatedSnippets.httpResponse()).is(httpResponse(HttpStatus.OK).content(content)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,19 +83,23 @@ public class HttpResponseSnippetTests extends AbstractSnippetTests {
|
||||
String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4";
|
||||
byte[] contentBytes = japaneseContent.getBytes("UTF-8");
|
||||
new HttpResponseSnippet().document(this.operationBuilder.response()
|
||||
.header("Content-Type", "text/plain;charset=UTF-8").content(contentBytes).build());
|
||||
.header("Content-Type", "text/plain;charset=UTF-8")
|
||||
.content(contentBytes)
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpResponse())
|
||||
.is(httpResponse(HttpStatus.OK).header("Content-Type", "text/plain;charset=UTF-8")
|
||||
.content(japaneseContent).header(HttpHeaders.CONTENT_LENGTH, contentBytes.length));
|
||||
.is(httpResponse(HttpStatus.OK).header("Content-Type", "text/plain;charset=UTF-8")
|
||||
.content(japaneseContent)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, contentBytes.length));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseWithCustomSnippetAttributes() throws IOException {
|
||||
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
|
||||
given(resolver.resolveTemplateResource("http-response"))
|
||||
.willReturn(snippetResource("http-response-with-title"));
|
||||
new HttpResponseSnippet(attributes(key("title").value("Title for the response"))).document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver)).build());
|
||||
.willReturn(snippetResource("http-response-with-title"));
|
||||
new HttpResponseSnippet(attributes(key("title").value("Title for the response"))).document(
|
||||
this.operationBuilder.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.httpResponse()).contains("Title for the response");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -49,7 +49,7 @@ public class ContentTypeLinkExtractorTests {
|
||||
public void extractionFailsWithNullContentType() throws IOException {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
new ContentTypeLinkExtractor()
|
||||
.extractLinks(this.responseFactory.create(HttpStatus.OK.value(), new HttpHeaders(), null));
|
||||
.extractLinks(this.responseFactory.create(HttpStatus.OK.value(), new HttpHeaders(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -73,7 +73,7 @@ public class LinkExtractorsPayloadTests {
|
||||
@Test
|
||||
public void multipleLinksWithDifferentRels() throws IOException {
|
||||
Map<String, List<Link>> links = this.linkExtractor
|
||||
.extractLinks(createResponse("multiple-links-different-rels"));
|
||||
.extractLinks(createResponse("multiple-links-different-rels"));
|
||||
assertLinks(Arrays.asList(new Link("alpha", "https://alpha.example.com", "Alpha"),
|
||||
new Link("bravo", "https://bravo.example.com")), links);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -42,37 +42,39 @@ public class LinksSnippetFailureTests {
|
||||
@Test
|
||||
public void undocumentedLink() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("foo", "bar")),
|
||||
Collections.<LinkDescriptor>emptyList()).document(this.operationBuilder.build()))
|
||||
.withMessage("Links with the following relations were not documented: [foo]");
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("foo", "bar")),
|
||||
Collections.<LinkDescriptor>emptyList())
|
||||
.document(this.operationBuilder.build()))
|
||||
.withMessage("Links with the following relations were not documented: [foo]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingLink() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor(),
|
||||
Arrays.asList(new LinkDescriptor("foo").description("bar")))
|
||||
.document(this.operationBuilder.build()))
|
||||
.withMessage("Links with the following relations were not found in the response: [foo]");
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor(),
|
||||
Arrays.asList(new LinkDescriptor("foo").description("bar")))
|
||||
.document(this.operationBuilder.build()))
|
||||
.withMessage("Links with the following relations were not found in the response: [foo]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedLinkAndMissingLink() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("a", "alpha")),
|
||||
Arrays.asList(new LinkDescriptor("foo").description("bar")))
|
||||
.document(this.operationBuilder.build()))
|
||||
.withMessage("Links with the following relations were not documented: [a]. Links with the following"
|
||||
+ " relations were not found in the response: [foo]");
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("a", "alpha")),
|
||||
Arrays.asList(new LinkDescriptor("foo").description("bar")))
|
||||
.document(this.operationBuilder.build()))
|
||||
.withMessage("Links with the following relations were not documented: [a]. Links with the following"
|
||||
+ " relations were not found in the response: [foo]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linkWithNoDescription() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("foo", "bar")),
|
||||
Arrays.asList(new LinkDescriptor("foo"))).document(this.operationBuilder.build()))
|
||||
.withMessage("No description was provided for the link with rel 'foo' and no title was available"
|
||||
+ " from the link in the payload");
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("foo", "bar")),
|
||||
Arrays.asList(new LinkDescriptor("foo")))
|
||||
.document(this.operationBuilder.build()))
|
||||
.withMessage("No description was provided for the link with rel 'foo' and no title was available"
|
||||
+ " from the link in the payload");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -49,7 +49,7 @@ public class LinksSnippetTests extends AbstractSnippetTests {
|
||||
public void ignoredLink() throws IOException {
|
||||
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("a", "alpha"), new Link("b", "bravo")),
|
||||
Arrays.asList(new LinkDescriptor("a").ignored(), new LinkDescriptor("b").description("Link b")))
|
||||
.document(this.operationBuilder.build());
|
||||
.document(this.operationBuilder.build());
|
||||
assertThat(this.generatedSnippets.links()).is(tableWithHeader("Relation", "Description").row("`b`", "Link b"));
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class LinksSnippetTests extends AbstractSnippetTests {
|
||||
public void allUndocumentedLinksCanBeIgnored() throws IOException {
|
||||
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("a", "alpha"), new Link("b", "bravo")),
|
||||
Arrays.asList(new LinkDescriptor("b").description("Link b")), true)
|
||||
.document(this.operationBuilder.build());
|
||||
.document(this.operationBuilder.build());
|
||||
assertThat(this.generatedSnippets.links()).is(tableWithHeader("Relation", "Description").row("`b`", "Link b"));
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class LinksSnippetTests extends AbstractSnippetTests {
|
||||
public void presentOptionalLink() throws IOException {
|
||||
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("foo", "blah")),
|
||||
Arrays.asList(new LinkDescriptor("foo").description("bar").optional()))
|
||||
.document(this.operationBuilder.build());
|
||||
.document(this.operationBuilder.build());
|
||||
assertThat(this.generatedSnippets.links()).is(tableWithHeader("Relation", "Description").row("`foo`", "bar"));
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class LinksSnippetTests extends AbstractSnippetTests {
|
||||
public void missingOptionalLink() throws IOException {
|
||||
new LinksSnippet(new StubLinkExtractor(),
|
||||
Arrays.asList(new LinkDescriptor("foo").description("bar").optional()))
|
||||
.document(this.operationBuilder.build());
|
||||
.document(this.operationBuilder.build());
|
||||
assertThat(this.generatedSnippets.links()).is(tableWithHeader("Relation", "Description").row("`foo`", "bar"));
|
||||
}
|
||||
|
||||
@@ -81,9 +81,9 @@ public class LinksSnippetTests extends AbstractSnippetTests {
|
||||
public void documentedLinks() throws IOException {
|
||||
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("a", "alpha"), new Link("b", "bravo")),
|
||||
Arrays.asList(new LinkDescriptor("a").description("one"), new LinkDescriptor("b").description("two")))
|
||||
.document(this.operationBuilder.build());
|
||||
.document(this.operationBuilder.build());
|
||||
assertThat(this.generatedSnippets.links())
|
||||
.is(tableWithHeader("Relation", "Description").row("`a`", "one").row("`b`", "two"));
|
||||
.is(tableWithHeader("Relation", "Description").row("`a`", "one").row("`b`", "two"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,9 +91,9 @@ public class LinksSnippetTests extends AbstractSnippetTests {
|
||||
new LinksSnippet(
|
||||
new StubLinkExtractor().withLinks(new Link("a", "alpha", "Link a"), new Link("b", "bravo", "Link b")),
|
||||
Arrays.asList(new LinkDescriptor("a").description("one"), new LinkDescriptor("b")))
|
||||
.document(this.operationBuilder.build());
|
||||
.document(this.operationBuilder.build());
|
||||
assertThat(this.generatedSnippets.links())
|
||||
.is(tableWithHeader("Relation", "Description").row("`a`", "one").row("`b`", "Link b"));
|
||||
.is(tableWithHeader("Relation", "Description").row("`a`", "one").row("`b`", "Link b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,9 +103,9 @@ public class LinksSnippetTests extends AbstractSnippetTests {
|
||||
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("a", "alpha"), new Link("b", "bravo")),
|
||||
Arrays.asList(new LinkDescriptor("a").description("one"), new LinkDescriptor("b").description("two")),
|
||||
attributes(key("title").value("Title for the links")))
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.build());
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.links()).contains("Title for the links");
|
||||
}
|
||||
|
||||
@@ -116,30 +116,31 @@ public class LinksSnippetTests extends AbstractSnippetTests {
|
||||
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("a", "alpha"), new Link("b", "bravo")),
|
||||
Arrays.asList(new LinkDescriptor("a").description("one").attributes(key("foo").value("alpha")),
|
||||
new LinkDescriptor("b").description("two").attributes(key("foo").value("bravo"))))
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.links()).is(
|
||||
tableWithHeader("Relation", "Description", "Foo").row("a", "one", "alpha").row("b", "two", "bravo"));
|
||||
.document(this.operationBuilder
|
||||
.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.links())
|
||||
.is(tableWithHeader("Relation", "Description", "Foo").row("a", "one", "alpha").row("b", "two", "bravo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void additionalDescriptors() throws IOException {
|
||||
HypermediaDocumentation
|
||||
.links(new StubLinkExtractor().withLinks(new Link("a", "alpha"), new Link("b", "bravo")),
|
||||
new LinkDescriptor("a").description("one"))
|
||||
.and(new LinkDescriptor("b").description("two")).document(this.operationBuilder.build());
|
||||
.links(new StubLinkExtractor().withLinks(new Link("a", "alpha"), new Link("b", "bravo")),
|
||||
new LinkDescriptor("a").description("one"))
|
||||
.and(new LinkDescriptor("b").description("two"))
|
||||
.document(this.operationBuilder.build());
|
||||
assertThat(this.generatedSnippets.links())
|
||||
.is(tableWithHeader("Relation", "Description").row("`a`", "one").row("`b`", "two"));
|
||||
.is(tableWithHeader("Relation", "Description").row("`a`", "one").row("`b`", "two"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tableCellContentIsEscapedWhenNecessary() throws IOException {
|
||||
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("Foo|Bar", "foo")),
|
||||
Arrays.asList(new LinkDescriptor("Foo|Bar").description("one|two")))
|
||||
.document(this.operationBuilder.build());
|
||||
.document(this.operationBuilder.build());
|
||||
assertThat(this.generatedSnippets.links()).is(tableWithHeader("Relation", "Description")
|
||||
.row(escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two")));
|
||||
.row(escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two")));
|
||||
}
|
||||
|
||||
private String escapeIfNecessary(String input) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -72,8 +72,8 @@ public class QueryStringParserTests {
|
||||
@Test
|
||||
public void malformedParameter() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.queryStringParser.parse(URI.create("http://localhost?a=apple=avocado")))
|
||||
.withMessage("The parameter 'a=apple=avocado' is malformed");
|
||||
.isThrownBy(() -> this.queryStringParser.parse(URI.create("http://localhost?a=apple=avocado")))
|
||||
.withMessage("The parameter 'a=apple=avocado' is malformed");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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,7 +48,8 @@ public class DelegatingOperationRequestPreprocessorTests {
|
||||
given(preprocessor3.preprocess(preprocessedRequest2)).willReturn(preprocessedRequest3);
|
||||
|
||||
OperationRequest result = new DelegatingOperationRequestPreprocessor(
|
||||
Arrays.asList(preprocessor1, preprocessor2, preprocessor3)).preprocess(originalRequest);
|
||||
Arrays.asList(preprocessor1, preprocessor2, preprocessor3))
|
||||
.preprocess(originalRequest);
|
||||
|
||||
assertThat(result).isSameAs(preprocessedRequest3);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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,7 +48,8 @@ public class DelegatingOperationResponsePreprocessorTests {
|
||||
given(preprocessor3.preprocess(preprocessedResponse2)).willReturn(preprocessedResponse3);
|
||||
|
||||
OperationResponse result = new DelegatingOperationResponsePreprocessor(
|
||||
Arrays.asList(preprocessor1, preprocessor2, preprocessor3)).preprocess(originalResponse);
|
||||
Arrays.asList(preprocessor1, preprocessor2, preprocessor3))
|
||||
.preprocess(originalResponse);
|
||||
|
||||
assertThat(result).isSameAs(preprocessedResponse3);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -49,32 +49,32 @@ public class LinkMaskingContentModifierTests {
|
||||
@Test
|
||||
public void halLinksAreMasked() throws Exception {
|
||||
assertThat(this.contentModifier.modifyContent(halPayloadWithLinks(this.links), null))
|
||||
.isEqualTo(halPayloadWithLinks(this.maskedLinks));
|
||||
.isEqualTo(halPayloadWithLinks(this.maskedLinks));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formattedHalLinksAreMasked() throws Exception {
|
||||
assertThat(this.contentModifier.modifyContent(formattedHalPayloadWithLinks(this.links), null))
|
||||
.isEqualTo(formattedHalPayloadWithLinks(this.maskedLinks));
|
||||
.isEqualTo(formattedHalPayloadWithLinks(this.maskedLinks));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atomLinksAreMasked() throws Exception {
|
||||
assertThat(this.contentModifier.modifyContent(atomPayloadWithLinks(this.links), null))
|
||||
.isEqualTo(atomPayloadWithLinks(this.maskedLinks));
|
||||
.isEqualTo(atomPayloadWithLinks(this.maskedLinks));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formattedAtomLinksAreMasked() throws Exception {
|
||||
assertThat(this.contentModifier.modifyContent(formattedAtomPayloadWithLinks(this.links), null))
|
||||
.isEqualTo(formattedAtomPayloadWithLinks(this.maskedLinks));
|
||||
.isEqualTo(formattedAtomPayloadWithLinks(this.maskedLinks));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void maskCanBeCustomized() throws Exception {
|
||||
assertThat(
|
||||
new LinkMaskingContentModifier("custom").modifyContent(formattedAtomPayloadWithLinks(this.links), null))
|
||||
.isEqualTo(formattedAtomPayloadWithLinks(new Link("a", "custom"), new Link("b", "custom")));
|
||||
.isEqualTo(formattedAtomPayloadWithLinks(new Link("a", "custom"), new Link("b", "custom")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +82,7 @@ public class LinkMaskingContentModifierTests {
|
||||
String ellipsis = "\u2026";
|
||||
assertThat(
|
||||
new LinkMaskingContentModifier(ellipsis).modifyContent(formattedHalPayloadWithLinks(this.links), null))
|
||||
.isEqualTo(formattedHalPayloadWithLinks(new Link("a", ellipsis), new Link("b", ellipsis)));
|
||||
.isEqualTo(formattedHalPayloadWithLinks(new Link("a", ellipsis), new Link("b", ellipsis)));
|
||||
}
|
||||
|
||||
private byte[] atomPayloadWithLinks(Link... links) throws JsonProcessingException {
|
||||
@@ -91,7 +91,7 @@ public class LinkMaskingContentModifierTests {
|
||||
|
||||
private byte[] formattedAtomPayloadWithLinks(Link... links) throws JsonProcessingException {
|
||||
return new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true)
|
||||
.writeValueAsBytes(createAtomPayload(links));
|
||||
.writeValueAsBytes(createAtomPayload(links));
|
||||
}
|
||||
|
||||
private AtomPayload createAtomPayload(Link... links) {
|
||||
@@ -106,7 +106,7 @@ public class LinkMaskingContentModifierTests {
|
||||
|
||||
private byte[] formattedHalPayloadWithLinks(Link... links) throws JsonProcessingException {
|
||||
return new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true)
|
||||
.writeValueAsBytes(createHalPayload(links));
|
||||
.writeValueAsBytes(createHalPayload(links));
|
||||
}
|
||||
|
||||
private HalPayload createHalPayload(Link... links) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2020 the original author or authors.
|
||||
* Copyright 2014-2023 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,7 +61,7 @@ public class ParametersModifyingOperationPreprocessorTests {
|
||||
public void setNewParameter() {
|
||||
Parameters parameters = new Parameters();
|
||||
OperationRequest request = this.preprocessor.set("a", "alpha", "avocado")
|
||||
.preprocess(createGetRequest(parameters));
|
||||
.preprocess(createGetRequest(parameters));
|
||||
assertThat(request.getParameters()).containsEntry("a", Arrays.asList("alpha", "avocado"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost:8080?a=alpha&a=avocado"));
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class ParametersModifyingOperationPreprocessorTests {
|
||||
Parameters parameters = new Parameters();
|
||||
parameters.add("a", "apple");
|
||||
OperationRequest request = this.preprocessor.set("a", "alpha", "avocado")
|
||||
.preprocess(createGetRequest(parameters));
|
||||
.preprocess(createGetRequest(parameters));
|
||||
assertThat(request.getParameters()).containsEntry("a", Arrays.asList("alpha", "avocado"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost:8080?a=alpha&a=avocado"));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -40,7 +40,7 @@ public class PatternReplacingContentModifierTests {
|
||||
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(pattern, "<<uuid>>");
|
||||
assertThat(
|
||||
contentModifier.modifyContent("{\"id\" : \"CA761232-ED42-11CE-BACD-00AA0057B223\"}".getBytes(), null))
|
||||
.isEqualTo("{\"id\" : \"<<uuid>>\"}".getBytes());
|
||||
.isEqualTo("{\"id\" : \"<<uuid>>\"}".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -49,7 +49,7 @@ public class PatternReplacingContentModifierTests {
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(pattern, "<<uuid>>");
|
||||
assertThat(contentModifier.modifyContent("{\"id\" : \"CA76-ED42-11CE-BACD\"}".getBytes(), null))
|
||||
.isEqualTo("{\"id\" : \"CA76-ED42-11CE-BACD\"}".getBytes());
|
||||
.isEqualTo("{\"id\" : \"CA76-ED42-11CE-BACD\"}".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,7 +59,7 @@ public class PatternReplacingContentModifierTests {
|
||||
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(pattern, "<<number>>");
|
||||
assertThat(contentModifier.modifyContent((japaneseContent + " 123").getBytes(),
|
||||
new MediaType("text", "plain", Charset.forName("UTF-8"))))
|
||||
.isEqualTo((japaneseContent + " <<number>>").getBytes());
|
||||
.isEqualTo((japaneseContent + " <<number>>").getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,7 +69,7 @@ public class PatternReplacingContentModifierTests {
|
||||
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(pattern, "<<number>>",
|
||||
StandardCharsets.UTF_8);
|
||||
assertThat(contentModifier.modifyContent((japaneseContent + " 123").getBytes(), new MediaType("text", "plain")))
|
||||
.isEqualTo((japaneseContent + " <<number>>").getBytes());
|
||||
.isEqualTo((japaneseContent + " <<number>>").getBytes());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -41,15 +41,17 @@ public class PrettyPrintingContentModifierTests {
|
||||
@Test
|
||||
public void prettyPrintJson() {
|
||||
assertThat(new PrettyPrintingContentModifier().modifyContent("{\"a\":5}".getBytes(), null))
|
||||
.isEqualTo(String.format("{%n \"a\" : 5%n}").getBytes());
|
||||
.isEqualTo(String.format("{%n \"a\" : 5%n}").getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prettyPrintXml() {
|
||||
assertThat(new PrettyPrintingContentModifier()
|
||||
.modifyContent("<one a=\"alpha\"><two b=\"bravo\"/></one>".getBytes(), null))
|
||||
.isEqualTo(String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n"
|
||||
+ "<one a=\"alpha\">%n <two b=\"bravo\"/>%n</one>%n").getBytes());
|
||||
.modifyContent("<one a=\"alpha\"><two b=\"bravo\"/></one>".getBytes(), null))
|
||||
.isEqualTo(String
|
||||
.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n"
|
||||
+ "<one a=\"alpha\">%n <two b=\"bravo\"/>%n</one>%n")
|
||||
.getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,7 +63,7 @@ public class PrettyPrintingContentModifierTests {
|
||||
public void nonJsonAndNonXmlContentIsHandledGracefully() {
|
||||
String content = "abcdefg";
|
||||
assertThat(new PrettyPrintingContentModifier().modifyContent(content.getBytes(), null))
|
||||
.isEqualTo(content.getBytes());
|
||||
.isEqualTo(content.getBytes());
|
||||
assertThat(this.outputCapture).isEmpty();
|
||||
}
|
||||
|
||||
@@ -69,7 +71,7 @@ public class PrettyPrintingContentModifierTests {
|
||||
public void nonJsonContentThatInitiallyLooksLikeJsonIsHandledGracefully() {
|
||||
String content = "\"abc\",\"def\"";
|
||||
assertThat(new PrettyPrintingContentModifier().modifyContent(content.getBytes(), null))
|
||||
.isEqualTo(content.getBytes());
|
||||
.isEqualTo(content.getBytes());
|
||||
assertThat(this.outputCapture).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -69,7 +69,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestUriPortCanBeModified() {
|
||||
this.preprocessor.port(23456);
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345"));
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com:23456"));
|
||||
assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST)).isEqualTo("api.example.com:23456");
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestUriPortCanBeRemoved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345"));
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com"));
|
||||
assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST)).isEqualTo("api.example.com");
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestUriPathIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345/foo/bar"));
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345/foo/bar"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com/foo/bar"));
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestUriQueryIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345?foo=bar"));
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345?foo=bar"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com?foo=bar"));
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestUriAnchorIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345#foo"));
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345#foo"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com#foo"));
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
OperationRequest processed = this.preprocessor.preprocess(createRequestWithContent(
|
||||
"The uri 'https://localhost:12345' should be used. foo:bar will be unaffected"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'https://localhost:12345' should be used. foo:bar will be unaffected");
|
||||
.isEqualTo("The uri 'https://localhost:12345' should be used. foo:bar will be unaffected");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,7 +122,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
OperationRequest processed = this.preprocessor.preprocess(createRequestWithContent(
|
||||
"The uri 'https://localhost:12345' should be used. foo:bar will be unaffected"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used. foo:bar will be unaffected");
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used. foo:bar will be unaffected");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,7 +131,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
OperationRequest processed = this.preprocessor.preprocess(
|
||||
createRequestWithContent("The uri 'https://localhost' should be used. foo:bar will be unaffected"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'https://api.example.com' should be used. foo:bar will be unaffected");
|
||||
.isEqualTo("The uri 'https://api.example.com' should be used. foo:bar will be unaffected");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,7 +140,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
OperationRequest processed = this.preprocessor.preprocess(
|
||||
createRequestWithContent("The uri 'http://localhost' should be used. foo:bar will be unaffected"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'http://localhost:23456' should be used. foo:bar will be unaffected");
|
||||
.isEqualTo("The uri 'http://localhost:23456' should be used. foo:bar will be unaffected");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,7 +149,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
OperationRequest processed = this.preprocessor.preprocess(createRequestWithContent(
|
||||
"The uri 'http://localhost:12345' should be used. foo:bar will be unaffected"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'http://localhost:23456' should be used. foo:bar will be unaffected");
|
||||
.isEqualTo("The uri 'http://localhost:23456' should be used. foo:bar will be unaffected");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,7 +158,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
OperationRequest processed = this.preprocessor.preprocess(createRequestWithContent(
|
||||
"The uri 'http://localhost:12345' should be used. foo:bar will be unaffected"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'http://localhost' should be used. foo:bar will be unaffected");
|
||||
.isEqualTo("The uri 'http://localhost' should be used. foo:bar will be unaffected");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -167,14 +167,14 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
OperationRequest processed = this.preprocessor.preprocess(createRequestWithContent(
|
||||
"Use 'http://localhost:12345' or 'https://localhost:23456' to access the service"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("Use 'http://localhost' or 'https://localhost' to access the service");
|
||||
.isEqualTo("Use 'http://localhost' or 'https://localhost' to access the service");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestContentUriPathIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345/foo/bar' should be used"));
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345/foo/bar' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost/foo/bar' should be used");
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestContentUriQueryIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345?foo=bar' should be used"));
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345?foo=bar' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost?foo=bar' should be used");
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestContentUriAnchorIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345#foo' should be used"));
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345#foo' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost#foo' should be used");
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void responseContentUriSchemeCanBeModified() {
|
||||
this.preprocessor.scheme("https");
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'https://localhost:12345' should be used");
|
||||
}
|
||||
|
||||
@@ -206,16 +206,16 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void responseContentUriHostCanBeModified() {
|
||||
this.preprocessor.host("api.example.com");
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'https://localhost:12345' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'https://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used");
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseContentUriPortCanBeModified() {
|
||||
this.preprocessor.port(23456);
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost:23456' should be used");
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void responseContentUriPortCanBeRemoved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost' should be used");
|
||||
}
|
||||
|
||||
@@ -233,14 +233,14 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
OperationResponse processed = this.preprocessor.preprocess(createResponseWithContent(
|
||||
"Use 'http://localhost:12345' or 'https://localhost:23456' to access the service"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("Use 'http://localhost' or 'https://localhost' to access the service");
|
||||
.isEqualTo("Use 'http://localhost' or 'https://localhost' to access the service");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseContentUriPathIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345/foo/bar' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345/foo/bar' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost/foo/bar' should be used");
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void responseContentUriQueryIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345?foo=bar' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345?foo=bar' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost?foo=bar' should be used");
|
||||
}
|
||||
|
||||
@@ -256,14 +256,14 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void responseContentUriAnchorIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345#foo' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345#foo' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost#foo' should be used");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urisInRequestHeadersCanBeModified() {
|
||||
OperationRequest processed = this.preprocessor.host("api.example.com")
|
||||
.preprocess(createRequestWithHeader("Foo", "https://locahost:12345"));
|
||||
.preprocess(createRequestWithHeader("Foo", "https://locahost:12345"));
|
||||
assertThat(processed.getHeaders().getFirst("Foo")).isEqualTo("https://api.example.com:12345");
|
||||
assertThat(processed.getHeaders().getFirst("Host")).isEqualTo("api.example.com");
|
||||
}
|
||||
@@ -271,31 +271,31 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
@Test
|
||||
public void urisInResponseHeadersCanBeModified() {
|
||||
OperationResponse processed = this.preprocessor.host("api.example.com")
|
||||
.preprocess(createResponseWithHeader("Foo", "https://locahost:12345"));
|
||||
.preprocess(createResponseWithHeader("Foo", "https://locahost:12345"));
|
||||
assertThat(processed.getHeaders().getFirst("Foo")).isEqualTo("https://api.example.com:12345");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urisInRequestPartHeadersCanBeModified() {
|
||||
OperationRequest processed = this.preprocessor.host("api.example.com")
|
||||
.preprocess(createRequestWithPartWithHeader("Foo", "https://locahost:12345"));
|
||||
.preprocess(createRequestWithPartWithHeader("Foo", "https://locahost:12345"));
|
||||
assertThat(processed.getParts().iterator().next().getHeaders().getFirst("Foo"))
|
||||
.isEqualTo("https://api.example.com:12345");
|
||||
.isEqualTo("https://api.example.com:12345");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urisInRequestPartContentCanBeModified() {
|
||||
OperationRequest processed = this.preprocessor.host("api.example.com")
|
||||
.preprocess(createRequestWithPartWithContent("The uri 'https://localhost:12345' should be used"));
|
||||
.preprocess(createRequestWithPartWithContent("The uri 'https://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getParts().iterator().next().getContent()))
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used");
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifiedUriDoesNotGetDoubleEncoded() {
|
||||
this.preprocessor.scheme("https");
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("http://localhost:12345?foo=%7B%7D"));
|
||||
.preprocess(createRequestWithUri("http://localhost:12345?foo=%7B%7D"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://localhost:12345?foo=%7B%7D"));
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -53,14 +53,17 @@ public class AsciidoctorRequestFieldsSnippetTests {
|
||||
public void requestFieldsWithListDescription() throws IOException {
|
||||
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
|
||||
given(resolver.resolveTemplateResource("request-fields"))
|
||||
.willReturn(snippetResource("request-fields-with-list-description"));
|
||||
.willReturn(snippetResource("request-fields-with-list-description"));
|
||||
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").description(Arrays.asList("one", "two")))).document(
|
||||
this.operationBuilder.attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver))
|
||||
.request("http://localhost").content("{\"a\": \"foo\"}").build());
|
||||
.request("http://localhost")
|
||||
.content("{\"a\": \"foo\"}")
|
||||
.build());
|
||||
assertThat(this.generatedSnippets.requestFields())
|
||||
.is(SnippetConditions.tableWithHeader(TemplateFormats.asciidoctor(), "Path", "Type", "Description")
|
||||
//
|
||||
.row("a", "String", String.format(" - one%n - two")).configuration("[cols=\"1,1,1a\"]"));
|
||||
.is(SnippetConditions.tableWithHeader(TemplateFormats.asciidoctor(), "Path", "Type", "Description")
|
||||
//
|
||||
.row("a", "String", String.format(" - one%n - two"))
|
||||
.configuration("[cols=\"1,1,1a\"]"));
|
||||
}
|
||||
|
||||
private FileSystemResource snippetResource(String name) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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,7 +48,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void extractMapSubsectionOfJsonMap() throws JsonParseException, JsonMappingException, IOException {
|
||||
byte[] extractedPayload = new FieldPathPayloadSubsectionExtractor("a.b")
|
||||
.extractSubsection("{\"a\":{\"b\":{\"c\":5}}}".getBytes(), MediaType.APPLICATION_JSON);
|
||||
.extractSubsection("{\"a\":{\"b\":{\"c\":5}}}".getBytes(), MediaType.APPLICATION_JSON);
|
||||
Map<String, Object> extracted = new ObjectMapper().readValue(extractedPayload, Map.class);
|
||||
assertThat(extracted.size()).isEqualTo(1);
|
||||
assertThat(extracted.get("c")).isEqualTo(5);
|
||||
@@ -59,7 +59,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
public void extractSingleElementArraySubsectionOfJsonMap()
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
byte[] extractedPayload = new FieldPathPayloadSubsectionExtractor("a.[]")
|
||||
.extractSubsection("{\"a\":[{\"b\":5}]}".getBytes(), MediaType.APPLICATION_JSON);
|
||||
.extractSubsection("{\"a\":[{\"b\":5}]}".getBytes(), MediaType.APPLICATION_JSON);
|
||||
Map<String, Object> extracted = new ObjectMapper().readValue(extractedPayload, Map.class);
|
||||
assertThat(extracted.size()).isEqualTo(1);
|
||||
assertThat(extracted).containsOnlyKeys("b");
|
||||
@@ -70,7 +70,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
public void extractMultiElementArraySubsectionOfJsonMap()
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
byte[] extractedPayload = new FieldPathPayloadSubsectionExtractor("a")
|
||||
.extractSubsection("{\"a\":[{\"b\":5},{\"b\":4}]}".getBytes(), MediaType.APPLICATION_JSON);
|
||||
.extractSubsection("{\"a\":[{\"b\":5},{\"b\":4}]}".getBytes(), MediaType.APPLICATION_JSON);
|
||||
Map<String, Object> extracted = new ObjectMapper().readValue(extractedPayload, Map.class);
|
||||
assertThat(extracted.size()).isEqualTo(1);
|
||||
assertThat(extracted).containsOnlyKeys("b");
|
||||
@@ -81,7 +81,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
public void extractMapSubsectionFromSingleElementArrayInAJsonMap()
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
byte[] extractedPayload = new FieldPathPayloadSubsectionExtractor("a.[].b")
|
||||
.extractSubsection("{\"a\":[{\"b\":{\"c\":5}}]}".getBytes(), MediaType.APPLICATION_JSON);
|
||||
.extractSubsection("{\"a\":[{\"b\":{\"c\":5}}]}".getBytes(), MediaType.APPLICATION_JSON);
|
||||
Map<String, Object> extracted = new ObjectMapper().readValue(extractedPayload, Map.class);
|
||||
assertThat(extracted.size()).isEqualTo(1);
|
||||
assertThat(extracted.get("c")).isEqualTo(5);
|
||||
@@ -91,8 +91,8 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void extractMapSubsectionWithCommonStructureFromMultiElementArrayInAJsonMap()
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
byte[] extractedPayload = new FieldPathPayloadSubsectionExtractor("a.[].b").extractSubsection(
|
||||
"{\"a\":[{\"b\":{\"c\":5}},{\"b\":{\"c\":6}}]}".getBytes(), MediaType.APPLICATION_JSON);
|
||||
byte[] extractedPayload = new FieldPathPayloadSubsectionExtractor("a.[].b")
|
||||
.extractSubsection("{\"a\":[{\"b\":{\"c\":5}},{\"b\":{\"c\":6}}]}".getBytes(), MediaType.APPLICATION_JSON);
|
||||
Map<String, Object> extracted = new ObjectMapper().readValue(extractedPayload, Map.class);
|
||||
assertThat(extracted.size()).isEqualTo(1);
|
||||
assertThat(extracted).containsOnlyKeys("c");
|
||||
@@ -152,11 +152,11 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
throws JsonParseException, JsonMappingException, JsonProcessingException, IOException {
|
||||
ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
|
||||
byte[] prettyPrintedPayload = objectMapper
|
||||
.writeValueAsBytes(objectMapper.readValue("{\"a\": { \"b\": { \"c\": 1 }}}", Object.class));
|
||||
.writeValueAsBytes(objectMapper.readValue("{\"a\": { \"b\": { \"c\": 1 }}}", Object.class));
|
||||
byte[] extractedSubsection = new FieldPathPayloadSubsectionExtractor("a.b")
|
||||
.extractSubsection(prettyPrintedPayload, MediaType.APPLICATION_JSON);
|
||||
.extractSubsection(prettyPrintedPayload, MediaType.APPLICATION_JSON);
|
||||
byte[] prettyPrintedSubsection = objectMapper
|
||||
.writeValueAsBytes(objectMapper.readValue("{\"c\": 1 }", Object.class));
|
||||
.writeValueAsBytes(objectMapper.readValue("{\"c\": 1 }", Object.class));
|
||||
assertThat(new String(extractedSubsection)).isEqualTo(new String(prettyPrintedSubsection));
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
throws JsonParseException, JsonMappingException, JsonProcessingException, IOException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
byte[] payload = objectMapper
|
||||
.writeValueAsBytes(objectMapper.readValue("{\"a\": { \"b\": { \"c\": 1 }}}", Object.class));
|
||||
.writeValueAsBytes(objectMapper.readValue("{\"a\": { \"b\": { \"c\": 1 }}}", Object.class));
|
||||
byte[] extractedSubsection = new FieldPathPayloadSubsectionExtractor("a.b").extractSubsection(payload,
|
||||
MediaType.APPLICATION_JSON);
|
||||
byte[] subsection = objectMapper.writeValueAsBytes(objectMapper.readValue("{\"c\": 1 }", Object.class));
|
||||
@@ -175,17 +175,17 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
@Test
|
||||
public void extractNonExistentSubsection() {
|
||||
assertThatThrownBy(() -> new FieldPathPayloadSubsectionExtractor("a.c")
|
||||
.extractSubsection("{\"a\":{\"b\":{\"c\":5}}}".getBytes(), MediaType.APPLICATION_JSON))
|
||||
.isInstanceOf(PayloadHandlingException.class)
|
||||
.hasMessage("a.c does not identify a section of the payload");
|
||||
.extractSubsection("{\"a\":{\"b\":{\"c\":5}}}".getBytes(), MediaType.APPLICATION_JSON))
|
||||
.isInstanceOf(PayloadHandlingException.class)
|
||||
.hasMessage("a.c does not identify a section of the payload");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractEmptyArraySubsection() {
|
||||
assertThatThrownBy(() -> new FieldPathPayloadSubsectionExtractor("a")
|
||||
.extractSubsection("{\"a\":[]}}".getBytes(), MediaType.APPLICATION_JSON))
|
||||
.isInstanceOf(PayloadHandlingException.class)
|
||||
.hasMessage("a identifies an empty section of the payload");
|
||||
.extractSubsection("{\"a\":[]}}".getBytes(), MediaType.APPLICATION_JSON))
|
||||
.isInstanceOf(PayloadHandlingException.class)
|
||||
.hasMessage("a identifies an empty section of the payload");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -40,14 +40,14 @@ public class FieldTypeResolverTests {
|
||||
@Deprecated
|
||||
public void whenForContentCalledWithJsonContentThenReturnsJsonFieldTypeResolver() {
|
||||
assertThat(FieldTypeResolver.forContent("{\"field\": \"value\"}".getBytes(), MediaType.APPLICATION_JSON))
|
||||
.isInstanceOf(JsonContentHandler.class);
|
||||
.isInstanceOf(JsonContentHandler.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void whenForContentCalledWithXmlContentThenReturnsXmlContentHandler() {
|
||||
assertThat(FieldTypeResolver.forContent("<a><b>5</b></a>".getBytes(), MediaType.APPLICATION_XML))
|
||||
.isInstanceOf(XmlContentHandler.class);
|
||||
.isInstanceOf(XmlContentHandler.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,13 +60,15 @@ public class FieldTypeResolverTests {
|
||||
@Test
|
||||
public void whenForContentWithDescriptorsCalledWithJsonContentThenReturnsJsonFieldTypeResolver() {
|
||||
assertThat(FieldTypeResolver.forContentWithDescriptors("{\"field\": \"value\"}".getBytes(),
|
||||
MediaType.APPLICATION_JSON, Collections.emptyList())).isInstanceOf(JsonContentHandler.class);
|
||||
MediaType.APPLICATION_JSON, Collections.emptyList()))
|
||||
.isInstanceOf(JsonContentHandler.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenForContentWithDescriptorsCalledWithXmlContentThenReturnsXmlContentHandler() {
|
||||
assertThat(FieldTypeResolver.forContentWithDescriptors("<a><b>5</b></a>".getBytes(), MediaType.APPLICATION_XML,
|
||||
Collections.emptyList())).isInstanceOf(XmlContentHandler.class);
|
||||
Collections.emptyList()))
|
||||
.isInstanceOf(XmlContentHandler.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user