Class RequestSpecHelper

java.lang.Object
org.javalite.activeweb.SpecHelper
org.javalite.activeweb.RequestSpecHelper
All Implemented Interfaces:
JSpecSupport
Direct Known Subclasses:
ControllerSpec, IntegrationSpec

public class RequestSpecHelper extends SpecHelper
This class is not used directly in applications.
Author:
Igor Polevoy
  • 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

      protected String contentType()
      Provides content type set on response by controller
      Returns:
      content type set on response by controller
    • responseContent

      protected String 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

      protected String layout()
      Provides layout set after executing an action of a controller.
      Returns:
      layout set after executing an action of a controller.
    • template

      protected String template()
    • assigns

      protected Map 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

      protected Map vals()
      Synonym of assigns().
      Returns:
      values assigned by controller during execution
    • val

      protected Object val(String name)
      Returns a single value assigned by controller.
      Parameters:
      name - name of a value assigned by controller.
      Returns:
      a single value assigned by controller.
    • val

      protected <T> T val(String name, Class<T> type)
      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

      protected String header(String headerName)
      Returns header set by controller or filter.
      Parameters:
      headerName - name of header
      Returns:
      header value (can be null).
    • headers

      protected Map<String,​String> 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

      protected List<String> 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

      protected String valString(String name)
      String value assigned by controller.
      Parameters:
      name - name of a value assigned by controller.
      Returns:
      a single value assigned by controller.
    • valInteger

      protected int valInteger(String name)
      int value assigned by controller.
      Parameters:
      name - name of a value assigned by controller.
      Returns:
      a single value assigned by controller.
    • valLong

      protected long valLong(String name)
      long value assigned by controller.
      Parameters:
      name - name of a value assigned by controller.
      Returns:
      a single value assigned by controller.
    • valDouble

      protected double valDouble(String name)
      double value assigned by controller.
      Parameters:
      name - name of a value assigned by controller.
      Returns:
      a single value assigned by controller.
    • valFloat

      protected float valFloat(String name)
      float value assigned by controller.
      Parameters:
      name - name of a value assigned by controller.
      Returns:
      a single value assigned by controller.
    • valBoolean

      protected boolean valBoolean(String name)
      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

      protected String 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

      protected Cookie[] getCookies()
      Returns all cookies from last response. Use in test validations.
      Returns:
      all cookies from last response.
    • cookie

      protected Cookie cookie(String name)
      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

      protected String cookieValue(String name)
      Convenience method, returns cookie value.
      Parameters:
      name - name of cookie.
      Returns:
      cookie value.
    • text

      protected String text(String cssQuery)
      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

      public int count(String cssQuery)
      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.