In the current version Cactus does not support unit testing of Taglet that
extend TagBodySupport and that make use of bodyContent (it does support
however, unit testing of Taglet that extend TagSupport).

In order to support it, I propose the following naive idea (I need your
helpto ensure it's going to work) :

- Implement a class that extends javax.servlet.jsp.tagext.BodyContent. Let's
call it BodyContentWrapper.
- Add a method to BodyContentWrapper (like setContent(String) ) to easily
initialize it with a String representing the body content.
- Use the following code to unit test a Taglet:

public class MyTagletToTest extends TagBodySupport
{
 [...]
}

public void testXXX()
{
    // Set up of test
    MyTagletToTest taglet = new MyTagletToTest();
    taglet.setPageContext(pageContext);
    BodyContentWrapper body = new BodyContentWrapper("some body content");
    taglet.setBodyContent(body);

    // The test starts here
    taglet.someMethod(....);

    // Asserts on the server side
    [...]
}

public void endXXX(...)
{
    Do some asserts on the returned content. Use HttpUnit powerful API when
we have integrated with it.
}

Would that work ?
The only issue I can see so far, is if the body content contains another
nested tag ...  Hum ...We are doing unit testing here, meaning that we are
not testing a nested tag. So we simply have to put in the bodyContent the
expected result from a nested tag ... What do you  think ?

Thanks
Vincent

Reply via email to