1 32 33 package com.jeantessier.dependency; 34 35 import java.util.*; 36 37 import junit.framework.*; 38 39 import org.apache.log4j.*; 40 41 public class TestTransitiveClosureNonMaximized extends TestCase { 42 private NodeFactory factory; 43 44 private FeatureNode in2; 45 private FeatureNode in1; 46 private FeatureNode base; 47 private FeatureNode out1; 48 private FeatureNode out2; 49 50 private RegularExpressionSelectionCriteria startCriteria; 51 private RegularExpressionSelectionCriteria stopCriteria; 52 53 private NodeFactory resultFactory; 54 55 protected void setUp() { 56 factory = new NodeFactory(); 57 58 in2 = factory.createFeature("in2.In2.In2()"); 59 in1 = factory.createFeature("in1.In1.In1()"); 60 base = factory.createFeature("base.Base.Base()"); 61 out1 = factory.createFeature("out1.Out1.Out1()"); 62 out2 = factory.createFeature("out2.Out2.Out2()"); 63 64 in2.addDependency(in1); 65 in1.addDependency(base); 66 base.addDependency(out1); 67 out1.addDependency(out2); 68 69 List scopeIncludes = new ArrayList(1); 70 scopeIncludes.add("/^base/"); 71 List filderIncludes = Collections.EMPTY_LIST; 72 73 startCriteria = new RegularExpressionSelectionCriteria(); 74 startCriteria.setMatchingPackages(false); 75 startCriteria.setMatchingClasses(false); 76 startCriteria.setMatchingFeatures(false); 77 startCriteria.setGlobalIncludes(scopeIncludes); 78 79 stopCriteria = new RegularExpressionSelectionCriteria(); 80 stopCriteria.setMatchingPackages(false); 81 stopCriteria.setMatchingClasses(false); 82 stopCriteria.setMatchingFeatures(false); 83 stopCriteria.setGlobalIncludes(filderIncludes); 84 } 85 86 public void testFeatureToFeatureFromFeature() { 87 startCriteria.setMatchingFeatures(true); 88 stopCriteria.setMatchingFeatures(true); 89 90 Logger.getLogger(getClass()).info("Start f2f test from feature ..."); 91 compute(Collections.singleton(base)); 92 Logger.getLogger(getClass()).info("Stop f2f test from feature ..."); 93 94 assertEquals(5, resultFactory.getFeatures().size()); 95 assertTrue(resultFactory.getFeatures().values().contains(in2)); 96 assertTrue(resultFactory.getFeatures().values().contains(in1)); 97 assertTrue(resultFactory.getFeatures().values().contains(base)); 98 assertTrue(resultFactory.getFeatures().values().contains(out1)); 99 assertTrue(resultFactory.getFeatures().values().contains(out2)); 100 101 assertEquals(0, resultFactory.createFeature("in2.In2.In2()").getInboundDependencies().size()); 102 assertEquals(1, resultFactory.createFeature("in2.In2.In2()").getOutboundDependencies().size()); 103 assertEquals(1, resultFactory.createFeature("in1.In1.In1()").getInboundDependencies().size()); 104 assertEquals(1, resultFactory.createFeature("in1.In1.In1()").getOutboundDependencies().size()); 105 assertEquals(1, resultFactory.createFeature("base.Base.Base()").getInboundDependencies().size()); 106 assertEquals(1, resultFactory.createFeature("base.Base.Base()").getOutboundDependencies().size()); 107 assertEquals(1, resultFactory.createFeature("out1.Out1.Out1()").getInboundDependencies().size()); 108 assertEquals(1, resultFactory.createFeature("out1.Out1.Out1()").getOutboundDependencies().size()); 109 assertEquals(1, resultFactory.createFeature("out2.Out2.Out2()").getInboundDependencies().size()); 110 assertEquals(0, resultFactory.createFeature("out2.Out2.Out2()").getOutboundDependencies().size()); 111 112 assertEquals(0, resultFactory.createClass("in2.In2").getInboundDependencies().size()); 113 assertEquals(0, resultFactory.createClass("in2.In2").getOutboundDependencies().size()); 114 assertEquals(0, resultFactory.createClass("in1.In1").getInboundDependencies().size()); 115 assertEquals(0, resultFactory.createClass("in1.In1").getOutboundDependencies().size()); 116 assertEquals(0, resultFactory.createClass("base.Base").getInboundDependencies().size()); 117 assertEquals(0, resultFactory.createClass("base.Base").getOutboundDependencies().size()); 118 assertEquals(0, resultFactory.createClass("out1.Out1").getInboundDependencies().size()); 119 assertEquals(0, resultFactory.createClass("out1.Out1").getOutboundDependencies().size()); 120 assertEquals(0, resultFactory.createClass("out2.Out2").getInboundDependencies().size()); 121 assertEquals(0, resultFactory.createClass("out2.Out2").getOutboundDependencies().size()); 122 123 assertEquals(0, resultFactory.createPackage("in2").getInboundDependencies().size()); 124 assertEquals(0, resultFactory.createPackage("in2").getOutboundDependencies().size()); 125 assertEquals(0, resultFactory.createPackage("in1").getInboundDependencies().size()); 126 assertEquals(0, resultFactory.createPackage("in1").getOutboundDependencies().size()); 127 assertEquals(0, resultFactory.createPackage("base").getInboundDependencies().size()); 128 assertEquals(0, resultFactory.createPackage("base").getOutboundDependencies().size()); 129 assertEquals(0, resultFactory.createPackage("out1").getInboundDependencies().size()); 130 assertEquals(0, resultFactory.createPackage("out1").getOutboundDependencies().size()); 131 assertEquals(0, resultFactory.createPackage("out2").getInboundDependencies().size()); 132 assertEquals(0, resultFactory.createPackage("out2").getOutboundDependencies().size()); 133 } 134 135 public void testFeatureToFeatureFromPackages() { 136 startCriteria.setMatchingFeatures(true); 137 stopCriteria.setMatchingFeatures(true); 138 139 Logger.getLogger(getClass()).info("Start f2f test from package list ..."); 140 compute(factory.getPackages().values()); 141 Logger.getLogger(getClass()).info("Stop f2f test from package list ..."); 142 143 assertEquals(5, resultFactory.getFeatures().size()); 144 assertTrue(resultFactory.getFeatures().values().contains(in2)); 145 assertTrue(resultFactory.getFeatures().values().contains(in1)); 146 assertTrue(resultFactory.getFeatures().values().contains(base)); 147 assertTrue(resultFactory.getFeatures().values().contains(out1)); 148 assertTrue(resultFactory.getFeatures().values().contains(out2)); 149 150 assertEquals(0, resultFactory.createFeature("in2.In2.In2()").getInboundDependencies().size()); 151 assertEquals(1, resultFactory.createFeature("in2.In2.In2()").getOutboundDependencies().size()); 152 assertEquals(1, resultFactory.createFeature("in1.In1.In1()").getInboundDependencies().size()); 153 assertEquals(1, resultFactory.createFeature("in1.In1.In1()").getOutboundDependencies().size()); 154 assertEquals(1, resultFactory.createFeature("base.Base.Base()").getInboundDependencies().size()); 155 assertEquals(1, resultFactory.createFeature("base.Base.Base()").getOutboundDependencies().size()); 156 assertEquals(1, resultFactory.createFeature("out1.Out1.Out1()").getInboundDependencies().size()); 157 assertEquals(1, resultFactory.createFeature("out1.Out1.Out1()").getOutboundDependencies().size()); 158 assertEquals(1, resultFactory.createFeature("out2.Out2.Out2()").getInboundDependencies().size()); 159 assertEquals(0, resultFactory.createFeature("out2.Out2.Out2()").getOutboundDependencies().size()); 160 161 assertEquals(0, resultFactory.createClass("in2.In2").getInboundDependencies().size()); 162 assertEquals(0, resultFactory.createClass("in2.In2").getOutboundDependencies().size()); 163 assertEquals(0, resultFactory.createClass("in1.In1").getInboundDependencies().size()); 164 assertEquals(0, resultFactory.createClass("in1.In1").getOutboundDependencies().size()); 165 assertEquals(0, resultFactory.createClass("base.Base").getInboundDependencies().size()); 166 assertEquals(0, resultFactory.createClass("base.Base").getOutboundDependencies().size()); 167 assertEquals(0, resultFactory.createClass("out1.Out1").getInboundDependencies().size()); 168 assertEquals(0, resultFactory.createClass("out1.Out1").getOutboundDependencies().size()); 169 assertEquals(0, resultFactory.createClass("out2.Out2").getInboundDependencies().size()); 170 assertEquals(0, resultFactory.createClass("out2.Out2").getOutboundDependencies().size()); 171 172 assertEquals(0, resultFactory.createPackage("in2").getInboundDependencies().size()); 173 assertEquals(0, resultFactory.createPackage("in2").getOutboundDependencies().size()); 174 assertEquals(0, resultFactory.createPackage("in1").getInboundDependencies().size()); 175 assertEquals(0, resultFactory.createPackage("in1").getOutboundDependencies().size()); 176 assertEquals(0, resultFactory.createPackage("base").getInboundDependencies().size()); 177 assertEquals(0, resultFactory.createPackage("base").getOutboundDependencies().size()); 178 assertEquals(0, resultFactory.createPackage("out1").getInboundDependencies().size()); 179 assertEquals(0, resultFactory.createPackage("out1").getOutboundDependencies().size()); 180 assertEquals(0, resultFactory.createPackage("out2").getInboundDependencies().size()); 181 assertEquals(0, resultFactory.createPackage("out2").getOutboundDependencies().size()); 182 } 183 184 public void testClassToClassFromClass() { 185 startCriteria.setMatchingClasses(true); 186 stopCriteria.setMatchingClasses(true); 187 188 Logger.getLogger(getClass()).info("Start c2c test from class ..."); 189 compute(Collections.singleton(base.getClassNode())); 190 Logger.getLogger(getClass()).info("Stop c2c test from class ..."); 191 192 assertEquals(0, resultFactory.getFeatures().size()); 193 194 assertEquals(5, resultFactory.getClasses().size()); 195 assertTrue(resultFactory.getClasses().values().contains(in2.getClassNode())); 196 assertTrue(resultFactory.getClasses().values().contains(in1.getClassNode())); 197 assertTrue(resultFactory.getClasses().values().contains(base.getClassNode())); 198 assertTrue(resultFactory.getClasses().values().contains(out1.getClassNode())); 199 assertTrue(resultFactory.getClasses().values().contains(out2.getClassNode())); 200 201 assertEquals(0, resultFactory.createClass("in2.In2").getInboundDependencies().size()); 202 assertEquals(1, resultFactory.createClass("in2.In2").getOutboundDependencies().size()); 203 assertEquals(1, resultFactory.createClass("in1.In1").getInboundDependencies().size()); 204 assertEquals(1, resultFactory.createClass("in1.In1").getOutboundDependencies().size()); 205 assertEquals(1, resultFactory.createClass("base.Base").getInboundDependencies().size()); 206 assertEquals(1, resultFactory.createClass("base.Base").getOutboundDependencies().size()); 207 assertEquals(1, resultFactory.createClass("out1.Out1").getInboundDependencies().size()); 208 assertEquals(1, resultFactory.createClass("out1.Out1").getOutboundDependencies().size()); 209 assertEquals(1, resultFactory.createClass("out2.Out2").getInboundDependencies().size()); 210 assertEquals(0, resultFactory.createClass("out2.Out2").getOutboundDependencies().size()); 211 212 assertEquals(0, resultFactory.createPackage("in2").getInboundDependencies().size()); 213 assertEquals(0, resultFactory.createPackage("in2").getOutboundDependencies().size()); 214 assertEquals(0, resultFactory.createPackage("in1").getInboundDependencies().size()); 215 assertEquals(0, resultFactory.createPackage("in1").getOutboundDependencies().size()); 216 assertEquals(0, resultFactory.createPackage("base").getInboundDependencies().size()); 217 assertEquals(0, resultFactory.createPackage("base").getOutboundDependencies().size()); 218 assertEquals(0, resultFactory.createPackage("out1").getInboundDependencies().size()); 219 assertEquals(0, resultFactory.createPackage("out1").getOutboundDependencies().size()); 220 assertEquals(0, resultFactory.createPackage("out2").getInboundDependencies().size()); 221 assertEquals(0, resultFactory.createPackage("out2").getOutboundDependencies().size()); 222 } 223 224 public void testClassToClassFromPackageList() { 225 startCriteria.setMatchingClasses(true); 226 stopCriteria.setMatchingClasses(true); 227 228 Logger.getLogger(getClass()).info("Start c2c test from package list ..."); 229 compute(factory.getPackages().values()); 230 Logger.getLogger(getClass()).info("Stop c2c test from package list ..."); 231 232 assertEquals(0, resultFactory.getFeatures().size()); 233 234 assertEquals(5, resultFactory.getClasses().size()); 235 assertTrue(resultFactory.getClasses().values().contains(in2.getClassNode())); 236 assertTrue(resultFactory.getClasses().values().contains(in1.getClassNode())); 237 assertTrue(resultFactory.getClasses().values().contains(base.getClassNode())); 238 assertTrue(resultFactory.getClasses().values().contains(out1.getClassNode())); 239 assertTrue(resultFactory.getClasses().values().contains(out2.getClassNode())); 240 241 assertEquals(0, resultFactory.createClass("in2.In2").getInboundDependencies().size()); 242 assertEquals(1, resultFactory.createClass("in2.In2").getOutboundDependencies().size()); 243 assertEquals(1, resultFactory.createClass("in1.In1").getInboundDependencies().size()); 244 assertEquals(1, resultFactory.createClass("in1.In1").getOutboundDependencies().size()); 245 assertEquals(1, resultFactory.createClass("base.Base").getInboundDependencies().size()); 246 assertEquals(1, resultFactory.createClass("base.Base").getOutboundDependencies().size()); 247 assertEquals(1, resultFactory.createClass("out1.Out1").getInboundDependencies().size()); 248 assertEquals(1, resultFactory.createClass("out1.Out1").getOutboundDependencies().size()); 249 assertEquals(1, resultFactory.createClass("out2.Out2").getInboundDependencies().size()); 250 assertEquals(0, resultFactory.createClass("out2.Out2").getOutboundDependencies().size()); 251 252 assertEquals(0, resultFactory.createPackage("in2").getInboundDependencies().size()); 253 assertEquals(0, resultFactory.createPackage("in2").getOutboundDependencies().size()); 254 assertEquals(0, resultFactory.createPackage("in1").getInboundDependencies().size()); 255 assertEquals(0, resultFactory.createPackage("in1").getOutboundDependencies().size()); 256 assertEquals(0, resultFactory.createPackage("base").getInboundDependencies().size()); 257 assertEquals(0, resultFactory.createPackage("base").getOutboundDependencies().size()); 258 assertEquals(0, resultFactory.createPackage("out1").getInboundDependencies().size()); 259 assertEquals(0, resultFactory.createPackage("out1").getOutboundDependencies().size()); 260 assertEquals(0, resultFactory.createPackage("out2").getInboundDependencies().size()); 261 assertEquals(0, resultFactory.createPackage("out2").getOutboundDependencies().size()); 262 } 263 264 public void testPackageToPackageFromPackage() { 265 startCriteria.setMatchingPackages(true); 266 stopCriteria.setMatchingPackages(true); 267 268 Logger.getLogger(getClass()).info("Start p2p test from package ..."); 269 compute(Collections.singleton(base.getClassNode().getPackageNode())); 270 Logger.getLogger(getClass()).info("Stop p2p test from package ..."); 271 272 assertEquals(0, resultFactory.getFeatures().size()); 273 274 assertEquals(0, resultFactory.getClasses().size()); 275 276 assertEquals(5, resultFactory.getPackages().size()); 277 assertTrue(resultFactory.getPackages().values().contains(in2.getClassNode().getPackageNode())); 278 assertTrue(resultFactory.getPackages().values().contains(in1.getClassNode().getPackageNode())); 279 assertTrue(resultFactory.getPackages().values().contains(base.getClassNode().getPackageNode())); 280 assertTrue(resultFactory.getPackages().values().contains(out1.getClassNode().getPackageNode())); 281 assertTrue(resultFactory.getPackages().values().contains(out2.getClassNode().getPackageNode())); 282 283 assertEquals(0, resultFactory.createPackage("in2").getInboundDependencies().size()); 284 assertEquals(1, resultFactory.createPackage("in2").getOutboundDependencies().size()); 285 assertEquals(1, resultFactory.createPackage("in1").getInboundDependencies().size()); 286 assertEquals(1, resultFactory.createPackage("in1").getOutboundDependencies().size()); 287 assertEquals(1, resultFactory.createPackage("base").getInboundDependencies().size()); 288 assertEquals(1, resultFactory.createPackage("base").getOutboundDependencies().size()); 289 assertEquals(1, resultFactory.createPackage("out1").getInboundDependencies().size()); 290 assertEquals(1, resultFactory.createPackage("out1").getOutboundDependencies().size()); 291 assertEquals(1, resultFactory.createPackage("out2").getInboundDependencies().size()); 292 assertEquals(0, resultFactory.createPackage("out2").getOutboundDependencies().size()); 293 } 294 295 public void testPackageToPackageFromPackageList() { 296 startCriteria.setMatchingPackages(true); 297 stopCriteria.setMatchingPackages(true); 298 299 Logger.getLogger(getClass()).info("Start p2p test from package list ..."); 300 compute(factory.getPackages().values()); 301 Logger.getLogger(getClass()).info("Stop p2p test from package list ..."); 302 303 assertEquals(0, resultFactory.getFeatures().size()); 304 305 assertEquals(0, resultFactory.getClasses().size()); 306 307 assertEquals(5, resultFactory.getPackages().size()); 308 assertTrue(resultFactory.getPackages().values().contains(in2.getClassNode().getPackageNode())); 309 assertTrue(resultFactory.getPackages().values().contains(in1.getClassNode().getPackageNode())); 310 assertTrue(resultFactory.getPackages().values().contains(base.getClassNode().getPackageNode())); 311 assertTrue(resultFactory.getPackages().values().contains(out1.getClassNode().getPackageNode())); 312 assertTrue(resultFactory.getPackages().values().contains(out2.getClassNode().getPackageNode())); 313 314 assertEquals(0, resultFactory.createPackage("in2").getInboundDependencies().size()); 315 assertEquals(1, resultFactory.createPackage("in2").getOutboundDependencies().size()); 316 assertEquals(1, resultFactory.createPackage("in1").getInboundDependencies().size()); 317 assertEquals(1, resultFactory.createPackage("in1").getOutboundDependencies().size()); 318 assertEquals(1, resultFactory.createPackage("base").getInboundDependencies().size()); 319 assertEquals(1, resultFactory.createPackage("base").getOutboundDependencies().size()); 320 assertEquals(1, resultFactory.createPackage("out1").getInboundDependencies().size()); 321 assertEquals(1, resultFactory.createPackage("out1").getOutboundDependencies().size()); 322 assertEquals(1, resultFactory.createPackage("out2").getInboundDependencies().size()); 323 assertEquals(0, resultFactory.createPackage("out2").getOutboundDependencies().size()); 324 } 325 326 private void compute(Collection nodes) { 327 RegularExpressionSelectionCriteria localStartCriteria = new RegularExpressionSelectionCriteria(); 328 localStartCriteria.setGlobalIncludes(startCriteria.getGlobalIncludes()); 329 RegularExpressionSelectionCriteria localStopCriteria = new RegularExpressionSelectionCriteria(); 330 localStopCriteria.setGlobalIncludes(stopCriteria.getGlobalIncludes()); 331 332 TransitiveClosure closure = new TransitiveClosure(localStartCriteria, localStopCriteria); 333 closure.setMaximumInboundDepth(TransitiveClosure.UNBOUNDED_DEPTH); 334 closure.setMaximumOutboundDepth(TransitiveClosure.UNBOUNDED_DEPTH); 335 closure.traverseNodes(nodes); 336 337 RegularExpressionSelectionCriteria localScopeCriteria = new RegularExpressionSelectionCriteria(); 338 localScopeCriteria.setMatchingPackages(startCriteria.isMatchingPackages()); 339 localScopeCriteria.setMatchingClasses(startCriteria.isMatchingClasses()); 340 localScopeCriteria.setMatchingFeatures(startCriteria.isMatchingFeatures()); 341 RegularExpressionSelectionCriteria localFilterCriteria = new RegularExpressionSelectionCriteria(); 342 localFilterCriteria.setMatchingPackages(stopCriteria.isMatchingPackages()); 343 localFilterCriteria.setMatchingClasses(stopCriteria.isMatchingClasses()); 344 localFilterCriteria.setMatchingFeatures(stopCriteria.isMatchingFeatures()); 345 346 GraphSummarizer summarizer = new GraphSummarizer(localScopeCriteria, localFilterCriteria); 347 summarizer.traverseNodes(closure.getFactory().getPackages().values()); 348 349 resultFactory = summarizer.getScopeFactory(); 350 } 351 } 352 | Popular Tags |