1 package org.seasar.cubby.tags; 2 3 import java.io.IOException; 4 import java.io.StringReader; 5 6 import javax.servlet.jsp.tagext.BodyTag; 7 import javax.servlet.jsp.tagext.SimpleTag; 8 9 import junit.framework.TestCase; 10 11 import org.jdom.Document; 12 import org.jdom.Element; 13 import org.jdom.JDOMException; 14 import org.jdom.input.SAXBuilder; 15 16 abstract public class JspTagTestCase extends TestCase { 17 protected MockJspFragment jspBody; 18 protected MockJspContext context; 19 20 @Override 21 protected void setUp() throws Exception { 22 jspBody = new MockJspFragment(); 23 context = new MockJspContext(); 24 jspBody.setJspContext(context); 25 } 26 27 28 protected void setupSimpleTag(SimpleTag tag) { 29 tag.setJspBody(jspBody); 30 tag.setJspContext(context); 31 } 32 33 protected void setupBodyTag(BodyTag tag) { 34 tag.setPageContext(context); 35 } 36 37 protected Element getResultAsElementFromContext() throws JDOMException, 38 IOException { 39 String result = context.getResult(); 40 Document document = new SAXBuilder().build(new StringReader(result)); 41 Element element = document.getRootElement(); 42 return element; 43 } 44 45 }