001: /*
002: * $Id: TooltipTest.java 474191 2006-11-13 08:30:40Z mrdon $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp.ui;
022:
023: import java.util.HashMap;
024:
025: import org.apache.struts2.TestConfigurationProvider;
026: import org.apache.struts2.views.jsp.AbstractUITagTest;
027: import org.apache.struts2.views.jsp.ParamTag;
028: import org.apache.struts2.views.jsp.StrutsMockBodyContent;
029:
030: import com.mockobjects.servlet.MockJspWriter;
031:
032: /**
033: * UI components Tooltip test case.
034: */
035: public class TooltipTest extends AbstractUITagTest {
036:
037: public void testWithoutFormOverriding() throws Exception {
038:
039: // we test it on textfield component, but since the tooltip are common to
040: // all components, it will be the same for other components as well.
041: FormTag formTag = new FormTag();
042: formTag.setPageContext(pageContext);
043: formTag.setId("myFormId");
044: formTag.setAction("testAction");
045: formTag.setName("myForm");
046:
047: TextFieldTag tag = new TextFieldTag();
048: tag.setPageContext(pageContext);
049: tag.setLabel("MyLabel");
050: tag.setId("myId");
051:
052: tag.setTooltip("myTooltip");
053: tag.setTooltipConfig("#{"
054: + "'tooltipIcon':'/struts/tooltip/myTooltip.gif', "
055: + "'tooltipDelay':'500', "
056: + "'jsTooltipEnabled':'true' " + "}");
057:
058: formTag.doStartTag();
059: tag.doStartTag();
060: tag.doEndTag();
061: formTag.doEndTag();
062:
063: verify(TooltipTest.class.getResource("tooltip-1.txt"));
064: }
065:
066: public void testWithFormOverriding() throws Exception {
067:
068: FormTag formTag = new FormTag();
069: formTag.setPageContext(pageContext);
070: formTag.setName("myForm");
071: formTag.setId("myFormId");
072: formTag.setAction("testAction");
073:
074: formTag.setTooltipConfig("#{"
075: + "'tooltipIcon':'/struts/tooltip/myTooltip.gif', "
076: + "'tooltipDelay':'500', "
077: + "'jsTooltipEnabled':'true' " + "}");
078:
079: TextFieldTag tag = new TextFieldTag();
080: tag.setPageContext(pageContext);
081: tag.setLabel("MyLabel");
082: tag.setId("myId");
083:
084: tag.setTooltip("myTooltip");
085:
086: formTag.doStartTag();
087: tag.doStartTag();
088: tag.doEndTag();
089: formTag.doEndTag();
090:
091: verify(TooltipTest.class.getResource("tooltip-2.txt"));
092: }
093:
094: public void testWithPartialFormOverriding() throws Exception {
095:
096: FormTag formTag = new FormTag();
097: formTag.setName("myForm");
098: formTag.setPageContext(pageContext);
099: formTag.setId("myFormId");
100: formTag.setAction("testAction");
101:
102: formTag.setTooltipConfig("#{"
103: + "'tooltipIcon':'/struts/tooltip/myTooltip.gif', "
104: + "'tooltipDelay':'500', "
105: + "'jsTooltipEnabled':'true' " + "}");
106:
107: TextFieldTag tag = new TextFieldTag();
108: tag.setPageContext(pageContext);
109: tag.setLabel("MyLabel");
110: tag.setId("myId");
111:
112: tag.setTooltip("myTooltip");
113: tag.setTooltipConfig("#{"
114: + "'tooltipIcon':'/struts/tooltip/myTooltip2.gif', "
115: + "'tooltipDelay':'5000' " + "}");
116:
117: formTag.doStartTag();
118: tag.doStartTag();
119: tag.doEndTag();
120: formTag.doEndTag();
121:
122: verify(TooltipTest.class.getResource("tooltip-3.txt"));
123: }
124:
125: public void testUsingParamValueToSetConfigurations()
126: throws Exception {
127: FormTag formTag = new FormTag();
128: formTag.setName("myForm");
129: formTag.setPageContext(pageContext);
130: formTag.setId("myFormId");
131: formTag.setAction("testAction");
132:
133: ParamTag formParamTag = new ParamTag();
134: formParamTag.setPageContext(pageContext);
135: formParamTag.setName("tooltipConfig");
136: formParamTag.setValue("#{"
137: + "'tooltipIcon':'/struts/tooltip/myTooltip.gif', "
138: + "'tooltipDelay':'500', "
139: + "'jsTooltipEnabled':'true' " + "}");
140:
141: TextFieldTag tag = new TextFieldTag();
142: tag.setPageContext(pageContext);
143: tag.setLabel("MyLabel");
144: tag.setId("myId");
145: tag.setTooltip("myTooltip");
146:
147: ParamTag textFieldParamTag = new ParamTag();
148: textFieldParamTag.setPageContext(pageContext);
149: textFieldParamTag.setName("tooltipConfig");
150: textFieldParamTag.setValue("#{"
151: + "'tooltipIcon':'/struts/tooltip/myTooltip2.gif', "
152: + "'tooltipDelay':'5000' " + "}");
153:
154: formTag.doStartTag();
155: formParamTag.doStartTag();
156: formParamTag.doEndTag();
157: tag.doStartTag();
158: textFieldParamTag.doStartTag();
159: textFieldParamTag.doEndTag();
160: tag.doEndTag();
161: formTag.doEndTag();
162:
163: verify(TooltipTest.class.getResource("tooltip-3.txt"));
164: }
165:
166: public void testUsingParamBodyValueToSetConfigurations()
167: throws Exception {
168:
169: FormTag formTag = new FormTag();
170: formTag.setName("myForm");
171: formTag.setPageContext(pageContext);
172: formTag.setId("myFormId");
173: formTag.setAction("testAction");
174:
175: ParamTag formParamTag = new ParamTag();
176: formParamTag.setPageContext(pageContext);
177: formParamTag.setName("tooltipConfig");
178: StrutsMockBodyContent bodyContent = new StrutsMockBodyContent(
179: new MockJspWriter());
180: bodyContent
181: .setString("tooltipIcon=/struts/tooltip/myTooltip.gif| "
182: + "tooltipDelay=500| "
183: + "jsTooltipEnabled=true ");
184: formParamTag.setBodyContent(bodyContent);
185:
186: TextFieldTag tag = new TextFieldTag();
187: tag.setPageContext(pageContext);
188: tag.setLabel("MyLabel");
189: tag.setId("myId");
190: tag.setTooltip("myTooltip");
191:
192: ParamTag textFieldParamTag = new ParamTag();
193: textFieldParamTag.setPageContext(pageContext);
194: textFieldParamTag.setName("tooltipConfig");
195: StrutsMockBodyContent bodyContent2 = new StrutsMockBodyContent(
196: new MockJspWriter());
197: bodyContent2
198: .setString("tooltipIcon=/struts/tooltip/myTooltip2.gif| "
199: + "tooltipDelay=5000 ");
200: textFieldParamTag.setBodyContent(bodyContent2);
201:
202: formTag.doStartTag();
203: formParamTag.doStartTag();
204: formParamTag.doEndTag();
205: tag.doStartTag();
206: textFieldParamTag.doStartTag();
207: textFieldParamTag.doEndTag();
208: tag.doEndTag();
209: formTag.doEndTag();
210:
211: System.out.println(writer.toString());
212:
213: verify(TooltipTest.class.getResource("tooltip-3.txt"));
214: }
215:
216: /**
217: * @throws Exception
218: *
219: */
220: public void setUp() throws Exception {
221: super .setUp();
222: initDispatcher(new HashMap<String, String>() {
223: {
224: put("configProviders", TestConfigurationProvider.class
225: .getName());
226: }
227: });
228: }
229: }
|