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
24 import org.jdom.Document;
25 import org.jdom.Element;
26 import org.jdom.JDOMException;
27 import org.jdom.input.SAXBuilder;
28 import org.seasar.cubby.action.impl.ActionErrorsImpl;
29 import org.seasar.extension.unit.S2TestCase;
30
31 abstract class AbstractTagTestCase extends S2TestCase {
32
33 protected MockJspFragment jspBody;
34
35 protected MockJspContext context;
36
37 public AbstractTagTestCase() {
38 super();
39 }
40
41 public AbstractTagTestCase(String name) {
42 super(name);
43 }
44
45 @Override
46 protected void setUp() throws Exception {
47 super.setUp();
48 jspBody = new MockJspFragment();
49 context = new MockJspContext();
50 jspBody.setJspContext(context);
51 }
52
53 protected Element getResultAsElementFromContext() throws JDOMException,
54 IOException {
55 String result = context.getResult();
56 Document document = new SAXBuilder().build(new StringReader(result));
57 Element element = document.getRootElement();
58 return element;
59 }
60
61 public void setupErrors(JspContext context) {
62 ActionErrorsImpl errors = new ActionErrorsImpl();
63 context.setAttribute("errors", errors, PageContext.REQUEST_SCOPE);
64 }
65
66 }