Package com.jcabi.http.request
Class FakeRequest
- java.lang.Object
-
- com.jcabi.http.request.FakeRequest
-
- All Implemented Interfaces:
Request
@Immutable @Loggable(1) public final class FakeRequest extends Object implements Request
Implementation ofRequest
that always returns the same response, specified in the constructor.The class is immutable and thread-safe.
- Since:
- 0.9 // @checkstyle ClassDataAbstractionCoupling (500 lines)
-
-
Constructor Summary
Constructors Constructor Description FakeRequest()
Public ctor.FakeRequest(int status, String reason, Collection<Map.Entry<String,String>> headers, byte[] body)
Public ctor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RequestBody
body()
Get request body.Response
fetch()
Execute it with a specified HTTP method.Response
fetch(InputStream stream)
Execute this request using the content provided by theInputStream
being passed as the request body.Request
header(String name, Object value)
Set request header.Request
method(String method)
Use this method.RequestBody
multipartBody()
Get multipart form (multipart/form-data) body.Request
reset(String name)
Remove all headers with this name.Request
through(Wire wire)
Send it through a decoratingWire
.<T extends Wire>
Requestthrough(Class<T> type, Object... args)
Send it through a decoratingWire
.Request
timeout(int connect, int read)
Use this timeout values.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.
-
-
-
Constructor Detail
-
FakeRequest
public FakeRequest()
Public ctor.
-
FakeRequest
public FakeRequest(int status, String reason, Collection<Map.Entry<String,String>> headers, byte[] body)
Public ctor.- Parameters:
status
- HTTP status code to returnreason
- HTTP reasonheaders
- HTTP headersbody
- HTTP body
-
-
Method Detail
-
uri
public RequestURI uri()
Description copied from interface:Request
Get destination URI.
-
header
public Request header(String name, Object value)
Description copied from interface:Request
Set request header.
-
reset
public Request reset(String name)
Description copied from interface:Request
Remove all headers with this name.
-
body
public RequestBody body()
Description copied from interface:Request
Get request body.
-
multipartBody
public RequestBody multipartBody()
Description copied from interface:Request
Get multipart form (multipart/form-data) body.- Specified by:
multipartBody
in interfaceRequest
- Returns:
- New altered request
-
method
public Request method(String method)
Description copied from interface:Request
Use this method.
-
timeout
public Request timeout(int connect, int read)
Description copied from interface:Request
Use this timeout values.
-
fetch
public Response fetch() throws IOException
Description copied from interface:Request
Execute it with a specified HTTP method.- Specified by:
fetch
in interfaceRequest
- Returns:
- Response
- Throws:
IOException
- If fails to fetch HTTP request
-
fetch
public Response fetch(InputStream stream) throws IOException
Description copied from interface:Request
Execute this request using the content provided by theInputStream
being passed as the request body. Note that the request MUST have an empty body when this method is being invoked, or it will throw anIllegalStateException
.- Specified by:
fetch
in interfaceRequest
- Parameters:
stream
- The input stream to use- Returns:
- Response
- Throws:
IOException
- If fails to fetch HTTP request
-
through
public <T extends Wire> Request through(Class<T> type, Object... args)
Description copied from interface:Request
Send it through a decoratingWire
.
-
through
public Request through(Wire wire)
Description copied from interface:Request
Send it through a decoratingWire
.
-
withStatus
public FakeRequest withStatus(int status)
Make a similar request, with the provided status code.- Parameters:
status
- The code- Returns:
- New request
-
withReason
public FakeRequest withReason(String reason)
Make a similar request, with the provided reason line.- Parameters:
reason
- Reason line- Returns:
- New request
-
withHeader
public FakeRequest withHeader(String name, String value)
Make a similar request, with the provided HTTP header.- Parameters:
name
- Name of the headervalue
- Value of it- Returns:
- New request
-
withBody
public FakeRequest withBody(String text)
Make a similar request, with the provided body.- Parameters:
text
- Body- Returns:
- New request
-
withBody
public FakeRequest withBody(byte[] body)
Make a similar request, with the provided body.- Parameters:
body
- Body- Returns:
- New request
-
-