Upgrade to Gradle 6.8 and modernize the build
Closes gh-719
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -22,12 +22,16 @@ import org.springframework.restdocs.hypermedia.LinksSnippet;
|
||||
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
|
||||
|
||||
public class Hypermedia {
|
||||
public final class Hypermedia {
|
||||
|
||||
private Hypermedia() {
|
||||
|
||||
}
|
||||
|
||||
// tag::ignore-links[]
|
||||
public static LinksSnippet links(LinkDescriptor... descriptors) {
|
||||
return HypermediaDocumentation.links(linkWithRel("self").ignored().optional(),
|
||||
linkWithRel("curies").ignored()).and(descriptors);
|
||||
return HypermediaDocumentation.links(linkWithRel("self").ignored().optional(), linkWithRel("curies").ignored())
|
||||
.and(descriptors);
|
||||
}
|
||||
// end::ignore-links[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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,8 +27,7 @@ public class Payload {
|
||||
@SuppressWarnings("unused")
|
||||
public void bookFieldDescriptors() {
|
||||
// tag::book-descriptors[]
|
||||
FieldDescriptor[] book = new FieldDescriptor[] {
|
||||
fieldWithPath("title").description("Title of the book"),
|
||||
FieldDescriptor[] book = new FieldDescriptor[] { fieldWithPath("title").description("Title of the book"),
|
||||
fieldWithPath("author").description("Author of the book") };
|
||||
// end::book-descriptors[]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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,6 +29,7 @@ public class SnippetReuse {
|
||||
linkWithRel("last").optional().description("The last page of results"),
|
||||
linkWithRel("next").optional().description("The next page of results"),
|
||||
linkWithRel("prev").optional().description("The previous page of results"));
|
||||
|
||||
// end::field[]
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,7 @@ public class CustomDefaultOperationPreprocessors {
|
||||
public void setup() {
|
||||
// tag::custom-default-operation-preprocessors[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation)
|
||||
.operationPreprocessors()
|
||||
.apply(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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,7 @@ public class CustomDefaultSnippets {
|
||||
public void setUp() {
|
||||
// tag::custom-default-snippets[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation).snippets()
|
||||
.withDefaults(curlRequest()))
|
||||
.apply(documentationConfiguration(this.restDocumentation).snippets().withDefaults(curlRequest()))
|
||||
.build();
|
||||
// end::custom-default-snippets[]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -18,6 +18,7 @@ package com.example.mockmvc;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.restdocs.JUnitRestDocumentation;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
@@ -41,8 +42,7 @@ public class CustomEncoding {
|
||||
public void setUp() {
|
||||
// tag::custom-encoding[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation)
|
||||
.snippets().withEncoding("ISO-8859-1"))
|
||||
.apply(documentationConfiguration(this.restDocumentation).snippets().withEncoding("ISO-8859-1"))
|
||||
.build();
|
||||
// end::custom-encoding[]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -18,6 +18,7 @@ package com.example.mockmvc;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.restdocs.JUnitRestDocumentation;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
@@ -42,8 +43,8 @@ public class CustomFormat {
|
||||
public void setUp() {
|
||||
// tag::custom-format[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation)
|
||||
.snippets().withTemplateFormat(TemplateFormats.markdown()))
|
||||
.apply(documentationConfiguration(this.restDocumentation).snippets()
|
||||
.withTemplateFormat(TemplateFormats.markdown()))
|
||||
.build();
|
||||
// end::custom-format[]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -18,6 +18,7 @@ package com.example.mockmvc;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.restdocs.JUnitRestDocumentation;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
@@ -41,10 +42,8 @@ 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))
|
||||
.apply(documentationConfiguration(this.restDocumentation).uris().withScheme("https")
|
||||
.withHost("example.com").withPort(443))
|
||||
.build();
|
||||
// end::custom-uri-configuration[]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -18,6 +18,7 @@ package com.example.mockmvc;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
||||
import org.springframework.restdocs.JUnitRestDocumentation;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
@@ -45,20 +46,17 @@ 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-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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,8 +35,7 @@ public class ExampleApplicationJUnit5Tests {
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(WebApplicationContext webApplicationContext,
|
||||
RestDocumentationContextProvider restDocumentation) {
|
||||
public void setUp(WebApplicationContext webApplicationContext, RestDocumentationContextProvider restDocumentation) {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
|
||||
.apply(documentationConfiguration(restDocumentation)) // <1>
|
||||
.build();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -18,31 +18,32 @@ package com.example.mockmvc;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.restdocs.ManualRestDocumentation;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
|
||||
|
||||
public class ExampleApplicationTestNgTests {
|
||||
|
||||
public final ManualRestDocumentation restDocumentation = new ManualRestDocumentation();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
// tag::setup[]
|
||||
private MockMvc mockMvc;
|
||||
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext context;
|
||||
|
||||
@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-2021 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,20 +31,17 @@ 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"))));
|
||||
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"))));
|
||||
// end::headers[]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -16,39 +16,36 @@
|
||||
|
||||
package com.example.mockmvc;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links;
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.halLinks;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.halLinks;
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
public class Hypermedia {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
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"))));
|
||||
// end::explicit-extractor[]
|
||||
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-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package com.example.mockmvc;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
public class InvokeService {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
@@ -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-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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,11 +32,10 @@ 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-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -18,6 +18,7 @@ package com.example.mockmvc;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
||||
import org.springframework.restdocs.JUnitRestDocumentation;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
@@ -40,8 +41,8 @@ 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-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
package com.example.mockmvc;
|
||||
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
public class PathParameters {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
@@ -31,11 +31,10 @@ 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-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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,91 +40,69 @@ 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>
|
||||
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())
|
||||
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"))));
|
||||
.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())
|
||||
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>
|
||||
.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>
|
||||
.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>
|
||||
.attributes(key("constraints").value("Must be a valid email address"))))); // <3>
|
||||
// end::constraints[]
|
||||
}
|
||||
|
||||
public void descriptorReuse() throws Exception {
|
||||
FieldDescriptor[] book = new FieldDescriptor[] {
|
||||
fieldWithPath("title").description("Title of the book"),
|
||||
FieldDescriptor[] book = new FieldDescriptor[] { fieldWithPath("title").description("Title of the book"),
|
||||
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-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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,8 +33,8 @@ 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>
|
||||
.andDo(document("index", preprocessRequest(removeHeaders("Foo")), // <1>
|
||||
preprocessResponse(prettyPrint()))); // <2>
|
||||
// end::preprocessing[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.example.mockmvc;
|
||||
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
|
||||
@@ -23,8 +25,6 @@ import static org.springframework.restdocs.request.RequestDocumentation.paramete
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
public class RequestParameters {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
@@ -32,21 +32,18 @@ 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-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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,30 +33,24 @@ public class RequestPartPayload {
|
||||
|
||||
public void fields() throws Exception {
|
||||
// tag::fields[]
|
||||
MockMultipartFile image = new MockMultipartFile("image", "image.png", "image/png",
|
||||
"<<png data>>".getBytes());
|
||||
MockMultipartFile metadata = new MockMultipartFile("metadata", "",
|
||||
"application/json", "{ \"version\": \"1.0\"}".getBytes());
|
||||
MockMultipartFile image = new MockMultipartFile("image", "image.png", "image/png", "<<png data>>".getBytes());
|
||||
MockMultipartFile metadata = new MockMultipartFile("metadata", "", "application/json",
|
||||
"{ \"version\": \"1.0\"}".getBytes());
|
||||
|
||||
this.mockMvc.perform(fileUpload("/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>
|
||||
this.mockMvc.perform(fileUpload("/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>
|
||||
// end::fields[]
|
||||
}
|
||||
|
||||
public void body() throws Exception {
|
||||
// tag::body[]
|
||||
MockMultipartFile image = new MockMultipartFile("image", "image.png", "image/png",
|
||||
"<<png data>>".getBytes());
|
||||
MockMultipartFile metadata = new MockMultipartFile("metadata", "",
|
||||
"application/json", "{ \"version\": \"1.0\"}".getBytes());
|
||||
MockMultipartFile image = new MockMultipartFile("image", "image.png", "image/png", "<<png data>>".getBytes());
|
||||
MockMultipartFile metadata = new MockMultipartFile("metadata", "", "application/json",
|
||||
"{ \"version\": \"1.0\"}".getBytes());
|
||||
|
||||
this.mockMvc.perform(fileUpload("/images").file(image).file(metadata)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("image-upload", requestPartBody("metadata"))); // <1>
|
||||
this.mockMvc.perform(fileUpload("/images").file(image).file(metadata).accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk()).andDo(document("image-upload", requestPartBody("metadata"))); // <1>
|
||||
// end::body[]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2021 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,9 @@ 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-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,7 @@ public class CustomDefaultSnippets {
|
||||
public void setUp() {
|
||||
// tag::custom-default-snippets[]
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).snippets()
|
||||
.withDefaults(curlRequest()))
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).snippets().withDefaults(curlRequest()))
|
||||
.build();
|
||||
// end::custom-default-snippets[]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,7 @@ public class CustomEncoding {
|
||||
public void setUp() {
|
||||
// tag::custom-encoding[]
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation)
|
||||
.snippets().withEncoding("ISO-8859-1"))
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).snippets().withEncoding("ISO-8859-1"))
|
||||
.build();
|
||||
// end::custom-encoding[]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,10 +37,8 @@ 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-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,20 +43,18 @@ 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() throws Exception {
|
||||
// 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-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,9 @@ public class ExampleApplicationJUnit5Tests {
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(RestDocumentationContextProvider restDocumentation) {
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(restDocumentation)) // <1>
|
||||
this.spec = new RequestSpecBuilder().addFilter(documentationConfiguration(restDocumentation)) // <1>
|
||||
.build();
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,9 +37,7 @@ public class ExampleApplicationTestNgTests {
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp(Method method) {
|
||||
this.spec = new RequestSpecBuilder().addFilter(
|
||||
documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
this.spec = new RequestSpecBuilder().addFilter(documentationConfiguration(this.restDocumentation)).build();
|
||||
this.restDocumentation.beforeTest(getClass(), method.getName());
|
||||
}
|
||||
|
||||
@@ -51,4 +49,5 @@ public class ExampleApplicationTestNgTests {
|
||||
this.restDocumentation.afterTest();
|
||||
}
|
||||
// end::teardown[]
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,9 +36,9 @@ public class ExampleApplicationTests {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.spec = new RequestSpecBuilder().addFilter(
|
||||
documentationConfiguration(this.restDocumentation)) // <1>
|
||||
this.spec = new RequestSpecBuilder().addFilter(documentationConfiguration(this.restDocumentation)) // <1>
|
||||
.build();
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,18 @@ public class HttpHeaders {
|
||||
|
||||
public void headers() throws Exception {
|
||||
// tag::headers[]
|
||||
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").description(
|
||||
"Remaining requests permitted in current period"),
|
||||
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));
|
||||
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")
|
||||
.description("Remaining requests permitted in current period"),
|
||||
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));
|
||||
// end::headers[]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,24 +31,21 @@ public class Hypermedia {
|
||||
|
||||
public void defaultExtractor() throws Exception {
|
||||
// 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() throws Exception {
|
||||
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-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,4 +35,5 @@ public class InvokeService {
|
||||
.then().assertThat().statusCode(is(200)); // <5>
|
||||
// end::invoke-service[]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,7 @@ public class ParameterizedOutput {
|
||||
// tag::parameterized-output[]
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation))
|
||||
this.spec = new RequestSpecBuilder().addFilter(documentationConfiguration(this.restDocumentation))
|
||||
.addFilter(document("{method-name}/{step}")).build();
|
||||
}
|
||||
// end::parameterized-output[]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,12 +30,12 @@ public class PathParameters {
|
||||
|
||||
public void pathParametersSnippet() throws Exception {
|
||||
// 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-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,92 +39,76 @@ public class Payload {
|
||||
|
||||
public void response() throws Exception {
|
||||
// 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() throws Exception {
|
||||
// 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));
|
||||
.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() throws Exception {
|
||||
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));
|
||||
// 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() throws Exception {
|
||||
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));
|
||||
// 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() throws Exception {
|
||||
FieldDescriptor[] book = new FieldDescriptor[] {
|
||||
fieldWithPath("title").description("Title of the book"),
|
||||
FieldDescriptor[] book = new FieldDescriptor[] { fieldWithPath("title").description("Title of the book"),
|
||||
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));
|
||||
.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() throws Exception {
|
||||
// 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));
|
||||
.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() throws Exception {
|
||||
// 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));
|
||||
.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-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,11 +32,9 @@ public class PerTestPreprocessing {
|
||||
|
||||
public void general() throws Exception {
|
||||
// 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-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,23 +30,22 @@ public class RequestParameters {
|
||||
|
||||
public void getQueryStringSnippet() throws Exception {
|
||||
// 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() throws Exception {
|
||||
// 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-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,11 +38,10 @@ public class RequestPartPayload {
|
||||
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));
|
||||
.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[]
|
||||
}
|
||||
|
||||
@@ -51,10 +50,9 @@ public class RequestPartPayload {
|
||||
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));
|
||||
.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-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,12 +30,11 @@ public class RequestParts {
|
||||
|
||||
public void upload() throws Exception {
|
||||
// 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-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,12 +30,10 @@ public class RestAssuredSnippetReuse extends SnippetReuse {
|
||||
|
||||
public void documentation() throws Exception {
|
||||
// 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-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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,10 +40,9 @@ 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-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -34,10 +34,8 @@ public class ExampleApplicationJUnit5Tests {
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(ApplicationContext applicationContext,
|
||||
RestDocumentationContextProvider restDocumentation) {
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(applicationContext)
|
||||
.configureClient()
|
||||
public void setUp(ApplicationContext applicationContext, RestDocumentationContextProvider restDocumentation) {
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(applicationContext).configureClient()
|
||||
.filter(documentationConfiguration(restDocumentation)) // <1>
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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,7 @@ public class ExampleApplicationTestNgTests {
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp(Method method) {
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(this.context)
|
||||
.configureClient()
|
||||
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-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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,8 +40,7 @@ public class ExampleApplicationTests {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(this.context)
|
||||
.configureClient()
|
||||
this.webTestClient = WebTestClient.bindToApplicationContext(this.context).configureClient()
|
||||
.filter(documentationConfiguration(this.restDocumentation)) // <1>
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ public class HttpHeaders {
|
||||
.get().uri("/people").header("Authorization", "Basic dXNlcjpzZWNyZXQ=") // <1>
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
.consumeWith(document("headers",
|
||||
requestHeaders( // <2>
|
||||
requestHeaders(// <2>
|
||||
headerWithName("Authorization").description("Basic auth credentials")), // <3>
|
||||
responseHeaders( // <4>
|
||||
responseHeaders(// <4>
|
||||
headerWithName("X-RateLimit-Limit")
|
||||
.description("The total number of requests permitted per period"),
|
||||
headerWithName("X-RateLimit-Remaining")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2021 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,21 +30,20 @@ public class Hypermedia {
|
||||
|
||||
public void defaultExtractor() throws Exception {
|
||||
// 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() throws Exception {
|
||||
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[]
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class PathParameters {
|
||||
this.webTestClient.get().uri("/locations/{latitude}/{longitude}", 51.5072, 0.1275) // <1>
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
.consumeWith(document("locations",
|
||||
pathParameters( // <2>
|
||||
pathParameters(// <2>
|
||||
parameterWithName("latitude").description("The location's latitude"), // <3>
|
||||
parameterWithName("longitude").description("The location's longitude")))); // <4>
|
||||
// end::path-parameters[]
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Payload {
|
||||
this.webTestClient.get().uri("user/5").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
.consumeWith(document("user",
|
||||
responseFields( // <1>
|
||||
responseFields(// <1>
|
||||
fieldWithPath("contact.email").description("The user's email address"), // <2>
|
||||
fieldWithPath("contact.name").description("The user's name")))); // <3>
|
||||
// end::response[]
|
||||
|
||||
@@ -35,7 +35,7 @@ public class RequestParameters {
|
||||
// tag::request-parameters-query-string[]
|
||||
this.webTestClient.get().uri("/users?page=2&per_page=100") // <1>
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
.consumeWith(document("users", requestParameters( // <2>
|
||||
.consumeWith(document("users", requestParameters(// <2>
|
||||
parameterWithName("page").description("The page to retrieve"), // <3>
|
||||
parameterWithName("per_page").description("Entries per page") // <4>
|
||||
)));
|
||||
|
||||
@@ -37,7 +37,7 @@ public class RequestParts {
|
||||
multipartData.add("file", "example".getBytes());
|
||||
this.webTestClient.post().uri("/upload").body(BodyInserters.fromMultipartData(multipartData)) // <1>
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
.consumeWith(document("upload", requestParts( // <2>
|
||||
.consumeWith(document("upload", requestParts(// <2>
|
||||
partWithName("file").description("The file to upload")) // <3>
|
||||
));
|
||||
// end::request-parts[]
|
||||
|
||||
@@ -34,7 +34,7 @@ public class WebTestClientSnippetReuse extends SnippetReuse {
|
||||
// tag::use[]
|
||||
this.webTestClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange()
|
||||
.expectStatus().isOk().expectBody()
|
||||
.consumeWith(document("example", this.pagingLinks.and( // <1>
|
||||
.consumeWith(document("example", this.pagingLinks.and(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
linkWithRel("bravo").description("Link to the bravo resource"))));
|
||||
// end::use[]
|
||||
|
||||
Reference in New Issue
Block a user