GroovyPageUnitTestMixin (Grails 3.2.7)
Date: 2017-03-06

Package: grails.test.mixin.web

## [Groovy] Class GroovyPageUnitTestMixin

- grails.test.mixin.web.GroovyPageUnitTestMixin

- A unit testing mixing that add behavior to support the testing of tag libraries and GSP pages. Can be used in combination with DomainClassUnitTestMixin to support the testing of tag libraries and GSPs

  Views and templates can be mocked via the ControllerUnitTestMixin.getGroovyPages map where the keys are the names of the pages and the values are the contents of the GSP page

  Alternatively, within a Grails project the unit test will fallback to loading views and templates from grails-app/views

  For mocking tag libraries the GroovyPageUnitTestMixin.mockTagLib method allows you to mock custom tag libraries. There is no need to mock core tag libraries like as these will be loaded on demand

  Authors:
    Graeme Rocher
  Since:
    2.0

- - ### Constructor Summary

    Constructors
    Constructor and description
    `GroovyPageUnitTestMixin (java.util.Set<java.lang.String> features)`
    `GroovyPageUnitTestMixin ()`

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `java.lang.String` | `applyTemplate(java.lang.String contents, java.util.Map model = [:])` Renders a template for the given contents and model
    `protected void` | `applyTemplate(java.io.StringWriter sw, java.lang.Object template, java.lang.Object params = [:])`
    `void` | `assertOutputEquals(java.lang.Object expected, java.lang.Object template, java.lang.Object params = [:], groovy.lang.Closure transform = { it.toString()` Asserts the output of a given template against the specified expected value.
    `void` | `assertOutputMatches(java.lang.Object regex, java.lang.Object template, java.lang.Object params = [:], groovy.lang.Closure transform = { it.toString()` Asserts the output of a given template against the specified regex.
    `java.lang.Object` | `mockTagLib(java.lang.Class tagLibClass)` Mocks a tag library, making it available to subsequent calls to controllers mocked via mockController(Class) and GSPs rendered via applyTemplate(String, Map)
    `java.lang.String` | `render(java.util.Map args)` Mimics the behavior of the render method in controllers but returns the rendered contents directly

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ControllerUnitTestMixin` | `createAndEnhance, getFlash, getGroovyPages, getModel, getParams, getRequest, getResponse, getServletContext, getSession, getStatus, getView, getViews, getWebRequest, mockCommandObject, mockController, testFor`
    `class GrailsUnitTestMixin` | `defineBeans, getApplicationContext, getConfig, getGrailsApplication, getMainContext, getMessageSource, mockCodec, shouldFail, shouldFail`
    `class TestMixinRuntimeSupport` | `getFeatures, getRuntime, setRuntime, setTestClass`
    `class groovy.lang.GroovyObjectSupport` | `groovy.lang.GroovyObjectSupport#setProperty(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#getProperty(java.lang.String), groovy.lang.GroovyObjectSupport#getMetaClass(), groovy.lang.GroovyObjectSupport#setMetaClass(groovy.lang.MetaClass), groovy.lang.GroovyObjectSupport#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#wait(long, int), groovy.lang.GroovyObjectSupport#wait(long), groovy.lang.GroovyObjectSupport#wait(), groovy.lang.GroovyObjectSupport#equals(java.lang.Object), groovy.lang.GroovyObjectSupport#toString(), groovy.lang.GroovyObjectSupport#hashCode(), groovy.lang.GroovyObjectSupport#getClass(), groovy.lang.GroovyObjectSupport#notify(), groovy.lang.GroovyObjectSupport#notifyAll()`

- - ### Constructor Detail

    - #### GroovyPageUnitTestMixin(java.util.Set<java.lang.String> features)

    - #### GroovyPageUnitTestMixin()

  - ### Method Detail

    - #### java.lang.String applyTemplate(java.lang.String contents, java.util.Map model = [:])

      Renders a template for the given contents and model

      Parameters:
        `contents` - The contents
        `model` - The model
      Returns:
        The rendered template

    - #### protected void applyTemplate(java.io.StringWriter sw, java.lang.Object template, java.lang.Object params = [:])

    - #### void assertOutputEquals(java.lang.Object expected, java.lang.Object template, java.lang.Object params = [:], groovy.lang.Closure transform = { it.toString()

      Asserts the output of a given template against the specified expected value.

      Parameters:
        `expected` - The expected output
        `template` - A snippet of GSP
        `params` - An optional parameter that allows variables to be placed in the binding of the GSP
        `transform` - An optional parameter that allows the specification of a closure to transform the passed StringWriter

    - #### void assertOutputMatches(java.lang.Object regex, java.lang.Object template, java.lang.Object params = [:], groovy.lang.Closure transform = { it.toString()

      Asserts the output of a given template against the specified regex.

      Parameters:
        `expected` - The regex expression expected to match the output
        `template` - A snippet of GSP
        `params` - An optional parameter that allows variables to be placed in the binding of the GSP
        `transform` - An optional parameter that allows the specification of a closure to transform the passed StringWriter

    - #### java.lang.Object mockTagLib(java.lang.Class tagLibClass)

      Mocks a tag library, making it available to subsequent calls to controllers mocked via mockController(Class) and GSPs rendered via applyTemplate(String, Map)

      Parameters:
        `tagLibClass` - The tag library class
      Returns:
        The tag library instance

    - #### java.lang.String render(java.util.Map args)

      Mimics the behavior of the render method in controllers but returns the rendered contents directly

      Parameters:
        `args` - The same arguments as the controller render method accepts
      Returns:
        The resulting rendering GSP