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