1 20 package org.enhydra.barracuda.plankton.data; 21 22 import java.io.*; 23 import java.util.*; 24 25 import junit.framework.*; 26 27 import org.apache.log4j.*; 28 import org.enhydra.barracuda.testbed.*; 29 30 31 36 public abstract class PMapTestCases extends PDataTestCases { 37 38 42 public PMapTestCases(String name) { 43 super(name); 44 } 45 46 52 55 public abstract void testClone(); 56 57 60 public void testEquals() { 61 if (logger.isInfoEnabled()) logger.info("testing equals()"); 62 PMap pmap1 = null; 63 PMap pmap2 = null; 64 65 pmap1 = this.getPMapInstance(); 67 pmap2 = this.getPMapInstance(); 68 assertEquals("Empty lists equality check failed", pmap1, pmap2); 69 70 pmap1 = this.getPMapInstance(); 72 pmap2 = this.getPMapInstance(); 73 String foo1 = "foo1"; 74 String foo2 = "foo2"; 75 String foo3 = "foo3"; 76 pmap1 = this.getPMapInstance(); 77 pmap1.put("key1", foo1); 78 pmap1.put("key2", foo2); 79 pmap1.put("key3", foo3); 80 pmap2 = this.getPMapInstance(); 81 pmap2.put("key1", foo1); 82 pmap2.put("key2", foo2); 83 pmap2.put("key3", foo3); 84 assertEquals("Non-empty lists equality check 1a failed", pmap1, pmap2); 85 pmap2.put("key4", "blah"); 86 assertTrue("Non-empty lists inequality check 1b failed", !(pmap1.equals(pmap2))); 87 assertTrue("Non-empty lists inequality check 1c failed", !(pmap2.equals(pmap1))); 88 89 pmap1 = this.getPMapInstance(); 91 pmap2 = this.getPMapInstance(); 92 pmap1.put("key1", "foo1"); 93 pmap1.put("key2", "foo2"); 94 pmap1.put("key3", "foo3"); 95 pmap2 = this.getPMapInstance(); 96 pmap2.put("key1", "foo1"); 97 pmap2.put("key2", "foo2"); 98 pmap2.put("key3", "foo3"); 99 assertEquals("Non-empty lists equality check 2a failed", pmap1, pmap2); 100 pmap2.put("key4", "blah"); 101 assertTrue("Non-empty lists inequality check 2b failed", !(pmap1.equals(pmap2))); 102 assertTrue("Non-empty lists inequality check 2c failed", !(pmap2.equals(pmap1))); 103 104 } 105 106 109 public void testParentalInheritance() { 110 if (logger.isInfoEnabled()) logger.info("testing parental inheritance methods"); 111 PMap proot = null; 112 PMap pchild1 = null; 113 PMap pchild2 = null; 114 PMap pchild3 = null; 115 Map tmap = null; 116 117 118 proot = getPMapInstance(); 121 pchild1 = getPMapInstance(); 122 pchild2 = getPMapInstance(); 123 proot.put("k1", pchild1); 124 pchild1.put("k2", pchild2); 125 assertTrue("Parental Inheritance check 1 failed...parent inheritance failed (should've but didn't)", proot.getParent()==null); 126 assertTrue("Parental Inheritance check 1a failed...parent inheritance failed (should've but didn't)", pchild1.getParent()==proot); 127 assertTrue("Parental Inheritance check 1b failed...parent inheritance failed (should've but didn't)", pchild2.getParent()==pchild1); 128 proot = getPMapInstance(); 130 pchild1 = getPMapInstance(); 131 pchild2 = getPMapInstance(); 132 tmap = new HashMap(); 133 tmap.put("c1", pchild1); 134 tmap.put("c2", pchild2); 135 proot.putAll(tmap); 136 assertTrue("Parental Inheritance check 1d failed...parent inheritance failed (should've but didn't)", pchild1.getParent()==proot); 137 assertTrue("Parental Inheritance check 1e failed...parent inheritance failed (should've but didn't)", pchild2.getParent()==proot); 138 proot = getPMapInstance(); 140 pchild1 = getPMapInstance(); 141 proot.put("key1", pchild1); 142 proot.remove("key1"); 143 assertTrue("Parental Inheritance check 1n failed...child retained parental setting", pchild1.getParent()==null); 144 145 146 proot = getPMapInstance(); 149 pchild1 = getPMapInstance(); 150 pchild1.setInheritParents(false); 151 pchild2 = getPMapInstance(); 152 pchild2.setInheritParents(false); 153 proot.put("k1", pchild1); 154 pchild1.put("k2", pchild2); 155 assertTrue("Parental Inheritance check 2 failed...parent inheritance failed (shouldn't have but did)", proot.getParent()==null); 156 assertTrue("Parental Inheritance check 2a failed...parent inheritance failed (shouldn't have but did)", pchild1.getParent()!=proot); 157 assertTrue("Parental Inheritance check 2b failed...parent inheritance failed (shouldn't have but did)", pchild2.getParent()!=pchild1); 158 proot = getPMapInstance(); 160 pchild1 = getPMapInstance(); 161 pchild1.setInheritParents(false); 162 pchild2 = getPMapInstance(); 163 pchild2.setInheritParents(false); 164 tmap = new HashMap(); 165 tmap.put("c1", pchild1); 166 tmap.put("c2", pchild2); 167 proot.putAll(tmap); 168 assertTrue("Parental Inheritance check 2d failed...parent inheritance failed (shouldn't have but did)", pchild1.getParent()!=proot); 169 assertTrue("Parental Inheritance check 2e failed...parent inheritance failed (shouldn't have but did)", pchild2.getParent()!=proot); 170 proot = getPMapInstance(); 172 pchild1 = getPMapInstance(); 173 proot.put("key1", pchild1); 174 pchild1.setInheritParents(false); proot.remove(pchild1); 176 assertTrue("Parental Inheritance check 2n failed...child's parental value was improperly cleared", pchild1.getParent()==proot); 177 } 178 179 182 public void testMapManipulation() { 183 if (logger.isInfoEnabled()) logger.info("testing basic data manipulation"); 184 PMap proot = null; 185 PMap pmap1 = null; 186 PMap pmap2 = null; 187 PMap pmap3 = null; 188 Map tmap = null; 189 Object [] keys = new Object [] {"key1", "key2", "key3"}; 190 Object [] vals = new Object [] {"Foo", new Integer (99), null}; 191 192 proot = getPMapInstance(); 195 for (int i=0; i<vals.length; i++) { 196 proot.put(keys[i], vals[i]); 197 assertTrue("Add data check 1a, idx["+i+"] - key missing", proot.containsKey(keys[i])); 198 assertTrue("Add data check 1b, idx["+i+"] - value missing", proot.containsValue(vals[i])); 199 assertTrue("Add data check 1c, idx["+i+"] - incorrect size", proot.size()==i+1); 200 assertTrue("Add data check 1d, idx["+i+"] - data not retrieved", proot.get(keys[i])==vals[i]); 201 assertTrue("Add data check 1e, idx["+i+"] - map claims to be empty", !proot.isEmpty()); 202 } 203 for (int i=vals.length-1; i>=0; i--) { 205 proot.remove(keys[i]); 206 assertTrue("Remove data check 1a, idx["+i+"] - key not removed", !proot.containsKey(keys[i])); 207 assertTrue("Remove data check 1b, idx["+i+"] - value not removed", !proot.containsValue(vals[i])); 208 assertTrue("Remove data check 1c, idx["+i+"] - incorrect size", proot.size()==i); 209 assertTrue("Remove data check 1d, idx["+i+"] - data not removed", proot.get(keys[i])==null); 210 } 211 assertTrue("Remove data check 1e - map not empty", proot.isEmpty()); 212 213 tmap = new HashMap(); 215 for (int i=0; i<vals.length; i++) {tmap.put(keys[i], vals[i]);} 216 proot = getPMapInstance(); 218 proot.putAll(tmap); 219 assertTrue("Add data check 2a - incorrect size", proot.size()==vals.length); 220 for (int i=0; i<vals.length; i++) { 221 assertTrue("Add data check 2a, idx["+i+"] - key missing", proot.containsKey(keys[i])); 222 assertTrue("Add data check 2b, idx["+i+"] - value missing", proot.containsValue(vals[i])); 223 assertTrue("Add data check 2c, idx["+i+"] - data not retrieved", proot.get(keys[i])==vals[i]); 224 assertTrue("Add data check 2d, idx["+i+"] - map claims to be empty", !proot.isEmpty()); 225 } 226 227 proot = getPMapInstance(); 230 for (int i=0; i<vals.length; i++) { 231 proot.put(keys[i], vals[i]); 232 } 233 assertTrue("Clear check 3a failed - data not added", proot.size()==vals.length); 234 proot.clear(); 235 assertTrue("Clear check 3b failed - data not removed", proot.size()==0); 236 } 237 238 239 } 240 | Popular Tags |