public class MockRest extends Object implements MockHttpConnection
Allows you to test your REST resource classes without a running servlet container.
Modifier and Type | Class and Description |
---|---|
static class |
MockRest.Builder
Builder class.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
debug
Debug mode enabled.
|
protected Map<String,Object> |
headers
Requests headers to add to every request.
|
Modifier | Constructor and Description |
---|---|
protected |
MockRest(MockRest.Builder b)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static MockRest |
build(Object impl)
Convenience method for creating a MockRest over the specified REST implementation bean or bean class.
|
static MockRest |
build(Object impl,
Marshall m)
Convenience method for creating a MockRest over the specified REST implementation bean or bean class.
|
static MockRest |
build(Object impl,
Serializer s,
Parser p)
Convenience method for creating a MockRest over the specified REST implementation bean or bean class.
|
MockServletRequest |
connect(String path)
Perform a CONNECT request.
|
static MockRest.Builder |
create(Object impl)
Creates a new builder with the specified REST implementation bean or bean class.
|
MockServletRequest |
delete(String path)
Perform a DELETE request.
|
MockServletRequest |
get()
Shortcut for
get( |
MockServletRequest |
get(String path)
Perform a GET request.
|
Map<String,Object> |
getHeaders()
Returns the headers that were defined in this class.
|
MockServletRequest |
head(String path)
Perform a HEAD request.
|
MockServletRequest |
options(String path)
Perform an OPTIONS request.
|
MockServletRequest |
patch(String path,
Object body)
Perform a PATCH request.
|
MockServletRequest |
post(String path,
Object body)
Perform a POST request.
|
MockServletRequest |
put(String path,
Object body)
Perform a PUT request.
|
MockServletRequest |
request(String method,
Map<String,Object> headers,
String path)
Performs a REST request against the REST interface.
|
MockServletRequest |
request(String method,
String path)
Performs a REST request against the REST interface.
|
MockServletRequest |
request(String method,
String path,
Map<String,Object> headers,
Object body)
Performs a REST request against the REST interface.
|
MockServletRequest |
request(String method,
String path,
Object body)
Performs a REST request against the REST interface.
|
MockServletRequest |
trace(String path)
Perform a TRACE request.
|
protected final boolean debug
protected MockRest(MockRest.Builder b)
b
- Builder.public static MockRest.Builder create(Object impl)
No
impl
- The REST bean or bean class annotated with @RestResource
.
public static MockRest build(Object impl)
Equivalent to calling:
MockRest.create(impl, SimpleJson.
impl
- The REST bean or bean class annotated with @RestResource
.
MockRest
object.public static MockRest build(Object impl, Marshall m)
Note that the marshall itself is not involved in any serialization or parsing.
Equivalent to calling:
MockRest.create(impl, SimpleJson.
impl
- The REST bean or bean class annotated with @RestResource
.
m
- The marshall to use for specifying the MockRest
object.public static MockRest build(Object impl, Serializer s, Parser p)
Note that the marshall itself is not involved in any serialization or parsing.
Equivalent to calling:
MockRest.create(impl, SimpleJson.
impl
- The REST bean or bean class annotated with @RestResource
.
s
- The serializer to use for specifying the p
- The parser to use for specifying the MockRest
object.public MockServletRequest request(String method, String path, Map<String,Object> headers, Object body)
request
in interface MockHttpConnection
method
- The HTTP methodpath
- The URI path.headers
- Optional headers to include in the request.body
- The body of the request.
byte []
Reader
InputStream
CharSequence
public MockServletRequest request(String method, String path)
method
- The HTTP methodpath
- The URI path.public MockServletRequest request(String method, String path, Object body)
method
- The HTTP methodpath
- The URI path.body
- The body of the request.
byte []
Reader
InputStream
CharSequence
public MockServletRequest request(String method, Map<String,Object> headers, String path)
method
- The HTTP methodheaders
- Optional headers to include in the request.path
- The URI path.public MockServletRequest get(String path)
path
- The URI path.public MockServletRequest get()
get("" )
public MockServletRequest put(String path, Object body)
path
- The URI path.body
- The body of the request.
byte []
Reader
InputStream
CharSequence
public MockServletRequest post(String path, Object body)
path
- The URI path.body
- The body of the request.
byte []
Reader
InputStream
CharSequence
public MockServletRequest delete(String path)
path
- The URI path.public MockServletRequest head(String path)
path
- The URI path.public MockServletRequest options(String path)
path
- The URI path.public MockServletRequest patch(String path, Object body)
path
- The URI path.body
- The body of the request.
byte []
Reader
InputStream
CharSequence
public MockServletRequest connect(String path)
path
- The URI path.public MockServletRequest trace(String path)
path
- The URI path.public Map<String,Object> getHeaders()
Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.