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