Migrate tests to JUnit 5
Closes gh-959
This commit is contained in:
@@ -16,8 +16,8 @@ dependencies {
|
||||
internal(platform(project(":spring-restdocs-platform")))
|
||||
|
||||
testImplementation(testFixtures(project(":spring-restdocs-core")))
|
||||
testImplementation("junit:junit")
|
||||
testImplementation("org.assertj:assertj-core")
|
||||
testImplementation("org.hamcrest:hamcrest-library")
|
||||
testImplementation("org.mockito:mockito-core")
|
||||
}
|
||||
|
||||
tasks.named("test") {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
import jakarta.servlet.http.Part;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -46,19 +46,19 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class MockMvcRequestConverterTests {
|
||||
class MockMvcRequestConverterTests {
|
||||
|
||||
private final MockMvcRequestConverter factory = new MockMvcRequestConverter();
|
||||
|
||||
@Test
|
||||
public void httpRequest() {
|
||||
void httpRequest() {
|
||||
OperationRequest request = createOperationRequest(MockMvcRequestBuilders.get("/foo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
assertThat(request.getMethod()).isEqualTo(HttpMethod.GET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpRequestWithCustomPort() {
|
||||
void httpRequestWithCustomPort() {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo").buildRequest(new MockServletContext());
|
||||
mockRequest.setServerPort(8080);
|
||||
OperationRequest request = this.factory.convert(mockRequest);
|
||||
@@ -67,14 +67,14 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithContextPath() {
|
||||
void requestWithContextPath() {
|
||||
OperationRequest request = createOperationRequest(MockMvcRequestBuilders.get("/foo/bar").contextPath("/foo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo/bar"));
|
||||
assertThat(request.getMethod()).isEqualTo(HttpMethod.GET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithHeaders() {
|
||||
void requestWithHeaders() {
|
||||
OperationRequest request = createOperationRequest(
|
||||
MockMvcRequestBuilders.get("/foo").header("a", "alpha", "apple").header("b", "bravo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
@@ -84,7 +84,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithCookies() {
|
||||
void requestWithCookies() {
|
||||
OperationRequest request = createOperationRequest(MockMvcRequestBuilders.get("/foo")
|
||||
.cookie(new jakarta.servlet.http.Cookie("cookieName1", "cookieVal1"),
|
||||
new jakarta.servlet.http.Cookie("cookieName2", "cookieVal2")));
|
||||
@@ -104,7 +104,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpsRequest() {
|
||||
void httpsRequest() {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo").buildRequest(new MockServletContext());
|
||||
mockRequest.setScheme("https");
|
||||
mockRequest.setServerPort(443);
|
||||
@@ -114,7 +114,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpsRequestWithCustomPort() {
|
||||
void httpsRequestWithCustomPort() {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo").buildRequest(new MockServletContext());
|
||||
mockRequest.setScheme("https");
|
||||
mockRequest.setServerPort(8443);
|
||||
@@ -124,7 +124,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithParametersProducesUriWithQueryString() {
|
||||
void getRequestWithParametersProducesUriWithQueryString() {
|
||||
OperationRequest request = createOperationRequest(
|
||||
MockMvcRequestBuilders.get("/foo").param("a", "alpha", "apple").param("b", "br&vo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo?a=alpha&a=apple&b=br%26vo"));
|
||||
@@ -132,7 +132,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithQueryString() {
|
||||
void getRequestWithQueryString() {
|
||||
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/foo?a=alpha&b=bravo");
|
||||
OperationRequest request = createOperationRequest(builder);
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo?a=alpha&b=bravo"));
|
||||
@@ -140,7 +140,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithParametersCreatesFormUrlEncodedContent() {
|
||||
void postRequestWithParametersCreatesFormUrlEncodedContent() {
|
||||
OperationRequest request = createOperationRequest(
|
||||
MockMvcRequestBuilders.post("/foo").param("a", "alpha", "apple").param("b", "br&vo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
@@ -150,7 +150,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithParametersAndQueryStringCreatesFormUrlEncodedContentWithoutDuplication() {
|
||||
void postRequestWithParametersAndQueryStringCreatesFormUrlEncodedContentWithoutDuplication() {
|
||||
OperationRequest request = createOperationRequest(
|
||||
MockMvcRequestBuilders.post("/foo?a=alpha").param("a", "apple").param("b", "br&vo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo?a=alpha"));
|
||||
@@ -160,7 +160,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mockMultipartFileUpload() {
|
||||
void mockMultipartFileUpload() {
|
||||
OperationRequest request = createOperationRequest(MockMvcRequestBuilders.multipart("/foo")
|
||||
.file(new MockMultipartFile("file", new byte[] { 1, 2, 3, 4 })));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
@@ -175,7 +175,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mockMultipartFileUploadWithContentType() {
|
||||
void mockMultipartFileUploadWithContentType() {
|
||||
OperationRequest request = createOperationRequest(MockMvcRequestBuilders.multipart("/foo")
|
||||
.file(new MockMultipartFile("file", "original", "image/png", new byte[] { 1, 2, 3, 4 })));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
@@ -189,7 +189,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithPart() throws IOException {
|
||||
void requestWithPart() throws IOException {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo").buildRequest(new MockServletContext());
|
||||
Part mockPart = mock(Part.class);
|
||||
given(mockPart.getHeaderNames()).willReturn(Arrays.asList("a", "b"));
|
||||
@@ -211,7 +211,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithPartWithContentType() throws IOException {
|
||||
void requestWithPartWithContentType() throws IOException {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo").buildRequest(new MockServletContext());
|
||||
Part mockPart = mock(Part.class);
|
||||
given(mockPart.getHeaderNames()).willReturn(Arrays.asList("a", "b"));
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.Collections;
|
||||
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -37,12 +37,12 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
*
|
||||
* @author Tomasz Kopczynski
|
||||
*/
|
||||
public class MockMvcResponseConverterTests {
|
||||
class MockMvcResponseConverterTests {
|
||||
|
||||
private final MockMvcResponseConverter factory = new MockMvcResponseConverter();
|
||||
|
||||
@Test
|
||||
public void basicResponse() {
|
||||
void basicResponse() {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
OperationResponse operationResponse = this.factory.convert(response);
|
||||
@@ -50,7 +50,7 @@ public class MockMvcResponseConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseWithCookie() {
|
||||
void responseWithCookie() {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
Cookie cookie = new Cookie("name", "value");
|
||||
@@ -66,7 +66,7 @@ public class MockMvcResponseConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseWithCustomStatus() {
|
||||
void responseWithCustomStatus() {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
response.setStatus(600);
|
||||
OperationResponse operationResponse = this.factory.convert(response);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -19,12 +19,13 @@ package org.springframework.restdocs.mockmvc;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assume;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.restdocs.JUnitRestDocumentation;
|
||||
import org.springframework.restdocs.RestDocumentationContextProvider;
|
||||
import org.springframework.restdocs.RestDocumentationExtension;
|
||||
import org.springframework.restdocs.generate.RestDocumentationGenerator;
|
||||
import org.springframework.test.web.servlet.request.RequestPostProcessor;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -41,24 +42,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Wilkinson
|
||||
* @author Dmitriy Mayboroda
|
||||
*/
|
||||
public class MockMvcRestDocumentationConfigurerTests {
|
||||
@ExtendWith(RestDocumentationExtension.class)
|
||||
class MockMvcRestDocumentationConfigurerTests {
|
||||
|
||||
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@Rule
|
||||
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();
|
||||
|
||||
@Test
|
||||
public void defaultConfiguration() {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(this.restDocumentation)
|
||||
void defaultConfiguration(RestDocumentationContextProvider restDocumentation) {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(restDocumentation)
|
||||
.beforeMockMvcCreated(null, null);
|
||||
postProcessor.postProcessRequest(this.request);
|
||||
assertUriConfiguration("http", "localhost", 8080);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customScheme() {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(this.restDocumentation).uris()
|
||||
void customScheme(RestDocumentationContextProvider restDocumentation) {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(restDocumentation).uris()
|
||||
.withScheme("https")
|
||||
.beforeMockMvcCreated(null, null);
|
||||
postProcessor.postProcessRequest(this.request);
|
||||
@@ -66,8 +65,8 @@ public class MockMvcRestDocumentationConfigurerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customHost() {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(this.restDocumentation).uris()
|
||||
void customHost(RestDocumentationContextProvider restDocumentation) {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(restDocumentation).uris()
|
||||
.withHost("api.example.com")
|
||||
.beforeMockMvcCreated(null, null);
|
||||
postProcessor.postProcessRequest(this.request);
|
||||
@@ -75,8 +74,8 @@ public class MockMvcRestDocumentationConfigurerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customPort() {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(this.restDocumentation).uris()
|
||||
void customPort(RestDocumentationContextProvider restDocumentation) {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(restDocumentation).uris()
|
||||
.withPort(8081)
|
||||
.beforeMockMvcCreated(null, null);
|
||||
postProcessor.postProcessRequest(this.request);
|
||||
@@ -84,8 +83,8 @@ public class MockMvcRestDocumentationConfigurerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noContentLengthHeaderWhenRequestHasNotContent() {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(this.restDocumentation).uris()
|
||||
void noContentLengthHeaderWhenRequestHasNotContent(RestDocumentationContextProvider restDocumentation) {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(restDocumentation).uris()
|
||||
.withPort(8081)
|
||||
.beforeMockMvcCreated(null, null);
|
||||
postProcessor.postProcessRequest(this.request);
|
||||
@@ -94,8 +93,8 @@ public class MockMvcRestDocumentationConfigurerTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void uriTemplateFromRequestAttribute() {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(this.restDocumentation)
|
||||
void uriTemplateFromRequestAttribute(RestDocumentationContextProvider restDocumentation) {
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(restDocumentation)
|
||||
.beforeMockMvcCreated(null, null);
|
||||
this.request.setAttribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, "{a}/{b}");
|
||||
postProcessor.postProcessRequest(this.request);
|
||||
@@ -106,11 +105,11 @@ public class MockMvcRestDocumentationConfigurerTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void uriTemplateFromRequest() {
|
||||
void uriTemplateFromRequest(RestDocumentationContextProvider restDocumentation) {
|
||||
Method setUriTemplate = ReflectionUtils.findMethod(MockHttpServletRequest.class, "setUriTemplate",
|
||||
String.class);
|
||||
Assume.assumeNotNull(setUriTemplate);
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(this.restDocumentation)
|
||||
Assumptions.assumeFalse(setUriTemplate == null);
|
||||
RequestPostProcessor postProcessor = new MockMvcRestDocumentationConfigurer(restDocumentation)
|
||||
.beforeMockMvcCreated(null, null);
|
||||
ReflectionUtils.invokeMethod(setUriTemplate, this.request, "{a}/{b}");
|
||||
postProcessor.postProcessRequest(this.request);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2024 the original author or authors.
|
||||
* Copyright 2014-2025 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,11 +34,10 @@ import java.util.regex.Pattern;
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -47,7 +46,8 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.restdocs.JUnitRestDocumentation;
|
||||
import org.springframework.restdocs.RestDocumentationContextProvider;
|
||||
import org.springframework.restdocs.RestDocumentationExtension;
|
||||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentationIntegrationTests.TestConfiguration;
|
||||
import org.springframework.restdocs.templates.TemplateFormat;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
@@ -56,7 +56,7 @@ import org.springframework.restdocs.testfixtures.SnippetConditions.CodeBlockCond
|
||||
import org.springframework.restdocs.testfixtures.SnippetConditions.HttpRequestCondition;
|
||||
import org.springframework.restdocs.testfixtures.SnippetConditions.HttpResponseCondition;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
@@ -106,29 +106,30 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
* @author Tomasz Kopczynski
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@WebAppConfiguration
|
||||
@ExtendWith(RestDocumentationExtension.class)
|
||||
@ContextConfiguration(classes = TestConfiguration.class)
|
||||
public class MockMvcRestDocumentationIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();
|
||||
private RestDocumentationContextProvider restDocumentation;
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void deleteSnippets() {
|
||||
@BeforeEach
|
||||
void setUp(RestDocumentationContextProvider restDocumentation) {
|
||||
this.restDocumentation = restDocumentation;
|
||||
FileSystemUtils.deleteRecursively(new File("build/generated-snippets"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void clearOutputDirSystemProperty() {
|
||||
@AfterEach
|
||||
void clearOutputDirSystemProperty() {
|
||||
System.clearProperty("org.springframework.restdocs.outputDir");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicSnippetGeneration() throws Exception {
|
||||
void basicSnippetGeneration() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(new MockMvcRestDocumentationConfigurer(this.restDocumentation).snippets().withEncoding("UTF-8"))
|
||||
.build();
|
||||
@@ -140,7 +141,19 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void markdownSnippetGeneration() throws Exception {
|
||||
void getRequestWithBody() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(new MockMvcRestDocumentationConfigurer(this.restDocumentation).snippets().withEncoding("UTF-8"))
|
||||
.build();
|
||||
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON).content("some body content"))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("get-request-with-body"));
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/get-request-with-body"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
void markdownSnippetGeneration() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(new MockMvcRestDocumentationConfigurer(this.restDocumentation).snippets()
|
||||
.withEncoding("UTF-8")
|
||||
@@ -154,7 +167,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithContent() throws Exception {
|
||||
void curlSnippetWithContent() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -168,7 +181,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithCookies() throws Exception {
|
||||
void curlSnippetWithCookies() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -182,7 +195,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithQueryStringOnPost() throws Exception {
|
||||
void curlSnippetWithQueryStringOnPost() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -196,7 +209,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithEmptyParameterQueryString() throws Exception {
|
||||
void curlSnippetWithEmptyParameterQueryString() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -210,7 +223,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithContentAndParametersOnPost() throws Exception {
|
||||
void curlSnippetWithContentAndParametersOnPost() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -224,7 +237,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpieSnippetWithContent() throws Exception {
|
||||
void httpieSnippetWithContent() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -237,7 +250,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpieSnippetWithCookies() throws Exception {
|
||||
void httpieSnippetWithCookies() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -251,7 +264,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpieSnippetWithQueryStringOnPost() throws Exception {
|
||||
void httpieSnippetWithQueryStringOnPost() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -265,7 +278,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpieSnippetWithContentAndParametersOnPost() throws Exception {
|
||||
void httpieSnippetWithContentAndParametersOnPost() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -280,7 +293,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linksSnippet() throws Exception {
|
||||
void linksSnippet() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -293,7 +306,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathParametersSnippet() throws Exception {
|
||||
void pathParametersSnippet() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -305,7 +318,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryParametersSnippet() throws Exception {
|
||||
void queryParametersSnippet() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -317,7 +330,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestFieldsSnippet() throws Exception {
|
||||
void requestFieldsSnippet() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -329,7 +342,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestPartsSnippet() throws Exception {
|
||||
void requestPartsSnippet() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -341,7 +354,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseFieldsSnippet() throws Exception {
|
||||
void responseFieldsSnippet() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -354,7 +367,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseWithSetCookie() throws Exception {
|
||||
void responseWithSetCookie() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -368,7 +381,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parameterizedOutputDirectory() throws Exception {
|
||||
void parameterizedOutputDirectory() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -380,7 +393,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiStep() throws Exception {
|
||||
void multiStep() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.alwaysDo(document("{method-name}-{step}"))
|
||||
@@ -398,7 +411,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alwaysDoWithAdditionalSnippets() throws Exception {
|
||||
void alwaysDoWithAdditionalSnippets() throws Exception {
|
||||
RestDocumentationResultHandler documentation = document("{method-name}-{step}");
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
@@ -412,7 +425,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preprocessedRequest() throws Exception {
|
||||
void preprocessedRequest() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -455,7 +468,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPreprocessedRequest() throws Exception {
|
||||
void defaultPreprocessedRequest() throws Exception {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
@@ -486,7 +499,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preprocessedResponse() throws Exception {
|
||||
void preprocessedResponse() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -515,7 +528,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPreprocessedResponse() throws Exception {
|
||||
void defaultPreprocessedResponse() throws Exception {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
@@ -537,7 +550,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customSnippetTemplate() throws Exception {
|
||||
void customSnippetTemplate() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -559,7 +572,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customContextPath() throws Exception {
|
||||
void customContextPath() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
@@ -573,7 +586,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionShouldBeThrownWhenCallDocumentMockMvcNotConfigured() {
|
||||
void exceptionShouldBeThrownWhenCallDocumentMockMvcNotConfigured() {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
|
||||
assertThatThrownBy(() -> mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)).andDo(document("basic")))
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
@@ -583,7 +596,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionShouldBeThrownWhenCallDocumentSnippetsMockMvcNotConfigured() {
|
||||
void exceptionShouldBeThrownWhenCallDocumentSnippetsMockMvcNotConfigured() {
|
||||
RestDocumentationResultHandler documentation = document("{method-name}-{step}");
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
|
||||
assertThatThrownBy(() -> mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
|
||||
@@ -594,7 +607,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiPart() throws Exception {
|
||||
void multiPart() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation))
|
||||
.build();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -19,7 +19,7 @@ package org.springframework.restdocs.mockmvc;
|
||||
import java.net.URI;
|
||||
|
||||
import jakarta.servlet.ServletContext;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -44,97 +44,97 @@ import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuild
|
||||
* @author Andy Wilkinson
|
||||
*
|
||||
*/
|
||||
public class RestDocumentationRequestBuildersTests {
|
||||
class RestDocumentationRequestBuildersTests {
|
||||
|
||||
private final ServletContext servletContext = new MockServletContext();
|
||||
|
||||
@Test
|
||||
public void getTemplate() {
|
||||
void getTemplate() {
|
||||
assertTemplate(get("/{template}", "t"), HttpMethod.GET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUri() {
|
||||
void getUri() {
|
||||
assertUri(get(URI.create("/uri")), HttpMethod.GET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postTemplate() {
|
||||
void postTemplate() {
|
||||
assertTemplate(post("/{template}", "t"), HttpMethod.POST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postUri() {
|
||||
void postUri() {
|
||||
assertUri(post(URI.create("/uri")), HttpMethod.POST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putTemplate() {
|
||||
void putTemplate() {
|
||||
assertTemplate(put("/{template}", "t"), HttpMethod.PUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putUri() {
|
||||
void putUri() {
|
||||
assertUri(put(URI.create("/uri")), HttpMethod.PUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patchTemplate() {
|
||||
void patchTemplate() {
|
||||
assertTemplate(patch("/{template}", "t"), HttpMethod.PATCH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patchUri() {
|
||||
void patchUri() {
|
||||
assertUri(patch(URI.create("/uri")), HttpMethod.PATCH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteTemplate() {
|
||||
void deleteTemplate() {
|
||||
assertTemplate(delete("/{template}", "t"), HttpMethod.DELETE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteUri() {
|
||||
void deleteUri() {
|
||||
assertUri(delete(URI.create("/uri")), HttpMethod.DELETE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionsTemplate() {
|
||||
void optionsTemplate() {
|
||||
assertTemplate(options("/{template}", "t"), HttpMethod.OPTIONS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionsUri() {
|
||||
void optionsUri() {
|
||||
assertUri(options(URI.create("/uri")), HttpMethod.OPTIONS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headTemplate() {
|
||||
void headTemplate() {
|
||||
assertTemplate(head("/{template}", "t"), HttpMethod.HEAD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headUri() {
|
||||
void headUri() {
|
||||
assertUri(head(URI.create("/uri")), HttpMethod.HEAD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestTemplate() {
|
||||
void requestTemplate() {
|
||||
assertTemplate(request(HttpMethod.GET, "/{template}", "t"), HttpMethod.GET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestUri() {
|
||||
void requestUri() {
|
||||
assertUri(request(HttpMethod.GET, URI.create("/uri")), HttpMethod.GET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartTemplate() {
|
||||
void multipartTemplate() {
|
||||
assertTemplate(multipart("/{template}", "t"), HttpMethod.POST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartUri() {
|
||||
void multipartUri() {
|
||||
assertUri(multipart(URI.create("/uri")), HttpMethod.POST);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user