Source Code Cross Referenced for ComponentTest.java in  » Ajax » NextApp-Echo2 » nextapp » echo2 » app » test » 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 » Ajax » NextApp Echo2 » nextapp.echo2.app.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003:         * Copyright (C) 2002-2005 NextApp, Inc.
004:         *
005:         * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006:         *
007:         * The contents of this file are subject to the Mozilla Public License Version
008:         * 1.1 (the "License"); you may not use this file except in compliance with
009:         * the License. You may obtain a copy of the License at
010:         * http://www.mozilla.org/MPL/
011:         *
012:         * Software distributed under the License is distributed on an "AS IS" basis,
013:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014:         * for the specific language governing rights and limitations under the
015:         * License.
016:         *
017:         * Alternatively, the contents of this file may be used under the terms of
018:         * either the GNU General Public License Version 2 or later (the "GPL"), or
019:         * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020:         * in which case the provisions of the GPL or the LGPL are applicable instead
021:         * of those above. If you wish to allow use of your version of this file only
022:         * under the terms of either the GPL or the LGPL, and not to allow others to
023:         * use your version of this file under the terms of the MPL, indicate your
024:         * decision by deleting the provisions above and replace them with the notice
025:         * and other provisions required by the GPL or the LGPL. If you do not delete
026:         * the provisions above, a recipient may use your version of this file under
027:         * the terms of any one of the MPL, the GPL or the LGPL.
028:         */
029:
030:        package nextapp.echo2.app.test;
031:
032:        import java.util.Locale;
033:
034:        import nextapp.echo2.app.ApplicationInstance;
035:        import nextapp.echo2.app.Color;
036:        import nextapp.echo2.app.Component;
037:        import nextapp.echo2.app.Extent;
038:        import nextapp.echo2.app.Font;
039:        import nextapp.echo2.app.layout.GridLayoutData;
040:        import junit.framework.TestCase;
041:
042:        /**
043:         * Unit test(s) for the <code>nextapp.echo2.app.Component</code> object. 
044:         */
045:        public class ComponentTest extends TestCase {
046:
047:            /**
048:             * Test <code>background</code> property.
049:             */
050:            public void testBackground() {
051:                NullComponent c = new NullComponent();
052:                PropertyChangeEvaluator pce = new PropertyChangeEvaluator();
053:                c.addPropertyChangeListener(pce);
054:                c.setBackground(new Color(0x12, 0x34, 0x56));
055:                assertEquals(new Color(0x12, 0x34, 0x56), c.getBackground());
056:                assertEquals(Component.PROPERTY_BACKGROUND, pce.lastEvent
057:                        .getPropertyName());
058:            }
059:
060:            /**
061:             * Test <code>enabled</code> property.
062:             */
063:            public void testEnabled() {
064:                NullComponent c = new NullComponent();
065:                PropertyChangeEvaluator pce = new PropertyChangeEvaluator();
066:                c.addPropertyChangeListener(pce);
067:                assertTrue(c.isEnabled());
068:                c.setEnabled(false);
069:                assertFalse(c.isEnabled());
070:                assertEquals(Component.ENABLED_CHANGED_PROPERTY, pce.lastEvent
071:                        .getPropertyName());
072:                c.setEnabled(false);
073:                assertFalse(c.isEnabled());
074:                c.setEnabled(true);
075:                assertTrue(c.isEnabled());
076:                c.setEnabled(true);
077:                assertTrue(c.isEnabled());
078:            }
079:
080:            /**
081:             * Test <code>focusTraversalIndex</code> property.
082:             */
083:            public void testFocusTraversalIndex() {
084:                Component c = new NullComponent();
085:                PropertyChangeEvaluator pce = new PropertyChangeEvaluator();
086:                c.addPropertyChangeListener(pce);
087:                assertEquals(0, c.getFocusTraversalIndex());
088:                c.setFocusTraversalIndex(5);
089:                assertEquals(Component.FOCUS_TRAVERSAL_INDEX_CHANGED_PROPERTY,
090:                        pce.lastEvent.getPropertyName());
091:                assertEquals(5, c.getFocusTraversalIndex());
092:                c.setVisible(false);
093:                assertEquals(false, c.isVisible());
094:                assertEquals(5, c.getFocusTraversalIndex());
095:                c.setFocusTraversalIndex(70);
096:                assertEquals(false, c.isVisible());
097:                assertEquals(70, c.getFocusTraversalIndex());
098:            }
099:
100:            /**
101:             * Test <code>font</code> property. 
102:             */
103:            public void testFont() {
104:                NullComponent c = new NullComponent();
105:                PropertyChangeEvaluator pce = new PropertyChangeEvaluator();
106:                c.addPropertyChangeListener(pce);
107:                c.setFont(new Font(Font.COURIER, Font.BOLD, new Extent(12,
108:                        Extent.PT)));
109:                assertEquals(new Font(Font.COURIER, Font.BOLD, new Extent(12,
110:                        Extent.PT)), c.getFont());
111:                assertEquals(Component.PROPERTY_FONT, pce.lastEvent
112:                        .getPropertyName());
113:            }
114:
115:            /**
116:             * Test <code>foreground</code> property.
117:             */
118:            public void testForeground() {
119:                NullComponent c = new NullComponent();
120:                PropertyChangeEvaluator pce = new PropertyChangeEvaluator();
121:                c.addPropertyChangeListener(pce);
122:                c.setForeground(new Color(0x12, 0x34, 0x56));
123:                assertEquals(new Color(0x12, 0x34, 0x56), c.getForeground());
124:                assertEquals(Component.PROPERTY_FOREGROUND, pce.lastEvent
125:                        .getPropertyName());
126:            }
127:
128:            /**
129:             * Test adding multiple child components and retrieving one at a specific
130:             * index via <code>getComponent()</code>.
131:             */
132:            public void testGetComponent() {
133:                NullComponent c = new NullComponent();
134:                for (int i = 0; i < 5; ++i) {
135:                    c.add(new NullComponent());
136:                }
137:                NullComponent sixthComponent = new NullComponent();
138:                c.add(sixthComponent);
139:                for (int i = 0; i < 5; ++i) {
140:                    c.add(new NullComponent());
141:                }
142:                assertTrue(sixthComponent == c.getComponent(5));
143:            }
144:
145:            /**
146:             * Tests <code>getComponent(String)</code>,
147:             * and <code>getId()</code>/<code>setId()</code> methods.
148:             */
149:            public void testGetComponentById() {
150:                NullComponent c1 = new NullComponent();
151:                c1.setId("c1");
152:                NullComponent c2 = new NullComponent();
153:                c2.setId("c2");
154:                c1.add(c2);
155:                NullComponent c3 = new NullComponent();
156:                c3.setId("c3");
157:                c1.add(c3);
158:                NullComponent c4 = new NullComponent();
159:                c4.setId("c4");
160:                c2.add(c4);
161:                NullComponent c5 = new NullComponent();
162:                c5.setId("c5");
163:                c2.add(c5);
164:                NullComponent c6 = new NullComponent();
165:                c6.setId("c6");
166:                c5.add(c6);
167:
168:                assertEquals("c1", c1.getId());
169:                assertEquals("c2", c2.getId());
170:                assertEquals("c3", c3.getId());
171:                assertEquals("c4", c4.getId());
172:                assertEquals("c5", c5.getId());
173:                assertEquals("c6", c6.getId());
174:
175:                assertEquals(c1, c1.getComponent("c1"));
176:                assertEquals(c2, c1.getComponent("c2"));
177:                assertEquals(c3, c1.getComponent("c3"));
178:                assertEquals(c4, c1.getComponent("c4"));
179:                assertEquals(c5, c1.getComponent("c5"));
180:                assertEquals(c6, c1.getComponent("c6"));
181:
182:                assertEquals(null, c2.getComponent("c1"));
183:                assertEquals(c2, c2.getComponent("c2"));
184:                assertEquals(null, c2.getComponent("c3"));
185:                assertEquals(c4, c2.getComponent("c4"));
186:                assertEquals(c5, c2.getComponent("c5"));
187:                assertEquals(c6, c2.getComponent("c6"));
188:
189:                assertEquals(null, c3.getComponent("c1"));
190:                assertEquals(null, c3.getComponent("c2"));
191:                assertEquals(c3, c3.getComponent("c3"));
192:                assertEquals(null, c3.getComponent("c4"));
193:                assertEquals(null, c3.getComponent("c5"));
194:                assertEquals(null, c3.getComponent("c6"));
195:            }
196:
197:            /**
198:             * Test <code>getComponentCount()</code>.
199:             */
200:            public void testGetComponentCount() {
201:                NullComponent c = new NullComponent();
202:                for (int i = 0; i < 5; ++i) {
203:                    c.add(new NullComponent());
204:                }
205:                assertEquals(5, c.getComponentCount());
206:            }
207:
208:            /**
209:             * Test <code>getComponents()</code>.
210:             */
211:            public void testGetComponents() {
212:                NullComponent parent = new NullComponent();
213:                NullComponent child1 = new NullComponent();
214:                NullComponent child2 = new NullComponent();
215:                parent.add(child1);
216:                parent.add(child2);
217:                Component[] children = parent.getComponents();
218:                assertSame(child1, children[0]);
219:                assertSame(child2, children[1]);
220:            }
221:
222:            /**
223:             * Test <code>getVisibleComponent()</code>.
224:             */
225:            public void testGetVisibleComponent() {
226:                IndexOutOfBoundsException exception;
227:                NullComponent parent = new NullComponent();
228:                NullComponent child1 = new NullComponent();
229:                NullComponent child2 = new NullComponent();
230:                parent.add(child1);
231:                parent.add(child2);
232:
233:                assertSame(child1, parent.getVisibleComponent(0));
234:                assertSame(child2, parent.getVisibleComponent(1));
235:                exception = null;
236:                try {
237:                    parent.getVisibleComponent(2);
238:                } catch (IndexOutOfBoundsException ex) {
239:                    exception = ex;
240:                }
241:                assertNotNull(exception);
242:
243:                child1.setVisible(false);
244:                assertSame(child2, parent.getVisibleComponent(0));
245:                exception = null;
246:                try {
247:                    parent.getVisibleComponent(1);
248:                } catch (IndexOutOfBoundsException ex) {
249:                    exception = ex;
250:                }
251:                assertNotNull(exception);
252:
253:                child2.setVisible(false);
254:                exception = null;
255:                try {
256:                    parent.getVisibleComponent(0);
257:                } catch (IndexOutOfBoundsException ex) {
258:                    exception = ex;
259:                }
260:                assertNotNull(exception);
261:
262:                child1.setVisible(true);
263:                assertSame(child1, parent.getVisibleComponent(0));
264:                exception = null;
265:                try {
266:                    parent.getVisibleComponent(1);
267:                } catch (IndexOutOfBoundsException ex) {
268:                    exception = ex;
269:                }
270:                assertNotNull(exception);
271:            }
272:
273:            /**
274:             * Test <code>getVisibleComponent()</code>.
275:             */
276:            public void testGetVisibleComponent2() {
277:                NullComponent c = new NullComponent();
278:                Exception exception = null;
279:                try {
280:                    c.getVisibleComponent(0);
281:                } catch (IndexOutOfBoundsException ex) {
282:                    exception = ex;
283:                }
284:                assertNotNull(exception);
285:            }
286:
287:            /**
288:             * Test <code>getVisibleComponentCount()</code>.
289:             */
290:            public void testGetVisibleComponentCount() {
291:                NullComponent c = new NullComponent();
292:                for (int i = 0; i < 5; ++i) {
293:                    c.add(new NullComponent());
294:                }
295:                assertEquals(5, c.getVisibleComponentCount());
296:                c.getComponent(1).setVisible(false);
297:                assertEquals(4, c.getVisibleComponentCount());
298:                c.getComponent(2).setVisible(false);
299:                assertEquals(3, c.getVisibleComponentCount());
300:            }
301:
302:            /**
303:             * Test <code>getVisibleComponents()</code>.
304:             */
305:            public void testGetVisibleComponents() {
306:                NullComponent parent = new NullComponent();
307:                NullComponent child1 = new NullComponent();
308:                NullComponent child2 = new NullComponent();
309:                parent.add(child1);
310:                parent.add(child2);
311:                Component[] children = parent.getVisibleComponents();
312:                assertEquals(2, children.length);
313:                assertSame(child1, children[0]);
314:                assertSame(child2, children[1]);
315:
316:                child1.setVisible(false);
317:                children = parent.getVisibleComponents();
318:                assertEquals(1, children.length);
319:                assertSame(child2, children[0]);
320:
321:                child2.setVisible(false);
322:                children = parent.getVisibleComponents();
323:                assertEquals(0, children.length);
324:
325:                child1.setVisible(true);
326:                children = parent.getVisibleComponents();
327:                assertEquals(1, children.length);
328:                assertSame(child1, children[0]);
329:            }
330:
331:            /**
332:             * Test <code>indexOf()</code> method.
333:             */
334:            public void testIndexOf() {
335:                NullComponent parent = new NullComponent();
336:                NullComponent a = new NullComponent();
337:                NullComponent b = new NullComponent();
338:                NullComponent c = new NullComponent();
339:                NullComponent d = new NullComponent();
340:                parent.add(a);
341:                parent.add(b);
342:                parent.add(c);
343:                assertEquals(0, parent.indexOf(a));
344:                assertEquals(1, parent.indexOf(b));
345:                assertEquals(2, parent.indexOf(c));
346:                assertEquals(-1, parent.indexOf(d));
347:            }
348:
349:            /**
350:             * Tests invocation of the <code>init()</code>/<code>dispose</code>
351:             * life-cycle methods with a single <code>Component</code>.
352:             */
353:            public void testLifecycleSingleComponent() {
354:                ColumnApp app = new ColumnApp();
355:                ApplicationInstance.setActive(app);
356:                app.doInit();
357:
358:                LifecycleTestComponent ltc1 = new LifecycleTestComponent();
359:                assertEquals(0, ltc1.getInitCount());
360:                assertEquals(0, ltc1.getDisposeCount());
361:                app.getColumn().add(ltc1);
362:                assertEquals(1, ltc1.getInitCount());
363:                assertEquals(0, ltc1.getDisposeCount());
364:                app.getColumn().remove(ltc1);
365:                assertEquals(1, ltc1.getInitCount());
366:                assertEquals(1, ltc1.getDisposeCount());
367:                app.getColumn().add(ltc1);
368:                assertEquals(2, ltc1.getInitCount());
369:                assertEquals(1, ltc1.getDisposeCount());
370:                app.getColumn().add(ltc1);
371:                assertEquals(3, ltc1.getInitCount());
372:                assertEquals(2, ltc1.getDisposeCount());
373:                app.getColumn().remove(ltc1);
374:                assertEquals(3, ltc1.getInitCount());
375:                assertEquals(3, ltc1.getDisposeCount());
376:                app.getColumn().remove(ltc1);
377:                assertEquals(3, ltc1.getInitCount());
378:                assertEquals(3, ltc1.getDisposeCount());
379:
380:                ApplicationInstance.setActive(null);
381:            }
382:
383:            /**
384:             * Tests invocation of the <code>init()</code>/<code>dispose</code>
385:             * life-cycle methods with a <code>Component</code> hierarchy.
386:             */
387:            public void testLifecycleComponentHierarchy() {
388:                ColumnApp app = new ColumnApp();
389:                ApplicationInstance.setActive(app);
390:                app.doInit();
391:
392:                LifecycleTestComponent ltc1 = new LifecycleTestComponent();
393:                LifecycleTestComponent ltc2 = new LifecycleTestComponent();
394:
395:                assertEquals(0, ltc1.getInitCount());
396:                assertEquals(0, ltc1.getDisposeCount());
397:                assertEquals(0, ltc2.getInitCount());
398:                assertEquals(0, ltc2.getDisposeCount());
399:
400:                ltc1.add(ltc2);
401:
402:                assertEquals(0, ltc1.getInitCount());
403:                assertEquals(0, ltc1.getDisposeCount());
404:                assertEquals(0, ltc2.getInitCount());
405:                assertEquals(0, ltc2.getDisposeCount());
406:
407:                app.getColumn().add(ltc1);
408:
409:                assertEquals(1, ltc1.getInitCount());
410:                assertEquals(0, ltc1.getDisposeCount());
411:                assertEquals(1, ltc2.getInitCount());
412:                assertEquals(0, ltc2.getDisposeCount());
413:
414:                app.getColumn().remove(ltc1);
415:
416:                assertEquals(1, ltc1.getInitCount());
417:                assertEquals(1, ltc1.getDisposeCount());
418:                assertEquals(1, ltc2.getInitCount());
419:                assertEquals(1, ltc2.getDisposeCount());
420:
421:                app.getColumn().add(ltc1);
422:
423:                assertEquals(2, ltc1.getInitCount());
424:                assertEquals(1, ltc1.getDisposeCount());
425:                assertEquals(2, ltc2.getInitCount());
426:                assertEquals(1, ltc2.getDisposeCount());
427:
428:                app.getColumn().add(ltc1);
429:
430:                assertEquals(3, ltc1.getInitCount());
431:                assertEquals(2, ltc1.getDisposeCount());
432:                assertEquals(3, ltc2.getInitCount());
433:                assertEquals(2, ltc2.getDisposeCount());
434:
435:                app.getColumn().remove(ltc1);
436:
437:                assertEquals(3, ltc1.getInitCount());
438:                assertEquals(3, ltc1.getDisposeCount());
439:                assertEquals(3, ltc2.getInitCount());
440:                assertEquals(3, ltc2.getDisposeCount());
441:
442:                app.getColumn().remove(ltc1);
443:
444:                assertEquals(3, ltc1.getInitCount());
445:                assertEquals(3, ltc1.getDisposeCount());
446:                assertEquals(3, ltc2.getInitCount());
447:                assertEquals(3, ltc2.getDisposeCount());
448:
449:                ApplicationInstance.setActive(null);
450:            }
451:
452:            /**
453:             * Ensure <code>IllegalStateException</code> is thrown if an attempt is
454:             * made to remove a <code>Component</code> from its hierarchy during the
455:             * execution of the <code>Component.init()</code> method.
456:             */
457:            public void testLifecycleRemoveDuringInit() {
458:                ColumnApp app = new ColumnApp();
459:                ApplicationInstance.setActive(app);
460:                app.doInit();
461:
462:                LifecycleTestComponent special = new LifecycleTestComponent() {
463:
464:                    public void init() {
465:                        super .init();
466:                        getParent().remove(this );
467:                    }
468:                };
469:
470:                try {
471:                    app.getColumn().add(special);
472:                    fail("Did not throw IllegalStateException as expected.");
473:                } catch (IllegalStateException ex) {
474:                    // Expected.
475:                }
476:            }
477:
478:            /**
479:             * Ensure <code>IllegalStateException</code> is thrown if an attempt is
480:             * made to add a <code>Component</code> back to a hierarchy during the
481:             * execution of the <code>Component.dispose()</code> method.
482:             */
483:            public void testLifecycleAddDuringDispose() {
484:                ColumnApp app = new ColumnApp();
485:                ApplicationInstance.setActive(app);
486:                app.doInit();
487:
488:                LifecycleTestComponent special = new LifecycleTestComponent() {
489:
490:                    public void dispose() {
491:                        super .init();
492:                        getParent().add(this );
493:                    }
494:                };
495:
496:                app.getColumn().add(special);
497:
498:                try {
499:                    app.getColumn().remove(special);
500:                    fail("Did not throw IllegalStateException as expected.");
501:                } catch (IllegalStateException ex) {
502:                    // Expected.
503:                }
504:            }
505:
506:            /**
507:             * Test <code>layoutData</code> property.
508:             */
509:            public void testLayoutData() {
510:                NullComponent c = new NullComponent();
511:                assertNull(c.getLayoutData());
512:                PropertyChangeEvaluator pce = new PropertyChangeEvaluator();
513:                c.addPropertyChangeListener(pce);
514:                GridLayoutData data = new GridLayoutData();
515:                data.setColumnSpan(2);
516:                c.setLayoutData(data);
517:                assertEquals(2, ((GridLayoutData) c.getLayoutData())
518:                        .getColumnSpan());
519:                assertEquals(Component.PROPERTY_LAYOUT_DATA, pce.lastEvent
520:                        .getPropertyName());
521:            }
522:
523:            /**
524:             * Test querying rendered <code>locale</code> property when no application 
525:             * is active. 
526:             */
527:            public void testRenderLocaleWithoutApplication() {
528:                NullComponent c = new NullComponent();
529:                assertNull(c.getRenderLocale());
530:                c.setLocale(Locale.TRADITIONAL_CHINESE);
531:                assertEquals(Locale.TRADITIONAL_CHINESE, c.getRenderLocale());
532:            }
533:
534:            /**
535:             * Test basic <code>PropertyChangeListener</code> functionality.
536:             */
537:            public void testPropertyChangeListeners() {
538:                PropertyChangeEvaluator pce = new PropertyChangeEvaluator();
539:                NullComponent c = new NullComponent();
540:                c.addPropertyChangeListener(pce);
541:                c.setBackground(new Color(0xabcdef));
542:                assertEquals(null, pce.lastEvent.getOldValue());
543:                assertEquals(new Color(0xabcdef), pce.lastEvent.getNewValue());
544:                assertEquals(c, pce.lastEvent.getSource());
545:                assertEquals(Component.PROPERTY_BACKGROUND, pce.lastEvent
546:                        .getPropertyName());
547:                c.setBackground(new Color(0xfedcba));
548:                assertEquals(new Color(0xabcdef), pce.lastEvent.getOldValue());
549:                assertEquals(new Color(0xfedcba), pce.lastEvent.getNewValue());
550:                c.setBackground(null);
551:                assertEquals(new Color(0xfedcba), pce.lastEvent.getOldValue());
552:                assertEquals(null, pce.lastEvent.getNewValue());
553:            }
554:
555:            /**
556:             * Test <code>removeAll()</code> method.
557:             */
558:            public void testRemoveAll() {
559:                NullComponent c = new NullComponent();
560:                c.add(new NullComponent());
561:                c.add(new NullComponent());
562:                c.add(new NullComponent());
563:                assertEquals(3, c.getComponentCount());
564:                c.removeAll();
565:                assertEquals(0, c.getComponentCount());
566:            }
567:
568:            /**
569:             * Test <code>remove(index)</code> method.
570:             */
571:            public void testRemoveByIndex() {
572:                NullComponent parent = new NullComponent();
573:                NullComponent a = new NullComponent();
574:                NullComponent b = new NullComponent();
575:                NullComponent c = new NullComponent();
576:                NullComponent d = new NullComponent();
577:                parent.add(a);
578:                parent.add(b);
579:                parent.add(c);
580:                parent.add(d);
581:                parent.remove(2);
582:                assertEquals(0, parent.indexOf(a));
583:                assertEquals(1, parent.indexOf(b));
584:                assertEquals(2, parent.indexOf(d));
585:                assertEquals(-1, parent.indexOf(c));
586:            }
587:
588:            /**
589:             * Tests assignment/reassignment of render ids.
590:             */
591:            public void testRenderId() {
592:                ColumnApp app1 = new ColumnApp();
593:                ApplicationInstance.setActive(app1);
594:                app1.doInit();
595:                NullComponent component1 = new NullComponent();
596:                assertNull(component1.getRenderId());
597:                app1.getColumn().add(component1);
598:                assertNotNull(component1.getApplicationInstance());
599:                assertNotNull(component1.getRenderId());
600:                ApplicationInstance.setActive(null);
601:
602:                ColumnApp app2 = new ColumnApp();
603:                ApplicationInstance.setActive(app2);
604:                app2.doInit();
605:                NullComponent component2 = new NullComponent();
606:                assertNull(component2.getRenderId());
607:                app2.getColumn().add(component2);
608:                assertNotNull(component2.getApplicationInstance());
609:                assertNotNull(component2.getRenderId());
610:                ApplicationInstance.setActive(null);
611:
612:                // This code relies on fact that ids are handed out sequentially, so sequence counters should be at same index.
613:                assertTrue(component1.getRenderId().equals(
614:                        component2.getRenderId()));
615:
616:                ApplicationInstance.setActive(app1);
617:                app1.getColumn().remove(component1);
618:                ApplicationInstance.setActive(null);
619:
620:                ApplicationInstance.setActive(app2);
621:                app2.getColumn().add(component1);
622:                ApplicationInstance.setActive(null);
623:
624:                assertFalse(component1.getRenderId().equals(
625:                        component2.getRenderId()));
626:            }
627:
628:            /**
629:             * Test render-enabled state.
630:             */
631:            public void testRenderEnabled() {
632:                ColumnApp app = new ColumnApp();
633:                ApplicationInstance.setActive(app);
634:                app.doInit();
635:                assertTrue(app.getContentPane().isRenderEnabled());
636:                assertTrue(app.getColumn().isRenderEnabled());
637:                assertTrue(app.getLabel().isRenderEnabled());
638:                app.getColumn().setEnabled(false);
639:                assertTrue(app.getContentPane().isRenderEnabled());
640:                assertFalse(app.getColumn().isRenderEnabled());
641:                assertFalse(app.getLabel().isRenderEnabled());
642:                app.getLabel().setEnabled(false);
643:                assertTrue(app.getContentPane().isRenderEnabled());
644:                assertFalse(app.getColumn().isRenderEnabled());
645:                assertFalse(app.getLabel().isRenderEnabled());
646:                app.getColumn().setEnabled(true);
647:                assertTrue(app.getContentPane().isRenderEnabled());
648:                assertTrue(app.getColumn().isRenderEnabled());
649:                assertFalse(app.getLabel().isRenderEnabled());
650:                app.getLabel().setEnabled(true);
651:                assertTrue(app.getContentPane().isRenderEnabled());
652:                assertTrue(app.getColumn().isRenderEnabled());
653:                assertTrue(app.getLabel().isRenderEnabled());
654:            }
655:
656:            /**
657:             * Test render-visible state.
658:             */
659:            public void testRenderVisible() {
660:                ColumnApp app = new ColumnApp();
661:                ApplicationInstance.setActive(app);
662:                app.doInit();
663:                assertTrue(app.getContentPane().isRenderVisible());
664:                assertTrue(app.getColumn().isRenderVisible());
665:                assertTrue(app.getLabel().isRenderVisible());
666:                app.getColumn().setVisible(false);
667:                assertTrue(app.getContentPane().isRenderVisible());
668:                assertFalse(app.getColumn().isRenderVisible());
669:                assertFalse(app.getLabel().isRenderVisible());
670:                app.getLabel().setVisible(false);
671:                assertTrue(app.getContentPane().isRenderVisible());
672:                assertFalse(app.getColumn().isRenderVisible());
673:                assertFalse(app.getLabel().isRenderVisible());
674:                app.getColumn().setVisible(true);
675:                assertTrue(app.getContentPane().isRenderVisible());
676:                assertTrue(app.getColumn().isRenderVisible());
677:                assertFalse(app.getLabel().isRenderVisible());
678:                app.getLabel().setVisible(true);
679:                assertTrue(app.getContentPane().isRenderVisible());
680:                assertTrue(app.getColumn().isRenderVisible());
681:                assertTrue(app.getLabel().isRenderVisible());
682:            }
683:
684:            /**
685:             * Test <code>visible</code> property.
686:             */
687:            public void testVisible() {
688:                NullComponent c = new NullComponent();
689:                PropertyChangeEvaluator pce = new PropertyChangeEvaluator();
690:                c.addPropertyChangeListener(pce);
691:                assertTrue(c.isVisible());
692:                c.setVisible(false);
693:                assertFalse(c.isVisible());
694:                assertEquals(Component.VISIBLE_CHANGED_PROPERTY, pce.lastEvent
695:                        .getPropertyName());
696:                c.setVisible(false);
697:                assertFalse(c.isVisible());
698:                c.setVisible(true);
699:                assertTrue(c.isVisible());
700:                c.setVisible(true);
701:                assertTrue(c.isVisible());
702:            }
703:
704:            /**
705:             * Test <code>visibleIndexOf()</code> method.
706:             */
707:            public void testVisibleIndexOf() {
708:                NullComponent parent = new NullComponent();
709:                NullComponent a = new NullComponent();
710:                NullComponent b = new NullComponent();
711:                NullComponent c = new NullComponent();
712:                NullComponent d = new NullComponent();
713:                parent.add(a);
714:                parent.add(b);
715:                parent.add(c);
716:                assertEquals(0, parent.visibleIndexOf(a));
717:                assertEquals(1, parent.visibleIndexOf(b));
718:                assertEquals(2, parent.visibleIndexOf(c));
719:                assertEquals(-1, parent.visibleIndexOf(d));
720:                b.setVisible(false);
721:                assertEquals(0, parent.visibleIndexOf(a));
722:                assertEquals(-1, parent.visibleIndexOf(b));
723:                assertEquals(1, parent.visibleIndexOf(c));
724:                assertEquals(-1, parent.visibleIndexOf(d));
725:                a.setVisible(false);
726:                assertEquals(-1, parent.visibleIndexOf(a));
727:                assertEquals(-1, parent.visibleIndexOf(b));
728:                assertEquals(0, parent.visibleIndexOf(c));
729:                assertEquals(-1, parent.visibleIndexOf(d));
730:                c.setVisible(false);
731:                assertEquals(-1, parent.visibleIndexOf(a));
732:                assertEquals(-1, parent.visibleIndexOf(b));
733:                assertEquals(-1, parent.visibleIndexOf(c));
734:                assertEquals(-1, parent.visibleIndexOf(d));
735:            }
736:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.