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 TestLinkMaximizerSystematic 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 LinkMaximizer(); 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_B); 89 90 Visitor visitor = new LinkMaximizer(); 91 visitor.traverseNodes(factory.getPackages().values()); 92 93 assertEquals("a outbound", 2, a.getOutboundDependencies().size()); 94 assertTrue("Missing a --> b", a.getOutboundDependencies().contains(b)); 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", 1, b.getInboundDependencies().size()); 103 assertTrue("Missing b <-- a", b.getInboundDependencies().contains(a)); 104 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 105 assertEquals("b_B inbound", 1, b_B.getInboundDependencies().size()); 106 assertTrue("Missing b.B <-- a", b_B.getInboundDependencies().contains(a)); 107 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 108 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 109 } 110 111 public void testPackageFeature() { 112 a.addDependency(b_B_b); 113 114 Visitor visitor = new LinkMaximizer(); 115 visitor.traverseNodes(factory.getPackages().values()); 116 117 assertEquals("a outbound", 3, a.getOutboundDependencies().size()); 118 assertTrue("Missing a --> b", a.getOutboundDependencies().contains(b)); 119 assertTrue("Missing a --> b.B", a.getOutboundDependencies().contains(b_B)); 120 assertTrue("Missing a --> b.B.b", a.getOutboundDependencies().contains(b_B_b)); 121 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 122 assertEquals("a_A outbound", 0, a_A.getOutboundDependencies().size()); 123 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 124 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 125 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 126 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 127 assertEquals("b inbound", 1, b.getInboundDependencies().size()); 128 assertTrue("Missing b <-- a", b.getInboundDependencies().contains(a)); 129 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 130 assertEquals("b_B inbound", 1, b_B.getInboundDependencies().size()); 131 assertTrue("Missing b.B <-- a", b_B.getInboundDependencies().contains(a)); 132 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 133 assertEquals("b_B_b inbound", 1, b_B_b.getInboundDependencies().size()); 134 assertTrue("Missing b.B.b <-- a", b_B_b.getInboundDependencies().contains(a)); 135 } 136 137 public void testClassPackage() { 138 a_A.addDependency(b); 139 140 Visitor visitor = new LinkMaximizer(); 141 visitor.traverseNodes(factory.getPackages().values()); 142 143 assertEquals("a outbound", 1, a.getOutboundDependencies().size()); 144 assertTrue("Missing a --> b", a.getOutboundDependencies().contains(b)); 145 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 146 assertEquals("a_A outbound", 1, a_A.getOutboundDependencies().size()); 147 assertTrue("Missing a.A --> b", a_A.getOutboundDependencies().contains(b)); 148 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 149 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 150 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 151 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 152 assertEquals("b inbound", 2, b.getInboundDependencies().size()); 153 assertTrue("Missing b <-- a", b.getInboundDependencies().contains(a)); 154 assertTrue("Missing b <-- a.A", b.getInboundDependencies().contains(a_A)); 155 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 156 assertEquals("b_B inbound", 0, b_B.getInboundDependencies().size()); 157 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 158 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 159 } 160 161 public void testClassClass() { 162 a_A.addDependency(b_B); 163 164 Visitor visitor = new LinkMaximizer(); 165 visitor.traverseNodes(factory.getPackages().values()); 166 167 assertEquals("a outbound", 2, a.getOutboundDependencies().size()); 168 assertTrue("Missing a --> b", a.getOutboundDependencies().contains(b)); 169 assertTrue("Missing a --> b.B", a.getOutboundDependencies().contains(b_B)); 170 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 171 assertEquals("a_A outbound", 2, a_A.getOutboundDependencies().size()); 172 assertTrue("Missing a.A --> b", a_A.getOutboundDependencies().contains(b)); 173 assertTrue("Missing a.A --> b.B", a_A.getOutboundDependencies().contains(b_B)); 174 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 175 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 176 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 177 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 178 assertEquals("b inbound", 2, b.getInboundDependencies().size()); 179 assertTrue("Missing b <-- a", b.getInboundDependencies().contains(a)); 180 assertTrue("Missing b <-- a.A", b.getInboundDependencies().contains(a_A)); 181 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 182 assertEquals("b_B inbound", 2, b_B.getInboundDependencies().size()); 183 assertTrue("Missing b.B <-- a", b_B.getInboundDependencies().contains(a)); 184 assertTrue("Missing b.B <-- a.A", b_B.getInboundDependencies().contains(a_A)); 185 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 186 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 187 } 188 189 public void testClassClassSparse() { 190 a.addDependency(b); 191 a_A.addDependency(b_B); 192 193 Visitor visitor = new LinkMaximizer(); 194 visitor.traverseNodes(factory.getPackages().values()); 195 196 assertEquals("a outbound", 2, a.getOutboundDependencies().size()); 197 assertTrue("Missing a --> b", a.getOutboundDependencies().contains(b)); 198 assertTrue("Missing a --> b.B", a.getOutboundDependencies().contains(b_B)); 199 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 200 assertEquals("a_A outbound", 2, a_A.getOutboundDependencies().size()); 201 assertTrue("Missing a.A --> b", a_A.getOutboundDependencies().contains(b)); 202 assertTrue("Missing a.A --> b.B", a_A.getOutboundDependencies().contains(b_B)); 203 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 204 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 205 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 206 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 207 assertEquals("b inbound", 2, b.getInboundDependencies().size()); 208 assertTrue("Missing b <-- a", b.getInboundDependencies().contains(a)); 209 assertTrue("Missing b <-- a.A", b.getInboundDependencies().contains(a_A)); 210 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 211 assertEquals("b_B inbound", 2, b_B.getInboundDependencies().size()); 212 assertTrue("Missing b.B <-- a", b_B.getInboundDependencies().contains(a)); 213 assertTrue("Missing b.B <-- a.A", b_B.getInboundDependencies().contains(a_A)); 214 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 215 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 216 } 217 218 public void testClassFeature() { 219 a_A.addDependency(b_B_b); 220 221 Visitor visitor = new LinkMaximizer(); 222 visitor.traverseNodes(factory.getPackages().values()); 223 224 assertEquals("a outbound", 3, a.getOutboundDependencies().size()); 225 assertTrue("Missing a --> b", a.getOutboundDependencies().contains(b)); 226 assertTrue("Missing a --> b.B", a.getOutboundDependencies().contains(b_B)); 227 assertTrue("Missing a --> b.B.b", a.getOutboundDependencies().contains(b_B_b)); 228 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 229 assertEquals("a_A outbound", 3, a_A.getOutboundDependencies().size()); 230 assertTrue("Missing a.A --> b", a_A.getOutboundDependencies().contains(b)); 231 assertTrue("Missing a.A --> b.B", a_A.getOutboundDependencies().contains(b_B)); 232 assertTrue("Missing a.A --> b.B.b", a_A.getOutboundDependencies().contains(b_B_b)); 233 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 234 assertEquals("a_A_a outbound", 0, a_A_a.getOutboundDependencies().size()); 235 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 236 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 237 assertEquals("b inbound", 2, b.getInboundDependencies().size()); 238 assertTrue("Missing b <-- a", b.getInboundDependencies().contains(a)); 239 assertTrue("Missing b <-- a_A", b.getInboundDependencies().contains(a_A)); 240 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 241 assertEquals("b_B inbound", 2, b_B.getInboundDependencies().size()); 242 assertTrue("Missing b.B <-- a", b_B.getInboundDependencies().contains(a)); 243 assertTrue("Missing b.B <-- a_A", b_B.getInboundDependencies().contains(a_A)); 244 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 245 assertEquals("b_B_b inbound", 2, b_B_b.getInboundDependencies().size()); 246 assertTrue("Missing b.B.b <-- a", b_B_b.getInboundDependencies().contains(a)); 247 assertTrue("Missing b.B.b <-- a_A", b_B_b.getInboundDependencies().contains(a_A)); 248 } 249 250 public void testFeaturePackage() { 251 a_A_a.addDependency(b); 252 253 Visitor visitor = new LinkMaximizer(); 254 visitor.traverseNodes(factory.getPackages().values()); 255 256 assertEquals("a outbound", 1, a.getOutboundDependencies().size()); 257 assertTrue("Missing a --> b", a.getOutboundDependencies().contains(b)); 258 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 259 assertEquals("a_A outbound", 1, a_A.getOutboundDependencies().size()); 260 assertTrue("Missing a.A --> b", a_A.getOutboundDependencies().contains(b)); 261 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 262 assertEquals("a_A_a outbound", 1, a_A_a.getOutboundDependencies().size()); 263 assertTrue("Missing a.A.a --> b", a_A_a.getOutboundDependencies().contains(b)); 264 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 265 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 266 assertEquals("b inbound", 3, b.getInboundDependencies().size()); 267 assertTrue("Missing b <-- a", b.getInboundDependencies().contains(a)); 268 assertTrue("Missing b <-- a.A", b.getInboundDependencies().contains(a_A)); 269 assertTrue("Missing b <-- a.A.a", b.getInboundDependencies().contains(a_A_a)); 270 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 271 assertEquals("b_B inbound", 0, b_B.getInboundDependencies().size()); 272 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 273 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 274 } 275 276 public void testFeatureClass() { 277 a_A_a.addDependency(b_B); 278 279 Visitor visitor = new LinkMaximizer(); 280 visitor.traverseNodes(factory.getPackages().values()); 281 282 assertEquals("a outbound", 2, a.getOutboundDependencies().size()); 283 assertTrue("Missing a --> b", a.getOutboundDependencies().contains(b)); 284 assertTrue("Missing a --> b.B", a.getOutboundDependencies().contains(b_B)); 285 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 286 assertEquals("a_A outbound", 2, a_A.getOutboundDependencies().size()); 287 assertTrue("Missing a.A --> b", a_A.getOutboundDependencies().contains(b)); 288 assertTrue("Missing a.A --> b.B", a_A.getOutboundDependencies().contains(b_B)); 289 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 290 assertEquals("a_A_a outbound", 2, a_A_a.getOutboundDependencies().size()); 291 assertTrue("Missing a.A.a --> b", a_A_a.getOutboundDependencies().contains(b)); 292 assertTrue("Missing a.A.a --> b.B", a_A_a.getOutboundDependencies().contains(b_B)); 293 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 294 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 295 assertEquals("b inbound", 3, b.getInboundDependencies().size()); 296 assertTrue("Missing b <-- a", b.getInboundDependencies().contains(a)); 297 assertTrue("Missing b <-- a.A", b.getInboundDependencies().contains(a_A)); 298 assertTrue("Missing b <-- a.A.a", b.getInboundDependencies().contains(a_A_a)); 299 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 300 assertEquals("b_B inbound", 3, b_B.getInboundDependencies().size()); 301 assertTrue("Missing b.B <-- a", b_B.getInboundDependencies().contains(a)); 302 assertTrue("Missing b.B <-- a.A", b_B.getInboundDependencies().contains(a_A)); 303 assertTrue("Missing b.B <-- a.A.a", b_B.getInboundDependencies().contains(a_A_a)); 304 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 305 assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies().size()); 306 } 307 308 public void testFeatureFeature() { 309 a_A_a.addDependency(b_B_b); 310 311 Visitor visitor = new LinkMaximizer(); 312 visitor.traverseNodes(factory.getPackages().values()); 313 314 assertEquals("a outbound", 3, a.getOutboundDependencies().size()); 315 assertTrue("Missing a --> b", a.getOutboundDependencies().contains(b)); 316 assertTrue("Missing a --> b.B", a.getOutboundDependencies().contains(b_B)); 317 assertTrue("Missing a --> b.B.b", a.getOutboundDependencies().contains(b_B_b)); 318 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 319 assertEquals("a_A outbound", 3, a_A.getOutboundDependencies().size()); 320 assertTrue("Missing a.A --> b", a_A.getOutboundDependencies().contains(b)); 321 assertTrue("Missing a.A --> b.B", a_A.getOutboundDependencies().contains(b_B)); 322 assertTrue("Missing a.A --> b.B.b", a_A.getOutboundDependencies().contains(b_B_b)); 323 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 324 assertEquals("a_A_a outbound", 3, a_A_a.getOutboundDependencies().size()); 325 assertTrue("Missing a.A.a --> b", a_A_a.getOutboundDependencies().contains(b)); 326 assertTrue("Missing a.A.a --> b.B", a_A_a.getOutboundDependencies().contains(b_B)); 327 assertTrue("Missing a.A.a --> b.B.b", a_A_a.getOutboundDependencies().contains(b_B_b)); 328 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 329 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 330 assertEquals("b inbound", 3, b.getInboundDependencies().size()); 331 assertTrue("Missing b <-- a", b.getInboundDependencies().contains(a)); 332 assertTrue("Missing b <-- a.A", b.getInboundDependencies().contains(a_A)); 333 assertTrue("Missing b <-- a.A.a", b.getInboundDependencies().contains(a_A_a)); 334 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 335 assertEquals("b_B inbound", 3, b_B.getInboundDependencies().size()); 336 assertTrue("Missing b.B <-- a", b_B.getInboundDependencies().contains(a)); 337 assertTrue("Missing b.B <-- a.A", b_B.getInboundDependencies().contains(a_A)); 338 assertTrue("Missing b.B <-- a.A.a", b_B.getInboundDependencies().contains(a_A_a)); 339 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 340 assertEquals("b_B_b inbound", 3, b_B_b.getInboundDependencies().size()); 341 assertTrue("Missing b.B.b <-- a", b_B_b.getInboundDependencies().contains(a)); 342 assertTrue("Missing b.B.b <-- a.A", b_B_b.getInboundDependencies().contains(a_A)); 343 assertTrue("Missing b.B.b <-- a.A.a", b_B_b.getInboundDependencies().contains(a_A_a)); 344 } 345 346 public void testFeatureFeatureSparse() { 347 a.addDependency(b); 348 a_A.addDependency(b_B); 349 a_A_a.addDependency(b_B_b); 350 351 Visitor visitor = new LinkMaximizer(); 352 visitor.traverseNodes(factory.getPackages().values()); 353 354 assertEquals("a outbound", 3, a.getOutboundDependencies().size()); 355 assertTrue("Missing a --> b", a.getOutboundDependencies().contains(b)); 356 assertTrue("Missing a --> b.B", a.getOutboundDependencies().contains(b_B)); 357 assertTrue("Missing a --> b.B.b", a.getOutboundDependencies().contains(b_B_b)); 358 assertEquals("a inbound", 0, a.getInboundDependencies().size()); 359 assertEquals("a_A outbound", 3, a_A.getOutboundDependencies().size()); 360 assertTrue("Missing a.A --> b", a_A.getOutboundDependencies().contains(b)); 361 assertTrue("Missing a.A --> b.B", a_A.getOutboundDependencies().contains(b_B)); 362 assertTrue("Missing a.A --> b.B.b", a_A.getOutboundDependencies().contains(b_B_b)); 363 assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size()); 364 assertEquals("a_A_a outbound", 3, a_A_a.getOutboundDependencies().size()); 365 assertTrue("Missing a.A.a --> b", a_A_a.getOutboundDependencies().contains(b)); 366 assertTrue("Missing a.A.a --> b.B", a_A_a.getOutboundDependencies().contains(b_B)); 367 assertTrue("Missing a.A.a --> b.B.b", a_A_a.getOutboundDependencies().contains(b_B_b)); 368 assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size()); 369 assertEquals("b outbound", 0, b.getOutboundDependencies().size()); 370 assertEquals("b inbound", 3, b.getInboundDependencies().size()); 371 assertTrue("Missing b <-- a", b.getInboundDependencies().contains(a)); 372 assertTrue("Missing b <-- a.A", b.getInboundDependencies().contains(a_A)); 373 assertTrue("Missing b <-- a.A.a", b.getInboundDependencies().contains(a_A_a)); 374 assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size()); 375 assertEquals("b_B inbound", 3, b_B.getInboundDependencies().size()); 376 assertTrue("Missing b.B <-- a", b_B.getInboundDependencies().contains(a)); 377 assertTrue("Missing b.B <-- a.A", b_B.getInboundDependencies().contains(a_A)); 378 assertTrue("Missing b.B <-- a.A.a", b_B.getInboundDependencies().contains(a_A_a)); 379 assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size()); 380 assertEquals("b_B_b inbound", 3, b_B_b.getInboundDependencies().size()); 381 assertTrue("Missing b.B.b <-- a", b_B_b.getInboundDependencies().contains(a)); 382 assertTrue("Missing b.B.b <-- a.A", b_B_b.getInboundDependencies().contains(a_A)); 383 assertTrue("Missing b.B.b <-- a.A.a", b_B_b.getInboundDependencies().contains(a_A_a)); 384 } 385 } 386 | Popular Tags |