View Javadoc

1   /*
2    * $Id: TooltipTest.java 738624 2009-01-28 21:12:12Z musachy $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.views.jsp.ui;
23  
24  import java.util.HashMap;
25  
26  import org.apache.struts2.TestConfigurationProvider;
27  import org.apache.struts2.views.jsp.AbstractUITagTest;
28  import org.apache.struts2.views.jsp.ParamTag;
29  import org.apache.struts2.views.jsp.StrutsMockBodyContent;
30  
31  import com.mockobjects.servlet.MockJspWriter;
32  
33  /***
34   * UI components Tooltip test case.
35   */
36  public class TooltipTest extends AbstractUITagTest {
37  
38      public void testWithoutFormOverriding() throws Exception {
39  
40          // we test it on textfield component, but since the tooltip are common to
41          // all components, it will be the same for other components as well.
42          FormTag formTag = new FormTag();
43          formTag.setPageContext(pageContext);
44          formTag.setId("myFormId");
45          formTag.setAction("testAction");
46          formTag.setName("myForm");
47  
48  
49          TextFieldTag tag = new TextFieldTag();
50          tag.setPageContext(pageContext);
51          tag.setLabel("MyLabel");
52          tag.setId("myId");
53  
54  
55          tag.setTooltip("myTooltip");
56          tag.setTooltipConfig(
57                  "#{" +
58                          "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
59                          "'tooltipDelay':'500', " +
60                          "'jsTooltipEnabled':'true' "+
61                          "}"
62          );
63  
64          formTag.doStartTag();
65          tag.doStartTag();
66          tag.doEndTag();
67          formTag.doEndTag();
68  
69          verify(TooltipTest.class.getResource("tooltip-1.txt"));
70      }
71  
72      public void testWithoutFormOverridingNoJS() throws Exception {
73  
74          // we test it on textfield component, but since the tooltip are common to
75          // all components, it will be the same for other components as well.
76          FormTag formTag = new FormTag();
77          formTag.setPageContext(pageContext);
78          formTag.setId("myFormId");
79          formTag.setAction("testAction");
80          formTag.setName("myForm");
81  
82  
83          TextFieldTag tag = new TextFieldTag();
84          tag.setPageContext(pageContext);
85          tag.setLabel("MyLabel");
86          tag.setId("myId");
87  
88  
89          tag.setTooltip("myTooltip");
90          tag.setTooltipConfig(
91                  "#{" +
92                          "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
93                          "'tooltipDelay':'500', " +
94                          "'jsTooltipEnabled':'false' "+
95                          "}"
96          );
97  
98          formTag.doStartTag();
99          tag.doStartTag();
100         tag.doEndTag();
101         formTag.doEndTag();
102 
103         verify(TooltipTest.class.getResource("tooltip-4.txt"));
104     }
105     
106     public void testWithoutFormOverridingNew() throws Exception {
107 
108         // we test it on textfield component, but since the tooltip are common to
109         // all components, it will be the same for other components as well.
110         FormTag formTag = new FormTag();
111         formTag.setPageContext(pageContext);
112         formTag.setId("myFormId");
113         formTag.setAction("testAction");
114         formTag.setName("myForm");
115 
116 
117         TextFieldTag tag = new TextFieldTag();
118         tag.setPageContext(pageContext);
119         tag.setLabel("MyLabel");
120         tag.setId("myId");
121 
122 
123         //same parameters as the OGNL map configuration, output must be the same
124         tag.setTooltip("myTooltip");
125         tag.setTooltipIconPath("/struts/tooltip/myTooltip.gif");
126         tag.setTooltipDelay("500");
127         tag.setJavascriptTooltip("true");
128        
129 
130         formTag.doStartTag();
131         tag.doStartTag();
132         tag.doEndTag();
133         formTag.doEndTag();
134 
135         verify(TooltipTest.class.getResource("tooltip-1.txt"));
136     }
137 
138     public void testWithFormOverriding() throws Exception {
139 
140         FormTag formTag = new FormTag();
141         formTag.setPageContext(pageContext);
142         formTag.setName("myForm");
143         formTag.setId("myFormId");
144         formTag.setAction("testAction");
145 
146         formTag.setTooltipConfig(
147                 "#{" +
148                 "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
149                 "'tooltipDelay':'500', " +
150                 "'jsTooltipEnabled':'true' "+
151                 "}"
152         );
153 
154 
155         TextFieldTag tag = new TextFieldTag();
156         tag.setPageContext(pageContext);
157         tag.setLabel("MyLabel");
158         tag.setId("myId");
159 
160         tag.setTooltip("myTooltip");
161 
162         formTag.doStartTag();
163         tag.doStartTag();
164         tag.doEndTag();
165         formTag.doEndTag();
166 
167         verify(TooltipTest.class.getResource("tooltip-2.txt"));
168     }
169     
170     public void testWithFormOverridingNew() throws Exception {
171 
172         FormTag formTag = new FormTag();
173         formTag.setPageContext(pageContext);
174         formTag.setName("myForm");
175         formTag.setId("myFormId");
176         formTag.setAction("testAction");
177 
178         // same parameters as the OGNL map configuration, output must be the same
179         formTag.setTooltip("myTooltip");
180         formTag.setTooltipIconPath("/struts/tooltip/myTooltip.gif");
181         formTag.setTooltipDelay("500");
182         formTag.setJavascriptTooltip("true");
183 
184 
185         TextFieldTag tag = new TextFieldTag();
186         tag.setPageContext(pageContext);
187         tag.setLabel("MyLabel");
188         tag.setId("myId");
189 
190         tag.setTooltip("myTooltip");
191 
192         formTag.doStartTag();
193         tag.doStartTag();
194         tag.doEndTag();
195         formTag.doEndTag();
196 
197         verify(TooltipTest.class.getResource("tooltip-2.txt"));
198     }
199 
200     public void testWithPartialFormOverriding() throws Exception {
201 
202         FormTag formTag = new FormTag();
203         formTag.setName("myForm");
204         formTag.setPageContext(pageContext);
205         formTag.setId("myFormId");
206         formTag.setAction("testAction");
207 
208         formTag.setTooltipConfig(
209                 "#{" +
210                 "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
211                 "'tooltipDelay':'500', " +
212                 "'jsTooltipEnabled':'true' "+
213                 "}"
214         );
215 
216 
217         TextFieldTag tag = new TextFieldTag();
218         tag.setPageContext(pageContext);
219         tag.setLabel("MyLabel");
220         tag.setId("myId");
221 
222         tag.setTooltip("myTooltip");
223         tag.setTooltipConfig(
224                 "#{" +
225                 "'tooltipIcon':'/struts/tooltip/myTooltip2.gif', " +
226                 "'tooltipDelay':'5000' " +
227                 "}"
228         );
229 
230         formTag.doStartTag();
231         tag.doStartTag();
232         tag.doEndTag();
233         formTag.doEndTag();
234 
235         verify(TooltipTest.class.getResource("tooltip-3.txt"));
236     }
237 
238     public void testWithPartialFormOverridingNew() throws Exception {
239 
240         FormTag formTag = new FormTag();
241         formTag.setName("myForm");
242         formTag.setPageContext(pageContext);
243         formTag.setId("myFormId");
244         formTag.setAction("testAction");
245 
246         // same parameters as the OGNL map configuration, output must be the same
247         formTag.setTooltip("myTooltip");
248         formTag.setTooltipIconPath("/struts/tooltip/myTooltip.gif");
249         formTag.setTooltipDelay("500");
250         formTag.setJavascriptTooltip("true");
251 
252 
253         TextFieldTag tag = new TextFieldTag();
254         tag.setPageContext(pageContext);
255         tag.setLabel("MyLabel");
256         tag.setId("myId");
257 
258 
259         //same parameters as the OGNL map configuration, output must be the same
260         tag.setTooltip("myTooltip");
261         tag.setTooltipIconPath("/struts/tooltip/myTooltip2.gif");
262         tag.setTooltipDelay("5000");
263         tag.setJavascriptTooltip("true");
264 
265         formTag.doStartTag();
266         tag.doStartTag();
267         tag.doEndTag();
268         formTag.doEndTag();
269 
270         verify(TooltipTest.class.getResource("tooltip-3.txt"));
271     }
272 
273     public void testUsingParamValueToSetConfigurations() throws Exception {
274         FormTag formTag = new FormTag();
275         formTag.setName("myForm");
276         formTag.setPageContext(pageContext);
277         formTag.setId("myFormId");
278         formTag.setAction("testAction");
279 
280 
281         ParamTag formParamTag = new ParamTag();
282         formParamTag.setPageContext(pageContext);
283         formParamTag.setName("tooltipConfig");
284         formParamTag.setValue(
285                 "#{" +
286                 "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
287                 "'tooltipDelay':'500', " +
288                 "'jsTooltipEnabled':'true' "+
289                 "}"
290         );
291 
292 
293         TextFieldTag tag = new TextFieldTag();
294         tag.setPageContext(pageContext);
295         tag.setLabel("MyLabel");
296         tag.setId("myId");
297         tag.setTooltip("myTooltip");
298 
299         ParamTag textFieldParamTag = new ParamTag();
300         textFieldParamTag.setPageContext(pageContext);
301         textFieldParamTag.setName("tooltipConfig");
302         textFieldParamTag.setValue(
303                 "#{" +
304                 "'tooltipIcon':'/struts/tooltip/myTooltip2.gif', " +
305                 "'tooltipDelay':'5000' "+
306                 "}"
307         );
308 
309         formTag.doStartTag();
310         formParamTag.doStartTag();
311         formParamTag.doEndTag();
312         tag.doStartTag();
313         textFieldParamTag.doStartTag();
314         textFieldParamTag.doEndTag();
315         tag.doEndTag();
316         formTag.doEndTag();
317 
318         verify(TooltipTest.class.getResource("tooltip-3.txt"));
319     }
320 
321 
322     public void testUsingParamBodyValueToSetConfigurations() throws Exception {
323 
324         FormTag formTag = new FormTag();
325         formTag.setName("myForm");
326         formTag.setPageContext(pageContext);
327         formTag.setId("myFormId");
328         formTag.setAction("testAction");
329 
330 
331         ParamTag formParamTag = new ParamTag();
332         formParamTag.setPageContext(pageContext);
333         formParamTag.setName("tooltipConfig");
334         StrutsMockBodyContent bodyContent = new StrutsMockBodyContent(new MockJspWriter());
335         bodyContent.setString(
336                 "tooltipIcon=/struts/tooltip/myTooltip.gif| " +
337                 "tooltipDelay=500| " +
338                 "jsTooltipEnabled=true "
339         );
340         formParamTag.setBodyContent(bodyContent);
341 
342         TextFieldTag tag = new TextFieldTag();
343         tag.setPageContext(pageContext);
344         tag.setLabel("MyLabel");
345         tag.setId("myId");
346         tag.setTooltip("myTooltip");
347 
348 
349         ParamTag textFieldParamTag = new ParamTag();
350         textFieldParamTag.setPageContext(pageContext);
351         textFieldParamTag.setName("tooltipConfig");
352         StrutsMockBodyContent bodyContent2 = new StrutsMockBodyContent(new MockJspWriter());
353         bodyContent2.setString(
354                 "tooltipIcon=/struts/tooltip/myTooltip2.gif| " +
355                 "tooltipDelay=5000 "
356         );
357         textFieldParamTag.setBodyContent(bodyContent2);
358 
359         formTag.doStartTag();
360         formParamTag.doStartTag();
361         formParamTag.doEndTag();
362         tag.doStartTag();
363         textFieldParamTag.doStartTag();
364         textFieldParamTag.doEndTag();
365         tag.doEndTag();
366         formTag.doEndTag();
367 
368         System.out.println(writer.toString());
369 
370         verify(TooltipTest.class.getResource("tooltip-3.txt"));
371     }
372 
373     /***
374      * @throws Exception 
375      * 
376      */
377     public void setUp() throws Exception {
378         super.setUp();
379         initDispatcher(new HashMap<String,String>(){{ 
380             put("configProviders", TestConfigurationProvider.class.getName());
381         }});
382     }
383 }