public class MockMvcRequestSpecificationImpl extends Object implements MockMvcRequestSpecification, MockMvcAuthenticationSpecification
Constructor and Description |
---|
MockMvcRequestSpecificationImpl(MockMvcFactory mockMvcFactory,
RestAssuredMockMvcConfig config,
List<org.springframework.test.web.servlet.ResultHandler> resultHandlers,
List<org.springframework.test.web.servlet.request.RequestPostProcessor> requestPostProcessors,
String basePath,
MockMvcRequestSpecification requestSpecification,
io.restassured.specification.ResponseSpecification responseSpecification,
MockMvcAuthenticationScheme authentication) |
Modifier and Type | Method and Description |
---|---|
MockMvcRequestSpecification |
accept(io.restassured.http.ContentType contentType)
Specify the accept header of the request.
|
MockMvcRequestSpecification |
accept(org.springframework.http.MediaType... mediaTypes)
Specify the accept header of the request.
|
MockMvcRequestSpecification |
accept(String mediaTypes)
Specify the accept header of the request.
|
MockMvcRequestSpecification |
and()
Syntactic sugar
|
MockMvcRequestSpecification |
attribute(String attributeName,
Object attributeValue)
Specify a single-value request attribute
|
MockMvcRequestSpecification |
attributes(Map<String,?> attributesMap)
Specify request attributes as a map
|
MockMvcAuthenticationSpecification |
auth()
Specify authentication details that'll be used in the request.
|
MockMvcRequestSpecification |
authentication(Object authentication)
Authenticate using the given authentication instance.
|
MockMvcRequestSpecification |
basePath(String path) |
MockMvcRequestSpecification |
body(byte[] body)
Specify a byte array request body that'll be sent with the request.
|
MockMvcRequestSpecification |
body(File body)
Specify file content that'll be sent with the request.
|
MockMvcRequestSpecification |
body(Object object)
Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request.
|
MockMvcRequestSpecification |
body(Object object,
io.restassured.mapper.ObjectMapper mapper)
Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request using a specific object mapper.
|
MockMvcRequestSpecification |
body(Object object,
io.restassured.mapper.ObjectMapperType mapperType)
Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request using a specific object mapper type.
|
MockMvcRequestSpecification |
body(String body)
Specify a String request body (such as e.g.
|
MockMvcRequestSpecification |
config(RestAssuredMockMvcConfig config)
Define a REST Assured Mock Mvc configuration.
|
MockMvcRequestSpecification |
contentType(io.restassured.http.ContentType contentType)
Specify the content type of the request.
|
MockMvcRequestSpecification |
contentType(String contentType)
Specify the content type of the request.
|
MockMvcRequestSpecification |
cookie(io.restassured.http.Cookie cookie)
Specify a
Cookie to send with the request. |
MockMvcRequestSpecification |
cookie(String cookieName,
Object cookieValue,
Object... additionalValues)
Specify a cookie that'll be sent with the request e.g:
|
MockMvcRequestSpecification |
cookies(io.restassured.http.Cookies cookies)
Specify the cookies that'll be sent with the request as
Cookies : |
MockMvcRequestSpecification |
cookies(Map<String,?> cookies)
Specify the cookies that'll be sent with the request as Map e.g:
|
MockMvcRequestSpecification |
cookies(String firstCookieName,
Object firstCookieValue,
Object... cookieNameValuePairs)
Specify the cookies that'll be sent with the request.
|
MockMvcResponse |
delete() |
MockMvcResponse |
delete(String path,
Map<String,?> pathParams) |
MockMvcResponse |
delete(String path,
Object... pathParams) |
MockMvcResponse |
delete(URI uri) |
MockMvcResponse |
delete(URL url) |
MockMvcRequestSpecification |
formParam(String parameterName,
Collection<?> parameterValues)
Specify a multi-value form parameter that'll be sent with the request e.g:
|
MockMvcRequestSpecification |
formParam(String parameterName,
Object... parameterValues)
Specify a form parameter that'll be sent with the request.
|
MockMvcRequestSpecification |
formParams(Map<String,?> parametersMap)
Specify the form parameters that'll be sent with the request.
|
MockMvcRequestSpecification |
formParams(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify the form parameters that'll be sent with the request.
|
MockMvcResponse |
get() |
MockMvcResponse |
get(String path,
Map<String,?> pathParams) |
MockMvcResponse |
get(String path,
Object... pathParams) |
MockMvcResponse |
get(URI uri) |
MockMvcResponse |
get(URL url) |
AsyncConfig |
getAsyncConfig() |
Map<String,Object> |
getAttributes() |
Object |
getAuthentication() |
String |
getBasePath() |
io.restassured.http.Cookies |
getCookies() |
Map<String,Object> |
getFormParams() |
MockHttpServletRequestBuilderInterceptor |
getInterceptor() |
io.restassured.internal.log.LogRepository |
getLogRepository() |
MockMvcFactory |
getMockMvcFactory() |
List<io.restassured.module.mockmvc.internal.MockMvcMultiPart> |
getMultiParts() |
Map<String,Object> |
getParams() |
Map<String,Object> |
getQueryParams() |
Object |
getRequestBody() |
String |
getRequestContentType() |
io.restassured.http.Headers |
getRequestHeaders() |
io.restassured.filter.log.RequestLoggingFilter |
getRequestLoggingFilter() |
List<org.springframework.test.web.servlet.request.RequestPostProcessor> |
getRequestPostProcessors() |
io.restassured.config.RestAssuredConfig |
getRestAssuredConfig() |
RestAssuredMockMvcConfig |
getRestAssuredMockMvcConfig() |
List<org.springframework.test.web.servlet.ResultHandler> |
getResultHandlers() |
MockMvcResponse |
head() |
MockMvcResponse |
head(String path,
Map<String,?> pathParams) |
MockMvcResponse |
head(String path,
Object... pathParams) |
MockMvcResponse |
head(URI uri) |
MockMvcResponse |
head(URL url) |
MockMvcRequestSpecification |
header(io.restassured.http.Header header)
Specify a
Header to send with the request. |
MockMvcRequestSpecification |
header(String headerName,
Object headerValue,
Object... additionalHeaderValues)
Specify a header that'll be sent with the request e.g:
|
MockMvcRequestSpecification |
headers(io.restassured.http.Headers headers)
Specify the headers that'll be sent with the request as
Headers , e.g: |
MockMvcRequestSpecification |
headers(Map<String,?> headers)
Specify the headers that'll be sent with the request as Map e.g:
|
MockMvcRequestSpecification |
headers(String firstHeaderName,
Object firstHeaderValue,
Object... headerNameValuePairs)
Specify the headers that'll be sent with the request.
|
MockMvcRequestSpecification |
interceptor(MockHttpServletRequestBuilderInterceptor interceptor)
Intercept the
MockHttpServletRequestBuilder created by REST Assured before it's
used to perform the request. |
MockMvcRequestLogSpecification |
log()
Returns the
MockMvcRequestLogSpecification that allows you to log different parts of the MockMvcRequestSpecification . |
MockMvcRequestSpecification |
mockMvc(org.springframework.test.web.servlet.MockMvc mockMvc)
Provide a
MockMvc instance to that REST Assured will use when making this request. |
MockMvcRequestSpecification |
multiPart(File file)
Specify a file to upload to the server using multi-part form data uploading.
|
MockMvcRequestSpecification |
multiPart(String controlName,
File file)
Specify a file to upload to the server using multi-part form data uploading with a specific
control name.
|
MockMvcRequestSpecification |
multiPart(String controlName,
File file,
String mimeType)
Specify a file to upload to the server using multi-part form data uploading with a specific
control name and mime-type.
|
MockMvcRequestSpecification |
multiPart(String controlName,
Object object)
Specify an object that will be serialized to JSON and uploaded to the server using multi-part form data
uploading with a specific control name.
|
MockMvcRequestSpecification |
multiPart(String controlName,
Object object,
String mimeType)
Specify an object that will be serialized and uploaded to the server using multi-part form data
uploading with a specific control name.
|
MockMvcRequestSpecification |
multiPart(String controlName,
String contentBody)
Specify a string to send to the server using multi-part form data.
|
MockMvcRequestSpecification |
multiPart(String controlName,
String fileName,
byte[] bytes)
Specify a byte-array to upload to the server using multi-part form data.
|
MockMvcRequestSpecification |
multiPart(String controlName,
String fileName,
byte[] bytes,
String mimeType)
Specify a byte-array to upload to the server using multi-part form data.
|
MockMvcRequestSpecification |
multiPart(String controlName,
String fileName,
InputStream stream)
Specify an inputstream to upload to the server using multi-part form data.
|
MockMvcRequestSpecification |
multiPart(String controlName,
String fileName,
InputStream stream,
String mimeType)
Specify an inputstream to upload to the server using multi-part form data.
|
MockMvcRequestSpecification |
multiPart(String controlName,
String filename,
Object object,
String mimeType)
Specify an object that will be serialized and uploaded to the server using multi-part form data
uploading with a specific control name.
|
MockMvcRequestSpecification |
multiPart(String controlName,
String contentBody,
String mimeType)
Specify a string to send to the server using multi-part form data with a specific mime-type.
|
MockMvcRequestSpecification |
none()
Explicitly state that you don't which to use any authentication in this request.
|
MockMvcResponse |
options() |
MockMvcResponse |
options(String path,
Map<String,?> pathParams) |
MockMvcResponse |
options(String path,
Object... pathParams) |
MockMvcResponse |
options(URI uri) |
MockMvcResponse |
options(URL url) |
MockMvcRequestSpecification |
param(String parameterName,
Collection<?> parameterValues)
Specify a multi-value parameter that'll be sent with the request e.g:
|
MockMvcRequestSpecification |
param(String parameterName,
Object... parameterValues)
Specify a parameter that'll be sent with the request e.g:
|
MockMvcRequestSpecification |
params(Map<String,?> parametersMap)
Specify the parameters that'll be sent with the request as Map e.g:
|
MockMvcRequestSpecification |
params(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify the parameters that'll be sent with the request.
|
MockMvcResponse |
patch() |
MockMvcResponse |
patch(String path,
Map<String,?> pathParams) |
MockMvcResponse |
patch(String path,
Object... pathParams) |
MockMvcResponse |
patch(URI uri) |
MockMvcResponse |
patch(URL url) |
MockMvcResponse |
post() |
MockMvcResponse |
post(String path,
Map<String,?> pathParams) |
MockMvcResponse |
post(String path,
Object... pathParams) |
MockMvcResponse |
post(URI uri) |
MockMvcResponse |
post(URL url) |
MockMvcRequestSpecification |
postProcessors(org.springframework.test.web.servlet.request.RequestPostProcessor postProcessor,
org.springframework.test.web.servlet.request.RequestPostProcessor... additionalPostProcessors)
An extension point for further initialization of
MockHttpServletRequest
in ways not built directly into the MockHttpServletRequestBuilder . |
MockMvcRequestSpecification |
principal(Object principal)
Authenticate using the given principal.
|
MockMvcRequestSpecification |
principal(Principal principal)
Authenticate using the given principal.
|
MockMvcRequestSpecification |
principalWithCredentials(Object principal,
Object credentials,
String... authorities)
Authenticate using the given principal and credentials.
|
MockMvcResponse |
put() |
MockMvcResponse |
put(String path,
Map<String,?> pathParams) |
MockMvcResponse |
put(String path,
Object... pathParams) |
MockMvcResponse |
put(URI uri) |
MockMvcResponse |
put(URL url) |
MockMvcRequestSpecification |
queryParam(String parameterName,
Collection<?> parameterValues)
Specify a multi-value query parameter that'll be sent with the request e.g:
|
MockMvcRequestSpecification |
queryParam(String parameterName,
Object... parameterValues)
Specify a query parameter that'll be sent with the request.
|
MockMvcRequestSpecification |
queryParams(Map<String,?> parametersMap)
Specify the query parameters that'll be sent with the request.
|
MockMvcRequestSpecification |
queryParams(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify the query parameters that'll be sent with the request.
|
MockMvcResponse |
request(io.restassured.http.Method method) |
MockMvcResponse |
request(io.restassured.http.Method method,
String path,
Object... pathParams) |
MockMvcResponse |
request(io.restassured.http.Method method,
URI uri) |
MockMvcResponse |
request(io.restassured.http.Method method,
URL url) |
MockMvcResponse |
request(String method) |
MockMvcResponse |
request(String method,
String path,
Object... pathParams) |
MockMvcResponse |
request(String method,
URI uri) |
MockMvcResponse |
request(String method,
URL url) |
MockMvcRequestSpecification |
resultHandlers(org.springframework.test.web.servlet.ResultHandler resultHandler,
org.springframework.test.web.servlet.ResultHandler... resultHandlers) |
MockMvcRequestSpecification |
sessionAttr(String name,
Object value)
Set a session attribute.
|
MockMvcRequestSpecification |
sessionAttrs(Map<String,Object> sessionAttributes)
Set session attributes.
|
MockMvcRequestSpecification |
sessionId(String sessionIdValue)
Set the session id for this request.
|
MockMvcRequestSpecification |
sessionId(String sessionIdName,
String sessionIdValue)
Set the session id name and value for this request.
|
void |
setRequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter requestLoggingFilter) |
MockMvcRequestSpecification |
spec(MockMvcRequestSpecification requestSpecificationToMerge)
Add request data from a pre-defined specification.
|
MockMvcRequestSpecification |
standaloneSetup(org.springframework.test.web.servlet.MockMvcBuilder builder)
Build a
MockMvc by using a provided AbstractMockMvcBuilder
for configuring Spring MVC infrastructure programmatically. |
MockMvcRequestSpecification |
standaloneSetup(Object... controllerOrMockMvcConfigurer)
Build a
MockMvc by registering one or more @Controller 's
instances and configuring Spring MVC infrastructure programmatically. |
MockMvcRequestSpecification |
webAppContextSetup(org.springframework.web.context.WebApplicationContext context,
org.springframework.test.web.servlet.setup.MockMvcConfigurer... mockMvcConfigurers)
Build a
MockMvc using the given, fully initialized, i.e. |
MockMvcRequestAsyncSender |
when()
Call this method when you're done setting up the request specification.
|
MockMvcRequestSpecification |
with(org.springframework.test.web.servlet.request.RequestPostProcessor requestPostProcessor,
org.springframework.test.web.servlet.request.RequestPostProcessor... additionalRequestPostProcessor)
Authenticate using a
RequestPostProcessor . |
public MockMvcRequestSpecificationImpl(MockMvcFactory mockMvcFactory, RestAssuredMockMvcConfig config, List<org.springframework.test.web.servlet.ResultHandler> resultHandlers, List<org.springframework.test.web.servlet.request.RequestPostProcessor> requestPostProcessors, String basePath, MockMvcRequestSpecification requestSpecification, io.restassured.specification.ResponseSpecification responseSpecification, MockMvcAuthenticationScheme authentication)
public MockMvcRequestSpecification mockMvc(org.springframework.test.web.servlet.MockMvc mockMvc)
MockMvcRequestSpecification
MockMvc
instance to that REST Assured will use when making this request.mockMvc
in interface MockMvcRequestSpecification
mockMvc
- The mock mvc instance to use.public MockMvcRequestSpecification standaloneSetup(Object... controllerOrMockMvcConfigurer)
MockMvcRequestSpecification
MockMvc
by registering one or more @Controller
's
instances and configuring Spring MVC infrastructure programmatically.
This allows full control over the instantiation and initialization of
controllerOrMockMvcConfigurer, and their dependencies, similar to plain unit tests while
also making it possible to test one controller at a time.
When this option is used, the minimum infrastructure required by the
org.springframework.web.servlet.DispatcherServlet
to serve requests with annotated controllerOrMockMvcConfigurer is
automatically created, and can be customized, resulting in configuration
that is equivalent to what the MVC Java configuration provides except
using builder style methods.
If the Spring MVC configuration of an application is relatively straight-forward, for example when using the MVC namespace or the MVC Java config, then using this builder might be a good option for testing a majority of controllers. A much smaller number of tests can be used to focus on testing and verifying the actual Spring MVC configuration.
standaloneSetup
in interface MockMvcRequestSpecification
controllerOrMockMvcConfigurer
- one or more @Controller
's to test
or a combination of controllers and MockMvcConfigurer
public MockMvcRequestSpecification standaloneSetup(org.springframework.test.web.servlet.MockMvcBuilder builder)
MockMvcRequestSpecification
MockMvc
by using a provided AbstractMockMvcBuilder
for configuring Spring MVC infrastructure programmatically.
This allows full control over the instantiation and initialization of
controllers, and their dependencies, similar to plain unit tests while
also making it possible to test one controller at a time.
If the Spring MVC configuration of an application is relatively straight-forward, for example when using the MVC namespace or the MVC Java config, then using this builder might be a good option for testing a majority of controllers. A much smaller number of tests can be used to focus on testing and verifying the actual Spring MVC configuration.
standaloneSetup
in interface MockMvcRequestSpecification
builder
- AbstractMockMvcBuilder
to build the MVC mockpublic MockMvcRequestSpecification webAppContextSetup(org.springframework.web.context.WebApplicationContext context, org.springframework.test.web.servlet.setup.MockMvcConfigurer... mockMvcConfigurers)
MockMvcRequestSpecification
MockMvc
using the given, fully initialized, i.e.
refreshed, WebApplicationContext
and assign it to REST Assured.
The org.springframework.web.servlet.DispatcherServlet
will use the context to discover Spring MVC infrastructure and
application controllers in it. The context must have been configured with
a ServletContext
.webAppContextSetup
in interface MockMvcRequestSpecification
context
- The web application context to usemockMvcConfigurers
- MockMvcConfigurer
's to be applied when creating a MockMvc
instance of this WebApplicationContext (optional)public MockMvcRequestSpecification interceptor(MockHttpServletRequestBuilderInterceptor interceptor)
MockMvcRequestSpecification
MockHttpServletRequestBuilder
created by REST Assured before it's
used to perform the request.interceptor
in interface MockMvcRequestSpecification
interceptor
- The interceptorpublic MockMvcRequestSpecification and()
MockMvcRequestSpecification
and
in interface MockMvcRequestSpecification
MockMvcRequestSpecification
instance.public MockMvcRequestSpecification postProcessors(org.springframework.test.web.servlet.request.RequestPostProcessor postProcessor, org.springframework.test.web.servlet.request.RequestPostProcessor... additionalPostProcessors)
MockMvcRequestSpecification
MockHttpServletRequest
in ways not built directly into the MockHttpServletRequestBuilder
.
Implementation of this interface can have builder-style methods themselves
and be made accessible through static factory methods.
Note that it's recommended to use MockMvcAuthenticationSpecification.with(RequestPostProcessor, RequestPostProcessor...)
instead of this method when setting authentication/authorization based RequestPostProcessors.
For example:
given().auth().with(httpBasic("username", "password")). ..
postProcessors
in interface MockMvcRequestSpecification
postProcessor
- a post-processor to addadditionalPostProcessors
- Additional post-processors to addMockHttpServletRequestBuilder.with(RequestPostProcessor)
public MockMvcAuthenticationSpecification auth()
MockMvcRequestSpecification
auth
in interface MockMvcRequestSpecification
MockMvcAuthenticationSpecification
.public MockMvcRequestSpecification contentType(io.restassured.http.ContentType contentType)
MockMvcRequestSpecification
contentType
in interface MockMvcRequestSpecification
contentType
- The content type of the requestContentType
public MockMvcRequestSpecification contentType(String contentType)
MockMvcRequestSpecification
contentType
in interface MockMvcRequestSpecification
contentType
- The content type of the requestContentType
public MockMvcRequestSpecification accept(io.restassured.http.ContentType contentType)
MockMvcRequestSpecification
header("Accept", contentType);
accept
in interface MockMvcRequestSpecification
contentType
- The content type whose accept header ContentType.getAcceptHeader()
will be used as Accept header in the request.ContentType
,
MockMvcRequestSpecification.header(String, Object, Object...)
public MockMvcRequestSpecification accept(org.springframework.http.MediaType... mediaTypes)
MockMvcRequestSpecification
header("Accept", contentType);
accept
in interface MockMvcRequestSpecification
mediaTypes
- The media type(s) that will be used as Accept header in the request.ContentType
,
MockMvcRequestSpecification.header(String, Object, Object...)
public MockMvcRequestSpecification accept(String mediaTypes)
MockMvcRequestSpecification
header("Accept", contentType);
accept
in interface MockMvcRequestSpecification
mediaTypes
- The media type(s) that will be used as Accept header in the request.ContentType
,
MockMvcRequestSpecification.header(String, Object, Object...)
public MockMvcRequestSpecification headers(String firstHeaderName, Object firstHeaderValue, Object... headerNameValuePairs)
MockMvcRequestSpecification
given().headers("headerName1", "headerValue1", "headerName2", "headerValue2").then().expect().body(equalTo("something")).when().get("/headers");This will send a GET request to "/headers" with two headers:
headers
in interface MockMvcRequestSpecification
firstHeaderName
- The name of the first headerfirstHeaderValue
- The value of the first headerheaderNameValuePairs
- Additional headers in name-value pairs.public MockMvcRequestSpecification headers(Map<String,?> headers)
MockMvcRequestSpecification
Map<String, String> headers = new HashMap<String, String>(); parameters.put("headerName1", "headerValue1"); parameters.put("headerName2", "headerValue2"); given().headers(headers).then().expect().body(equalTo("something")).when().get("/headers");This will send a GET request to "/headers" with two headers:
headers
in interface MockMvcRequestSpecification
headers
- The Map containing the header names and their values to send with the request.public MockMvcRequestSpecification headers(io.restassured.http.Headers headers)
MockMvcRequestSpecification
Headers
, e.g:
Header first = new Header("headerName1", "headerValue1"); Header second = new Header("headerName2", "headerValue2"); Headers headers = new Header(first, second); given().headers(headers).then().expect().body(equalTo("something")).when().get("/headers");This will send a GET request to "/headers" with two headers:
headers
in interface MockMvcRequestSpecification
headers
- The headers to use in the requestpublic MockMvcRequestSpecification header(String headerName, Object headerValue, Object... additionalHeaderValues)
MockMvcRequestSpecification
given().header("username", "John").and().expect().body(equalTo("something")).when().get("/header");This will set the header
username=John
in the GET request to "/header".
You can also specify several headers like this:
given().header("username", "John").and().header("zipCode", "12345").and().expect().body(equalTo("something")).when().get("/header");If you specify
additionalHeaderValues
then the Header will be a multi-value header. This means that you'll create several headers with the
same name but with different values.header
in interface MockMvcRequestSpecification
headerName
- The header nameheaderValue
- The header valueadditionalHeaderValues
- Additional header values. This will actually create two headers with the same name but with different values.MockMvcRequestSpecification.headers(String, Object, Object...)
public MockMvcRequestSpecification header(io.restassured.http.Header header)
MockMvcRequestSpecification
Header
to send with the request.
Header someHeader = new Header("some_name", "some_value"); given().header(someHeader).and().expect().body(equalTo("x")).when().get("/header");This will set the header
some_name=some_value
in the GET request to "/header".
header
in interface MockMvcRequestSpecification
header
- The header to add to the requestMockMvcRequestSpecification.headers(Headers)
public MockMvcRequestLogSpecification log()
MockMvcRequestSpecification
MockMvcRequestLogSpecification
that allows you to log different parts of the MockMvcRequestSpecification
.
This is mainly useful for debug purposes when writing your tests.log
in interface MockMvcRequestSpecification
public MockMvcRequestSpecification params(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
MockMvcRequestSpecification
given().params("username", "John", "token", "1234").when().get("/parameters").then().assertThat().body(equalTo("username, token"));This will send a GET request to "/parameters" with two parameters:
params
in interface MockMvcRequestSpecification
firstParameterName
- The name of the first parameterfirstParameterValue
- The value of the first parameterparameterNameValuePairs
- Additional parameters in name-value pairs.public MockMvcRequestSpecification params(Map<String,?> parametersMap)
MockMvcRequestSpecification
Map<String, String> parameters = new HashMap<String, String>(); parameters.put("username", "John"); parameters.put("token", "1234"); given().params(parameters).when().get("/cookie").then().assertThat().body(equalTo("username, token")).;This will send a GET request to "/cookie" with two parameters:
params
in interface MockMvcRequestSpecification
parametersMap
- The Map containing the parameter names and their values to send with the request.public MockMvcRequestSpecification param(String parameterName, Object... parameterValues)
MockMvcRequestSpecification
given().parameter("username", "John").and().expect().body(equalTo("username")).when().get("/cookie");This will set the parameter
username=John
in the GET request to "/cookie".
You can also specify several parameters like this:
given().param("username", "John").and().param("password", "1234").when().get("/cookie").then().assertThat().body(equalTo("username")).;
param
in interface MockMvcRequestSpecification
parameterName
- The parameter nameparameterValues
- Zero to many parameter values for this parameter nameMockMvcRequestSpecification.params(String, Object, Object...)
public MockMvcRequestSpecification param(String parameterName, Collection<?> parameterValues)
MockMvcRequestSpecification
given().param("cars", asList("Volvo", "Saab"))..;This will set the parameter
cars=Volvo
and cars=Saab
.
param
in interface MockMvcRequestSpecification
parameterName
- The parameter nameparameterValues
- The parameter valuespublic MockMvcRequestSpecification queryParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
MockMvcRequestSpecification
MockMvcRequestSpecification.params(String, Object, Object...)
for all http methods except for POST where MockMvcRequestSpecification.params(String, Object, Object...)
sets the form parameters and this method sets the
query parameters.queryParams
in interface MockMvcRequestSpecification
firstParameterName
- The name of the first parameterfirstParameterValue
- The value of the first parameterparameterNameValuePairs
- The value of the first parameter followed by additional parameters in name-value pairs.public MockMvcRequestSpecification queryParams(Map<String,?> parametersMap)
MockMvcRequestSpecification
MockMvcRequestSpecification.params(Map)
for all http methods except for POST where MockMvcRequestSpecification.params(Map)
sets the form parameters and this method sets the
query parameters.queryParams
in interface MockMvcRequestSpecification
parametersMap
- The Map containing the parameter names and their values to send with the request.public MockMvcRequestSpecification queryParam(String parameterName, Object... parameterValues)
MockMvcRequestSpecification
MockMvcRequestSpecification.param(String, Object...)
for all http methods except for POST where MockMvcRequestSpecification.param(String, Object...)
adds a form parameter and this method sets a
query parameter.queryParam
in interface MockMvcRequestSpecification
parameterName
- The parameter nameparameterValues
- Zero to many parameter values, i.e. you can specify multiple values for the same parameterMockMvcRequestSpecification.param(String, Object...)
public MockMvcRequestSpecification queryParam(String parameterName, Collection<?> parameterValues)
MockMvcRequestSpecification
given().queryParam("cars", asList("Volvo", "Saab"))..;This will set the parameter
cars=Volvo
and cars=Saab
.
Note that this method is the same as MockMvcRequestSpecification.param(String, java.util.Collection)
for all http methods except for POST where MockMvcRequestSpecification.param(String, java.util.Collection)
adds a form parameter and
this method sets a query parameter.queryParam
in interface MockMvcRequestSpecification
parameterName
- The parameter nameparameterValues
- The parameter valuespublic MockMvcRequestSpecification formParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
MockMvcRequestSpecification
MockMvcRequestSpecification.params(String, Object, Object...)
for all http methods except for POST where MockMvcRequestSpecification.params(String, Object, Object...)
sets the form parameters and this method sets the
form parameters.formParams
in interface MockMvcRequestSpecification
firstParameterName
- The name of the first parameterfirstParameterValue
- The value of the first parameterparameterNameValuePairs
- The value of the first parameter followed by additional parameters in name-value pairs.public MockMvcRequestSpecification formParams(Map<String,?> parametersMap)
MockMvcRequestSpecification
MockMvcRequestSpecification.params(Map)
for all http methods except for POST where MockMvcRequestSpecification.params(Map)
sets the form parameters and this method sets the
form parameters.formParams
in interface MockMvcRequestSpecification
parametersMap
- The Map containing the parameter names and their values to send with the request.public MockMvcRequestSpecification formParam(String parameterName, Object... parameterValues)
MockMvcRequestSpecification
MockMvcRequestSpecification.param(String, Object...)
for all http methods except for POST where MockMvcRequestSpecification.param(String, Object...)
adds a form parameter and this method sets a
form parameter.formParam
in interface MockMvcRequestSpecification
parameterName
- The parameter nameparameterValues
- Zero to many parameter values, i.e. you can specify multiple values for the same parameterMockMvcRequestSpecification.param(String, Object...)
public MockMvcRequestSpecification formParam(String parameterName, Collection<?> parameterValues)
MockMvcRequestSpecification
given().formParam("cars", asList("Volvo", "Saab"))..;This will set the parameter
cars=Volvo
and cars=Saab
.
Note that this method is the same as MockMvcRequestSpecification.param(String, java.util.Collection)
for all http methods except for POST where MockMvcRequestSpecification.param(String, java.util.Collection)
adds a form parameter and
this method sets a form parameter.formParam
in interface MockMvcRequestSpecification
parameterName
- The parameter nameparameterValues
- The parameter valuespublic MockMvcRequestSpecification attribute(String attributeName, Object attributeValue)
MockMvcRequestSpecification
attribute
in interface MockMvcRequestSpecification
attributeName
- The attribute nameattributeValue
- The attribute valuepublic MockMvcRequestSpecification attributes(Map<String,?> attributesMap)
MockMvcRequestSpecification
attributes
in interface MockMvcRequestSpecification
attributesMap
- The Map containing the request attribute names and their valuespublic MockMvcRequestSpecification body(String body)
MockMvcRequestSpecification
Example of use:
given().body("{ \"message\" : \"hello world\"}").then().expect().body(equalTo("hello world")).when().post("/json");This will POST a request containing JSON to "/json" and expect that the response body equals to "hello world".
body
in interface MockMvcRequestSpecification
body
- The body to send.public MockMvcRequestSpecification body(byte[] body)
MockMvcRequestSpecification
Example of use:
byte[] someBytes = .. given().body(someBytes).then().expect().body(equalTo("hello world")).when().post("/json");This will POST a request containing
someBytes
to "/json" and expect that the response body equals to "hello world".
body
in interface MockMvcRequestSpecification
body
- The body to send.public MockMvcRequestSpecification body(File body)
MockMvcRequestSpecification
Example of use:
File myFile = .. given().content(myFile).when().post("/json").then().content(equalTo("hello world"));This will POST a request containing
myFile
to "/json" and expect that the response content equals to "hello world".
body
in interface MockMvcRequestSpecification
body
- The content to send.public MockMvcRequestSpecification body(Object object)
MockMvcRequestSpecification
Example of use:
Message message = new Message(); message.setMessage("My beautiful message"); given(). contentType("application/json"). body(message). expect(). content(equalTo("Response to a beautiful message")). when(). post("/beautiful-message");Since the content-type is "application/json" then REST Assured will automatically try to serialize the object using Jackson or Gson if they are available in the classpath. If any of these frameworks are not in the classpath then an exception is thrown.
body
in interface MockMvcRequestSpecification
object
- The object to serialize and send with the requestpublic MockMvcRequestSpecification body(Object object, io.restassured.mapper.ObjectMapper mapper)
MockMvcRequestSpecification
Message message = new Message(); message.setMessage("My beautiful message"); given(). body(message, new MyObjectMapper()). expect(). content(equalTo("Response to a beautiful message")). when(). post("/beautiful-message");
body
in interface MockMvcRequestSpecification
object
- The object to serialize and send with the requestmapper
- The object mapperpublic MockMvcRequestSpecification body(Object object, io.restassured.mapper.ObjectMapperType mapperType)
MockMvcRequestSpecification
Message message = new Message(); message.setMessage("My beautiful message"); given(). body(message, ObjectMapper.GSON). expect(). content(equalTo("Response to a beautiful message")). when(). post("/beautiful-message");
body
in interface MockMvcRequestSpecification
object
- The object to serialize and send with the requestmapperType
- The object mapper type to be usedpublic MockMvcRequestSpecification cookies(String firstCookieName, Object firstCookieValue, Object... cookieNameValuePairs)
MockMvcRequestSpecification
given().cookies("username", "John", "token", "1234").then().expect().body(equalTo("username, token")).when().get("/cookie");This will send a GET request to "/cookie" with two cookies:
cookies
in interface MockMvcRequestSpecification
firstCookieName
- The name of the first cookiefirstCookieValue
- The value of the first cookiecookieNameValuePairs
- Additional cookies in name-value pairs.public MockMvcRequestSpecification cookies(Map<String,?> cookies)
MockMvcRequestSpecification
Map<String, String> cookies = new HashMap<String, String>(); cookies.put("username", "John"); cookies.put("token", "1234"); given().cookies(cookies).then().expect().body(equalTo("username, token")).when().get("/cookie");This will send a GET request to "/cookie" with two cookies:
cookies
in interface MockMvcRequestSpecification
cookies
- The Map containing the cookie names and their values to set in the request.public MockMvcRequestSpecification cookies(io.restassured.http.Cookies cookies)
MockMvcRequestSpecification
Cookies
:
Cookie cookie1 = Cookie.Builder("username", "John").setComment("comment 1").build(); Cookie cookie2 = Cookie.Builder("token", 1234).setComment("comment 2").build(); Cookies cookies = new Cookies(cookie1, cookie2); given().cookies(cookies).then().expect().body(equalTo("username, token")).when().get("/cookie");This will send a GET request to "/cookie" with two cookies:
cookies
in interface MockMvcRequestSpecification
cookies
- The cookies to set in the request.public MockMvcRequestSpecification cookie(String cookieName, Object cookieValue, Object... additionalValues)
MockMvcRequestSpecification
given().cookie("username", "John").and().expect().body(equalTo("username")).when().get("/cookie");This will set the cookie
username=John
in the GET request to "/cookie".
You can also specify several cookies like this:
given().cookie("username", "John").and().cookie("password", "1234").and().expect().body(equalTo("username")).when().get("/cookie");If you specify
additionalValues
then the Cookie will be a multi-value cookie. This means that you'll create several cookies with the
same name but with different values.cookie
in interface MockMvcRequestSpecification
cookieName
- The cookie cookieNamecookieValue
- The cookie valueadditionalValues
- Additional cookies values. This will actually create two cookies with the same name but with different values.MockMvcRequestSpecification.cookies(String, Object, Object...)
public MockMvcRequestSpecification cookie(io.restassured.http.Cookie cookie)
MockMvcRequestSpecification
Cookie
to send with the request.
Cookie someCookie = new Cookie.Builder("some_cookie", "some_value").setSecured(true).build(); given().cookie(someCookie).and().expect().body(equalTo("x")).when().get("/cookie");This will set the cookie
someCookie
in the GET request to "/cookie".
cookie
in interface MockMvcRequestSpecification
cookie
- The cookie to add to the requestMockMvcRequestSpecification.cookies(Cookies)
public MockMvcRequestSpecification multiPart(File file)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
file
- The file to uploadpublic MockMvcRequestSpecification multiPart(String controlName, File file)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.file
- The file to uploadpublic MockMvcRequestSpecification multiPart(String controlName, File file, String mimeType)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.file
- The file to uploadmimeType
- The mime-typepublic MockMvcRequestSpecification multiPart(String controlName, Object object)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.object
- The object to serialize to JSON or XML and send to the serverpublic MockMvcRequestSpecification multiPart(String controlName, Object object, String mimeType)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.object
- The object to serialize to JSON or XML and send to the servermimeType
- The mime-typepublic MockMvcRequestSpecification multiPart(String controlName, String filename, Object object, String mimeType)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.filename
- The name of the content you're uploadingobject
- The object to serialize to JSON or XML and send to the servermimeType
- The mime-typepublic MockMvcRequestSpecification multiPart(String controlName, String fileName, byte[] bytes)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.fileName
- The name of the content you're uploadingbytes
- The bytes you want to sendpublic MockMvcRequestSpecification multiPart(String controlName, String fileName, byte[] bytes, String mimeType)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.fileName
- The name of the content you're uploadingbytes
- The bytes you want to sendmimeType
- The mime-typepublic MockMvcRequestSpecification multiPart(String controlName, String fileName, InputStream stream)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.fileName
- The name of the content you're uploadingstream
- The stream you want to sendpublic MockMvcRequestSpecification multiPart(String controlName, String fileName, InputStream stream, String mimeType)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.fileName
- The name of the content you're uploadingstream
- The stream you want to sendmimeType
- The mime-typepublic MockMvcRequestSpecification multiPart(String controlName, String contentBody)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.contentBody
- The string to sendpublic MockMvcRequestSpecification multiPart(String controlName, String contentBody, String mimeType)
MockMvcRequestSpecification
multiPart
in interface MockMvcRequestSpecification
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.contentBody
- The string to sendmimeType
- The mime-typepublic MockMvcRequestSpecification config(RestAssuredMockMvcConfig config)
MockMvcRequestSpecification
given().config(newConfig().logConfig(new LogConfig(captor, true))). ..
newConfig()
can be statically imported from RestAssuredMockMvcConfig
.config
in interface MockMvcRequestSpecification
config
- The configuration to use for this request. If null
no config will be used.public MockMvcRequestSpecification spec(MockMvcRequestSpecification requestSpecificationToMerge)
MockMvcRequestSpecification
MockMvcRequestSpecification requestSpec = new MockMvcRequestSpecBuilder().addParam("parameter1", "value1").build(); given(). spec(requestSpec). param("parameter2", "value2"). when(). get("/something");This is useful when you want to reuse an entire specification across multiple requests. The specification passed to this method is merged with the current specification. Note that the supplied specification can overwrite data in the current specification. The following settings are overwritten:
requestSpecificationToMerge
)spec
in interface MockMvcRequestSpecification
requestSpecificationToMerge
- The specification to merge with.public MockMvcRequestSpecification sessionAttrs(Map<String,Object> sessionAttributes)
sessionAttrs
in interface MockMvcRequestSpecification
sessionAttributes
- the session attributespublic MockMvcRequestSpecification sessionId(String sessionIdValue)
MockMvcRequestSpecification
RestAssured.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));or you can use the
MockMvcRequestSpecification.sessionId(String, String)
method to set it for this request only.sessionId
in interface MockMvcRequestSpecification
sessionIdValue
- The session id value.public MockMvcRequestSpecification sessionId(String sessionIdName, String sessionIdValue)
MockMvcRequestSpecification
RestAssured.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));and then you can use the
MockMvcRequestSpecification.sessionId(String)
method to set the session id value without specifying the name for each request.sessionId
in interface MockMvcRequestSpecification
sessionIdName
- The session id namesessionIdValue
- The session id value.public MockMvcRequestSpecification resultHandlers(org.springframework.test.web.servlet.ResultHandler resultHandler, org.springframework.test.web.servlet.ResultHandler... resultHandlers)
public MockMvcRequestAsyncSender when()
MockMvcRequestSpecification
when
in interface MockMvcRequestSpecification
MockMvcRequestSender
that let's you send the request.public MockMvcResponse get(String path, Object... pathParams)
get
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse get(String path, Map<String,?> pathParams)
get
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse post(String path, Object... pathParams)
post
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse post(String path, Map<String,?> pathParams)
post
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse put(String path, Object... pathParams)
put
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse put(String path, Map<String,?> pathParams)
put
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse delete(String path, Object... pathParams)
delete
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse delete(String path, Map<String,?> pathParams)
delete
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse head(String path, Object... pathParams)
head
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse head(String path, Map<String,?> pathParams)
head
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse patch(String path, Object... pathParams)
patch
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse patch(String path, Map<String,?> pathParams)
patch
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse options(String path, Object... pathParams)
options
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse options(String path, Map<String,?> pathParams)
options
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse get(URI uri)
get
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse post(URI uri)
post
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse put(URI uri)
put
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse delete(URI uri)
delete
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse head(URI uri)
head
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse patch(URI uri)
patch
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse options(URI uri)
options
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse get(URL url)
get
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse post(URL url)
post
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse put(URL url)
put
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse delete(URL url)
delete
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse head(URL url)
head
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse patch(URL url)
patch
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse options(URL url)
options
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse get()
get
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse post()
post
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse put()
put
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse delete()
delete
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse head()
head
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse patch()
patch
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse options()
options
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse request(io.restassured.http.Method method)
request
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse request(String method)
request
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse request(io.restassured.http.Method method, String path, Object... pathParams)
request
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse request(String method, String path, Object... pathParams)
request
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse request(io.restassured.http.Method method, URI uri)
request
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse request(io.restassured.http.Method method, URL url)
request
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse request(String method, URI uri)
request
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public MockMvcResponse request(String method, URL url)
request
in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
public io.restassured.config.RestAssuredConfig getRestAssuredConfig()
public void setRequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter requestLoggingFilter)
public MockMvcFactory getMockMvcFactory()
public String getBasePath()
public Object getRequestBody()
public Object getAuthentication()
public RestAssuredMockMvcConfig getRestAssuredMockMvcConfig()
public io.restassured.http.Headers getRequestHeaders()
public io.restassured.http.Cookies getCookies()
public String getRequestContentType()
public List<io.restassured.module.mockmvc.internal.MockMvcMultiPart> getMultiParts()
public io.restassured.filter.log.RequestLoggingFilter getRequestLoggingFilter()
public List<org.springframework.test.web.servlet.ResultHandler> getResultHandlers()
public List<org.springframework.test.web.servlet.request.RequestPostProcessor> getRequestPostProcessors()
public MockHttpServletRequestBuilderInterceptor getInterceptor()
public MockMvcRequestSpecification basePath(String path)
public MockMvcRequestSpecification principal(Principal principal)
MockMvcAuthenticationSpecification
MockHttpServletRequestBuilder.principal(java.security.Principal)
.principal
in interface MockMvcAuthenticationSpecification
principal
- The principal to use.MockHttpServletRequestBuilder.principal(java.security.Principal)
public MockMvcRequestSpecification with(org.springframework.test.web.servlet.request.RequestPostProcessor requestPostProcessor, org.springframework.test.web.servlet.request.RequestPostProcessor... additionalRequestPostProcessor)
MockMvcAuthenticationSpecification
RequestPostProcessor
.
This is mainly useful when you have added the spring-security-test
artifact to classpath. This allows
you to do for example:
given().auth().with(user("username").password("password")). ..where
user
is statically imported from org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors
.with
in interface MockMvcAuthenticationSpecification
requestPostProcessor
- The first request post processor to be used for authenticationadditionalRequestPostProcessor
- Additional request post processors to be used for authenticationMockMvcAuthenticationScheme
instance.public MockMvcRequestSpecification principal(Object principal)
MockMvcAuthenticationSpecification
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(principal, ""));
Note that this method require Spring Security to be on the classpath. Also note that if you use this method Rest Assured will NOT be thread-safe.
principal
in interface MockMvcAuthenticationSpecification
principal
- The principal to use.public MockMvcRequestSpecification principalWithCredentials(Object principal, Object credentials, String... authorities)
MockMvcAuthenticationSpecification
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(principal, credentials, authorities));
Note that this method require Spring Security to be on the classpath. Also note that if you use this method Rest Assured will NOT be thread-safe.
principalWithCredentials
in interface MockMvcAuthenticationSpecification
principal
- The principal to use.credentials
- The credentials to useauthorities
- Optional list of authoritiespublic MockMvcRequestSpecification authentication(Object authentication)
MockMvcAuthenticationSpecification
SecurityContextHolder.getContext().setAuthentication(authentication);This means that the supplied object must be an instance of
org.springframework.security.core.Authentication
.
Note that this method require Spring Security to be on the classpath. Also note that if you use this method Rest Assured will NOT be thread-safe.
authentication
in interface MockMvcAuthenticationSpecification
authentication
- the spring security authentication to use.public MockMvcRequestSpecification none()
MockMvcAuthenticationSpecification
none
in interface MockMvcAuthenticationSpecification
public io.restassured.internal.log.LogRepository getLogRepository()
public AsyncConfig getAsyncConfig()
public MockMvcRequestSpecification sessionAttr(String name, Object value)
sessionAttr
in interface MockMvcRequestSpecification
name
- the session attribute namevalue
- the session attribute valueCopyright © 2010–2019. All rights reserved.