GroovyPageUnitTestMixin (Grails 2.3.8)
Date: 2014-04-24

Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | PROPERTY | CONSTR | METHOD | DETAIL: FIELD | PROPERTY | CONSTR | METHOD

## grails.test.mixin.web
[Groovy] Class GroovyPageUnitTestMixin

    java.lang.Object
      grails.test.mixin.support.GrailsUnitTestMixin
          grails.test.mixin.web.ControllerUnitTestMixin
              grails.test.mixin.web.GroovyPageUnitTestMixin

    class GroovyPageUnitTestMixin
    extends ControllerUnitTestMixin

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.groovyPages 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

Property Summary
`GroovyPageBinding` | `pageScope`

Method Summary
`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.
`void` | `bindGrailsWebRequest()`
`void` | `clearPageScope()`
`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

Methods inherited from class ControllerUnitTestMixin
bindGrailsWebRequest, cleanupGrailsWeb, clearGrailsWebRequest, configureGrailsWeb, createAndEnhance, getFlash, getModel, getParams, getSession, getStatus, getView, mockCommandObject, mockController, testFor

Methods inherited from class GrailsUnitTestMixin
cleanupModifiedMetaClasses, defineBeans, deregisterMetaClassCleaner, initGrailsApplication, mockCodec, mockFor, mockForConstraintsTests, registerBeans, registerMetaClassRegistryWatcher, resetGrailsApplication, shouldFail, shouldFail, shutdownApplicationContext

Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Property Detail

### pageScope

    GroovyPageBinding pageScope

Method Detail

### applyTemplate

    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

### applyTemplate

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

### assertOutputEquals

    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

### assertOutputMatches

    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

### bindGrailsWebRequest

    @java.lang.Override
    @org.junit.Before
    void bindGrailsWebRequest()

### clearPageScope

    @org.junit.After
    void clearPageScope()

### mockTagLib

    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

### render

    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

Groovy Documentation