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.util.HashMap;
19  import java.util.Map;
20  
21  import javax.servlet.jsp.PageContext;
22  
23  import org.jdom.Element;
24  import org.seasar.framework.util.StringUtil;
25  
26  public class TextareaTagTest extends SimpleTagTestCase {
27  
28  	TextareaTag tag;
29  	
30  	@Override
31  	protected void setUp() throws Exception {
32  		super.setUp();
33  		tag = new TextareaTag();
34  		setupSimpleTag(tag);
35  		setupErrors(context);
36  		jspBody.setBody("Dummy Body Text");
37  	}
38  
39  	public void testDoTag1() throws Exception {
40  		tag.setParent(new MockFormTag(new HashMap<String, String[]>()));
41  		tag.setName("content");
42  		tag.setValue("value1");
43  //		tag.setDynamicAttribute(null, "name", "content");
44  //		tag.setDynamicAttribute(null, "value", "value1");
45  		tag.setDynamicAttribute(null, "id", "content");
46  		tag.doTag();
47  		Element element = getResultAsElementFromContext();
48  		String message = "フォームオブジェクトが空でvalueが指定されている場合";
49  		assertEquals(message, "value1", element.getValue());
50  		assertEquals(message, 2, element.getAttributes().size());
51  		assertEquals(message, "content", element.getAttributeValue("id"));
52  		assertEquals(message, "content", element.getAttributeValue("name"));
53  	}
54  
55  	public void testDoTag2() throws Exception {
56  		FormDto form = new FormDto();
57  		form.setStringField("value1");
58  		Map<String, String[]> map = new HashMap<String, String[]>();
59  		map.put("stringField", new String[] { "value1" });
60  		tag.setParent(new MockFormTag(map));
61  		context.setAttribute("__form", form, PageContext.REQUEST_SCOPE);
62  		tag.setName("stringField");
63  //		tag.setDynamicAttribute(null, "name", "stringField");
64  		tag.doTag();
65  		Element element = getResultAsElementFromContext();
66  		String message = "フォームオブジェクトとname指定の場合";
67  		assertEquals(message, "value1", element.getValue());
68  		assertEquals(message, 1, element.getAttributes().size());
69  		assertEquals(message, "stringField", element.getAttributeValue("name"));
70  	}
71  
72  	public void testDoTag3() throws Exception {
73  		FormDto form = new FormDto();
74  		form.setStringField("value1");
75  		Map<String, String[]> map = new HashMap<String, String[]>();
76  		tag.setParent(new MockFormTag(map));
77  		tag.setName("stringField");
78  //		tag.setDynamicAttribute(null, "name", "stringField");
79  		tag.doTag();
80  		Element element = getResultAsElementFromContext();
81  		String message = "フォームオブジェクトが空でnameが指定されている場合";
82  		assertTrue(message, StringUtil.isEmpty(element.getValue()));
83  		assertEquals(message, 1, element.getAttributes().size());
84  		assertEquals(message, "stringField", element.getAttributeValue("name"));
85  	}
86  
87  }