1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.trinidad.render;
20
21
22 import javax.faces.component.NamingContainer;
23 import javax.faces.context.FacesContext;
24 import javax.faces.render.Renderer;
25
26 import junit.framework.Test;
27 import junit.framework.TestCase;
28 import junit.framework.TestSuite;
29
30 import org.apache.myfaces.trinidad.component.UIXForm;
31 import org.apache.myfaces.trinidad.component.UIXInput;
32 import org.apache.myfaces.trinidad.component.UIXPanel;
33
34 import org.apache.myfaces.trinidadbuild.test.FacesTestCase;
35
36 public class RenderUtilsTest extends FacesTestCase
37 {
38 public static final Test suite()
39 {
40 return new TestSuite(RenderUtilsTest.class);
41 }
42
43 public static void main(String[] args) throws Throwable
44 {
45 junit.textui.TestRunner.run(suite());
46 }
47
48 public RenderUtilsTest(
49 String testName)
50 {
51 super(testName);
52 }
53
54 static private class TestNamingContainer extends UIXPanel
55 implements NamingContainer
56 {
57 @Override
58 public String getClientId(FacesContext context)
59 {
60
61
62
63 String clientId = getId() + "_Client";
64 return clientId;
65 }
66
67 public String getContainerClientId(FacesContext p1)
68 {
69 return getId();
70 }
71
72 protected Renderer getRenderer(FacesContext context)
73 {
74 return null;
75 }
76 }
77
78 static private class TestUIXPanel extends UIXPanel
79 {
80
81
82 protected Renderer getRenderer(FacesContext context)
83 {
84 return null;
85 }
86 }
87
88
89
90 @SuppressWarnings("unchecked")
91 public void testButtonAndNamingContainerSiblings()
92 {
93 FacesContext context = FacesContext.getCurrentInstance();
94
95
96
97
98 TestUIXPanel button1 = new TestUIXPanel();
99 button1.setId("commandButton1");
100 TestNamingContainer table1 = new TestNamingContainer();
101 table1.setId("table1");
102 TestUIXPanel rootPanel = new TestUIXPanel();
103 rootPanel.setId("rootPanel");
104 rootPanel.getChildren().add(button1);
105 rootPanel.getChildren().add(table1);
106 TestUIXPanel tableChild = new TestUIXPanel();
107 tableChild.setId("tableChildId");
108 table1.getChildren().add(tableChild);
109
110 String relativeId =
111 RenderUtils.getRelativeId(context, button1, "table1");
112 assertEquals("table1", relativeId);
113
114 relativeId =
115 RenderUtils.getRelativeId(context, button1, ":table1");
116 assertEquals("table1", relativeId);
117
118
119 relativeId =
120 RenderUtils.getRelativeId(context, table1, "someRandomId");
121 assertEquals("table1_Client:someRandomId", relativeId);
122
123 relativeId =
124 RenderUtils.getRelativeId(context, table1, ":commandButton1");
125 assertEquals("commandButton1", relativeId);
126
127
128
129 relativeId =
130 RenderUtils.getRelativeId(context, table1, "::commandButton1");
131 assertEquals("commandButton1", relativeId);
132
133
134
135 relativeId =
136 RenderUtils.getRelativeId(context, table1, "commandButton1");
137 assertEquals("commandButton1", relativeId);
138
139
140 relativeId =
141 RenderUtils.getRelativeId(context, table1, "table1:tableChildId");
142 assertEquals("table1:tableChildId", relativeId);
143
144 relativeId =
145 RenderUtils.getRelativeId(context, table1, "tableChildId");
146 assertEquals("table1:tableChildId", relativeId);
147
148 }
149
150
151
152
153 @SuppressWarnings("unchecked")
154 public void testRelativeSearch()
155 {
156 FacesContext context = FacesContext.getCurrentInstance();
157
158
159
160 UIXForm form = new UIXForm(); form.setId("formId");
161 TestNamingContainer ncRoot = new TestNamingContainer(); ncRoot.setId("ncRoot");
162 TestUIXPanel button1 = new TestUIXPanel();
163 button1.setId("button1");
164 TestUIXPanel button2 = new TestUIXPanel();
165 button2.setId("button2");
166 TestUIXPanel rootButton = new TestUIXPanel();
167 rootButton.setId("rootButton");
168
169 form.getChildren().add(ncRoot);
170 form.getChildren().add(rootButton);
171 ncRoot.getChildren().add(button1);
172 ncRoot.getChildren().add(button2);
173
174 TestNamingContainer nc1 = new TestNamingContainer();
175 nc1.setId("nc1");
176
177
178 UIXInput inputA = new UIXInput(); inputA.setId("inputA");
179 UIXPanel panel1 = new UIXPanel(); panel1.setId("panel1");
180 UIXInput input1 = new UIXInput(); input1.setId("input1");
181 ncRoot.getChildren().add(nc1);
182 nc1.getChildren().add(inputA);
183 nc1.getChildren().add(panel1);
184 panel1.getChildren().add(input1);
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201 String relativeId =
202 RenderUtils.getRelativeId(context, input1, "::button1");
203
204 assertEquals("ncRoot:button1", relativeId);
205
206
207 relativeId =
208 RenderUtils.getRelativeId(context, input1, ":::button1");
209
210
211
212 assertEquals("ncRoot:button1", relativeId);
213
214
215 relativeId =
216 RenderUtils.getRelativeId(context, input1, "randomPeer");
217
218
219 assertEquals("nc1_Client:randomPeer", relativeId);
220
221 relativeId =
222 RenderUtils.getRelativeId(context, input1, "::randomPeer");
223
224
225 assertEquals("ncRoot_Client:randomPeer", relativeId);
226
227
228 relativeId =
229 RenderUtils.getRelativeId(context, input1, ":::rootButton");
230
231 assertEquals("rootButton", relativeId);
232
233
234
235 relativeId =
236 RenderUtils.getRelativeId(context, input1, "::rootButton");
237
238
239
240
241
242 assertEquals("ncRoot_Client:rootButton", relativeId);
243
244
245
246 relativeId =
247 RenderUtils.getRelativeId(context, input1, "::::rootButton");
248
249 assertEquals("rootButton", relativeId);
250
251
252
253 relativeId =
254 RenderUtils.getRelativeId(context, input1, "::::button1");
255
256 assertEquals("button1", relativeId);
257
258 relativeId =
259 RenderUtils.getRelativeId(context, input1, ":::::button1");
260 assertEquals("button1", relativeId);
261 }
262
263
264
265 }