com.mockrunner.tag
Class TagTestModule

java.lang.Object
  extended by com.mockrunner.base.WebTestModule
      extended by com.mockrunner.base.HTMLOutputModule
          extended by com.mockrunner.tag.TagTestModule

public class TagTestModule
extends HTMLOutputModule

Module for custom tag tests. Simulates the container by performing the tag lifecycle.


Constructor Summary
TagTestModule(WebMockObjectFactory mockFactory)
           
 
Method Summary
 void clearOutput()
          Resets the output buffer.
 NestedTag createNestedTag(java.lang.Class tagClass)
          Creates a NestedTag and returns it.
 NestedTag createNestedTag(java.lang.Class tagClass, java.util.Map attributes)
          Creates a NestedTag and returns it.
 javax.servlet.jsp.tagext.TagSupport createTag(java.lang.Class tagClass)
          Creates a tag.
 javax.servlet.jsp.tagext.TagSupport createTag(java.lang.Class tagClass, java.util.Map attributes)
          Creates a tag.
 javax.servlet.jsp.tagext.JspTag createWrappedTag(java.lang.Class tagClass)
          Creates a tag.
 javax.servlet.jsp.tagext.JspTag createWrappedTag(java.lang.Class tagClass, java.util.Map attributes)
          Creates a tag.
 int doAfterBody()
          Calls the doAfterBody method of the current tag.
 int doEndTag()
          Calls the doEndTag method of the current tag.
 void doInitBody()
          Calls the doInitBody method of the current tag.
 int doStartTag()
          Calls the doStartTag method of the current tag.
 void doTag()
          Calls the doStartTag method of the current tag.
 MockPageContext getMockPageContext()
          Returns the MockPageContext object.
 NestedTag getNestedTag()
          Returns the current nested tag.
 java.lang.String getOutput()
          Gets the output data the current tag has rendered.
 javax.servlet.jsp.tagext.TagSupport getTag()
          Returns the current wrapped tag.
 javax.servlet.jsp.tagext.JspTag getWrappedTag()
          Returns the current wrapped tag.
 void populateAttributes()
          Populates the attributes of the underlying tag by calling NestedTag.populateAttributes().
 int processTagLifecycle()
          Performs the tags lifecycle by calling NestedTag.doLifecycle().
 void release()
          Calls the release method of the current tag.
 void setBody(java.lang.String body)
          Sets the body of the tag as a static string.
 void setDoRelease(boolean doRelease)
          Specify if the release method should be called after processing the tag lifecycle.
 void setDoReleaseRecursive(boolean doRelease)
          Specify if the release method should be called after processing the tag lifecycle.
 NestedTag setTag(javax.servlet.jsp.tagext.JspTag tag)
          Creates a NestedTag and returns it.
 NestedTag setTag(javax.servlet.jsp.tagext.JspTag tag, java.util.Map attributes)
          Creates a NestedTag and returns it.
 NestedTag setTag(javax.servlet.jsp.tagext.TagSupport tag)
          Creates a NestedTag and returns it.
 NestedTag setTag(javax.servlet.jsp.tagext.TagSupport tag, java.util.Map attributes)
          Creates a NestedTag and returns it.
 
Methods inherited from class com.mockrunner.base.HTMLOutputModule
getOutputAsBufferedReader, getOutputAsJDOMDocument, getOutputAsW3CDocument, getOutputAsWellformedXML, setCaseSensitive, verifyOutput, verifyOutputContains, verifyOutputRegularExpression
 
Methods inherited from class com.mockrunner.base.WebTestModule
addRequestParameter, addRequestParameter, addRequestParameter, getRequestAttribute, getRequestParameter, getSessionAttribute, setRequestAttribute, setSessionAttribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TagTestModule

public TagTestModule(WebMockObjectFactory mockFactory)
Method Detail

createTag

public javax.servlet.jsp.tagext.TagSupport createTag(java.lang.Class tagClass)
Creates a tag. Internally a NestedTag is created but the wrapped tag is returned. If you simply want to test the output of the tag without nesting other tags, you do not have to care about the NestedTag, just use the returned instance. An empty attribute Map will be used for the tag.

Parameters:
tagClass - the class of the tag
Returns:
instance of TagSupport or BodyTagSupport
Throws:
RuntimeException, - if the created tag is not an instance of TagSupport

createTag

