Upgrade to Spring Java Format 0.0.38
Closes gh-890
This commit is contained in:
@@ -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[]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user