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