1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.views.jsp.ui;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.apache.struts2.TestAction;
28 import org.apache.struts2.views.jsp.AbstractUITagTest;
29
30
31 /***
32 */
33 public class LabelTest extends AbstractUITagTest {
34
35 public void testSimple() throws Exception {
36 TestAction testAction = (TestAction) action;
37 testAction.setFoo("bar");
38
39 LabelTag tag = new LabelTag();
40 tag.setPageContext(pageContext);
41 tag.setLabel("mylabel");
42 tag.setName("myname");
43 tag.setTitle("mytitle");
44 tag.setValue("%{foo}");
45
46 tag.doStartTag();
47 tag.doEndTag();
48
49 verify(LabelTest.class.getResource("Label-1.txt"));
50 }
51
52 public void testSimpleWithLabelposition() throws Exception {
53 TestAction testAction = (TestAction) action;
54 testAction.setFoo("bar");
55
56 LabelTag tag = new LabelTag();
57 tag.setPageContext(pageContext);
58 tag.setLabel("mylabel");
59 tag.setName("myname");
60 tag.setValue("%{foo}");
61 tag.setLabelposition("top");
62
63 tag.doStartTag();
64 tag.doEndTag();
65
66 verify(LabelTest.class.getResource("Label-3.txt"));
67 }
68
69 /***
70 * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
71 * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
72 * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
73 *
74 * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
75 * as key.
76 */
77 protected Map initializedGenericTagTestProperties() {
78 Map result = new HashMap();
79 new PropertyHolder("title", "someTitle").addToMap(result);
80 new PropertyHolder("cssClass", "cssClass1", "class=\"cssClass1\"").addToMap(result);
81 new PropertyHolder("cssStyle", "cssStyle1", "style=\"cssStyle1\"").addToMap(result);
82 new PropertyHolder("id", "someId").addToMap(result);
83 new PropertyHolder("for", "someFor").addToMap(result);
84 return result;
85 }
86
87 public void testWithNoValue() throws Exception {
88 TestAction testAction = (TestAction) action;
89 testAction.setFoo("baz");
90
91 LabelTag tag = new LabelTag();
92 tag.setPageContext(pageContext);
93 tag.setLabel("mylabel");
94 tag.setName("foo");
95 tag.setFor("for");
96
97 tag.doStartTag();
98 tag.doEndTag();
99
100 verify(LabelTest.class.getResource("Label-2.txt"));
101 }
102
103 public void testGenericSimple() throws Exception {
104 LabelTag tag = new LabelTag();
105 verifyGenericProperties(tag, "simple", null);
106 }
107
108 public void testGenericXhtml() throws Exception {
109 LabelTag tag = new LabelTag();
110 verifyGenericProperties(tag, "xhtml", null);
111 }
112
113 public void testWithKey() throws Exception {
114 TestAction testAction = (TestAction) action;
115 final String key = "labelKey";
116 final String value = "baz";
117 testAction.setText(key, value);
118
119 testAction.setFoo("notToBeOutput");
120
121 LabelTag tag = new LabelTag();
122 tag.setPageContext(pageContext);
123 tag.setLabel("mylabel");
124 tag.setFor("for");
125 tag.setName("foo");
126 tag.setKey(key);
127
128 tag.doStartTag();
129 tag.doEndTag();
130
131 verify(LabelTest.class.getResource("Label-2.txt"));
132 }
133
134 }