KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > mod > rule > BoundedDepthRuleTest


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 JavaDoc;
9
10 /**
11  * $Id: BoundedDepthRuleTest.java,v 1.1 2003/04/07 15:51:05 vanrogu Exp $
12  */

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 JavaDoc {
22         config = new OverridingPropertySet ( null );
23     }
24
25     public void testSimple ( ) throws Exception JavaDoc {
26         int min = 0;
27         int max = 0;
28         String JavaDoc 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 JavaDoc {
35         int min = 0;
36         int max = 3;
37         String JavaDoc 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 JavaDoc {
44         int min = 0;
45         int max = 2;
46         String JavaDoc 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 JavaDoc {
53         int min = 0;
54         int max = 1;
55         String JavaDoc 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 JavaDoc {
62         int min = 2;
63         int max = 999;
64         String JavaDoc 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 JavaDoc {
71         int min = 3;
72         int max = 999;
73         String JavaDoc 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 JavaDoc {
80         int min = 3;
81         int max = 3;
82         String JavaDoc 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 JavaDoc {
89         int min = 4;
90         int max = 999;
91         String JavaDoc 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 JavaDoc urlString, int expected ) throws Exception JavaDoc {
98         URL JavaDoc url = new URL JavaDoc(urlString);
99         config.setValue(BoundedDepthRule.MIN_DEPTH, new Integer JavaDoc(min));
100         config.setValue(BoundedDepthRule.MAX_DEPTH, new Integer JavaDoc(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