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: TestSSlider.java,v 1.8 2002/09/13 17:21:31 ludovicc Exp $ 37 */ 38 package test.view.swing; 39 40 import org.apache.commons.logging.Log; 41 import org.apache.commons.logging.LogFactory; 42 43 import junit.framework.TestCase; 44 import org.scopemvc.core.Selector; 45 import org.scopemvc.view.swing.SPanel; 46 import org.scopemvc.view.swing.SSlider; 47 48 /*** 49 * <P> 50 * 51 * </P> 52 * 53 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net>;Steve Meyfroidt</A> 54 * @created 13 September 2002 55 * @version $Revision: 1.8 $ $Date: 2002/09/13 17:21:31 $ 56 */ 57 public final class TestSSlider extends TestCase { 58 59 private static final Log LOG = LogFactory.getLog(TestSSlider.class); 60 61 private SSlider slider; 62 private SwingDummyController controller; 63 private SPanel view; 64 private SwingDummyModel model; 65 66 67 /*** 68 * Constructor for the TestSSlider object 69 * 70 * @param inName Name of the test 71 */ 72 public TestSSlider(String inName) { 73 super(inName); 74 } 75 76 77 /*** 78 * A unit test for JUnit 79 * 80 * @throws Exception Any abnormal exception 81 */ 82 public void testUnbound() throws Exception { 83 SuiteViewSwing.waitForAWT(); 84 assertTrue(!slider.isEnabled()); 85 86 slider.setSelector(Selector.fromString("intProperty")); 87 SuiteViewSwing.waitForAWT(); 88 assertEquals(Selector.fromString("intProperty"), slider.getSelector()); 89 assertTrue(!slider.isEnabled()); 90 } 91 92 93 /*** 94 * A unit test for JUnit 95 * 96 * @throws Exception Any abnormal exception 97 */ 98 public void testConvenience() throws Exception { 99 SuiteViewSwing.waitForAWT(); 100 assertTrue(!slider.isEnabled()); 101 102 slider.setSelectorString("intProperty"); 103 SuiteViewSwing.waitForAWT(); 104 assertEquals(Selector.fromString("intProperty"), slider.getSelector()); 105 assertTrue(!slider.isEnabled()); 106 } 107 108 109 /*** 110 * A unit test for JUnit 111 * 112 * @throws Exception Any abnormal exception 113 */ 114 public void testBind1() throws Exception { 115 slider.setSelector(Selector.fromString("intProperty")); 116 assertEquals(Selector.fromString("intProperty"), slider.getSelector()); 117 118 controller.setModel(model); 119 SuiteViewSwing.waitForAWT(); 120 assertSame(view.getBoundModel(), model); 121 assertSame(slider.getBoundModel(), model); 122 assertTrue(slider.isEnabled()); 123 assertTrue(model.getIntProperty() == slider.getValue()); 124 125 model.setIntProperty(50); 126 SuiteViewSwing.waitForAWT(); 127 assertTrue(slider.isEnabled()); 128 assertTrue(model.getIntProperty() == slider.getValue()); 129 130 model.setIntProperty(105); 131 SuiteViewSwing.waitForAWT(); 132 assertTrue(slider.isEnabled()); 133 assertTrue(model.getIntProperty() == slider.getValue()); 134 assertTrue(100 == model.getIntProperty()); 135 136 slider.setValue(30); 137 SuiteViewSwing.waitForAWT(); 138 assertTrue(slider.isEnabled()); 139 assertTrue(30 == model.getIntProperty()); 140 } 141 142 143 /*** 144 * A unit test for JUnit 145 * 146 * @throws Exception Any abnormal exception 147 */ 148 public void testBind2() throws Exception { 149 slider.setSelector(Selector.fromString("intProperty2")); 150 assertEquals(Selector.fromString("intProperty2"), slider.getSelector()); 151 152 controller.setModel(model); 153 SuiteViewSwing.waitForAWT(); 154 assertSame(view.getBoundModel(), model); 155 assertSame(slider.getBoundModel(), model); 156 assertTrue(slider.isEnabled()); 157 assertTrue(model.getIntProperty2().intValue() == slider.getValue()); 158 159 model.setIntProperty2(new Integer(50)); 160 SuiteViewSwing.waitForAWT(); 161 assertTrue(slider.isEnabled()); 162 assertTrue(model.getIntProperty2().intValue() == slider.getValue()); 163 164 model.setIntProperty2(new Integer(105)); 165 SuiteViewSwing.waitForAWT(); 166 assertTrue(slider.isEnabled()); 167 assertTrue(model.getIntProperty2().intValue() == slider.getValue()); 168 assertTrue(100 == model.getIntProperty2().intValue()); 169 170 slider.setValue(30); 171 SuiteViewSwing.waitForAWT(); 172 assertTrue(slider.isEnabled()); 173 assertTrue(30 == model.getIntProperty2().intValue()); 174 175 model.setIntProperty2(null); 176 SuiteViewSwing.waitForAWT(); 177 assertTrue(!slider.isEnabled()); 178 } 179 180 181 /*** 182 * A unit test for JUnit 183 * 184 * @throws Exception Any abnormal exception 185 */ 186 public void testBadBind() throws Exception { 187 slider.setSelector(Selector.fromString("stringProperty")); 188 controller.setModel(model); 189 SuiteViewSwing.waitForAWT(); 190 191 assertTrue(!slider.isEnabled()); 192 193 slider.setValue(50); 194 } 195 196 197 /*** 198 * A unit test for JUnit 199 * 200 * @throws Exception Any abnormal exception 201 */ 202 public void testReadOnlyBind() throws Exception { 203 slider.setSelector(Selector.fromString("intReadOnlyProperty")); 204 controller.setModel(model); 205 SuiteViewSwing.waitForAWT(); 206 207 assertTrue(!slider.isEnabled()); 208 } 209 210 211 /*** 212 * A unit test for JUnit 213 * 214 * @throws Exception Any abnormal exception 215 */ 216 public void testValidation() throws Exception { 217 slider.setSelector(Selector.fromString("invalidIntProperty")); 218 controller.setModel(model); 219 SuiteViewSwing.waitForAWT(); 220 221 assertTrue(slider.isEnabled()); 222 slider.setValue(10); 223 SuiteViewSwing.waitForAWT(); 224 assertEquals(10, model.getInvalidIntProperty()); 225 226 slider.setValue(60); 227 SuiteViewSwing.waitForAWT(); 228 assertTrue(slider.isEnabled()); 229 assertEquals(10, model.getInvalidIntProperty()); 230 assertEquals(60, slider.getValue()); 231 } 232 233 234 /*** 235 * A unit test for JUnit 236 * 237 * @throws Exception Any abnormal exception 238 */ 239 public void testBindNoMCE() throws Exception { 240 slider.setSelector(Selector.fromString("intProperty")); 241 assertEquals(Selector.fromString("intProperty"), slider.getSelector()); 242 243 SwingDummyModelNoMCE model = new SwingDummyModelNoMCE(); 244 245 controller.setModel(model); 246 SuiteViewSwing.waitForAWT(); 247 assertSame(view.getBoundModel(), model); 248 249 assertSame(slider.getBoundModel(), model); 250 assertTrue(slider.isEnabled()); 251 assertEquals(model.getIntProperty(), slider.getValue()); 252 253 model.setIntProperty(50); 254 assertTrue(slider.isEnabled()); 255 assertTrue(model.getIntProperty() != slider.getValue()); 256 257 view.refresh(); 258 assertTrue(slider.isEnabled()); 259 assertEquals(model.getIntProperty(), slider.getValue()); 260 261 model.setIntProperty(70); 262 assertTrue(slider.isEnabled()); 263 assertTrue(model.getIntProperty() != slider.getValue()); 264 265 view.refresh(); 266 assertTrue(slider.isEnabled()); 267 assertEquals(model.getIntProperty(), slider.getValue()); 268 269 slider.setValue(30); 270 SuiteViewSwing.waitForAWT(); 271 assertTrue(slider.isEnabled()); 272 assertEquals(slider.getValue(), model.getIntProperty()); 273 assertEquals(30, model.getIntProperty()); 274 } 275 276 277 /*** 278 * The JUnit setup method 279 * 280 * @throws Exception Any abnormal exception 281 */ 282 protected void setUp() throws Exception { 283 284 slider = new SSlider(); 285 286 view = new SPanel(); 287 view.add(slider); 288 289 controller = new SwingDummyController(); 290 controller.setView(view); 291 controller.startup(); 292 // does showView() 293 294 model = new SwingDummyModel(); 295 } 296 297 298 /*** 299 * The teardown method for JUnit 300 */ 301 protected void tearDown() { 302 controller.shutdown(); 303 } 304 }

This page was automatically generated by Maven