Package org.javalite.activeweb
Class RequestBuilder
java.lang.Object
org.javalite.activeweb.RequestBuilder
Class is used in DSL for building a fake request for a controller to be tested. This class is not used directly.
- Author:
- Igor Polevoy
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncontent(byte[] content)
Use to post content to a tested controller.Use to post content to a tested controller.contentType(String contentType)
Sets content type on request.Adds cookie to current request.void
Simulate HTTP DELETE call to an action of controller.Sets format for this request.Convenience method to add a non-file form item to request.Adds an "uploaded" file to the request.Adds "uploaded" file to the request.Convenience method for sending pairs of name and values with multi-part request.void
Simulate HTTP GET call to an action of controller.Sets a single header for the request.Convenience method to set names and values for headers.Sets ID for this request.void
Simulate HTTP OPTIONS call to an action of controller.Convenience method, exists to pass parameters with blank values.Sets a single parameter for request.Convenience method for setting parameters of the request.void
Simulate HTTP POST call to an action of controller.void
Simulate HTTP PUT call to an action of controller.queryString(String queryString)
Sets a query string (as in URL) for the request.remoteAddress(String remoteAddress)
Use to simulate a remote IP address.
-
Constructor Details
-
RequestBuilder
-
-
Method Details
-
formItem
Convenience method to add a non-file form item to request. Will callformItem(String, String, boolean, String, byte[])
internally. Content type will be set to "text/plain", and "isFile" to false.- Parameters:
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 item- Returns:
-
formItems
Convenience method for sending pairs of name and values with multi-part request.- Parameters:
namesAndValues
- names and following corresponding values. The following pattern is expected: name,value,name1,value1...- Returns:
-
formItem
public RequestBuilder formItem(String fileName, String fieldName, boolean isFile, String contentType, byte[] content)Adds an "uploaded" file to the request. Do not forget to set the content type to: "multipart/form-data", or this method will be ignored.- Parameters:
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.- Returns:
RequestBuilder
for setting additional request parameters.
-
formItem
Adds "uploaded" file to the request. Do not forget to set the content type to: "multipart/form-data", or this method will be ignored.- Parameters:
item
- this can be an instance of aFormItem
orFileItem
.- Returns:
RequestBuilder
for setting additional request parameters.
-
param
Sets a single parameter for request.For parameters with multiple values, set the value to be
List
- Parameters:
name
- name of parameter.value
- value of parameter.- Returns:
- instance of RequestBuilder.
-
param
Convenience method, exists to pass parameters with blank values. Calling this method such as:param("flag")
is equivalent to:param("flag", "")
- Parameters:
name
- name of parameter to pass- Returns:
- instance of RequestBuilder.
-
header
Sets a single header for the request.- Parameters:
name
- name of header.value
- value of header.- Returns:
- instance of RequestBuilder.
-
headers
Convenience method to set names and values for headers. If arguments are indexed from 1, then every odd argument is a name and every even argument that follows it is a value corresponding to the preceding odd argument.- Parameters:
namesAndValues
- names and following corresponding values- Returns:
- instance of RequestBuilder
-
params
Convenience method for setting parameters of the request. If arguments are indexed from 1, then every odd argument is a name and every even argument that follows it is a value corresponding to the preceding odd argument.For parameters with multiple values, set the value to be
List
- Parameters:
namesAndValues
- names and following corresponding values- Returns:
- instance of RequestBuilder.
-
contentType
Sets content type on request.- Parameters:
contentType
- content type.- Returns:
- instance of RequestBuilder
-
cookie
Adds cookie to current request. -
content
Use to post content to a tested controller.- Parameters:
content
- content string- Returns:
- self
-
content
Use to post content to a tested controller.- Parameters:
content
- content bytes- Returns:
- self
-
get
Simulate HTTP GET call to an action of controller.- Parameters:
actionName
- name of action as on a URL - not CamelCase.
-
post
Simulate HTTP POST call to an action of controller.- Parameters:
actionName
- name of action as on a URL - not CamelCase.
-
put
Simulate HTTP PUT call to an action of controller.- Parameters:
actionName
- name of action as on a URL - not CamelCase.
-
delete
Simulate HTTP DELETE call to an action of controller.- Parameters:
actionName
- name of action as on a URL - not CamelCase.
-
options
Simulate HTTP OPTIONS call to an action of controller.- Parameters:
actionName
- name of action as on a URL - not CamelCase.
-
id
Sets ID for this request. This method will convert ID value to string before executing a controller.- Parameters:
id
- id for this request; this value is accessible inside controller withgetId()
method.
-
format
Sets format for this request. Format is the part of URI that is trailing after a last dot, as in: /books.xml, here "xml" is a format.- Parameters:
format
- format for this request.
-
queryString
Sets a query string (as in URL) for the request.- Parameters:
queryString
- query string value- Returns:
- instance of RequestBuilder.
-
remoteAddress
Use to simulate a remote IP address. UseRequestAccess.remoteAddress()
to retrieve it.- Parameters:
remoteAddress
- simulated remote IP address.
-