|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | PROPERTY | CONSTR | METHOD | DETAIL: FIELD | PROPERTY | CONSTR | METHOD |
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
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, getFlash, getModel, getParams, getSession, getView, mockCommandObject, mockController, testFor |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#wait(long), 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 |
---|
GroovyPageBinding pageScope
Method Detail |
---|
java.lang.String applyTemplate(java.lang.String contents, java.util.Map model = [:])
contents
- The contentsmodel
- The 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()
expected
- The expected outputtemplate
- A snippet of GSPparams
- An optional parameter that allows variables to be placed in the binding of the GSPtransform
- 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()
expected
- The regex expression expected to match the outputtemplate
- A snippet of GSPparams
- An optional parameter that allows variables to be placed in the binding of the GSPtransform
- An optional parameter that allows the specification of a closure to transform the passed StringWriter
@Override @Before void bindGrailsWebRequest()
@After void clearPageScope()
java.lang.Object mockTagLib(java.lang.Class tagLibClass)
tagLibClass
- The tag library class
java.lang.String render(java.util.Map args)
args
- The same arguments as the controller render method accepts
Groovy Documentation