Source Code Cross Referenced for IndirectPropertyChangeSupportTest.java in  » Swing-Library » jgoodies-data-binding » com » jgoodies » binding » tests » 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 » Swing Library » jgoodies data binding » com.jgoodies.binding.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions are met:
006:         *
007:         *  o Redistributions of source code must retain the above copyright notice,
008:         *    this list of conditions and the following disclaimer.
009:         *
010:         *  o Redistributions in binary form must reproduce the above copyright notice,
011:         *    this list of conditions and the following disclaimer in the documentation
012:         *    and/or other materials provided with the distribution.
013:         *
014:         *  o Neither the name of JGoodies Karsten Lentzsch nor the names of
015:         *    its contributors may be used to endorse or promote products derived
016:         *    from this software without specific prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020:         * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021:         * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027:         * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028:         * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029:         */
030:
031:        package com.jgoodies.binding.tests;
032:
033:        import java.beans.PropertyChangeListener;
034:
035:        import junit.framework.TestCase;
036:
037:        import com.jgoodies.binding.PresentationModel;
038:        import com.jgoodies.binding.beans.BeanAdapter;
039:        import com.jgoodies.binding.beans.IndirectPropertyChangeSupport;
040:        import com.jgoodies.binding.tests.beans.EquityTestBean;
041:        import com.jgoodies.binding.tests.beans.TestBean;
042:        import com.jgoodies.binding.tests.event.PropertyChangeReport;
043:        import com.jgoodies.binding.value.Trigger;
044:
045:        /**
046:         * A test case for class {@link IndirectPropertyChangeSupport}
047:         * that checks whether listeners are added, removed and re-registered properly.
048:         * Also tests the classes BeanAdapter and PresentationModel that use
049:         * the IndirectPropertyChangeSupport directly or indirectly.
050:         *
051:         * @author Karsten Lentzsch
052:         * @version $Revision: 1.13 $
053:         */
054:        public final class IndirectPropertyChangeSupportTest extends TestCase {
055:
056:            // Re-Registering Listeners on Different Bean Types ***********************
057:
058:            public void testReregisterListenerOnDifferentBeans() {
059:                testReregisterListener(new EquityTestBean("key1"),
060:                        new EquityTestBean("key2"),
061:                        new IndirectPropertyChangeSupport());
062:
063:                TestBean bean1 = new EquityTestBean("key1");
064:                testReregisterListener(bean1, new EquityTestBean("key2"),
065:                        new IndirectPropertyChangeSupport(bean1));
066:            }
067:
068:            public void testReregisterListenerOnEqualBeans() {
069:                testReregisterListener(new EquityTestBean("key1"),
070:                        new EquityTestBean("key1"),
071:                        new IndirectPropertyChangeSupport());
072:
073:                TestBean bean1 = new EquityTestBean("key1");
074:                testReregisterListener(bean1, new EquityTestBean("key1"),
075:                        new IndirectPropertyChangeSupport(bean1));
076:            }
077:
078:            public void testBeanAdapterReregisterListenerOnEqualBeans() {
079:                TestBean bean1 = new EquityTestBean("key1");
080:                testReregisterListener(bean1, new EquityTestBean("key1"),
081:                        new BeanAdapter<TestBean>(bean1));
082:
083:                bean1 = new EquityTestBean("key1");
084:                testReregisterListener(bean1, new EquityTestBean("key1"),
085:                        new BeanAdapter<TestBean>(bean1, false));
086:            }
087:
088:            public void testPresentationModelReregisterListenerOnEqualBeans() {
089:                TestBean bean1 = new EquityTestBean("key1");
090:                testReregisterListener(bean1, new EquityTestBean("key1"),
091:                        new PresentationModel<TestBean>(bean1));
092:
093:                bean1 = new EquityTestBean("key1");
094:                testReregisterListener(bean1, new EquityTestBean("key1"),
095:                        new PresentationModel<TestBean>(bean1, new Trigger()));
096:            }
097:
098:            // Reusable Basic Test ****************************************************
099:
100:            private void testReregisterListener(TestBean bean1, TestBean bean2,
101:                    Object beanHolder) {
102:                String propertyName = "readWriteObjectProperty";
103:                setBean(beanHolder, bean1);
104:                PropertyChangeReport report1a = new PropertyChangeReport();
105:                PropertyChangeReport report1b = new PropertyChangeReport();
106:                PropertyChangeReport report2a = new PropertyChangeReport();
107:                PropertyChangeReport report2b = new PropertyChangeReport();
108:                addIndirectListener(beanHolder, report1a);
109:                addIndirectListener(beanHolder, report1b);
110:                addIndirectListener(beanHolder, propertyName, report2a);
111:                addIndirectListener(beanHolder, propertyName, report2b);
112:                bean1.setReadWriteObjectProperty("bean1value1");
113:                assertEquals("Changing the observed bean1 fires a change.", 1,
114:                        report1a.eventCount());
115:                assertEquals(
116:                        "All unnamed listeners receive the same number of events.",
117:                        report1a.eventCount(), report1b.eventCount());
118:                assertEquals(
119:                        "Changing the observed bean1 fires a named change.", 1,
120:                        report2a.eventCount());
121:                assertEquals(
122:                        "All named listeners receive the same number of events.",
123:                        report2a.eventCount(), report2b.eventCount());
124:
125:                bean2.setReadWriteObjectProperty("bean2value1");
126:                assertEquals("Changing the unobserved bean2 fires no change.",
127:                        1, report1a.eventCount());
128:                assertEquals(
129:                        "Changing the unobserved bean2 fires no named change.",
130:                        1, report1a.eventCount());
131:
132:                // Change the bean
133:                setBean(beanHolder, bean2);
134:                bean1.setReadWriteObjectProperty("bean1value2");
135:                assertEquals("Changing the unobserved bean1 fires no change.",
136:                        1, report1a.eventCount());
137:                assertEquals(
138:                        "Changing the unobserved bean1 fires no named change.",
139:                        1, report2a.eventCount());
140:
141:                bean2.setReadWriteObjectProperty("bean2value2");
142:                assertEquals("Changing the observed bean2 fires a change.", 2,
143:                        report1a.eventCount());
144:                assertEquals(
145:                        "2) All unnamed listeners receive the same number of events.",
146:                        report1a.eventCount(), report1b.eventCount());
147:                assertEquals("Changing the observed bean2 fires a change.", 2,
148:                        report2a.eventCount());
149:                assertEquals(
150:                        "2) All named listeners receive the same number of events.",
151:                        report2a.eventCount(), report2b.eventCount());
152:
153:                removeIndirectListener(beanHolder, report1a);
154:                removeIndirectListener(beanHolder, report1b);
155:                removeIndirectListener(beanHolder, propertyName, report2a);
156:                removeIndirectListener(beanHolder, propertyName, report2b);
157:
158:                // Change the bean back to bean1
159:                setBean(beanHolder, bean1);
160:                bean1.setReadWriteObjectProperty("bean1value3");
161:                assertEquals("Unregistered listeners receive no more events.",
162:                        2, report1a.eventCount());
163:                assertEquals(
164:                        "All unregistered listeners receive no more events.",
165:                        report1a.eventCount(), report1b.eventCount());
166:                assertEquals(
167:                        "Deregistered named listeners receive no more events.",
168:                        2, report2a.eventCount());
169:                assertEquals(
170:                        "All deregistered named listeners receive no more events.",
171:                        report2a.eventCount(), report2b.eventCount());
172:
173:            }
174:
175:            // Helper Code ***********************************************************
176:
177:            private void setBean(Object beanHolder, TestBean newBean) {
178:                if (beanHolder instanceof  IndirectPropertyChangeSupport)
179:                    ((IndirectPropertyChangeSupport) beanHolder)
180:                            .setBean(newBean);
181:                else if (beanHolder instanceof  BeanAdapter)
182:                    ((BeanAdapter<TestBean>) beanHolder).setBean(newBean);
183:                else if (beanHolder instanceof  PresentationModel)
184:                    ((PresentationModel<TestBean>) beanHolder).setBean(newBean);
185:                else
186:                    throw new IllegalArgumentException(
187:                            "Unknown bean holder type. "
188:                                    + "Must be one of: IndirectPropertyChangeSupport, BeanAdapter, PresentationModel");
189:            }
190:
191:            private void addIndirectListener(Object beanHolder,
192:                    PropertyChangeListener listener) {
193:                if (beanHolder instanceof  IndirectPropertyChangeSupport)
194:                    ((IndirectPropertyChangeSupport) beanHolder)
195:                            .addPropertyChangeListener(listener);
196:                else if (beanHolder instanceof  BeanAdapter)
197:                    ((BeanAdapter<?>) beanHolder)
198:                            .addBeanPropertyChangeListener(listener);
199:                else if (beanHolder instanceof  PresentationModel)
200:                    ((PresentationModel<?>) beanHolder)
201:                            .addBeanPropertyChangeListener(listener);
202:                else
203:                    throw new IllegalArgumentException(
204:                            "Unknown bean holder type. "
205:                                    + "Must be one of: IndirectPropertyChangeSupport, BeanAdapter, PresentationModel");
206:            }
207:
208:            private void addIndirectListener(Object beanHolder,
209:                    String propertyName, PropertyChangeListener listener) {
210:                if (beanHolder instanceof  IndirectPropertyChangeSupport)
211:                    ((IndirectPropertyChangeSupport) beanHolder)
212:                            .addPropertyChangeListener(propertyName, listener);
213:                else if (beanHolder instanceof  BeanAdapter)
214:                    ((BeanAdapter<?>) beanHolder)
215:                            .addBeanPropertyChangeListener(propertyName,
216:                                    listener);
217:                else if (beanHolder instanceof  PresentationModel)
218:                    ((PresentationModel<?>) beanHolder)
219:                            .addBeanPropertyChangeListener(propertyName,
220:                                    listener);
221:                else
222:                    throw new IllegalArgumentException(
223:                            "Unknown bean holder type. "
224:                                    + "Must be one of: IndirectPropertyChangeSupport, BeanAdapter, PresentationModel");
225:            }
226:
227:            private void removeIndirectListener(Object beanHolder,
228:                    PropertyChangeListener listener) {
229:                if (beanHolder instanceof  IndirectPropertyChangeSupport)
230:                    ((IndirectPropertyChangeSupport) beanHolder)
231:                            .removePropertyChangeListener(listener);
232:                else if (beanHolder instanceof  BeanAdapter)
233:                    ((BeanAdapter<?>) beanHolder)
234:                            .removeBeanPropertyChangeListener(listener);
235:                else if (beanHolder instanceof  PresentationModel)
236:                    ((PresentationModel<?>) beanHolder)
237:                            .removeBeanPropertyChangeListener(listener);
238:                else
239:                    throw new IllegalArgumentException(
240:                            "Unknown bean holder type. "
241:                                    + "Must be one of: IndirectPropertyChangeSupport, BeanAdapter, PresentationModel");
242:            }
243:
244:            private void removeIndirectListener(Object beanHolder,
245:                    String propertyName, PropertyChangeListener listener) {
246:                if (beanHolder instanceof  IndirectPropertyChangeSupport)
247:                    ((IndirectPropertyChangeSupport) beanHolder)
248:                            .removePropertyChangeListener(propertyName,
249:                                    listener);
250:                else if (beanHolder instanceof  BeanAdapter)
251:                    ((BeanAdapter<?>) beanHolder)
252:                            .removeBeanPropertyChangeListener(propertyName,
253:                                    listener);
254:                else if (beanHolder instanceof  PresentationModel)
255:                    ((PresentationModel<?>) beanHolder)
256:                            .removeBeanPropertyChangeListener(propertyName,
257:                                    listener);
258:                else
259:                    throw new IllegalArgumentException(
260:                            "Unknown bean holder type. "
261:                                    + "Must be one of: IndirectPropertyChangeSupport, BeanAdapter, PresentationModel");
262:            }
263:
264:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.