Source Code Cross Referenced for JavaBeanObservableValueTest.java in  » IDE-Eclipse » jface » org » eclipse » core » tests » internal » databinding » internal » beans » 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 » IDE Eclipse » jface » org.eclipse.core.tests.internal.databinding.internal.beans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2006 Brad Reynolds and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     Brad Reynolds - initial API and implementation
010:         *     Brad Reynolds - bug 171616
011:         *     Katarzyna Marszalek - test case for bug 198519
012:         ******************************************************************************/package org.eclipse.core.tests.internal.databinding.internal.beans;
013:
014:        import java.beans.IntrospectionException;
015:        import java.beans.PropertyDescriptor;
016:
017:        import junit.framework.Test;
018:
019:        import org.eclipse.core.databinding.beans.BeansObservables;
020:        import org.eclipse.core.databinding.observable.ChangeEvent;
021:        import org.eclipse.core.databinding.observable.IChangeListener;
022:        import org.eclipse.core.databinding.observable.IObservable;
023:        import org.eclipse.core.databinding.observable.Realm;
024:        import org.eclipse.core.databinding.observable.value.ComputedValue;
025:        import org.eclipse.core.databinding.observable.value.IObservableValue;
026:        import org.eclipse.core.internal.databinding.internal.beans.JavaBeanObservableValue;
027:        import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
028:        import org.eclipse.jface.conformance.databinding.ObservableValueContractTest;
029:        import org.eclipse.jface.conformance.databinding.SuiteBuilder;
030:        import org.eclipse.jface.examples.databinding.model.SimplePerson;
031:        import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
032:
033:        /**
034:         * @since 3.2
035:         */
036:        public class JavaBeanObservableValueTest extends
037:                AbstractDefaultRealmTestCase {
038:            private Bean bean;
039:            private JavaBeanObservableValue observableValue;
040:            private PropertyDescriptor propertyDescriptor;
041:            private String propertyName;
042:
043:            /* (non-Javadoc)
044:             * @see junit.framework.TestCase#setUp()
045:             */
046:            protected void setUp() throws Exception {
047:                super .setUp();
048:
049:                bean = new Bean();
050:                propertyName = "value";
051:                propertyDescriptor = new PropertyDescriptor(propertyName,
052:                        Bean.class);
053:                observableValue = new JavaBeanObservableValue(Realm
054:                        .getDefault(), bean, propertyDescriptor);
055:            }
056:
057:            public void testSetsValueInBean() throws Exception {
058:                String value = "value";
059:                assertNull(observableValue.getValue());
060:                observableValue.setValue(value);
061:                assertEquals("value", value, observableValue.getValue());
062:            }
063:
064:            public void testGetObserved() throws Exception {
065:                assertEquals(bean, observableValue.getObserved());
066:            }
067:
068:            public void testGetPropertyDescriptor() throws Exception {
069:                assertEquals(propertyDescriptor, observableValue
070:                        .getPropertyDescriptor());
071:            }
072:
073:            public void testSetValueThrowsExceptionThrownByBean()
074:                    throws Exception {
075:                ThrowsSetException temp = new ThrowsSetException();
076:                JavaBeanObservableValue observable = new JavaBeanObservableValue(
077:                        Realm.getDefault(), temp, new PropertyDescriptor(
078:                                "value", ThrowsSetException.class));
079:
080:                try {
081:                    observable.setValue("");
082:                    fail("exception should have been thrown");
083:                } catch (RuntimeException e) {
084:                    assertEquals(temp.thrownException, e.getCause());
085:                }
086:            }
087:
088:            public void testGetValueThrowsExceptionThrownByBean()
089:                    throws Exception {
090:                ThrowsGetException temp = new ThrowsGetException();
091:                JavaBeanObservableValue observable = new JavaBeanObservableValue(
092:                        Realm.getDefault(), temp, new PropertyDescriptor(
093:                                "value", ThrowsGetException.class));
094:
095:                try {
096:                    observable.getValue();
097:                    fail("exception should have been thrown");
098:                } catch (RuntimeException e) {
099:                    assertEquals(temp.thrownException, e.getCause());
100:                }
101:            }
102:
103:            public void testBug198519() {
104:                final SimplePerson person = new SimplePerson();
105:                final ComputedValue cv = new ComputedValue() {
106:                    final IObservableValue name = BeansObservables
107:                            .observeValue(person, "name"); //$NON-NLS-1$
108:
109:                    protected Object calculate() {
110:                        return Boolean.valueOf(name.getValue() != null);
111:                    }
112:                };
113:                cv.addChangeListener(new IChangeListener() {
114:                    public void handleChange(ChangeEvent event) {
115:                        cv.getValue();
116:                    }
117:                });
118:                person.setName("foo");
119:            }
120:
121:            public static Test suite() {
122:                Object[] params = new Object[] { new Delegate() };
123:
124:                return new SuiteBuilder().addTests(
125:                        JavaBeanObservableValueTest.class)
126:                        .addParameterizedTests(
127:                                ObservableValueContractTest.class, params)
128:                        .build();
129:            }
130:
131:            /* package */static class Delegate extends
132:                    AbstractObservableValueContractDelegate {
133:                private Bean bean;
134:
135:                public void setUp() {
136:                    super .setUp();
137:
138:                    bean = new Bean("");
139:                }
140:
141:                public IObservableValue createObservableValue(Realm realm) {
142:                    try {
143:                        PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
144:                                "value", Bean.class);
145:                        return new JavaBeanObservableValue(realm, bean,
146:                                propertyDescriptor);
147:                    } catch (IntrospectionException e) {
148:                        throw new RuntimeException(e);
149:                    }
150:                }
151:
152:                public void change(IObservable observable) {
153:                    IObservableValue observableValue = (IObservableValue) observable;
154:                    observableValue.setValue(createValue(observableValue));
155:                }
156:
157:                public Object getValueType(IObservableValue observable) {
158:                    return String.class;
159:                }
160:
161:                public Object createValue(IObservableValue observable) {
162:                    return observable.getValue() + "a";
163:                }
164:            }
165:
166:            /**
167:             * Throws an exception when the value is set.
168:             * 
169:             * @since 3.2
170:             */
171:            /* package */class ThrowsSetException {
172:                private String value;
173:
174:                /* package */NullPointerException thrownException;
175:
176:                public void setValue(String value) {
177:                    throw thrownException = new NullPointerException();
178:                }
179:
180:                public String getValue() {
181:                    return value;
182:                }
183:            }
184:
185:            /* package */class ThrowsGetException {
186:                public String value;
187:
188:                /* package */NullPointerException thrownException;
189:
190:                public String getValue() {
191:                    throw thrownException = new NullPointerException();
192:                }
193:
194:                public void setValue(String value) {
195:                    this.value = value;
196:                }
197:            }
198:        }
www_._j___ava_2s_._c_o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.