View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: TestSTextArea.java,v 1.8 2002/09/13 17:21:31 ludovicc Exp $ 37 */ 38 package test.view.swing; 39 40 41 import java.awt.event.FocusEvent; 42 import org.apache.commons.logging.Log; 43 import org.apache.commons.logging.LogFactory; 44 import junit.framework.TestCase; 45 import org.scopemvc.core.Selector; 46 import org.scopemvc.view.swing.SPanel; 47 import org.scopemvc.view.swing.STextArea; 48 49 /*** 50 * <P> 51 * 52 * </P> 53 * 54 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net>;Steve Meyfroidt</A> 55 * @created 13 September 2002 56 * @version $Revision: 1.8 $ $Date: 2002/09/13 17:21:31 $ 57 */ 58 public final class TestSTextArea extends TestCase { 59 60 private static final Log LOG = LogFactory.getLog(TestSTextArea.class); 61 62 private STextArea textarea; 63 private SwingDummyController controller; 64 private SPanel view; 65 private SwingDummyModel model; 66 67 68 /*** 69 * Constructor for the TestSTextArea object 70 * 71 * @param inName Name of the test 72 */ 73 public TestSTextArea(String inName) { 74 super(inName); 75 } 76 77 78 /*** 79 * A unit test for JUnit 80 * 81 * @throws Exception Any abnormal exception 82 */ 83 public void testUnbound() throws Exception { 84 SuiteViewSwing.waitForAWT(); 85 assertTrue(!textarea.isEnabled()); 86 // assertTrue(textarea.getText().length() < 1); 87 88 textarea.setSelector(Selector.fromString("stringProperty")); 89 SuiteViewSwing.waitForAWT(); 90 assertEquals(Selector.fromString("stringProperty"), textarea.getSelector()); 91 assertTrue(!textarea.isEnabled()); 92 // assertTrue(textarea.getText().length() < 1); 93 } 94 95 96 /*** 97 * A unit test for JUnit 98 * 99 * @throws Exception Any abnormal exception 100 */ 101 public void testBind1() throws Exception { 102 textarea.setSelector(Selector.fromString("stringProperty")); 103 assertEquals(Selector.fromString("stringProperty"), textarea.getSelector()); 104 105 controller.setModel(model); 106 SuiteViewSwing.waitForAWT(); 107 assertSame(view.getBoundModel(), model); 108 109 assertSame(textarea.getBoundModel(), model); 110 assertTrue(textarea.isEnabled()); 111 assertEquals(model.getStringProperty(), textarea.getText()); 112 113 model.setStringProperty("abc"); 114 SuiteViewSwing.waitForAWT(); 115 assertTrue(textarea.isEnabled()); 116 assertEquals(model.getStringProperty(), textarea.getText()); 117 118 model.setStringProperty("xyz"); 119 SuiteViewSwing.waitForAWT(); 120 assertTrue(textarea.isEnabled()); 121 assertEquals(model.getStringProperty(), textarea.getText()); 122 123 textarea.setText("gui"); 124 textarea.focusLost(new FocusEvent(textarea, FocusEvent.FOCUS_LOST)); 125 SuiteViewSwing.waitForAWT(); 126 assertTrue(textarea.isEnabled()); 127 assertEquals("gui", textarea.getText()); 128 assertEquals(model.getStringProperty(), textarea.getText()); 129 130 textarea.setText(""); 131 textarea.focusLost(new FocusEvent(textarea, FocusEvent.FOCUS_LOST)); 132 SuiteViewSwing.waitForAWT(); 133 assertTrue(!textarea.isEnabled()); 134 assertNull(model.getStringProperty()); 135 136 model.setStringProperty("abc"); 137 SuiteViewSwing.waitForAWT(); 138 139 model.setStringProperty(null); 140 SuiteViewSwing.waitForAWT(); 141 assertTrue(!textarea.isEnabled()); 142 assertNull(model.getStringProperty()); 143 } 144 145 146 /*** 147 * A unit test for JUnit 148 * 149 * @throws Exception Any abnormal exception 150 */ 151 public void testConvenience() throws Exception { 152 textarea.setSelectorString("stringProperty"); 153 assertEquals(Selector.fromString("stringProperty"), textarea.getSelector()); 154 } 155 156 /*** 157 * A unit test for JUnit 158 * 159 * @throws Exception Any abnormal exception 160 */ 161 public void testBindNull() throws Exception { 162 textarea.setDisableOnNull(false); 163 textarea.setSelector(Selector.fromString("stringProperty")); 164 assertEquals(Selector.fromString("stringProperty"), textarea.getSelector()); 165 166 controller.setModel(model); 167 SuiteViewSwing.waitForAWT(); 168 assertSame(view.getBoundModel(), model); 169 assertSame(textarea.getBoundModel(), model); 170 assertTrue(textarea.isEnabled()); 171 assertEquals(model.getStringProperty(), textarea.getText()); 172 173 model.setStringProperty("abc"); 174 SuiteViewSwing.waitForAWT(); 175 assertTrue(textarea.isEnabled()); 176 assertEquals(model.getStringProperty(), textarea.getText()); 177 178 model.setStringProperty("xyz"); 179 SuiteViewSwing.waitForAWT(); 180 assertTrue(textarea.isEnabled()); 181 assertEquals(model.getStringProperty(), textarea.getText()); 182 183 textarea.setText("gui"); 184 textarea.focusLost(new FocusEvent(textarea, FocusEvent.FOCUS_LOST)); 185 SuiteViewSwing.waitForAWT(); 186 assertTrue(textarea.isEnabled()); 187 assertEquals("gui", textarea.getText()); 188 assertEquals(model.getStringProperty(), textarea.getText()); 189 190 textarea.setText(""); 191 textarea.focusLost(new FocusEvent(textarea, FocusEvent.FOCUS_LOST)); 192 SuiteViewSwing.waitForAWT(); 193 assertTrue(textarea.isEnabled()); 194 assertTrue(model.getStringProperty() == null); 195 196 model.setStringProperty(null); 197 SuiteViewSwing.waitForAWT(); 198 assertTrue(textarea.isEnabled()); 199 assertNull(model.getStringProperty()); 200 assertTrue(textarea.getText().length() < 1); 201 } 202 203 204 /*** 205 * A unit test for JUnit 206 * 207 * @throws Exception Any abnormal exception 208 */ 209 public void testBadBind() throws Exception { 210 textarea.setSelector(Selector.fromString("subModel")); 211 controller.setModel(model); 212 SuiteViewSwing.waitForAWT(); 213 214 assertTrue(!textarea.isEnabled()); 215 // assertTrue(! textarea.isSelected()); 216 217 textarea.focusLost(new FocusEvent(textarea, FocusEvent.FOCUS_LOST)); 218 } 219 220 221 /*** 222 * A unit test for JUnit 223 * 224 * @throws Exception Any abnormal exception 225 */ 226 public void testBadBind2() throws Exception { 227 textarea.setDisableOnNull(false); 228 textarea.setSelector(Selector.fromString("subModel")); 229 controller.setModel(model); 230 SuiteViewSwing.waitForAWT(); 231 232 assertTrue(!textarea.isEnabled()); 233 // assertTrue(! textarea.isSelected()); 234 235 textarea.focusLost(new FocusEvent(textarea, FocusEvent.FOCUS_LOST)); 236 } 237 238 239 /*** 240 * A unit test for JUnit 241 * 242 * @throws Exception Any abnormal exception 243 */ 244 public void testReadOnlyBind() throws Exception { 245 textarea.setSelector(Selector.fromString("readOnlyStringProperty")); 246 controller.setModel(model); 247 SuiteViewSwing.waitForAWT(); 248 249 assertTrue(!textarea.isEnabled()); 250 assertEquals(model.getReadOnlyStringProperty(), textarea.getText()); 251 } 252 253 254 /*** 255 * A unit test for JUnit 256 * 257 * @throws Exception Any abnormal exception 258 */ 259 public void testBooleanBind() throws Exception { 260 textarea.setSelector(Selector.fromString("booleanProperty1")); 261 assertEquals(Selector.fromString("booleanProperty1"), textarea.getSelector()); 262 263 controller.setModel(model); 264 SuiteViewSwing.waitForAWT(); 265 assertSame(view.getBoundModel(), model); 266 assertSame(textarea.getBoundModel(), model); 267 268 model.setBooleanProperty1(Boolean.TRUE); 269 SuiteViewSwing.waitForAWT(); 270 assertTrue(textarea.isEnabled()); 271 assertEquals("" + model.getBooleanProperty1(), textarea.getText()); 272 273 model.setBooleanProperty1(Boolean.FALSE); 274 SuiteViewSwing.waitForAWT(); 275 assertTrue(textarea.isEnabled()); 276 assertEquals("" + model.getBooleanProperty1(), textarea.getText()); 277 278 model.setBooleanProperty1(Boolean.FALSE); 279 SuiteViewSwing.waitForAWT(); 280 textarea.setText("true"); 281 textarea.focusLost(new FocusEvent(textarea, FocusEvent.FOCUS_LOST)); 282 SuiteViewSwing.waitForAWT(); 283 assertTrue(textarea.isEnabled()); 284 assertEquals("true", textarea.getText()); 285 assertEquals("" + model.getBooleanProperty1(), textarea.getText()); 286 287 model.setBooleanProperty1(null); 288 SuiteViewSwing.waitForAWT(); 289 assertTrue(!textarea.isEnabled()); 290 assertNull(model.getBooleanProperty1()); 291 } 292 293 294 /*** 295 * A unit test for JUnit 296 * 297 * @throws Exception Any abnormal exception 298 */ 299 public void testInvalidBooleanBind() throws Exception { 300 textarea.setSelector(Selector.fromString("booleanProperty1")); 301 assertEquals(Selector.fromString("booleanProperty1"), textarea.getSelector()); 302 303 controller.setModel(model); 304 SuiteViewSwing.waitForAWT(); 305 assertSame(view.getBoundModel(), model); 306 assertSame(textarea.getBoundModel(), model); 307 308 model.setBooleanProperty1(Boolean.FALSE); 309 SuiteViewSwing.waitForAWT(); 310 311 textarea.setText("rubbish"); 312 textarea.focusLost(new FocusEvent(textarea, FocusEvent.FOCUS_LOST)); 313 SuiteViewSwing.waitForAWT(); 314 assertTrue(textarea.isEnabled()); 315 assertEquals("rubbish", textarea.getText()); 316 assertEquals(Boolean.FALSE, model.getBooleanProperty1()); 317 } 318 319 320 /*** 321 * A unit test for JUnit 322 * 323 * @throws Exception Any abnormal exception 324 */ 325 public void testInvalidBooleanBind2() throws Exception { 326 textarea.setSelector(Selector.fromString("booleanProperty1")); 327 assertEquals(Selector.fromString("booleanProperty1"), textarea.getSelector()); 328 329 controller.setModel(model); 330 SuiteViewSwing.waitForAWT(); 331 assertSame(view.getBoundModel(), model); 332 assertSame(textarea.getBoundModel(), model); 333 334 model.setBooleanProperty1(Boolean.FALSE); 335 SuiteViewSwing.waitForAWT(); 336 337 textarea.setText("rubbish"); 338 textarea.focusLost(new FocusEvent(textarea, FocusEvent.FOCUS_LOST)); 339 SuiteViewSwing.waitForAWT(); 340 assertTrue(textarea.isEnabled()); 341 assertEquals("rubbish", textarea.getText()); 342 assertEquals(Boolean.FALSE, model.getBooleanProperty1()); 343 } 344 345 346 /*** 347 * A unit test for JUnit 348 * 349 * @throws Exception Any abnormal exception 350 */ 351 public void testBindNoMCE() throws Exception { 352 textarea.setSelector(Selector.fromString("stringProperty")); 353 assertEquals(Selector.fromString("stringProperty"), textarea.getSelector()); 354 355 SwingDummyModelNoMCE model = new SwingDummyModelNoMCE(); 356 357 controller.setModel(model); 358 SuiteViewSwing.waitForAWT(); 359 assertSame(view.getBoundModel(), model); 360 361 assertSame(textarea.getBoundModel(), model); 362 assertTrue(textarea.isEnabled()); 363 assertEquals(model.getStringProperty(), textarea.getText()); 364 String x = model.getStringProperty(); 365 366 model.setStringProperty("abc"); 367 SuiteViewSwing.waitForAWT(); 368 assertTrue(textarea.isEnabled()); 369 assertEquals(x, textarea.getText()); 370 371 view.refresh(); 372 assertTrue(textarea.isEnabled()); 373 assertEquals(model.getStringProperty(), textarea.getText()); 374 x = model.getStringProperty(); 375 376 model.setStringProperty("xyz"); 377 SuiteViewSwing.waitForAWT(); 378 assertTrue(textarea.isEnabled()); 379 assertEquals(x, textarea.getText()); 380 381 view.refresh(); 382 assertTrue(textarea.isEnabled()); 383 assertEquals(model.getStringProperty(), textarea.getText()); 384 385 textarea.setText("gui"); 386 textarea.focusLost(new FocusEvent(textarea, FocusEvent.FOCUS_LOST)); 387 SuiteViewSwing.waitForAWT(); 388 assertTrue(textarea.isEnabled()); 389 assertEquals("gui", textarea.getText()); 390 assertEquals(model.getStringProperty(), textarea.getText()); 391 392 textarea.setText(""); 393 textarea.focusLost(new FocusEvent(textarea, FocusEvent.FOCUS_LOST)); 394 SuiteViewSwing.waitForAWT(); 395 // assertTrue(! textarea.isEnabled()); 396 assertNull(model.getStringProperty()); 397 398 model.setStringProperty("abc"); 399 SuiteViewSwing.waitForAWT(); 400 401 model.setStringProperty(null); 402 SuiteViewSwing.waitForAWT(); 403 view.refresh(); 404 assertTrue(!textarea.isEnabled()); 405 assertNull(model.getStringProperty()); 406 } 407 408 409 /*** 410 * A unit test for JUnit 411 * 412 * @throws Exception Any abnormal exception 413 */ 414 public void testInitialNullBind() throws Exception { 415 textarea.setSelectorString("subModel.stringProperty"); 416 model.setSubModel(null); 417 controller.setModel(model); 418 SuiteViewSwing.waitForAWT(); 419 420 assertTrue(!textarea.isEnabled()); 421 assertEquals("", textarea.getText()); 422 423 SwingDummyModel submodel = new SwingDummyModel(); 424 submodel.setStringProperty("test"); 425 model.setSubModel(submodel); 426 SuiteViewSwing.waitForAWT(); 427 428 assertTrue(textarea.isEnabled()); 429 assertEquals("test", textarea.getText()); 430 } 431 432 433 /*** 434 * The JUnit setup method 435 * 436 * @throws Exception Any abnormal exception 437 */ 438 protected void setUp() throws Exception { 439 440 textarea = new STextArea(); 441 textarea.setColumns(10); 442 textarea.setRows(5); 443 textarea.setDisableOnNull(true); 444 445 view = new SPanel(); 446 view.add(textarea); 447 448 controller = new SwingDummyController(); 449 controller.setView(view); 450 controller.startup(); 451 // does showView() 452 453 model = new SwingDummyModel(); 454 } 455 456 457 /*** 458 * The teardown method for JUnit 459 */ 460 protected void tearDown() { 461 controller.shutdown(); 462 } 463 464 // ***** setDisableOnNull(false); and test empty string, null, boolean 465 }

This page was automatically generated by Maven