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 org.apache.struts2.TestAction;
25 import org.apache.struts2.views.jsp.AbstractUITagTest;
26
27
28 /***
29 */
30 public class ComponentTest extends AbstractUITagTest {
31
32 /***
33 * Test that id attribute is evaludated against the Ognl Stack.
34 * @throws Exception
35 */
36 public void testIdIsEvaluatedAgainstStack1() throws Exception {
37 TestAction testAction = (TestAction) action;
38 testAction.setFoo("myFooValue");
39
40 TextFieldTag tag = new TextFieldTag();
41 tag.setPageContext(pageContext);
42 tag.setLabel("mylabel");
43 tag.setName("myname");
44 tag.setValue("foo");
45 tag.setId("%{foo}");
46
47 tag.doStartTag();
48 tag.doEndTag();
49
50 verify(ComponentTag.class.getResource("Component-2.txt"));
51 }
52
53 public void testIdIsEvaludatedAgainstStack2() throws Exception {
54 TestAction testAction = (TestAction) action;
55 testAction.setFoo("myFooValue");
56
57 TextFieldTag tag = new TextFieldTag();
58 tag.setPageContext(pageContext);
59 tag.setLabel("mylabel");
60 tag.setName("myname");
61 tag.setValue("foo");
62 tag.setId("foo");
63
64 tag.doStartTag();
65 tag.doEndTag();
66
67 verify(ComponentTag.class.getResource("Component-3.txt"));
68 }
69
70
71 /***
72 * Note -- this test uses empty.vm, so it's basically clear
73 */
74 public void testSimple() throws Exception {
75 TestAction testAction = (TestAction) action;
76 testAction.setFoo("bar");
77
78 ComponentTag tag = new ComponentTag();
79 tag.setPageContext(pageContext);
80 tag.setLabel("mylabel");
81 tag.setName("myname");
82 tag.setValue("foo");
83
84 tag.doStartTag();
85 tag.doEndTag();
86
87 verify(ComponentTag.class.getResource("Component-1.txt"));
88 }
89
90 /***
91 * executes a component test passing in a custom parameter. it also executes calling a custom template using an
92 * absolute reference.
93 */
94 public void testWithParam() throws Exception {
95 TestAction testAction = (TestAction) action;
96 testAction.setFoo("bar");
97
98 ComponentTag tag = new ComponentTag();
99 tag.setPageContext(pageContext);
100 tag.setLabel("mylabel");
101 tag.setName("myname");
102 tag.setValue("foo");
103 tag.setTheme("test");
104 tag.setTemplate("Component");
105
106 tag.doStartTag();
107 tag.getComponent().addParameter("hello", "world");
108 tag.getComponent().addParameter("argle", "bargle");
109 tag.getComponent().addParameter("glip", "glop");
110 tag.getComponent().addParameter("array", new String[]{"a", "b", "c"});
111 tag.getComponent().addParameter("obj", tag);
112 tag.doEndTag();
113
114
115 verify(ComponentTag.class.getResource("Component-param.txt"));
116 }
117 }