1 32 33 package com.jeantessier.dependency; 34 35 import java.io.*; 36 import java.util.*; 37 38 import junit.framework.*; 39 40 import org.apache.oro.text.perl.*; 41 42 public class TestLinkMinimizerSystematic extends TestCase { 43 NodeFactory factory; 44 45 PackageNode a; 46 ClassNode a_A; 47 FeatureNode a_A_a; 48 49 PackageNode b; 50 ClassNode b_B; 51 FeatureNode b_B_b; 52 53 protected void setUp() throws Exception { 54 factory = new NodeFactory(); 55 56 a = factory.createPackage("a"); 57 a_A = factory.createClass("a.A"); 58 a_A_a = factory.createFeature("a.A.a()"); 59 60 b = factory.createPackage("b"); 61 b_B = factory.createClass("b.B"); 62 b_B_b = factory.createFeature("b.B.b()"); 63 } 64 65 public void testPackagePackage() { 66 a.addDependency(b); 67 68 Visitor visitor = new LinkMinimizer(); 69 visitor.traverseNodes(factory.getPackages().values()); 70 71 assertEquals("a outbound", 1, a.getOutboundDependencies().size()); 72 assertTrue("Missing a --> b", a.getOutboundDependencies().contains(b)); 73 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 74 assertEquals("a_A outbound", 0, a_A.getOutboundDependencies().size()); 75 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 76 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 77 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 78 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 79 assertEquals("b inbound", 1, b.getInboundDependencies().size()); 80 assertTrue("Missing b <-- a", b.getInboundDependencies().contains(a)); 81 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 82 assertEquals("b_B inbound", 0, b_B.getInboundDependencies().size()); 83 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 84 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 85 } 86 87 public void testPackageClass() { 88 a.addDependency(b); 89 a.addDependency(b_B); 90 91 Visitor visitor = new LinkMinimizer(); 92 visitor.traverseNodes(factory.getPackages().values()); 93 94 assertEquals("a outbound", 1, a.getOutboundDependencies().size()); 95 assertTrue("Missing a --> b.B", a.getOutboundDependencies().contains(b_B)); 96 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 97 assertEquals("a_A outbound", 0, a_A.getOutboundDependencies().size()); 98 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 99 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 100 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 101 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 102 assertEquals("b inbound", 0, b.getInboundDependencies().size()); 103 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 104 assertEquals("b_B inbound", 1, b_B.getInboundDependencies().size()); 105 assertTrue("Missing b.B <-- a", b_B.getInboundDependencies().contains(a)); 106 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 107 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 108 } 109 110 public void testPackageFeature() { 111 a.addDependency(b); 112 a.addDependency(b_B); 113 a.addDependency(b_B_b); 114 115 Visitor visitor = new LinkMinimizer(); 116 visitor.traverseNodes(factory.getPackages().values()); 117 118 assertEquals("a outbound", 1, a.getOutboundDependencies().size()); 119 assertTrue("Missing a --> b.B.b", a.getOutboundDependencies().contains(b_B_b)); 120 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 121 assertEquals("a_A outbound", 0, a_A.getOutboundDependencies().size()); 122 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 123 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 124 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 125 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 126 assertEquals("b inbound", 0, b.getInboundDependencies().size()); 127 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 128 assertEquals("b_B inbound", 0, b_B.getInboundDependencies().size()); 129 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 130 assertEquals("b_B_b inbound", 1, b_B_b.getInboundDependencies().size()); 131 assertTrue("Missing b.B.b <-- a", b_B_b.getInboundDependencies().contains(a)); 132 } 133 134 public void testClassPackage() { 135 a.addDependency(b); 136 a_A.addDependency(b); 137 138 Visitor visitor = new LinkMinimizer(); 139 visitor.traverseNodes(factory.getPackages().values()); 140 141 assertEquals("a outbound", 0, a.getOutboundDependencies().size()); 142 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 143 assertEquals("a_A outbound", 1, a_A.getOutboundDependencies().size()); 144 assertTrue("Missing a.A --> b", a_A.getOutboundDependencies().contains(b)); 145 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 146 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 147 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 148 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 149 assertEquals("b inbound", 1, b.getInboundDependencies().size()); 150 assertTrue("Missing b <-- a.A", b.getInboundDependencies().contains(a_A)); 151 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 152 assertEquals("b_B inbound", 0, b_B.getInboundDependencies().size()); 153 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 154 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 155 } 156 157 public void testClassClass() { 158 a.addDependency(b); 159 a.addDependency(b_B); 160 a_A.addDependency(b); 161 a_A.addDependency(b_B); 162 163 Visitor visitor = new LinkMinimizer(); 164 visitor.traverseNodes(factory.getPackages().values()); 165 166 assertEquals("a outbound", 0, a.getOutboundDependencies().size()); 167 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 168 assertEquals("a_A outbound", 1, a_A.getOutboundDependencies().size()); 169 assertTrue("Missing a.A --> b.B", a_A.getOutboundDependencies().contains(b_B)); 170 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 171 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 172 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 173 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 174 assertEquals("b inbound", 0, b.getInboundDependencies().size()); 175 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 176 assertEquals("b_B inbound", 1, b_B.getInboundDependencies().size()); 177 assertTrue("Missing b.B <-- a.A", b_B.getInboundDependencies().contains(a_A)); 178 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 179 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 180 } 181 182 public void testClassClassSparse() { 183 a.addDependency(b); 184 a_A.addDependency(b_B); 185 186 Visitor visitor = new LinkMinimizer(); 187 visitor.traverseNodes(factory.getPackages().values()); 188 189 assertEquals("a outbound", 0, a.getOutboundDependencies().size()); 190 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 191 assertEquals("a_A outbound", 1, a_A.getOutboundDependencies().size()); 192 assertTrue("Missing a.A --> b.B", a_A.getOutboundDependencies().contains(b_B)); 193 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 194 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 195 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 196 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 197 assertEquals("b inbound", 0, b.getInboundDependencies().size()); 198 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 199 assertEquals("b_B inbound", 1, b_B.getInboundDependencies().size()); 200 assertTrue("Missing b.B <-- a_A", b_B.getInboundDependencies().contains(a_A)); 201 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 202 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 203 } 204 205 public void testClassFeature() { 206 a.addDependency(b); 207 a.addDependency(b_B); 208 a.addDependency(b_B_b); 209 a_A.addDependency(b); 210 a_A.addDependency(b_B); 211 a_A.addDependency(b_B_b); 212 213 Visitor visitor = new LinkMinimizer(); 214 visitor.traverseNodes(factory.getPackages().values()); 215 216 assertEquals("a outbound", 0, a.getOutboundDependencies().size()); 217 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 218 assertEquals("a_A outbound", 1, a_A.getOutboundDependencies().size()); 219 assertTrue("Missing a.A --> b.B.b", a_A.getOutboundDependencies().contains(b_B_b)); 220 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 221 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 222 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 223 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 224 assertEquals("b inbound", 0, b.getInboundDependencies().size()); 225 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 226 assertEquals("b_B inbound", 0, b_B.getInboundDependencies().size()); 227 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 228 assertEquals("b_B_b inbound", 1, b_B_b.getInboundDependencies().size()); 229 assertTrue("Missing b.B.b <-- a_A", b_B_b.getInboundDependencies().contains(a_A)); 230 } 231 232 public void testFeaturePackage() { 233 a.addDependency(b); 234 a_A.addDependency(b); 235 a_A_a.addDependency(b); 236 237 Visitor visitor = new LinkMinimizer(); 238 visitor.traverseNodes(factory.getPackages().values()); 239 240 assertEquals("a outbound", 0, a.getOutboundDependencies().size()); 241 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 242 assertEquals("a_A outbound", 0, a_A.getOutboundDependencies().size()); 243 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 244 assertEquals("a_A_a outbound", 1, a_A_a.getOutboundDependencies().size()); 245 assertTrue("Missing a.A.a --> b", a_A_a.getOutboundDependencies().contains(b)); 246 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 247 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 248 assertEquals("b inbound", 1, b.getInboundDependencies().size()); 249 assertTrue("Missing b <-- a.A.a", b.getInboundDependencies().contains(a_A_a)); 250 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 251 assertEquals("b_B inbound", 0, b_B.getInboundDependencies().size()); 252 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 253 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 254 } 255 256 public void testFeatureClass() { 257 a.addDependency(b); 258 a.addDependency(b_B); 259 a_A.addDependency(b); 260 a_A.addDependency(b_B); 261 a_A_a.addDependency(b); 262 a_A_a.addDependency(b_B); 263 264 Visitor visitor = new LinkMinimizer(); 265 visitor.traverseNodes(factory.getPackages().values()); 266 267 assertEquals("a outbound", 0, a.getOutboundDependencies().size()); 268 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 269 assertEquals("a_A outbound", 0, a_A.getOutboundDependencies().size()); 270 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 271 assertEquals("a_A_a outbound", 1, a_A_a.getOutboundDependencies().size()); 272 assertTrue("Missing a.A.a --> b.B", a_A_a.getOutboundDependencies().contains(b_B)); 273 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 274 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 275 assertEquals("b inbound", 0, b.getInboundDependencies().size()); 276 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 277 assertEquals("b_B inbound", 1, b_B.getInboundDependencies().size()); 278 assertTrue("Missing b.B <-- a.A.a", b_B.getInboundDependencies().contains(a_A_a)); 279 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 280 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 281 } 282 283 public void testFeatureFeature() { 284 a.addDependency(b); 285 a.addDependency(b_B); 286 a.addDependency(b_B_b); 287 a_A.addDependency(b); 288 a_A.addDependency(b_B); 289 a_A.addDependency(b_B_b); 290 a_A_a.addDependency(b); 291 a_A_a.addDependency(b_B); 292 a_A_a.addDependency(b_B_b); 293 294 Visitor visitor = new LinkMinimizer(); 295 visitor.traverseNodes(factory.getPackages().values()); 296 297 assertEquals("a outbound", 0, a.getOutboundDependencies().size()); 298 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 299 assertEquals("a_A outbound", 0, a_A.getOutboundDependencies().size()); 300 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 301 assertEquals("a_A_a outbound", 1, a_A_a.getOutboundDependencies().size()); 302 assertTrue("Missing a.A.a --> b.B.b", a_A_a.getOutboundDependencies().contains(b_B_b)); 303 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 304 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 305 assertEquals("b inbound", 0, b.getInboundDependencies().size()); 306 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 307 assertEquals("b_B inbound", 0, b_B.getInboundDependencies().size()); 308 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 309 assertEquals("b_B_b inbound", 1, b_B_b.getInboundDependencies().size()); 310 assertTrue("Missing b.B.b <-- a.A.a", b_B_b.getInboundDependencies().contains(a_A_a)); 311 } 312 313 public void testFeatureFeatureSparse() { 314 a.addDependency(b); 315 a_A.addDependency(b_B); 316 a_A_a.addDependency(b_B_b); 317 318 Visitor visitor = new LinkMinimizer(); 319 visitor.traverseNodes(factory.getPackages().values()); 320 321 assertEquals("a outbound", 0, a.getOutboundDependencies().size()); 322 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 323 assertEquals("a_A outbound", 0, a_A.getOutboundDependencies().size()); 324 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 325 assertEquals("a_A_a outbound", 1, a_A_a.getOutboundDependencies().size()); 326 assertTrue("Missing a.A.a --> b.B.b", a_A_a.getOutboundDependencies().contains(b_B_b)); 327 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 328 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 329 assertEquals("b inbound", 0, b.getInboundDependencies().size()); 330 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 331 assertEquals("b_B inbound", 0, b_B.getInboundDependencies().size()); 332 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 333 assertEquals("b_B_b inbound", 1, b_B_b.getInboundDependencies().size()); 334 assertTrue("Missing b.B.b <-- a.A.a", b_B_b.getInboundDependencies().contains(a_A_a)); 335 } 336 } 337 | Popular Tags |