public javax.servlet.jsp.tagext.TagSupport createTag(java.lang.Class tagClass,
                                                     java.util.Map attributes)
Creates a tag. Internally a NestedTag is created but the wrapped tag is returned. If you simply want to test the output of the tag without nesting other tags, you do not have to care about the NestedTag, just use the returned instance. The attributes Map contains the attributes of this tag (propertyname maps to propertyvalue). The attributes are populated (i.e. the tags setters are called) during the lifecycle or with an explicit call of populateAttributes().

Parameters:
tagClass - the class of the tag
attributes - the attribute map
Returns:
instance of TagSupport or BodyTagSupport
Throws:
RuntimeException, - if the created tag is not an instance of TagSupport

createWrappedTag

public javax.servlet.jsp.tagext.JspTag createWrappedTag(java.lang.Class tagClass)
Creates a tag. Internally a NestedTag is created but the wrapped tag is returned. If you simply want to test the output of the tag without nesting other tags, you do not have to care about the NestedTag, just use the returned instance. An empty attribute Map will be used for the tag. This method can be used for all kind of tags. The tag class does not need to be a subclass of TagSupport.

Parameters:
tagClass - the class of the tag
Returns:
instance of JspTag

createWrappedTag

public javax.servlet.jsp.tagext.JspTag createWrappedTag(java.lang.Class tagClass,
                                                        java.util.Map attributes)
Creates a tag. Internally a NestedTag is created but the wrapped tag is returned. If you simply want to test the output of the tag without nesting other tags, you do not have to care about the NestedTag, just use the returned instance. The attributes Map contains the attributes of this tag (propertyname maps to propertyvalue). The attributes are populated (i.e. the tags setters are called) during the lifecycle or with an explicit call of populateAttributes(). This method can be used for all kind of tags. The tag class does not need to be a subclass of TagSupport.

Parameters:
tagClass - the class of the tag
attributes - the attribute map
Returns:
instance of JspTag

createNestedTag

public NestedTag createNestedTag(java.lang.Class tagClass)
Creates a NestedTag and returns it. You can add child tags or body blocks to the NestedTag. Use getTag() to get the wrapped tag. An empty attribute Map will be used for the tag.

Parameters:
tagClass - the class of the tag
Returns:
instance of NestedStandardTag, NestedBodyTag or NestedSimpleTag

createNestedTag

public NestedTag createNestedTag(java.lang.Class tagClass,
                                 java.util.Map attributes)
Creates a NestedTag and returns it. You can add child tags or body blocks to the NestedTag. Use getTag() to get the wrapped tag. The attributes Map contains the attributes of this tag (propertyname maps to propertyvalue). The attributes are populated (i.e. the tags setters are called) during the lifecycle or with an explicit call of populateAttributes().

Parameters:
tagClass - the class of the tag
attributes - the attribute map
Returns:
instance of NestedStandardTag, NestedBodyTag or NestedSimpleTag

setTag

public NestedTag setTag(javax.servlet.jsp.tagext.TagSupport tag)
Creates a NestedTag and returns it. You can add child tags or body blocks to the NestedTag. Use getTag() to get the wrapped tag. An empty attribute Map will be used for the tag.

Parameters:
tag - the tag
Returns:
instance of NestedStandardTag or NestedBodyTag

setTag

public NestedTag setTag(javax.servlet.jsp.tagext.TagSupport tag,
                        java.util.Map attributes)
Creates a NestedTag and returns it. You can add child tags or body blocks to the NestedTag. Use getTag() to get the wrapped tag. The attributes Map contains the attributes of this tag (propertyname maps to propertyvalue). The attributes are populated (i.e. the tags setters are called) during the lifecycle or with an explicit call of populateAttributes().

Parameters:
tag - the tag
attributes - the attribute map
Returns:
instance of NestedStandardTag or NestedBodyTag

setTag

public NestedTag setTag(javax.servlet.jsp.tagext.JspTag tag)
Creates a NestedTag and returns it. You can add child tags or body blocks to the NestedTag. Use getTag() to get the wrapped tag. An empty attribute Map will be used for the tag. This method can be used for all kind of tags. The tag class does not need to be a subclass of TagSupport.

Parameters:
tag - the tag
Returns:
instance of NestedStandardTag, NestedBodyTag or NestedSimpleTag

setTag

