Source Code Cross Referenced for ComponentTest.java in  » Web-Framework » struts-2.0.11 » org » apache » struts2 » components » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » struts 2.0.11 » org.apache.struts2.components 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ComponentTest.java 471756 2006-11-06 15:01:43Z husted $
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.components;
022:
023:        import java.util.Iterator;
024:        import java.util.Locale;
025:        import java.util.Stack;
026:
027:        import javax.servlet.jsp.tagext.TagSupport;
028:
029:        import org.apache.struts2.views.jsp.AbstractTagTest;
030:        import org.apache.struts2.views.jsp.BeanTag;
031:        import org.apache.struts2.views.jsp.ElseIfTag;
032:        import org.apache.struts2.views.jsp.ElseTag;
033:        import org.apache.struts2.views.jsp.I18nTag;
034:        import org.apache.struts2.views.jsp.IfTag;
035:        import org.apache.struts2.views.jsp.IteratorTag;
036:        import org.apache.struts2.views.jsp.PropertyTag;
037:        import org.apache.struts2.views.jsp.PushTag;
038:        import org.apache.struts2.views.jsp.SetTag;
039:        import org.apache.struts2.views.jsp.TextTag;
040:        import org.apache.struts2.views.jsp.URLTag;
041:        import org.apache.struts2.views.jsp.iterator.AppendIteratorTag;
042:        import org.apache.struts2.views.jsp.iterator.MergeIteratorTag;
043:        import org.apache.struts2.views.jsp.ui.TextFieldTag;
044:        import org.apache.struts2.views.jsp.ui.UpDownSelectTag;
045:
046:        import com.opensymphony.xwork2.ActionContext;
047:        import com.opensymphony.xwork2.util.LocalizedTextUtil;
048:
049:        /**
050:         * Test case for method findAncestor(Class) in Component and some commons
051:         * test cases for Component in general.
052:         *
053:         */
054:        public class ComponentTest extends AbstractTagTest {
055:
056:            public void testFindAncestorTest() throws Exception {
057:                Property property = new Property(stack);
058:                Form form = new Form(stack, request, response);
059:                ActionComponent actionComponent = new ActionComponent(stack,
060:                        request, response);
061:                Anchor anchor = new Anchor(stack, request, response);
062:                Form form2 = new Form(stack, request, response);
063:                TextField textField = new TextField(stack, request, response);
064:
065:                Stack stack = property.getComponentStack();
066:                Iterator i = stack.iterator();
067:
068:                try {
069:                    // component stack
070:                    assertEquals(property.getComponentStack().size(), 6);
071:                    assertEquals(i.next(), property);
072:                    assertEquals(i.next(), form);
073:                    assertEquals(i.next(), actionComponent);
074:                    assertEquals(i.next(), anchor);
075:                    assertEquals(i.next(), form2);
076:                    assertEquals(i.next(), textField);
077:
078:                    // property
079:                    assertNull(property.findAncestor(Component.class));
080:
081:                    // form
082:                    assertEquals(form.findAncestor(Component.class), property);
083:                    assertEquals(form.findAncestor(Property.class), property);
084:
085:                    // action
086:                    assertEquals(actionComponent.findAncestor(Component.class),
087:                            form);
088:                    assertEquals(actionComponent.findAncestor(Property.class),
089:                            property);
090:                    assertEquals(actionComponent.findAncestor(Form.class), form);
091:
092:                    // anchor
093:                    assertEquals(anchor.findAncestor(Component.class),
094:                            actionComponent);
095:                    assertEquals(anchor.findAncestor(ActionComponent.class),
096:                            actionComponent);
097:                    assertEquals(anchor.findAncestor(Form.class), form);
098:                    assertEquals(anchor.findAncestor(Property.class), property);
099:
100:                    // form2
101:                    assertEquals(form2.findAncestor(Component.class), anchor);
102:                    assertEquals(form2.findAncestor(Anchor.class), anchor);
103:                    assertEquals(form2.findAncestor(ActionComponent.class),
104:                            actionComponent);
105:                    assertEquals(form2.findAncestor(Form.class), form);
106:                    assertEquals(form2.findAncestor(Property.class), property);
107:
108:                    // textField
109:                    assertEquals(textField.findAncestor(Component.class), form2);
110:                    assertEquals(textField.findAncestor(Form.class), form2);
111:                    assertEquals(textField.findAncestor(Anchor.class), anchor);
112:                    assertEquals(textField.findAncestor(ActionComponent.class),
113:                            actionComponent);
114:                    assertEquals(textField.findAncestor(Property.class),
115:                            property);
116:                } finally {
117:                    property.getComponentStack().pop();
118:                    property.getComponentStack().pop();
119:                    property.getComponentStack().pop();
120:                    property.getComponentStack().pop();
121:                    property.getComponentStack().pop();
122:                }
123:            }
124:
125:            // Action Component
126:            /*
127:            public void testActionComponentDisposeItselfFromComponentStack() throws Exception {
128:                ConfigurationManager.clearConfigurationProviders();
129:                ConfigurationManager.addConfigurationProvider(new TestConfigurationProvider());
130:                ConfigurationManager.getConfiguration().reload();
131:
132:                ActionContext actionContext = new ActionContext(context);
133:                actionContext.setValueStack(stack);
134:                ActionContext.setContext(actionContext);
135:
136:                request.setupGetServletPath(TestConfigurationProvider.TEST_NAMESPACE + "/" + "foo.action");
137:                try {
138:                    TextFieldTag t = new TextFieldTag();
139:                    t.setName("textFieldName");
140:                    t.setPageContext(pageContext);
141:                    t.doStartTag();
142:
143:                    ActionTag tag = new ActionTag();
144:                    tag.setPageContext(pageContext);
145:                    tag.setName(TestConfigurationProvider.TEST_NAMESPACE_ACTION);
146:                    tag.setId(TestConfigurationProvider.TEST_NAMESPACE_ACTION);
147:                    tag.doStartTag();
148:                    assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent());
149:                    tag.doEndTag();
150:                    assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent());
151:
152:                    t.doEndTag();
153:                }
154:                catch(Exception e) {
155:                    e.printStackTrace();
156:                    fail(e.toString());
157:                }
158:            }
159:             */
160:
161:            // AppendInterator
162:            public void testAppendIteratorDisposeItselfFromComponentStack()
163:                    throws Exception {
164:                TextFieldTag t = new TextFieldTag();
165:                t.setPageContext(pageContext);
166:                t.setName("textFieldName");
167:
168:                AppendIteratorTag tag = new AppendIteratorTag();
169:                tag.setPageContext(pageContext);
170:
171:                try {
172:                    t.doStartTag();
173:                    tag.doStartTag();
174:                    assertEquals(tag.getComponent().getComponentStack().peek(),
175:                            tag.getComponent());
176:                    tag.doEndTag();
177:                    assertEquals(t.getComponent().getComponentStack().peek(), t
178:                            .getComponent());
179:                    t.doEndTag();
180:                } catch (Exception e) {
181:                    e.printStackTrace();
182:                    fail(e.toString());
183:                }
184:            }
185:
186:            // Bean
187:            public void testBeanComponentDisposeItselfFromComponentStack()
188:                    throws Exception {
189:                TextFieldTag t = new TextFieldTag();
190:                t.setPageContext(pageContext);
191:                t.setName("textFieldName");
192:
193:                BeanTag tag = new BeanTag();
194:                tag.setName("org.apache.struts2.util.Counter");
195:                tag.setPageContext(pageContext);
196:
197:                try {
198:                    t.doStartTag();
199:                    tag.doStartTag();
200:                    assertEquals(tag.getComponent().getComponentStack().peek(),
201:                            tag.getComponent());
202:                    tag.doEndTag();
203:                    assertEquals(t.getComponent().getComponentStack().peek(), t
204:                            .getComponent());
205:                    t.doEndTag();
206:                } catch (Exception e) {
207:                    e.printStackTrace();
208:                    fail();
209:                }
210:            }
211:
212:            // ElseIf
213:            public void testElseIfComponentDisposeItselfFromComponentStack()
214:                    throws Exception {
215:                TextFieldTag t = new TextFieldTag();
216:                t.setPageContext(pageContext);
217:                t.setName("textFieldName");
218:
219:                ElseIfTag tag = new ElseIfTag();
220:                tag.setPageContext(pageContext);
221:
222:                try {
223:                    t.doStartTag();
224:                    tag.doStartTag();
225:                    assertEquals(tag.getComponent().getComponentStack().peek(),
226:                            tag.getComponent());
227:                    tag.doEndTag();
228:                    assertEquals(t.getComponent().getComponentStack().peek(), t
229:                            .getComponent());
230:                    t.doEndTag();
231:                } catch (Exception e) {
232:                    e.printStackTrace();
233:                    fail(e.toString());
234:                }
235:            }
236:
237:            // Else
238:            public void testElseComponentDisposeItselfFromComponentStack()
239:                    throws Exception {
240:                TextFieldTag t = new TextFieldTag();
241:                t.setPageContext(pageContext);
242:                t.setName("textFieldName");
243:
244:                ElseTag tag = new ElseTag();
245:                tag.setPageContext(pageContext);
246:
247:                try {
248:                    t.doStartTag();
249:                    tag.doStartTag();
250:                    assertEquals(tag.getComponent().getComponentStack().peek(),
251:                            tag.getComponent());
252:                    tag.doEndTag();
253:                    assertEquals(t.getComponent().getComponentStack().peek(), t
254:                            .getComponent());
255:                    t.doEndTag();
256:                } catch (Exception e) {
257:                    e.printStackTrace();
258:                    fail(e.toString());
259:                }
260:            }
261:
262:            // If
263:            public void testIfComponentDisposeItselfFromComponentStack()
264:                    throws Exception {
265:                TextFieldTag t = new TextFieldTag();
266:                t.setPageContext(pageContext);
267:                t.setName("textFieldName");
268:
269:                IfTag tag = new IfTag();
270:                tag.setTest("false");
271:                tag.setPageContext(pageContext);
272:
273:                try {
274:                    t.doStartTag();
275:                    tag.doStartTag();
276:                    assertEquals(tag.getComponent().getComponentStack().peek(),
277:                            tag.getComponent());
278:                    tag.doEndTag();
279:                    assertEquals(t.getComponent().getComponentStack().peek(), t
280:                            .getComponent());
281:                    t.doEndTag();
282:                } catch (Exception e) {
283:                    e.printStackTrace();
284:                    fail(e.toString());
285:                }
286:            }
287:
288:            // Iterator
289:            public void testIteratorComponentDisposeItselfFromComponentStack()
290:                    throws Exception {
291:                TextFieldTag t = new TextFieldTag();
292:                t.setPageContext(pageContext);
293:                t.setName("textFieldName");
294:
295:                IteratorTag tag = new IteratorTag();
296:                tag.setValue("{1,2}");
297:                tag.setPageContext(pageContext);
298:
299:                try {
300:                    t.doStartTag();
301:                    tag.doStartTag();
302:                    assertEquals(tag.getComponent().getComponentStack().peek(),
303:                            tag.getComponent());
304:                    int endIt = tag.doAfterBody();
305:                    while (TagSupport.EVAL_BODY_AGAIN == endIt) {
306:                        assertEquals(tag.getComponent().getComponentStack()
307:                                .peek(), tag.getComponent());
308:                        endIt = tag.doAfterBody();
309:                    }
310:                    tag.doEndTag();
311:                    assertEquals(t.getComponent().getComponentStack().peek(), t
312:                            .getComponent());
313:                    t.doEndTag();
314:                } catch (Exception e) {
315:                    e.printStackTrace();
316:                    fail(e.toString());
317:                }
318:            }
319:
320:            // MergeIterator
321:            public void testMergeIteratorComponentDisposeItselfFromComponentStack()
322:                    throws Exception {
323:                TextFieldTag t = new TextFieldTag();
324:                t.setPageContext(pageContext);
325:                t.setName("textFieldName");
326:
327:                MergeIteratorTag tag = new MergeIteratorTag();
328:                tag.setPageContext(pageContext);
329:
330:                try {
331:                    t.doStartTag();
332:                    tag.doStartTag();
333:                    assertEquals(tag.getComponent().getComponentStack().peek(),
334:                            tag.getComponent());
335:                    tag.doEndTag();
336:                    assertEquals(t.getComponent().getComponentStack().peek(), t
337:                            .getComponent());
338:                    t.doEndTag();
339:                } catch (Exception e) {
340:                    e.printStackTrace();
341:                    fail(e.toString());
342:                }
343:            }
344:
345:            // Property
346:            public void testPropertyComponentDisposeItselfFromComponentStack()
347:                    throws Exception {
348:                TextFieldTag t = new TextFieldTag();
349:                t.setPageContext(pageContext);
350:                t.setName("textFieldName");
351:
352:                PropertyTag tag = new PropertyTag();
353:                tag.setPageContext(pageContext);
354:
355:                try {
356:                    t.doStartTag();
357:                    tag.doStartTag();
358:                    assertEquals(tag.getComponent().getComponentStack().peek(),
359:                            tag.getComponent());
360:                    tag.doEndTag();
361:                    assertEquals(t.getComponent().getComponentStack().peek(), t
362:                            .getComponent());
363:                    t.doEndTag();
364:                } catch (Exception e) {
365:                    e.printStackTrace();
366:                    fail(e.toString());
367:                }
368:            }
369:
370:            // Push
371:            public void testPushComponentDisposeItselfFromComponentStack()
372:                    throws Exception {
373:                TextFieldTag t = new TextFieldTag();
374:                t.setPageContext(pageContext);
375:                t.setName("textFieldName");
376:
377:                PushTag tag = new PushTag();
378:                tag.setValue("'aaaa'");
379:                tag.setPageContext(pageContext);
380:
381:                try {
382:                    t.doStartTag();
383:                    tag.doStartTag();
384:                    assertEquals(tag.getComponent().getComponentStack().peek(),
385:                            tag.getComponent());
386:                    tag.doEndTag();
387:                    assertEquals(t.getComponent().getComponentStack().peek(), t
388:                            .getComponent());
389:                    t.doEndTag();
390:                } catch (Exception e) {
391:                    e.printStackTrace();
392:                    fail(e.toString());
393:                }
394:            }
395:
396:            // Set
397:            public void testSetComponentDisposeItselfFromComponentStack()
398:                    throws Exception {
399:                TextFieldTag t = new TextFieldTag();
400:                t.setPageContext(pageContext);
401:                t.setName("textFieldName");
402:
403:                SetTag tag = new SetTag();
404:                tag.setName("name");
405:                tag.setValue("'value'");
406:                tag.setPageContext(pageContext);
407:
408:                try {
409:                    t.doStartTag();
410:                    tag.doStartTag();
411:                    assertEquals(tag.getComponent().getComponentStack().peek(),
412:                            tag.getComponent());
413:                    tag.doEndTag();
414:                    assertEquals(t.getComponent().getComponentStack().peek(), t
415:                            .getComponent());
416:                    t.doEndTag();
417:                } catch (Exception e) {
418:                    e.printStackTrace();
419:                    fail(e.toString());
420:                }
421:            }
422:
423:            // Text
424:            public void testTextComponentDisposeItselfFromComponentStack()
425:                    throws Exception {
426:                TextFieldTag t = new TextFieldTag();
427:                t.setPageContext(pageContext);
428:                t.setName("textFieldName");
429:
430:                TextTag tag = new TextTag();
431:                tag.setName("some.i18n.key");
432:                tag.setPageContext(pageContext);
433:
434:                try {
435:                    t.doStartTag();
436:                    tag.doStartTag();
437:                    assertEquals(tag.getComponent().getComponentStack().peek(),
438:                            tag.getComponent());
439:                    tag.doEndTag();
440:                    assertEquals(t.getComponent().getComponentStack().peek(), t
441:                            .getComponent());
442:                    t.doEndTag();
443:                } catch (Exception e) {
444:                    e.printStackTrace();
445:                    fail(e.toString());
446:                }
447:            }
448:
449:            public void testI18nComponentDisposeItselfFromComponentStack()
450:                    throws Exception {
451:                stack.getContext().put(ActionContext.LOCALE,
452:                        Locale.getDefault());
453:
454:                TextFieldTag t = new TextFieldTag();
455:                t.setPageContext(pageContext);
456:                t.setName("textFieldName");
457:
458:                LocalizedTextUtil
459:                        .addDefaultResourceBundle("org.apache.struts2.components.temp");
460:
461:                I18nTag tag = new I18nTag();
462:                tag.setName("org.apache.struts2.components.tempo");
463:                tag.setPageContext(pageContext);
464:
465:                try {
466:                    t.doStartTag();
467:                    tag.doStartTag();
468:                    assertEquals(tag.getComponent().getComponentStack().peek(),
469:                            tag.getComponent());
470:                    tag.doEndTag();
471:                    assertEquals(t.getComponent().getComponentStack().peek(), t
472:                            .getComponent());
473:                    t.doEndTag();
474:                } catch (Exception e) {
475:                    e.printStackTrace();
476:                    fail(e.toString());
477:                }
478:            }
479:
480:            // URL
481:            public void testURLComponentDisposeItselfFromComponentStack()
482:                    throws Exception {
483:                TextFieldTag t = new TextFieldTag();
484:                t.setPageContext(pageContext);
485:                t.setName("textFieldName");
486:
487:                URLTag tag = new URLTag();
488:                tag.setPageContext(pageContext);
489:
490:                try {
491:                    t.doStartTag();
492:                    tag.doStartTag();
493:                    assertEquals(tag.getComponent().getComponentStack().peek(),
494:                            tag.getComponent());
495:                    tag.doEndTag();
496:                    assertEquals(t.getComponent().getComponentStack().peek(), t
497:                            .getComponent());
498:                    t.doEndTag();
499:                } catch (Exception e) {
500:                    e.printStackTrace();
501:                    fail(e.toString());
502:                }
503:            }
504:
505:            // updownselect
506:            public void testUpDownSelectDisposeItselfFromComponentStack()
507:                    throws Exception {
508:                TextFieldTag t = new TextFieldTag();
509:                t.setPageContext(pageContext);
510:                t.setName("textFieldName");
511:
512:                UpDownSelectTag tag = new UpDownSelectTag();
513:                tag.setId("myId");
514:                tag.setPageContext(pageContext);
515:                tag.setName("updownselectName");
516:                tag.setList("{}");
517:
518:                try {
519:                    t.doStartTag();
520:                    tag.doStartTag();
521:                    assertEquals(tag.getComponent().getComponentStack().peek(),
522:                            tag.getComponent());
523:                    tag.doEndTag();
524:                    assertEquals(t.getComponent().getComponentStack().peek(), t
525:                            .getComponent());
526:                    t.doEndTag();
527:                } catch (Exception e) {
528:                    e.printStackTrace();
529:                    fail(e.toString());
530:                }
531:            }
532:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.