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 TestGraphCopierWithFiltering 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 includeFilter; 58 private List excludeFilter; 59 60 private GraphCopier copier; 61 62 protected void setUp() throws Exception { 63 scopeCriteria = new RegularExpressionSelectionCriteria(); 64 filterCriteria = new RegularExpressionSelectionCriteria(); 65 factory = new NodeFactory(); 66 67 a = factory.createPackage("a"); 68 a_A = factory.createClass("a.A"); 69 a_A_a = factory.createFeature("a.A.a"); 70 71 b = factory.createPackage("b"); 72 b_B = factory.createClass("b.B"); 73 b_B_b = factory.createFeature("b.B.b"); 74 75 c = factory.createPackage("c"); 76 c_C = factory.createClass("c.C"); 77 c_C_c = factory.createFeature("c.C.c"); 78 79 includeFilter = new LinkedList(); 80 includeFilter.add("/^b/"); 81 82 excludeFilter = new LinkedList(); 83 excludeFilter.add("/^c/"); 84 85 copier = new GraphCopier(new SelectiveTraversalStrategy(scopeCriteria, filterCriteria)); 86 } 87 88 public void testIncludeFilterF2FtoP2P() { 89 a_A_a.addDependency(b_B_b); 90 a_A_a.addDependency(c_C_c); 91 92 scopeCriteria.setMatchingClasses(false); 93 scopeCriteria.setMatchingFeatures(false); 94 filterCriteria.setMatchingClasses(false); 95 filterCriteria.setMatchingFeatures(false); 96 filterCriteria.setGlobalIncludes(includeFilter); 97 98 copier.traverseNodes(factory.getPackages().values()); 99 100 assertTrue(copier.getScopeFactory().createPackage("a").getInboundDependencies().isEmpty()); 101 assertTrue(copier.getScopeFactory().createPackage("a").getOutboundDependencies().isEmpty()); 102 } 103 104 public void testExcludeFilterF2FtoP2P() { 105 a_A_a.addDependency(b_B_b); 106 a_A_a.addDependency(c_C_c); 107 108 scopeCriteria.setMatchingClasses(false); 109 scopeCriteria.setMatchingFeatures(false); 110 filterCriteria.setMatchingClasses(false); 111 filterCriteria.setMatchingFeatures(false); 112 filterCriteria.setGlobalExcludes(excludeFilter); 113 114 copier.traverseNodes(factory.getPackages().values()); 115 116 assertTrue(copier.getScopeFactory().createPackage("a").getInboundDependencies().isEmpty()); 117 assertTrue(copier.getScopeFactory().createPackage("a").getOutboundDependencies().isEmpty()); 118 } 119 } 120 | Popular Tags |