Package org.javalite.activeweb
Class RequestSpecHelper
java.lang.Object
org.javalite.activeweb.SpecHelper
org.javalite.activeweb.RequestSpecHelper
- All Implemented Interfaces:
JSpecSupport
- Direct Known Subclasses:
ControllerSpec
,IntegrationSpec
This class is not used directly in applications.
- Author:
- Igor Polevoy
-
Nested Class Summary
Nested classes/interfaces inherited from class org.javalite.activeweb.SpecHelper
SpecHelper.DynamicBuilder, SpecHelper.ModuleBuilder
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Map
assigns()
Provides values assigned by controller during execution.void
protected byte[]
Provides content generated by controller as bytes.protected String
Provides content type set on response by controllerprotected Cookie
Returns a cookie from last response by name,null
if not found.protected String
cookieValue(String name)
Convenience method, returns cookie value.int
Parses controller response and counts elements that are found by a CSS query.protected Cookie[]
Returns all cookies from last response.protected String
Returns header set by controller or filter.Returns all headers set by controller or filter.headers()
Returns all headers set by controller or filter.protected String
layout()
Provides layout set after executing an action of a controller.protected boolean
Returns true after execution of an action that sent a redirect.protected String
Returns a redirect value if one was produced by a controller or filter, null if not.protected String
Provides content generated by controller after controller execution - if views were integrated.protected int
Provides status code set on response by controllerprotected String
template()
protected String
Parses controller response content and selects content of HTML element using CSS selectors.
Example:protected Object
Returns a single value assigned by controller.protected <T> T
Returns a single value assigned by controller.protected boolean
valBoolean(String name)
boolean value assigned by controller.protected double
double value assigned by controller.protected float
float value assigned by controller.protected int
valInteger(String name)
int value assigned by controller.protected long
long value assigned by controller.protected Map
vals()
Synonym ofassigns()
.protected String
String value assigned by controller.Methods inherited from class org.javalite.activeweb.SpecHelper
afterEnd, atStart, createInjector, flash, flash, flashExists, injector, registerTag, session, session, session, sessionBoolean, sessionDouble, sessionFloat, sessionHas, sessionInteger, sessionLong, sessionObject, sessionString, setInjector, setTemplateLocation
-
Constructor Details
-
RequestSpecHelper
public RequestSpecHelper()
-
-
Method Details
-
atStart00
@BeforeEach public final void atStart00() -
statusCode
protected int statusCode()Provides status code set on response by controller- Returns:
- status code set on response by controller
-
contentType
Provides content type set on response by controller- Returns:
- content type set on response by controller
-
responseContent
Provides content generated by controller after controller execution - if views were integrated.- Returns:
- content generated by controller/view
-
bytesContent
protected byte[] bytesContent()Provides content generated by controller as bytes.- Returns:
- byte array as it was written from controller.
-
layout
Provides layout set after executing an action of a controller.- Returns:
- layout set after executing an action of a controller.
-
template
-
assigns
Provides values assigned by controller during execution. These values will be forwarded to a view during normal processing.- Returns:
- values assigned by controller during execution
-
vals
Synonym ofassigns()
.- Returns:
- values assigned by controller during execution
-
val
Returns a single value assigned by controller.- Parameters:
name
- name of a value assigned by controller.- Returns:
- a single value assigned by controller.
-
val
Returns a single value assigned by controller.- Parameters:
name
- name of a value assigned by controller.type
- type to be returned.- Returns:
- a single value assigned by controller.
-
header
Returns header set by controller or filter.- Parameters:
headerName
- name of header- Returns:
- header value (can be null).
-
headers
Returns all headers set by controller or filter. If a header has more than one value, only one value is returned.- Returns:
- map of headers, where keys are names of headers, and values are header values.
-
headerNames
Returns all headers set by controller or filter. If a header has more than one value, only one is returned.- Returns:
- map of headers, where keys are names of headers, and values are header values.
-
valString
String value assigned by controller.- Parameters:
name
- name of a value assigned by controller.- Returns:
- a single value assigned by controller.
-
valInteger
int value assigned by controller.- Parameters:
name
- name of a value assigned by controller.- Returns:
- a single value assigned by controller.
-
valLong
long value assigned by controller.- Parameters:
name
- name of a value assigned by controller.- Returns:
- a single value assigned by controller.
-
valDouble
double value assigned by controller.- Parameters:
name
- name of a value assigned by controller.- Returns:
- a single value assigned by controller.
-
valFloat
float value assigned by controller.- Parameters:
name
- name of a value assigned by controller.- Returns:
- a single value assigned by controller.
-
valBoolean
boolean value assigned by controller.- Parameters:
name
- name of a value assigned by controller.- Returns:
- a single value assigned by controller.
-
redirected
protected boolean redirected()Returns true after execution of an action that sent a redirect.- Returns:
- true after execution of an action that sent a redirect, false otherwise.
-
redirectValue
Returns a redirect value if one was produced by a controller or filter, null if not.- Returns:
- a redirect value if one was produced by a controller or filter, null if not.
-
getCookies
Returns all cookies from last response. Use in test validations.- Returns:
- all cookies from last response.
-
cookie
Returns a cookie from last response by name,null
if not found.- Parameters:
name
- name of cookie.- Returns:
- a cookie from last response by name,
null
if not found.
-
cookieValue
Convenience method, returns cookie value.- Parameters:
name
- name of cookie.- Returns:
- cookie value.
-
text
Parses controller response content and selects content of HTML element using CSS selectors.
Example:
request().get("index"); a(find("div[class='greeting']").shouldEqual("Hello!");
- Parameters:
cssQuery
- CSS query. Implementation is based on JSoup.- Returns:
- contents of selected element as text.
-
count
Parses controller response and counts elements that are found by a CSS query. Example:
request().get("index"); a(count("div[class='main']").shouldEqual(1);
- Parameters:
cssQuery
- CSS query. Implementation is based on JSoup.- Returns:
- number of elements in HTML document that were matching the query.
-