Class ViewSpec

java.lang.Object
org.javalite.activeweb.SpecHelper
org.javalite.activeweb.ViewSpec
All Implemented Interfaces:
JSpecSupport

public abstract class ViewSpec extends SpecHelper
This is a spec used to test templates and custom tags.
Author:
Max Artyukhov
  • Constructor Details

    • ViewSpec

      public ViewSpec()
  • Method Details

    • beforeTest

      public final void beforeTest()
    • afterTest

      public final void afterTest()
    • setTemplateLocation

      public void setTemplateLocation(String templateLocation)
      By default the template location is set to src/main/webapp/WEB-INF/views. However in some cases you want to have test templates that are different from runtime templates. In those cases you can override that default location with your value,
      Overrides:
      setTemplateLocation in class SpecHelper
      Parameters:
      templateLocation - location of your templates relative to the directory where test is executed, usually a root of your Maven module
    • setInjector

      protected void setInjector(com.google.inject.Injector injector)
      Sets injector for tags if they require dependencies.
      Overrides:
      setInjector in class SpecHelper
      Parameters:
      injector - injector to source dependencies form.
    • registerTag

      protected void registerTag(String name, FreeMarkerTag tag)
      Use to register a tag before the test.
      Overrides:
      registerTag in class SpecHelper
      Parameters:
      name - name of tag as used in a template.
      tag - tag instance
    • render

      protected String render(String templateName)
      Renders a template by name
      Parameters:
      templateName - name of template to render
      Returns:
      rendered template
    • render

      protected String render(String templateName, Map values)
      Renders a template by name
      Parameters:
      templateName - name of template to render
      values - values to be passed into template
      Returns:
      rendered template content as string
    • render

      protected String render(String templateName, String... namesAndValues)
      Renders a template by name.
      Parameters:
      templateName - name of template to render
      namesAndValues - - list of names and values, where first, third, etc argument is a name and second, fourth, etc. argument is a corresponding value.
      Returns:
      rendered template content as string
    • setCurrentController

      protected <T extends AppController> void setCurrentController(Class<T> controllerClass)
      This method is only needed as a hint to the LinkToTag. If the link_to tag is used in a template without the controller attribute, it needs a current controller in context to generate a proper link. At runtime as well as in controller tests, a controller is always present in context, and link_to works as expected. However, since view specs are executed outside of controller execution, if you have a link_to in the template you are testing, you will need to provide a clue to your view before the test is executed.
      Parameters:
      controllerClass - controller class to aid to the link_to tag to generate a proper link.
    • contentFor

      protected List<String> contentFor(String name)
      This method returns chunks of content that was assigned from a tested template. Call this method after rendering a view in order to verify that the view did set appropriate text chunks with the ContentForTag when it is used in a template, example:
       
      <@content for="title">Book title</@content>
       
       
      Parameters:
      name - name of a content piece as was specified by the "for" attribute of the "content" tag.
      Returns:
      piece of content assigned from "content" tag if one was used in a tested view.