1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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  }