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: TestActiveBoundModel.java,v 1.4 2002/09/12 19:09:37 ludovicc Exp $ 37 */ 38 package test.view.util; 39 40 41 import junit.framework.TestCase; 42 import org.scopemvc.core.Control; 43 import org.scopemvc.core.Controller; 44 import org.scopemvc.core.Selector; 45 import org.scopemvc.core.View; 46 import org.scopemvc.view.util.ActiveBoundModel; 47 import org.scopemvc.view.util.ModelBindable; 48 import test.model.basic.BasicTestModel; 49 50 /*** 51 * <P> 52 * 53 * </P> 54 * 55 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net>;Steve Meyfroidt</A> 56 * @created 05 September 2002 57 * @version $Revision: 1.4 $ $Date: 2002/09/12 19:09:37 $ 58 */ 59 public final class TestActiveBoundModel extends TestCase { 60 61 /*** 62 * TODO: describe of the Field 63 */ 64 public static BasicTestModel testModel, subModel; 65 /*** 66 * TODO: describe of the Field 67 */ 68 public static TestView testView; 69 70 private final static long WAIT_FOR_MCE = 200; 71 /*** 72 * TODO: describe of the Field 73 */ 74 public ActiveBoundModel activeBoundModel; 75 76 77 /*** 78 * Constructor for the TestActiveBoundModel object 79 * 80 * @param inName Name of the test 81 */ 82 public TestActiveBoundModel(String inName) { 83 super(inName); 84 } 85 86 87 /*** 88 * A unit test for JUnit 89 * 90 * @throws Exception Any abnormal exception 91 */ 92 public void testGetPropertyState() throws Exception { 93 94 assertTrue(activeBoundModel.getPropertyReadOnly()); 95 assertNull(activeBoundModel.getPropertyValue()); 96 97 activeBoundModel.setBoundModel(testModel); 98 99 assertTrue(activeBoundModel.getPropertyReadOnly()); 100 assertSame(testModel, activeBoundModel.getPropertyValue()); 101 102 activeBoundModel.setSelector(Selector.fromString("subModel.name")); 103 104 assertTrue(!activeBoundModel.getPropertyReadOnly()); 105 assertEquals(testModel.getSubModel().getName(), activeBoundModel.getPropertyValue()); 106 } 107 108 109 /*** 110 * A unit test for JUnit 111 * 112 * @throws Exception Any abnormal exception 113 */ 114 public void testActiveBoundModelSetters() throws Exception { 115 116 testView.setBoundModel(testModel); 117 assertSame(testView.getViewValue(), testModel); 118 assertTrue(!testView.enabled); 119 120 testView.setSelector(Selector.fromString("subModel.name")); 121 assertEquals(subModel.getName(), testView.getViewValue()); 122 assertTrue(testView.enabled); 123 124 testView.setSelector(BasicTestModel.NAME); 125 assertEquals(testModel.getName(), testView.getViewValue()); 126 assertTrue(testView.enabled); 127 128 testView.setBoundModel(null); 129 assertTrue(!testView.enabled); 130 // Now handled in the widget 131 132 subModel.makeNameReadOnly(true); 133 Thread.currentThread().sleep(WAIT_FOR_MCE); 134 testView.setSelector(Selector.fromString("subModel.name")); 135 testView.setBoundModel(testModel); 136 assertEquals(subModel.getName(), testView.getViewValue()); 137 assertTrue(!testView.enabled); 138 // Now handled in the widget 139 140 testView.setSelector(Selector.fromString("subModel.subModel.name")); 141 assertNull(testView.getViewValue()); 142 assertTrue(!testView.enabled); 143 // Now handled in the widget 144 } 145 146 147 /*** 148 * A unit test for JUnit 149 * 150 * @throws Exception Any abnormal exception 151 */ 152 public void testAccessChanges() throws Exception { 153 154 testView.setBoundModel(testModel); 155 testView.setSelector(Selector.fromString("subModel.name")); 156 assertEquals(testView.getViewValue(), subModel.getName()); 157 assertTrue(testView.enabled); 158 159 subModel.makeNameReadOnly(true); 160 Thread.currentThread().sleep(WAIT_FOR_MCE); 161 assertEquals(testView.getViewValue(), subModel.getName()); 162 assertTrue(!testView.enabled); 163 164 subModel.makeNameReadOnly(false); 165 Thread.currentThread().sleep(WAIT_FOR_MCE); 166 assertEquals(testView.getViewValue(), subModel.getName()); 167 assertTrue(testView.enabled); 168 } 169 170 171 /*** 172 * A unit test for JUnit 173 * 174 * @throws Exception Any abnormal exception 175 */ 176 public void testValueChanges() throws Exception { 177 178 testView.setBoundModel(testModel); 179 testView.setSelector(Selector.fromString("subModel.name")); 180 assertEquals(testView.getViewValue(), subModel.getName()); 181 182 subModel.setName("New name"); 183 Thread.currentThread().sleep(WAIT_FOR_MCE); 184 assertEquals(testView.getViewValue(), subModel.getName()); 185 assertEquals(testView.getViewValue(), "New name"); 186 187 BasicTestModel newSubModel = new BasicTestModel("New submodel"); 188 testModel.setSubModel(newSubModel); 189 Thread.currentThread().sleep(WAIT_FOR_MCE); 190 assertEquals(testView.getViewValue(), newSubModel.getName()); 191 192 subModel.makeNameReadOnly(true); 193 Thread.currentThread().sleep(WAIT_FOR_MCE); 194 testModel.setSubModel(subModel); 195 Thread.currentThread().sleep(WAIT_FOR_MCE); 196 assertEquals(testView.getViewValue(), subModel.getName()); 197 assertTrue(!testView.enabled); 198 // Now handled in the widget 199 } 200 201 202 /*** 203 * A unit test for JUnit 204 * 205 * @throws Exception Any abnormal exception 206 */ 207 public void testViewToModel() throws Exception { 208 209 testView.setBoundModel(testModel); 210 testView.setSelector(BasicTestModel.NAME); 211 testView.value = "New name"; 212 testView.boundModel.updateModel(); 213 Thread.currentThread().sleep(WAIT_FOR_MCE); 214 assertEquals(testView.value, testModel.getName()); 215 } 216 217 218 /*** 219 * The JUnit setup method 220 * 221 * @throws Exception Any abnormal exception 222 */ 223 protected void setUp() throws Exception { 224 testModel = new BasicTestModel("model"); 225 subModel = new BasicTestModel("submodel"); 226 testModel.setSubModel(subModel); 227 activeBoundModel = new ActiveBoundModel(new TestView()); 228 testView = new TestView(); 229 } 230 231 232 /*** 233 * TODO: document the class 234 * 235 * @author lclaude 236 * @created 05 September 2002 237 */ 238 public class TestView implements View, ModelBindable { 239 /*** 240 * TODO: describe of the Field 241 */ 242 public ActiveBoundModel boundModel = new ActiveBoundModel(this); 243 /*** 244 * TODO: describe of the Field 245 */ 246 public Object value; 247 /*** 248 * TODO: describe of the Field 249 */ 250 public boolean enabled = true; 251 252 /*** 253 * Gets the controller 254 * 255 * @return The controller value 256 */ 257 public Controller getController() { 258 return null; 259 } 260 261 /*** 262 * TODO: document the method 263 * 264 * @param inControl TODO: Describe the Parameter 265 */ 266 public void issueControl(Control inControl) { } 267 268 /*** 269 * Gets the selector 270 * 271 * @return The selector value 272 */ 273 public Selector getSelector() { 274 return boundModel.getSelector(); 275 } 276 277 /*** 278 * Gets the bound model 279 * 280 * @return The boundModel value 281 */ 282 public Object getBoundModel() { 283 return boundModel.getBoundModel(); 284 } 285 286 /*** 287 * Gets the view value 288 * 289 * @return The viewValue value 290 */ 291 public Object getViewValue() { 292 return value; 293 } 294 295 /*** 296 * Sets the controller 297 * 298 * @param inController The new controller value 299 */ 300 public void setController(Controller inController) { } 301 302 /*** 303 * Sets the selector 304 * 305 * @param inSelector The new selector value 306 */ 307 public void setSelector(Selector inSelector) { 308 boundModel.setSelector(inSelector); 309 } 310 311 /*** 312 * Sets the bound model 313 * 314 * @param inModel The new boundModel value 315 */ 316 public void setBoundModel(Object inModel) { 317 boundModel.setBoundModel(inModel); 318 } 319 320 /*** 321 * TODO: document the method 322 * 323 * @param inValue TODO: Describe the Parameter 324 * @param inReadOnly TODO: Describe the Parameter 325 */ 326 public void updateFromProperty(Object inValue, boolean inReadOnly) { 327 value = inValue; 328 enabled = !inReadOnly; 329 } 330 331 /*** 332 * TODO: document the method 333 * 334 * @param inException TODO: Describe the Parameter 335 */ 336 public void validationFailed(Exception inException) { } 337 338 /*** 339 * TODO: document the method 340 */ 341 public void validationSuccess() { } 342 } 343 } 344

This page was automatically generated by Maven