1 32 33 package com.jeantessier.dependency; 34 35 import java.util.*; 36 37 import junit.framework.*; 38 39 public class TestTransitiveClosureSlice extends TestCase { 40 private NodeFactory factory; 41 42 private Node in3; 43 private Node in2; 44 private Node in1; 45 private Node base; 46 private Node out1; 47 private Node out2; 48 private Node out3; 49 50 private TransitiveClosure selector; 51 52 protected void setUp() throws Exception { 53 factory = new NodeFactory(); 54 55 in3 = factory.createPackage("in3"); 56 in2 = factory.createPackage("in2"); 57 in1 = factory.createPackage("in1"); 58 base = factory.createPackage("base"); 59 out1 = factory.createPackage("out1"); 60 out2 = factory.createPackage("out2"); 61 out3 = factory.createPackage("out3"); 62 63 in3.addDependency(in2); 64 in2.addDependency(in1); 65 in1.addDependency(base); 66 base.addDependency(out1); 67 out1.addDependency(out2); 68 out2.addDependency(out3); 69 70 selector = new TransitiveClosure(new RegularExpressionSelectionCriteria(), new NullSelectionCriteria()); 71 } 72 73 public void testDefaultDepth() { 74 selector.traverseNodes(Collections.singleton(base)); 75 76 assertEquals("number of packages", 4, selector.getFactory().getPackages().size()); 77 assertEquals("base.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size()); 78 assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size()); 79 assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size()); 80 assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size()); 81 assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size()); 82 assertEquals("out2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size()); 83 assertEquals("out3.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out3")).getInboundDependencies().size()); 84 assertEquals("out3.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out3")).getOutboundDependencies().size()); 85 } 86 87 public void testUnboundedDepthInboundOutbound() { 88 selector.setMaximumInboundDepth(TransitiveClosure.UNBOUNDED_DEPTH); 89 selector.setMaximumOutboundDepth(TransitiveClosure.UNBOUNDED_DEPTH); 90 91 selector.traverseNodes(Collections.singleton(base)); 92 93 assertEquals("number of packages", 7, selector.getFactory().getPackages().size()); 94 assertEquals("in3.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in3")).getInboundDependencies().size()); 95 assertEquals("in3.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in3")).getOutboundDependencies().size()); 96 assertEquals("in2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getInboundDependencies().size()); 97 assertEquals("in2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getOutboundDependencies().size()); 98 assertEquals("in1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size()); 99 assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size()); 100 assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size()); 101 assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size()); 102 assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size()); 103 assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size()); 104 assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size()); 105 assertEquals("out2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size()); 106 assertEquals("out3.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out3")).getInboundDependencies().size()); 107 assertEquals("out3.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out3")).getOutboundDependencies().size()); 108 } 109 110 public void testUnboundedDepthInbound() { 111 selector.setMaximumInboundDepth(TransitiveClosure.UNBOUNDED_DEPTH); 112 selector.setMaximumOutboundDepth(TransitiveClosure.DO_NOT_FOLLOW); 113 114 selector.traverseNodes(Collections.singleton(base)); 115 116 assertEquals("number of packages", 4, selector.getFactory().getPackages().size()); 117 assertEquals("in3.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in3")).getInboundDependencies().size()); 118 assertEquals("in3.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in3")).getOutboundDependencies().size()); 119 assertEquals("in2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getInboundDependencies().size()); 120 assertEquals("in2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getOutboundDependencies().size()); 121 assertEquals("in1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size()); 122 assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size()); 123 assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size()); 124 assertEquals("base.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size()); 125 } 126 127 public void testUnboundedDepthOutbound() { 128 selector.setMaximumInboundDepth(TransitiveClosure.DO_NOT_FOLLOW); 129 selector.setMaximumOutboundDepth(TransitiveClosure.UNBOUNDED_DEPTH); 130 131 selector.traverseNodes(Collections.singleton(base)); 132 133 assertEquals("number of packages", 4, selector.getFactory().getPackages().size()); 134 assertEquals("base.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size()); 135 assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size()); 136 assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size()); 137 assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size()); 138 assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size()); 139 assertEquals("out2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size()); 140 assertEquals("out3.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out3")).getInboundDependencies().size()); 141 assertEquals("out3.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out3")).getOutboundDependencies().size()); 142 } 143 144 public void testZeroDepthInboundOutbound() { 145 selector.setMaximumInboundDepth(0); 146 selector.setMaximumOutboundDepth(0); 147 148 selector.traverseNodes(Collections.singleton(base)); 149 150 assertEquals("number of packages", 1, selector.getFactory().getPackages().size()); 151 assertEquals("base.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size()); 152 assertEquals("base.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size()); 153 } 154 155 public void testSingleDepthInboundOutbound() { 156 selector.setMaximumInboundDepth(1); 157 selector.setMaximumOutboundDepth(1); 158 159 selector.traverseNodes(Collections.singleton(base)); 160 161 assertEquals("number of packages", 3, selector.getFactory().getPackages().size()); 162 assertEquals("in1.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size()); 163 assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size()); 164 assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size()); 165 assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size()); 166 assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size()); 167 assertEquals("out1.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size()); 168 } 169 170 public void testDoubleDepthInboundOutbound() { 171 selector.setMaximumInboundDepth(2); 172 selector.setMaximumOutboundDepth(2); 173 174 selector.traverseNodes(Collections.singleton(base)); 175 176 assertEquals("number of packages", 5, selector.getFactory().getPackages().size()); 177 assertEquals("in2.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in2")).getInboundDependencies().size()); 178 assertEquals("in2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getOutboundDependencies().size()); 179 assertEquals("in1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size()); 180 assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size()); 181 assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size()); 182 assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size()); 183 assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size()); 184 assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size()); 185 assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size()); 186 assertEquals("out2.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size()); 187 } 188 189 public void testExactDepthInboundOutbound() { 190 selector.setMaximumInboundDepth(3); 191 selector.setMaximumOutboundDepth(3); 192 193 selector.traverseNodes(Collections.singleton(base)); 194 195 assertEquals("number of packages", 7, selector.getFactory().getPackages().size()); 196 assertEquals("in3.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in3")).getInboundDependencies().size()); 197 assertEquals("in3.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in3")).getOutboundDependencies().size()); 198 assertEquals("in2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getInboundDependencies().size()); 199 assertEquals("in2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getOutboundDependencies().size()); 200 assertEquals("in1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size()); 201 assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size()); 202 assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size()); 203 assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size()); 204 assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size()); 205 assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size()); 206 assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size()); 207 assertEquals("out2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size()); 208 assertEquals("out3.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out3")).getInboundDependencies().size()); 209 assertEquals("out3.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out3")).getOutboundDependencies().size()); 210 } 211 212 public void testOverDepthInboundOutbound() { 213 selector.setMaximumInboundDepth(4); 214 selector.setMaximumOutboundDepth(4); 215 216 selector.traverseNodes(Collections.singleton(base)); 217 218 assertEquals("number of packages", 7, selector.getFactory().getPackages().size()); 219 assertEquals("in3.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in3")).getInboundDependencies().size()); 220 assertEquals("in3.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in3")).getOutboundDependencies().size()); 221 assertEquals("in2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getInboundDependencies().size()); 222 assertEquals("in2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getOutboundDependencies().size()); 223 assertEquals("in1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size()); 224 assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size()); 225 assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size()); 226 assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size()); 227 assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size()); 228 assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size()); 229 assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size()); 230 assertEquals("out2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size()); 231 assertEquals("out3.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out3")).getInboundDependencies().size()); 232 assertEquals("out3.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out3")).getOutboundDependencies().size()); 233 } 234 } 235 | Popular Tags |