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