public class RequestBuilder extends Object
Constructor and Description |
---|
RequestBuilder(String controllerPath,
SessionTestFacade sessionFacade) |
Modifier and Type | Method and Description |
---|---|
RequestBuilder |
content(byte[] content) |
RequestBuilder |
contentType(String contentType)
Sets content type on request.
|
RequestBuilder |
cookie(Cookie cookie)
Adds cookie to current request.
|
void |
delete(String actionName)
Simulate HTTP DELETE call to an action of controller.
|
RequestBuilder |
format(String format)
Sets format for this request.
|
RequestBuilder |
formItem(FormItem item)
Adds "uploaded" file to the request.
|
RequestBuilder |
formItem(Object fieldName,
Object value)
Convenience method to add a non-file form item to request.
|
RequestBuilder |
formItem(String fileName,
String fieldName,
boolean isFile,
String contentType,
byte[] content)
Adds an "uploaded" file to the request.
|
RequestBuilder |
formItems(Object... namesAndValues)
Convenience method for sending pairs of name and values with multi-part request.
|
void |
get(String actionName)
Simulate HTTP GET call to an action of controller.
|
RequestBuilder |
header(String name,
String value)
Sets a single header for the request.
|
RequestBuilder |
headers(String... namesAndValues)
Convenience method to set names and values for headers.
|
RequestBuilder |
id(Object id)
Sets ID for this request.
|
void |
options(String actionName)
Simulate HTTP OPTIONS call to an action of controller.
|
RequestBuilder |
param(String name)
Convenience method, exists to pass parameters with blank values.
|
RequestBuilder |
param(String name,
Object value)
Sets a single parameter for request.
|
RequestBuilder |
params(Object... namesAndValues)
Convenience method for setting parameters of the request.
|
void |
post(String actionName)
Simulate HTTP POST call to an action of controller.
|
void |
put(String actionName)
Simulate HTTP PUT call to an action of controller.
|
RequestBuilder |
queryString(String queryString)
Sets a query string (as in URL) for the request.
|
RequestBuilder |
remoteAddress(String remoteAddress)
Use to simulate a remote IP address.
|
public RequestBuilder(String controllerPath, SessionTestFacade sessionFacade)
public RequestBuilder formItem(Object fieldName, Object value)
formItem(String, String, boolean, String, byte[])
internally.
Content type will be set to "text/plain", and "isFile" to false.fieldName
- name of field - toString() will be used to add to form itemvalue
- - value of parameter, toString().getBytes() will be used to add to form itemRequestBuilder
for setting additional request parameters.#formItem(String, String, boolean, String, byte[])}
public RequestBuilder formItems(Object... namesAndValues)
namesAndValues
- names and following corresponding values. The following pattern is expected:
name,value,name1,value1...RequestBuilder
for setting additional request parameters.public RequestBuilder formItem(String fileName, String fieldName, boolean isFile, String contentType, byte[] content)
fileName
- name of file.fieldName
- name of field name - this is typically a name of a HTML form field.isFile
- set true for file, false for regular field.contentType
- this is content type for this field, not the request. Set to a value reflecting the file
content, such as "image/png", "application/pdf", etc.content
- this is the binary content of the file.RequestBuilder
for setting additional request parameters.public RequestBuilder formItem(FormItem item)
item
- this can be an instance of a FormItem
or FileItem
.RequestBuilder
for setting additional request parameters.public RequestBuilder param(String name, Object value)
For parameters with multiple values, set the value to be List
name
- name of parameter.value
- value of parameter.public RequestBuilder param(String name)
param("flag")
is equivalent to:
param("flag", "")
name
- name of parameter to passpublic RequestBuilder header(String name, String value)
name
- name of header.value
- value of header.public RequestBuilder headers(String... namesAndValues)
namesAndValues
- names and following corresponding valuespublic RequestBuilder params(Object... namesAndValues)
For parameters with multiple values, set the value to be List
namesAndValues
- names and following corresponding valuespublic RequestBuilder contentType(String contentType)
contentType
- content type.public RequestBuilder cookie(Cookie cookie)
public RequestBuilder content(byte[] content)
public void get(String actionName)
actionName
- name of action as on a URL - not CamelCase.public void post(String actionName)
actionName
- name of action as on a URL - not CamelCase.public void put(String actionName)
actionName
- name of action as on a URL - not CamelCase.public void delete(String actionName)
actionName
- name of action as on a URL - not CamelCase.public void options(String actionName)
actionName
- name of action as on a URL - not CamelCase.public RequestBuilder id(Object id)
id
- id for this request; this value is accessible inside controller with getId()
method.public RequestBuilder format(String format)
format
- format for this request.HttpSupport#format()}
public RequestBuilder queryString(String queryString)
queryString
- query string valuepublic RequestBuilder remoteAddress(String remoteAddress)
HttpSupport.remoteAddress()
to retrieve it.remoteAddress
- simulated remote IP address.Copyright © 2019 JavaLite. All rights reserved.