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 TestClosureStartSelector extends TestCase { 43 private NodeFactory factory; 44 private NodeFactory localFactory; 45 private RegularExpressionSelectionCriteria localCriteria; 46 47 private PackageNode a; 48 private ClassNode a_A; 49 private FeatureNode a_A_a; 50 51 private PackageNode b; 52 private ClassNode b_B; 53 private FeatureNode b_B_b; 54 55 private PackageNode c; 56 private ClassNode c_C; 57 private FeatureNode c_C_c; 58 59 protected void setUp() throws Exception { 60 factory = new NodeFactory(); 61 localFactory = new NodeFactory(); 62 localCriteria = new RegularExpressionSelectionCriteria(); 63 64 a = factory.createPackage("a"); 65 a_A = factory.createClass("a.A"); 66 a_A_a = factory.createFeature("a.A.a"); 67 68 b = factory.createPackage("b"); 69 b_B = factory.createClass("b.B"); 70 b_B_b = factory.createFeature("b.B.b"); 71 72 c = factory.createPackage("c"); 73 c_C = factory.createClass("c.C"); 74 c_C_c = factory.createFeature("c.C.c"); 75 76 a_A_a.addDependency(b_B_b); 77 b_B_b.addDependency(c_C_c); 78 } 79 80 public void testOneSelectedNode() { 81 localCriteria.setGlobalIncludes("/b.B.b/"); 82 83 ClosureStartSelector selector = new ClosureStartSelector(localFactory, localCriteria); 84 selector.traverseNodes(factory.getPackages().values()); 85 86 assertEquals("nodes in selection", 1, selector.getSelectedNodes().size()); 87 assertEquals("b.B.b in selection", b_B_b, selector.getSelectedNodes().iterator().next()); 88 assertSame("b.B.b in selection", b_B_b, selector.getSelectedNodes().iterator().next()); 89 } 90 91 public void testOneCopiedNode() { 92 localCriteria.setGlobalIncludes("/b.B.b/"); 93 94 ClosureStartSelector selector = new ClosureStartSelector(localFactory, localCriteria); 95 selector.traverseNodes(factory.getPackages().values()); 96 97 assertEquals("packages in scope", 1, localFactory.getPackages().size()); 98 assertEquals("classes in scope" , 1, localFactory.getClasses().size()); 99 assertEquals("features in scope", 1, localFactory.getFeatures().size()); 100 101 assertEquals("package b in scope" , b, localFactory.getPackages().get("b")); 102 assertEquals("class b.B in scope" , b_B, localFactory.getClasses().get("b.B")); 103 assertEquals("feature b.B.b in scope", b_B_b, localFactory.getFeatures().get("b.B.b")); 104 105 assertNotSame("package b in scope" , b, localFactory.getPackages().get("b")); 106 assertNotSame("class b.B in scope" , b_B, localFactory.getClasses().get("b.B")); 107 assertNotSame("feature b.B.b in scope", b_B_b, localFactory.getFeatures().get("b.B.b")); 108 109 assertEquals("nodes in selection", 1, selector.getCopiedNodes().size()); 110 assertEquals("b.B.b in selection", b_B_b, selector.getCopiedNodes().iterator().next()); 111 assertNotSame("b.B.b in selection", b_B_b, selector.getCopiedNodes().iterator().next()); 112 assertSame("b.B.b in selection", localFactory.getFeatures().get("b.B.b"), selector.getCopiedNodes().iterator().next()); 113 } 114 115 public void testMultipleSelectedNodes() { 116 localCriteria.setGlobalIncludes("/a.A.a/, /^b/"); 117 118 ClosureStartSelector selector = new ClosureStartSelector(localFactory, localCriteria); 119 selector.traverseNodes(factory.getPackages().values()); 120 121 assertEquals("nodes in selection", 4, selector.getSelectedNodes().size()); 122 assertTrue("a.A.a in selection", selector.getSelectedNodes().contains(a_A_a)); 123 assertTrue("b in selection", selector.getSelectedNodes().contains(b)); 124 assertTrue("b.B in selection", selector.getSelectedNodes().contains(b_B)); 125 assertTrue("b.B.b in selection", selector.getSelectedNodes().contains(b_B_b)); 126 } 127 128 public void testMultipleCopiedNodes() { 129 localCriteria.setGlobalIncludes("/a.A.a/, /^b/"); 130 131 ClosureStartSelector selector = new ClosureStartSelector(localFactory, localCriteria); 132 selector.traverseNodes(factory.getPackages().values()); 133 134 assertEquals("packages in scope", 2, localFactory.getPackages().size()); 135 assertEquals("classes in scope" , 2, localFactory.getClasses().size()); 136 assertEquals("features in scope", 2, localFactory.getFeatures().size()); 137 138 assertEquals("package a in scope" , a, localFactory.getPackages().get("a")); 139 assertEquals("class a.A in scope" , a_A, localFactory.getClasses().get("a.A")); 140 assertEquals("feature a.A.a in scope", a_A_a, localFactory.getFeatures().get("a.A.a")); 141 assertEquals("package b in scope" , b, localFactory.getPackages().get("b")); 142 assertEquals("class b.B in scope" , b_B, localFactory.getClasses().get("b.B")); 143 assertEquals("feature b.B.b in scope", b_B_b, localFactory.getFeatures().get("b.B.b")); 144 145 assertNotSame("package a in scope" , a, localFactory.getPackages().get("a")); 146 assertNotSame("class a.A in scope" , a_A, localFactory.getClasses().get("a.A")); 147 assertNotSame("feature a.A.a in scope", a_A_a, localFactory.getFeatures().get("a.A.a")); 148 assertNotSame("package b in scope" , b, localFactory.getPackages().get("b")); 149 assertNotSame("class b.B in scope" , b_B, localFactory.getClasses().get("b.B")); 150 assertNotSame("feature b.B.b in scope", b_B_b, localFactory.getFeatures().get("b.B.b")); 151 152 assertEquals("nodes in selection", 4, selector.getCopiedNodes().size()); 153 assertTrue("a.A.a in selection", selector.getCopiedNodes().contains(a_A_a)); 154 assertTrue("b in selection", selector.getCopiedNodes().contains(b)); 155 assertTrue("b.B in selection", selector.getCopiedNodes().contains(b_B)); 156 assertTrue("b.B.b in selection", selector.getCopiedNodes().contains(b_B_b)); 157 } 158 159 public void testVisitInferredPackage() { 160 ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria()); 161 selector.traverseNodes(Collections.singleton(b)); 162 163 assertEquals("package.isConfirmed()", b.isConfirmed(), ((Node) localFactory.getPackages().get(b.getName())).isConfirmed()); 164 } 165 166 public void testVisitConfirmedPackage() { 167 b.setConfirmed(true); 168 169 ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria()); 170 selector.traverseNodes(Collections.singleton(b)); 171 172 assertEquals("package.isConfirmed()", b.isConfirmed(), ((Node) localFactory.getPackages().get(b.getName())).isConfirmed()); 173 } 174 175 public void testVisitInferredClass() { 176 ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria()); 177 selector.traverseNodes(Collections.singleton(b_B)); 178 179 assertEquals("class.isConfirmed()", b_B.isConfirmed(), ((Node) localFactory.getClasses().get(b_B.getName())).isConfirmed()); 180 } 181 182 public void testVisitConfirmedClass() { 183 b_B.setConfirmed(true); 184 185 ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria()); 186 selector.traverseNodes(Collections.singleton(b_B)); 187 188 assertEquals("class.isConfirmed()", b_B.isConfirmed(), ((Node) localFactory.getClasses().get(b_B.getName())).isConfirmed()); 189 } 190 191 public void testVisitInferredFeature() { 192 ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria()); 193 selector.traverseNodes(Collections.singleton(b_B_b)); 194 195 assertEquals("feature.isConfirmed()", b_B_b.isConfirmed(), ((Node) localFactory.getFeatures().get(b_B_b.getName())).isConfirmed()); 196 } 197 198 public void testVisitConfirmedFeature() { 199 b_B_b.setConfirmed(true); 200 201 ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria()); 202 selector.traverseNodes(Collections.singleton(b_B_b)); 203 204 assertEquals("feature.isConfirmed()", b_B_b.isConfirmed(), ((Node) localFactory.getFeatures().get(b_B_b.getName())).isConfirmed()); 205 } 206 } 207 | Popular Tags |