1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.seasar.cubby.tags;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import javax.servlet.jsp.PageContext;
26
27 import org.jdom.Element;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.seasar.cubby.internal.util.StringUtils;
31
32 public class TextareaTagTest extends SimpleTagTestCase {
33
34 private TextareaTag tag;
35
36 @Before
37 public void setup() throws Exception {
38 tag = new TextareaTag();
39 setupSimpleTag(tag);
40 setupErrors(context);
41 jspBody.setBody("Dummy Body Text");
42 }
43
44 @Test
45 public void doTag1() throws Exception {
46 tag.setParent(new MockFormTag(new HashMap<String, String[]>()));
47 tag.setName("content");
48 tag.setValue("value1");
49
50
51 tag.setDynamicAttribute(null, "id", "content");
52 tag.doTag();
53 Element element = getResultAsElementFromContext();
54 String message = "フォームオブジェクトが空でvalueが指定されている場合";
55 assertEquals(message, "value1", element.getValue());
56 assertEquals(message, 2, element.getAttributes().size());
57 assertEquals(message, "content", element.getAttributeValue("id"));
58 assertEquals(message, "content", element.getAttributeValue("name"));
59 }
60
61 @Test
62 public void doTag2() throws Exception {
63 FormDto form = new FormDto();
64 form.setStringField("value1");
65 Map<String, String[]> map = new HashMap<String, String[]>();
66 map.put("stringField", new String[] { "value1" });
67 tag.setParent(new MockFormTag(map));
68 context.setAttribute("__form", form, PageContext.REQUEST_SCOPE);
69 tag.setName("stringField");
70
71 tag.doTag();
72 Element element = getResultAsElementFromContext();
73 String message = "フォームオブジェクトとname指定の場合";
74 assertEquals(message, "value1", element.getValue());
75 assertEquals(message, 1, element.getAttributes().size());
76 assertEquals(message, "stringField", element.getAttributeValue("name"));
77 }
78
79 @Test
80 public void doTag3() throws Exception {
81 FormDto form = new FormDto();
82 form.setStringField("value1");
83 Map<String, String[]> map = new HashMap<String, String[]>();
84 tag.setParent(new MockFormTag(map));
85 tag.setName("stringField");
86
87 tag.doTag();
88 Element element = getResultAsElementFromContext();
89 String message = "フォームオブジェクトが空でnameが指定されている場合";
90 assertTrue(message, StringUtils.isEmpty(element.getValue()));
91 assertEquals(message, 1, element.getAttributes().size());
92 assertEquals(message, "stringField", element.getAttributeValue("name"));
93 }
94
95 }