public NestedTag setTag(javax.servlet.jsp.tagext.JspTag tag,
                        java.util.Map attributes)
Creates a NestedTag and returns it. You can add child tags or body blocks to the NestedTag. Use getTag() to get the wrapped tag. The attributes Map contains the attributes of this tag (propertyname maps to propertyvalue). The attributes are populated (i.e. the tags setters are called) during the lifecycle or with an explicit call of populateAttributes(). This method can be used for all kind of tags. The tag class does not need to be a subclass of TagSupport.

Parameters:
tag - the tag
attributes - the attribute map
Returns:
instance of NestedStandardTag, NestedBodyTag or NestedSimpleTag

setDoRelease

public void setDoRelease(boolean doRelease)
Specify if the release method should be called after processing the tag lifecycle. Delegates to NestedTag.setDoRelease(boolean) Defaults to false. It's the container behaviour to call release, but it's usually not necessary in the tests, because the tag instances are not reused during a test run.

Parameters:
doRelease - should release be called

setDoReleaseRecursive

public void setDoReleaseRecursive(boolean doRelease)
Specify if the release method should be called after processing the tag lifecycle. Delegates to NestedTag.setDoReleaseRecursive(boolean) Defaults to false. It's the container behaviour to call release, but it's usually not necessary in the tests, because the tag instances are not reused during a test run.

Parameters:
doRelease - should release be called

populateAttributes

public void populateAttributes()
Populates the attributes of the underlying tag by calling NestedTag.populateAttributes(). The setters of the tag are called. Please note that child tags are not populated. This is done during the lifecycle.


setBody

public void setBody(java.lang.String body)
Sets the body of the tag as a static string. Please note that all childs of the underlying NestedTag are deleted and the static content is set. If you want to use nested tags, please use the method NestedTag.addTextChild(java.lang.String) to set static content.

Parameters:
body - the static body content

getTag

public javax.servlet.jsp.tagext.TagSupport getTag()
Returns the current wrapped tag.

Returns:
instance of TagSupport or BodyTagSupport
Throws:
RuntimeException, - if the wrapped tag is not an instance of TagSupport

getWrappedTag

public javax.servlet.jsp.tagext.JspTag getWrappedTag()
Returns the current wrapped tag. This method can be used for all kind of tags. The tag class does not need to be a subclass of TagSupport.

Returns:
instance of JspTag

getNestedTag

public NestedTag getNestedTag()
Returns the current nested tag. You can add child tags or body blocks to the NestedTag. Use getTag() to get the wrapped tag.

Returns:
instance of NestedStandardTag or NestedBodyTag

getMockPageContext

public MockPageContext getMockPageContext()
Returns the MockPageContext object. Delegates to WebMockObjectFactory.getMockPageContext().

Returns:
the MockPageContext

doTag

public void doTag()
Calls the doStartTag method of the current tag.

Throws:
RuntimeException, - if the tag is not a simple tag

doStartTag

public int doStartTag()
Calls the doStartTag method of the current tag.

Returns:
the result of doStartTag
Throws:
RuntimeException, - if the tag is a simple tag

doEndTag

public int doEndTag()
Calls the doEndTag method of the current tag.

Returns:
the result of doEndTag
Throws:
RuntimeException, - if the tag is a simple tag

doInitBody

public void doInitBody()
Calls the doInitBody method of the current tag.

Throws:
java.lang.RuntimeException - if the current tag is no body tag
RuntimeException, - if the tag is a simple tag

doAfterBody

public int doAfterBody()
Calls the doAfterBody method of the current tag.

Returns:
the result of doAfterBody
Throws:
RuntimeException, - if the tag is a simple tag

release

public void release()
Calls the release method of the current tag.

Throws:
RuntimeException, - if the tag is a simple tag

processTagLifecycle

public int processTagLifecycle()
Performs the tags lifecycle by calling NestedTag.doLifecycle(). All doBody and doTag methods are called as in the real web container. The evaluation of the body is simulated by performing the lifecycle recursively for all childs of the NestedTag.

Returns:
the result of the final doEndTag call or -1 in the case of a simple tag

clearOutput

public void clearOutput()
Resets the output buffer.


getOutput

public java.lang.String getOutput()
Gets the output data the current tag has rendered. Makes only sense after calling at least doStartTag() or processTagLifecycle()

Specified by:
getOutput in class HTMLOutputModule
Returns:
the output data