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

This page was automatically generated by Maven