MockRequestBuilder class final
Describes one request for MockMvc.perform: method, path, headers, query parameters, cookies, user and body.
The shortcuts of MockMvc (MockMvc.get, MockMvc.post and the others) build it for you; build it yourself for cookies, a principal, a RequestPostProcessor (a test user, a CSRF token) or a method without a shortcut. Its collections are mutable, so a cascade fills them.
await mvc.perform(
MockRequestBuilder(HttpMethod.get, '/api/books')
..params['q'] = 'dune'
..headers['Accept'] = 'application/json',
).andExpect(status: 200);
Spring (Java): MockHttpServletRequestBuilder, from get(...),
post(...) and the other MockMvcRequestBuilders.
Constructors
-
MockRequestBuilder(HttpMethod method, String path, [List<
Object?> uriVariables = const []]) -
A
methodrequest topath. Each{name}placeholder ofpathis filled, in order, fromuriVariables, URL-encoded; extra placeholders stay as written.
Properties
-
Cookies to send, by name.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
headers
→ Map<
String, String> -
The headers to send, by name.
final
- method → HttpMethod
-
The HTTP method.
final
-
params
→ Map<
String, Object> -
Query parameters to add; a
Listvalue sends the parameter once per element.final - path → String
-
The path, with the URI variables filled in; it may carry a query
(
/api/books?q=dune).final - principal ↔ Principal?
-
The authenticated user the request comes from;
nullfor an anonymous request. Withspring_boot_starter_security, itsuser(...)post-processor sets a full security context instead.getter/setter pair - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
build(
) → MockServerHttpRequest - Builds the request; MockMvc calls it, and then applies the post-processors, which this does not.
-
content(
Object body) → void -
Sets the body: a
String(sent as UTF-8) or bytes. NoContent-Typeis added; set one in headers. -
json(
Object? value) → void -
Sets the body to
valueencoded as JSON, andContent-Type: application/jsonunless headers already have a content type. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
with_(
RequestPostProcessor processor) → void -
Adds
processor, which changes the request just before it is sent, after the MockMvc.defaultPostProcessors. Spring's.with(...); the trailing_is there becausewithis a Dart keyword.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited