public class MockRequest extends Object
| Modifier and Type | Field and Description |
|---|---|
protected org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder |
builder |
protected org.springframework.test.web.servlet.MockMvc |
mockMvc |
protected org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder |
multipartBuilder |
protected Object[] |
uriVars |
protected String |
urlTemplate |
| Constructor and Description |
|---|
MockRequest(org.springframework.test.web.servlet.MockMvc mockMvc,
org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder builder,
String urlTemplate,
Object[] uriVars) |
| Modifier and Type | Method and Description |
|---|---|
MockRequest |
characterEncoding(Charset charset)
设置字符编码
|
MockRequest |
characterEncoding(String charsetEncoding)
设置字符编码
|
MockRequest |
content(byte[] content)
设置内容
|
MockRequest |
content(Object content)
设置内容
|
MockRequest |
content(String content)
设置内容
|
MockRequest |
content(String contentJsonKey,
Object contentJsonValue)
设置完整内容
|
MockRequest |
contentType(org.springframework.http.MediaType contentType)
设置请求内容类型枚举
|
MockRequest |
contentType(String contentType)
设置请求内容类型
|
MockRequest |
file(String multipartParamName,
String filePath)
设置要上传的文件
|
org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder |
getOriginBuilder() |
org.springframework.test.web.servlet.MockMvc |
getOriginMockMvc() |
org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder |
getOriginMultipartBuilder() |
MockRequest |
header(String name,
Object... values)
设置头信息
|
MockRequest |
queryParam(String name,
String... values)
设置查询参数
|
MockRequest |
queryParams(org.springframework.util.MultiValueMap<String,String> params)
批量设置查询参数
|
MockResponse |
send()
发送模拟请求
|
protected final String urlTemplate
protected final Object[] uriVars
protected final org.springframework.test.web.servlet.MockMvc mockMvc
protected org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder builder
protected org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder multipartBuilder
public MockRequest header(String name, Object... values)
name - 头信息键values - 头信息值public MockRequest contentType(org.springframework.http.MediaType contentType)
contentType - 内容类型枚举public MockRequest contentType(String contentType)
contentType - 内容类型public MockRequest characterEncoding(Charset charset)
charset - 字符编码枚举public MockRequest characterEncoding(String charsetEncoding)
charsetEncoding - 字符编码public MockRequest content(byte[] content)
content - 内容public MockRequest content(String content)
content - 内容public MockRequest content(Object content)
content - 内容对象public MockRequest content(String contentJsonKey, Object contentJsonValue)
contentJsonKey - JSON参数键contentJsonValue - JSON参数值public MockRequest file(String multipartParamName, String filePath)
multipartParamName - multipart参数名:对应controller参数注解 RequestPart.name() 的值filePath - 文件路径,可以是相对于`/src/test/resources`目录的路径public MockRequest queryParam(String name, String... values)
name - 参数名values - 参数值public MockRequest queryParams(org.springframework.util.MultiValueMap<String,String> params)
params - 参数集合public MockResponse send() throws Exception
Exception - 异常@NonNull public org.springframework.test.web.servlet.MockMvc getOriginMockMvc()
@NonNull public org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder getOriginBuilder()
@Nullable public org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder getOriginMultipartBuilder()
Copyright © 2021–2022 EasyJ开源社区. All rights reserved.