1 32 33 package com.jeantessier.dependency; 34 35 import java.io.*; 36 import java.util.*; 37 38 import junit.framework.*; 39 40 public class TestGraphSummarizerWithFiltering extends TestCase { 41 private RegularExpressionSelectionCriteria scopeCriteria; 42 private RegularExpressionSelectionCriteria filterCriteria; 43 private NodeFactory factory; 44 45 private Node a; 46 private Node a_A; 47 private Node a_A_a; 48 49 private Node b; 50 private Node b_B; 51 private Node b_B_b; 52 53 private Node c; 54 private Node c_C; 55 private Node c_C_c; 56 57 private List includeScope; 58 private List includeFilter; 59 private List excludeFilter; 60 61 private GraphCopier copier; 62 63 protected void setUp() throws Exception { 64 scopeCriteria = new RegularExpressionSelectionCriteria(); 65 filterCriteria = new RegularExpressionSelectionCriteria(); 66 factory = new NodeFactory(); 67 68 a = factory.createPackage("a"); 69 a_A = factory.createClass("a.A"); 70 a_A_a = factory.createFeature("a.A.a"); 71 72 b = factory.createPackage("b"); 73 b_B = factory.createClass("b.B"); 74 b_B_b = factory.createFeature("b.B.b"); 75 76 c = factory.createPackage("c"); 77 c_C = factory.createClass("c.C"); 78 c_C_c = factory.createFeature("c.C.c"); 79 80 includeScope = new LinkedList(); 81 includeScope.add("/^a/"); 82 83 includeFilter = new LinkedList(); 84 includeFilter.add("/^b/"); 85 86 excludeFilter = new LinkedList(); 87 excludeFilter.add("/^c/"); 88 89 copier = new GraphSummarizer(scopeCriteria, filterCriteria); 90 } 91 92 public void testIncludeFilterF2FtoP2P() { 93 a_A_a.addDependency(b_B_b); 94 a_A_a.addDependency(c_C_c); 95 96 scopeCriteria.setMatchingClasses(false); 97 scopeCriteria.setMatchingFeatures(false); 98 filterCriteria.setMatchingClasses(false); 99 filterCriteria.setMatchingFeatures(false); 100 filterCriteria.setGlobalIncludes(includeFilter); 101 102 copier.traverseNodes(factory.getPackages().values()); 103 104 assertTrue(copier.getScopeFactory().createPackage("a").getInboundDependencies().isEmpty()); 105 assertEquals(copier.getScopeFactory().createPackage("a").getOutboundDependencies().toString(), 106 1, 107 copier.getScopeFactory().createPackage("a").getOutboundDependencies().size()); 108 assertTrue(copier.getScopeFactory().createPackage("a").getOutboundDependencies().contains(b)); 109 } 110 111 public void testExcludeFilterF2FtoP2P() { 112 a_A_a.addDependency(b_B_b); 113 a_A_a.addDependency(c_C_c); 114 115 scopeCriteria.setMatchingClasses(false); 116 scopeCriteria.setMatchingFeatures(false); 117 scopeCriteria.setGlobalIncludes(includeScope); 118 filterCriteria.setMatchingClasses(false); 119 filterCriteria.setMatchingFeatures(false); 120 filterCriteria.setGlobalExcludes(excludeFilter); 121 122 assertTrue(!filterCriteria.matchesFeatureName(c_C_c.getName())); 123 124 copier.traverseNodes(factory.getPackages().values()); 125 126 assertTrue(copier.getScopeFactory().createPackage("a").getInboundDependencies().isEmpty()); 127 assertEquals(copier.getScopeFactory().createPackage("a").getOutboundDependencies().toString(), 128 1, 129 copier.getScopeFactory().createPackage("a").getOutboundDependencies().size()); 130 assertTrue(copier.getScopeFactory().createPackage("a").getOutboundDependencies().contains(b)); 131 } 132 } 133 | Popular Tags |