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: TestBeansPropertyManager2.java,v 1.5 2002/09/12 19:09:35 ludovicc Exp $ 37 */ 38 package test.model.beans; 39 40 41 import java.util.ArrayList; 42 import junit.framework.TestCase; 43 import org.scopemvc.core.PropertyManager; 44 import org.scopemvc.core.Selector; 45 import org.scopemvc.model.beans.BeansPropertyManager; 46 47 /*** 48 * <P> 49 * 50 * </P> 51 * 52 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A> 53 * @created 05 September 2002 54 * @version $Revision: 1.5 $ $Date: 2002/09/12 19:09:35 $ 55 */ 56 public final class TestBeansPropertyManager2 extends TestCase { 57 58 private ModelObject m; 59 private PropertyManager manager; 60 61 62 /*** 63 * Constructor for the TestBeansPropertyManager2 object 64 * 65 * @param inName Name of the test 66 */ 67 public TestBeansPropertyManager2(String inName) { 68 super(inName); 69 } 70 71 72 // ------------- Simple sets 73 74 /*** 75 * A unit test for JUnit 76 * 77 * @throws Exception Any abnormal exception 78 */ 79 public void testSet0() throws Exception { 80 manager.set(m, Selector.fromString("stringProperty"), "test"); 81 assertEquals("test", m.getStringProperty()); 82 } 83 84 85 /*** 86 * A unit test for JUnit 87 * 88 * @throws Exception Any abnormal exception 89 */ 90 public void testSet1() throws Exception { 91 manager.set(m, Selector.fromString("intProperty"), new Integer(68)); 92 assertTrue(68 == m.getIntProperty()); 93 } 94 95 96 /*** 97 * A unit test for JUnit 98 * 99 * @throws Exception Any abnormal exception 100 */ 101 public void testSet2() throws Exception { 102 String[] s = {"a", "b", "c"}; 103 manager.set(m, Selector.fromString("stringIndexedProperty"), s); 104 assertSame(s, m.getStringIndexedProperty()); 105 } 106 107 108 /*** 109 * A unit test for JUnit 110 * 111 * @throws Exception Any abnormal exception 112 */ 113 public void testSet3() throws Exception { 114 ArrayList l = new ArrayList(); 115 l.add("a"); 116 l.add("b"); 117 manager.set(m, Selector.fromString("stringNonIndexedProperty"), l); 118 assertSame(l, m.getStringNonIndexedProperty()); 119 } 120 121 122 /*** 123 * A unit test for JUnit 124 * 125 * @throws Exception Any abnormal exception 126 */ 127 public void testSet4() throws Exception { 128 String[] a = new String[2]; 129 a[0] = "x"; 130 a[1] = "y"; 131 manager.set(m, Selector.fromString("stringNonIndexedProperty2"), a); 132 assertSame(a, m.getStringNonIndexedProperty2()); 133 } 134 135 136 // -------------------- Unknown simple property 137 138 /*** 139 * A unit test for JUnit 140 * 141 * @throws Exception Any abnormal exception 142 */ 143 public void testSetUnknown() throws Exception { 144 try { 145 manager.set(m, Selector.fromString("unknown"), "test"); 146 fail(); 147 } catch (Exception e) { 148 // expected 149 } 150 } 151 152 153 // -------------------- Read only simple property 154 155 /*** 156 * A unit test for JUnit 157 * 158 * @throws Exception Any abnormal exception 159 */ 160 public void testSetReadOnly() throws Exception { 161 try { 162 manager.set(m, Selector.fromString("readOnlyStringProperty"), "test"); 163 fail(); 164 } catch (Exception e) { 165 // expected 166 } 167 } 168 169 170 // -------------------- Indexed property 171 172 /*** 173 * A unit test for JUnit 174 * 175 * @throws Exception Any abnormal exception 176 */ 177 public void testSetIndexed0() throws Exception { 178 manager.set(m, Selector.fromString("stringIndexedProperty.0"), "test"); 179 String s1 = m.getStringIndexedProperty(0); 180 assertSame("test", s1); 181 } 182 183 184 /*** 185 * A unit test for JUnit 186 * 187 * @throws Exception Any abnormal exception 188 */ 189 public void testSetIndexed1() throws Exception { 190 manager.set(m, Selector.fromString("stringIndexedProperty.1"), "test1"); 191 String s1 = m.getStringIndexedProperty(1); 192 assertSame("test1", s1); 193 } 194 195 196 // -------------------- Unknown indexed property 197 198 /*** 199 * A unit test for JUnit 200 * 201 * @throws Exception Any abnormal exception 202 */ 203 public void testSetIndexedUnknown0() throws Exception { 204 try { 205 manager.set(m, Selector.fromString("stringIndexedProperty.99"), "test"); 206 fail(); 207 } catch (Exception e) { 208 } 209 } 210 211 212 /*** 213 * A unit test for JUnit 214 * 215 * @throws Exception Any abnormal exception 216 */ 217 public void testSetIndexedUnknown1() throws Exception { 218 try { 219 manager.set(m, Selector.fromString("unknown.0"), "test"); 220 fail(); 221 } catch (Exception e) { 222 // expected 223 } 224 } 225 226 227 // -------------------- NonIndexed List property 228 229 /*** 230 * A unit test for JUnit 231 * 232 * @throws Exception Any abnormal exception 233 */ 234 public void testSetNonIndexed0() throws Exception { 235 manager.set(m, Selector.fromString("stringNonIndexedProperty.0"), "test"); 236 Object s1 = m.getStringNonIndexedProperty().get(0); 237 assertSame("test", s1); 238 } 239 240 241 /*** 242 * A unit test for JUnit 243 * 244 * @throws Exception Any abnormal exception 245 */ 246 public void testSetNonIndexed1() throws Exception { 247 manager.set(m, Selector.fromString("stringNonIndexedProperty.1"), "test1"); 248 Object s1 = m.getStringNonIndexedProperty().get(1); 249 assertSame("test1", s1); 250 } 251 252 253 // -------------------- NonIndexed Array property 254 255 /*** 256 * A unit test for JUnit 257 * 258 * @throws Exception Any abnormal exception 259 */ 260 public void testSetNonIndexed2() throws Exception { 261 manager.set(m, Selector.fromString("stringNonIndexedProperty2.0"), "test2"); 262 Object s1 = m.getStringNonIndexedProperty2()[0]; 263 assertSame("test2", s1); 264 } 265 266 267 /*** 268 * A unit test for JUnit 269 * 270 * @throws Exception Any abnormal exception 271 */ 272 public void testSetNonIndexed3() throws Exception { 273 manager.set(m, Selector.fromString("stringNonIndexedProperty2.1"), "test3"); 274 Object s1 = m.getStringNonIndexedProperty2()[1]; 275 assertSame("test3", s1); 276 } 277 278 279 // -------------------- Unknown indexed property 280 281 /*** 282 * A unit test for JUnit 283 * 284 * @throws Exception Any abnormal exception 285 */ 286 public void testSetNonIndexedUnknown0() throws Exception { 287 try { 288 manager.set(m, Selector.fromString("stringNonIndexedProperty.99"), "test"); 289 fail(); 290 } catch (Exception e) { 291 } 292 } 293 294 295 // -------------------- Hidden Indexed property 296 297 /*** 298 * A unit test for JUnit 299 * 300 * @throws Exception Any abnormal exception 301 */ 302 public void testGetHiddenIndexed0() throws Exception { 303 manager.set(m, Selector.fromString("hiddenStringIndexedProperty.0"), "test"); 304 String s1 = m.getHiddenStringIndexedProperty(0); 305 assertSame("test", s1); 306 } 307 308 309 /*** 310 * A unit test for JUnit 311 * 312 * @throws Exception Any abnormal exception 313 */ 314 public void testGetHiddenIndexed1() throws Exception { 315 manager.set(m, Selector.fromString("hiddenStringIndexedProperty.1"), "test1"); 316 String s1 = m.getHiddenStringIndexedProperty(1); 317 assertSame("test1", s1); 318 } 319 320 321 // -------------------- Unknown hidden indexed property 322 323 /*** 324 * A unit test for JUnit 325 * 326 * @throws Exception Any abnormal exception 327 */ 328 public void testGetHiddenIndexedUnknown0() throws Exception { 329 try { 330 manager.set(m, Selector.fromString("hiddenStringIndexedProperty.99"), "test"); 331 fail(); 332 } catch (Exception e) { 333 } 334 } 335 336 337 // -------------------- Submodel access 338 339 /*** 340 * A unit test for JUnit 341 * 342 * @throws Exception Any abnormal exception 343 */ 344 public void testSetSubmodel0() throws Exception { 345 ModelObject o = new ModelObject(); 346 m.setSubModel(o); 347 348 manager.set(m, Selector.fromString("subModel.stringProperty"), "test3"); 349 assertSame("test3", o.getStringProperty()); 350 351 manager.set(m, Selector.fromString("subModel.stringIndexedProperty.1"), "test4"); 352 assertSame("test4", o.getStringIndexedProperty(1)); 353 } 354 355 356 /*** 357 * The JUnit setup method 358 */ 359 protected void setUp() { 360 m = new ModelObject(); 361 manager = BeansPropertyManager.getInstance(m); 362 } 363 } 364

This page was automatically generated by Maven