@Immutable @Loggable(value=1) public final class FakeRequest extends Object implements Request
Request
that always returns the same
response, specified in the constructor.
The class is immutable and thread-safe.
Constructor and Description |
---|
FakeRequest()
Public ctor.
|
FakeRequest(int status,
String reason,
Collection<Map.Entry<String,String>> headers,
byte[] body)
Public ctor.
|
Modifier and Type | Method and Description |
---|---|
RequestBody |
body()
Get request body.
|
Response |
fetch()
Execute it with a specified HTTP method.
|
Request |
header(String name,
Object value)
Set request header.
|
Request |
method(String method)
Use this method.
|
Request |
reset(String name)
Remove all headers with this name.
|
<T extends Wire> |
through(Class<T> type,
Object... args)
Send it through a decorating
Wire . |
String |
toString() |
RequestURI |
uri()
Get destination URI.
|
FakeRequest |
withBody(byte[] body)
Make a similar request, with the provided body.
|
FakeRequest |
withBody(String text)
Make a similar request, with the provided body.
|
FakeRequest |
withHeader(String name,
String value)
Make a similar request, with the provided HTTP header.
|
FakeRequest |
withReason(String reason)
Make a similar request, with the provided reason line.
|
FakeRequest |
withStatus(int status)
Make a similar request, with the provided status code.
|
public FakeRequest()
public FakeRequest(int status, @NotNull(message="HTTP reason can\'t be NULL") String reason, @NotNull(message="list of headers can\'t be NULL") Collection<Map.Entry<String,String>> headers, @NotNull(message="body can\'t be NULL") byte[] body)
status
- HTTP status code to returnreason
- HTTP reasonheaders
- HTTP headersbody
- HTTP body@NotNull public RequestURI uri()
Request
public Request header(@NotNull(message="header name can\'t be NULL") String name, @NotNull(message="header value can\'t be NULL") Object value)
Request
public Request reset(@NotNull(message="header name can\'t be NULL") String name)
Request
public RequestBody body()
Request
public Request method(@NotNull(message="method can\'t be NULL") String method)
Request
public Response fetch() throws IOException
Request
fetch
in interface Request
IOException
- If fails to fetch HTTP requestpublic <T extends Wire> Request through(Class<T> type, Object... args)
Request
Wire
.public FakeRequest withStatus(int status)
status
- The codepublic FakeRequest withReason(String reason)
reason
- Reason linepublic FakeRequest withHeader(String name, String value)
name
- Name of the headervalue
- Value of itpublic FakeRequest withBody(String text)
text
- Bodypublic FakeRequest withBody(byte[] body)
body
- BodyCopyright © 2012–2014 jcabi.com. All rights reserved.