1 package net.javacoding.jspider.mod.rule; 2 3 import junit.framework.TestCase; 4 import net.javacoding.jspider.spi.Rule; 5 import net.javacoding.jspider.mockobjects.OverridingPropertySet; 6 import net.javacoding.jspider.api.model.Decision; 7 8 import java.net.URL ; 9 10 13 public class BoundedDepthRuleTest extends TestCase { 14 15 OverridingPropertySet config; 16 17 public BoundedDepthRuleTest ( ) { 18 super ( "BoundedDepthRuleTest" ); 19 } 20 21 protected void setUp() throws Exception { 22 config = new OverridingPropertySet ( null ); 23 } 24 25 public void testSimple ( ) throws Exception { 26 int min = 0; 27 int max = 0; 28 String urlString = "http://j-spider.sourceforge.net/test.html"; 29 int expected = Decision.RULE_ACCEPT; 30 31 applyTest(min,max,urlString, expected); 32 } 33 34 public void testMaxOK ( ) throws Exception { 35 int min = 0; 36 int max = 3; 37 String urlString = "http://j-spider.sourceforge.net/test/abc/index.html"; 38 int expected = Decision.RULE_ACCEPT; 39 40 applyTest(min,max,urlString, expected); 41 } 42 43 public void testMaxOnBoundary ( ) throws Exception { 44 int min = 0; 45 int max = 2; 46 String urlString = "http://j-spider.sourceforge.net/test/abc/index.html"; 47 int expected = Decision.RULE_ACCEPT; 48 49 applyTest(min,max,urlString, expected); 50 } 51 52 public void testMaxError ( ) throws Exception { 53 int min = 0; 54 int max = 1; 55 String urlString = "http://j-spider.sourceforge.net/test/abc/index.html"; 56 int expected = Decision.RULE_IGNORE; 57 58 applyTest(min,max,urlString, expected); 59 } 60 61 public void testMinOK ( ) throws Exception { 62 int min = 2; 63 int max = 999; 64 String urlString = "http://j-spider.sourceforge.net/test/abc/def/index.html"; 65 int expected = Decision.RULE_ACCEPT; 66 67 applyTest(min,max,urlString, expected); 68 } 69 70 public void testMinOnBoundary ( ) throws Exception { 71 int min = 3; 72 int max = 999; 73 String urlString = "http://j-spider.sourceforge.net/test/abc/def/index.html"; 74 int expected = Decision.RULE_ACCEPT; 75 76 applyTest(min,max,urlString, expected); 77 } 78 79 public void testBothOnBoundary ( ) throws Exception { 80 int min = 3; 81 int max = 3; 82 String urlString = "http://j-spider.sourceforge.net/test/abc/def/index.html"; 83 int expected = Decision.RULE_ACCEPT; 84 85 applyTest(min,max,urlString, expected); 86 } 87 88 public void testMinError ( ) throws Exception { 89 int min = 4; 90 int max = 999; 91 String urlString = "http://j-spider.sourceforge.net/test/abc/def/index.html"; 92 int expected = Decision.RULE_IGNORE; 93 94 applyTest(min,max,urlString, expected); 95 } 96 97 public void applyTest ( int min, int max, String urlString, int expected ) throws Exception { 98 URL url = new URL (urlString); 99 config.setValue(BoundedDepthRule.MIN_DEPTH, new Integer (min)); 100 config.setValue(BoundedDepthRule.MAX_DEPTH, new Integer (max)); 101 Rule rule = new BoundedDepthRule(config); 102 Decision decision = rule.apply(null, null, url); 103 assertEquals("wrong decision taken on url", expected, decision.getDecision() ); 104 } 105 106 } 107 | Popular Tags |