1 /*
2 * Scope: a generic MVC framework.
3 * Copyright (c) 2000-2002, Steve Meyfroidt
4 * All rights reserved.
5 * Email: smeyfroi@users.sourceforge.net
6 *
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name "Scope" nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 *
37 * $Id: TestSRadioButton.java,v 1.7 2002/08/05 13:19:26 ludovicc Exp $
38 */
39
40
41 package test.view.swing;
42
43
44 import junit.framework.TestCase;
45 import org.apache.commons.logging.LogFactory;import org.apache.commons.logging.Log;
46 import org.scopemvc.core.Selector;
47 import org.scopemvc.view.swing.SRadioButton;
48 import org.scopemvc.view.swing.SPanel;
49
50
51 /***
52 * <P>
53 * </P>
54 *
55 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net>Steve Meyfroidt</A>
56 * @version $Revision: 1.7 $ $Date: 2002/08/05 13:19:26 $
57 */
58 public final class TestSRadioButton extends TestCase {
59
60
61 private static final Log LOG = LogFactory.getLog(TestSCheckBox.class);
62
63
64 private SRadioButton radiobutton;
65 private SwingDummyController controller;
66 private SPanel view;
67 private SwingDummyModel model;
68
69
70 public TestSRadioButton(String inName) {
71 super(inName);
72 }
73
74
75 protected void setUp() throws Exception {
76
77 radiobutton = new SRadioButton();
78
79 view = new SPanel();
80 view.add(radiobutton);
81
82 controller = new SwingDummyController();
83 controller.setView(view);
84 controller.startup(); // does showView()
85
86 model = new SwingDummyModel();
87 }
88
89
90 protected void tearDown() {
91 controller.shutdown();
92 }
93
94
95 public void testUnbound() throws Exception {
96 SuiteViewSwing.waitForAWT();
97 assertTrue(! radiobutton.isEnabled());
98 assertTrue(! radiobutton.isSelected());
99
100 radiobutton.setSelector(Selector.fromString("booleanProperty"));
101 SuiteViewSwing.waitForAWT();
102 assertEquals(Selector.fromString("booleanProperty"), radiobutton.getSelector());
103 assertTrue(! radiobutton.isEnabled());
104 assertTrue(! radiobutton.isSelected());
105 }
106
107
108 public void testConvenience() throws Exception {
109 SuiteViewSwing.waitForAWT();
110 assertTrue(! radiobutton.isEnabled());
111 assertTrue(! radiobutton.isSelected());
112
113 radiobutton.setSelectorString("booleanProperty");
114 SuiteViewSwing.waitForAWT();
115 assertEquals(Selector.fromString("booleanProperty"), radiobutton.getSelector());
116 assertTrue(! radiobutton.isEnabled());
117 assertTrue(! radiobutton.isSelected());
118 }
119
120
121 public void testBind1() throws Exception {
122 radiobutton.setSelector(Selector.fromString("booleanProperty"));
123 assertEquals(Selector.fromString("booleanProperty"), radiobutton.getSelector());
124
125 controller.setModel(model);
126 SuiteViewSwing.waitForAWT();
127 assertSame(view.getBoundModel(), model);
128 assertSame(radiobutton.getBoundModel(), model);
129 assertTrue(radiobutton.isEnabled());
130 assertTrue(! radiobutton.isSelected());
131
132 model.setBooleanProperty(true);
133 SuiteViewSwing.waitForAWT();
134 assertTrue(radiobutton.isEnabled());
135 assertTrue(radiobutton.isSelected());
136
137 model.setBooleanProperty(false);
138 SuiteViewSwing.waitForAWT();
139 assertTrue(radiobutton.isEnabled());
140 assertTrue(! radiobutton.isSelected());
141
142 radiobutton.doClick();
143 SuiteViewSwing.waitForAWT();
144 assertTrue(radiobutton.isEnabled());
145 assertTrue(radiobutton.isSelected());
146 assertTrue(model.getBooleanProperty());
147 }
148
149
150 public void testBind2() throws Exception {
151 radiobutton.setSelector(Selector.fromString("booleanProperty1"));
152 assertEquals(Selector.fromString("booleanProperty1"), radiobutton.getSelector());
153
154 controller.setModel(model);
155 SuiteViewSwing.waitForAWT();
156 assertSame(view.getBoundModel(), model);
157 assertSame(radiobutton.getBoundModel(), model);
158 assertTrue(radiobutton.isEnabled());
159 assertTrue(! radiobutton.isSelected());
160
161 model.setBooleanProperty1(Boolean.TRUE);
162 SuiteViewSwing.waitForAWT();
163 assertTrue(radiobutton.isEnabled());
164 assertTrue(radiobutton.isSelected());
165
166 model.setBooleanProperty1(Boolean.FALSE);
167 SuiteViewSwing.waitForAWT();
168 assertTrue(radiobutton.isEnabled());
169 assertTrue(! radiobutton.isSelected());
170
171 radiobutton.doClick();
172 SuiteViewSwing.waitForAWT();
173 assertTrue(radiobutton.isEnabled());
174 assertTrue(radiobutton.isSelected());
175 assertEquals(Boolean.TRUE, model.getBooleanProperty1());
176
177 model.setBooleanProperty1(null);
178 SuiteViewSwing.waitForAWT();
179 assertTrue(radiobutton.isSelected());
180 assertTrue(! radiobutton.isEnabled());
181 }
182
183
184 public void testValidation() throws Exception {
185 radiobutton.setSelector(Selector.fromString("invalidBooleanProperty"));
186 controller.setModel(model);
187 SuiteViewSwing.waitForAWT();
188 assertTrue(radiobutton.isEnabled());
189 assertTrue(! radiobutton.isSelected());
190
191 radiobutton.doClick();
192 SuiteViewSwing.waitForAWT();
193 assertTrue(radiobutton.isEnabled());
194 assertTrue(radiobutton.isSelected());
195 assertTrue(! model.getInvalidBooleanProperty());
196 }
197
198
199 public void testBadBind() throws Exception {
200 radiobutton.setSelector(Selector.fromString("stringProperty"));
201 controller.setModel(model);
202 SuiteViewSwing.waitForAWT();
203
204 assertTrue(! radiobutton.isEnabled());
205 assertTrue(! radiobutton.isSelected());
206
207 radiobutton.doClick();
208 }
209
210
211 public void testReadOnlyBind() throws Exception {
212 radiobutton.setSelector(Selector.fromString("booleanReadOnlyProperty"));
213 controller.setModel(model);
214 SuiteViewSwing.waitForAWT();
215
216 assertTrue(! radiobutton.isEnabled());
217 assertTrue(radiobutton.isSelected());
218 }
219
220
221 public void testControlIssue1() throws Exception {
222 radiobutton.setSelector(Selector.fromString("booleanProperty"));
223 controller.setModel(model);
224 radiobutton.setControlID("test1");
225 SuiteViewSwing.waitForAWT();
226
227 assertNull(controller.lastControl);
228
229 radiobutton.doClick();
230 SuiteViewSwing.waitForAWT();
231 assertTrue(controller.controlMatches("test1"));
232
233 radiobutton.setControlID("test1a");
234 radiobutton.doClick();
235 SuiteViewSwing.waitForAWT();
236 assertTrue(controller.controlMatches("test1a"));
237 }
238
239
240 public void testControlIssue2() throws Exception {
241 radiobutton.setSelector(Selector.fromString("booleanProperty"));
242 controller.setModel(model);
243 radiobutton.setControlID("test2");
244 SuiteViewSwing.waitForAWT();
245
246 assertNull(controller.lastControl);
247
248 model.setBooleanProperty(true);
249 SuiteViewSwing.waitForAWT();
250 assertTrue(controller.controlMatches("test2"));
251
252 radiobutton.setControlID("test2a");
253 model.setBooleanProperty(false);
254 SuiteViewSwing.waitForAWT();
255 assertTrue(controller.controlMatches("test2a"));
256 }
257
258
259 public void testBindNoMCE() throws Exception {
260 radiobutton.setSelector(Selector.fromString("booleanProperty"));
261 assertEquals(Selector.fromString("booleanProperty"), radiobutton.getSelector());
262
263 SwingDummyModelNoMCE model = new SwingDummyModelNoMCE();
264
265 controller.setModel(model);
266 SuiteViewSwing.waitForAWT();
267 assertSame(view.getBoundModel(), model);
268
269 assertSame(radiobutton.getBoundModel(), model);
270 assertTrue(radiobutton.isEnabled());
271 assertTrue(! radiobutton.isSelected());
272
273 model.setBooleanProperty(true);
274 assertTrue(radiobutton.isEnabled());
275 assertTrue(! radiobutton.isSelected());
276
277 view.refresh();
278 assertTrue(radiobutton.isEnabled());
279 assertTrue(radiobutton.isSelected());
280
281 model.setBooleanProperty(false);
282 assertTrue(radiobutton.isEnabled());
283 assertTrue(radiobutton.isSelected());
284
285 view.refresh();
286 assertTrue(radiobutton.isEnabled());
287 assertTrue(! radiobutton.isSelected());
288
289 radiobutton.doClick();
290 SuiteViewSwing.waitForAWT();
291 assertTrue(radiobutton.isEnabled());
292 assertTrue(radiobutton.isSelected());
293 assertTrue(model.getBooleanProperty());
294 }
295 }
This page was automatically generated by Maven