1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.tags;
17
18 import java.io.IOException;
19 import java.io.StringReader;
20
21 import javax.servlet.jsp.JspContext;
22 import javax.servlet.jsp.PageContext;
23 import javax.servlet.jsp.tagext.BodyTag;
24 import javax.servlet.jsp.tagext.SimpleTag;
25
26 import org.jdom.Document;
27 import org.jdom.Element;
28 import org.jdom.JDOMException;
29 import org.jdom.input.SAXBuilder;
30 import org.seasar.cubby.action.impl.ActionErrorsImpl;
31 import org.seasar.extension.unit.S2TestCase;
32
33 abstract public class JspTagTestCase extends S2TestCase {
34 protected MockJspFragment jspBody;
35 protected MockJspContext context;
36
37 @Override
38 protected void setUp() throws Exception {
39 super.setUp();
40 jspBody = new MockJspFragment();
41 context = new MockJspContext();
42 jspBody.setJspContext(context);
43 }
44
45
46 protected void setupSimpleTag(SimpleTag tag) {
47 tag.setJspBody(jspBody);
48 tag.setJspContext(context);
49 }
50
51 protected void setupBodyTag(BodyTag tag) {
52 tag.setPageContext(context);
53 }
54
55 protected Element getResultAsElementFromContext() throws JDOMException,
56 IOException {
57 String result = context.getResult();
58 Document document = new SAXBuilder().build(new StringReader(result));
59 Element element = document.getRootElement();
60 return element;
61 }
62
63 public void setupErrors(JspContext context) {
64 ActionErrorsImpl errors = new ActionErrorsImpl();
65 context.setAttribute("errors", errors, PageContext.REQUEST_SCOPE);
66 }
67
68 }