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: TestBeansPropertyManager3.java,v 1.7 2002/09/12 19:09:35 ludovicc Exp $ 37 */ 38 package test.model.beans; 39 40 41 import java.util.ArrayList; 42 import java.util.Arrays; 43 import java.util.HashSet; 44 import java.util.Iterator; 45 import java.util.List; 46 import java.util.Set; 47 import junit.framework.TestCase; 48 import org.scopemvc.core.PropertyManager; 49 import org.scopemvc.core.Selector; 50 import org.scopemvc.model.beans.BeansPropertyManager; 51 import org.scopemvc.model.collection.ListModel; 52 import org.scopemvc.model.util.CompoundSelectorIterator; 53 import org.scopemvc.model.util.IntIndexSelectorIterator; 54 55 /*** 56 * <P> 57 * 58 * </P> 59 * 60 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A> 61 * @created 05 September 2002 62 * @version $Revision: 1.7 $ $Date: 2002/09/12 19:09:35 $ 63 */ 64 public final class TestBeansPropertyManager3 extends TestCase { 65 66 private ModelObject m; 67 private PropertyManager manager; 68 69 70 /*** 71 * Constructor for the TestBeansPropertyManager3 object 72 * 73 * @param inName Name of the test 74 */ 75 public TestBeansPropertyManager3(String inName) { 76 super(inName); 77 } 78 79 80 /*** 81 * A unit test for JUnit 82 * 83 * @throws Exception Any abnormal exception 84 */ 85 public void testIsReadOnly() throws Exception { 86 assertTrue(!manager.isReadOnly(m, Selector.fromString("stringProperty"))); 87 assertTrue(!manager.isReadOnly(m, Selector.fromString("intProperty"))); 88 assertTrue(!manager.isReadOnly(m, Selector.fromString("stringIndexedProperty"))); 89 assertTrue(!manager.isReadOnly(m, Selector.fromString("stringIndexedProperty.0"))); 90 assertTrue(!manager.isReadOnly(m, Selector.fromString("stringNonIndexedProperty"))); 91 assertTrue(!manager.isReadOnly(m, Selector.fromString("stringNonIndexedProperty.0"))); 92 assertTrue(!manager.isReadOnly(m, Selector.fromString("stringNonIndexedProperty2"))); 93 assertTrue(!manager.isReadOnly(m, Selector.fromString("stringNonIndexedProperty2.0"))); 94 assertTrue(manager.isReadOnly(m, Selector.fromString("readOnlyStringProperty"))); 95 96 // try { 97 manager.isReadOnly(m, Selector.fromString("unknown")); 98 // fail(); 99 // } catch (Exception e) { 100 // // expected 101 // } 102 } 103 104 105 /*** 106 * A unit test for JUnit 107 * 108 * @throws Exception Any abnormal exception 109 */ 110 public void testHasProperty() throws Exception { 111 assertTrue(manager.hasProperty(m, Selector.fromString("stringProperty"))); 112 assertTrue(manager.hasProperty(m, Selector.fromString("intProperty"))); 113 assertTrue(!manager.hasProperty(m, Selector.fromString("unknown"))); 114 assertTrue(manager.hasProperty(m, Selector.fromString("stringIndexedProperty"))); 115 assertTrue(manager.hasProperty(m, Selector.fromString("stringIndexedProperty.0"))); 116 assertTrue(!manager.hasProperty(m, Selector.fromString("stringIndexedProperty.0.name"))); 117 assertTrue(!manager.hasProperty(m, Selector.fromString("stringIndexedProperty.99"))); 118 assertTrue(manager.hasProperty(m, Selector.fromString("stringNonIndexedProperty"))); 119 assertTrue(manager.hasProperty(m, Selector.fromString("stringNonIndexedProperty.0"))); 120 assertTrue(!manager.hasProperty(m, Selector.fromString("stringNonIndexedProperty.99"))); 121 assertTrue(manager.hasProperty(m, Selector.fromString("stringNonIndexedProperty2"))); 122 assertTrue(manager.hasProperty(m, Selector.fromString("stringNonIndexedProperty2.0"))); 123 assertTrue(!manager.hasProperty(m, Selector.fromString("stringNonIndexedProperty2.99"))); 124 assertTrue(!manager.hasProperty(m, Selector.fromString("hiddenStringIndexedProperty"))); 125 assertTrue(manager.hasProperty(m, Selector.fromString("hiddenStringIndexedProperty.0"))); 126 assertTrue(manager.hasProperty(m, Selector.fromString("readOnlyStringProperty"))); 127 } 128 129 130 /*** 131 * A unit test for JUnit 132 * 133 * @throws Exception Any abnormal exception 134 */ 135 public void testGetPropertyClass() throws Exception { 136 assertTrue(manager.getPropertyClass(m, Selector.fromString("stringProperty")) == String.class); 137 assertTrue(manager.getPropertyClass(m, Selector.fromString("intProperty")) == Integer.TYPE); 138 assertTrue(manager.getPropertyClass(m, Selector.fromString("stringIndexedProperty")) == String[].class); 139 assertTrue(manager.getPropertyClass(m, Selector.fromString("stringIndexedProperty.0")) == String.class); 140 assertTrue(manager.getPropertyClass(m, Selector.fromString("stringNonIndexedProperty")) == java.util.ArrayList.class); 141 assertTrue(manager.getPropertyClass(m, Selector.fromString("stringNonIndexedProperty.0")) == Object.class); 142 assertTrue(manager.getPropertyClass(m, Selector.fromString("stringNonIndexedProperty2")) == String[].class); 143 assertTrue(manager.getPropertyClass(m, Selector.fromString("stringNonIndexedProperty2.0")) == Object.class); 144 assertTrue(manager.getPropertyClass(m, Selector.fromString("hiddenStringIndexedProperty.0")) == String.class); 145 assertTrue(manager.getPropertyClass(m, Selector.fromString("readOnlyStringProperty")) == String.class); 146 } 147 148 149 /*** 150 * A unit test for JUnit 151 * 152 * @throws Exception Any abnormal exception 153 */ 154 public void testGetSelectorIterator0() throws Exception { 155 String[] names = {"stringProperty", "intProperty", "stringIndexedProperty", "stringNonIndexedProperty", "stringNonIndexedProperty2", "readOnlyStringProperty"}; 156 Set nameSet = new HashSet(Arrays.asList(names)); 157 for (Iterator i = manager.getSelectorIterator(m); i.hasNext(); ) { 158 Selector s = (Selector) i.next(); 159 nameSet.remove(s.getName()); 160 } 161 assertTrue(nameSet.toString(), nameSet.isEmpty()); 162 } 163 164 165 /*** 166 * A unit test for JUnit 167 * 168 * @throws Exception Any abnormal exception 169 */ 170 public void testGetSelectorIterator1() throws Exception { 171 manager = BeansPropertyManager.getInstance(m.getStringIndexedProperty()); 172 Iterator i = manager.getSelectorIterator(m.getStringIndexedProperty()); 173 assertTrue(i instanceof IntIndexSelectorIterator); 174 int count = 0; 175 while (i.hasNext()) { 176 i.next(); 177 ++count; 178 } 179 assertTrue(count == m.getStringIndexedProperty().length); 180 } 181 182 183 /*** 184 * A unit test for JUnit 185 * 186 * @throws Exception Any abnormal exception 187 */ 188 public void testGetSelectorIterator2() throws Exception { 189 ListModel lm = new ListModel(m.getStringNonIndexedProperty()); 190 manager = BeansPropertyManager.getInstance(lm); 191 Iterator i = manager.getSelectorIterator(lm); 192 assertTrue(i instanceof CompoundSelectorIterator); 193 194 Set names = new HashSet(); 195 while (i.hasNext()) { 196 names.add(((Selector) i.next()).getName()); 197 } 198 199 assertTrue("Not size: " + (lm.getSize() + 3) + ", " + names.toString(), names.size() == lm.getSize() + 3); 200 201 assertTrue("Can't find size property", names.contains("size")); 202 assertTrue("Can't find empty property", names.contains("empty")); 203 assertTrue("Can't find list property", names.contains("list")); 204 } 205 206 207 /*** 208 * A unit test for JUnit 209 * 210 * @throws Exception Any abnormal exception 211 */ 212 public void testGetSelectorIterator3() throws Exception { 213 manager = BeansPropertyManager.getInstance(m.getStringNonIndexedProperty2()); 214 Iterator i = manager.getSelectorIterator(m.getStringNonIndexedProperty2()); 215 assertTrue(i instanceof IntIndexSelectorIterator); 216 int count = 0; 217 while (i.hasNext()) { 218 i.next(); 219 ++count; 220 } 221 assertTrue(count == m.getStringNonIndexedProperty2().length); 222 } 223 224 225 /*** 226 * A unit test for JUnit 227 * 228 * @throws Exception Any abnormal exception 229 */ 230 public void testGetSelectorFor() throws Exception { 231 assertNull(manager.getSelectorFor(m, null)); 232 233 assertNull(manager.getSelectorFor(m, "not a property")); 234 235 // JavaBean 236 Selector s = manager.getSelectorFor(m, m.getStringProperty()); 237 assertEquals(s, Selector.fromString("stringProperty")); 238 239 // Object[] 240 Object o = m.getStringIndexedProperty(); 241 manager = BeansPropertyManager.getInstance(o); 242 assertEquals(Selector.fromInt(1), manager.getSelectorFor(o, m.getStringIndexedProperty(1))); 243 244 // java.util.List 245 java.util.List l = m.getStringNonIndexedProperty(); 246 manager = BeansPropertyManager.getInstance(l); 247 assertEquals(Selector.fromInt(1), manager.getSelectorFor(l, l.get(1))); 248 } 249 250 251 /*** 252 * The JUnit setup method 253 */ 254 protected void setUp() { 255 m = new ModelObject(); 256 manager = BeansPropertyManager.getInstance(m); 257 } 258 } 259

This page was automatically generated by Maven