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 TestTransitiveClosureEngine extends TestCase { 43 private NodeFactory factory; 44 45 private PackageNode a; 46 private ClassNode a_A; 47 private FeatureNode a_A_a; 48 49 private PackageNode b; 50 private ClassNode b_B; 51 private FeatureNode b_B_b; 52 53 private PackageNode c; 54 private ClassNode c_C; 55 private FeatureNode c_C_c; 56 57 private RegularExpressionSelectionCriteria startCriteria; 58 private RegularExpressionSelectionCriteria stopCriteria; 59 60 protected void setUp() throws Exception { 61 super.setUp(); 62 63 factory = new NodeFactory(); 64 65 a = factory.createPackage("a"); 66 a_A = factory.createClass("a.A"); 67 a_A_a = factory.createFeature("a.A.a"); 68 69 b = factory.createPackage("b"); 70 b_B = factory.createClass("b.B"); 71 b_B_b = factory.createFeature("b.B.b"); 72 73 c = factory.createPackage("c"); 74 c_C = factory.createClass("c.C"); 75 c_C_c = factory.createFeature("c.C.c"); 76 77 a_A_a.addDependency(b_B_b); 78 b_B_b.addDependency(c_C_c); 79 80 startCriteria = new RegularExpressionSelectionCriteria(); 81 stopCriteria = new RegularExpressionSelectionCriteria(); 82 stopCriteria.setGlobalIncludes(""); 83 } 84 85 public void testSelectScope() { 86 startCriteria.setGlobalIncludes("/a.A.a/"); 87 88 GraphCopier copier = new GraphCopier(new SelectiveTraversalStrategy(startCriteria, new RegularExpressionSelectionCriteria())); 89 90 copier.traverseNodes(factory.getPackages().values()); 91 92 assertEquals("packages in scope: " , 1, copier.getScopeFactory().getPackages().values().size()); 93 assertEquals("classes in scope" , 1, copier.getScopeFactory().getClasses().values().size()); 94 assertEquals("features in scope" , 1, copier.getScopeFactory().getFeatures().values().size()); 95 96 assertEquals("package b in scope" , a, copier.getScopeFactory().getPackages().get("a")); 97 assertEquals("class a.A in scope" , a_A, copier.getScopeFactory().getClasses().get("a.A")); 98 assertEquals("feature a.A.a in scope", a_A_a, copier.getScopeFactory().getFeatures().get("a.A.a")); 99 } 100 101 public void testOutboundStartingPoint() { 102 startCriteria.setGlobalIncludes("/a.A.a/"); 103 104 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureOutboundSelector()); 105 106 assertEquals("Nb layers", 1, engine.getNbLayers()); 107 108 assertEquals("layer 0", 1, engine.getLayer(0).size()); 109 assertEquals("a.A.a in layer 0", a_A_a, engine.getLayer(0).iterator().next()); 110 assertNotSame("a.A.a in layer 0", a_A_a, engine.getLayer(0).iterator().next()); 111 112 assertEquals("Nb outbounds from a.A.a", 0, ((Node) engine.getLayer(0).iterator().next()).getOutboundDependencies().size()); 113 114 assertEquals("packages in scope: ", 1, engine.getFactory().getPackages().values().size()); 115 assertEquals("classes in scope" , 1, engine.getFactory().getClasses().values().size()); 116 assertEquals("features in scope", 1, engine.getFactory().getFeatures().values().size()); 117 118 assertEquals("package a in scope", a, engine.getFactory().getPackages().get("a")); 119 assertEquals("class a.A in scope", a_A, engine.getFactory().getClasses().get("a.A")); 120 assertEquals("feature a.A.a in scope", a_A_a, engine.getFactory().getFeatures().get("a.A.a")); 121 } 122 123 public void testOneOutboundLayer() { 124 startCriteria.setGlobalIncludes("/a.A.a/"); 125 126 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureOutboundSelector()); 127 engine.computeNextLayer(); 128 129 assertEquals("Nb layers", 2, engine.getNbLayers()); 130 131 assertEquals("layer 1", 1, engine.getLayer(1).size()); 132 assertEquals("b.B.b in layer 1", b_B_b, engine.getLayer(1).iterator().next()); 133 assertNotSame("b.B.b in layer 1", b_B_b, engine.getLayer(1).iterator().next()); 134 135 assertEquals("Nb outbounds from a.A.a", a_A_a.getOutboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getOutboundDependencies().size()); 136 assertEquals("Nb outbounds from b.B.b", 0, ((Node) engine.getLayer(1).iterator().next()).getOutboundDependencies().size()); 137 138 assertEquals("packages in scope: ", 2, engine.getFactory().getPackages().values().size()); 139 assertEquals("classes in scope" , 2, engine.getFactory().getClasses().values().size()); 140 assertEquals("features in scope", 2, engine.getFactory().getFeatures().values().size()); 141 142 assertEquals("package a in scope", a, engine.getFactory().getPackages().get("a")); 143 assertEquals("class a.A in scope", a_A, engine.getFactory().getClasses().get("a.A")); 144 assertEquals("feature a.A.a in scope", a_A_a, engine.getFactory().getFeatures().get("a.A.a")); 145 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 146 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 147 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 148 } 149 150 public void testTwoOutboundLayers() { 151 startCriteria.setGlobalIncludes("/a.A.a/"); 152 153 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureOutboundSelector()); 154 engine.computeNextLayer(); 155 engine.computeNextLayer(); 156 157 assertEquals("Nb layers", 3, engine.getNbLayers()); 158 159 assertEquals("layer 2", 1, engine.getLayer(1).size()); 160 assertEquals("c.C.c in layer 2", c_C_c, engine.getLayer(2).iterator().next()); 161 assertNotSame("c.C.c in layer 2", c_C_c, engine.getLayer(2).iterator().next()); 162 163 assertEquals("Nb outbounds from a.A.a", a_A_a.getOutboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getOutboundDependencies().size()); 164 assertEquals("Nb outbounds from b.B.b", b_B_b.getOutboundDependencies().size(), ((Node) engine.getLayer(1).iterator().next()).getOutboundDependencies().size()); 165 assertEquals("Nb outbounds from c.C.c", 0, ((Node) engine.getLayer(2).iterator().next()).getOutboundDependencies().size()); 166 167 assertEquals("packages in scope: ", 3, engine.getFactory().getPackages().values().size()); 168 assertEquals("classes in scope" , 3, engine.getFactory().getClasses().values().size()); 169 assertEquals("features in scope", 3, engine.getFactory().getFeatures().values().size()); 170 171 assertEquals("package a in scope", a, engine.getFactory().getPackages().get("a")); 172 assertEquals("class a.A in scope", a_A, engine.getFactory().getClasses().get("a.A")); 173 assertEquals("feature a.A.a in scope", a_A_a, engine.getFactory().getFeatures().get("a.A.a")); 174 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 175 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 176 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 177 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 178 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 179 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 180 } 181 182 public void testThreeOutboundLayers() { 183 startCriteria.setGlobalIncludes("/a.A.a/"); 184 185 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureOutboundSelector()); 186 engine.computeNextLayer(); 187 engine.computeNextLayer(); 188 engine.computeNextLayer(); 189 190 assertEquals("Nb layers", 3, engine.getNbLayers()); 191 192 assertEquals("Nb outbounds from a.A.a", a_A_a.getOutboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getOutboundDependencies().size()); 193 assertEquals("Nb outbounds from b.B.b", b_B_b.getOutboundDependencies().size(), ((Node) engine.getLayer(1).iterator().next()).getOutboundDependencies().size()); 194 assertEquals("Nb outbounds from c.C.c", c_C_c.getOutboundDependencies().size(), ((Node) engine.getLayer(2).iterator().next()).getOutboundDependencies().size()); 195 196 assertEquals("packages in scope: ", 3, engine.getFactory().getPackages().values().size()); 197 assertEquals("classes in scope" , 3, engine.getFactory().getClasses().values().size()); 198 assertEquals("features in scope", 3, engine.getFactory().getFeatures().values().size()); 199 200 assertEquals("package a in scope", a, engine.getFactory().getPackages().get("a")); 201 assertEquals("class a.A in scope", a_A, engine.getFactory().getClasses().get("a.A")); 202 assertEquals("feature a.A.a in scope", a_A_a, engine.getFactory().getFeatures().get("a.A.a")); 203 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 204 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 205 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 206 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 207 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 208 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 209 } 210 211 public void testFourOutboundLayers() { 212 startCriteria.setGlobalIncludes("/a.A.a/"); 213 214 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureOutboundSelector()); 215 engine.computeNextLayer(); 216 engine.computeNextLayer(); 217 engine.computeNextLayer(); 218 engine.computeNextLayer(); 219 220 assertEquals("Nb layers", 3, engine.getNbLayers()); 221 222 assertEquals("Nb outbounds from a.A.a", a_A_a.getOutboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getOutboundDependencies().size()); 223 assertEquals("Nb outbounds from b.B.b", b_B_b.getOutboundDependencies().size(), ((Node) engine.getLayer(1).iterator().next()).getOutboundDependencies().size()); 224 assertEquals("Nb outbounds from c.C.c", c_C_c.getOutboundDependencies().size(), ((Node) engine.getLayer(2).iterator().next()).getOutboundDependencies().size()); 225 226 assertEquals("packages in scope: ", 3, engine.getFactory().getPackages().values().size()); 227 assertEquals("classes in scope" , 3, engine.getFactory().getClasses().values().size()); 228 assertEquals("features in scope", 3, engine.getFactory().getFeatures().values().size()); 229 230 assertEquals("package a in scope", a, engine.getFactory().getPackages().get("a")); 231 assertEquals("class a.A in scope", a_A, engine.getFactory().getClasses().get("a.A")); 232 assertEquals("feature a.A.a in scope", a_A_a, engine.getFactory().getFeatures().get("a.A.a")); 233 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 234 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 235 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 236 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 237 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 238 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 239 } 240 241 public void testInboundStartingPoint() { 242 startCriteria.setGlobalIncludes("/c.C.c/"); 243 244 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 245 246 assertEquals("Nb layers", 1, engine.getNbLayers()); 247 248 assertEquals("layer 0", 1, engine.getLayer(0).size()); 249 assertEquals("c.C.c in layer 0", c_C_c, engine.getLayer(0).iterator().next()); 250 assertNotSame("c.C.c in layer 0", c_C_c, engine.getLayer(0).iterator().next()); 251 252 assertEquals("Nb inbounds from c.C.c", 0, ((Node) engine.getLayer(0).iterator().next()).getInboundDependencies().size()); 253 254 assertEquals("packages in scope: ", 1, engine.getFactory().getPackages().values().size()); 255 assertEquals("classes in scope" , 1, engine.getFactory().getClasses().values().size()); 256 assertEquals("features in scope", 1, engine.getFactory().getFeatures().values().size()); 257 258 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 259 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 260 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 261 } 262 263 public void testOneInboundLayer() { 264 startCriteria.setGlobalIncludes("/c.C.c/"); 265 266 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 267 engine.computeNextLayer(); 268 269 assertEquals("Nb layers", 2, engine.getNbLayers()); 270 271 assertEquals("layer 1", 1, engine.getLayer(1).size()); 272 assertEquals("b.B.b in layer 1", b_B_b, engine.getLayer(1).iterator().next()); 273 assertNotSame("b.B.b in layer 1", b_B_b, engine.getLayer(1).iterator().next()); 274 275 assertEquals("Nb inbounds from c.C.c", c_C_c.getInboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getInboundDependencies().size()); 276 assertEquals("Nb inbounds from b.B.b", 0, ((Node) engine.getLayer(1).iterator().next()).getInboundDependencies().size()); 277 278 assertEquals("packages in scope: ", 2, engine.getFactory().getPackages().values().size()); 279 assertEquals("classes in scope" , 2, engine.getFactory().getClasses().values().size()); 280 assertEquals("features in scope", 2, engine.getFactory().getFeatures().values().size()); 281 282 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 283 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 284 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 285 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 286 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 287 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 288 } 289 290 public void testTwoInboundLayers() { 291 startCriteria.setGlobalIncludes("/c.C.c/"); 292 293 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 294 engine.computeNextLayer(); 295 engine.computeNextLayer(); 296 297 assertEquals("Nb layers", 3, engine.getNbLayers()); 298 299 assertEquals("layer 2", 1, engine.getLayer(1).size()); 300 assertEquals("a.A.a in layer 2", a_A_a, engine.getLayer(2).iterator().next()); 301 assertNotSame("a.A.a in layer 2", a_A_a, engine.getLayer(2).iterator().next()); 302 303 assertEquals("Nb inbounds from c.C.c", c_C_c.getInboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getInboundDependencies().size()); 304 assertEquals("Nb inbounds from b.B.b", b_B_b.getInboundDependencies().size(), ((Node) engine.getLayer(1).iterator().next()).getInboundDependencies().size()); 305 assertEquals("Nb inbounds from a.A.a", 0, ((Node) engine.getLayer(2).iterator().next()).getInboundDependencies().size()); 306 307 assertEquals("packages in scope: ", 3, engine.getFactory().getPackages().values().size()); 308 assertEquals("classes in scope" , 3, engine.getFactory().getClasses().values().size()); 309 assertEquals("features in scope", 3, engine.getFactory().getFeatures().values().size()); 310 311 assertEquals("package a in scope", a, engine.getFactory().getPackages().get("a")); 312 assertEquals("class a.A in scope", a_A, engine.getFactory().getClasses().get("a.A")); 313 assertEquals("feature a.A.a in scope", a_A_a, engine.getFactory().getFeatures().get("a.A.a")); 314 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 315 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 316 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 317 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 318 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 319 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 320 } 321 322 public void testThreeInboundLayers() { 323 startCriteria.setGlobalIncludes("/c.C.c/"); 324 325 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 326 engine.computeNextLayer(); 327 engine.computeNextLayer(); 328 engine.computeNextLayer(); 329 330 assertEquals("Nb layers", 3, engine.getNbLayers()); 331 332 assertEquals("Nb inbounds from c.C.c", c_C_c.getInboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getInboundDependencies().size()); 333 assertEquals("Nb inbounds from b.B.b", b_B_b.getInboundDependencies().size(), ((Node) engine.getLayer(1).iterator().next()).getInboundDependencies().size()); 334 assertEquals("Nb inbounds from a.A.a", a_A_a.getInboundDependencies().size(), ((Node) engine.getLayer(2).iterator().next()).getInboundDependencies().size()); 335 336 assertEquals("packages in scope: ", 3, engine.getFactory().getPackages().values().size()); 337 assertEquals("classes in scope" , 3, engine.getFactory().getClasses().values().size()); 338 assertEquals("features in scope", 3, engine.getFactory().getFeatures().values().size()); 339 340 assertEquals("package a in scope", a, engine.getFactory().getPackages().get("a")); 341 assertEquals("class a.A in scope", a_A, engine.getFactory().getClasses().get("a.A")); 342 assertEquals("feature a.A.a in scope", a_A_a, engine.getFactory().getFeatures().get("a.A.a")); 343 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 344 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 345 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 346 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 347 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 348 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 349 } 350 351 public void testFourInboundLayers() { 352 startCriteria.setGlobalIncludes("/c.C.c/"); 353 354 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 355 engine.computeNextLayer(); 356 engine.computeNextLayer(); 357 engine.computeNextLayer(); 358 engine.computeNextLayer(); 359 360 assertEquals("Nb layers", 3, engine.getNbLayers()); 361 362 assertEquals("Nb inbounds from c.C.c", c_C_c.getInboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getInboundDependencies().size()); 363 assertEquals("Nb inbounds from b.B.b", b_B_b.getInboundDependencies().size(), ((Node) engine.getLayer(1).iterator().next()).getInboundDependencies().size()); 364 assertEquals("Nb inbounds from a.A.a", a_A_a.getInboundDependencies().size(), ((Node) engine.getLayer(2).iterator().next()).getInboundDependencies().size()); 365 366 assertEquals("packages in scope: ", 3, engine.getFactory().getPackages().values().size()); 367 assertEquals("classes in scope" , 3, engine.getFactory().getClasses().values().size()); 368 assertEquals("features in scope", 3, engine.getFactory().getFeatures().values().size()); 369 370 assertEquals("package a in scope", a, engine.getFactory().getPackages().get("a")); 371 assertEquals("class a.A in scope", a_A, engine.getFactory().getClasses().get("a.A")); 372 assertEquals("feature a.A.a in scope", a_A_a, engine.getFactory().getFeatures().get("a.A.a")); 373 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 374 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 375 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 376 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 377 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 378 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 379 } 380 381 public void testStopCriteria() { 382 startCriteria.setGlobalIncludes("/c.C.c/"); 383 stopCriteria.setGlobalIncludes("/b.B.b/"); 384 385 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 386 engine.computeNextLayer(); 387 engine.computeNextLayer(); 388 engine.computeNextLayer(); 389 engine.computeNextLayer(); 390 391 assertEquals("Nb layers", 2, engine.getNbLayers()); 392 393 assertEquals("Nb inbounds from c.C.c", c_C_c.getInboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getInboundDependencies().size()); 394 assertEquals("Nb inbounds from b.B.b", 0, ((Node) engine.getLayer(1).iterator().next()).getInboundDependencies().size()); 395 396 assertEquals("packages in scope: ", 2, engine.getFactory().getPackages().values().size()); 397 assertEquals("classes in scope" , 2, engine.getFactory().getClasses().values().size()); 398 assertEquals("features in scope", 2, engine.getFactory().getFeatures().values().size()); 399 400 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 401 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 402 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 403 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 404 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 405 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 406 } 407 408 public void testComputeAllLayers() { 409 startCriteria.setGlobalIncludes("/c.C.c/"); 410 411 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 412 engine.computeAllLayers(); 413 414 assertEquals("Nb layers", 3, engine.getNbLayers()); 415 416 assertEquals("Nb inbounds from c.C.c", c_C_c.getInboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getInboundDependencies().size()); 417 assertEquals("Nb inbounds from b.B.b", b_B_b.getInboundDependencies().size(), ((Node) engine.getLayer(1).iterator().next()).getInboundDependencies().size()); 418 assertEquals("Nb inbounds from a.A.a", a_A_a.getInboundDependencies().size(), ((Node) engine.getLayer(2).iterator().next()).getInboundDependencies().size()); 419 420 assertEquals("packages in scope: ", 3, engine.getFactory().getPackages().values().size()); 421 assertEquals("classes in scope" , 3, engine.getFactory().getClasses().values().size()); 422 assertEquals("features in scope", 3, engine.getFactory().getFeatures().values().size()); 423 424 assertEquals("package a in scope", a, engine.getFactory().getPackages().get("a")); 425 assertEquals("class a.A in scope", a_A, engine.getFactory().getClasses().get("a.A")); 426 assertEquals("feature a.A.a in scope", a_A_a, engine.getFactory().getFeatures().get("a.A.a")); 427 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 428 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 429 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 430 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 431 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 432 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 433 } 434 435 public void testComputeAllLayersWithStopCriteria() { 436 startCriteria.setGlobalIncludes("/c.C.c/"); 437 stopCriteria.setGlobalIncludes("/b.B.b/"); 438 439 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 440 engine.computeAllLayers(); 441 442 assertEquals("Nb layers", 2, engine.getNbLayers()); 443 444 assertEquals("Nb inbounds from c.C.c", c_C_c.getInboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getInboundDependencies().size()); 445 assertEquals("Nb inbounds from b.B.b", 0, ((Node) engine.getLayer(1).iterator().next()).getInboundDependencies().size()); 446 447 assertEquals("packages in scope: ", 2, engine.getFactory().getPackages().values().size()); 448 assertEquals("classes in scope" , 2, engine.getFactory().getClasses().values().size()); 449 assertEquals("features in scope", 2, engine.getFactory().getFeatures().values().size()); 450 451 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 452 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 453 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 454 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 455 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 456 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 457 } 458 459 public void testComputeAllLayersUntilStartCriteria() { 460 startCriteria.setGlobalIncludes("/c.C.c/"); 461 stopCriteria.setGlobalIncludes("//"); 462 463 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 464 engine.computeAllLayers(); 465 466 assertEquals("Nb layers", 1, engine.getNbLayers()); 467 468 assertEquals("Nb inbounds from c.C.c", 0, ((Node) engine.getLayer(0).iterator().next()).getInboundDependencies().size()); 469 470 assertEquals("packages in scope: ", 1, engine.getFactory().getPackages().values().size()); 471 assertEquals("classes in scope" , 1, engine.getFactory().getClasses().values().size()); 472 assertEquals("features in scope", 1, engine.getFactory().getFeatures().values().size()); 473 474 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 475 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 476 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 477 } 478 479 public void testCompute1LayerOnly() { 480 startCriteria.setGlobalIncludes("/c.C.c/"); 481 stopCriteria.setGlobalIncludes(""); 482 483 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 484 engine.computeLayers(1); 485 486 assertEquals("Nb layers", 2, engine.getNbLayers()); 487 488 assertEquals("Nb inbounds from c.C.c", c_C_c.getInboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getInboundDependencies().size()); 489 assertEquals("Nb inbounds from b.B.b", 0, ((Node) engine.getLayer(1).iterator().next()).getInboundDependencies().size()); 490 491 assertEquals("packages in scope: ", 2, engine.getFactory().getPackages().values().size()); 492 assertEquals("classes in scope" , 2, engine.getFactory().getClasses().values().size()); 493 assertEquals("features in scope", 2, engine.getFactory().getFeatures().values().size()); 494 495 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 496 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 497 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 498 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 499 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 500 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 501 } 502 503 public void testCompute4LayersWithStopCriteria() { 504 startCriteria.setGlobalIncludes("/c.C.c/"); 505 stopCriteria.setGlobalIncludes("/b.B.b/"); 506 507 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 508 engine.computeLayers(4); 509 510 assertEquals("Nb layers", 2, engine.getNbLayers()); 511 512 assertEquals("Nb inbounds from c.C.c", c_C_c.getInboundDependencies().size(), ((Node) engine.getLayer(0).iterator().next()).getInboundDependencies().size()); 513 assertEquals("Nb inbounds from b.B.b", 0, ((Node) engine.getLayer(1).iterator().next()).getInboundDependencies().size()); 514 515 assertEquals("packages in scope: ", 2, engine.getFactory().getPackages().values().size()); 516 assertEquals("classes in scope" , 2, engine.getFactory().getClasses().values().size()); 517 assertEquals("features in scope", 2, engine.getFactory().getFeatures().values().size()); 518 519 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 520 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 521 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 522 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 523 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 524 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 525 } 526 527 public void testComputeAllOutboundLayersP2P() { 528 startCriteria.setGlobalIncludes("/^a/"); 529 stopCriteria.setGlobalIncludes("/^c/"); 530 531 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureOutboundSelector()); 532 engine.computeAllLayers(); 533 534 assertEquals("Nb layers", 3, engine.getNbLayers()); 535 536 Node node = null; 537 Iterator i = engine.getLayer(0).iterator(); 538 while (i.hasNext()) { 539 Node temp = (Node) i.next(); 540 if (temp.equals(a_A_a)) { 541 node = temp; 542 } 543 } 544 545 assertEquals("Layer 0 size", 3, engine.getLayer(0).size()); 546 assertEquals("Layer 0 content", a_A_a.getName(), node.getName()); 547 assertEquals("Nb outbounds from a.A.a", a_A_a.getOutboundDependencies().size(), node.getOutboundDependencies().size()); 548 assertEquals("Layer 1 size", 1, engine.getLayer(1).size()); 549 assertEquals("Layer 1 content", b_B_b.getName(), ((Node) engine.getLayer(1).iterator().next()).getName()); 550 assertEquals("Nb outbounds from b.B.b", b_B_b.getOutboundDependencies().size(), ((Node) engine.getLayer(1).iterator().next()).getOutboundDependencies().size()); 551 assertEquals("Layer 2 size", 1, engine.getLayer(2).size()); 552 assertEquals("Layer 2 content", c_C_c.getName(), ((Node) engine.getLayer(2).iterator().next()).getName()); 553 assertEquals("Nb outbounds from c.C.c", c_C_c.getOutboundDependencies().size(), ((Node) engine.getLayer(2).iterator().next()).getOutboundDependencies().size()); 554 555 assertEquals("packages in scope: ", 3, engine.getFactory().getPackages().values().size()); 556 assertEquals("classes in scope" , 3, engine.getFactory().getClasses().values().size()); 557 assertEquals("features in scope", 3, engine.getFactory().getFeatures().values().size()); 558 559 assertEquals("package a in scope", a, engine.getFactory().getPackages().get("a")); 560 assertEquals("class a.A in scope", a_A, engine.getFactory().getClasses().get("a.A")); 561 assertEquals("feature a.A.a in scope", a_A_a, engine.getFactory().getFeatures().get("a.A.a")); 562 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 563 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 564 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 565 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 566 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 567 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 568 } 569 570 public void testComputeAllInboundLayersP2P() { 571 startCriteria.setGlobalIncludes("/^c/"); 572 stopCriteria.setGlobalIncludes("/^a/"); 573 574 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory.getPackages().values(), startCriteria, stopCriteria, new ClosureInboundSelector()); 575 engine.computeAllLayers(); 576 577 assertEquals("Nb layers", 3, engine.getNbLayers()); 578 579 Node node = null; 580 Iterator i = engine.getLayer(0).iterator(); 581 while (i.hasNext()) { 582 Node temp = (Node) i.next(); 583 if (temp.equals(c_C_c)) { 584 node = temp; 585 } 586 } 587 588 assertEquals("Layer 0 size", 3, engine.getLayer(0).size()); 589 assertEquals("Layer 0 content", c_C_c.getName(), node.getName()); 590 assertEquals("Nb inbounds from c.C.c", c_C_c.getInboundDependencies().size(), node.getInboundDependencies().size()); 591 assertEquals("Layer 1 size", 1, engine.getLayer(1).size()); 592 assertEquals("Layer 1 content", b_B_b.getName(), ((Node) engine.getLayer(1).iterator().next()).getName()); 593 assertEquals("Nb inbounds from b.B.b", b_B_b.getInboundDependencies().size(), ((Node) engine.getLayer(1).iterator().next()).getInboundDependencies().size()); 594 assertEquals("Layer 2 size", 1, engine.getLayer(1).size()); 595 assertEquals("Layer 2 content", a_A_a.getName(), ((Node) engine.getLayer(2).iterator().next()).getName()); 596 assertEquals("Nb inbounds from a.A.a", a_A_a.getInboundDependencies().size(), ((Node) engine.getLayer(2).iterator().next()).getInboundDependencies().size()); 597 598 assertEquals("packages in scope: ", 3, engine.getFactory().getPackages().values().size()); 599 assertEquals("classes in scope" , 3, engine.getFactory().getClasses().values().size()); 600 assertEquals("features in scope", 3, engine.getFactory().getFeatures().values().size()); 601 602 assertEquals("package a in scope", a, engine.getFactory().getPackages().get("a")); 603 assertEquals("class a.A in scope", a_A, engine.getFactory().getClasses().get("a.A")); 604 assertEquals("feature a.A.a in scope", a_A_a, engine.getFactory().getFeatures().get("a.A.a")); 605 assertEquals("package b in scope", b, engine.getFactory().getPackages().get("b")); 606 assertEquals("class b.B in scope", b_B, engine.getFactory().getClasses().get("b.B")); 607 assertEquals("feature b.B.b in scope", b_B_b, engine.getFactory().getFeatures().get("b.B.b")); 608 assertEquals("package c in scope", c, engine.getFactory().getPackages().get("c")); 609 assertEquals("class c.C in scope", c_C, engine.getFactory().getClasses().get("c.C")); 610 assertEquals("feature c.C.c in scope", c_C_c, engine.getFactory().getFeatures().get("c.C.c")); 611 } 612 } 613 | Popular Tags |