wicket.util.tester
Class TagTester

java.lang.Object
  extended by wicket.util.tester.TagTester

public class TagTester
extends java.lang.Object

Tag tester is used to test that a generated markup tag contains the correct attributes, values etc. This can be done instead of comparing generated markup with some expected markup. The advantage of this is that a lot of tests doesn't fail, when the generated markup changes just a little bit.

It also gives a more programmatic way of testing the generated output, by not having to worry about how the markup looks precisely instead of which attributes exists on the given tags and what values they have.

Example:

  ...
  TagTester tagTester = application.getTagByWicketId("form");
  assertTrue(tag.hasAttribute("action"));
  ...
 

Author:
Frank Bille (billen)

Method Summary
static TagTester createTagByAttribute(java.lang.String markup, java.lang.String attribute, java.lang.String value)
          Static factory method for creating a TagTester based on a tag found by an attribute with a specific value.
 java.lang.String getAttribute(java.lang.String attribute)
          Get the attribute value for the given attribute.
 boolean getAttributeContains(java.lang.String attribute, java.lang.String partialValue)
          Check if an attribute contains the specified partial value.
 boolean getAttributeEndsWith(java.lang.String attribute, java.lang.String expected)
          Check if an attributes value ends with the given parameter.
 boolean getAttributeIs(java.lang.String attribute, java.lang.String expected)
          Check if an attributes value is the exact same as the given parameter.
 TagTester getChild(java.lang.String attribute, java.lang.String value)
          Get a child tag for testing.
 java.lang.String getMarkup()
          Get markup for this tag.
 java.lang.String getName()
          Get the tag name.
 boolean hasAttribute(java.lang.String attribute)
          Does the tag contain the attribute.
 boolean hasChildTag(java.lang.String tagName)
          Check if the tag has a child with the tagName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getName

public java.lang.String getName()
Get the tag name.

Returns:
Tag name.

hasAttribute

public boolean hasAttribute(java.lang.String attribute)
Does the tag contain the attribute. Please note that this is case in-sensitive, because attributes in HTML may be case in-sensitive.

Parameters:
attribute - The attribute to look for in the tag.
Returns:
True if the tag has an attribute, false if not.

getAttribute

public java.lang.String getAttribute(java.lang.String attribute)
Get the attribute value for the given attribute. Please note that this is case in-sensitive, because attributes in HTML may be case in-sensitive.

Parameters:
attribute - The attribute to look for in the tag.
Returns:
The value of the attribute or null if it isn't found.

getAttributeContains

public boolean getAttributeContains(java.lang.String attribute,
                                    java.lang.String partialValue)
Check if an attribute contains the specified partial value.

For example:

Markup:

  <span wicket:id="helloComp" class="style1 style2">Hello</span>
 

Test

 TagTester tester = application.getTagByWicketId("helloComp");
 assertTrue(tester.getAttributeContains("class", "style2"));
 

Parameters:
attribute - The attribute to test on
partialValue - The partial value to test if the attribute value contains.
Returns:
True if the attribute value contains the partial value.

getAttributeIs

public boolean getAttributeIs(java.lang.String attribute,
                              java.lang.String expected)
Check if an attributes value is the exact same as the given parameter.

Parameters:
attribute - The attribute to test.
expected - The value which should be the same at the attributes value
Returns:
True if the attributes value is the same as the parameter.

getAttributeEndsWith

public boolean getAttributeEndsWith(java.lang.String attribute,
                                    java.lang.String expected)
Check if an attributes value ends with the given parameter.

Parameters:
attribute -
expected -
Returns:
True if the attributes value ends with the expected value

hasChildTag

public boolean hasChildTag(java.lang.String tagName)
Check if the tag has a child with the tagName.

Parameters:
tagName - The tag name to search for.
Returns:
True if this tag has a child with the given tagName.

getChild

public TagTester getChild(java.lang.String attribute,
                          java.lang.String value)
Get a child tag for testing. If this tag contains child tags, you can get one of them as a TagTester.

Parameters:
attribute - The attribute on the child tag to search for
value - The value that the attribute must have.
Returns:
The TagTester for the child tag.

getMarkup

public java.lang.String getMarkup()
Get markup for this tag. This includes every markup which is between the open tag and the close tag.

Returns:
The entire markup between the open tag and the close tag.

createTagByAttribute

public static TagTester createTagByAttribute(java.lang.String markup,
                                             java.lang.String attribute,
                                             java.lang.String value)
Static factory method for creating a TagTester based on a tag found by an attribute with a specific value. Please note that it will return the first tag which matches the criteria. It's therefore good for attributes suck as "id" or "wicket:id", but only if "wicket:id" is unique in the specified markup.

Parameters:
markup - The markup to look for the tag to create the TagTester from.
attribute - The attribute which should be on the tag in the markup.
value - The value which the attribute must have.
Returns:
The TagTester which matches the tag in the markup, that has the given value on the given attribute.


Copyright © 2004-2007 Wicket developers. All Rights Reserved.