Package com.jcabi.http.request
Class FakeRequest
java.lang.Object
com.jcabi.http.request.FakeRequest
- All Implemented Interfaces:
Request
Implementation of
Request that always returns the same
response, specified in the constructor.
The class is immutable and thread-safe.
- Since:
- 0.9 // @checkstyle ClassDataAbstractionCoupling (500 lines)
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionPublic ctor.FakeRequest(int status, String reason, Collection<Map.Entry<String, String>> headers, byte[] body) Public ctor. -
Method Summary
Modifier and TypeMethodDescriptionbody()Get request body.fetch()Execute it with a specified HTTP method.fetch(InputStream stream) Execute this request using the content provided by theInputStreambeing passed as the request body.Set request header.Use this method.Get multipart form (multipart/form-data) body.Remove all headers with this name.Send it through a decoratingWire.Send it through a decoratingWire.timeout(int connect, int read) Use this timeout values.toString()uri()Get destination URI.withBody(byte[] body) Make a similar request, with the provided body.Make a similar request, with the provided body.withHeader(String name, String value) Make a similar request, with the provided HTTP header.withReason(String reason) Make a similar request, with the provided reason line.withStatus(int status) Make a similar request, with the provided status code.
-
Constructor Details
-
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 Details
-
toString
-
uri
Description copied from interface:RequestGet destination URI. -
header
Description copied from interface:RequestSet request header. -
reset
Description copied from interface:RequestRemove all headers with this name. -
body
Description copied from interface:RequestGet request body. -
multipartBody
Description copied from interface:RequestGet multipart form (multipart/form-data) body.- Specified by:
multipartBodyin interfaceRequest- Returns:
- New altered request
-
method
Description copied from interface:RequestUse this method. -
timeout
Description copied from interface:RequestUse this timeout values. -
fetch
Description copied from interface:RequestExecute it with a specified HTTP method.- Specified by:
fetchin interfaceRequest- Returns:
- Response
- Throws:
IOException- If fails to fetch HTTP request
-
fetch
Description copied from interface:RequestExecute this request using the content provided by theInputStreambeing 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:
fetchin interfaceRequest- Parameters:
stream- The input stream to use- Returns:
- Response
- Throws:
IOException- If fails to fetch HTTP request
-
through
Description copied from interface:RequestSend it through a decoratingWire. -
through
Description copied from interface:RequestSend it through a decoratingWire. -
withStatus
Make a similar request, with the provided status code.- Parameters:
status- The code- Returns:
- New request
-
withReason
Make a similar request, with the provided reason line.- Parameters:
reason- Reason line- Returns:
- New request
-
withHeader
Make a similar request, with the provided HTTP header.- Parameters:
name- Name of the headervalue- Value of it- Returns:
- New request
-
withBody
Make a similar request, with the provided body.- Parameters:
text- Body- Returns:
- New request
-
withBody
Make a similar request, with the provided body.- Parameters:
body- Body- Returns:
- New request
-