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


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 2007 IBM Corporation 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:         *     IBM Corporation - initial API and implementation
010:         *     Brad Reynolds - bug 159539
011:         *     Brad Reynolds - bug 140644
012:         *     Brad Reynolds - bug 159940
013:         *     Brad Reynolds - bug 116920, 159768
014:         *******************************************************************************/package org.eclipse.core.tests.databinding;
015:
016:        import java.util.ArrayList;
017:
018:        import org.eclipse.core.databinding.AggregateValidationStatus;
019:        import org.eclipse.core.databinding.Binding;
020:        import org.eclipse.core.databinding.DataBindingContext;
021:        import org.eclipse.core.databinding.UpdateListStrategy;
022:        import org.eclipse.core.databinding.UpdateValueStrategy;
023:        import org.eclipse.core.databinding.observable.list.IObservableList;
024:        import org.eclipse.core.databinding.observable.list.WritableList;
025:        import org.eclipse.core.databinding.observable.map.IObservableMap;
026:        import org.eclipse.core.databinding.observable.value.IObservableValue;
027:        import org.eclipse.core.databinding.observable.value.WritableValue;
028:        import org.eclipse.core.databinding.validation.IValidator;
029:        import org.eclipse.core.databinding.validation.ValidationStatus;
030:        import org.eclipse.core.runtime.IStatus;
031:        import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
032:        import org.eclipse.jface.tests.databinding.EventTrackers.ChangeEventTracker;
033:        import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
034:
035:        public class DatabindingContextTest extends
036:                AbstractDefaultRealmTestCase {
037:            private DataBindingContext dbc;
038:
039:            /*
040:             * (non-Javadoc)
041:             * 
042:             * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#setUp()
043:             */
044:            protected void setUp() throws Exception {
045:                super .setUp();
046:
047:                dbc = new DataBindingContext();
048:            }
049:
050:            /*
051:             * (non-Javadoc)
052:             * 
053:             * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#tearDown()
054:             */
055:            protected void tearDown() throws Exception {
056:                if (dbc != null) {
057:                    dbc.dispose();
058:                }
059:                super .tearDown();
060:            }
061:
062:            public void testDisposeBindings() throws Exception {
063:                Binding binding = new BindingStub();
064:                binding.init(dbc);
065:
066:                assertFalse(binding.isDisposed());
067:                dbc.dispose();
068:                assertTrue("binding should be diposed when dbc is disposed",
069:                        binding.isDisposed());
070:            }
071:
072:            public void testBindValue() throws Exception {
073:                IObservableValue target = WritableValue
074:                        .withValueType(String.class);
075:                IObservableValue model = WritableValue
076:                        .withValueType(String.class);
077:
078:                Binding binding = dbc.bindValue(target, model, null, null);
079:                assertTrue("binding is of the incorrect type", binding
080:                        .getClass().getName().endsWith("ValueBinding"));
081:            }
082:
083:            public void testBindList() throws Exception {
084:                IObservableList target = WritableList
085:                        .withElementType(Object.class);
086:                IObservableList model = WritableList
087:                        .withElementType(Object.class);
088:
089:                Binding binding = dbc.bindList(target, model, null, null);
090:                assertTrue("binding is of the incorrect type", binding
091:                        .getClass().getName().endsWith("ListBinding"));
092:            }
093:
094:            /**
095:             * Asserts that IStatus is populated and change events are fired when a
096:             * Binding that is associated with a context is in error.
097:             * 
098:             * @throws Exception
099:             */
100:            public void testValidationError() throws Exception {
101:                WritableValue targetObservable = WritableValue
102:                        .withValueType(String.class);
103:                WritableValue modelObservable = WritableValue
104:                        .withValueType(String.class);
105:
106:                final String errorMessage = "error";
107:                ValueChangeEventTracker errorCounter = new ValueChangeEventTracker();
108:                ChangeEventTracker errorsCounter = new ChangeEventTracker();
109:
110:                IObservableValue error = new AggregateValidationStatus(dbc
111:                        .getBindings(), AggregateValidationStatus.MAX_SEVERITY);
112:                error.addValueChangeListener(errorCounter);
113:                assertTrue(((IStatus) error.getValue()).isOK());
114:
115:                IObservableMap errors = dbc.getValidationStatusMap();
116:                errors.addChangeListener(errorsCounter);
117:                assertEquals(0, errors.size());
118:
119:                IValidator validator = new IValidator() {
120:                    public IStatus validate(Object value) {
121:                        return ValidationStatus.error(errorMessage);
122:                    }
123:                };
124:
125:                dbc.bindValue(targetObservable, modelObservable,
126:                        new UpdateValueStrategy()
127:                                .setAfterGetValidator(validator), null);
128:
129:                targetObservable.setValue("");
130:                assertFalse(((IStatus) error.getValue()).isOK());
131:                assertEquals(errorMessage, ((IStatus) error.getValue())
132:                        .getMessage());
133:                assertEquals(1, errors.size());
134:                assertEquals(1, errorsCounter.count);
135:                assertEquals(1, errorCounter.count);
136:                error.dispose();
137:            }
138:
139:            /**
140:             * Asserts that then
141:             * {@link DataBindingContext#bindValue(IObservableValue, IObservableValue, org.eclipse.jface.databinding.DefaultBindSpec, BindSpec)}
142:             * if invoked the created binding is added to the internal list of bindings.
143:             * 
144:             * @throws Exception
145:             */
146:            public void testBindValueAddBinding() throws Exception {
147:                WritableValue targetValue = WritableValue
148:                        .withValueType(String.class);
149:                WritableValue modelValue = WritableValue
150:                        .withValueType(String.class);
151:
152:                assertNotNull(dbc.getBindings());
153:                assertEquals(0, dbc.getBindings().size());
154:
155:                Binding binding = dbc.bindValue(targetValue, modelValue, null,
156:                        null);
157:                assertNotNull(binding);
158:                assertNotNull(dbc.getBindings());
159:                assertEquals(1, dbc.getBindings().size());
160:                assertEquals(binding, dbc.getBindings().get(0));
161:            }
162:
163:            /**
164:             * Asserts that when
165:             * {@link DataBindingContext#bindList(IObservableList, IObservableList, org.eclipse.jface.databinding.DefaultBindSpec, UpdateListStrategy)}
166:             * is invoked the created binding is added to the intenal list of bindings.
167:             * 
168:             * @throws Exception
169:             */
170:            public void testBindListAddBinding() throws Exception {
171:                WritableList targetList = new WritableList(new ArrayList(),
172:                        Object.class);
173:                WritableList modelList = new WritableList(new ArrayList(),
174:                        Object.class);
175:
176:                assertNotNull(dbc.getBindings());
177:                assertEquals(0, dbc.getBindings().size());
178:
179:                Binding binding = dbc.bindList(targetList, modelList, null,
180:                        null);
181:                assertNotNull(binding);
182:                assertNotNull(dbc.getBindings());
183:                assertEquals(1, dbc.getBindings().size());
184:                assertEquals(binding, dbc.getBindings().get(0));
185:            }
186:
187:            public void testGetBindingsImmutability() throws Exception {
188:                BindingStub binding = new BindingStub();
189:                binding.init(dbc);
190:
191:                try {
192:                    dbc.getBindings().remove(0);
193:                    fail("exception should have been thrown");
194:                } catch (UnsupportedOperationException e) {
195:                }
196:            }
197:
198:            public void testRemoveBinding() throws Exception {
199:                BindingStub binding = new BindingStub();
200:                binding.init(dbc);
201:
202:                assertTrue("context should contain the binding", dbc
203:                        .getBindings().contains(binding));
204:                binding.dispose();
205:                assertFalse("binding should have been removed", dbc
206:                        .getBindings().contains(binding));
207:            }
208:
209:            /**
210:             * Asserts that when a ValueBinding is created validation is ran to ensure
211:             * that the validation status of the Binding reflects the validity of the
212:             * value in the target.
213:             * 
214:             * @throws Exception
215:             */
216:            public void testValidateTargetAfterValueBindingCreation()
217:                    throws Exception {
218:                WritableValue target = new WritableValue("", String.class);
219:                WritableValue model = new WritableValue("2", String.class);
220:                class Validator implements  IValidator {
221:                    public IStatus validate(Object value) {
222:                        return ValidationStatus.error("error");
223:                    }
224:                }
225:
226:                Binding binding = dbc.bindValue(target, model,
227:                        new UpdateValueStrategy()
228:                                .setAfterConvertValidator(new Validator()),
229:                        null);
230:
231:                assertEquals(IStatus.ERROR, ((IStatus) binding
232:                        .getValidationStatus().getValue()).getSeverity());
233:            }
234:
235:            protected void assertNoErrorsFound() {
236:                IStatus status = AggregateValidationStatus
237:                        .getStatusMaxSeverity(dbc.getBindings());
238:                assertTrue("No errors should be found, but found " + status,
239:                        status.isOK());
240:            }
241:
242:            protected void assertErrorsFound() {
243:                IStatus status = AggregateValidationStatus
244:                        .getStatusMaxSeverity(dbc.getBindings());
245:                assertFalse("Errors should be found, but found none.", status
246:                        .isOK());
247:            }
248:
249:            private static class BindingStub extends Binding {
250:                DataBindingContext context;
251:
252:                public BindingStub() {
253:                    super (new WritableValue(), new WritableValue());
254:                }
255:
256:                public IObservableValue getPartialValidationStatus() {
257:                    return null;
258:                }
259:
260:                public IObservableValue getValidationStatus() {
261:                    return null;
262:                }
263:
264:                public void updateTargetToModel() {
265:                }
266:
267:                public void updateModelToTarget() {
268:                }
269:
270:                public void updateTargetFromModel(int phase) {
271:                }
272:
273:                public void updateModelFromTarget(int phase) {
274:                }
275:
276:                protected void postInit() {
277:                }
278:
279:                protected void preInit() {
280:                }
281:
282:                public void validateModelToTarget() {
283:                }
284:
285:                public void validateTargetToModel() {
286:                }
287:            }
288:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.