1 /*
2 Copyright (c) 2003, Laurent Caillette.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modifica-
6 tion, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10
11 2. Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following disclaimer in the documentation
13 and/or other materials provided with the distribution.
14
15 3. The end-user documentation included with the redistribution, if any, must
16 include the following acknowledgment: "This product includes software
17 written by Laurent Caillette."
18 Alternately, this acknowledgment may appear in the software itself, if
19 and wherever such third-party acknowledgments normally appear.
20
21 4. The name "Laurent Caillette" must not be used to endorse or
22 promote products derived from this software without
23 prior written permission. For written permission, please contact
24 laurent.caillette@laposte.net
25
26 5. Products derived from this software may not be called
27 "Laurent Caillette", nor may "Laurent Caillette" appear
28 in their name, without prior written permission of the
29 author.
30
31 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
32 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
33 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34 AUTHOR (LAURENT CAILLETTE) BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
36 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
37 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 */
42 package tweed.binding;
43 import javax.swing.JTextField;
44 import java.awt.Component;
45 import junit.framework.Test;
46 import junit.framework.TestCase;
47 import junit.framework.TestSuite;
48 import junit.textui.TestRunner;
49 import org.apache.avalon.framework.logger.Logger;
50 import tweed.action.ActionPerformer;
51 import tweed.context.Context;
52 import tweed.invocation.CommandInvoker;
53 import tweed.system.bus.EventBus;
54 import tweed.testutil.LogUtil;
55 /***
56 *
57 * @author Laurent Caillette
58 * @version $Id$
59 */
60 public class InputValidationHubTest extends TestCase {
61
62 public void testState() {
63
64 final Component component1 = new JTextField() ;
65 final Component component2 = new JTextField() ;
66
67 boolean caught ;
68
69 Binding binding = new Binding( context ) {
70
71 protected void doUpdateView() { }
72
73 protected void doUpdateModel() {
74 createMessage( "validation failed" ).
75 addComponent( component1 ).
76 addComponent( component2 )
77 ;
78 }
79
80 } ;
81
82 caught = false ;
83 try {
84 binding.updateModel() ;
85 } catch( IllegalStateException ex ) {
86 caught = true ;
87 }
88 assertTrue( "Didn't detect that bindings were ended", caught ) ;
89
90 hub.beginBindings() ;
91
92 binding.updateModel() ;
93 hub.endBindings() ;
94
95 caught = false ;
96 try {
97 binding.updateModel() ;
98 } catch( IllegalStateException ex ) {
99 caught = true ;
100 }
101 assertTrue( "Didn't detect that bindings were ended", caught ) ;
102 }
103
104
105 private Context context ;
106 private InputValidationHub hub ;
107
108 protected void setUp() {
109
110 final Logger logger = LogUtil.createTestLogger() ;
111 final InputValidationHub[] hubRef = new InputValidationHub[ 1 ] ;
112
113 context = new Context() {
114
115 public CommandInvoker getInvoker() {
116 return null ;
117 }
118
119 public Context getContext() {
120 return this ;
121 }
122
123 public boolean isClientSide() {
124 return true ;
125 }
126
127 public boolean isServerSide() {
128 return false ;
129 }
130
131 public Logger getLogger() {
132 return logger ;
133 }
134
135 public ActionPerformer getActionPerformer() {
136 return null ;
137 }
138
139 public InputValidationHub getInputValidationHub() {
140 return hubRef[ 0 ] ;
141 }
142
143 EventBus bus = null ;
144
145 public EventBus getBus() {
146 if( bus == null ) {
147 bus = new EventBus( this ) ;
148 }
149 return bus ;
150 }
151
152 } ;
153
154 hubRef[ 0 ] = new InputValidationHub( context ) ;
155 hub = hubRef[ 0 ] ;
156
157 }
158
159 // =====
160 // JUnit
161 // =====
162
163 public InputValidationHubTest( final String name ) {
164 super( name );
165 }
166
167 public static Test suite() {
168 TestSuite suite = new TestSuite() ;
169 suite.addTestSuite( InputValidationHubTest.class ) ;
170 return suite;
171 }
172
173 public static void main( String[] args ) {
174 TestRunner.run( InputValidationHubTest.suite() );
175 }
176
177 }
This page was automatically generated by Maven